Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Feb 2023 19:38:30 -0500
From:      Paul Procacci <pprocacci@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Source IP selection
Message-ID:  <CAFbbPuh8wnjKkLaPPKi2GzrqB8Gd-ebjze6-W3u%2B8pOH2zppng@mail.gmail.com>
In-Reply-To: <20230215222458.bij5oh3wtaq6inje@beesty.loosely.org>
References:  <20230215174535.jlxuis3xwhxee3bq@beesty.loosely.org> <20230215214519.C9CC199766DF@ary.qy> <20230215222458.bij5oh3wtaq6inje@beesty.loosely.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--00000000000035dc8705f4c66b93
Content-Type: text/plain; charset="UTF-8"

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
-- 
__________________

:(){ :|:& };:

--00000000000035dc8705f4c66b93
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div dir=3D"ltr"><br></div><br><div class=3D"gmail_qu=
ote"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, Feb 15, 2023 at 5:25 PM =
Ian Zimmerman &lt;<a href=3D"mailto:possessor.assizer305@aceecat.org" targe=
t=3D"_blank">possessor.assizer305@aceecat.org</a>&gt; wrote:<br></div><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:=
1px solid rgb(204,204,204);padding-left:1ex">On Wed, Feb 15, 2023 at 04:45:=
19PM -0500, John Levine wrote:<br>
&gt; &gt;how is the source IP address selected for an unbound socket, if th=
ere<br>
&gt; &gt;are multiple addresses (ie. aliases) configured on the outgoing<br=
>
&gt; &gt;interface? I am interested in particular in the UDP case, ie.<br>
&gt; &gt;the sendto() syscall.<br>
&gt; &gt;This is almost the question at the following link but ... not abou=
t<br>
&gt; &gt;THAT kernel but FreeBSD.<br>
&gt; &gt;<br>
&gt; &gt;<a href=3D"https://stackoverflow.com/questions/63955841/how-does-t=
cp-ip-select-a-source-ip-address" rel=3D"noreferrer" target=3D"_blank">http=
s://stackoverflow.com/questions/63955841/how-does-tcp-ip-select-a-source-ip=
-address</a><br>
&gt; <br>
&gt; Same answer, use bind() if you want to bind to a specific address.<br>
<br>
Let me ask a little more specifically then :)<br>
<br>
May the kernel choose an address through which there&#39;s no route to<br>
the destination?<br>
<br>
-- <br>
Ian<br>
<br>
</blockquote></div><div><br></div>The address that gets picked is determine=
d upon which flags are set on the socket and what is configured on the inte=
rface.<br></div><div>- In some cases, that happens to be the address with a=
 broadcast address.=C2=A0 (IP_SENDONES)<br></div><div>- In some cases, that=
 happens to be the address with a route with `dev if&#39; specified. (IP_RO=
UTETOIF)<br></div><div>- In some cases, that happens to be when multicast i=
s being used (IN_MULTICAST)<br></div><div><br></div><div>In your case and w=
ithout looking at your routing table, it would seem to IP_SENDONES is the c=
ase in which your address gets selected.<br></div><div>Other aliases associ=
ated with the interface have no broasdcast as they are all /32&#39;s.<br></=
div><div><br></div><div>Ref: netinet/ip_output.c<br></div><div><br></div>~P=
aul<br><div><div>-- <br><div dir=3D"ltr">__________________<br><br>:(){ :|:=
&amp; };:</div></div></div></div>

--00000000000035dc8705f4c66b93--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFbbPuh8wnjKkLaPPKi2GzrqB8Gd-ebjze6-W3u%2B8pOH2zppng>