Re: Source IP selection

From: Paul Procacci <pprocacci_at_gmail.com>
Date: Thu, 16 Feb 2023 00:38:30 UTC
On Wed, Feb 15, 2023 at 5:25 PM Ian Zimmerman <
possessor.assizer305@aceecat.org> wrote:

> On Wed, Feb 15, 2023 at 04:45:19PM -0500, John Levine wrote:
> > >how is the source IP address selected for an unbound socket, if there
> > >are multiple addresses (ie. aliases) configured on the outgoing
> > >interface? I am interested in particular in the UDP case, ie.
> > >the sendto() syscall.
> > >This is almost the question at the following link but ... not about
> > >THAT kernel but FreeBSD.
> > >
> > >
> https://stackoverflow.com/questions/63955841/how-does-tcp-ip-select-a-source-ip-address
> >
> > Same answer, use bind() if you want to bind to a specific address.
>
> Let me ask a little more specifically then :)
>
> May the kernel choose an address through which there's no route to
> the destination?
>
> --
> Ian
>
>
The address that gets picked is determined upon which flags are set on the
socket and what is configured on the interface.
- In some cases, that happens to be the address with a broadcast address.
(IP_SENDONES)
- In some cases, that happens to be the address with a route with `dev if'
specified. (IP_ROUTETOIF)
- In some cases, that happens to be when multicast is being used
(IN_MULTICAST)

In your case and without looking at your routing table, it would seem to
IP_SENDONES is the case in which your address gets selected.
Other aliases associated with the interface have no broasdcast as they are
all /32's.

Ref: netinet/ip_output.c

~Paul
-- 
__________________

:(){ :|:& };: