Re: [exim/exim] selectable local IP in smtp transport (Issue #2953)

kurahaupo via Exim-dev <[email protected]> Thu, 09 Apr 2026 06:45:49 +0100
Newsgroups gmane.mail.exim.devel
Message-ID <exim/exim/issues/2953/comment/[email protected]>
I started writing this in response to https://bugs.exim.org/show_bug.cgi?id=2953 on 2023-04-18 (almost 3 years ago). Since it was still in my unsent messages, and it still seemed relevant, I'm adding this here.

The idea of picking an interface rather than an address is misleading, since that's not actually how routing works. (The exception is unrouted addresses, like fe80::/16 , where the application entirely takes responsibility for routing decisions, and addresses typically written with %interface appended.)

A TCP socket is identified by a quadruplet of { local-IP, local-port, remote-IP, remote-port }. These are the only parameters that are involved in creating a new socket connection (unless your OS has some non-POSIX extension).

That said, it's possible to obtain the list of addresses bound to a particular interface, and then to call bind() with one of those, but Exim does not appear to do this.

In any case it should be noted that having an address bound to an interface is only advisory:

* it doesn't necessarily guarantee that departing packets will go out that interface. In general the outbound interface will be determined purely by the destination address. (on Linux, the route to ANY local address will go via the "lo" interface.)
* it may or may not affect whether packets arriving on other interfaces are accepted for that address. (on Linux: /proc/sys/net/ipv4/conf/all/rp_filter controls this. Moreover this is based on matching the outbound interface, which as noted above may in fact be a different interface.)

If you don't bind an address to the socket before connecting it, the OS will choose a source address for you:

* Find the most specific route to the remote address;
* If the route specifies a source address, bind that as the source address; otherwise
* look at the route's outgoing interface (could be lo or lo0 ) if it's actually local to this host), and pick its "primary" address as the source (local) address. This is the step that people typically think of as the equivalence.
* Then, on Linux, and if you started without binding an address, re-do the route selection. This might or might not result in the same route being selected.

---
View it on Exim Forgejo ( https://code.exim.org/exim/exim/issues/2953#issuecomment-239490 ) or reply to this email directly.