amt: add an IPv6 outer transport
v2 cover amt: add an IPv6 outer transport
The amt driver runs AMT (RFC 7450) only over IPv4: the relay and the gateway bind one AF_INET UDP socket and every message is routed and sent with the IPv4 helpers. RFC 7450 defines the protocol over either IP version, with an IPv6 form of the Relay Advertisement, so a gateway on an IPv6-only access network cannot reach an amt relay today.
This series adds an IPv6 outer transport to both modes. The outer family is fixed when the link is created: an IPv6 local address (IFLA_AMT_LOCAL_IP6) selects IPv6, and the inner multicast family stays independent, so an IPv6 tunnel carries IGMP/IPv4 and MLD/IPv6 alike.
Use case, which Jakub asked about on v1: Blockcast runs amt relays and gateways to deliver multicast video over networks that do not carry multicast natively, and some of those access networks are IPv6-only. The gateway side has to reach a relay from such a network, and the relay has to answer it, so both ends need the IPv6 form.
Patches 1-5 convert the relay: the AF_INET6 socket, the IPv6 Relay Advertisement, tunnel state keyed on a union amt_addr, and the Membership Query, Membership Update and Multicast Data paths, which share one amt_udp_xmit() instead of IPv6 twins of each sender. Multicast Data over IPv6 is checked against the tunnel MTU and never fragmented. Patch 6 sizes headroom and MTU for the 40-byte outer header. Patches 7-8 convert the gateway; the learned IPv6 relay address is published under a seqlock because, unlike the IPv4 one, it cannot be stored in one access. Patch 9 adds the netlink attributes, last, so that no intermediate commit can create a half-working IPv6 device. Patch 10 adds the AMT headers and selftests to MAINTAINERS, and patches 11-12 add selftests. amt_v6.sh uses the same tools as amt.sh (smcroute, socat, nc) plus jq, and tcpdump for one check that it skips without it.
The series is based on net-next 24630ff92eff, which merged net with the six-patch "amt: relay tunnel lifetime, validation and request-path hardening" series (net v7). It depends on that series: the tunnel creation, MAC and per-source cap that patch 3 re-keys are the ones it introduced.
The IPv6 Relay Advertisement is sent from the address the Discovery was sent to, as RFC 7450 s5.1.2 requires, so a gateway can discover the relay through an anycast or secondary address. A Discovery sent to a multicast group, or from ::, is not answered, since neither can be used as an address. The IPv4 Advertisement has always been sent from local_ip, which breaks the same case for an IPv4 gateway. This series leaves that alone: it changes the behaviour of existing IPv4 relays and is not needed by the IPv6 code. The IPv4 control senders also look the route up with a zero TOS while the packet carries AMT_TOS, which is the mismatch that patch 2 avoids for IPv6; that is a possible separate fix for net.
The IPv6 socket is bound to the underlying link. That makes the IPv6 route lookups strict about the output interface, as the IPv4 ones already are, and keeps link-local peers on other links out of the tunnel table. An IPv6 gateway accepts a zero UDP checksum on Multicast Data only, as RFC 7450 s5.2.3.3 requires; a relay requires the checksum on everything.
The IPv6 tunnel MTU follows the route's path MTU, as on every IPv6 UDP tunnel in the tree. RFC 7450 s5.3.3.6.1 and s6.1 want a relay to offer a switch that turns dynamic tunnel MTU adjustment off. The IPv6 stack gives a tunnel no way to do that: it records every Packet Too Big in a route exception before it looks up the socket, and "mtu lock" does not apply to IPv6. So this series does not offer the switch. Patch 5 explains this in detail.
Received headers are handled as commit 3656a79f94c4 ("amt: re-read skb header pointers after every pull") requires. amt_rcv(), amt_request_handler() and amt_update_handler() copy the outer source address by value before any pull, or after the last one. The discovery and advertisement handlers take header pointers only after their last pskb_may_pull(), and the send paths never pull the received skb.
The iproute2 support is a separate iproute2-next patch:
https://lore.kernel.org/netdev/[email protected]/
The selftests skip when iproute2 or the kernel lacks the attributes.
IFLA_AMT_LOCAL_IP6, IFLA_AMT_DISCOVERY_IP6 and IFLA_AMT_REMOTE_IP6 are the next three values after IFLA_AMT_MAX_TUNNELS in this series. The net-next amt limits series appends IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES at the same position, so whichever of the two lands second renumbers its attributes after the other's.
Changes in v2 (netdev's Sashiko review of v1, and net v7):
- The base is net-next 24630ff92eff. The three net prerequisites of v1 are now in net, as v7 of the hardening series. v1's "amt: send the relay General Query directly" is not needed any more, and the GSO fix was done differently: the device still offers software GSO, so the tunnel MTU check in 5/12 is made per segment with skb_gso_validate_network_len() instead of assuming a single packet.
- v1 3/13 and 5/13 are one patch now (3/12). v7 made the Request handler stateless and moved tunnel creation to the authenticated Membership Update, so the endpoint key is carried through amt_tunnel_lookup(), amt_tunnel_get_or_create(), amt_update_tunnel() and the new amt_relay_mac(), which both handlers use for the MAC. The ICMPv6 Destination Unreachable for a full tunnel table is gone, as v7 drops such a Request silently.
- 2/12: route on AMT_TOS through the flow label (Medium on 4/13, Low on 2/13); count route and allocation failures with DEV_STATS_INC(); drop a Discovery from ::. A failure of ip6_local_out() is still not counted, as udp_tunnel6_xmit_skb() returns void and passing a device would add control messages to the tunnel's byte counters.
- 4/12: the Membership Query and the relay's General Query take the gateway endpoint as a union amt_addr, for v7's stateless Request.
- 5/12: at most one Packet Too Big per multicast packet (High on 6/13), not one per tunnel; the inner family comes from the parsed version, not skb->protocol (Low); a tunnel MTU below IPV6_MIN_MTU, which a source would ignore, only drops the payload.
- 7/12 (8/13): the message says that none of the new sender code can run yet and that the amt_send_membership_update() conversion changes no IPv4 behaviour (Low).
- 8/12 (9/13): an Advertisement is accepted only if its UDP length is that of the device's family (Low); the deferred Query check in amt_membership_query_handler() uses amt_from_relay(); the IPv4 half of the 0.0.0.0 fix is net v7 3/6 (Medium).
- 9/12 (10/13): the policy of the existing IPv4 attributes is net v7 4/6, so the hunk that refused a 16-byte value is dropped (Low).
- 11/12 (12/13): disc_answer() reports a harness failure separately, so the ff02::1 check cannot pass because the capture never ran (Medium); the script skips without CONFIG_IPV6 before creating any link (Low). CONFIG_IP_MROUTE is already in the net selftests config.
- Fixed by net v7 and inherited: the Update handler use-after-free (High, 5/13), the duplicate-tunnel race and the zero-key MAC (Medium, 3/13).
Omar Ramadan (12):
amt: create an AF_INET6 encapsulation socket for an IPv6 outer address
amt: send the Relay Advertisement over IPv6
amt: key relay tunnels on a union amt_addr endpoint
amt: send the Membership Query over IPv6
amt: forward multicast data over IPv6
amt: size the encapsulation headroom by the outer IP version
amt: send the AMT gateway control plane over IPv6
amt: receive the AMT gateway control plane over IPv6
amt: add netlink attributes for an IPv6 outer transport
MAINTAINERS: amt: cover the amt headers and selftests
selftests: net: add amt_v6.sh for an IPv6 outer transport
selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes
MAINTAINERS | 3 + drivers/net/amt.c | 861 ++++++++++++++++++----- include/net/amt.h | 60 +- include/uapi/linux/amt.h | 13 + tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/amt_gw_v6.sh | 207 ++++++ tools/testing/selftests/net/amt_v6.sh | 355 ++++++++++ 7 files changed, 1301 insertions(+), 200 deletions(-) create mode 100755 tools/testing/selftests/net/amt_gw_v6.sh create mode 100755 tools/testing/selftests/net/amt_v6.sh
base-commit: 24630ff92eff08500ec4772728d4b1fa08c28f47
Signature · 1 line
2.47.3
PATCH v2 1/12 amt: create an AF_INET6 encapsulation socket for an IPv6 outer address
The amt device binds one AF_INET UDP socket on the relay port, so a relay and its gateways can only talk AMT over IPv4. RFC 7450 defines the protocol over either IP version: the Relay Advertisement carries an IPv4 or an IPv6 relay address, and s5.2 selects the form from the IP version of the outer header, so an IPv6-only access network needs an IPv6 outer transport to reach the relay at all.
Add the outer IPv6 local address to struct amt_dev, and amt_v6(), which reports the device's outer family from it. amt_create_sock() binds an AF_INET6 socket for an IPv6 device. The socket sends and verifies the UDP checksum, which RFC 8200 s8.1 makes mandatory over IPv6, and it is V6ONLY, so that it does not also claim the IPv4 wildcard port, which an IPv4 amt device in the same netns may hold.
The socket is also bound to the underlying link, IFLA_AMT_LINK. The IPv4 paths pass that link as the output interface, and an IPv4 route lookup then only uses routes through it. An IPv6 lookup that has a source address, as every AMT send does, treats the output interface as a preference unless the socket is bound to a device, so without the binding the outer IPv6 traffic could leave through another link while the device's MTU and headroom are derived from this one. The binding also keeps packets that arrive on other links away from the socket. A link-local address is unique only on its link, and relay tunnels are keyed on the gateway's address, so two gateways on different links with the same link-local address would otherwise share a tunnel, and the replies would go out the wrong link.
The new socket also hands ICMPv6 errors to amt_err_lookup(). This relies on amt_parse_type() pulling the AMT header behind the transport header, as "amt: pull the AMT header behind the transport header in amt_parse_type()" in net makes it do, since on the error path skb->data points at the quoted IPv6 header.
Nothing sets local_ipv6 yet. The netlink attribute that does is added at the end of this series, once every path can use it, so there is no functional change here.
--- drivers/net/amt.c | 36 ++++++++++++++++++++++++++++++------ include/net/amt.h | 2 ++ 2 files changed, 32 insertions(+), 6 deletions(-)
drivers/net/amt.c +30 -6
@@ -90,6 +90,14 @@ static struct in6_addr mld2_all_node = MLD2_ALL_NODE_INIT;static struct mld2_grec mldv2_zero_grec;#endif +/* The outer transport family is fixed when the link is created: an IPv6 +* local address selects IPv6, otherwise the device runs over IPv4. +*/ +static bool amt_v6 (const struct amt_dev *amt) +{ +return IS_ENABLED (CONFIG_IPV6 ) && !ipv6_addr_any (&amt->local_ipv6); +} +static void __amt_source_gc_work (void ) {struct amt_source_node *snode;
@@ -3310,19 +3318,35 @@ static int amt_err_lookup(struct sock *sk, struct sk_buff *skb)return 0 ; } -static struct sock *amt_create_sock (struct net *net,__be16 port) +static struct sock *amt_create_sock (const struct amt_dev *amt) {struct udp_port_cfg udp_conf;struct socket *sock;int err;memset (&udp_conf,0 ,sizeof (udp_conf)); - udp_conf.family =AF_INET ; - udp_conf.local_ip.s_addr =htonl (INADDR_ANY ); +if (amt_v6 (amt)) { +/* Bound to :: by the memset, and to the underlying link: a +* bound socket makes every IPv6 route lookup strict about +* the output interface, as the IPv4 lookup is, and receives +* from that link only, where a link-local peer is unique. +* V6ONLY keeps the socket off the IPv4 wildcard, so an IPv4 +* amt device can use the same port in the netns. The UDP +* checksum is mandatory over IPv6. +*/ + udp_conf.family =AF_INET6 ; + udp_conf.bind_ifindex = amt->stream_dev->ifindex; + udp_conf.use_udp6_tx_checksums = true; + udp_conf.use_udp6_rx_checksums = true; + udp_conf.ipv6_v6only = true; + }else { + udp_conf.family =AF_INET ; + udp_conf.local_ip.s_addr =htonl (INADDR_ANY ); + } - udp_conf.local_udp_port = port; + udp_conf.local_udp_port = amt->relay_port; - err =udp_sock_create (net, &udp_conf, &sock); + err =udp_sock_create (amt->net, &udp_conf, &sock);if (err <0 )return ERR_PTR (err);
@@ -3334,7 +3358,7 @@ static int amt_socket_create(struct amt_dev *amt)struct udp_tunnel_sock_cfg tunnel_cfg;struct sock *sk; - sk =amt_create_sock (amt->net, amt->relay_port); + sk =amt_create_sock (amt);if (IS_ERR (sk))return PTR_ERR (sk);
include/net/amt.h +2 -0
@@ -361,6 +361,8 @@ struct amt_dev {__be16 gw_port;/* Outer local ip */ __be32 local_ip; +/* Outer local IPv6 address, :: unless the outer transport is IPv6 */ +struct in6_addr local_ipv6;/* Outer remote ip */ __be32 remote_ip;/* Outer discovery ip */
Signature · 1 line
2.47.3
PATCH v2 2/12 amt: send the Relay Advertisement over IPv6
In reply to Omar RamadanA gateway finds its relay with a Relay Discovery, and the relay answers with a Relay Advertisement carrying the address the gateway should use from then on. RFC 7450 s5.1.2 defines two forms of the Advertisement:
the same fixed header and nonce followed by either a 4-byte IPv4 or a 16-byte IPv6 relay address, and s5.2 selects the form from the IP version of the outer header rather than from a field in the message. An amt relay on an IPv6 outer transport therefore has to answer with the 24-byte IPv6 form.
Add struct amt_header_advertisement_v6 for that form and amt_send_advertisement_v6(), which fills it on the stack and sends it with a new amt_send_ctrl_v6() helper. The helper routes with ip6_dst_lookup_flow() through amt_route6(), which the later IPv6 senders share, and sends with udp_tunnel6_xmit_skb(), which builds the UDP and IPv6 headers and fills in the UDP checksum that RFC 8200 s8.1 makes mandatory over IPv6. Like the IPv4 control messages, it marks the skb TC_PRIO_CONTROL, uses AMT_TOS as the traffic class and passes no netdev, so control traffic stays out of the amt device's tunnel stats.
amt_discovery_handler() answers an IPv6 device's Discovery with the IPv6 form, sent back to the outer source of the Discovery. RFC 7450 s5.1.2 makes the source of the Advertisement the destination of the Discovery, the Relay Discovery Address, so amt_send_ctrl_v6() and amt_route6() take the source address from their caller. The socket is bound to ::, so a Discovery sent to an anycast or secondary address reaches the relay, and a gateway accepts only an Advertisement whose source is the address it sent the Discovery to; answering from local_ipv6 would leave such a gateway stuck in discovery. The relay address carried in the message stays local_ipv6. The same socket also receives a Discovery sent to a multicast group the host has joined, such as ff02::1, and a multicast address may not be a source (RFC 4291 s2.7), so a Discovery with a multicast destination is dropped rather than answered by every relay on the link with an invalid packet. The handler copies both outer addresses by value after its last pskb_may_pull(), and sending does not pull the received skb.
The IPv4 Advertisement has always been sent from local_ip, so an IPv4 gateway that discovers the relay through another of its addresses drops the reply. That is left as it is: changing the source of an existing IPv4 relay's replies is a fix of its own for net, and nothing in this series depends on it.
amt_v6() is still false for every device, so there is no functional change yet.
--- drivers/net/amt.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++ include/net/amt.h | 21 +++++++++ 2 files changed, 136 insertions(+)
drivers/net/amt.c +115 -0
@@ -708,6 +708,80 @@ static void __amt_update_relay_status(struct amt_tunnel_list *tunnel, tunnel->status = status; } +static struct dst_entry *amt_route6 (struct amt_dev *amt,struct sock *sk, +const struct in6_addr *saddr, +const struct in6_addr *daddr, +__be16 sport,__be16 dport) +{ +struct flowi6 fl6; + +memset (&fl6,0 ,sizeof (fl6)); + fl6.flowi6_oif = amt->stream_dev->ifindex; + fl6.flowi6_proto =IPPROTO_UDP ; + fl6.daddr = *daddr; + fl6.saddr = *saddr; + fl6.fl6_dport = dport; + fl6.fl6_sport = sport; +/* The packet carries AMT_TOS, so route on it too: a policy rule +* that matches the DSCP must see the same value. +*/ + fl6.flowlabel =ip6_make_flowinfo (AMT_TOS ,0 ); + +return ip6_dst_lookup_flow (amt->net, sk, &fl6,NULL ); +} + +/* Send an AMT control message over the IPv6 outer transport from @saddr. +* udp_tunnel6_xmit_skb() adds the UDP and IPv6 headers, including the UDP +* checksum that IPv6 requires. Returns 0 once the message is handed to the +* IPv6 stack. +*/ +static int amt_send_ctrl_v6 (struct amt_dev *amt,const struct in6_addr *saddr, +const struct in6_addr *daddr, +__be16 sport,__be16 dport, +const void *msg,unsigned int len) +{ +struct dst_entry *dst; +struct sk_buff *skb; +struct sock *sk; +int hlen, err; + +rcu_read_lock (); + sk =rcu_dereference (amt->sk); +if (!sk || !netif_running (amt->stream_dev) || + !netif_running (amt->dev)) { + err = -ENETDOWN ; + goto out; + } + + dst =amt_route6 (amt, sk, saddr, daddr, sport, dport); +if (IS_ERR (dst)) { +DEV_STATS_INC (amt->dev, tx_errors); + err =PTR_ERR (dst); + goto out; + } + + hlen =LL_RESERVED_SPACE (amt->dev) +sizeof (struct ipv6hdr ) + +sizeof (struct udphdr ); + skb =netdev_alloc_skb_ip_align (amt->dev, hlen + len + + amt->dev->needed_tailroom); +if (!skb) { +dst_release (dst); +DEV_STATS_INC (amt->dev, tx_errors); + err = -ENOMEM ; + goto out; + } + +skb_reserve (skb, hlen); +skb_put_data (skb, msg, len); + skb->priority =TC_PRIO_CONTROL ; +udp_tunnel6_xmit_skb (dst, sk, skb,NULL , saddr, daddr,AMT_TOS , +ip6_dst_hoplimit (dst),0 , sport, dport, false,0 ); + err =0 ; +out: +rcu_read_unlock (); +return err; +} +static void amt_send_discovery (struct amt_dev *amt) {struct amt_header_discovery *amtd;
@@ -3010,6 +3084,24 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,rcu_read_unlock (); } +/* The IPv6 form of amt_send_advertisement(), carrying the relay's IPv6 +* address. It is sent from @saddr, the address the Discovery was sent to. +*/ +static void amt_send_advertisement_v6 (struct amt_dev *amt,__be32 nonce, +const struct in6_addr *saddr, +const struct in6_addr *daddr, +__be16 dport) +{ +struct amt_header_advertisement_v6 amta = { + .type =AMT_MSG_ADVERTISEMENT , + .nonce = nonce, + .ip6 = amt->local_ipv6, + }; + +amt_send_ctrl_v6 (amt, saddr, daddr, amt->relay_port, dport, + &amta,sizeof (amta)); +} +static bool amt_discovery_handler (struct amt_dev *amt,struct sk_buff *skb) {struct amt_header_discovery *amtd;
@@ -3026,6 +3118,29 @@ static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb)if (amtd->reserved || amtd->version)return true; +/* The Advertisement takes the form of the outer IP version, and +* RFC 7450 s5.1.2 sources it from the address the Discovery was +* sent to, which may be an anycast Relay Discovery Address rather +* than local_ipv6. +*/ +if (amt_v6 (amt)) { +struct in6_addr saddr =ipv6_hdr (skb)->saddr; +struct in6_addr daddr =ipv6_hdr (skb)->daddr; + +/* The socket bound to :: also receives a Discovery sent to +* a group, and a multicast address can never be a source +* (RFC 4291 s2.7), so such a Discovery is not answered. Nor +* is one from ::, which has nowhere to be sent. +*/ +if (ipv6_addr_is_multicast (&daddr) || +ipv6_addr_any (&saddr)) +return true; + +amt_send_advertisement_v6 (amt, amtd->nonce, &daddr, &saddr, + udph->source); +return false; + } +amt_send_advertisement (amt, amtd->nonce, iph->saddr, udph->source);return false;
include/net/amt.h +21 -0
@@ -133,6 +133,27 @@ struct amt_header_advertisement {__be32 ip4; } __packed; +/* The IPv6 form of the Relay Advertisement (RFC 7450 s5.1.2): the same +* header and nonce, followed by a 16-byte relay address. s5.2 selects the +* form from the IP version of the outer header, not from a field in the +* message, so it is a type of its own. +*/ +struct amt_header_advertisement_v6 { +#if defined(__LITTLE_ENDIAN_BITFIELD) +u32 type:4 , + version:4 , + reserved:24 ; +#elif defined(__BIG_ENDIAN_BITFIELD) +u32 version:4 , + type:4 , + reserved:24 ; +#else +#error "Please fix <asm/byteorder.h>" +#endif +__be32 nonce; +struct in6_addr ip6; +} __packed; +struct amt_header_request {#if defined(__LITTLE_ENDIAN_BITFIELD) u32 type:4,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v2 02/12] amt: send the Relay Advertisement over IPv6
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The IPv6 control-message helper does not count send failures that happen after the packet is handed to the IPv6 stack.
--
amt: send the Relay Advertisement over IPv6
This patch adds the IPv6 form of the AMT Relay Advertisement (struct amt_header_advertisement_v6) and a new amt_send_ctrl_v6() helper. The helper routes with ip6_dst_lookup_flow() and sends with udp_tunnel6_xmit_skb(). amt_discovery_handler() now answers a Discovery on an IPv6 device with this form, sourced from the Discovery's destination address.
Quoted 4 lines
drivers/net/amt.c +0
-0
[ ... ]
Quoted 10 lines
drivers/net/amt.c +10
-0+/* Send an AMT control message over the IPv6 outer transport from @saddr. +* udp_tunnel6_xmit_skb() adds the UDP and IPv6 headers, including the UDP +* checksum that IPv6 requires. Returns 0 once the message is handed to the +* IPv6 stack. +*/ +static int amt_send_ctrl_v6 (struct amt_dev *amt,const struct in6_addr *saddr, +const struct in6_addr *daddr, +__be16 sport,__be16 dport, +const void *msg,unsigned int len) +{
[ ... ]
drivers/net/amt.c static void __amt_update_relay_status(struct amt_tunnel_list *tunnel, · line 779
Quoted 6 lines
drivers/net/amt.c +6
-0+skb_reserve (skb, hlen); +skb_put_data (skb, msg, len); + skb->priority =TC_PRIO_CONTROL ; +udp_tunnel6_xmit_skb (dst, sk, skb,NULL , saddr, daddr,AMT_TOS , +ip6_dst_hoplimit (dst),0 , sport, dport, false,0 ); + err =0 ;
[Severity: Low]
If the packet is dropped after it is handed to the IPv6 stack, should that drop show up in amt->dev tx_errors the way it does for the IPv4 control messages?
udp_tunnel6_xmit_skb() returns void, and ip6tunnel_xmit() only looks at the ip6_local_out() result when a netdev is passed:
include/net/ip6_tunnel.h:ip6tunnel_xmit() {
...
err = ip6_local_out(skb_dst_dev_net(skb), sk, skb);
if (dev) {
if (unlikely(net_xmit_eval(err)))
pkt_len = -1;
iptunnel_xmit_stats(dev, pkt_len);
}
...
}Since dev is NULL here, a drop by netfilter, neighbour resolution or the qdisc is never counted. The IPv4 senders, including amt_send_advertisement(), do count it:
err = ip_local_out(amt->net, sk, skb); if (unlikely(net_xmit_eval(err))) DEV_STATS_INC(amt->dev, tx_errors);
Route lookup and allocation failures in amt_send_ctrl_v6() still increment tx_errors. So the IPv4 and IPv6 paths differ only for drops after the handoff.
The commit message says:
Like the IPv4 control messages, it marks the
skb TC_PRIO_CONTROL, uses AMT_TOS as the traffic class and passes no netdev, so control traffic stays out of the amt device's tunnel stats.
Passing NULL also hides these post-handoff errors, and the message doesn't mention that.
At the end of the series the same udp_tunnel6_xmit_skb(..., NULL, ...); err = 0; sequence is still present. That means every later IPv6 control sender that uses this helper has the same gap.
Quoted 4 lines
drivers/net/amt.c +4
-0+out: +rcu_read_unlock (); +return err; +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125191450.2497936-1-omar%40blockcast.net
PATCH v2 3/12 amt: key relay tunnels on a union amt_addr endpoint
In reply to Omar RamadanA relay keeps one struct amt_tunnel_list per gateway endpoint and finds it by the gateway's IPv4 address, stored as __be32 ip4 and taken from ip_hdr(skb)->saddr, together with its UDP source port. On an IPv6 outer transport that reads the traffic class and flow label of the IPv6 header as an address, and the field cannot hold the gateway's address anyway.
Store the endpoint as a union amt_addr, which group and source nodes already use, and move the union above struct amt_tunnel_list so the tunnel can embed it. Its ip6 member is no longer under CONFIG_IPV6, so code that only copies, compares or prints an endpoint compiles without an #if and relies on amt_v6() being false. A kernel without IPv6 pays 12 bytes per group and source node, which it already zeroes. The tunnel needs no family of its own: the relay's socket is bound to one family, so every tunnel has the device's family, which amt_v6() reports.
amt_outer_saddr() copies the outer source address of a received message by value into a zeroed union amt_addr. amt_request_handler() and amt_update_handler() take that snapshot on entry, before pskb_may_pull() and iptunnel_pull_header() can reallocate the header, and pass it to amt_tunnel_lookup(), amt_tunnel_get_or_create() and amt_update_tunnel(). They match endpoints with the existing amt_addr_equal(); the union is zero-padded for IPv4, so one memcmp() serves both families. The per-source tunnel count in amt_request_handler() and amt_tunnel_get_or_create() compares the same way.
The Membership Update MAC becomes amt_relay_mac(), one siphash() over the packed {address, port, nonce} tuple instead of siphash_3u32() over the IPv4 address. The Request and Update handlers both compute it with the helper. Only the relay computes and checks the MAC; the gateway echoes it verbatim, so the different IPv4 value is not visible on the wire.
The IPv4 senders and the relay status debug message are converted to tunnel->addr.ip4, and the debug message prints an IPv6 endpoint with %pI6c. amt_v6() is still false for every device, so there is no functional change.
--- drivers/net/amt.c | 89 ++++++++++++++++++++++++++++++++--------------- include/net/amt.h | 20 ++++++----- 2 files changed, 72 insertions(+), 37 deletions(-)
drivers/net/amt.c +60 -29
@@ -98,6 +98,32 @@ static bool amt_v6(const struct amt_dev *amt)return IS_ENABLED (CONFIG_IPV6 ) && !ipv6_addr_any (&amt->local_ipv6); } +/* 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) +{ +memset (addr,0 ,sizeof (*addr)); +if (amt_v6 (amt)) + addr->ip6 =ipv6_hdr (skb)->saddr; +else + addr->ip4 =ip_hdr (skb)->saddr; +} + +/* The Membership Update MAC for a gateway endpoint. The gateway only echoes +* it, so one siphash() over the zero-padded endpoint serves both families. +*/ +static u64 amt_relay_mac (const union amt_addr *addr,__be16 port,__be32 nonce, +const siphash_key_t *key) +{ +struct { +union amt_addr addr; +__be16 port; +__be32 nonce; + } __packed in = { .addr = *addr, .port = port, .nonce = nonce }; + +return siphash (&in,sizeof (in), key) >>16 ; +} +static void __amt_source_gc_work (void ) {struct amt_source_node *snode;
@@ -701,10 +727,16 @@ static void __amt_update_relay_status(struct amt_tunnel_list *tunnel, {if (validate && tunnel->status >= status)return ; -netdev_dbg (tunnel->amt->dev, -"Update Tunnel(IP = %pI4, PORT = %u) status %s -> %s" , - &tunnel->ip4,ntohs (tunnel->source_port), - status_str[tunnel->status], status_str[status]); +if (amt_v6 (tunnel->amt)) +netdev_dbg (tunnel->amt->dev, +"Update Tunnel(IP = %pI6c, PORT = %u) status %s -> %s" , + &tunnel->addr.ip6,ntohs (tunnel->source_port), + status_str[tunnel->status], status_str[status]); +else +netdev_dbg (tunnel->amt->dev, +"Update Tunnel(IP = %pI4, PORT = %u) status %s -> %s" , + &tunnel->addr.ip4,ntohs (tunnel->source_port), + status_str[tunnel->status], status_str[status]); tunnel->status = status; }
@@ -1292,12 +1324,12 @@ static void amt_send_multicast_data(struct amt_dev *amt,memset (&fl4,0 ,sizeof (struct flowi4 )); fl4.flowi4_oif = amt->stream_dev->ifindex; - fl4.daddr = tunnel->ip4; + 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->ip4); +netdev_dbg (amt->dev,"no route to %pI4\n" , &tunnel->addr.ip4);kfree_skb (skb);return ; }
@@ -2728,12 +2760,14 @@ static bool amt_membership_query_handler(struct amt_dev *amt,* race with amt_tunnel_expire() creates the replacement. */ static struct amt_tunnel_list *amt_tunnel_lookup (struct amt_dev *amt, -__be32 saddr,__be16 sport) +union amt_addr *saddr, +__be16 sport) {struct amt_tunnel_list *tunnel;list_for_each_entry_rcu (tunnel, &amt->tunnel_list, list) { -if (tunnel->ip4 == saddr && tunnel->source_port == sport && +if (amt_addr_equal (&tunnel->addr, saddr) && + tunnel->source_port == sport && !READ_ONCE (tunnel->dead))return tunnel; }
@@ -2759,7 +2793,7 @@ static u32 amt_max_tunnels_per_src(const struct amt_dev *amt)* verified source address may hold. */ static struct amt_tunnel_list *amt_tunnel_get_or_create (struct amt_dev *amt, -__be32 saddr, +union amt_addr *saddr,__be16 sport) {struct amt_tunnel_list *tunnel;
@@ -2779,7 +2813,8 @@ static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,* against its address. */ list_for_each_entry (tunnel, &amt->tunnel_list, list) { -if (tunnel->ip4 != saddr ||READ_ONCE (tunnel->dead)) +if (!amt_addr_equal (&tunnel->addr, saddr) || +READ_ONCE (tunnel->dead))continue ;if (tunnel->source_port == sport) {spin_unlock_bh (&amt->lock);
@@ -2808,7 +2843,7 @@ static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt, } tunnel->source_port = sport; - tunnel->ip4 = saddr; + tunnel->addr = *saddr; tunnel->amt = amt;spin_lock_init (&tunnel->lock);for (i =0 ; i < amt->hash_buckets; i++)
@@ -2838,7 +2873,7 @@ static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,* second amt_tunnel_get_or_create() call, which creates its replacement. */ static bool amt_update_tunnel (struct amt_dev *amt,struct sk_buff *skb, -__be32 saddr,__be16 sport,bool v6) +union amt_addr *saddr,__be16 sport,bool v6) {struct amt_tunnel_list *tunnel;int i;
@@ -2878,12 +2913,13 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)struct ethhdr *eth;struct iphdr *iph;unsigned int seq; +union amt_addr saddr;u64 response_mac; -__be32 saddr;__be32 nonce;__be16 sport; - saddr =ip_hdr (skb)->saddr; +/* Snapshot the outer source before any pull can move the header. */ +amt_outer_saddr (amt, skb, &saddr); hdr_size =sizeof (*amtmu) +sizeof (struct udphdr );if (!pskb_may_pull (skb, hdr_size))
@@ -2910,10 +2946,7 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb) }while (read_seqcount_retry (&amt->key_seq, seq));for (i =0 ; i <ARRAY_SIZE (key); i++) { -u64 mac =siphash_3u32 ((__force u32 )saddr, - (__force u32 )sport, - (__force u32 )nonce, - &key[i]) >>16 ; +u64 mac =amt_relay_mac (&saddr, sport, nonce, &key[i]);if (response_mac == mac) { verified = true;
@@ -2947,7 +2980,7 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)return true; } -if (!amt_update_tunnel (amt, skb, saddr, sport, false)) +if (!amt_update_tunnel (amt, skb, &saddr, sport, false))return true;skb_push (skb,sizeof (struct ethhdr ));
@@ -2966,7 +2999,7 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)return true; } -if (!amt_update_tunnel (amt, skb, saddr, sport, true)) +if (!amt_update_tunnel (amt, skb, &saddr, sport, true))return true;skb_push (skb,sizeof (struct ethhdr ));
@@ -3165,8 +3198,8 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)struct amt_header_request *amtrh;struct amt_tunnel_list *tunnel;bool full, have = false; +union amt_addr saddr;struct udphdr *udph; -struct iphdr *iph;siphash_key_t key;u32 per_src =0 ;u64 mac;
@@ -3174,7 +3207,7 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)if (!pskb_may_pull (skb,sizeof (*udph) +sizeof (*amtrh)))return true; - iph =ip_hdr (skb); +amt_outer_saddr (amt, skb, &saddr); udph =udp_hdr (skb); amtrh = (struct amt_header_request *)(udp_hdr (skb) +1 );
@@ -3198,7 +3231,8 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)*/ rcu_read_lock ();list_for_each_entry_rcu (tunnel, &amt->tunnel_list, list) { -if (tunnel->ip4 != iph->saddr ||READ_ONCE (tunnel->dead)) +if (!amt_addr_equal (&tunnel->addr, &saddr) || +READ_ONCE (tunnel->dead))continue ; per_src++;if (tunnel->source_port == udph->source)
@@ -3210,15 +3244,12 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)if (!have && (full || per_src >=amt_max_tunnels_per_src (amt)))return true; - mac =siphash_3u32 ((__force u32 )iph->saddr, - (__force u32 )udph->source, - (__force u32 )amtrh->nonce, - &key) >>16 ; + mac =amt_relay_mac (&saddr, udph->source, amtrh->nonce, &key);if (!amtrh->p) -amt_send_igmp_gq (amt, iph->saddr, udph->source, amtrh->nonce, +amt_send_igmp_gq (amt, saddr.ip4, udph->source, amtrh->nonce, mac);else -amt_send_mld_gq (amt, iph->saddr, udph->source, amtrh->nonce, +amt_send_mld_gq (amt, saddr.ip4, udph->source, amtrh->nonce, mac);return false;
include/net/amt.h +12 -8
@@ -252,6 +252,14 @@ struct amt_relay_headers { }; } __packed; +/* ip6 is present without CONFIG_IPV6 too, so that code which only copies +* or compares addresses needs no #if; amt_v6() is then false. +*/ +union amt_addr { +__be32 ip4; +struct in6_addr ip6; +}; +struct amt_tunnel_list {struct list_head list;/* Protect All resources under an amt_tunne_list */
@@ -273,18 +281,14 @@ struct amt_tunnel_list {*/ bool dead;__be16 source_port; -__be32 ip4; +/* Outer source address of the gateway endpoint, in the device's +* outer family (amt_v6()). +*/ +union amt_addr addr;struct rcu_head rcu;struct hlist_head groups[]; }; -union amt_addr { -__be32 ip4; -#if IS_ENABLED (CONFIG_IPV6 ) -struct in6_addr ip6; -#endif -}; -/* RFC 3810 * * When the router is in EXCLUDE mode, the router state is represented
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v2 03/12] amt: key relay tunnels on a union amt_addr endpoint
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] This patch makes the per-source tunnel cap compare the full 16-byte union amt_addr endpoint with memcmp() (amt_addr_equal()).
- [Low] The commit message says 'amt_request_handler() and amt_update_handler() take that snapshot on entry, before…
--
amt: key relay tunnels on a union amt_addr endpoint
This commit stores the relay tunnel endpoint as a union amt_addr instead of a __be32 and matches endpoints with amt_addr_equal(). It adds amt_outer_saddr() to snapshot the outer source address and amt_relay_mac() to compute the Membership Update MAC over the full endpoint.
Quoted 4 lines
amt_outer_saddr()copies the outer source address of a received message by value into a zeroed unionamt_addr.amt_request_handler()andamt_update_handler()take that snapshot on entry, beforepskb_may_pull()andiptunnel_pull_header()can reallocate the header,
[Severity: Low]
Is this description accurate for amt_request_handler()?
It holds for amt_update_handler(), where amt_outer_saddr() runs before both pskb_may_pull() and iptunnel_pull_header().
In amt_request_handler(), though, the snapshot is taken after the function's only pskb_may_pull(), and that handler never calls iptunnel_pull_header():
if (!pskb_may_pull(skb, sizeof(*udph) + sizeof(*amtrh))) return true; amt_outer_saddr(amt, skb, &saddr);
The code itself looks fine. ip_hdr() and ipv6_hdr() are derived again after the pull, and nothing pulls after the snapshot.
Could the commit message be changed to describe the ordering in amt_request_handler() correctly?
Quoted 4 lines
drivers/net/amt.c +0
-0
[ ... ]
Quoted 10 lines
drivers/net/amt.c +2
-1@@ -3198,7 +3231,8 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)*/ rcu_read_lock ();list_for_each_entry_rcu (tunnel, &amt->tunnel_list, list) { -if (tunnel->ip4 != iph->saddr ||READ_ONCE (tunnel->dead)) +if (!amt_addr_equal (&tunnel->addr, &saddr) || +READ_ONCE (tunnel->dead))continue ; per_src++;if (tunnel->source_port == udph->source)
[ ... ]
drivers/net/amt.c static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) · line 3246
Quoted 4 lines
drivers/net/amt.c +0
-0@@ -3210,15 +3244,12 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)if (!have && (full || per_src >=amt_max_tunnels_per_src (amt)))return true;
[Severity: Medium]
Does an exact 16-byte compare still make the per-source cap work on an IPv6 relay?
amt_tunnel_get_or_create() uses the same exact match before it allocates a tunnel:
list_for_each_entry(tunnel, &amt->tunnel_list, list) {
if (!amt_addr_equal(&tunnel->addr, saddr) ||
READ_ONCE(tunnel->dead))
continue;
...
if (amt->nr_tunnels >= amt->max_tunnels ||
per_src >= amt_max_tunnels_per_src(amt)) {amt_max_tunnels_per_src() caps the count at clamp(max_tunnels / 8, 1, AMT_MAX_TUNNELS_PER_SRC). Its comment says it limits "the tunnels one verified source address may hold".
On IPv6 this counts per /128. The MAC return-routability check only shows that the sender can receive at one /128. An ordinary host usually has at least a /64 routed to it (SLAAC or prefix delegation).
The defaults are a max_tunnels of 128 and 16 tunnels per source. Could one host run Request -> Query -> Update from eight addresses in its /64, fill the table, and keep it full by refreshing last_seen? After that, full would be true here and every legitimate gateway would be refused a Query. Over IPv4 the same attack needs eight separate IPv4 addresses.
This can't be reached at this commit, since amt_v6() is false. It becomes reachable later in the series, when "amt: add netlink attributes for an IPv6 outer transport" adds IFLA_AMT_LOCAL_IP6.
The selftest in "selftests: net: add amt_v6.sh for an IPv6 outer transport" only checks that two gateways in the same /64 are kept apart.
The commit message only says that the per-source count "compares the same way".
Would counting per /64 for IPv6 (or per a configurable prefix) keep the cap doing its job? The cap allows up to 16 tunnels per source, so separate gateways in one /64 would still be kept apart.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125191450.2497936-1-omar%40blockcast.net
PATCH v2 4/12 amt: send the Membership Query over IPv6
In reply to Omar RamadanAfter 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.
--- drivers/net/amt.c | 118 +++++++++++++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 37 deletions(-)
drivers/net/amt.c +81 -37
@@ -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 )); elseskb_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;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v2 04/12] amt: send the Membership Query over IPv6
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] This patch changes daddr in amt_send_membership_query() (drivers/net/amt.c) from __be32 daddr to `const union amt_addr…
--
amt: send the Membership Query over IPv6
This moves the routing and transmit step of amt_send_membership_query() into a new amt_udp_xmit() helper. The helper sends over IPv4 or IPv6 depending on the device's outer family. amt_send_igmp_gq(), amt_send_mld_gq() and amt_send_membership_query() now take the gateway's endpoint as a union amt_addr pointer.
Quoted 4 lines
drivers/net/amt.c +0
-0
[ ... ]
drivers/net/amt.c static void amt_send_multicast_data(struct amt_dev *amt, · line 1438
Quoted 10 lines
drivers/net/amt.c +2
-1@@ -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) {
[Severity: Low]
This isn't a bug, but should the comment above amt_send_membership_query() be updated as well? It still says:
/* Send a Membership Query in reply to an unauthenticated Request.
*
* 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.
*/
With this change, daddr is passed by reference. It points to the stack variable saddr in amt_request_handler(), and reaches this function through amt_send_igmp_gq() and amt_send_mld_gq():
amt_send_igmp_gq(amt, &saddr, udph->source, amtrh->nonce, mac);
The first half of the comment, that no per-source state is read or created, still holds. Only the "passed by value" part no longer matches the new signature.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125191450.2497936-1-omar%40blockcast.net
PATCH v2 5/12 amt: forward multicast data over IPv6
In reply to Omar Ramadanamt_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 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 an IPv6 payload that exceeds the tunnel MTU dropped with a Packet Too Big to its 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.
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, so a forged Packet Too Big can at most lower the tunnel MTU to 1280 bytes less the outer headers; an IPv6 payload between that and 1280 bytes is then undeliverable.
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.
--- drivers/net/amt.c | 126 +++++++++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 41 deletions(-)
drivers/net/amt.c +85 -41
@@ -1237,26 +1237,51 @@ 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. 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) +{ +return dst_mtu (dst) -sizeof (struct ipv6hdr ) -sizeof (struct udphdr ) - +sizeof (struct amt_header_mcast_data ); +} + +/* 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
@@ -1357,26 +1382,58 @@ 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 so that amt_dev_xmit() can send a single Packet Too Big to +* the source once it has walked every tunnel. +*/ 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);return ; + }/* amt_dev_xmit() pulled the Ethernet header without moving the mac * header. The tunnelled payload has no link-layer header, so the
@@ -1385,18 +1442,7 @@ 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);kfree_skb (skb);return ; }
@@ -1410,17 +1456,12 @@ static void amt_send_multicast_data(struct amt_dev *amt,skb_set_inner_protocol (skb,htons (ETH_P_IP )); elseskb_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.
@@ -1464,7 +1505,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)
@@ -1482,6 +1523,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);
@@ -1575,8 +1617,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);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v2 05/12] amt: forward multicast data over IPv6
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] When the outer transport is IPv6, amt_tmtu_exceeded() (drivers/net/amt.c:1255) checks a GSO inner IPv6 packet with…
- [Low] amt_tmtu() (drivers/net/amt.c:1246) computes dst_mtu(dst) - sizeof(struct ipv6hdr) - sizeof(struct udphdr) - sizeof(struct…
--
amt: forward multicast data over IPv6
This patch lets an IPv6 relay send Multicast Data by routing the copy through amt_udp_xmit() for either outer family. Over IPv6 it routes first and drops a payload that exceeds the route MTU less the outer headers. It then sends one Packet Too Big to the source after it has walked all tunnels.
Quoted 9 lines
drivers/net/amt.c +1
-0@@ -1237,26 +1237,51 @@ 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
drivers/net/amt.c static void amt_req_work(struct work_struct *work) · line 1250
Quoted 10 lines
drivers/net/amt.c +10
-0+* carry a Fragment header, so a payload larger than the tunnel MTU is +* dropped, and an IPv6 source is sent a Packet Too Big. 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) +{ +return dst_mtu (dst) -sizeof (struct ipv6hdr ) -sizeof (struct udphdr ) - +sizeof (struct amt_header_mcast_data ); +}
[Severity: Low]
Can this u32 subtraction wrap when dst_mtu(dst) is below 50?
ip6_dst_mtu_maybe_forward() returns the raw RTAX_MTU metric when one is set, and ip_metrics_convert() only clamps RTAX_MTU from above. So an admin route with something like "mtu 40" is accepted. A large lwtunnel headroom (for example seg6 with a big SRH) can also push dst_mtu() below the 50 byte overhead.
In that case tmtu becomes roughly 4G, and amt_tmtu_exceeded() never fires in amt_send_multicast_data():
tmtu = amt_tmtu(dst);
if (amt_tmtu_exceeded(oskb, tmtu)) {The copy is still dropped later in the IPv6 output path. Because the patch already leaves out tunnel MTUs below IPV6_MIN_MTU, no Packet Too Big to the source is lost. However, an skb copy is still made and pushed through IPv6 output per tunnel per packet. An ICMPv6 Packet Too Big is generated toward the relay's own address, and tx_dropped is not counted on the amt device.
Should amt_tmtu() clamp at zero, or should amt_send_multicast_data() treat a dst_mtu() smaller than the overhead as exceeded?
drivers/net/amt.c static void amt_req_work(struct work_struct *work) · line 1260
Quoted 10 lines
drivers/net/amt.c +10
-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; +}
[Severity: Medium]
Is the transport header reliable at this point for an inner IPv6 GSO skb that carries extension headers?
skb_gso_validate_network_len() computes the per-segment length as (skb_transport_header - skb_network_header) plus skb_gso_transport_seglen(). Earlier, amt_dev_xmit() calls ipv6_mc_check_mld(), and ipv6_mc_check_ip6hdr() always resets the transport header to just past the fixed IPv6 header:
net/ipv6/mcast_snoop.c:ipv6_mc_check_ip6hdr() {
...
skb_set_transport_header(skb, offset);
...
}ipv6_mc_check_exthdrs() then returns -ENOMSG for a non-MLD packet before it corrects the offset:
if (ip6h->nexthdr != IPPROTO_HOPOPTS)
return -ENOMSG;
...
if (nexthdr != IPPROTO_ICMPV6)
return -ENOMSG;
if (!skb_set_transport_header_careful(skb, offset))So for every IPv6 data packet the transport header stays at nh+40, even when Hop-by-Hop or Destination Options headers come before UDP.
For an SKB_GSO_UDP_L4 skb with such headers, the computed segment length is short by the length of those extension headers. A segment that is larger than tmtu by up to that amount passes this check. In that case *ptb is not lowered, no Packet Too Big reaches the source, and the copy is encapsulated.
skb_reset_inner_headers() in amt_send_multicast_data() then copies the same offset into inner_transport_header. The outer ip6_finish_output_gso() validation would also under-count, so the oversized segments go out on a path whose route MTU cannot carry them.
This seems to contradict this part of the commit message:
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.
Would it make sense to locate the real upper-layer offset (for example with ipv6_skip_exthdr()) before validating, or to fix up the transport header in amt_dev_xmit() for data packets?
[ ... ]
Quoted 12 lines
drivers/net/amt.c +3
-1@@ -1575,8 +1617,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);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125191450.2497936-1-omar%40blockcast.net
PATCH v2 6/12 amt: size the encapsulation headroom by the outer IP version
In reply to Omar RamadanThe amt device reserves AMT_RELAY_HLEN or AMT_GW_HLEN of headroom and subtracts the same amount from the stream device's MTU. Both assume a 20-byte IPv4 outer header. An IPv6 outer header is 40 bytes, so on an IPv6 device an inner packet in the last 20 bytes below the MTU would not fit the stream device once encapsulated, and ip6_fragment() drops
it: nothing sets ignore_df on the tunnel skb.
Add AMT_RELAY_HLEN6 and AMT_GW_HLEN6, pick between the IPv4 and IPv6 sizes in amt_hlen(), and use amt_hlen() wherever the device sizes its headroom and MTU: at newlink and on NETDEV_CHANGEMTU of the stream device.
amt_v6() is still false for every device, so there is no functional change.
--- drivers/net/amt.c | 26 +++++++++++++++----------- include/net/amt.h | 7 +++++++ 2 files changed, 22 insertions(+), 11 deletions(-)
drivers/net/amt.c +15 -11
@@ -104,6 +104,14 @@ static unsigned int amt_ip_hlen(const struct amt_dev *amt)return amt_v6 (amt) ?sizeof (struct ipv6hdr ) :sizeof (struct iphdr ); } +/* Headroom the device reserves for its outer encapsulation. */ +static unsigned int amt_hlen (const struct amt_dev *amt) +{ +if (amt->mode ==AMT_MODE_RELAY ) +return amt_v6 (amt) ?AMT_RELAY_HLEN6 :AMT_RELAY_HLEN ; +return amt_v6 (amt) ?AMT_GW_HLEN6 :AMT_GW_HLEN ; +} +/* 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)
@@ -3903,10 +3911,10 @@ static int amt_newlink(struct net_device *dev, amt->qrv =READ_ONCE (amt->net->ipv4.sysctl_igmp_qrv); amt->qri =10 ; dev->needed_headroom = amt->stream_dev->needed_headroom + -AMT_RELAY_HLEN ; - dev->mtu = amt->stream_dev->mtu -AMT_RELAY_HLEN ; +amt_hlen (amt); + dev->mtu = amt->stream_dev->mtu -amt_hlen (amt); dev->max_mtu = dev->mtu; - dev->min_mtu =ETH_MIN_MTU +AMT_RELAY_HLEN ; + dev->min_mtu =ETH_MIN_MTU +amt_hlen (amt); }else {if (!data[IFLA_AMT_DISCOVERY_IP ]) { NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_AMT_DISCOVERY_IP],
@@ -3929,10 +3937,10 @@ static int amt_newlink(struct net_device *dev, } dev->needed_headroom = amt->stream_dev->needed_headroom + -AMT_GW_HLEN ; - dev->mtu = amt->stream_dev->mtu -AMT_GW_HLEN ; +amt_hlen (amt); + dev->mtu = amt->stream_dev->mtu -amt_hlen (amt); dev->max_mtu = dev->mtu; - dev->min_mtu =ETH_MIN_MTU +AMT_GW_HLEN ; + dev->min_mtu =ETH_MIN_MTU +amt_hlen (amt); } amt->qi =AMT_INIT_QUERY_INTERVAL ;
@@ -4053,11 +4061,7 @@ static int amt_device_event(struct notifier_block *unused,amt_dellink (amt->dev, &list);break ;case NETDEV_CHANGEMTU : -if (amt->mode ==AMT_MODE_RELAY ) - new_mtu = dev->mtu -AMT_RELAY_HLEN ; -else - new_mtu = dev->mtu -AMT_GW_HLEN ; - + new_mtu = dev->mtu -amt_hlen (amt);dev_set_mtu (amt->dev, new_mtu);break ; }
include/net/amt.h +7 -0
@@ -434,9 +434,16 @@ struct amt_dev {#define AMT_GW_HLEN (sizeof(struct iphdr) + \ sizeof(struct udphdr) + \ sizeof(struct amt_gw_headers)) +/* IPv6-outer gateway headroom: the outer header is a struct ipv6hdr. */ +#define AMT_GW_HLEN6 (sizeof(struct ipv6hdr) + \ + sizeof(struct udphdr) + \ + sizeof(struct amt_gw_headers))#define AMT_RELAY_HLEN (sizeof(struct iphdr) + \ sizeof(struct udphdr) + \ sizeof(struct amt_relay_headers)) +#define AMT_RELAY_HLEN6 (sizeof(struct ipv6hdr) + \ + sizeof(struct udphdr) + \ + sizeof(struct amt_relay_headers))static inline bool netif_is_amt (const struct net_device *dev) {
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v2 06/12] amt: size the encapsulation headroom by the outer IP version
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message names the wrong drop site for the packets it is meant to protect.
--
amt: size the encapsulation headroom by the outer IP version
This adds AMT_RELAY_HLEN6 and AMT_GW_HLEN6 and a new helper, amt_hlen(), that picks the IPv4 or IPv6 headroom size for the device's outer family. amt_hlen() is then used to size needed_headroom, mtu, max_mtu and min_mtu in amt_newlink(), and the new MTU on NETDEV_CHANGEMTU in amt_device_event().
Quoted 6 lines
The amt device reserves
AMT_RELAY_HLENorAMT_GW_HLENof headroom and subtracts the same amount from the stream device's MTU. Both assume a 20-byte IPv4 outer header. An IPv6 outer header is 40 bytes, so on an IPv6 device an inner packet in the last 20 bytes below the MTU would not fit the stream device once encapsulated, andip6_fragment()drops
it: nothing setsignore_dfon the tunnel skb.
[Severity: Low]
Is this description accurate for this tree? The previous patch in the series, "amt: forward multicast data over IPv6", added a tunnel MTU check to the relay's bulk transmit path. The check runs before encapsulation:
drivers/net/amt.c:amt_send_multicast_data() {
...
tmtu = amt_tmtu(dst);
if (amt_tmtu_exceeded(oskb, tmtu)) {
dst_release(dst);
...
DEV_STATS_INC(amt->dev, tx_dropped);
return;
}
...
}amt_tmtu() returns:
return dst_mtu(dst) - sizeof(struct ipv6hdr) - sizeof(struct udphdr) - sizeof(struct amt_header_mcast_data);
That is dst_mtu - 50.
An inner packet that does not fit is dropped here, before skb_copy_expand() and amt_udp_xmit() are called, so it never reaches ip6_fragment(). The drop is counted in tx_dropped, and *ptb is lowered so amt_dev_xmit() sends a Packet Too Big if the payload is IPv6. An IPv4 multicast payload is dropped without notice, because icmp_send() does not answer multicast.
The size of the window also seems different from what the message says. sizeof(struct amt_relay_headers) is 12, so the old relay MTU is stream_mtu - 40 and the tunnel MTU is stream_mtu - 50. The affected packets fall in a 10-byte window, not the last 20 bytes.
The other relay sends (Advertisement, Membership Query) are small control messages. The gateway's Membership Update only carries IGMP/MLD reports.
The code change itself looks right. Only the stated reason seems off. Could the commit message say that the relay's own tunnel MTU check in amt_send_multicast_data() drops these packets, and that IPv4 multicast payloads are dropped without notice?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125191450.2497936-1-omar%40blockcast.net
PATCH v2 7/12 amt: send the AMT gateway control plane over IPv6
In reply to Omar RamadanA gateway sends three control messages: the Relay Discovery to its discovery address, then the Request and the Membership Updates to the relay it learned. All three are built for an IPv4 outer header only, so a gateway on an IPv6-only access network cannot reach any relay.
Send the Discovery and the Request of a gateway with an IPv6 local address from amt_send_discovery_v6() and amt_send_request_v6(). Both messages are a few bytes with no payload, so they are built on the stack and sent with amt_send_ctrl_v6(), the helper that already sends the relay's IPv6 Advertisement, rather than with a copy of the IPv4 skb construction. The Membership Update carries the gateway's IGMP or MLD report, so amt_send_membership_update() keeps building on that skb: it sizes the headroom for the outer family and sends through amt_udp_xmit(), like the relay's Membership Query and Multicast Data, which avoids an IPv6 copy of the function.
struct amt_dev gains the gateway's IPv6 discovery address and the IPv6 relay address it learns and sends to. Nothing writes the latter until the next patch, which also adds its synchronisation.
amt_send_ctrl_v6() now holds rcu_read_lock_bh() instead of rcu_read_lock(). The gateway sends the Discovery and the Request from its event worker in process context, and udp_tunnel6_xmit_skb() reaches ip6tunnel_xmit(), which increments and later decrements the per-CPU xmit recursion counter with __this_cpu_inc() and __this_cpu_dec(). With preemption enabled the task could migrate in between and leave both counters wrong. The IPv4 Discovery and Request go through ip_local_out() and never touch the counter, and the relay's Advertisement is sent from softirq, so neither is affected.
Nothing can set a local IPv6 address until the netlink attributes arrive, so none of the IPv6 sender code added here runs yet, and the conversion of amt_send_membership_update() to amt_ip_hlen() and amt_udp_xmit() changes no IPv4 behaviour.
The P bit of the Request and the inner protocol of the Update still follow the inner family, so an IPv6 gateway requests and reports both IGMP and MLD, as an IPv4 one does.
--- drivers/net/amt.c | 84 ++++++++++++++++++++++++++++++----------------- include/net/amt.h | 8 +++++ 2 files changed, 62 insertions(+), 30 deletions(-)
drivers/net/amt.c +54 -30
@@ -791,8 +791,11 @@ static int amt_send_ctrl_v6(struct amt_dev *amt, const struct in6_addr *saddr,struct sock *sk;int hlen, err; -rcu_read_lock (); - sk =rcu_dereference (amt->sk); +/* The gateway sends from its event worker, but ip6tunnel_xmit() +* counts xmit recursion per CPU, which needs BH disabled. +*/ +rcu_read_lock_bh (); + sk =rcu_dereference_bh (amt->sk);if (!sk || !netif_running (amt->stream_dev) || !netif_running (amt->dev)) { err = -ENETDOWN ;
@@ -824,10 +827,39 @@ static int amt_send_ctrl_v6(struct amt_dev *amt, const struct in6_addr *saddr, ip6_dst_hoplimit(dst), 0, sport, dport, false, 0); err =0 ; out: -rcu_read_unlock (); +rcu_read_unlock_bh ();return err; } +/* IPv6-outer variant of amt_send_discovery(). */ +static void amt_send_discovery_v6 (struct amt_dev *amt) +{ +struct amt_header_discovery amtd = { + .type =AMT_MSG_DISCOVERY , + .nonce = amt->nonce, + }; + +if (!amt_send_ctrl_v6 (amt, &amt->local_ipv6, &amt->discovery_ipv6, + amt->gw_port, amt->relay_port, + &amtd,sizeof (amtd))) +amt_update_gw_status (amt,AMT_STATUS_SENT_DISCOVERY , true); +} + +/* IPv6-outer variant of amt_send_request(). The inner-family @v6 sets the +* P bit (IGMP vs MLD) independently of the outer transport. +*/ +static void amt_send_request_v6 (struct amt_dev *amt,bool v6) +{ +struct amt_header_request amtrh = { + .type =AMT_MSG_REQUEST , + .p = v6, + .nonce = amt->nonce, + }; + +amt_send_ctrl_v6 (amt, &amt->local_ipv6, &amt->remote_ipv6, + amt->gw_port, amt->relay_port, &amtrh,sizeof (amtrh)); +} +static void amt_send_discovery (struct amt_dev *amt) {struct amt_header_discovery *amtd;
@@ -841,6 +873,11 @@ static void amt_send_discovery(struct amt_dev *amt)u32 len;int err; +if (amt_v6 (amt)) { +amt_send_discovery_v6 (amt); +return ; + } +rcu_read_lock (); sk =rcu_dereference (amt->sk);if (!sk)
@@ -931,6 +968,11 @@ static void amt_send_request(struct amt_dev *amt, bool v6)u32 len;int err; +if (amt_v6 (amt)) { +amt_send_request_v6 (amt, v6); +return ; + } +rcu_read_lock (); remote_ip =READ_ONCE (amt->remote_ip); sk =rcu_dereference (amt->sk);
@@ -1336,9 +1378,7 @@ static bool amt_send_membership_update(struct amt_dev *amt, {__be32 remote_ip =READ_ONCE (amt->remote_ip);struct amt_header_membership_update *amtmu; -struct iphdr *iph; -struct flowi4 fl4; -struct rtable *rt; +union amt_addr remote = {};struct sock *sk;int err;
@@ -1347,23 +1387,11 @@ static bool amt_send_membership_update(struct amt_dev *amt,return true; err =skb_cow_head (skb,LL_RESERVED_SPACE (amt->dev) +sizeof (*amtmu) + -sizeof (*iph) +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 = remote_ip; - 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" , &remote_ip); -return true; - } - amtmu =skb_push (skb,sizeof (*amtmu)); amtmu->version =0 ; amtmu->type =AMT_MSG_MEMBERSHIP_UPDATE ;
@@ -1375,17 +1403,13 @@ static bool amt_send_membership_update(struct amt_dev *amt,skb_set_inner_protocol (skb,htons (ETH_P_IP )); elseskb_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->gw_port, - amt->relay_port, - false, - false, -0 ); +if (amt_v6 (amt)) + remote.ip6 = amt->remote_ipv6; +else + remote.ip4 = remote_ip; +if (amt_udp_xmit (amt, sk, skb, &remote, amt->gw_port, + amt->relay_port,inet_dsfield_to_dscp (AMT_TOS ),NULL )) +return true;amt_update_gw_status (amt,AMT_STATUS_SENT_UPDATE , true);return false; }
include/net/amt.h +8 -0
@@ -390,8 +390,16 @@ struct amt_dev {struct in6_addr local_ipv6;/* Outer remote ip */ __be32 remote_ip; +/* Outer remote ipv6 (learned from the v6 Relay Advertisement; +* in6addr_any in v4 mode, mutually exclusive with remote_ip) +*/ +struct in6_addr remote_ipv6;/* Outer discovery ip */ __be32 discovery_ip; +/* Outer discovery ipv6 (v6 gateway only; in6addr_any in v4 mode, +* mutually exclusive with discovery_ip) +*/ +struct in6_addr discovery_ipv6;/* Only used in gateway mode */ __be32 nonce;/* Gateway sent request and received query */
Signature · 1 line
2.47.3
PATCH v2 8/12 amt: receive the AMT gateway control plane over IPv6
In reply to Omar RamadanAn IPv6 gateway now sends its Discovery, Request and Updates over IPv6, but it cannot take the replies. amt_rcv() checks the outer source of an Advertisement against the discovery address, and that of Multicast Data and a Membership Query against the learned relay address, by reading ip_hdr(skb)->saddr, which on an IPv6 outer header is part of the flow label and payload length. amt_advertisement_handler() parses only the IPv4 form, so the gateway never learns an IPv6 relay address.
amt_rcv() now takes the outer source by value with amt_outer_saddr() before amt_parse_type() pulls, and checks it through amt_from_relay(), which compares it with the discovery address for an Advertisement and with the learned relay address otherwise, in the device's family. The IPv4 comparison it replaces is the one "amt: reject a gateway Query or Data from 0.0.0.0" fixed in net for IPv4, so this patch carries only the IPv6 half. amt_membership_query_handler() repeats the check for a Query that waited in the event queue, now through amt_from_relay() too. amt_advertisement_handler() pulls the 24-byte IPv6 form on an IPv6 gateway. Its fixed header and nonce are laid out as in the IPv4 form, so the shared checks run once and only the relay address is checked and recorded per family. An IPv6 relay address is refused when it is unspecified, loopback, multicast or IPv4-mapped, the IPv6 counterparts of the checks on the IPv4 address; the V6ONLY socket could not reach an IPv4-mapped relay.
The IPv6 relay address needs more care than the IPv4 one. The Advertisement handler, its only writer, runs from the event workqueue, while it is read in softirq, on receive and on transmit, and from amt_fill_info(), which no longer relies on RTNL. Nothing serialises them. remote_ip is a single 32-bit word, but a struct in6_addr is copied word by word, so with a plain assignment a reader could see half of an old and half of a new address: a packet sent to a spliced destination, or a valid relay's traffic dropped as "Invalid Relay IP". Publish it with amt_set_remote_ipv6() under a seqlock, remote_ipv6_lock, and read it with amt_get_remote_ipv6(), which retries until it has a consistent copy. Readers take no lock, so the receive path does not contend with the worker. Every consumer takes one snapshot per packet and uses it throughout, and amt_rcv() takes it only for the message types that use it. amt_newlink() initialises the seqlock before the device is registered.
amt_clear_remote() forgets the learned relay in both families. It replaces the IPv4-only reset in amt_event_send_request(), amt_dev_open() and amt_dev_stop(), so a gateway that is taken down and up again neither accepts traffic from its previous relay's IPv6 address nor keeps reporting it.
IPv6 input does not drop a packet from the unspecified address, as IPv4 input drops a 0.0.0.0 source as a martian. Such a packet would match the cleared relay address of a gateway that has lost its relay, and with a zero nonce in that window it could inject a Membership Query; a relay would create a tunnel for it. amt_rcv() drops it, and amt_from_relay() matches nothing against a relay address that is not known, in either family.
RFC 7450 s5.2.3.3 says a gateway that processes Multicast Data itself, as amt_rcv() does, must not discard it for a zero UDP checksum, and s5.1.6 lets a relay send one, the RFC 6936 exception to RFC 8200 s8.1. The socket of an IPv6 gateway therefore accepts a zero checksum; a non-zero one is still verified. amt_rcv() drops a zero checksum on every other message a gateway receives, as RFC 6936 s5 asks, and the socket of a relay keeps requiring the checksum.
The Membership Query and Multicast Data handlers dispatch on the inner family and work on the AMT payload behind the outer header, so they need no change. With this an IPv6 gateway discovers an IPv6 relay, completes the Request, Query and Update exchange and receives multicast, as an IPv4 gateway does.
--- drivers/net/amt.c | 151 ++++++++++++++++++++++++++++++++++++++-------- include/net/amt.h | 2 + 2 files changed, 127 insertions(+), 26 deletions(-)
drivers/net/amt.c +125 -26
@@ -831,6 +831,61 @@ static int amt_send_ctrl_v6(struct amt_dev *amt, const struct in6_addr *saddr,return err; } +/* The learned relay address is written by the event worker and read by the +* softirq RX and TX paths. A struct in6_addr cannot be stored or loaded in +* one access, so it is published under a seqlock, and every consumer takes +* one snapshot per packet. +*/ +static void amt_set_remote_ipv6 (struct amt_dev *amt, +const struct in6_addr *addr) +{ +write_seqlock_bh (&amt->remote_ipv6_lock); + amt->remote_ipv6 = *addr; +write_sequnlock_bh (&amt->remote_ipv6_lock); +} + +static void amt_get_remote_ipv6 (const struct amt_dev *amt, +struct in6_addr *addr) +{ +unsigned int seq; + +do { + seq =read_seqbegin (&amt->remote_ipv6_lock); + *addr = amt->remote_ipv6; + }while (read_seqretry (&amt->remote_ipv6_lock, seq)); +} + +/* Forget the relay a gateway learned, in both outer families. */ +static void amt_clear_remote (struct amt_dev *amt) +{ +WRITE_ONCE (amt->remote_ip,0 ); +amt_set_remote_ipv6 (amt, &in6addr_any); +} + +/* Whether a message a gateway received came from its relay: the discovery +* address for an Advertisement, the learned relay address otherwise. A +* relay address that is not known, the unspecified address, matches +* nothing. +*/ +static bool amt_from_relay (const struct amt_dev *amt, +const union amt_addr *saddr,bool discovery) +{ +__be32 relay4; + +if (amt_v6 (amt)) { +struct in6_addr relay; + +if (discovery) + relay = amt->discovery_ipv6; +else +amt_get_remote_ipv6 (amt, &relay); +return !ipv6_addr_any (&relay) && +ipv6_addr_equal (&saddr->ip6, &relay); + } + relay4 = discovery ? amt->discovery_ip :READ_ONCE (amt->remote_ip); +return relay4 && saddr->ip4 == relay4; +} +/* IPv6-outer variant of amt_send_discovery(). */ static void amt_send_discovery_v6 (struct amt_dev *amt) {
@@ -855,9 +910,11 @@ static void amt_send_request_v6(struct amt_dev *amt, bool v6) .p = v6, .nonce = amt->nonce, }; +struct in6_addr remote6; -amt_send_ctrl_v6 (amt, &amt->local_ipv6, &amt->remote_ipv6, - amt->gw_port, amt->relay_port, &amtrh,sizeof (amtrh)); +amt_get_remote_ipv6 (amt, &remote6); +amt_send_ctrl_v6 (amt, &amt->local_ipv6, &remote6, amt->gw_port, + amt->relay_port, &amtrh,sizeof (amtrh)); }static void amt_send_discovery (struct amt_dev *amt)
@@ -1254,7 +1311,7 @@ static void amt_event_send_request(struct amt_dev *amt) amt->qi =AMT_INIT_REQ_TIMEOUT ;WRITE_ONCE (amt->ready4, false);WRITE_ONCE (amt->ready6, false); -WRITE_ONCE (amt->remote_ip,0 ); +amt_clear_remote (amt);amt_update_gw_status (amt,AMT_STATUS_INIT , false); amt->req_cnt =0 ; amt->nonce =0 ;
@@ -1404,7 +1461,7 @@ static bool amt_send_membership_update(struct amt_dev *amt,else skb_set_inner_protocol (skb,htons (ETH_P_IPV6 ));if (amt_v6 (amt)) - remote.ip6 = amt->remote_ipv6; +amt_get_remote_ipv6 (amt, &remote.ip6);else remote.ip4 = remote_ip; if (amt_udp_xmit(amt, sk, skb, &remote, amt->gw_port,
@@ -2662,27 +2719,48 @@ static bool amt_advertisement_handler(struct amt_dev *amt, struct sk_buff *skb)struct amt_header_advertisement *amta;int hdr_size; - hdr_size =sizeof (*amta) +sizeof (struct udphdr ); +/* The IPv6 form (RFC 7450 s5.1.2) has the same header and nonce, with +* a 16-byte relay address in place of ip4. +*/ + hdr_size =sizeof (struct udphdr ) + + (amt_v6 (amt) ?sizeof (struct amt_header_advertisement_v6 ) : +sizeof (*amta));if (!pskb_may_pull (skb, hdr_size))return true; - amta = (struct amt_header_advertisement *)(udp_hdr (skb) +1 ); -if (!amta->ip4) +/* The two forms differ only in their length, and the device's family +* picks one, so a message of the other form is not accepted. +*/ +if (ntohs (udp_hdr (skb)->len) != hdr_size)return true; + amta = (struct amt_header_advertisement *)(udp_hdr (skb) +1 );if (amta->reserved || amta->version)return true; -if (ipv4_is_loopback (amta->ip4) ||ipv4_is_multicast (amta->ip4) || -ipv4_is_zeronet (amta->ip4)) -return true; -if (amt->status !=AMT_STATUS_SENT_DISCOVERY || amt->nonce != amta->nonce)return true; -WRITE_ONCE (amt->remote_ip, amta->ip4); -netdev_dbg (amt->dev,"advertised remote ip = %pI4\n" , &amta->ip4); +if (amt_v6 (amt)) { +const struct in6_addr *ip6; + + ip6 = &((struct amt_header_advertisement_v6 *)amta)->ip6; +if (ipv6_addr_any (ip6) ||ipv6_addr_loopback (ip6) || +ipv6_addr_is_multicast (ip6) ||ipv6_addr_v4mapped (ip6)) +return true; + +amt_set_remote_ipv6 (amt, ip6); +netdev_dbg (amt->dev,"advertised remote ipv6 = %pI6c\n" , ip6); + }else { +if (!amta->ip4 ||ipv4_is_loopback (amta->ip4) || +ipv4_is_multicast (amta->ip4) ||ipv4_is_zeronet (amta->ip4)) +return true; + +WRITE_ONCE (amt->remote_ip, amta->ip4); +netdev_dbg (amt->dev,"advertised remote ip = %pI4\n" , + &amta->ip4); + }mod_delayed_work (amt_wq, &amt->req_wq,0 );amt_update_gw_status (amt,AMT_STATUS_RECEIVED_ADVERTISEMENT , true);
@@ -2767,6 +2845,7 @@ static bool amt_membership_query_handler(struct amt_dev *amt,struct ethhdr *eth, *oeth;struct igmpv3_query *ihv3;u8 h_source[ETH_ALEN ]; +union amt_addr saddr;struct iphdr *iph;int hdr_size, len;u64 response_mac;
@@ -2780,7 +2859,8 @@ static bool amt_membership_query_handler(struct amt_dev *amt,return true;/* A deferred query may outlive a relay address change. */ -if (ip_hdr (skb)->saddr !=READ_ONCE (amt->remote_ip)) +amt_outer_saddr (amt, skb, &saddr); +if (!amt_from_relay (amt, &saddr, false))return true;if (amtmq->nonce != amt->nonce)
@@ -3409,9 +3489,8 @@ static void amt_gw_rcv(struct amt_dev *amt, struct sk_buff *skb)static int amt_rcv (struct sock *sk,struct sk_buff *skb) { +union amt_addr saddr;struct amt_dev *amt; -__be32 remote_ip; -__be32 saddr;int type;bool err;
@@ -3422,10 +3501,17 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)kfree_skb (skb); goto out; } - remote_ip =READ_ONCE (amt->remote_ip); skb->dev = amt->dev; - saddr =ip_hdr (skb)->saddr; +/* Snapshot the outer source before amt_parse_type() pulls. */ +amt_outer_saddr (amt, skb, &saddr); +/* IPv4 input drops a 0.0.0.0 source as a martian, but IPv6 input +* delivers ::, which no relay or gateway can be. +*/ +if (amt_v6 (amt) &&ipv6_addr_any (&saddr.ip6)) { + err = true; + goto drop; + } type =amt_parse_type (skb);if (type ==-1 ) { err = true;
@@ -3433,9 +3519,17 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb) }if (amt->mode ==AMT_MODE_GATEWAY ) { +/* RFC 6936 s5: accept the zero checksum only on the message +* that needs it. +*/ +if (amt_v6 (amt) && !udp_hdr (skb)->check && + type !=AMT_MSG_MULTICAST_DATA ) { + err = true; + goto drop; + }switch (type) {case AMT_MSG_ADVERTISEMENT : -if (saddr != amt->discovery_ip) { +if (!amt_from_relay (amt, &saddr, true)) {netdev_dbg (amt->dev,"Invalid Relay IP\n" ); err = true; goto drop;
@@ -3447,7 +3541,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb) } goto out;case AMT_MSG_MULTICAST_DATA : -if (!remote_ip || saddr != remote_ip) { +if (!amt_from_relay (amt, &saddr, false)) {netdev_dbg (amt->dev,"Invalid Relay IP\n" ); err = true; goto drop;
@@ -3458,7 +3552,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)else goto out;case AMT_MSG_MEMBERSHIP_QUERY : -if (!remote_ip || saddr != remote_ip) { +if (!amt_from_relay (amt, &saddr, false)) {netdev_dbg (amt->dev,"Invalid Relay IP\n" ); err = true; goto drop;
@@ -3597,13 +3691,17 @@ static struct sock *amt_create_sock(const struct amt_dev *amt)* the output interface, as the IPv4 lookup is, and receives * from that link only, where a link-local peer is unique. * V6ONLY keeps the socket off the IPv4 wildcard, so an IPv4 -* amt device can use the same port in the netns. The UDP -* checksum is mandatory over IPv6. +* amt device can use the same port in the netns. +* +* The UDP checksum is always sent (RFC 8200 s8.1). A gateway +* also accepts a zero checksum, as RFC 7450 s5.2.3.3 requires +* for Multicast Data, and amt_rcv() drops it on the other +* messages; a non-zero checksum is still verified. */ udp_conf.family =AF_INET6 ; udp_conf.bind_ifindex = amt->stream_dev->ifindex; udp_conf.use_udp6_tx_checksums = true; - udp_conf.use_udp6_rx_checksums = true; + udp_conf.use_udp6_rx_checksums = amt->mode ==AMT_MODE_RELAY ; udp_conf.ipv6_v6only = true; }else { udp_conf.family =AF_INET ;
@@ -3672,7 +3770,7 @@ static int amt_dev_open(struct net_device *dev) } amt->req_cnt =0 ; -WRITE_ONCE (amt->remote_ip,0 ); +amt_clear_remote (amt); amt->nonce =0 ; amt->status =AMT_STATUS_INIT ;
@@ -3721,7 +3819,7 @@ static int amt_dev_stop(struct net_device *dev) amt->ready4 = false; amt->ready6 = false; amt->req_cnt =0 ; -WRITE_ONCE (amt->remote_ip,0 ); +amt_clear_remote (amt);/* Mark every tunnel dead first, so a concurrent amt_tunnel_expire() * sees ->dead and bails instead of freeing a tunnel in parallel; this
@@ -3891,6 +3989,7 @@ static int amt_newlink(struct net_device *dev, amt->max_tunnels =AMT_MAX_TUNNELS ;spin_lock_init (&amt->lock); +seqlock_init (&amt->remote_ipv6_lock);seqcount_spinlock_init (&amt->key_seq, &amt->lock); amt->max_groups =AMT_MAX_GROUP ; amt->max_sources =AMT_MAX_SOURCE ;
include/net/amt.h +2 -0
@@ -394,6 +394,8 @@ struct amt_dev {* in6addr_any in v4 mode, mutually exclusive with remote_ip) */ struct in6_addr remote_ipv6; +/* Publishes remote_ipv6, which is too wide for a single access */ +seqlock_t remote_ipv6_lock;/* Outer discovery ip */ __be32 discovery_ip;/* Outer discovery ipv6 (v6 gateway only; in6addr_any in v4 mode,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v2 08/12] amt: receive the AMT gateway control plane over IPv6
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] This patch changes how an IPv4 gateway handles Relay Advertisements, and the commit message does not say so.
--
amt: receive the AMT gateway control plane over IPv6
This patch lets an IPv6 AMT gateway receive Advertisements, Membership Queries and Multicast Data over an IPv6 outer header. The learned IPv6 relay address is published under a new seqlock. A zero UDP checksum is now accepted only for Multicast Data on an IPv6 gateway.
Quoted 4 lines
drivers/net/amt.c +0
-0
[ ... ]
Quoted 11 lines
drivers/net/amt.c +6
-1@@ -2662,27 +2719,48 @@ static bool amt_advertisement_handler(struct amt_dev *amt, struct sk_buff *skb)struct amt_header_advertisement *amta;int hdr_size; - hdr_size =sizeof (*amta) +sizeof (struct udphdr ); +/* The IPv6 form (RFC 7450 s5.1.2) has the same header and nonce, with +* a 16-byte relay address in place of ip4. +*/ + hdr_size =sizeof (struct udphdr ) + + (amt_v6 (amt) ?sizeof (struct amt_header_advertisement_v6 ) : +sizeof (*amta));
drivers/net/amt.c static bool amt_advertisement_handler(struct amt_dev *amt, struct sk_buff *skb) · line 2735
Quoted 10 lines
drivers/net/amt.c +4
-2if (!pskb_may_pull (skb, hdr_size))return true; - amta = (struct amt_header_advertisement *)(udp_hdr (skb) +1 ); -if (!amta->ip4) +/* The two forms differ only in their length, and the device's family +* picks one, so a message of the other form is not accepted. +*/ +if (ntohs (udp_hdr (skb)->len) != hdr_size)return true;
[Severity: Low]
Is this new length check meant to apply to IPv4 gateways as well?
When amt_v6() is false, hdr_size is 8 + 12 = 20. With this check an IPv4 gateway now drops every Advertisement whose UDP length is not exactly 20. That includes the 24-byte form that carries an IPv6 relay address.
Before this patch amt_advertisement_handler() only did a minimum pskb_may_pull() and had no length check. An IPv4 gateway would accept the 24-byte form and store the first 32 bits of the IPv6 address as remote_ip. It would then send its Requests to an unrelated IPv4 host.
The commit message says:
The IPv4 comparison it replaces is the one "amt: reject a gateway Query or Data from 0.0.0.0" fixed in net for IPv4, so this patch carries only the IPv6 half.
It does not mention that IPv4 Advertisement parsing changes too. The check is still unchanged at the end of the series.
If the old IPv4 mis-parse counts as a bug, could it be split out and sent to net with a Fixes: tag, as was done for the 0.0.0.0 fix? Otherwise, could the changelog state that the IPv4 behaviour changes?
Quoted 4 lines
drivers/net/amt.c +1
-0+ amta = (struct amt_header_advertisement *)(udp_hdr (skb) +1 );if (amta->reserved || amta->version)return true;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125191450.2497936-1-omar%40blockcast.net
PATCH v2 9/12 amt: add netlink attributes for an IPv6 outer transport
In reply to Omar RamadanEvery path of the relay and the gateway can now run over an IPv6 outer transport, but nothing can create such a device. Add the attributes that do:
- IFLA_AMT_LOCAL_IP6, the local IPv6 address. It selects IPv6 as the outer transport and is mutually exclusive with IFLA_AMT_LOCAL_IP.
- IFLA_AMT_DISCOVERY_IP6, the IPv6 address a gateway sends its Relay Discovery to. A gateway's discovery address has to be in the family of its local address, as both ends of the tunnel use one outer transport.
- IFLA_AMT_REMOTE_IP6, the relay address the gateway learned from the IPv6 Relay Advertisement. Like IFLA_AMT_REMOTE_IP it is only reported, and the policy rejects it on input.
amt_fill_info() reports the addresses in the device's outer family. IFLA_AMT_LOCAL_IP6 is refused with -EAFNOSUPPORT on a kernel built without IPv6, rather than creating an IPv4 device with no local address. An IPv6 local or discovery address is refused when it is unspecified, loopback or multicast, as the IPv4 ones are, and also when it is IPv4-mapped: the V6ONLY socket could never send from or to such an address, so the device would be created but silently fail every send.
The existing IFLA_AMT_LOCAL_IP and IFLA_AMT_DISCOVERY_IP cannot simply carry 16 bytes. Net requires exactly four bytes for them ("amt: require an exact IPv4-sized IFLA_AMT_{LOCAL,DISCOVERY}_IP"), so the IPv6 addresses need attributes of their own. A kernel that does not know the new attributes ignores them and fails the request for lack of a local address, so userspace can tell whether IPv6 is supported. vxlan (IFLA_VXLAN_LOCAL6, IFLA_VXLAN_GROUP6) and geneve (IFLA_GENEVE_REMOTE6) add their IPv6 addresses the same way. The attributes are appended to the enum, so the existing values do not change, and strict_start_type makes the policy validate them, and any attribute added after them, strictly. Their policy is an exact 16-byte length.
A relay has always ignored IFLA_AMT_DISCOVERY_IP, and existing users may pass it, so an IPv4 relay still accepts it. An IPv6 relay has no existing users, so it rejects a discovery address of either family, and an IPv4 relay rejects IFLA_AMT_DISCOVERY_IP6.
--- drivers/net/amt.c | 164 ++++++++++++++++++++++++++++++--------- include/uapi/linux/amt.h | 13 ++++ 2 files changed, 141 insertions(+), 36 deletions(-)
drivers/net/amt.c +128 -36
@@ -3916,6 +3916,7 @@ static void amt_link_setup(struct net_device *dev) }static const struct nla_policy amt_policy[IFLA_AMT_MAX +1 ] = { + [IFLA_AMT_UNSPEC ] = { .strict_start_type =IFLA_AMT_LOCAL_IP6 }, [IFLA_AMT_MODE ] = { .type =NLA_U32 }, [IFLA_AMT_RELAY_PORT ] = { .type =NLA_U16 }, [IFLA_AMT_GATEWAY_PORT ] = { .type =NLA_U16 },
@@ -3924,6 +3925,10 @@ static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = { [IFLA_AMT_REMOTE_IP] = { .len = sizeof_field(struct iphdr, daddr) }, [IFLA_AMT_DISCOVERY_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)), [IFLA_AMT_MAX_TUNNELS] = { .type = NLA_U32 }, + [IFLA_AMT_LOCAL_IP6] = NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)), + [IFLA_AMT_DISCOVERY_IP6 ] = + NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)), + [IFLA_AMT_REMOTE_IP6] = { .type = NLA_REJECT }, }; static int amt_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -3950,16 +3955,53 @@ static int amt_validate(struct nlattr *tb[], struct nlattr *data[],return -EINVAL ; } -if (!data[IFLA_AMT_LOCAL_IP ]) { -NL_SET_ERR_MSG_ATTR (extack, data[IFLA_AMT_DISCOVERY_IP ], -"Local attribute is required" ); +if (!data[IFLA_AMT_LOCAL_IP ] && !data[IFLA_AMT_LOCAL_IP6 ]) { +NL_SET_ERR_MSG_MOD (extack,"Local attribute is required" );return -EINVAL ; } -if (!data[IFLA_AMT_DISCOVERY_IP ] && -nla_get_u32 (data[IFLA_AMT_MODE ]) ==AMT_MODE_GATEWAY ) { -NL_SET_ERR_MSG_ATTR (extack, data[IFLA_AMT_LOCAL_IP ], -"Discovery attribute is required" ); +if (data[IFLA_AMT_LOCAL_IP ] && data[IFLA_AMT_LOCAL_IP6 ]) { +NL_SET_ERR_MSG_ATTR (extack, data[IFLA_AMT_LOCAL_IP6 ], +"Local IPv4 and IPv6 are mutually exclusive" ); +return -EINVAL ; + } + +if (data[IFLA_AMT_LOCAL_IP6 ] && !IS_ENABLED (CONFIG_IPV6 )) { +NL_SET_ERR_MSG_ATTR (extack, data[IFLA_AMT_LOCAL_IP6 ], +"IPv6 support is disabled" ); +return -EAFNOSUPPORT ; + } + +if (nla_get_u32 (data[IFLA_AMT_MODE ]) !=AMT_MODE_GATEWAY ) { +struct nlattr *disc = data[IFLA_AMT_DISCOVERY_IP6 ]; + +/* An IPv4 relay has always ignored IFLA_AMT_DISCOVERY_IP, +* and existing users may pass it. An IPv6 relay has no such +* users, so it rejects a discovery address of either family. +*/ +if (!disc && data[IFLA_AMT_LOCAL_IP6 ]) + disc = data[IFLA_AMT_DISCOVERY_IP ]; +if (disc) { +NL_SET_ERR_MSG_ATTR (extack, disc, +"Discovery is only valid in gateway mode" ); +return -EINVAL ; + } +return 0 ; + } + +/* A gateway's discovery address is in the family of its local +* address, since both ends of the tunnel use one outer transport. +*/ +if (data[IFLA_AMT_LOCAL_IP6 ] ? !data[IFLA_AMT_DISCOVERY_IP6 ] : + !data[IFLA_AMT_DISCOVERY_IP ]) { +NL_SET_ERR_MSG_MOD (extack, +"Discovery attribute of the local family is required" ); +return -EINVAL ; + } + +if (data[IFLA_AMT_DISCOVERY_IP ] && data[IFLA_AMT_DISCOVERY_IP6 ]) { +NL_SET_ERR_MSG_ATTR (extack, data[IFLA_AMT_DISCOVERY_IP6 ], +"Discovery IPv4 and IPv6 are mutually exclusive" );return -EINVAL ; }
@@ -4010,13 +4052,25 @@ static int amt_newlink(struct net_device *dev, goto err; } - amt->local_ip =nla_get_in_addr (data[IFLA_AMT_LOCAL_IP ]); -if (ipv4_is_loopback (amt->local_ip) || -ipv4_is_zeronet (amt->local_ip) || -ipv4_is_multicast (amt->local_ip)) { -NL_SET_ERR_MSG_ATTR (extack, tb[IFLA_AMT_LOCAL_IP ], -"Invalid Local address" ); - goto err; +if (data[IFLA_AMT_LOCAL_IP6 ]) { + amt->local_ipv6 =nla_get_in6_addr (data[IFLA_AMT_LOCAL_IP6 ]); +if (ipv6_addr_loopback (&amt->local_ipv6) || +ipv6_addr_any (&amt->local_ipv6) || +ipv6_addr_is_multicast (&amt->local_ipv6) || +ipv6_addr_v4mapped (&amt->local_ipv6)) { +NL_SET_ERR_MSG_ATTR (extack, data[IFLA_AMT_LOCAL_IP6 ], +"Invalid Local IPv6 address" ); + goto err; + } + }else { + amt->local_ip =nla_get_in_addr (data[IFLA_AMT_LOCAL_IP ]); +if (ipv4_is_loopback (amt->local_ip) || +ipv4_is_zeronet (amt->local_ip) || +ipv4_is_multicast (amt->local_ip)) { +NL_SET_ERR_MSG_ATTR (extack, tb[IFLA_AMT_LOCAL_IP ], +"Invalid Local address" ); + goto err; + } } amt->relay_port = nla_get_be16_default(data[IFLA_AMT_RELAY_PORT],
@@ -4039,24 +4093,35 @@ static int amt_newlink(struct net_device *dev, dev->max_mtu = dev->mtu; dev->min_mtu =ETH_MIN_MTU +amt_hlen (amt); }else { -if (!data[IFLA_AMT_DISCOVERY_IP ]) { -NL_SET_ERR_MSG_ATTR (extack, tb[IFLA_AMT_DISCOVERY_IP ], -"discovery must be set in gateway mode" ); - goto err; - }if (!amt->gw_port) {NL_SET_ERR_MSG_ATTR (extack, tb[IFLA_AMT_DISCOVERY_IP ],"gateway port must not be 0" ); goto err; } -WRITE_ONCE (amt->remote_ip,0 ); - amt->discovery_ip =nla_get_in_addr (data[IFLA_AMT_DISCOVERY_IP ]); -if (ipv4_is_loopback (amt->discovery_ip) || -ipv4_is_zeronet (amt->discovery_ip) || -ipv4_is_multicast (amt->discovery_ip)) { -NL_SET_ERR_MSG_ATTR (extack, tb[IFLA_AMT_DISCOVERY_IP ], -"discovery must be unicast" ); - goto err; +if (data[IFLA_AMT_DISCOVERY_IP6 ]) { +struct nlattr *attr = data[IFLA_AMT_DISCOVERY_IP6 ]; + + amt->discovery_ipv6 =nla_get_in6_addr (attr); +if (ipv6_addr_loopback (&amt->discovery_ipv6) || +ipv6_addr_any (&amt->discovery_ipv6) || +ipv6_addr_is_multicast (&amt->discovery_ipv6) || +ipv6_addr_v4mapped (&amt->discovery_ipv6)) { +NL_SET_ERR_MSG_ATTR (extack, attr, +"discovery must be unicast" ); + goto err; + } + }else { +WRITE_ONCE (amt->remote_ip,0 ); + amt->discovery_ip = +nla_get_in_addr (data[IFLA_AMT_DISCOVERY_IP ]); +if (ipv4_is_loopback (amt->discovery_ip) || +ipv4_is_zeronet (amt->discovery_ip) || +ipv4_is_multicast (amt->discovery_ip)) { +NL_SET_ERR_MSG_ATTR (extack, + tb[IFLA_AMT_DISCOVERY_IP ], +"discovery must be unicast" ); + goto err; + } } dev->needed_headroom = amt->stream_dev->needed_headroom +
@@ -4110,7 +4175,28 @@ static size_t amt_get_size(const struct net_device *dev)nla_total_size (sizeof (__u32)) +/* IFLA_MAX_TUNNELS */ nla_total_size (sizeof (__be32)) +/* IFLA_AMT_DISCOVERY_IP */ nla_total_size (sizeof (__be32)) +/* IFLA_AMT_REMOTE_IP */ -nla_total_size (sizeof (__be32));/* IFLA_AMT_LOCAL_IP */ +nla_total_size (sizeof (__be32)) +/* IFLA_AMT_LOCAL_IP */ +/* IFLA_AMT_{LOCAL,DISCOVERY,REMOTE}_IP6. Only one address of +* each IPv4/IPv6 pair is emitted, but this sizes for both. +*/ +3 *nla_total_size (sizeof (struct in6_addr )); +} + +/* The IPv6 addresses of an IPv6 device, one of each IPv4/IPv6 pair. */ +static int amt_fill_addr6 (struct sk_buff *skb,const struct amt_dev *amt) +{ +struct in6_addr remote6; + +if (nla_put_in6_addr (skb,IFLA_AMT_LOCAL_IP6 , &amt->local_ipv6)) +return -EMSGSIZE ; +if (amt->mode ==AMT_MODE_GATEWAY && +nla_put_in6_addr (skb,IFLA_AMT_DISCOVERY_IP6 , &amt->discovery_ipv6)) +return -EMSGSIZE ; +amt_get_remote_ipv6 (amt, &remote6); +if (!ipv6_addr_any (&remote6) && +nla_put_in6_addr (skb,IFLA_AMT_REMOTE_IP6 , &remote6)) +return -EMSGSIZE ; +return 0 ; }static int amt_fill_info (struct sk_buff *skb,const struct net_device *dev)
@@ -4127,15 +4213,21 @@ static int amt_fill_info(struct sk_buff *skb, const struct net_device *dev) goto nla_put_failure;if (nla_put_u32 (skb,IFLA_AMT_LINK , amt->stream_dev->ifindex)) goto nla_put_failure; -if (nla_put_in_addr (skb,IFLA_AMT_LOCAL_IP , amt->local_ip)) - goto nla_put_failure; -if (nla_put_in_addr (skb,IFLA_AMT_DISCOVERY_IP , amt->discovery_ip)) - goto nla_put_failure; - - remote_ip =READ_ONCE (amt->remote_ip); -if (remote_ip) -if (nla_put_in_addr (skb,IFLA_AMT_REMOTE_IP , remote_ip)) +if (amt_v6 (amt)) { +if (amt_fill_addr6 (skb, amt)) goto nla_put_failure; + }else { +if (nla_put_in_addr (skb,IFLA_AMT_LOCAL_IP , amt->local_ip)) + goto nla_put_failure; +if (nla_put_in_addr (skb,IFLA_AMT_DISCOVERY_IP , + amt->discovery_ip)) + goto nla_put_failure; + + remote_ip =READ_ONCE (amt->remote_ip); +if (remote_ip) +if (nla_put_in_addr (skb,IFLA_AMT_REMOTE_IP , remote_ip)) + goto nla_put_failure; + }if (nla_put_u32 (skb,IFLA_AMT_MAX_TUNNELS , amt->max_tunnels)) goto nla_put_failure;
include/uapi/linux/amt.h +13 -0
@@ -54,6 +54,19 @@ enum {IFLA_AMT_DISCOVERY_IP ,/* This attribute specify number of maximum tunnel. */ IFLA_AMT_MAX_TUNNELS , +/* This attribute specifies the local IPv6 address. It selects IPv6 +* as the outer transport and excludes IFLA_AMT_LOCAL_IP. +*/ +IFLA_AMT_LOCAL_IP6 , +/* This attribute specifies the IPv6 address of the relay a gateway +* sends its Discovery to. It is the IPv6 form of +* IFLA_AMT_DISCOVERY_IP and needs IFLA_AMT_LOCAL_IP6. +*/ +IFLA_AMT_DISCOVERY_IP6 , +/* This attribute reports the IPv6 relay address a gateway learned +* from the Relay Advertisement. It is read-only. +*/ +IFLA_AMT_REMOTE_IP6 , __IFLA_AMT_MAX, };
Signature · 1 line
2.47.3
PATCH v2 10/12 MAINTAINERS: amt: cover the amt headers and selftests
In reply to Omar RamadanThe AMT entry lists only drivers/net/amt.c, so get_maintainer.pl does not find the AMT maintainer for changes to include/net/amt.h, include/uapi/linux/amt.h or tools/testing/selftests/net/amt.sh, and this series touches the first two and adds selftests next to the third. Add the two headers, and a glob that covers amt.sh and the new amt_*.sh scripts.
--- MAINTAINERS | 3 +++ 1 file changed, 3 insertions(+)
MAINTAINERS +3 -0
@@ -1506,6 +1506,9 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git F: drivers/net/amt.c +F: include/net/amt.h +F: include/uapi/linux/amt.h +F: tools/testing/selftests/net/amt*.sh ANALOG DEVICES INC AD3530R DRIVER M: Kim Seer Paller <[email protected]>
Signature · 1 line
2.47.3
PATCH v2 11/12 selftests: net: add amt_v6.sh for an IPv6 outer transport
In reply to Omar Ramadanamt.sh runs the gateway and the relay over IPv4; its 2001:db8:: addresses are inner MLD carried in that IPv4 tunnel. Nothing covers the IPv6 outer transport this series adds.
amt_v6.sh is amt.sh with the gateway<->relay link moved to IPv6, and a second gateway on that link:
amtg: mode gateway local 2001:db8:a::1 discovery 2001:db8:a::3
amtg2: mode gateway local 2001:db8:a::4 discovery 2001:db8:a::3
amtr: mode relay local 2001:db8:a::2
The namespaces, inner addresses and smcroute (S,G) routes are those of amt.sh, and the scripts use the same tools, plus jq. The relay forwards to a tunnel only after the gateway's Membership Update, and the gateway sends that only after the relay's Membership Query, so the forwarding checks cover the whole handshake. The test checks that:
- the gateway learns 2001:db8:a::2 from an Advertisement it requested through the relay's second address, 2001:db8:a::3, so the Advertisement has to come from the address the Discovery was sent to;
- IPv4 and IPv6 multicast both reach the listener through the tunnel;
- IPv4 multicast also reaches a listener on the second gateway, which shares the first one's /64 and gateway port, so the relay has to deliver each gateway's Membership Query to that gateway and not to one whose address merely begins the same way;
- with the relay's route MTU to the gateway lowered, an IPv6 payload above the tunnel MTU earns its source a Packet Too Big, and neither is the AMT datagram fragmented nor does it reach IPv6 output, where it would be refused and counted in Ip6FragFails;
- a Relay Discovery sent to ff02::1 draws no reply at all, while the same Discovery sent to the discovery address, the positive control with the same capture filter, draws an Advertisement. This check needs tcpdump and is skipped without it;
- taking amtg down clears the learned relay address, and bringing it up discovers the relay again.
A probe creates a throwaway IPv6 relay first. It skips when the kernel ignores IFLA_AMT_LOCAL_IP6 ("Local attribute is required") or iproute2 cannot pass it, which includes an iproute2 that packs the IPv6 literal into the 4-byte IFLA_AMT_LOCAL_IP: this kernel refuses that, and an older one creates an IPv4 relay, which the probe reads back. Any other failure after the probe, including in setup, is a FAIL. DAD is off in the namespaces: the relay sends its MLD General Query from amtr's link-local address, which must not be tentative at that point.
The script skips when /proc/net/if_inet6 is missing, that is without CONFIG_IPV6, before it creates any link. disc_answer() returns a distinct status when tcpdump fails to start or a send fails, and the ff02::1 check accepts only "no reply", so a broken capture cannot pass it.
The iproute2 side is posted to iproute2-next separately.
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/amt_v6.sh | 355 ++++++++++++++++++++++++++ 2 files changed, 356 insertions(+) create mode 100755 tools/testing/selftests/net/amt_v6.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -9,6 +9,7 @@ CFLAGS += -I../ TEST_PROGS := \ altnames.sh \ amt.sh \ + amt_v6.sh \ arp_ndisc_evict_nocarrier.sh \ arp_ndisc_untracked_subnets.sh \ bareudp.sh \
tools/testing/selftests/net/amt_v6.sh new file +355 -0
355 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v2 11/12] selftests: net: add amt_v6.sh for an IPv6 outer transport
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] probe_v6_relay() in tools/testing/selftests/net/amt_v6.sh is meant to skip in one case it cannot recognise.
- [Medium] selftests: net: probe_v6_relay() fails instead of skipping without CONFIG_AMT
- [Low] The commit message overstates how closely amt_v6.sh mirrors amt.sh.
--
selftests: net: add amt_v6.sh for an IPv6 outer transport
This adds amt_v6.sh, a variant of amt.sh in which the AMT gateway and relay use an IPv6 outer link, with a second gateway on the same link. It checks discovery through a secondary relay address, IPv4 and IPv6 multicast forwarding, tunnel MTU handling, that a Discovery sent to ff02::1 gets no answer, and rediscovery after down/up. A probe skips the test when the kernel or iproute2 lacks IPv6 AMT support.
Quoted 2 lines
amt_v6.shisamt.shwith the gateway<->relay link moved to IPv6, and a second gateway on that link:
[ ... ]
Quoted 2 lines
The namespaces, inner addresses and smcroute (S,G) routes are those of
amt.sh, and the scripts use the same tools, plus jq.
[Severity: Low]
Is "plus jq" accurate? amt.sh already uses jq in test_remote_ip() and test_query_egress().
Also, amt_v6.sh does not carry over test_query_egress() from amt.sh. That test installs clsact and flower egress counters on amtr for IGMP (ip_proto 2) and MLD query (ICMPv6 type 130) packets, and it fails if a relay General Query leaves through the amt device. The send_mcast_torture4 and send_mcast_torture6 runs are not carried over either.
This series adds the IPv6-outer General Query path:
amt_send_igmp_gq() / amt_send_mld_gq()
-> amt_send_membership_query()
Should the egress check be added here as well? If not, could the commit message say that these checks were dropped, instead of describing the script as amt.sh with the link moved to IPv6?
Quoted 6 lines
tools/testing/selftests/net/amt_v6.sh new file +0
-0@@ -0,0 +1,355 @@
[ ... ]
Quoted 11 lines
tools/testing/selftests/net/amt_v6.sh new file +11
-0+# An iproute2 without IPv6 AMT support either rejects the address or packs +# it into the 4-byte IFLA_AMT_LOCAL_IP, which this kernel refuses and an +# older one takes as an IPv4 address. A kernel without IPv6 AMT support +# ignores IFLA_AMT_LOCAL_IP6 and asks for a local address. Skip in those +# cases only. +probe_v6_relay() +{ + local err got + + if ! err=$(ip -n "$RELAY" link add amtprobe type amt mode relay \ + local "$RELAY6" dev br_gw 2>&1); then
tools/testing/selftests/net/amt_v6.sh line 110
Quoted 10 lines
tools/testing/selftests/net/amt_v6.sh new file +10
-0+ case "$err" in + *"Local attribute is required"*|*"expected rather than"*|\ + *"IPv6 address in an IPv4 attribute"*) + echo "SKIP: no IPv6 AMT support: $err" + exit "$ksft_skip" + ;; + esac + echo "FAIL: cannot create an IPv6 relay: $err" + exit "$ksft_fail" + fi
[Severity: Medium]
Does this also skip when the amt link type is not available at all?
On a kernel built without CONFIG_AMT, or where the amt module cannot be loaded, rtnl_link_ops_get() finds no "amt" ops and __rtnl_newlink() returns -EOPNOTSUPP with the extack "Unknown device type". An iproute2 that does not know the amt link type at all rejects the command line before anything reaches the kernel.
Neither error text matches any of the three case patterns. In both cases probe_v6_relay() prints "FAIL: cannot create an IPv6 relay" and exits with ksft_fail. A kselftest run on a config without AMT would then report a failure rather than a skip.
amt.sh avoids the iproute2 half of this with its ip link help check before setup. Should amt_v6.sh do the same? Should it also treat a missing amt device type as a skip, for example by matching "Unknown device type" or by checking that the amt module can be loaded first?
[Severity: Medium]
Does this skip in the packed-attribute case described in the comment above and in the commit message?
If iproute2 packs the 16-byte IPv6 literal into IFLA_AMT_LOCAL_IP, the kernel refuses it during generic netlink policy validation, before amt_validate() runs:
drivers/net/amt.c:amt_policy[] {
...
[IFLA_AMT_LOCAL_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
...
}NLA_POLICY_EXACT_LEN() is an NLA_BINARY range of 4..4. A 16-byte attribute therefore fails in nla_validate_range_unsigned(), which returns -ERANGE with the extack "binary attribute size out of range".
That string matches none of the three patterns. As far as I can tell, nothing in the tree emits "IPv6 address in an IPv4 attribute"; it only appears in amt_v6.sh and amt_gw_v6.sh.
In that case, wouldn't the probe print "FAIL: cannot create an IPv6 relay" and exit with ksft_fail instead of ksft_skip?
probe_v6_gateway() in the later patch "selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes" repeats the same pattern, so this is still there at the end of the series.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125191450.2497936-1-omar%40blockcast.net
PATCH v2 12/12 selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes
In reply to Omar Ramadanamt_v6.sh builds a gateway and a relay over an IPv6 outer transport and checks the data plane, but only with valid attributes. The link-creation rules this series adds for IFLA_AMT_LOCAL_IP6 and IFLA_AMT_DISCOVERY_IP6 are not exercised.
This adds a small companion without a data plane: one netns and one dummy device, no relay, socat or smcroute. It checks that the IPv6 local and discovery addresses of a gateway, and the local address of a relay, read back through amt_fill_info(), that a relay reports no discovery address, that an IPv4 gateway still creates and reports its IPv4 discovery address, and that an IPv4 relay still accepts the IPv4 discovery address it has always ignored. It then checks each rejection:
a gateway without a discovery address, a gateway whose local and discovery addresses differ in family (both ways), an IPv6 relay given a discovery address of either family, an IPv4 relay given an IPv6 one, and an unspecified, loopback, multicast or IPv4-mapped IPv6 local or discovery address. Each rejection is matched on its extack message as well as on the failure, so a rule that fails for the wrong reason is not a pass.
Three cases are left out because iproute2 cannot express them: both discovery <v4> and discovery <v6>, or both local <v4> and local <v6>, in one command, and a 16-byte IFLA_AMT_LOCAL_IP or IFLA_AMT_DISCOVERY_IP. iproute2 rejects the repeated argument before it builds a message, and with IPv6 support it never sends 16 bytes in an IPv4 attribute, so those checks are reachable only from a raw netlink client or an older iproute2.
The probe checks the readback as well as the result. An iproute2 without the IPv6 attributes may pack the first four bytes of the IPv6 literal into the IPv4 attribute, so discovery 2001:db8:a::2 becomes 32.1.13.184 and a kernel without this series builds a valid IPv4 gateway from it; this kernel refuses it ("IPv6 address in an IPv4 attribute"). That refusal is logged as a passing test before the probe skips, since it is the rule an older iproute2 exercises. If such an iproute2 gets an IPv4 device back from a kernel that has the IPv6 attributes, recognised by its "Discovery attribute of the local family is required" message, the refusal is broken and the probe fails. The probe skips on an iproute2 that rejects the literal, on a kernel that ignores the attributes ("Local attribute is required"), and on a kernel without IPv6 ("IPv6 support is disabled", or no /proc/net/if_inet6). Any other failure to create the probe link is a FAIL.
The script uses lib.sh: setup_ns for the namespace, check_err and log_test for reporting, and $ksft_skip when a prerequisite is missing.
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/amt_gw_v6.sh | 207 +++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100755 tools/testing/selftests/net/amt_gw_v6.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -9,6 +9,7 @@ CFLAGS += -I../ TEST_PROGS := \ altnames.sh \ amt.sh \ + amt_gw_v6.sh \ amt_v6.sh \ arp_ndisc_evict_nocarrier.sh \ arp_ndisc_untracked_subnets.sh \
tools/testing/selftests/net/amt_gw_v6.sh new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v2 12/12] selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In probe_v6_gateway() (tools/testing/selftests/net/amt_gw_v6.sh, lines 48-64), the first…
- [Medium] In probe_v6_gateway() (tools/testing/selftests/net/amt_gw_v6.sh, lines 66-80), the probe…
- [Low] selftests: net: missing CONFIG_AMT skip handling in probe_v6_gateway()
--
selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes
This adds a netlink-only companion to amt_v6.sh. It checks that the IPv6 local and discovery addresses of AMT gateways and relays read back through amt_fill_info(), and that each invalid combination is refused with the expected extack message. A probe at the start skips the test when iproute2 or the kernel lacks IPv6 AMT support.
Quoted 5 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +0
-0
[ ... ]
Quoted 14 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +14
-0+probe_v6_gateway() +{ + local got + + if ! add_amt amtprobe mode gateway local "$V6_LOCAL" \ + discovery "$V6_DISC"; then + case "$ADD_ERR" in + *"IPv6 address in an IPv4 attribute"*) + # An older iproute2 on this kernel: the rule that + # refuses the 16-byte IPv4 attribute is what ran. + RET=0 + log_test "16-byte IPv4 address attribute is refused" + echo "SKIP: iproute2 lacks IPv6 AMT support" + exit "$ksft_skip"
tools/testing/selftests/net/amt_gw_v6.sh line 65
Quoted 10 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +10
-0+ ;; + *"Local attribute is required"*|*"expected rather than"*|\ + *"IPv6 support is disabled"*) + echo "SKIP: no IPv6 AMT support: $ADD_ERR" + exit "$ksft_skip" + ;; + esac + echo "FAIL: cannot create an IPv6 gateway: $ADD_ERR" + exit "$ksft_fail" + fi
[Severity: Low]
What happens here on a kernel built without CONFIG_AMT, or where the amt module cannot be loaded?
In that case __rtnl_newlink() in net/core/rtnetlink.c finds no link ops for "amt" and fails the request with -EOPNOTSUPP and the extack message "Unknown device type". ADD_ERR then holds "Error: Unknown device type.", or "RTNETLINK answers: Operation not supported" from an iproute2 that does not print extack. Neither matches any arm of the case statement, so probe_v6_gateway() prints "FAIL: cannot create an IPv6 gateway" and exits with ksft_fail.
An iproute2 with no amt link support at all ends up in the same place. It cannot parse the mode, local and discovery arguments, so it typically fails with "Garbage instead of arguments" before anything is sent to the kernel.
Both are missing prerequisites, not failures of the code under test. The comment above probe_v6_gateway() says only failures of the code under test should be reported as FAIL. amt.sh already handles the iproute2 side by checking ip link help for amt before it starts.
Would it make sense to do the same check here, and to add "Unknown device type" and "Operation not supported" to the skip arm? The test would then report SKIP rather than FAIL on such a setup.
[Severity: Medium]
Can the first case arm in probe_v6_gateway() ever match? I could not find the string "IPv6 address in an IPv4 attribute" anywhere in the kernel tree. It only shows up here and in probe_v6_relay() in amt_v6.sh.
As far as I can tell, the only thing that refuses a 16-byte IFLA_AMT_LOCAL_IP or IFLA_AMT_DISCOVERY_IP is the policy in drivers/net/amt.c:
amt_policy[] {
...
[IFLA_AMT_LOCAL_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
...
[IFLA_AMT_DISCOVERY_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
...
}validate_nla() checks that policy before amt_validate() or amt_newlink() runs. When the length is wrong, nla_validate_range_unsigned() in lib/nlattr.c reports:
if (binary) NL_SET_ERR_MSG_ATTR_POL(extack, nla, pt, "binary attribute size out of range");
Take an iproute2 that packs the IPv6 literal into the IPv4 attribute. Wouldn't ADD_ERR be "Error: binary attribute size out of range." in that case? That string matches none of the arms, so the script reaches the "FAIL: cannot create an IPv6 gateway" exit on a correct kernel, not the intended PASS and SKIP.
The commit message also says:
this kernel refuses it ("IPv6 address in an IPv4 attribute").
Does any rule in this series emit that message? The skip list in probe_v6_relay() in amt_v6.sh has the same pattern, so it would also report FAIL instead of SKIP with such an iproute2.
tools/testing/selftests/net/amt_gw_v6.sh line 77
Quoted 12 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +12
-0+ got=$(amt_field amtprobe discovery) + ip -n "$GW" link del amtprobe + if [[ "$got" != *:* ]]; then + # A kernel with the IPv6 attributes names the missing + # discovery address this way, and must have refused the + # 16-byte IPv4 attribute that an older iproute2 sent. + add_amt amtprobe mode gateway local "$V4_LOCAL" + ip -n "$GW" link del amtprobe 2>/dev/null + if [[ "$ADD_ERR" == *"of the local family is required"* ]]; then + echo "FAIL: 16-byte IPv4 attribute read back as '$got'" + exit "$ksft_fail" + fi
[Severity: Medium]
Can this FAIL branch be reached through anything other than a userspace limitation?
If the probe link was created, the exact-length policy on IFLA_AMT_LOCAL_IP and IFLA_AMT_DISCOVERY_IP means iproute2 sent 4-byte attributes, not 16-byte ones. A readback without a colon here, or an empty one from the "// empty" in amt_field(), would come from one of two sources:
- an iproute2 that truncated 2001:db8:a::1 and 2001:db8:a::2 to 32.1.13.184. The kernel correctly accepts that as a valid IPv4 unicast local and discovery address.
- an iproute2 that prints IFLA_AMT_DISCOVERY_IP6 under a JSON key other than discovery.
The follow-up check then creates an IPv4 gateway with no discovery address. On this kernel, amt_validate() rejects every such gateway with the same message:
if (data[IFLA_AMT_LOCAL_IP6] ? !data[IFLA_AMT_DISCOVERY_IP6] :
!data[IFLA_AMT_DISCOVERY_IP]) {
NL_SET_ERR_MSG_MOD(extack,
"Discovery attribute of the local family is required");So doesn't this branch always print "16-byte IPv4 attribute read back" and exit with ksft_fail, even though the kernel did what it should?
The commit message describes this case as:
If such
an iproute2 gets an IPv4 device back from a kernel that has the IPv6 attributes, recognised by its "Discovery attribute of the local family is required" message, the refusal is broken and the probe fails.
The four truncated bytes cannot be told apart from a real IPv4 address. Is there a kernel refusal that could be broken here, or should this case be a SKIP?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125191450.2497936-1-omar%40blockcast.net