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

Peter Jeremy peter at rulingia.com
Tue May 11 10:38:44 UTC 2021


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

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).

-- 
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/20210511/5bd5ed48/attachment.sig>


More information about the freebsd-net mailing list