Chapter 13. Address Resolver & Selection

Additional info can be found at

Address Resolver & Destination Address Selection

Name to IPv4 or IPv6 address resolving is usually done using a libc resolver library. Usually the function getaddrinfo is used for that. In case of more than one IPv6 address is returned, according to RFC 3484 / Default Address Selection for Internet Protocol version 6 a sorting should be applied, which can be optionally configured.

The ”magic” is controlled by a file named /etc/gai.conf (it can be that it is empty or missing by default). Default is usually somewhere stored in documentation, see ”man gai.conf” or e.g. /usr/share/doc/glibc-common/gai.conf.

For controlling sort order by configuration following are needed for testing:

$ dig +short aaaa st1.bieringer.de
2001:4dd0:ff00:834::2
2a01:238:423d:8800:85b3:9e6b:3019:8909 

precedence  ::1/128       50            # default
precedence  ::/0          40            # default
precedence  2002::/16     30            # default
precedence ::/96          20            # default
precedence ::ffff:0:0/96  10            # default
precedence 2001:4dd0:ff00:834::/64  80  # dst-A
precedence 2a01:238:423d:8800::/64  90  # dst-B

$ telnet st1.bieringer.de
Trying 2a01:238:423d:8800:85b3:9e6b:3019:8909...    (dst-B)
...
Trying 2001:4dd0:ff00:834::2...                     (dst-A)
...

precedence 2001:4dd0:ff00:834::/64  90  # dst-A ex 80
precedence 2a01:238:423d:8800::/64  80  # dst-B ex 90

$ telnet st1.bieringer.de
Trying 2001:4dd0:ff00:834::2...                     (dst-A)
...
Trying 2a01:238:423d:8800:85b3:9e6b:3019:8909...    (dst-B)
...

Source Address Selection

Source address selection in Linux is done automatically by kernel and usually only using information from routing tables and try to match the same scope of address.

Source Address Selection with ”ip addrlabel”

With extension of internal ”ip addrlabel” a source address can be bound to a destination address (e.g. selected via mechanisms above). Binding means here: ”same label” (label is a number).

# ip addrlabel
prefix ::1/128 label 0 
prefix ::/96 label 3 
prefix ::ffff:0.0.0.0/96 label 4 
prefix 2001::/32 label 6 
prefix 2001:10::/28 label 7 
prefix 2002::/16 label 2 
prefix fc00::/7 label 5 
prefix ::/0 label 1 

# ip -6 addr show dev eth1 | grep -w inet6 |grep -w global
    inet6 2001:6f8:12d8:2:5054:ff:fefb:6582/64 scope global dynamic 
    inet6 2001:6f8:900:8cbc:5054:ff:fefb:6582/64 scope global dynamic 

$ telnet st1.bieringer.de
Trying 2001:4dd0:ff00:834::2...                     (dst-A)
...
Trying 2a01:238:423d:8800:85b3:9e6b:3019:8909...    (dst-B)
...

IP6 2001:6f8:12d8:2:5054:ff:fefb:6582.37762 > 2001:4dd0:ff00:834::2.telnet:                  (src-A -> dst-A)
IP6 2001:6f8:12d8:2:5054:ff:fefb:6582.45754 > 2a01:238:423d:8800:85b3:9e6b:3019:8909.telnet: (src-A -> dst-B)

# ip addrlabel add prefix 2001:6f8:12d8:2::/64 label 200
# ip addrlabel add prefix 2001:6f8:900:8cbc::/64 label 300
# ip addrlabel add prefix 2001:4dd0:ff00:834::/64 label 200
# ip addrlabel add prefix 2a01:238:423d:8800::/64 label 300

# ip addrlabel
prefix ::1/128 label 0 
prefix ::/96 label 3 
prefix ::ffff:0.0.0.0/96 label 4 
prefix 2a01:238:423d:8800::/64 label 300   # dst-B
prefix 2001:4dd0:ff00:834::/64 label 200   # dst-A
prefix 2001:6f8:900:8cbc::/64 label 300    # src-B
prefix 2001:6f8:12d8:2::/64 label 200      # src-A
prefix 2001::/32 label 6 
prefix 2001:10::/28 label 7 
prefix 2002::/16 label 2 
prefix fc00::/7 label 5 
prefix ::/0 label 1 

$ telnet st1.bieringer.de
Trying 2001:4dd0:ff00:834::2...                     (dst-A)
...
Trying 2a01:238:423d:8800:85b3:9e6b:3019:8909...    (dst-B)
...

IP6 2001:6f8:12d8:2:5054:ff:fefb:6582.37765   > 2001:4dd0:ff00:834::2.telnet:                  (src-A -> dst-A)
IP6 2001:6f8:900:8cbc:5054:ff:fefb:6582.39632 > 2a01:238:423d:8800:85b3:9e6b:3019:8909.telnet: (src-B -> dst-B)

Setup of persistent ”ip addrtable” is probably currently not supported by Linux distributions, so extension of network init scripts or rc.local must be used for that. A script which uses information from /etc/gai.conf and configure ”ip addrtable” accordingly can be found here: /etc/gai.conf - it ain't what you think it is