conn: fix sticky source address on multi-IP hosts
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | conn: enable IP_PKTINFO ancillary data on PacketConnconn/ | +2 | 0 replies | |
| 2/3 | conn: reset udpAddrPool slice length before copyconn/ | +2 | 0 replies | |
| 3/3 | conn: propagate ancillary data to coalesced split framesconn/ | +5 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH wireguard-go 0/3] conn: fix sticky source address on multi-IP hosts
Three independent bugs in conn/bind_std.go cause the sticky source address feature to silently fail on hosts with multiple addresses on the listening interface. With UDP_GRO enabled (Linux 5.12+) the brokenness compounds: even after fixing PKTINFO delivery on the PacketConn, coalesced reads drop the cmsg on every frame past the first.
Symptom on a real-world setup: a Linux box with a static 2001:db8::100 and a DHCPv6-assigned 2001:db8::943 on enp1s0, where the default route's preferred source is ::943. A peer initiates a handshake to [::100]:port; the server responds from ::943; the peer rejects the response because the source IP does not match its configured endpoint; the session never establishes. The user has to install a route hack (ip -6 route ... src ::100) as a workaround.
After this series, the kernel's PKTINFO ancillary data correctly threads through the PacketConn, recvmmsg/UDP_GRO split path, and back into the outgoing sendmsg cmsg, so the response is emitted from the address the peer reached, regardless of route source preference.
Reproduction via netns, verified end-to-end:
sudo ip netns add srvns && sudo ip netns add cltns
sudo ip link add veth-srv type veth peer name veth-srvNS sudo ip link add veth-clt type veth peer name veth-cltNS sudo ip link set veth-srvNS netns srvns
sudo ip link set veth-cltNS netns cltns
sudo ip link add br-test type bridge
sudo ip link set veth-srv master br-test
sudo ip link set veth-clt master br-test
sudo ip link set veth-srv up
sudo ip link set veth-clt up
sudo ip link set br-test up
sudo ip netns exec srvns ip link set veth-srvNS up
sudo ip netns exec srvns ip -6 addr add fd00:1::100/64 dev veth-srvNS sudo ip netns exec srvns ip -6 addr add fd00:1::943/64 dev veth-srvNS sudo ip netns exec cltns ip link set veth-cltNS up
sudo ip netns exec cltns ip -6 addr add fd00:1::1/64 dev veth-cltNS
sleep 3 # wait for DAD
sudo ip netns exec srvns ip -6 route get fd00:1::1
# confirms: src fd00:1::943 (the preferred source from /64)
Run wireguard-go in each netns with the client's Endpoint set to [fd00:1::100]:port. Before the series, tcpdump -i br-test shows the handshake response from ::943 and the client immediately roams its endpoint to ::943. After the series, the response is from ::100 and the client's endpoint stays as configured.
Each patch is independent and reviewable on its own:
1/3 enables PKTINFO delivery on the receive path so ep.src actually
gets populated;
2/3 fixes a slice-length pool-reuse bug in Send() that truncates the
destination address after v4/v6 transitions; 3/3 restores PKTINFO on each frame produced by splitCoalescedMessages
so UDP_GRO offload no longer defeats the fix from 1/3.
conn/bind_std.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
2.54.0