Date: Tue, 11 May 2021 20:38:21 +1000 From: Peter Jeremy <peter@rulingia.com> To: "Patrick M. Hausen" <hausen@punkt.de> Cc: freebsd-net@freebsd.org Subject: Re: sender source IP address on UDP socket bound to INADDR_ANY in golang Message-ID: <YJpenW9tB7LzlyS9@server.rulingia.com> In-Reply-To: <2B26D5AB-0F77-4E36-AD9A-D7D6CE5F173C@punkt.de> References: <2B26D5AB-0F77-4E36-AD9A-D7D6CE5F173C@punkt.de>
next in thread | previous in thread | raw e-mail | index | archive | help
--3LdTRkK5WjZEBujW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2021-May-08 19:05:56 +0200, "Patrick M. Hausen" <hausen@punkt.de> wrote: >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. =2E.. >Their code in question is here: >https://github.com/AdguardTeam/dnsproxy/blob/1163404e605c3dfbeab360fc3540f= c290f61a321/proxyutil/udp_unix.go#L47 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... FreeBSD ip(4) documents that setting IPPROTO_IP.IP_RECVDSTADDR on a SOCK_DGRAM socket will allow recvmsg(2) to retrieve the local dst address as a control message. The code to retrieve that seems to be present, and there's code that supports setting IP_RECVDSTADDR, though I haven't dug through to find the relevant setsockopt(2) call. I'm not sure how to debug that further without tracing through the Go code. You could try ktrace'ing the executable to verify that the relevant setsockopt() calls (though I don't think ktrace will report the actual flag state). --=20 Peter Jeremy --3LdTRkK5WjZEBujW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQKTBAEBCgB9FiEE7rKYbDBnHnTmXCJ+FqWXoOSiCzQFAmCaXphfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEVF QjI5ODZDMzA2NzFFNzRFNjVDMjI3RTE2QTU5N0EwRTRBMjBCMzQACgkQFqWXoOSi CzT6Yg//QfIrt1ef3KuwEyobIuA+2mxDPC3tzzFJv3oNZnB2AU5zmEJ0iqvNkqzS t92H+YrqZfewj7TdOiBrcrF1eOItNVzC940qdO5yII7y2gRrvVOdAwNRuHRI94rV HWNMdXnMSAXd15uI9Z5BiCEr1vtEDfKwAIYXcZfGFZuNnPlM6gasYh6AQ6Eaqjj+ dKPeBJETtKnjdVevTldZIbb9Uadhn0wz8IoClXAGT/uRQUV1c/EWbqDwnq8vzTzk TeExCxYmgPekRb1ujltB8CBqgO8OYShqTCTiF/mF2q7ikLzwE+pC9brS4t7BrjIl 4i3DshoRnShm6x4e+25RNA3ITd+wfKWDk9lr2HAZA/6UD2dQ5rrHrrqGL/4WsKij OUsBTIwiHgALqUmGU7UgZAw32npPURMxgEWpuAGBwqinf43cy01MPzrOHDMm8M73 KcZybnECTBt9pG0OvSqvGS0geFolgcqnrbJpS0/RyJY8eTbodknzNZI/T+6NLmcl UXLxEfzh0937Gv0JDLv0pCgMlY8gFTfIF47U3RlcEuMy56AidP6Wcky4R1wlKgGk MJ5oLlTqk44weNvwiIWeASGL/NCYGF5ZY5Pc7jhrpfHlx4wbzMa4pCFe9vfvIiia z88dVmtcyKkCeagDvp7YPYRVodWtSI8aX4Dkel1uhZyOsZ0Ly+o= =BfNE -----END PGP SIGNATURE----- --3LdTRkK5WjZEBujW--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YJpenW9tB7LzlyS9>