Skip site navigation (1)Skip section navigation (2)
Date:      15 Feb 2023 18:22:40 -0500
From:      "John Levine" <johnl@iecc.com>
To:        freebsd-questions@freebsd.org
Cc:        possessor.assizer305@aceecat.org
Subject:   Re: Source IP selection
Message-ID:  <20230215232241.5A86B9977DF3@ary.qy>
In-Reply-To: <20230215222458.bij5oh3wtaq6inje@beesty.loosely.org>

next in thread | previous in thread | raw e-mail | index | archive | help
It appears that Ian Zimmerman <possessor.assizer305@aceecat.org> said:
>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?

It knows what addreses it has configured on what interfaces, and
what's in its local routing table, not the entire state of the global
Internet. The routing table just tells it what interface to use for
what networks. I think it does soemthing simple minded like using the
first address configured on the interface if you don't override that
with bind(). 

If you bind a local address and then tell it to send to a remote
address that isn't in the routing table for the interface the address
is assigned to, I have no idea what happens. Try it and let us know
what happens.

If you told us what you are trying to do, you would get more useful
answers.

R's,
John



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20230215232241.5A86B9977DF3>