When a host creates an IP packet, it must select some source address. Correct source address selection is a critical procedure, because it gives the receiver the information needed to deliver a reply. If the source is selected incorrectly, in the best case, the backward path may appear different to the forward one which is harmful for performance. In the worst case, when the addresses are administratively scoped, the reply may be lost entirely.
Linux-2.2 selects source addresses using the following algorithm:
bind(2)syscall or supplying it to
sendmsg(2)via the ancillary data object
IP_PKTINFO. In this case the kernel only checks the validity of the address and never tries to ``improve'' an incorrect user choice, generating an error instead. 1cm NB. Never say ``Never''. The sysctl option
ip_dynaddrbreaks this axiom. It has been made deliberately with the purpose of automatically reselecting the address on hosts with dynamic dial-out interfaces. However, this hack must not be used on multihomed hosts and especially on routers: it would break them.
srcparameter to the
ip routecommand, sec.7, p..
scopeparameter to the
ip routecommand, sec.7, p.).
host, the algorithm fails and returns a zero source address.
lois always the first in the search list, so that if an address with global scope (not 127.0.0.1!) is configured on loopback, it is always preferred.