From nobody Thu Feb 16 00:38:30 2023 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PHGK23gxlz3rZ8C for ; Thu, 16 Feb 2023 00:38:46 +0000 (UTC) (envelope-from pprocacci@gmail.com) Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PHGK01nSCz41x5 for ; Thu, 16 Feb 2023 00:38:44 +0000 (UTC) (envelope-from pprocacci@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=p6tbRNAw; spf=pass (mx1.freebsd.org: domain of pprocacci@gmail.com designates 2607:f8b0:4864:20::22c as permitted sender) smtp.mailfrom=pprocacci@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-oi1-x22c.google.com with SMTP id be34so215320oib.10 for ; Wed, 15 Feb 2023 16:38:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=dwRmvNiYcNam9ZyayWzX24r4HuyLb4jtibUlfPZELf8=; b=p6tbRNAwkuoqDOSkm/pyktDDIdbHwZX1YYpZwxEWtLTiRaXUtC5Bv2ykJgmykJpUya LGMfGk/q6srmet02cHQbZwEvC6gtQD2Qq3Odvt2JKMhlNOWhfOCVGGO/aHTRORYuXoDQ agjqb90Q7pJUSths2VhpI/hVU4noLU4douMgzcfo8WsmU8wbVg3YFOg9p4ARtEtFXu7v MVP43Fh1ypMff4cEYIFRwM4ZbLRhFNSRGsqga8WCU18LizA0q6clTZeIiRKFczLebmQp ZnTWCAPPt77qD1SDE8E1TDt21vcNN0dNT8YP57qOvEFKYc69p9eUVE5HqEw9yd3KTkO7 qkhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dwRmvNiYcNam9ZyayWzX24r4HuyLb4jtibUlfPZELf8=; b=OSfi3mQcMi3cHmKoS/K2umApcqu0DxYezo1IcCSXlLjI6Ao/L8kVnqYjEkI+XAH7B9 EDoViPVgtfdcKTz0ChISkn4p4PJepEVE6V5HuS7/pDZ7qbbE+cdpgcj+1Gato0DDNgAL GmXey/pDWd/mLILwDugO49VXW8dlk2a/Xs/69es5Y0bgu65EOxiYYgcodT6k2crjF4Wf JfmS9JpQ4nFewm+7eVGFRi7eD8ZSBkYpIaMKQ9zsTFuEsahd5kJyswDdLaXYRetQQ3HF MqjAJ6npABKdICxkTEza84Zj0ZgTknXffVChLMv9Tx0+H3asGMCKmnnGrNIz6Tx03YtJ WwSg== X-Gm-Message-State: AO0yUKWH44+uXhIniRoCjG+KDG1ntfwBdwK3yWP+iK2YquicgVk4vDbz r0Uc45G560mRjKi3BqUncRv8UBsIJoSZ4ayHVAnrlJHG0Q== X-Google-Smtp-Source: AK7set8xsuHFr5zXjyx9dBaUicIK0qWTK77kL+s2tBg1dRAMJMe3keVlrP6sueFcon1Yrhqi465dC2yosx8/z3CySlw= X-Received: by 2002:a05:6808:1416:b0:37d:7a4e:fb77 with SMTP id w22-20020a056808141600b0037d7a4efb77mr27159oiv.148.1676507922946; Wed, 15 Feb 2023 16:38:42 -0800 (PST) List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 References: <20230215174535.jlxuis3xwhxee3bq@beesty.loosely.org> <20230215214519.C9CC199766DF@ary.qy> <20230215222458.bij5oh3wtaq6inje@beesty.loosely.org> In-Reply-To: <20230215222458.bij5oh3wtaq6inje@beesty.loosely.org> From: Paul Procacci Date: Wed, 15 Feb 2023 19:38:30 -0500 Message-ID: Subject: Re: Source IP selection To: freebsd-questions@freebsd.org Content-Type: multipart/alternative; boundary="00000000000035dc8705f4c66b93" X-Spamd-Result: default: False [-3.68 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-0.998]; NEURAL_HAM_SHORT(-0.68)[-0.678]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; ARC_NA(0.00)[]; MLMMJ_DEST(0.00)[freebsd-questions@freebsd.org]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::22c:from]; FROM_EQ_ENVFROM(0.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FREEMAIL_ENVFROM(0.00)[gmail.com]; MID_RHS_MATCH_FROMTLD(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_FROM(0.00)[gmail.com]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; TO_DN_NONE(0.00)[]; RCVD_TLS_LAST(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] X-Rspamd-Queue-Id: 4PHGK01nSCz41x5 X-Spamd-Bar: --- X-ThisMailContainsUnwantedMimeParts: N --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


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 th= ere
> >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 abou= t
> >THAT kernel but FreeBSD.
> >
> >http= s://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 determine= d upon which flags are set on the socket and what is configured on the inte= rface.
- In some cases, that happens to be the address with a= broadcast address.=C2=A0 (IP_SENDONES)
- In some cases, that= happens to be the address with a route with `dev if' specified. (IP_RO= UTETOIF)
- In some cases, that happens to be when multicast i= s being used (IN_MULTICAST)

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.
Other aliases associ= ated with the interface have no broasdcast as they are all /32's.

Ref: netinet/ip_output.c

~P= aul
--
__________________

:(){ :|:= & };:
--00000000000035dc8705f4c66b93--