Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.zx2c4.com (lists.zx2c4.com [165.227.139.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2C7ECA5FFD for ; Mon, 5 Oct 2026 07:13:00 +0000 (UTC) Received: by lists.zx2c4.com (OpenSMTPD) with ESMTP id 9186d8d8; Mon, 5 Oct 2026 06:56:08 +0000 (UTC) Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [2a00:1450:4864:20::42b]) by lists.zx2c4.com (OpenSMTPD) with ESMTPS id 455b78dd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 9 Jun 2026 22:01:52 +0000 (UTC) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-45ef1629ff4so4207326f8f.0 for ; Tue, 09 Jun 2026 15:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781042512; x=1781647312; darn=lists.zx2c4.com; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G7800XX0/jd3oHhl/vxf3RLaE2dN1LF3q0H5SjsvGhk=; b=MQT8kjeNBq3aV+4hv9eykhvO6Ggfhc+qH34cgjUBSyk2GAtbb/oGOhgdG/64FIkF8R vSsXrhlKDclPRsDprJ0mqtebGBPG8v9DpBeyLzSA3spWEabH9HSifiiB46Ej480pPVhv /QpYN1X2ltUCVvBx2VeqULfhDdGbexeFkLsSaXNL6oiv9S+o0qU0vmAKc3TRBDz5Ya19 bQBIS2gV8tgrrza9AqvdzBiSCF1n31mkPMJwCprZ9HkDZWezlVn9UxBYT4BBselWbn18 U/PSywICqNmqz2REjduZe51bEvHN+5BykFSKIg7BwHdddCujkmCjwMh0CEGol3+8JiSX HjeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781042512; x=1781647312; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=G7800XX0/jd3oHhl/vxf3RLaE2dN1LF3q0H5SjsvGhk=; b=X93R9Qw6iaowRL/JvAJ7lm9Yv4fTcJG140oKgt0y+2HK1pKOB/EAtK4vffiyeV+638 b5aR5qCJ2RtR5u03J/MoCu8+otE+QxNVFXOlCvuyXOE0sFbdg/O6rHr8pL57yQdad54b hXZUCo13gG4816w96qDh4jJ58ewI8VDLxJjYrHzN82uDfaLQEOEswZqNRgKlivl+q/NG bA39RfGCjqvJ/OgYlPShkncfB7ACKBhZA7Se4LDd8niu265v4FT2nVvN4DLSAkD0AFQo dDj9KQq9D3WagIeBRpUdBFAsNEME8993TDv5sP5+Lo75j0sLthiOSfhxlPBRtIwOJ1oa jVUA== X-Gm-Message-State: AOJu0YwMm2yWtNrbsWHfawRooe41sDrmZeSHos7E7F4WkHDVl+a1ZvrK 3A8IoZcZh8IUBZD5sZc0M/xyNd/MXQ7HFhCQ1tg5XF6TlGikYJPtzcEYkZK20sZV X-Gm-Gg: Acq92OGqXyh350DXcgZB6g/8GZGfNGWYQh/iPOsrlMIb7YwyyG+yYn1Z9OcQImijgww WVVSgFlMWjtnsadvF4cEi+t6rWm49TzgM+GUX6ri2/C4SoM9fHGxOqs13j/hERLgvK7lBuyXKjd 5J6sLEDsI5YwGm8i4o2/9Z2fRZ5b8Md/zd0c5gFEgzAVwEKgrNR8e/kSw/YwlhYgf/BxhZxTTcl DS7xxoxNLNpy22x5K5Rh0R1bzH/4tsZDLPsbo9joeEIdbr+Ow2LAG7/ArhYJstcSOGZmxDFOKgg Pe9MFIPlxrb4YFvdoIS61C27Ke5t26rbsrPgwVSnDSmKhYGfgn2IrfsP/NmDJSl4a6v1ciiSZsh 4kAVKPef3GW4IaJzrRE0i+0XGMcyNzFa3SitoefBLJQj4BEUy5yUy7mm1AYTjHS1BnnLPzPTfmu sysuJyy3HABz2C X-Received: by 2002:a05:600c:609b:b0:490:5466:8576 with SMTP id 5b1f17b1804b1-490c259854emr354604815e9.1.1781042511647; Tue, 09 Jun 2026 15:01:51 -0700 (PDT) Received: from akaWolf-arm ([2a10:1fc0:3::318:6a20]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4602cda3651sm54422367f8f.32.2026.06.09.15.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 15:01:51 -0700 (PDT) From: Artjom Vejsel To: wireguard@lists.zx2c4.com Cc: Jason@zx2c4.com, Artjom Vejsel Subject: [PATCH wireguard-go 1/3] conn: enable IP_PKTINFO ancillary data on PacketConn Date: Wed, 10 Jun 2026 01:01:36 +0300 Message-ID: <20260609220138.4160252-2-akawolf0@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260609220138.4160252-1-akawolf0@gmail.com> References: <20260609220138.4160252-1-akawolf0@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 05 Oct 2026 06:55:46 +0000 X-BeenThere: wireguard@lists.zx2c4.com X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: Development discussion of WireGuard List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: wireguard-bounces@lists.zx2c4.com Sender: "WireGuard" The IPV6_RECVPKTINFO/IP_PKTINFO setsockopts are set during socket creation via the ListenConfig control function. However, x/net/ipv4 and x/net/ipv6 PacketConn instances maintain their own internal control message option tracking (rawOpt), which is consulted during recvmmsg unpacking. Without calling SetControlMessage(FlagDst|FlagInterface, true), the PacketConn does not advertise these flags to the unpack path, and the resulting Message.NN remains zero on every read. Because Message.NN is zero, getSrcFromControl never finds a PKTINFO cmsg, StdNetEndpoint.src is never populated, and setSrcControl writes empty control bytes on send. The kernel then selects the outgoing source address by route lookup (RFC 6724) rather than honoring the destination address of the incoming packet. The sticky source address behavior is silently broken on hosts with multiple addresses on the listening interface. Reproduced with a userspace bind on a Linux interface holding two global IPv6 addresses, where the route preferred source differs from the address the peer initiated the handshake on: the server responded from the route-preferred address, the peer rejected the response, and the session never established. Signed-off-by: Artjom Vejsel --- conn/bind_std.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conn/bind_std.go b/conn/bind_std.go index f5c8816..c88ed4e 100644 --- a/conn/bind_std.go +++ b/conn/bind_std.go @@ -177,6 +177,7 @@ again: s.ipv4TxOffload, s.ipv4RxOffload = supportsUDPOffload(v4conn) if runtime.GOOS == "linux" || runtime.GOOS == "android" { v4pc = ipv4.NewPacketConn(v4conn) + _ = v4pc.SetControlMessage(ipv4.FlagDst|ipv4.FlagInterface, true) s.ipv4PC = v4pc } fns = append(fns, s.makeReceiveIPv4(v4pc, v4conn, s.ipv4RxOffload)) @@ -186,6 +187,7 @@ again: s.ipv6TxOffload, s.ipv6RxOffload = supportsUDPOffload(v6conn) if runtime.GOOS == "linux" || runtime.GOOS == "android" { v6pc = ipv6.NewPacketConn(v6conn) + _ = v6pc.SetControlMessage(ipv6.FlagDst|ipv6.FlagInterface, true) s.ipv6PC = v6pc } fns = append(fns, s.makeReceiveIPv6(v6pc, v6conn, s.ipv6RxOffload)) -- 2.54.0