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=1796020981; b=E6KqaM3n2hzuKMmnTv+YPV2AzeP2xcbdSKvYYMrXdoS9kwtnBIqFzW5QzeUSP5LP3ghi pMbngBfx+BPQO5GUpXkLva9KJztZZO1GRX3dIAA+sUM05NbTUw/LUNLQzjJmq3fDnFFmm tQWmm9ziyxn03kG6gbO8kWvVfL4PTq7VwGOvaoXK2HIACeycV5rKB8ZZJbt6rRUz1XgFK VY9HzBBME3TL7iCa1wNm7V8v8nMp0lAxWBKsfNneRE8fbGqgbjDL1iPA+myaTgtxYeYOa ndRKaqp3eo6AY05mYklXwXzBd6M2Zu6mQn8+i/4HYpExs/3b/ac+WDkUufKc3RZd0Lg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796020981; 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=ehL7S+RxHTKFlB3NepB3H1z8JfvYkRyIp/Wyp1/ITuU=; b=dumSAnnCUnYinXZGn7/TkGtzPrjms5+wXqjEJ4amI4GTd9+DyYTLgBI0QRupDKw1JkM3 Ps8X7k6pZocyf9u9TxyzjTMLqd5nEcmey1RORQa4xhMhTSCPxJvFVAmKtoCiF1bW+dJHu Ud0zizq587ALN19HzgOXb2exnCaWJ072FW3Kp4O49zUAaf5D+vRTi3Op64XCrJixwVCkY ZJ8l2auNmZ+PTZ29r15uJqdLDvgMbFZq2MwdnwpLA011u4jnfkSQR/X7xk8j7DorCLrq9 u3r/5+/nqgevJfIJWvd6/jC2EBD/T3M0JW+CskebYNxPkqBCW/LnQrstni5oNJZUvYg== 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=SmQ90wVb; 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 248B860A260B for ; Mon, 30 Nov 2026 06:43:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 248B860A260B 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=SmQ90wVb Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-386b8f2f671so5823054eec.1 for ; Sun, 29 Nov 2026 22:43:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796020980; x=1796625780; 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=ehL7S+RxHTKFlB3NepB3H1z8JfvYkRyIp/Wyp1/ITuU=; b=SmQ90wVbQvRPJ3H16VFSwkNYb2ySMKlz2DwuSsRmWHLCiE4GU3VC0zHPVAZIio5p0r 8F4ZQgIIKr3NiaR+XKtkMd1gUiVfhLBA7iHbBTqmcaGg7WBlhuoK2M8rXwQcrL3c4eiE Zf8HnlmPEVjz6eIo8BOwPWUZ2o4anfpMhXn2s82CjzqXL7hQUmnftTiRnGeVpF8FXCci vOLlErRVBxSrsUte2Wr5cZNEZPhybP6SPmyichM2p5Ib5FXBLb21pOjf45fra3+9s87X g7CM9cBa6wB5vKcOddeLdc2HTQ1xWgkoSKbmOy0Huwb3Oa9agd9oiT/wj4AmdoB5wh/Q srGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796020980; x=1796625780; 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=ehL7S+RxHTKFlB3NepB3H1z8JfvYkRyIp/Wyp1/ITuU=; b=IYBeZ6Z8qzVkLez9BFI+1hdGxm6MwKzGH0c/nfpltPGuvp1DniTlV/dYFADiz1qWPP lGEGNmu6XkRNtv+7NcGBpLysqkO6JqH3khjRyETqia+X0iUf8SLhOPBrCbwZ8iYk/hn3 saCqOllBV+2N/uqthVPANrXvRHcgMXyCedJEft6w2Gy/q902uoGEmZHynhLR5EufmNUs opwFd0VAmy0flfJllVCiiO7p1B/Xjcqm7YRHRle606yOwoiaL++S3oYQ0pt1oHKzNx04 SmFTQoEwWCqvaM2HXPF3UAxgdcZpM99/zAUiet7JoH1LPUWASd3Lp7x2aKrpZAnLb9hj ddrg== X-Forwarded-Encrypted: i=1; AL+hErFOLEdrUoJ0AiegFGNsT0/osHlUe6JsgXKXIBYMrbZPQon0v3s4k8JFAdcq7jgTnXTKiFkxV891UN6dPfA=@vger.kernel.org X-Gm-Message-State: APuU4Z+DtYNFJUB60Xpy9QPrnqCDlBGRBHX8WSP4CZxF38m3J2405zXn zERIl6RN1jpmsOL2q1EULsJ0NwTDJrsnRuShuSH4/uGBdOq/qRi+GXwzJ1y+UW/Yyi4= X-Gm-Gg: AZFdTZeQrvIqTQ887P+HKuvbMKNWxLKv1xk0ERDyGjn/PxVvYgNA88dw+uGrN2WAxRF WfwGKKlz/+Xg6CNlV6H6JB/y49UefJzlbWvp8thMBcv9ioqcaKbDktx9hqx+ZYaltaMXCMFm9eD pppWHvLz5xzgmYSB7ynF5W8Zu4T1MrcG++40rluwspQpsWrC19S7M6+lAMSHA6i8a/458kc2bQp U6I5YXkNWRdMj14UzBaR0Fqh3n7M6t+ac7LKCzplhh5AKH13ozZqQgGlZI7U5bw0iwEiKljXqSR vuNbI0DfoD451MdZaYItSaKVDgO8XQat2zVOtyu/aLega25cGO37AzMAHS6JOQkVl1ZEHHLbfa7 uy4eWIHfGtBoCtMGhQUaoa4UTRL7WUvu5Q2j37Uhyd9iOkku/t+unSCIDTIH7PPbmPOaweNREYE NPwDl3B+K9bz29kSqwshQdtUWikDpFbB/q9RFB07YT1tNieir8GNIbh8Pwx6SPVxtWEnYB7LhU9 oWWmYwDuUQKqwXgeTnXDFAogx+waW48RR9DZCvbMdgEio3s/iQdMc7VIFFSZKg0n40ovRmclqN2 GP7mFYV09lsU270eUHdk8vX3WPKW2okKS2qTvxcy9VvXTLaIOCQmfP3zixKnLXiyMpIXfJ7MXM5 +wQbAEgDpxGsUR9xX3J+ilcK/hpM= X-Received: by 2002:a05:7300:f68e:b0:386:240c:19d6 with SMTP id 5a478bee46e88-386241b6d72mr28295305eec.6.1796020980187; Sun, 29 Nov 2026 22:43:00 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 22:42:59 -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 05/12] amt: forward multicast data over IPv6 Date: Mon, 30 Nov 2026 06:42:42 +0000 Message-ID: <20261130064249.1874523-6-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: linux-kernel@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_multicast_data() routes and transmits the relay's copy of a multicast packet only over IPv4, so an IPv6 relay could establish tunnels but not deliver traffic through them. Size the copy's headroom for the outer family and send it through amt_udp_xmit(), which already carries the Membership Query over either family. The IPv4 route lookup still sets no DSCP. A copy that cannot be sent is still freed, but it is now counted in tx_dropped, and one for which amt_udp_xmit() finds no route is freed with a drop reason; before, nothing recorded the drop, as amt_dev_xmit() returns NETDEV_TX_OK for the packet. The inner protocol stays independent of the outer family, so an IPv6 tunnel carries both IPv4 and IPv6 multicast. RFC 7450 s5.3.3.6.3.2 forbids a Fragment header on a Multicast Data message sent over IPv6, and s5.3.3.6.2.2 wants a payload that exceeds the tunnel MTU dropped and, if it came from an SSM source, a Packet Too Big sent to it. This series sends one to any IPv6 source. The device MTU is derived from the link MTU only, so a smaller path MTU to a gateway is found at the route. The scrub in amt_udp_xmit() clears ignore_df, so ip6_fragment() never adds a Fragment header, but on its own it drops such a packet and sends the Packet Too Big to the relay itself. amt_send_multicast_data() therefore routes first and compares the inner packet with the route's MTU less the outer headers and the AMT header. The device offers software GSO, so a GSO skb is checked per segment with skb_gso_validate_network_len(), before the tunnel offloads are set up. A payload that does not fit is dropped. The inner IPv6 packet may carry extension headers. ipv6_mc_check_mld() leaves the transport header just past the fixed header, also for a packet it rejects as not MLD, and the per-segment length of a GSO skb is taken from that offset, so amt_dev_xmit() puts the transport header of a data packet back before it is checked and sent, to the offset it had on entry. For a forwarded packet that is the receive path's: ip6_rcv_core() sets it just past the fixed header and ipv6_parse_hopopts() moves it past a Hop-by-Hop header, and nothing on the forwarding path moves it past another extension header. Those are then not counted in the per-segment length, here as in ip6_forward() and in ip6_finish_output_gso(), where ip6mr forwarding ends, which validate a GSO skb the same way. A route MTU below the outer headers gives a tunnel MTU of zero instead of a wrapped one: every payload is dropped, and none is sent a Packet Too Big. A multicast packet can match every tunnel, and an attacker can create tunnels, so the Packet Too Big is not sent per tunnel. Each failing tunnel only lowers a value, and amt_dev_xmit() sends one Packet Too Big through icmpv6_ndo_send(), as ip6_tunnel does, after it has walked all tunnels, reporting the smallest failing tunnel MTU. A tunnel MTU below IPV6_MIN_MTU is left out, as a source ignores a smaller Packet Too Big, so such a tunnel only drops the payload. The inner version is the v6 flag the caller already computed, not skb->protocol. The tunnel MTU follows the route's path MTU, which ICMPv6 Packet Too Big messages lower, as it does on every IPv6 UDP tunnel in the tree. RFC 7450 s5.3.3.6.1 and s6.1 ask a relay that adjusts the tunnel MTU dynamically to offer a way to turn that off. The IPv6 stack gives a tunnel no such way: udpv6_err() records the lowered MTU in a route exception before it looks up a socket, "mtu lock" does not stop it (IPv6 path MTU discovery is not optional, see __ip6_rt_update_pmtu()), and ip6_skb_dst_mtu() ignores the socket's pmtudisc inside a tunnel's transmit. This series does not add one. The route MTU never drops below IPV6_MIN_MTU, as a smaller Packet Too Big is ignored. A forged Packet Too Big, which anyone who can send ICMPv6 to the relay can aim at a gateway's address, therefore lowers the tunnel MTU to 1280 bytes less the 50 of the IPv6, UDP and AMT headers, 1230, until the route exception expires, 10 minutes by default. Every multicast payload above that, IPv4 or IPv6, is then dropped toward that gateway, and its source is told nothing, as 1230 is below the 1280 a Packet Too Big can ask for. That is what path MTU discovery does to an IPv6 UDP tunnel that must not fragment. skb_tunnel_check_pmtu() is not used: with reply false it only updates the route's PMTU and sends nothing. An IPv4 payload is dropped without an ICMP error, since icmp_send() does not answer multicast datagrams, and it is not fragmented before encapsulation as s5.3.3.6.2.1 asks for DF=0. The IPv4 tunnel does not do that either; it clears DF on the outer header instead. With this, every relay message has an IPv6 path: Discovery and Advertisement, Request and Membership Query, Membership Update and Multicast Data. Assisted-by: LLM Signed-off-by: Omar Ramadan --- drivers/net/amt.c | 145 +++++++++++++++++++++++++++++++++------------- 1 file changed, 104 insertions(+), 41 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 8da1e73b1..cfd8e0277 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -1254,26 +1254,55 @@ static void amt_req_work(struct work_struct *work) msecs_to_jiffies(100)); } +/* RFC 7450 s5.3.3.6: a Multicast Data message sent over IPv6 must not + * carry a Fragment header, so a payload larger than the tunnel MTU is + * dropped, and an IPv6 source is sent a Packet Too Big, unless the tunnel + * MTU is below IPV6_MIN_MTU, which a source would ignore. An IPv4 source is + * not told, as icmp_send() never answers a multicast datagram. The tunnel + * MTU follows the route's path MTU, as on every IPv6 UDP tunnel. + */ +static u32 amt_tmtu(const struct dst_entry *dst) +{ + u32 hlen = sizeof(struct ipv6hdr) + sizeof(struct udphdr) + + sizeof(struct amt_header_mcast_data); + u32 mtu = dst_mtu(dst); + + return mtu > hlen ? mtu - hlen : 0; +} + +/* True if @skb, the inner packet before encapsulation, or any segment of + * it, is larger than @tmtu. + */ +static bool amt_tmtu_exceeded(const struct sk_buff *skb, u32 tmtu) +{ + if (skb_is_gso(skb)) + return !skb_gso_validate_network_len(skb, tmtu); + return skb->len > tmtu; +} + /* 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. + * steers the IPv4 route lookup. Over IPv6 the caller may pass the route it + * already looked up in @dst, which is consumed; otherwise it is looked up + * here. */ 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) + __be16 sport, __be16 dport, dscp_t dscp, + struct dst_entry *dst) { 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); + if (!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 @@ -1374,26 +1403,60 @@ static bool amt_send_membership_update(struct amt_dev *amt, return false; } +/* Send the relay's copy of a multicast packet to one gateway. Over IPv6 a + * payload that does not fit the tunnel MTU is dropped, and *@ptb is lowered + * to that MTU, if it is at least IPV6_MIN_MTU, so that amt_dev_xmit() can + * send a single Packet Too Big to the source once it has walked every + * tunnel. It does so for an IPv6 source only, whatever the payload. + */ static void amt_send_multicast_data(struct amt_dev *amt, const struct sk_buff *oskb, struct amt_tunnel_list *tunnel, - bool v6) + bool v6, u32 *ptb) { struct amt_header_mcast_data *amtmd; + struct dst_entry *dst = NULL; struct sk_buff *skb; - struct iphdr *iph; - struct flowi4 fl4; - struct rtable *rt; struct sock *sk; + int err; sk = rcu_dereference_bh(amt->sk); if (!sk) return; - skb = skb_copy_expand(oskb, sizeof(*amtmd) + sizeof(*iph) + + if (amt_v6(amt)) { + u32 tmtu; + + dst = amt_route6(amt, sk, &amt->local_ipv6, &tunnel->addr.ip6, + amt->relay_port, tunnel->source_port); + if (IS_ERR(dst)) { + netdev_dbg(amt->dev, "no route to %pI6c\n", + &tunnel->addr.ip6); + DEV_STATS_INC(amt->dev, tx_dropped); + return; + } + + tmtu = amt_tmtu(dst); + if (amt_tmtu_exceeded(oskb, tmtu)) { + dst_release(dst); + /* A source ignores a Packet Too Big below + * IPV6_MIN_MTU, so a tunnel that small is only + * dropped for. + */ + if (tmtu >= IPV6_MIN_MTU && (!*ptb || tmtu < *ptb)) + *ptb = tmtu; + DEV_STATS_INC(amt->dev, tx_dropped); + return; + } + } + + skb = skb_copy_expand(oskb, sizeof(*amtmd) + amt_ip_hlen(amt) + sizeof(struct udphdr), 0, GFP_ATOMIC); - if (!skb) + if (!skb) { + dst_release(dst); + DEV_STATS_INC(amt->dev, tx_dropped); return; + } /* amt_dev_xmit() pulled the Ethernet header without moving the mac * header. The tunnelled payload has no link-layer header, so the @@ -1402,18 +1465,8 @@ static void amt_send_multicast_data(struct amt_dev *amt, skb_reset_mac_header(skb); skb_reset_inner_headers(skb); if (udp_tunnel_handle_offloads(skb, true)) { - kfree_skb(skb); - return; - } - - memset(&fl4, 0, sizeof(struct flowi4)); - fl4.flowi4_oif = amt->stream_dev->ifindex; - fl4.daddr = tunnel->addr.ip4; - fl4.saddr = amt->local_ip; - 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", &tunnel->addr.ip4); + dst_release(dst); + DEV_STATS_INC(amt->dev, tx_dropped); kfree_skb(skb); return; } @@ -1427,17 +1480,12 @@ static void amt_send_multicast_data(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, - tunnel->source_port, - false, - false, - 0); + err = amt_udp_xmit(amt, sk, skb, &tunnel->addr, amt->relay_port, + tunnel->source_port, 0, dst); + if (err) { + DEV_STATS_INC(amt->dev, tx_dropped); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_OUTNOROUTES); + } } /* Send a Membership Query in reply to an unauthenticated Request. @@ -1482,7 +1530,7 @@ static bool amt_send_membership_query(struct amt_dev *amt, else skb_set_inner_protocol(skb, htons(ETH_P_IPV6)); return amt_udp_xmit(amt, sk, skb, daddr, amt->relay_port, dport, - inet_dsfield_to_dscp(AMT_TOS)); + inet_dsfield_to_dscp(AMT_TOS), NULL); } static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) @@ -1500,6 +1548,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) struct iphdr *iph; bool data = false; bool v6 = false; + u32 ptb = 0; u32 hash; iph = ip_hdr(skb); @@ -1524,6 +1573,9 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) group.ip4 = ip_hdr(skb)->daddr; #if IS_ENABLED(CONFIG_IPV6) } else if (iph->version == 6) { + bool th_set = skb_transport_header_was_set(skb); + int th_off = th_set ? skb_transport_offset(skb) : 0; + ip6h = ipv6_hdr(skb); if (!ipv6_addr_is_multicast(&ip6h->daddr)) goto free; @@ -1540,6 +1592,15 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) } } else { data = true; + /* ipv6_mc_check_mld() set the transport header + * just past the fixed IPv6 header, even when + * extension headers follow, which would make the + * segments of a GSO skb look shorter than they + * are. Put it back to the offset it had on entry, + * which the forwarding path also relies on. + */ + if (th_set) + skb_set_transport_header(skb, th_off); } v6 = true; group.ip6 = ipv6_hdr(skb)->daddr; @@ -1593,8 +1654,10 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) } continue; found: - amt_send_multicast_data(amt, skb, tunnel, v6); + amt_send_multicast_data(amt, skb, tunnel, v6, &ptb); } + if (ptb && v6) + icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, ptb); } dev_kfree_skb(skb);