WireGuard Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Artjom Vejsel <akawolf0@gmail.com>
To: wireguard@lists.zx2c4.com
Cc: Jason@zx2c4.com
Subject: [PATCH wireguard-go 0/3] conn: fix sticky source address on multi-IP hosts
Date: Wed, 10 Jun 2026 01:01:35 +0300	[thread overview]
Message-ID: <20260609220138.4160252-1-akawolf0@gmail.com> (raw)

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

-- 
2.54.0


             reply	other threads:[~2026-10-05  7:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 22:01 Artjom Vejsel [this message]
2026-06-09 22:01 ` [PATCH wireguard-go 1/3] conn: enable IP_PKTINFO ancillary data on PacketConn Artjom Vejsel
2026-06-09 22:01 ` [PATCH wireguard-go 2/3] conn: reset udpAddrPool slice length before copy Artjom Vejsel
2026-06-09 22:01 ` [PATCH wireguard-go 3/3] conn: propagate ancillary data to coalesced split frames Artjom Vejsel
  -- strict thread matches above, loose matches on Subject: below --
2026-06-08  0:33 [PATCH wireguard-go 0/3] conn: fix sticky source address on multi-IP hosts Artjom Vejsel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260609220138.4160252-1-akawolf0@gmail.com \
    --to=akawolf0@gmail.com \
    --cc=Jason@zx2c4.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox