sender source IP address on UDP socket bound to INADDR_ANY in golang

Peter Jeremy peter at rulingia.com
Wed May 12 12:06:31 UTC 2021


On 2021-May-11 13:40:44 +0200, "Patrick M. Hausen" <hausen at punkt.de> wrote:
>> Am 11.05.2021 um 12:38 schrieb Peter Jeremy <peter at rulingia.com>:
>> 
>> On 2021-May-08 19:05:56 +0200, "Patrick M. Hausen" <hausen at 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.
>> ...
>>> Their code in question is here:
>>> https://github.com/AdguardTeam/dnsproxy/blob/1163404e605c3dfbeab360fc3540fc290f61a321/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...
>
>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.

-- 
Peter Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 963 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-net/attachments/20210512/031afc21/attachment.sig>


More information about the freebsd-net mailing list