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, Artjom Vejsel <akawolf0@gmail.com>
Subject: [PATCH wireguard-go 3/3] conn: propagate ancillary data to coalesced split frames
Date: Mon,  8 Jun 2026 03:33:07 +0300	[thread overview]
Message-ID: <20260608003307.2598372-4-akawolf0@gmail.com> (raw)
In-Reply-To: <20260608003307.2598372-1-akawolf0@gmail.com>

splitCoalescedMessages divides a single coalesced read into individual
frames by copying Buffers[0][start:end], setting N, and propagating
Addr to each child slot, but it does not propagate the control buffer
(OOB) or its length (NN). The parent buffer holds the cmsg returned by
recvmmsg for the entire coalesced datagram, including the PKTINFO that
identifies the destination address of the original packet. The child
slots retain whatever control content was left over from a previous
recv, with NN == 0 for unused slots and stale data for reused ones.

receiveIP then calls getSrcFromControl(msg.OOB[:msg.NN], ep) on each
emitted message. Because NN is zero for every split frame except the
first (which still aliases the parent's storage), StdNetEndpoint.src
is never populated for the rest, and setSrcControl on the
corresponding send writes empty control bytes. The kernel falls back
to route-based source selection, defeating the sticky source address
mechanism whenever UDP_GRO coalesces packets — which is the common
case on Linux 5.12+.

Copy the parent's control buffer and length into each split child. The
n == i case is skipped because the destination slot is the parent
itself and the slices already alias.

Signed-off-by: Artjom Vejsel <akawolf0@gmail.com>
---
 conn/bind_std.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/conn/bind_std.go b/conn/bind_std.go
index 72f3047..88c0ce3 100644
--- a/conn/bind_std.go
+++ b/conn/bind_std.go
@@ -528,6 +528,11 @@ func splitCoalescedMessages(msgs []ipv6.Message, firstMsgAt int, getGSO getGSOFu
 			copied := copy(msgs[n].Buffers[0], msg.Buffers[0][start:end])
 			msgs[n].N = copied
 			msgs[n].Addr = msg.Addr
+			if n != i {
+				oobCopied := copy(msgs[n].OOB[:cap(msgs[n].OOB)], msg.OOB[:msg.NN])
+				msgs[n].OOB = msgs[n].OOB[:oobCopied]
+				msgs[n].NN = oobCopied
+			}
 			start = end
 			end += gsoSize
 			if end > msg.N {
-- 
2.54.0


  parent reply	other threads:[~2026-10-05  6:57 UTC|newest]

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