From: Omar Ramadan <omar@blockcast.net>
To: Taehee Yoo <ap420073@gmail.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Shuah Khan <shuah@kernel.org>
Cc: Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v2 04/12] amt: send the Membership Query over IPv6
Date: Wed, 25 Nov 2026 19:14:42 +0000 [thread overview]
Message-ID: <20261125191450.2497936-5-omar@blockcast.net> (raw)
In-Reply-To: <20261125191450.2497936-1-omar@blockcast.net>
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.
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.
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() now send directly through
amt_send_membership_query(), takes the IPv6 path. 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 <omar@blockcast.net>
---
drivers/net/amt.c | 118 +++++++++++++++++++++++++++++++---------------
1 file changed, 81 insertions(+), 37 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 38740e0ac..7e8219a0c 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)
@@ -997,7 +1003,8 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
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);
@@ -1005,8 +1012,8 @@ static bool amt_send_membership_query(struct amt_dev *amt,
* 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;
@@ -1095,8 +1102,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;
@@ -1112,8 +1119,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
@@ -1230,6 +1237,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)
@@ -1364,13 +1431,12 @@ static void amt_send_multicast_data(struct amt_dev *amt,
*/
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;
@@ -1379,23 +1445,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;
@@ -1409,18 +1463,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)
@@ -3246,10 +3290,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;
--
2.47.3
next prev parent reply other threads:[~2026-11-25 19:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 19:14 [PATCH net-next v2 00/12] amt: add an IPv6 outer transport Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 01/12] amt: create an AF_INET6 encapsulation socket for an IPv6 outer address Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 02/12] amt: send the Relay Advertisement over IPv6 Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 03/12] amt: key relay tunnels on a union amt_addr endpoint Omar Ramadan
2026-11-25 19:14 ` Omar Ramadan [this message]
2026-11-25 19:14 ` [PATCH net-next v2 05/12] amt: forward multicast data over IPv6 Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 06/12] amt: size the encapsulation headroom by the outer IP version Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 07/12] amt: send the AMT gateway control plane over IPv6 Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 08/12] amt: receive " Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 09/12] amt: add netlink attributes for an IPv6 outer transport Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 10/12] MAINTAINERS: amt: cover the amt headers and selftests Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 11/12] selftests: net: add amt_v6.sh for an IPv6 outer transport Omar Ramadan
2026-11-25 19:14 ` [PATCH net-next v2 12/12] selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes Omar Ramadan
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=20261125191450.2497936-5-omar@blockcast.net \
--to=omar@blockcast.net \
--cc=andrew+netdev@lunn.ch \
--cc=ap420073@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/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
all inboxes | Powered by JetHome®