Repository navigation
Tunnel inbound: SO_REUSEPORT fix and IPv6 support for the OpenBSD transparent proxy - #6624
Conversation
Every reply to a client is sent from a socket bound to the original destination with SO_BINDANY, and one such socket is created per session. Two clients talking to the same destination, two phones resolving over the same DNS server for instance, therefore bind the same address and port twice, and the second bind fails with EADDRINUSE, leaving that session without answers. SO_REUSEADDR does not help here: on OpenBSD it is only promoted to allow a duplicate binding for multicast addresses, so a unicast address needs SO_REUSEPORT on both sockets. The Linux implementation of FakeUDP already sets both options.
|
6546晾了三个星期为什么刚好合并两天才发现。。 |
|
Fair point. It only shows up when two sessions reach the same destination The fix was already sitting in my IPv6 branch. I split it out into its own |
|
|
pf divert-to works the same way for inet6, but the original destination arrives in different control messages: IPV6_PKTINFO carries the address and IPV6_RECVDSTPORT the port, instead of IP_RECVDSTADDR and IP_RECVDSTPORT. The reply socket has to be created in the matching address family as well, because OpenBSD always forces IPV6_V6ONLY and a single socket never serves both.
|
Done, added the IPv6 commit here. The PR is now two commits:
Tested on OpenBSD 7.7/7.8/7.9 amd64 on live routers, IPv6 via an HE tunnel: One piece is left out on purpose: outbound UDP to an IPv6 destination also |
这个策略是对的,这个 PR 只包含 OpenBSD 平台特定代码,所以将会得到快速合并 |
) #6688 (comment) Completes #6624 (comment) --------- Co-authored-by: 风扇滑翔翼 <[email protected]>
Follow-up to #6546.
On OpenBSD every UDP reply to a client is sent from a socket bound to the
original destination with
SO_BINDANY, andFakeUDPcreates one such socketper session. Two clients talking to the same destination at the same time, two
phones resolving over the same DNS server for instance, therefore bind the same
address and port twice. The second bind fails with
EADDRINUSE, surfacing asfake: bind ...: address already in use, and that session never gets an answer.SO_REUSEADDRalone does not cover this. Inin_pcbaddrisavail_lock()thereuse flag starts as
so->so_options & SO_REUSEPORTand is only widened toaccept
SO_REUSEADDRfor multicast addresses, so a duplicate binding on aunicast address needs
SO_REUSEPORTon both sockets:proxy/dokodemo/fakeudp_linux.goalready sets both options, this brings theOpenBSD implementation in line.
Tested on OpenBSD 7.7/7.8/7.9 amd64 on a live router with several LAN clients.