From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796020980; b=BEkCMTOFX6QDG1+scj3yaKUny1VXbSXUN2+OU/Ec6AGf7BCxp7pQk8jBEFjlrWuFNAtL frM55H3idFc1pio3gmkMLlw9pLREQ3uFvrpF3uvlzRPxr+J8seMwpWjPNe+4fIaUsz4ai QffN6+SjKpRNJCZswET1VWM4fRBdpE8M00a3wGhQeJDa4JqXEIA3eRWXKAb3K6Ag6JT0w mXDKFBNhwZqFQxzC2V/xZRA10/WWm3fsHQ/Nb6yPdppuNBke4Hxm7htX477rUvXO2gUa1 Mx4bNwjE+wC8UjQphVQlZDiBPa6r3Fd1gHG3Kzbaok0rfGymD2mzEzam1mHbKW9YyXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020980; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=URNM4n/71s1I+zQ2p6InL5al8Zx1n5HhfOkD3TBBj5o=; b=PPt1/f+IEkjylzRgdfdsjjAq8di2Pag9Op4/O0OQx1k2dZYexWdjiPYBcUNsUl2sBVX+ 9rJCAvOMm/uaBxAEhpmT74AtYKn8kUdjNWhf4c4mWk2CfdoQkjZ2H2dhVvQnTpXhvYibH O+2ixQhWU0ZEOoCYGR6bx9YY1f3Ddz9z6YTKfYGxRDalDX+mCVsRvLoqIABAk7Cew76Qs W/oFwFs8pkDykktSj6oTBx96BEUr1ZEXPwxYIxSo82KIg5SZ6k4F3CSywqvhUE1xeVqex GhQSFqAYPyILgDOnJfOFpaBnpeip9ZFl5HvyCa8qnvzLRoAPR7G48pdftnUDQujanlw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=blockcast.net; spf=pass smtp.mailfrom=blockcast.net; dkim=pass header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=XN3nTObj; arc=none smtp.remote-ip=74.125.82.41 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 539D2606A6BC for ; Mon, 30 Nov 2026 06:42:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 539D2606A6BC Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=blockcast.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blockcast.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=XN3nTObj Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-1b546061d58so3226176c88.1 for ; Sun, 29 Nov 2026 22:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796020978; x=1796625778; darn=vger.kernel.org; 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:content-type; bh=URNM4n/71s1I+zQ2p6InL5al8Zx1n5HhfOkD3TBBj5o=; b=XN3nTObj1b55DxKw1D9HJ7EfnE6Ch8o4/sZoR8RYa/Wr7R3lxiejzV125FzN2QPk+c KXEx2ec2//k83Mwsh683v+swF35z7AxwafL4TrdqpX67bReFoox4SISRf4OMcAD+2T6M OPEC3YwRrJGI2dF0BSA/sb9zLFAEU0dj9dUZ3dKNk4p6UgkzTfXGq/zcH+2rpsYhFjEZ +dWH+aRwb3uteo3DshUNhoaC7dGXyJFyTwkCO9BWNVy6N8ibJyOsk6L7h+zlWnHRxvVp JJ4HLs3ViYZgE5vHc/A0oFaQYl2yW2WdmDP/an9o/xQUBaZ0zAiBCdwIGP8hZu5d4mp3 stqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796020978; x=1796625778; 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:content-type; bh=URNM4n/71s1I+zQ2p6InL5al8Zx1n5HhfOkD3TBBj5o=; b=T1DbK4iGom7NhHbR+0MN1kpxS8ABDLweSqzPaYVqloR3kkWgGsaguYf25KVA0ccFj8 IcmXr1khckhpcaK7s6S7zIH779+ZoHzTY9VfXHZDezRHDnzhtZbz1Lr8ntk56nOutl6u Ck3Kzzgsk/fWZsPj17wJXDlU1ewMhk8/W4Zb+LpDymGuyEaWeaMikV+IvmH0Y7jBxVTZ AzTC+kttFLH396MIG/pQuH+nCMc+a0QmzbGDzWLLRTsG+9wbpubeLuMkyy4lKd6V/ZHh wKK+jERYRYUwsKPKyLE4E6xMJ8zxsy6dD8fqgGwkwo0NzXrtmoZxc1MNs+uov0MRcvwL xhJw== X-Forwarded-Encrypted: i=1; AL+hErFMDS7NxaiTMIevfrOzzAOqNADdadlfeFqmN+CMDXZ00DvTUxT6jDzkQgisjUpIkKXJYNZrYwU=@vger.kernel.org X-Gm-Message-State: APuU4Z+1H2uIZFBBTLZWSqO4hyPHXwJHuUbJwLT0134ZrmwEdU8v9bY4 frx+dU9NndRIJKc8rA0ImctRf6eWeQMxZjq1zlBBeRZPoH5eoGBnY+gsDd5osU4JWaQ= X-Gm-Gg: AZFdTZc2XVIBfvR99wcShJFNHUUUig23baQgTBcZ4k9rYOoHfPbPNjPMXxwAXLkX0Tj 17AorRUzQ49ZLu8rhP2dJEJKwGgLyTFkAA4TQm9/7Y490IoMFOYlO+zZzAhepC0WN68g2pWfQrq QPxaQ4lKohhVEAfUUH5xp/ee0TLxkQOUcWZ7yYmw01g+tmBekpPTjt+B/fCtEP0otO95okZDKm9 xB18fVwFcbRKwxVcVmZ7zsbFQjLQbVvYAL3DOEA9oOsDgxqxrvXOAzF/oiYGyB0eljDcH5/YwJ7 2uGeJZ9oKb9qsi3c8Lw9nF125VEdbDJH6Xt9yx3vnfgfWDsASE7j+q9AjrkC+8wS+Y5SV/q4fQb AJg6VryBF7v78doZIrvAD/56FGq+jX+FZnqb9B6i/ilRhbs9TkFd9IfpDxa2C6PhasA7gVuqRbZ M0J1+yQs9nCJZ7xqsRsnY4jVd2mjMEX45yWSx1VjIHgbCQBhdr+6G32zIymkIQmeJkpWud6XYUK focZti3roZmJWTpn+IGGocM+b6c9debOEW2I6u8xdPKj/FMOZ+T0+xZ7Om+J8QJ6T27qU0QUtZI 7eFthAeSlzFU6/o/UiDR2kP40Iwdc5u7fkdgeErqauXHRvzWYDoV8N9mo3uUgp5hd6xauxNwTRu CI8S/PuxJGh0hBrF/3LmbGZ5MTX5UHRd1XGfGLUZV9rez2x4N X-Received: by 2002:a05:701b:2918:b0:192:e5a8:6bae with SMTP id a92af1059eb24-1b570d52afcmr22063683c88.40.1796020978419; Sun, 29 Nov 2026 22:42:58 -0800 (PST) Received: from devbox.ts.blockcast.net ([2602:f74d:1::32]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385672c6f31sm94744995eec.15.2026.11.29.22.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 22:42:57 -0800 (PST) From: Omar Ramadan To: Taehee Yoo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: Simon Horman , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Willem de Bruijn Subject: [PATCH net-next v5 04/12] amt: send the Membership Query over IPv6 Date: Mon, 30 Nov 2026 06:42:41 +0000 Message-ID: <20261130064249.1874523-5-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130064249.1874523-1-omar@blockcast.net> References: <20261130064249.1874523-1-omar@blockcast.net> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit After the Request, a relay answers each gateway with a Membership Query through amt_send_membership_query(), which routes and transmits only over IPv4. Rather than adding an IPv6 twin of the function, move its routing and transmit step into amt_udp_xmit(). Given an skb that already carries the AMT message, a union amt_addr destination and the port pair, it sends over the device's family: ip_route_output_key() and udp_tunnel_xmit_skb() for IPv4, as before, and amt_route6() and udp_tunnel6_xmit_skb(), which fills in the mandatory IPv6 UDP checksum, for IPv6. Both use AMT_TOS, as the IPv4 path and the IPv6 control messages do. udp_tunnel_xmit_skb() scrubs the skb in iptunnel_xmit(), but udp_tunnel6_xmit_skb() does not, so the IPv6 path calls skb_scrub_packet() itself. Otherwise the conntrack entry and extensions of the inner packet would stay on the outer one, which conntrack would then pass as an already tracked flow. The Query is built here and has none; the Multicast Data and Membership Update sent through this helper later do. amt_send_membership_query() sizes its headroom for the outer family with amt_ip_hlen(), builds the AMT header and hands the skb to amt_udp_xmit(). The route lookup now runs after the header push; on a route failure the caller still frees the skb. Nothing sets amt->local_ipv6 yet, so amt_v6() is false for every device and the IPv6 branch of amt_udp_xmit() cannot run; the only change that takes effect is that the IPv4 route lookup now runs after the header push. The v6 argument keeps its meaning: it selects the inner protocol, IGMP or MLD, which is independent of the outer family, so an IPv6 relay queries for both. The relay's General Query, which amt_send_igmp_gq() and amt_send_mld_gq() send through amt_send_membership_query(), takes the IPv6 path once a device can have one. Both now take the gateway's endpoint as a union amt_addr, as amt_send_membership_query() does. Assisted-by: LLM Signed-off-by: Omar Ramadan --- drivers/net/amt.c | 127 +++++++++++++++++++++++++++++++--------------- 1 file changed, 86 insertions(+), 41 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 386dec11a..8da1e73b1 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -98,6 +98,12 @@ static bool amt_v6(const struct amt_dev *amt) return IS_ENABLED(CONFIG_IPV6) && !ipv6_addr_any(&amt->local_ipv6); } +/* Length of the outer IP header for the device's family. */ +static unsigned int amt_ip_hlen(const struct amt_dev *amt) +{ + return amt_v6(amt) ? sizeof(struct ipv6hdr) : sizeof(struct iphdr); +} + /* Snapshot the outer source address of a received AMT message. */ static void amt_outer_saddr(const struct amt_dev *amt, const struct sk_buff *skb, union amt_addr *addr) @@ -1014,16 +1020,17 @@ out: static bool amt_send_membership_query(struct amt_dev *amt, struct sk_buff *skb, - __be32 daddr, __be16 dport, + const union amt_addr *daddr, + __be16 dport, __be32 nonce, u64 mac, bool v6); -/* The destination is passed by value rather than as a tunnel: a Request is - * unauthenticated, so no tunnel state is created or changed for it - see - * amt_request_handler(). +/* The destination is a pointer to the caller's copy of the endpoint, not a + * tunnel: a Request is unauthenticated, so no tunnel state is created or + * changed for it - see amt_request_handler(). */ -static void amt_send_igmp_gq(struct amt_dev *amt, __be32 daddr, __be16 dport, - __be32 nonce, u64 mac) +static void amt_send_igmp_gq(struct amt_dev *amt, const union amt_addr *daddr, + __be16 dport, __be32 nonce, u64 mac) { struct sk_buff *skb; @@ -1112,8 +1119,8 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt) return skb; } -static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport, - __be32 nonce, u64 mac) +static void amt_send_mld_gq(struct amt_dev *amt, const union amt_addr *daddr, + __be16 dport, __be32 nonce, u64 mac) { struct sk_buff *skb; @@ -1129,8 +1136,8 @@ static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport, } } #else -static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport, - __be32 nonce, u64 mac) +static void amt_send_mld_gq(struct amt_dev *amt, const union amt_addr *daddr, + __be16 dport, __be32 nonce, u64 mac) { } #endif @@ -1247,6 +1254,66 @@ static void amt_req_work(struct work_struct *work) msecs_to_jiffies(100)); } +/* Route an AMT-encapsulated skb to @daddr and send it over the device's + * outer family. The caller has already pushed the AMT header; @dscp only + * steers the IPv4 route lookup. + */ +static int amt_udp_xmit(struct amt_dev *amt, struct sock *sk, + struct sk_buff *skb, const union amt_addr *daddr, + __be16 sport, __be16 dport, dscp_t dscp) +{ + struct rtable *rt; + struct flowi4 fl4; + + if (amt_v6(amt)) { + struct dst_entry *dst; + + dst = amt_route6(amt, sk, &amt->local_ipv6, &daddr->ip6, + sport, dport); + if (IS_ERR(dst)) { + netdev_dbg(amt->dev, "no route to %pI6c\n", + &daddr->ip6); + return PTR_ERR(dst); + } + /* iptunnel_xmit() scrubs the IPv4 tunnel skb, but + * udp_tunnel6_xmit_skb() does not, so drop the inner + * packet's conntrack and extensions here. Links cannot + * cross netns, so this is never xnet. + */ + skb_scrub_packet(skb, false); + udp_tunnel6_xmit_skb(dst, sk, skb, amt->dev, &amt->local_ipv6, + &daddr->ip6, AMT_TOS, + ip6_dst_hoplimit(dst), 0, sport, dport, + false, 0); + return 0; + } + + memset(&fl4, 0, sizeof(struct flowi4)); + fl4.flowi4_oif = amt->stream_dev->ifindex; + fl4.daddr = daddr->ip4; + fl4.saddr = amt->local_ip; + fl4.flowi4_dscp = dscp; + fl4.flowi4_proto = IPPROTO_UDP; + rt = ip_route_output_key(amt->net, &fl4); + if (IS_ERR(rt)) { + netdev_dbg(amt->dev, "no route to %pI4\n", &daddr->ip4); + return PTR_ERR(rt); + } + + udp_tunnel_xmit_skb(rt, sk, skb, + fl4.saddr, + fl4.daddr, + AMT_TOS, + ip4_dst_hoplimit(&rt->dst), + 0, + sport, + dport, + false, + false, + 0); + return 0; +} + static bool amt_send_membership_update(struct amt_dev *amt, struct sk_buff *skb, bool v6) @@ -1377,17 +1444,17 @@ static void amt_send_multicast_data(struct amt_dev *amt, * * No per-source state is read or created: the gateway echoes the nonce and * the keyed MAC in its Membership Update, where the MAC is recomputed, so - * everything this needs is passed by value. + * everything this needs is passed in: the nonce and the MAC by value, the + * endpoint as a pointer to the caller's copy. */ static bool amt_send_membership_query(struct amt_dev *amt, struct sk_buff *skb, - __be32 daddr, __be16 dport, + const union amt_addr *daddr, + __be16 dport, __be32 nonce, u64 mac, bool v6) { struct amt_header_membership_query *amtmq; - struct rtable *rt; - struct flowi4 fl4; struct sock *sk; int err; @@ -1396,23 +1463,11 @@ static bool amt_send_membership_query(struct amt_dev *amt, return true; err = skb_cow_head(skb, LL_RESERVED_SPACE(amt->dev) + sizeof(*amtmq) + - sizeof(struct iphdr) + sizeof(struct udphdr)); + amt_ip_hlen(amt) + sizeof(struct udphdr)); if (err) return true; skb_reset_inner_headers(skb); - memset(&fl4, 0, sizeof(struct flowi4)); - fl4.flowi4_oif = amt->stream_dev->ifindex; - fl4.daddr = daddr; - fl4.saddr = amt->local_ip; - fl4.flowi4_dscp = inet_dsfield_to_dscp(AMT_TOS); - fl4.flowi4_proto = IPPROTO_UDP; - rt = ip_route_output_key(amt->net, &fl4); - if (IS_ERR(rt)) { - netdev_dbg(amt->dev, "no route to %pI4\n", &daddr); - return true; - } - amtmq = skb_push(skb, sizeof(*amtmq)); amtmq->version = 0; amtmq->type = AMT_MSG_MEMBERSHIP_QUERY; @@ -1426,18 +1481,8 @@ static bool amt_send_membership_query(struct amt_dev *amt, skb_set_inner_protocol(skb, htons(ETH_P_IP)); else skb_set_inner_protocol(skb, htons(ETH_P_IPV6)); - udp_tunnel_xmit_skb(rt, sk, skb, - fl4.saddr, - fl4.daddr, - AMT_TOS, - ip4_dst_hoplimit(&rt->dst), - 0, - amt->relay_port, - dport, - false, - false, - 0); - return false; + return amt_udp_xmit(amt, sk, skb, daddr, amt->relay_port, dport, + inet_dsfield_to_dscp(AMT_TOS)); } static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) @@ -3265,10 +3310,10 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) mac = amt_relay_mac(&saddr, udph->source, amtrh->nonce, &key); if (!amtrh->p) - amt_send_igmp_gq(amt, saddr.ip4, udph->source, amtrh->nonce, + amt_send_igmp_gq(amt, &saddr, udph->source, amtrh->nonce, mac); else - amt_send_mld_gq(amt, saddr.ip4, udph->source, amtrh->nonce, + amt_send_mld_gq(amt, &saddr, udph->source, amtrh->nonce, mac); return false;