From owner-freebsd-net@freebsd.org Wed May 12 12:06:31 2021 Return-Path: Delivered-To: freebsd-net@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BB43463C355 for ; Wed, 12 May 2021 12:06:31 +0000 (UTC) (envelope-from peter@rulingia.com) Received: from vtr.rulingia.com (vtr.rulingia.com [IPv6:2001:19f0:5801:ebe:5400:1ff:fe53:30fd]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA512 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "vtr.rulingia.com", Issuer "R3" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FgD6G08V7z4XF7 for ; Wed, 12 May 2021 12:06:29 +0000 (UTC) (envelope-from peter@rulingia.com) Received: from server.rulingia.com (ppp239-208.static.internode.on.net [59.167.239.208]) by vtr.rulingia.com (8.16.1/8.15.2) with ESMTPS id 14CC6Egk046555 (version=TLSv1.3 cipher=AEAD-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 May 2021 22:06:20 +1000 (AEST) (envelope-from peter@rulingia.com) DKIM-Filter: OpenDKIM Filter v2.10.3 vtr.rulingia.com 14CC6Egk046555 X-Bogosity: Ham, spamicity=0.000000 Received: from server.rulingia.com (localhost.rulingia.com [127.0.0.1]) by server.rulingia.com (8.16.1/8.16.1) with ESMTPS id 14CC69Yl064006 (version=TLSv1.3 cipher=AEAD-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 12 May 2021 22:06:09 +1000 (AEST) (envelope-from peter@server.rulingia.com) Received: (from peter@localhost) by server.rulingia.com (8.16.1/8.16.1/Submit) id 14CC69E7064005; Wed, 12 May 2021 22:06:09 +1000 (AEST) (envelope-from peter) Date: Wed, 12 May 2021 22:06:09 +1000 From: Peter Jeremy To: "Patrick M. Hausen" Cc: freebsd-net@freebsd.org Subject: Re: sender source IP address on UDP socket bound to INADDR_ANY in golang Message-ID: References: <2B26D5AB-0F77-4E36-AD9A-D7D6CE5F173C@punkt.de> <846FFF4A-0D81-4F04-8358-1B14F996C0A2@punkt.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="B9JC0CRfskJyn7wx" Content-Disposition: inline In-Reply-To: <846FFF4A-0D81-4F04-8358-1B14F996C0A2@punkt.de> X-PGP-Key: http://www.rulingia.com/keys/peter.pgp X-Rspamd-Queue-Id: 4FgD6G08V7z4XF7 X-Spamd-Bar: ------ X-Spamd-Result: default: False [-6.10 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[rulingia.com:s=default]; FREEFALL_USER(0.00)[peter]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.20)[multipart/signed,text/plain]; SPAMHAUS_ZRD(0.00)[2001:19f0:5801:ebe:5400:1ff:fe53:30fd:from:127.0.2.255]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[rulingia.com:+]; RCPT_COUNT_TWO(0.00)[2]; DMARC_POLICY_ALLOW(-0.50)[rulingia.com,quarantine]; NEURAL_HAM_SHORT(-1.00)[-1.000]; SIGNED_PGP(-2.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RBL_DBL_DONT_QUERY_IPS(0.00)[2001:19f0:5801:ebe:5400:1ff:fe53:30fd:from]; ASN(0.00)[asn:20473, ipnet:2001:19f0:5800::/38, country:US]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-net] X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 May 2021 12:06:31 -0000 --B9JC0CRfskJyn7wx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2021-May-11 13:40:44 +0200, "Patrick M. Hausen" wrote: >> Am 11.05.2021 um 12:38 schrieb Peter Jeremy : >>=20 >> On 2021-May-08 19:05:56 +0200, "Patrick M. Hausen" wro= te: >>> I am facing a problem that is perfectly explained by the semantics >>> of the socket interface for UDP, if one assumes that the application >>> in question binds to INADDR_ANY and does not specifically set the >>> sender address when sending datagrams. >> ... >>> Their code in question is here: >>> https://github.com/AdguardTeam/dnsproxy/blob/1163404e605c3dfbeab360fc35= 40fc290f61a321/proxyutil/udp_unix.go#L47 >>=20 >> So, they say that they retrieve "the net interface IP the packet was >> sent to (dst addr) from the socket's OOB data" and I agree that's what >> the referenced code does. I hadn't heard of that behaviour before and >> went digging... > >Thank you. I received some code with internal debugging added from the >AdGuard core team and will try that today or tomorrow. If I read the quote >from the documentation correctly, on possible explanation would be them >calling recvmsg() but forgetting to setsockopt()? As I see it, the possibilities boil down to: 1) The Go code isn't enabling IPPROTO_IP.IP_RECVDSTADDR on the socket. 2) There's a FreeBSD kernel bug that mean setting IP_RECVDSTADDR isn't being correctly reflected into the recvmsg control message. 3) The control message isn't being correctly plumbed through from recvmsg(2) to the Go RecvMsg() return. Note that a lot of the relevant Go library code is BSD- or FreeBSD- specific so it's also possible that there is a bug in the Go library code. --=20 Peter Jeremy --B9JC0CRfskJyn7wx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQKTBAEBCgB9FiEE7rKYbDBnHnTmXCJ+FqWXoOSiCzQFAmCbxKtfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEVF QjI5ODZDMzA2NzFFNzRFNjVDMjI3RTE2QTU5N0EwRTRBMjBCMzQACgkQFqWXoOSi CzSPkhAAkjvAzewX4sAjnJSyGiv3OBBa1vePD4dRdyaoSrGk8maD2B5tHkIjkV0m ZArhcgiyuadHDnmHc1f4SahgvCxQ7jw9sO8oihh3P2bYw239JxqsWImZ6HkgTs6q +T/VkGYkNWDivbqAyZv6XdUCoz3akxbr1w01wTgatE3BDRvXK0YDokXafAc+4XGq 4P5TG1p76PVhyBLvZHDwTQ78WvP9oBy9wc+da2J+zhscOv6WM34sEHT50q0SrBBu pjlju8kqsMWctQq2+8krSfmJi2Pfxg5KSx3CEwPau7IAqWnlX9WdRJAVAwnoUGkq DGYcwUJeVDhOe/yyqSoirFdcyRLP3TwheoMr0xic7TMfK1SsA3oOBsi21gszXxhE wEE0mRWWzXXWZveqGDc1hRqxwModVXcb1qTV+137bJzfw4jF9gYz0Mdy7i4qfqdy jocVCH/iCeSoSNmH75wCohd9LnksDTLKb+KXBRMaWlVf++9qvqHO7w7oj+s6zvJf 7e6bhwXrPVqFUA+3mhaJW9lTkX0oPhM0r6BQ6tY1x4UpXn7i3EA0zt8hWfUbn1Qw ySnV3quqy3inctDezuV9ThkHmTna6I5EL+3u4i3Ducp+5mJNN1yQoV86UWON+xy/ zpoCpk2Z83cWcuaV9wIgkIkG726zro4y3BXgmC1Dkgg4jtAVzP4= =AbdL -----END PGP SIGNATURE----- --B9JC0CRfskJyn7wx--