From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796185931; b=RzclfciUmHhsktYqAOZZhiWpV2xuPv9IbG0CTT8/SdBBBjZ1Xc33KtHkO//WLRwMMi+C rFGpUgJ6eWhNkxUJbzWwOeBlnaIlauVuzWZWpQY6I9XhvgN0BXLXnRbhyzhzSybBfNx03 31nwttOs99Dk/2P6lGpFkFeuAPuSKnk6wN90FSOjk4TK0nFC2pYeooakwvKG8uoHE0HA5 U3gvn1GRUGn9NVOyM7braWeB3WikkIi6/wV/zlTzk1D2UfQB7Q5a+mYtsgQ3vQ4jUtF7o OoDzcBeZGTydW3/dHhxdZztnaVR6ukUrI643TbbG7yEZdt0MGtPOiRNdHbxq9kNLcUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796185931; 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=/Crp93P1zBqQ92dAIDL8xrDda/o8z6zU/V9yszf/rq4=; b=vGoeznaPr9HfeQZMpRLO+FPj7Y8fQoRaKz8elDp8ZjBJF0ttE7NiHFaHN8pHTJMoqFv0 7b2v/gDbuYwAFJ5cWOEm9NygVBncyMSNQwKcXxRqm9mMgGa3tsGqxhmuhvAE4Nst8OS6x qfo2zMrZgXBhlBswtGrde7UkQ1zrvFNcCFVlG44uXdHibihFgX7KFIoV3iEhAIjAHn2gt itoLyImvmjD7XEtILMDD6DFHiTdD1WQHahTuEN1wN0gkd41CsH5vPZ8j27alvVCqP9Aem Sy7tGecK75GdDVGmoEAjYmRgNco2eHue5eE1n1NWLj2IH7a47TdjUzmLm5wm8F6bXdQ== 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=c+u0Pr84; arc=none smtp.remote-ip=74.125.82.169 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 0B205606A33E for ; Wed, 2 Dec 2026 04:32:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0B205606A33E 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=c+u0Pr84 Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-380c28f9e35so13250811eec.1 for ; Tue, 01 Dec 2026 20:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796185930; x=1796790730; 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=/Crp93P1zBqQ92dAIDL8xrDda/o8z6zU/V9yszf/rq4=; b=c+u0Pr84GQeTUTBaT8ZKmWHQqo71k+9v04dFqUREHg0YQBheRbLRip9tYycbDUQJAy UlyGoV1DbpByjd+Xy2EBdFYCyLtg8DI0+c0F3Qz9F+CbJSPPqBbFD8ne6gQ9LfJg1cvX d8I2Tl7vqopjGzrZsC7A7/UI8Ed0E1MWtyRWqnb0GEQlwKDWHNlzUkjJ9i0M7c+1jSlH 7a4xwXU/91yXS/VuCmmJvnq7xaKAvRWmHhzhkLdeMc/7l+RE6BuVKmFWNKjJYHUMSJb2 DysB4reF4msSngAqPGHLvFtLdBi3WxEhXJAjdAwYjaMLfwEsfw778f+AC143rhsUzZN9 VxsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796185930; x=1796790730; 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=/Crp93P1zBqQ92dAIDL8xrDda/o8z6zU/V9yszf/rq4=; b=KfPhJ/GlWi6OPYvo3zCYeZPKpvVjwax0F1OThrh/R1joJbXgCcsPDJNfarUv9Qdsxy zgk9JJJI+RBAIdiM249oCyH0fxBtEmvL6MrIDf6RPmNH9d9Ze6bCafjBkJHxapaVn0au RIwcI14KrUGBTLIvsBHcwvgVanYEUu9kipcyNjCjuxlFzJOifGCBxc9zpoZb+jQW1qaN GJNDRmmWu8QmI6andDvmC+ycvNO4zclCvJEENuq+4KeJm5LR5wqMdBXCAFMx87odxcEd VblWDBRcCmW8cJkPRJE9l4J3Ht3/e8kjbJvshtp0ElqfJLiGx6x1Edjyc955h3g1CsJQ Uqyw== X-Forwarded-Encrypted: i=1; AL+hErE5xjr/q+N7kv245ypKCeeAEAJo6XPAftewDwTXG63Pk4uYjji0YNsHMiT3XUorhuQLlYmAXfI=@vger.kernel.org X-Gm-Message-State: APuU4Z/r2slD50f+f5upx/xvs2a3LZzT/LK8hUkNO0H3D8CXOeuwF0dz 77UUDG9Ly9J6I33Sg8rPe1nq6X7VKI/l9qKiqWJ3bvgTE1OijY5S0DzyE3kknHqGdp8= X-Gm-Gg: AZFdTZfhfGBit91n0Mj7ZWH75P+HfOcVL0MC9yx7RM2JR+z1TR7Tm+ElO5cSugoYXiI sUJWLiBGR/X2XyZckkVerDRbi3ablTtngXrPbjZdTPb5K0zmZOn+ZtY+HT/0q3tQrVBjyWX0SPB AosyyPiFPrW/wgyB90q0mMSNgckkgEe6w7gI0Uc5WUD2FSM9SmWOhht/xD15V+NlXCdAsDlOpFh ykeKu1XnQxY/i2atwS5fqQhSfjWWJP11jb6WvcM6J0xa/9RibTPTiijbRdY+TJfrXSP6zt6Ezmy VBz9zKujZakqHhHh51nfV8e2RzwL+mVY5mmJZ20Fu3ggMn2HFYAxl1GLRYxxLC+r+YFehr+UEYW aaZaXDX5PyW6wqHhedKVnddgodnazUW0Huh+8d28x5NG127XK1HLQ7VOJgfd0IzGC6dvhJEYbs5 aWqRommL3MHGOEc523rhpCBzi/YcKjN28hgysT9B+4mC8wUmdlLMYDzRAMIogrrJbinnvFhneNp YSAO+MVYdSBKvsOO+M8SenyDQEXfPHysuQsnWNJ9rRMvEU7ohIIS+3BeK9sFCDfXvMBiBIPkuHQ eCU/hJHYkrV6zN0LpJr2sZib2CBHpDTFrQoX/RQiGGC3pRN8nc5xB5VdfBeQeBR5/OkoNIVDzwV xSkMgmrdSqZ2YwXfwqgFPBtTrGt8= X-Received: by 2002:a05:7300:1911:b0:386:ea18:7868 with SMTP id 5a478bee46e88-386ea187930mr24983896eec.2.1796185930067; Tue, 01 Dec 2026 20:32:10 -0800 (PST) Received: from devbox.ts.blockcast.net ([2602:f74d:1::32]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386d605c894sm54632028eec.2.2026.12.01.20.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 20:32:08 -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 , David Ahern , Ido Schimmel Subject: [PATCH net-next v6 04/12] amt: send the Membership Query over IPv6 Date: Wed, 2 Dec 2026 04:31:52 +0000 Message-ID: <20261202043200.286260-5-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202043200.286260-1-omar@blockcast.net> References: <20261202043200.286260-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 amt_send_membership_query() routes and sends only over IPv4. Move that step into amt_udp_xmit(), which takes an skb that carries the AMT message, a union amt_addr destination and the ports, and sends over the device's family: ip_route_output_key() and udp_tunnel_xmit_skb() for IPv4, amt_route6() and udp_tunnel6_xmit_skb() for IPv6, both with AMT_TOS. iptunnel_xmit() scrubs the skb but udp_tunnel6_xmit_skb() does not, so the IPv6 path calls skb_scrub_packet(); otherwise the inner packet's conntrack entry would stay on the outer one. The Query has none, the Multicast Data and Membership Update sent through this helper later do. amt_send_membership_query() sizes its headroom with amt_ip_hlen(), and the IPv4 route lookup now runs after the header push; on a route failure the caller still frees the skb. amt_send_igmp_gq() and amt_send_mld_gq() take the gateway's endpoint as a union amt_addr. The v6 argument still selects the inner protocol, independent of the outer family. amt_v6() is still false for every device, so the only effect is the order of the IPv4 route lookup. Assisted-by: LLM Signed-off-by: Omar Ramadan --- drivers/net/amt.c | 122 ++++++++++++++++++++++++++++++---------------- 1 file changed, 81 insertions(+), 41 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index bfdce6897..1f4914a63 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -96,6 +96,11 @@ static bool amt_v6(const struct amt_dev *amt) return IS_ENABLED(CONFIG_IPV6) && !ipv6_addr_any(&amt->local_ipv6); } +static unsigned int amt_ip_hlen(const struct amt_dev *amt) +{ + return amt_v6(amt) ? sizeof(struct ipv6hdr) : sizeof(struct iphdr); +} + static void amt_outer_saddr(const struct amt_dev *amt, const struct sk_buff *skb, union amt_addr *addr) { @@ -999,16 +1004,16 @@ 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(). +/* A Request is unauthenticated, so @daddr is the caller's copy of the + * endpoint and no tunnel state is touched; 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; @@ -1097,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; @@ -1114,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 @@ -1232,6 +1237,63 @@ static void amt_req_work(struct work_struct *work) msecs_to_jiffies(100)); } +/* Route and send an AMT message to @daddr over the device's family. Over + * IPv6 @dst may hold the route already looked up; it is consumed. + */ +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); + } + /* Unlike iptunnel_xmit(), udp_tunnel6_xmit_skb() does not scrub + * the skb. + */ + 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) @@ -1362,17 +1424,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; @@ -1381,23 +1443,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; @@ -1411,18 +1461,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) @@ -3241,10 +3281,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;