amt: add an IPv6 outer transport
v5 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 needs the same tools as amt.sh (smcroute, socat, nc, jq, tc), and tcpdump for one check that it skips without it.
The series is based on net-next ccb81d5e317b, which carries the six-patch "amt: relay tunnel lifetime, validation and request-path hardening" series (net v7, merged in 24630ff92eff). 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. A relay also drops a packet from the wire whose outer
source is an address of its own host, as IPv4 input does with a
martian: it would answer it to itself over lo. 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, now at v2:
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 v5 (netdev's Sashiko review of v4):
- 2/12 (Medium): a relay's amt_rcv() drops a packet whose outer source is an address that ipv6_chk_addr() finds on a device of the namespace, before it parses the message. IPv4 input refuses such a source as a martian when it comes in from the wire; IPv6 input delivers it, and a forged Discovery or Request would have made the relay answer itself over lo. A packet that arrives over lo comes from the host itself and is not dropped, as for IPv4, so a gateway on the relay's host still reaches it. The check is in 8/12, which holds the receive path, and covers the Request and the Update too. 11/12 sends such a Discovery in from the wire, from a namespace that holds the address on its lo only, and checks that it is dropped and that nothing answers on lo; the same Discovery over lo is answered.
- 5/12 (Medium): not changed in design. The message and the comment say that the transport header is put back to the offset it had on entry, which for a forwarded packet is past a Hop-by-Hop header only; ip6_forward() and ip6_finish_output_gso(), where ip6mr forwarding ends, validate a GSO skb from the same offset, so another extension header is not counted there either.
- 11/12 (Medium, Low, Low): disc_answer() fails the check, with status 2, when tcpdump is still not listening after five seconds, instead of sending anyway; the comment that amtr is NOARP is removed, as ether_setup() clears the flag; no change for the ERR trap in slowwait, which does not fire for the polled command on bash 5.2.
- 12/12 (Low): the header no longer lists a 16-byte attribute as reachable only from a raw netlink client.
Changes in v4 (netdev's Sashiko review of v3):
- 5/12 (Medium): the message says what a forged Packet Too Big does: it lowers the tunnel MTU to 1230, so every multicast payload above that, IPv4 or IPv6, is dropped toward that gateway and its source is told nothing, until the route exception expires. The design is unchanged, as that is what path MTU discovery does to any IPv6 UDP tunnel that must not fragment. Two drops that were not counted are counted in tx_dropped, and two header comments say when no Packet Too Big is sent.
- 12/12 (Medium): the probe skips only on the readback an iproute2 that truncates the literal gives, 32.1.13.184; any other readback without a colon is a FAIL. The nodad comment and the header's list of what is not covered are corrected.
- 11/12: a listener that must get nothing has to be alive at the end, the Discovery capture waits until tcpdump is listening, and the comments on DAD and on the IGMP egress counter are corrected.
- 3/12, 4/12: the messages describe the old read of the source address, the Request handler and the first patch of the series correctly, and the comments that still said per address say source.
- 8/12: the comment and the message no longer say IPv4 input never delivers a 0.0.0.0 source, and amt_route6() refuses ::, which a transmit can read just after a gateway forgot its relay.
- 5/12, 8/12: the messages cite RFC 7450 s5.3.3.6.2.2 with its SSM condition and s5.1.6 as it reads, and describe the old read of the outer source on an IPv6 header correctly.
Changes in v3 (netdev's Sashiko review of v2):
- The base is net-next ccb81d5e317b. Only MAINTAINERS and the net selftests Makefile changed under the series, so 10/12 to 12/12 are rebased and nothing else is.
- 3/12 (Medium): the per-source tunnel cap counts the tunnels of one IPv6 /64, not of one address, as one host usually owns a whole /64 and could otherwise open the cap's worth of tunnels from each of its addresses and keep the table full. A tunnel is still found by its full endpoint, so gateways in one /64 each keep their own tunnel and share the cap. The message no longer says that amt_request_handler() snapshots the source before a pull (Low).
- 5/12 (Medium, Low): amt_dev_xmit() puts the transport header of a data packet back after ipv6_mc_check_mld(), which leaves it just past the fixed IPv6 header, so the per-segment length of an inner IPv6 GSO skb counts any extension headers. amt_tmtu() returns zero, not a wrapped value, for a route MTU below the outer headers.
- 2/12 (Low): the message says that a drop after the hand-off to IPv6 output is not counted in tx_errors, as the sender passes no netdev.
- 4/12 (Low): the comment of amt_send_membership_query() says that the endpoint is passed by pointer.
- 6/12 (Low): the message names the right drop site, the tunnel MTU check, and no longer claims that ip6_fragment() drops the packet.
- 8/12 (Low): the exact-length check of an Advertisement applies to an IPv6 gateway only, so an IPv4 gateway behaves as it always did. The message says so.
- 11/12 (Medium, Medium, Low): the probe skips on "binary attribute size out of range", which is what this kernel says to an iproute2 that packs an IPv6 literal into the IPv4 attribute, and on an iproute2 or kernel without amt, instead of failing; the egress check of amt.sh is ported, and a third gateway in the first gateways' /64 is checked to get no tunnel while one in another /64 does. The message no longer says "plus jq" and names the checks that are not carried over.
- 12/12 (Medium, Medium, Low): the same probe fixes; a readback that is not an IPv6 address is a skip, as four truncated bytes cannot be told from an IPv4 address.
- Not changed: the IPv4 Advertisement is still sent from local_ip, and the IPv6 tunnel MTU still follows the route's path MTU.
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 | 941 ++++++++++++++++++----- include/net/amt.h | 62 +- include/uapi/linux/amt.h | 13 + tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/amt_gw_v6.sh | 221 ++++++ tools/testing/selftests/net/amt_v6.sh | 564 ++++++++++++++ 7 files changed, 1595 insertions(+), 211 deletions(-) create mode 100755 tools/testing/selftests/net/amt_gw_v6.sh create mode 100755 tools/testing/selftests/net/amt_v6.sh
base-commit: ccb81d5e317b0ae2cc66ca1c628c0ca907928f94
PATCH v5 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 @@ drop: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 */
PATCH v5 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. Passing no netdev also means that a drop after the hand-off to IPv6 output, in netfilter, in neighbour resolution or by the qdisc, is not counted in tx_errors, whereas the IPv4 senders count an ip_local_out() error; only a failed route lookup or allocation is counted.
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 @@ out: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,
[email protected]
AI reviewRe: [PATCH net-next v5 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] Both the commit message and the new comment above struct amt_header_advertisement_v6 in include/net/amt.h ("s5.2 selects the…
--
amt: send the Relay Advertisement over IPv6
This adds struct amt_header_advertisement_v6 and amt_send_advertisement_v6(), which send the 24-byte IPv6 form of the Relay Advertisement. They use a new amt_send_ctrl_v6()/amt_route6() pair built on udp_tunnel6_xmit_skb(). On an IPv6 device, amt_discovery_handler() answers a Discovery with this form, sent from the address the Discovery was sent to; amt_v6() is still false for every device, so there is no functional change yet.
include/net/amt.h struct amt_header_advertisement { · line 140
Quoted 13 lines
include/net/amt.h +5
-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. +*/
[Severity: Low]
Is this an accurate reading of RFC 7450?
As far as I can tell, section 5.1.2.1 says the Relay Address field holds either an IPv4 or an IPv6 address, and the length of the Advertisement tells you which. Section 5.2 is about gateway operation. It doesn't seem to tie the Advertisement family to the outer header version.
The commit message makes the same claim:
... 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.
So does the new comment in amt_discovery_handler():
/* The Advertisement takes the form of the outer IP version, and
* RFC 7450 s5.1.2 sources it from the address the Discovery was
...A later patch in this series, "amt: receive the AMT gateway control plane over IPv6", describes it differently in amt_advertisement_handler():
/* The two forms differ only in their length. An IPv6 device's family
* picks one, so a message of the other form is not accepted; an IPv4
* device keeps the minimum-length check it always had. */
That comment reads as though length is what tells the two forms apart, and matching the Advertisement family to the device's outer family is a choice this driver makes.
The code looks fine. Could this header comment, the comment in amt_discovery_handler() and the commit message describe this as driver policy rather than something RFC 7450 s5.2 requires?
Quoted 1 line
include/net/amt.h +1
-0+struct amt_header_advertisement_v6 {
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130064249.1874523-1-omar%40blockcast.net
PATCH v5 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 would read four bytes from the middle of the IPv6 source 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_update_handler() takes that snapshot before pskb_may_pull() and iptunnel_pull_header() can reallocate the header; amt_request_handler() takes it after its only pskb_may_pull() and pulls nothing more. amt_update_handler() passes it to amt_update_tunnel(), which hands it on to amt_tunnel_get_or_create() and amt_tunnel_lookup(); amt_request_handler() walks the tunnel list itself, with the same matching, and uses the snapshot for the MAC and the Query. Tunnels are matched on their endpoint with the existing amt_addr_equal(); the union is zero-padded for IPv4, so one memcmp() serves both families.
The per-source tunnel cap counts differently. An IPv6 host normally owns a whole /64, so a count per address would let it open the cap's worth of tunnels from each of its addresses and keep the table full. amt_request_handler() and amt_tunnel_get_or_create() count the tunnels of one source with amt_same_source(), which compares the whole address for IPv4 and the /64 for IPv6. Gateways that share a /64 share the cap; each still has its own tunnel, found by its full endpoint. The kernel-doc and comments of the cap say source, not address.
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 | 120 ++++++++++++++++++++++++++++++++-------------- include/net/amt.h | 22 +++++---- 2 files changed, 98 insertions(+), 44 deletions(-)
drivers/net/amt.c +85 -35
@@ -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;
@@ -189,6 +215,23 @@ static bool amt_addr_equal(union amt_addr *a, union amt_addr *b)return !memcmp (a, b,sizeof (union amt_addr )); } +/* Bytes of an IPv6 source that make up its /64. */ +#define AMT_SRC_PREFIX6_LEN 8 + +/* Whether @a and @b are one source for the per-source tunnel cap. An IPv6 +* host normally owns a whole /64, so counting per address would let it +* reach the cap from each of its addresses and fill the table; the cap +* therefore counts per /64. For IPv4 a source is an address. Tunnels +* themselves are still found by their full endpoint. +*/ +static bool amt_same_source (const struct amt_dev *amt, +const union amt_addr *a,const union amt_addr *b) +{ +if (amt_v6 (amt)) +return !memcmp (&a->ip6, &b->ip6,AMT_SRC_PREFIX6_LEN ); +return a->ip4 == b->ip4; +} +static u32 amt_source_hash (struct amt_tunnel_list *tunnel,union amt_addr *src) {u32 hash =jhash (src,sizeof (*src), tunnel->amt->hash_seed);
@@ -701,10 +744,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 +1341,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,20 +2777,22 @@ 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; }return NULL ; } -/* Most tunnels one source address may hold: an eighth of the table, at -* least one and at most AMT_MAX_TUNNELS_PER_SRC. +/* Most tunnels one source (an IPv4 address or an IPv6 /64) may hold: an +* eighth of the table, at least one and at most AMT_MAX_TUNNELS_PER_SRC. */ static u32 amt_max_tunnels_per_src (const struct amt_dev *amt) {
@@ -2756,10 +2807,10 @@ static u32 amt_max_tunnels_per_src(const struct amt_dev *amt)* bounds the number of *verified* gateways rather than the number of * unverified Requests anyone can send. A per-source cap derived from the * table, amt_max_tunnels_per_src(), additionally limits the tunnels one -* verified source address may hold. +* verified source (an IPv4 address or an IPv6 /64) 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;
@@ -2776,12 +2827,14 @@ static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,* count how many tunnels this source already holds on the same walk. * Skip dead tunnels, as amt_tunnel_lookup() and the Request path do, so * a tunnel being freed neither stands in for its endpoint nor counts -* against its address. +* against its source. */ list_for_each_entry (tunnel, &amt->tunnel_list, list) { -if (tunnel->ip4 != saddr ||READ_ONCE (tunnel->dead)) +if (!amt_same_source (amt, &tunnel->addr, saddr) || +READ_ONCE (tunnel->dead))continue ; -if (tunnel->source_port == sport) { +if (amt_addr_equal (&tunnel->addr, saddr) && + tunnel->source_port == sport) {spin_unlock_bh (&amt->lock);return tunnel; }
@@ -2808,7 +2861,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 +2891,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 +2931,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 +2964,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 +2998,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 +3017,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 +3216,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 +3225,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,10 +3249,12 @@ 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_same_source (amt, &tunnel->addr, &saddr) || +READ_ONCE (tunnel->dead))continue ; per_src++; -if (tunnel->source_port == udph->source) +if (amt_addr_equal (&tunnel->addr, &saddr) && + tunnel->source_port == udph->source) have = true; }rcu_read_unlock ();
@@ -3210,15 +3263,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 +13 -9
@@ -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
@@ -424,7 +428,7 @@ struct amt_dev {#define AMT_SECRET_TIMEOUT 60000#define IANA_AMT_UDP_PORT 2268#define AMT_MAX_TUNNELS 128 -/* Upper bound of amt_max_tunnels_per_src(), the per-address tunnel cap */ +/* Upper bound of amt_max_tunnels_per_src(), the per-source tunnel cap */ #define AMT_MAX_TUNNELS_PER_SRC 16#define AMT_MAX_REQS 128#define AMT_GW_HLEN (sizeof(struct iphdr) + \
[email protected]
AI reviewRe: [PATCH net-next v5 03/12] amt: key relay tunnels on a union amt_addr endpoint
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] For an IPv6 relay, the per-source tunnel cap treats each /64 as one source.
--
amt: key relay tunnels on a union amt_addr endpoint
This commit stores the relay's tunnel endpoint as a union amt_addr instead of a __be32, so the field can hold an IPv6 outer source. It switches the Membership Update MAC to a single siphash() over the packed {address, port, nonce} tuple. It also makes the per-source tunnel cap treat an IPv6 /64 as one source.
Quoted 4 lines
drivers/net/amt.c +0
-0
[ ... ]
Quoted 10 lines
drivers/net/amt.c +6
-0@@ -189,6 +215,23 @@ static bool amt_addr_equal(union amt_addr *a, union amt_addr *b)return !memcmp (a, b,sizeof (union amt_addr )); } +/* Bytes of an IPv6 source that make up its /64. */ +#define AMT_SRC_PREFIX6_LEN 8 + +/* Whether @a and @b are one source for the per-source tunnel cap. An IPv6 +* host normally owns a whole /64, so counting per address would let it +* reach the cap from each of its addresses and fill the table; the cap
drivers/net/amt.c static bool amt_addr_equal(union amt_addr *a, union amt_addr *b) · line 233
Quoted 10 lines
drivers/net/amt.c +10
-0+* therefore counts per /64. For IPv4 a source is an address. Tunnels +* themselves are still found by their full endpoint. +*/ +static bool amt_same_source (const struct amt_dev *amt, +const union amt_addr *a,const union amt_addr *b) +{ +if (amt_v6 (amt)) +return !memcmp (&a->ip6, &b->ip6,AMT_SRC_PREFIX6_LEN ); +return a->ip4 == b->ip4; +}
[Severity: Medium]
With the cap counted per /64, can a single IPv6 subscriber still fill the relay's tunnel table?
The commit message says a per-address count "would let it open the cap's worth of tunnels from each of its addresses and keep the table full". The same reasoning seems to apply one level up. End sites are usually delegated a /56 or /48, and residential DHCPv6-PD often hands out a /56 or /60. That gives one party between 16 and 65536 distinct /64 sources.
amt_max_tunnels_per_src() is:
return clamp_t(u32, amt->max_tunnels / 8, 1, AMT_MAX_TUNNELS_PER_SRC);
With the default AMT_MAX_TUNNELS of 128 this is 16, so eight /64s are enough to reach max_tunnels. To get a valid MAC for an endpoint, the attacker only has to receive the Membership Query at that address. Anyone who holds a routed prefix can do that:
amt_request_handler() per_src counted only within one /64,
Query sent with MACamt_update_handler() amt_relay_mac() verified
-> amt_update_tunnel()
-> amt_tunnel_get_or_create() tunnel created
When the table is full, amt_request_handler() withholds the Query, and amt_tunnel_get_or_create() returns NULL for new legitimate gateways. On IPv4 the same attack needs eight separate public addresses.
This path can't be reached at this commit because amt_v6() is always false. It becomes reachable once IFLA_AMT_LOCAL_IP6 is added in "amt:
add netlink attributes for an IPv6 outer transport", and the per-/64 policy is still the same there.
The commit message covers the cost in the other direction: gateways that share a /64, including all of fe80::/64, share one cap of at most 16. It doesn't mention this case.
Would a shorter prefix, or an extra cap at a shorter prefix, fit the stated rationale better? If not, could the commit message at least describe this limitation?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130064249.1874523-1-omar%40blockcast.net
PATCH v5 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. The Query is built here and has none; the Multicast Data and Membership Update sent through this helper later do.
amt_send_membership_query() sizes its headroom for the outer family with amt_ip_hlen(), builds the AMT header and hands the skb to amt_udp_xmit(). The route lookup now runs after the header push; on a route failure the caller still frees the skb. Nothing sets amt->local_ipv6 yet, so amt_v6() is false for every device and the IPv6 branch of amt_udp_xmit() cannot run; the only change that takes effect is that the IPv4 route lookup now runs after the header push.
The v6 argument keeps its meaning: it selects the inner protocol, IGMP or MLD, which is independent of the outer family, so an IPv6 relay queries for both. The relay's General Query, which amt_send_igmp_gq() and amt_send_mld_gq() send through amt_send_membership_query(), takes the IPv6 path once a device can have one. Both now take the gateway's endpoint as a union amt_addr, as amt_send_membership_query() does.
--- drivers/net/amt.c | 127 +++++++++++++++++++++++++++++++--------------- 1 file changed, 86 insertions(+), 41 deletions(-)
drivers/net/amt.c +86 -41
@@ -98,6 +98,12 @@ static bool amt_v6(const struct amt_dev *amt)return IS_ENABLED (CONFIG_IPV6 ) && !ipv6_addr_any (&amt->local_ipv6); } +/* Length of the outer IP header for the device's family. */ +static unsigned int amt_ip_hlen (const struct amt_dev *amt) +{ +return amt_v6 (amt) ?sizeof (struct ipv6hdr ) :sizeof (struct iphdr ); +} +/* Snapshot the outer source address of a received AMT message. */ static void amt_outer_saddr (const struct amt_dev *amt,const struct sk_buff *skb,union amt_addr *addr)
@@ -1014,16 +1020,17 @@ out:static bool amt_send_membership_query (struct amt_dev *amt,struct sk_buff *skb, -__be32 daddr,__be16 dport, +const union amt_addr *daddr, +__be16 dport,__be32 nonce,u64 mac,bool v6); -/* The destination is passed by value rather than as a tunnel: a Request is -* unauthenticated, so no tunnel state is created or changed for it - see -* amt_request_handler(). +/* The destination is a pointer to the caller's copy of the endpoint, not a +* tunnel: a Request is unauthenticated, so no tunnel state is created or +* changed for it - see amt_request_handler(). */ -static void amt_send_igmp_gq (struct amt_dev *amt,__be32 daddr,__be16 dport, -__be32 nonce,u64 mac) +static void amt_send_igmp_gq (struct amt_dev *amt,const union amt_addr *daddr, +__be16 dport,__be32 nonce,u64 mac) {struct sk_buff *skb;
@@ -1112,8 +1119,8 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt)return skb; } -static void amt_send_mld_gq (struct amt_dev *amt,__be32 daddr,__be16 dport, -__be32 nonce,u64 mac) +static void amt_send_mld_gq (struct amt_dev *amt,const union amt_addr *daddr, +__be16 dport,__be32 nonce,u64 mac) {struct sk_buff *skb;
@@ -1129,8 +1136,8 @@ static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport, } }#else -static void amt_send_mld_gq (struct amt_dev *amt,__be32 daddr,__be16 dport, -__be32 nonce,u64 mac) +static void amt_send_mld_gq (struct amt_dev *amt,const union amt_addr *daddr, +__be16 dport,__be32 nonce,u64 mac) { }#endif
@@ -1247,6 +1254,66 @@ static void amt_req_work(struct work_struct *work) msecs_to_jiffies(100)); } +/* Route an AMT-encapsulated skb to @daddr and send it over the device's +* outer family. The caller has already pushed the AMT header; @dscp only +* steers the IPv4 route lookup. +*/ +static int amt_udp_xmit (struct amt_dev *amt,struct sock *sk, +struct sk_buff *skb,const union amt_addr *daddr, +__be16 sport,__be16 dport,dscp_t dscp) +{ +struct rtable *rt; +struct flowi4 fl4; + +if (amt_v6 (amt)) { +struct dst_entry *dst; + + dst =amt_route6 (amt, sk, &amt->local_ipv6, &daddr->ip6, + sport, dport); +if (IS_ERR (dst)) { +netdev_dbg (amt->dev,"no route to %pI6c\n" , + &daddr->ip6); +return PTR_ERR (dst); + } +/* iptunnel_xmit() scrubs the IPv4 tunnel skb, but +* udp_tunnel6_xmit_skb() does not, so drop the inner +* packet's conntrack and extensions here. Links cannot +* cross netns, so this is never xnet. +*/ +skb_scrub_packet (skb, false); +udp_tunnel6_xmit_skb (dst, sk, skb, amt->dev, &amt->local_ipv6, + &daddr->ip6,AMT_TOS , +ip6_dst_hoplimit (dst),0 , sport, dport, + false,0 ); +return 0 ; + } + +memset (&fl4,0 ,sizeof (struct flowi4 )); + fl4.flowi4_oif = amt->stream_dev->ifindex; + fl4.daddr = daddr->ip4; + fl4.saddr = amt->local_ip; + fl4.flowi4_dscp = dscp; + fl4.flowi4_proto =IPPROTO_UDP ; + rt =ip_route_output_key (amt->net, &fl4); +if (IS_ERR (rt)) { +netdev_dbg (amt->dev,"no route to %pI4\n" , &daddr->ip4); +return PTR_ERR (rt); + } + +udp_tunnel_xmit_skb (rt, sk, skb, + fl4.saddr, + fl4.daddr, +AMT_TOS , +ip4_dst_hoplimit (&rt->dst), +0 , + sport, + dport, + false, + false, +0 ); +return 0 ; +} +static bool amt_send_membership_update (struct amt_dev *amt,struct sk_buff *skb,bool v6)
@@ -1377,17 +1444,17 @@ static void amt_send_multicast_data(struct amt_dev *amt,* * No per-source state is read or created: the gateway echoes the nonce and * the keyed MAC in its Membership Update, where the MAC is recomputed, so -* everything this needs is passed by value. +* everything this needs is passed in: the nonce and the MAC by value, the +* endpoint as a pointer to the caller's copy. */ static bool amt_send_membership_query (struct amt_dev *amt,struct sk_buff *skb, -__be32 daddr,__be16 dport, +const union amt_addr *daddr, +__be16 dport,__be32 nonce,u64 mac,bool v6) {struct amt_header_membership_query *amtmq; -struct rtable *rt; -struct flowi4 fl4;struct sock *sk;int err;
@@ -1396,23 +1463,11 @@ static bool amt_send_membership_query(struct amt_dev *amt,return true; err =skb_cow_head (skb,LL_RESERVED_SPACE (amt->dev) +sizeof (*amtmq) + -sizeof (struct iphdr ) +sizeof (struct udphdr )); +amt_ip_hlen (amt) +sizeof (struct udphdr ));if (err)return true;skb_reset_inner_headers (skb); -memset (&fl4,0 ,sizeof (struct flowi4 )); - fl4.flowi4_oif = amt->stream_dev->ifindex; - fl4.daddr = daddr; - fl4.saddr = amt->local_ip; - fl4.flowi4_dscp =inet_dsfield_to_dscp (AMT_TOS ); - fl4.flowi4_proto =IPPROTO_UDP ; - rt =ip_route_output_key (amt->net, &fl4); -if (IS_ERR (rt)) { -netdev_dbg (amt->dev,"no route to %pI4\n" , &daddr); -return true; - } - amtmq =skb_push (skb,sizeof (*amtmq)); amtmq->version =0 ; amtmq->type =AMT_MSG_MEMBERSHIP_QUERY ;
@@ -1426,18 +1481,8 @@ static bool amt_send_membership_query(struct amt_dev *amt,skb_set_inner_protocol (skb,htons (ETH_P_IP )); 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)
@@ -3265,10 +3310,10 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) mac =amt_relay_mac (&saddr, udph->source, amtrh->nonce, &key);if (!amtrh->p) -amt_send_igmp_gq (amt, saddr.ip4, udph->source, amtrh->nonce, +amt_send_igmp_gq (amt, &saddr, udph->source, amtrh->nonce, mac);else -amt_send_mld_gq (amt, saddr.ip4, udph->source, amtrh->nonce, +amt_send_mld_gq (amt, &saddr, udph->source, amtrh->nonce, mac);return false;
PATCH v5 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 one for which amt_udp_xmit() finds no route is freed with a drop reason; before, nothing recorded the drop, as amt_dev_xmit() returns NETDEV_TX_OK for the packet. The inner protocol stays independent of the outer family, so an IPv6 tunnel carries both IPv4 and IPv6 multicast.
RFC 7450 s5.3.3.6.3.2 forbids a Fragment header on a Multicast Data message sent over IPv6, and s5.3.3.6.2.2 wants a payload that exceeds the tunnel MTU dropped and, if it came from an SSM source, a Packet Too Big sent to it. This series sends one to any IPv6 source. The device MTU is derived from the link MTU only, so a smaller path MTU to a gateway is found at the route. The scrub in amt_udp_xmit() clears ignore_df, so ip6_fragment() never adds a Fragment header, but on its own it drops such a packet and sends the Packet Too Big to the relay itself. amt_send_multicast_data() therefore routes first and compares the inner packet with the route's MTU less the outer headers and the AMT header. The device offers software GSO, so a GSO skb is checked per segment with skb_gso_validate_network_len(), before the tunnel offloads are set up. A payload that does not fit is dropped.
The inner IPv6 packet may carry extension headers. ipv6_mc_check_mld() leaves the transport header just past the fixed header, also for a packet it rejects as not MLD, and the per-segment length of a GSO skb is taken from that offset, so amt_dev_xmit() puts the transport header of a data packet back before it is checked and sent, to the offset it had on entry. For a forwarded packet that is the receive path's: ip6_rcv_core() sets it just past the fixed header and ipv6_parse_hopopts() moves it past a Hop-by-Hop header, and nothing on the forwarding path moves it past another extension header. Those are then not counted in the per-segment length, here as in ip6_forward() and in ip6_finish_output_gso(), where ip6mr forwarding ends, which validate a GSO skb the same way. A route MTU below the outer headers gives a tunnel MTU of zero instead of a wrapped one: every payload is dropped, and none is sent a Packet Too Big.
A multicast packet can match every tunnel, and an attacker can create tunnels, so the Packet Too Big is not sent per tunnel. Each failing tunnel only lowers a value, and amt_dev_xmit() sends one Packet Too Big through icmpv6_ndo_send(), as ip6_tunnel does, after it has walked all tunnels, reporting the smallest failing tunnel MTU. A tunnel MTU below IPV6_MIN_MTU is left out, as a source ignores a smaller Packet Too Big, so such a tunnel only drops the payload. The inner version is the v6 flag the caller already computed, not skb->protocol.
The tunnel MTU follows the route's path MTU, which ICMPv6 Packet Too Big messages lower, as it does on every IPv6 UDP tunnel in the tree. RFC 7450 s5.3.3.6.1 and s6.1 ask a relay that adjusts the tunnel MTU dynamically to offer a way to turn that off. The IPv6 stack gives a tunnel no such way: udpv6_err() records the lowered MTU in a route exception before it looks up a socket, "mtu lock" does not stop it (IPv6 path MTU discovery is not optional, see __ip6_rt_update_pmtu()), and ip6_skb_dst_mtu() ignores the socket's pmtudisc inside a tunnel's transmit. This series does not add one. The route MTU never drops below IPV6_MIN_MTU, as a smaller Packet Too Big is ignored. A forged Packet Too Big, which anyone who can send ICMPv6 to the relay can aim at a gateway's address, therefore lowers the tunnel MTU to 1280 bytes less the 50 of the IPv6, UDP and AMT headers, 1230, until the route exception expires, 10 minutes by default. Every multicast payload above that, IPv4 or IPv6, is then dropped toward that gateway, and its source is told nothing, as 1230 is below the 1280 a Packet Too Big can ask for. That is what path MTU discovery does to an IPv6 UDP tunnel that must not fragment.
skb_tunnel_check_pmtu() is not used: with reply false it only updates the route's PMTU and sends nothing. An IPv4 payload is dropped without an ICMP error, since icmp_send() does not answer multicast datagrams, and it is not fragmented before encapsulation as s5.3.3.6.2.1 asks for DF=0. The IPv4 tunnel does not do that either; it clears DF on the outer header instead.
With this, every relay message has an IPv6 path: Discovery and Advertisement, Request and Membership Query, Membership Update and Multicast Data.
--- drivers/net/amt.c | 145 +++++++++++++++++++++++++++++++++------------- 1 file changed, 104 insertions(+), 41 deletions(-)
drivers/net/amt.c +104 -41
@@ -1254,26 +1254,55 @@ static void amt_req_work(struct work_struct *work) msecs_to_jiffies(100)); } +/* RFC 7450 s5.3.3.6: a Multicast Data message sent over IPv6 must not +* carry a Fragment header, so a payload larger than the tunnel MTU is +* dropped, and an IPv6 source is sent a Packet Too Big, unless the tunnel +* MTU is below IPV6_MIN_MTU, which a source would ignore. An IPv4 source is +* not told, as icmp_send() never answers a multicast datagram. The tunnel +* MTU follows the route's path MTU, as on every IPv6 UDP tunnel. +*/ +static u32 amt_tmtu (const struct dst_entry *dst) +{ +u32 hlen =sizeof (struct ipv6hdr ) +sizeof (struct udphdr ) + +sizeof (struct amt_header_mcast_data ); +u32 mtu =dst_mtu (dst); + +return mtu > hlen ? mtu - hlen :0 ; +} + +/* True if @skb, the inner packet before encapsulation, or any segment of +* it, is larger than @tmtu. +*/ +static bool amt_tmtu_exceeded (const struct sk_buff *skb,u32 tmtu) +{ +if (skb_is_gso (skb)) +return !skb_gso_validate_network_len (skb, tmtu); +return skb->len > tmtu; +} +/* Route an AMT-encapsulated skb to @daddr and send it over the device's * outer family. The caller has already pushed the AMT header; @dscp only -* steers the IPv4 route lookup. +* steers the IPv4 route lookup. Over IPv6 the caller may pass the route it +* already looked up in @dst, which is consumed; otherwise it is looked up +* here. */ static int amt_udp_xmit (struct amt_dev *amt,struct sock *sk,struct sk_buff *skb,const union amt_addr *daddr, -__be16 sport,__be16 dport,dscp_t dscp) +__be16 sport,__be16 dport,dscp_t dscp, +struct dst_entry *dst) {struct rtable *rt;struct flowi4 fl4;if (amt_v6 (amt)) { -struct dst_entry *dst; - - dst =amt_route6 (amt, sk, &amt->local_ipv6, &daddr->ip6, - sport, dport); -if (IS_ERR (dst)) { -netdev_dbg (amt->dev,"no route to %pI6c\n" , - &daddr->ip6); -return PTR_ERR (dst); +if (!dst) { + dst =amt_route6 (amt, sk, &amt->local_ipv6, + &daddr->ip6, sport, dport); +if (IS_ERR (dst)) { +netdev_dbg (amt->dev,"no route to %pI6c\n" , + &daddr->ip6); +return PTR_ERR (dst); + } }/* iptunnel_xmit() scrubs the IPv4 tunnel skb, but * udp_tunnel6_xmit_skb() does not, so drop the inner
@@ -1374,26 +1403,60 @@ static bool amt_send_membership_update(struct amt_dev *amt,return false; } +/* Send the relay's copy of a multicast packet to one gateway. Over IPv6 a +* payload that does not fit the tunnel MTU is dropped, and *@ptb is lowered +* to that MTU, if it is at least IPV6_MIN_MTU, so that amt_dev_xmit() can +* send a single Packet Too Big to the source once it has walked every +* tunnel. It does so for an IPv6 source only, whatever the payload. +*/ static void amt_send_multicast_data (struct amt_dev *amt,const struct sk_buff *oskb,struct amt_tunnel_list *tunnel, -bool v6) +bool v6,u32 *ptb) {struct amt_header_mcast_data *amtmd; +struct dst_entry *dst =NULL ;struct sk_buff *skb; -struct iphdr *iph; -struct flowi4 fl4; -struct rtable *rt;struct sock *sk; +int err; sk =rcu_dereference_bh (amt->sk);if (!sk)return ; - skb =skb_copy_expand (oskb,sizeof (*amtmd) +sizeof (*iph) + +if (amt_v6 (amt)) { +u32 tmtu; + + dst =amt_route6 (amt, sk, &amt->local_ipv6, &tunnel->addr.ip6, + amt->relay_port, tunnel->source_port); +if (IS_ERR (dst)) { +netdev_dbg (amt->dev,"no route to %pI6c\n" , + &tunnel->addr.ip6); +DEV_STATS_INC (amt->dev, tx_dropped); +return ; + } + + tmtu =amt_tmtu (dst); +if (amt_tmtu_exceeded (oskb, tmtu)) { +dst_release (dst); +/* A source ignores a Packet Too Big below +* IPV6_MIN_MTU, so a tunnel that small is only +* dropped for. +*/ +if (tmtu >=IPV6_MIN_MTU && (!*ptb || tmtu < *ptb)) + *ptb = tmtu; +DEV_STATS_INC (amt->dev, tx_dropped); +return ; + } + } + + skb =skb_copy_expand (oskb,sizeof (*amtmd) +amt_ip_hlen (amt) +sizeof (struct udphdr ),0 ,GFP_ATOMIC ); -if (!skb) +if (!skb) { +dst_release (dst); +DEV_STATS_INC (amt->dev, tx_dropped);return ; + }/* amt_dev_xmit() pulled the Ethernet header without moving the mac * header. The tunnelled payload has no link-layer header, so the
@@ -1402,18 +1465,8 @@ static void amt_send_multicast_data(struct amt_dev *amt,skb_reset_mac_header (skb);skb_reset_inner_headers (skb);if (udp_tunnel_handle_offloads (skb, true)) { -kfree_skb (skb); -return ; - } - -memset (&fl4,0 ,sizeof (struct flowi4 )); - fl4.flowi4_oif = amt->stream_dev->ifindex; - fl4.daddr = tunnel->addr.ip4; - fl4.saddr = amt->local_ip; - fl4.flowi4_proto =IPPROTO_UDP ; - rt =ip_route_output_key (amt->net, &fl4); -if (IS_ERR (rt)) { -netdev_dbg (amt->dev,"no route to %pI4\n" , &tunnel->addr.ip4); +dst_release (dst); +DEV_STATS_INC (amt->dev, tx_dropped);kfree_skb (skb);return ; }
@@ -1427,17 +1480,12 @@ static void amt_send_multicast_data(struct amt_dev *amt,skb_set_inner_protocol (skb,htons (ETH_P_IP )); 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.
@@ -1482,7 +1530,7 @@ static bool amt_send_membership_query(struct amt_dev *amt,else skb_set_inner_protocol (skb,htons (ETH_P_IPV6 ));return amt_udp_xmit (amt, sk, skb, daddr, amt->relay_port, dport, -inet_dsfield_to_dscp (AMT_TOS )); +inet_dsfield_to_dscp (AMT_TOS ),NULL ); }static netdev_tx_t amt_dev_xmit (struct sk_buff *skb,struct net_device *dev)
@@ -1500,6 +1548,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)struct iphdr *iph;bool data = false;bool v6 = false; +u32 ptb =0 ;u32 hash; iph =ip_hdr (skb);
@@ -1524,6 +1573,9 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) group.ip4 =ip_hdr (skb)->daddr;#if IS_ENABLED (CONFIG_IPV6 ) } else if (iph->version == 6) { +bool th_set =skb_transport_header_was_set (skb); +int th_off = th_set ?skb_transport_offset (skb) :0 ; + ip6h =ipv6_hdr (skb);if (!ipv6_addr_is_multicast (&ip6h->daddr)) goto free;
@@ -1540,6 +1592,15 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) } }else { data = true; +/* ipv6_mc_check_mld() set the transport header +* just past the fixed IPv6 header, even when +* extension headers follow, which would make the +* segments of a GSO skb look shorter than they +* are. Put it back to the offset it had on entry, +* which the forwarding path also relies on. +*/ +if (th_set) +skb_set_transport_header (skb, th_off); } v6 = true; group.ip6 =ipv6_hdr (skb)->daddr;
@@ -1593,8 +1654,10 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) }continue ; found: -amt_send_multicast_data (amt, skb, tunnel, v6); +amt_send_multicast_data (amt, skb, tunnel, v6, &ptb); } +if (ptb && v6) +icmpv6_ndo_send (skb,ICMPV6_PKT_TOOBIG ,0 , ptb); }dev_kfree_skb (skb);
[email protected]
AI reviewRe: [PATCH net-next v5 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] In amt_send_multicast_data() (drivers/net/amt.c), a tunnel's MTU is dst_mtu() of the route to the gateway minus 50 (amt_tmtu(),…
- [Low] The commit message of "amt: forward multicast data over IPv6" describes the IPv6 Multicast Data path as if it takes effect here.
--
amt: forward multicast data over IPv6
This commit sends the relay's copy of a multicast packet through amt_udp_xmit(), so it can go over an IPv6 outer transport. Over IPv6 it looks up the route first and drops a payload that exceeds the route MTU less the outer and AMT headers. After walking all tunnels it sends one ICMPv6 Packet Too Big to an IPv6 source.
Quoted 3 lines
amt_send_multicast_data()routes and transmits the relay's copy of a multicast packet only over IPv4, so an IPv6 relay could establish tunnels but not deliver traffic through them.
[ ... ]
Quoted 4 lines
sent is still freed, but it is now counted in
tx_dropped, and one for whichamt_udp_xmit()finds no route is freed with a drop reason; before, nothing recorded the drop, asamt_dev_xmit()returnsNETDEV_TX_OKfor the packet.
[Severity: Low]
This isn't a bug, but is this description accurate for this commit?
At this point nothing writes amt->local_ipv6, so amt_v6() is false for every device:
drivers/net/amt.c:amt_v6() {
return IS_ENABLED(CONFIG_IPV6) && !ipv6_addr_any(&amt->local_ipv6);
}So none of these can run yet:
- the new IPv6 branch of amt_send_multicast_data()
- amt_tmtu() and amt_tmtu_exceeded()
- the icmpv6_ndo_send() call in amt_dev_xmit()
They only become reachable once "amt: add netlink attributes for an IPv6 outer transport" adds IFLA_AMT_LOCAL_IP6. The other patches in the series before that one say that amt_v6() is still false, or that there is no functional change.
The changes that do take effect here all hit existing IPv4-outer relays:
- tx_dropped is now counted on copy, offload and route failures.
- A no-route drop now carries SKB_DROP_REASON_IP_OUTNOROUTES. The old kfree_skb() already recorded a drop with NOT_SPECIFIED, so "nothing recorded the drop" is only true of the device stats.
- For IPv6-inner multicast data, amt_dev_xmit() now restores the transport header after ipv6_mc_check_mld(). skb_reset_inner_headers() then copies that offset into inner_transport_header of the IPv4 UDP tunnel skb.
The commit message explains the transport header restore only as input to the IPv6 MTU check, which can't run yet.
Could the message say which changes take effect at this commit? Could it also say that the restore changes how IPv4 relays handle IPv6 multicast?
Quoted 23 lines
drivers/net/amt.c +15
-0@@ -1254,26 +1254,55 @@ static void amt_req_work(struct work_struct *work) msecs_to_jiffies(100)); } +/* RFC 7450 s5.3.3.6: a Multicast Data message sent over IPv6 must not +* carry a Fragment header, so a payload larger than the tunnel MTU is +* dropped, and an IPv6 source is sent a Packet Too Big, unless the tunnel +* MTU is below IPV6_MIN_MTU, which a source would ignore. An IPv4 source is +* not told, as icmp_send() never answers a multicast datagram. The tunnel +* MTU follows the route's path MTU, as on every IPv6 UDP tunnel. +*/ +static u32 amt_tmtu (const struct dst_entry *dst) +{ +u32 hlen =sizeof (struct ipv6hdr ) +sizeof (struct udphdr ) + +sizeof (struct amt_header_mcast_data ); +u32 mtu =dst_mtu (dst); + +return mtu > hlen ? mtu - hlen :0 ; +}
[ ... ]
Quoted 1 line
drivers/net/amt.c +0
-0@@ -1374,26 +1403,60 @@ static bool amt_send_membership_update(struct amt_dev *amt,
[ ... ]
Quoted 5 lines
drivers/net/amt.c +5
-0+if (amt_v6 (amt)) { +u32 tmtu; + + dst =amt_route6 (amt, sk, &amt->local_ipv6, &tunnel->addr.ip6, + amt->relay_port, tunnel->source_port);
[ ... ]
Quoted 13 lines
drivers/net/amt.c +13
-0+ 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 ; + } + }
[ ... ]
drivers/net/amt.c static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) · line 1660
Quoted 9 lines
drivers/net/amt.c +3
-1@@ -1593,8 +1654,10 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) }continue ; found: -amt_send_multicast_data (amt, skb, tunnel, v6); +amt_send_multicast_data (amt, skb, tunnel, v6, &ptb); } +if (ptb && v6) +icmpv6_ndo_send (skb,ICMPV6_PKT_TOOBIG ,0 , ptb);
[Severity: Medium]
Can an off-path sender make the relay send a multicast source a Packet Too Big with a value of the sender's choosing?
amt_tmtu() takes the tunnel MTU from dst_mtu() of the route to the gateway. udpv6_err() lowers that route's MTU for every Packet Too Big, before it looks up a socket:
net/ipv6/udp.c:udpv6_err() {
...
udpv6_err_update_exception(net, skb, type, info);
...
}The gateway address can belong to an unauthenticated AMT gateway, which a relay accepts by design, or to any existing tunnel.
Take a forged Packet Too Big with MTU M, where 1330 <= M < 1490, naming a gateway that has joined group G. The 1490 bound assumes the 1440 device MTU at the end of the series on a 1500 link. That tunnel's MTU becomes M - 50, which is at least IPV6_MIN_MTU.
Every IPv6 packet of G larger than that would then make amt_dev_xmit() send the source a Packet Too Big carrying M - 50.
icmp6_send() allows a Packet Too Big for a multicast destination:
net/ipv6/icmp.c:icmp6_send() {
...
if (addr_type & IPV6_ADDR_MULTICAST || skb->pkt_type != PACKET_HOST) {
if (type != ICMPV6_PKT_TOOBIG &&
!(type == ICMPV6_PARAMPROB &&
code == ICMPV6_UNK_OPTION &&
(opt_unrec(skb, info))))
goto out;
...
}Packet Too Big is also cleared from the default icmpv6_ratemask, so these messages are not rate limited.
The source would then lower its PMTU for the group address itself. That affects every receiver of G, including native LAN receivers and the other AMT tunnels, not just the gateway whose path was forged. The source would have to fragment, and senders using IPV6_DONTFRAG would get EMSGSIZE.
The Packet Too Big also goes to any IPv6 source. RFC 7450 s5.3.3.6.2.2 asks for one only for an SSM source.
The commit message only covers the minimum forged value:
therefore lowers the tunnel MTU to 1280 bytes less the 50 of the IPv6, UDP and AMT headers, 1230, until the route exception expires, 10 minutes by default. Every multicast payload above that, IPv4 or IPv6, is then dropped toward that gateway, and its source is told nothing, as 1230 is below the 1280 a Packet Too Big can ask for.
Is it intended that a slightly larger forged MTU gets passed on to the source?
At this commit amt_v6() is still false. The code is unchanged at the end of the series, where IFLA_AMT_LOCAL_IP6 makes it reachable.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130064249.1874523-1-omar%40blockcast.net
PATCH v5 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, which is 20 bytes short of an IPv6 one. A relay's multicast payload close to the device MTU would then be larger than the tunnel MTU that amt_send_multicast_data() computes from the route, and be dropped there: an IPv6 payload with a Packet Too Big, an IPv4 payload without notice, as icmp_send() does not answer multicast. Sizing the device for the IPv6 headers makes the stack refuse such a payload first.
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)
@@ -3942,10 +3950,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],
@@ -3968,10 +3976,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 ;
@@ -4092,11 +4100,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) {
PATCH v5 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
@@ -808,8 +808,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 ;
@@ -841,10 +844,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;
@@ -858,6 +890,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)
@@ -948,6 +985,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);
@@ -1357,9 +1399,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;
@@ -1368,23 +1408,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 ;
@@ -1396,17 +1424,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 */
PATCH v5 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 four bytes from the middle of the source address. 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 IPv4 gateway keeps its minimum-length check; only an IPv6 gateway insists on the exact 24-byte form. 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. A transmit that read ready6 just before the relay was forgotten finds :: in its snapshot, which amt_route6() refuses. 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 delivers a packet from the unspecified address, which IPv4 input refuses as a martian, except to the limited broadcast address. 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 in either mode, and amt_from_relay() matches nothing against a relay address that is not known, in either family.
IPv4 input also refuses a source that is one of the host's own addresses, as a martian, when the packet comes in from the wire, since accept_local is 0; IPv6 input delivers it. A relay answers a Discovery with an Advertisement and a Request with a Membership Query, both sent to the source of the packet, so a forged Discovery or Request from one of the relay's own addresses, sent by anyone who can forge a source, would make the relay send to itself over lo, where a rule such as "-i lo -j ACCEPT" lets the datagram in and local UDP services bound to :: or to that address could see it. A relay's amt_rcv() therefore drops a packet whose outer source is an address that ipv6_chk_addr() finds on a device of the namespace, before it looks at the message. An address on a VRF slave or a tentative one is not found. A packet that arrives over lo comes from the host itself and is not dropped, as for IPv4, so a gateway on the relay's host still reaches its relay.
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. A relay should send a non-zero one over IPv6 (s5.1.6) but may use the RFC 6936 exception to RFC 8200 s8.1, so a gateway has to accept zero. 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 | 172 +++++++++++++++++++++++++++++++++++++++------- include/net/amt.h | 2 + 2 files changed, 148 insertions(+), 26 deletions(-)
drivers/net/amt.c +146 -26
@@ -778,6 +778,12 @@ static struct dst_entry *amt_route6(struct amt_dev *amt, struct sock *sk, {struct flowi6 fl6; +/* A gateway that has just forgotten its relay publishes ::, and a +* sender may have read ready6 before that. +*/ +if (ipv6_addr_any (daddr)) +return ERR_PTR (-EINVAL ); +memset (&fl6,0 ,sizeof (fl6)); fl6.flowi6_oif = amt->stream_dev->ifindex; fl6.flowi6_proto =IPPROTO_UDP ;
@@ -848,6 +854,61 @@ out: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) {
@@ -872,9 +933,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)
@@ -1271,7 +1334,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 ;
@@ -1425,7 +1488,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,
@@ -2699,27 +2762,49 @@ 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. An IPv6 device's family +* picks one, so a message of the other form is not accepted; an IPv4 +* device keeps the minimum-length check it always had. +*/ +if (amt_v6 (amt) &&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);
@@ -2804,6 +2889,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;
@@ -2817,7 +2903,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)
@@ -3448,9 +3535,8 @@ drop: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;
@@ -3461,10 +3547,31 @@ 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); +/* IPv6 input delivers a packet from ::, which no relay or gateway +* can be. +*/ +if (amt_v6 (amt) &&ipv6_addr_any (&saddr.ip6)) { + err = true; + goto drop; + } +/* IPv4 input refuses a source that is one of this host's own +* addresses as a martian (accept_local is 0) when it arrives from +* the wire, but IPv6 input delivers it. A relay answers a Discovery +* and a Request to their source, so a forged one would make it send +* to itself over lo, where a rule such as "-i lo -j ACCEPT" lets it +* in. A packet that arrives over lo comes from this host, as for +* IPv4, so a gateway on the relay's host still reaches it. +*/ +if (amt_v6 (amt) && amt->mode ==AMT_MODE_RELAY && + skb->skb_iif != amt->net->loopback_dev->ifindex && +ipv6_chk_addr (amt->net, &saddr.ip6,NULL ,0 )) { + err = true; + goto drop; + } type =amt_parse_type (skb);if (type ==-1 ) { err = true;
@@ -3472,9 +3579,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;
@@ -3486,7 +3601,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;
@@ -3497,7 +3612,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;
@@ -3636,13 +3751,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 ;
@@ -3711,7 +3830,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 ;
@@ -3760,7 +3879,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
@@ -3930,6 +4049,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,
[email protected]
AI reviewRe: [PATCH net-next v5 08/12] amt: receive the AMT gateway control plane over IPv6
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 3
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).
- [High] The relay's own-source filter in amt_rcv() only walks the unicast list.
- [Medium] The relay's new own-source drop in amt_rcv() calls ipv6_chk_addr(amt->net, &saddr.ip6, NULL, 0).
- [Medium] The relay's own-source check in amt_rcv() calls ipv6_chk_addr(amt->net, &saddr.ip6, NULL, 0).
- [Low] The commit message says this patch makes the IPv6 gateway control plane work ("An IPv6 gateway now sends its Discovery, Request and…
- [Low] Part of the commit message's case for the seqlock is that remote_ipv6 "is read ... from amt_fill_info(), which no longer relies…
- [Low] The block comment above amt_set_remote_ipv6() (drivers/net/amt.c:857-861) says the learned relay address "is written…
--
amt: receive the AMT gateway control plane over IPv6
This patch makes amt_rcv() and amt_advertisement_handler() handle an IPv6 outer header. It publishes the learned IPv6 relay address under a new seqlock, and adds a relay-side drop for packets whose IPv6 source is one of the host's own addresses. It also lets an IPv6 gateway socket accept a zero UDP checksum, and only for Multicast Data.
Quoted 2 lines
An IPv6 gateway now sends its Discovery, Request and Updates over IPv6, but it cannot take the replies.
[ ... ]
Quoted 3 lines
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.
[Severity: Low]
Is this accurate at this point in the series? At this commit nothing assigns amt->local_ipv6, and amt_validate() still requires the IPv4 local attribute:
drivers/net/amt.c:amt_validate() {
...
if (!data[IFLA_AMT_LOCAL_IP]) {
NL_SET_ERR_MSG_ATTR(extack, data[IFLA_AMT_DISCOVERY_IP],
"Local attribute is required");
...
}IFLA_AMT_LOCAL_IP6 and IFLA_AMT_DISCOVERY_IP6 don't exist yet, so amt_v6() is false for every device. None of the new IPv6 branches can run until the later "amt: add netlink attributes for an IPv6 outer transport" commit:
- the 24-byte Advertisement parse
- the :: source drop
- the relay's own-source drop
- the zero-checksum handling in amt_rcv()
- the use_udp6_rx_checksums change
Earlier patches in the series say that amt_v6() is still false and nothing changes functionally. The next patch says no such device can be created until it lands. Could this message say the same, rather than describing the behaviour as already active?
Quoted 4 lines
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.
[ ... ]
Quoted 3 lines
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.
[Severity: Low]
Does amt_fill_info() read remote_ipv6 at this commit? It seems to report only the IPv4 address:
drivers/net/amt.c:amt_fill_info() {
...
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;
...
}IFLA_AMT_REMOTE_IP6 doesn't exist yet. The amt_fill_info() reader, and the "reporting" mentioned later, only arrive with the later netlink attributes commit. That commit does read the field through amt_get_remote_ipv6(), so the code ends up correct. The only problem is that this commit's message describes a reader that isn't there yet.
Quoted 4 lines
drivers/net/amt.c +0
-0
[ ... ]
Quoted 16 lines
drivers/net/amt.c +12
-0@@ -848,6 +854,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); +}
[ ... ]
drivers/net/amt.c out: · line 886
Quoted 6 lines
drivers/net/amt.c +6
-0+/* 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); +}
[Severity: Low]
Is the single-writer description in the comment above amt_set_remote_ipv6() accurate? The commit message also calls the Advertisement handler "its only writer".
amt_clear_remote() also writes remote_ipv6 through amt_set_remote_ipv6(). It is called from amt_event_send_request() in the event worker, and also from amt_dev_open() and amt_dev_stop() in process context. In amt_dev_open() the call comes after amt_socket_create() has enabled receive, so it can run at the same time as the event worker.
write_seqlock_bh() serialises all of these writers, so nothing is corrupted today. Could the comment and the commit message mention the open and stop writers too? Otherwise a later change might rely on the single-writer description and replace the seqlock with a bare seqcount_t.
[ ... ]
Quoted 1 line
drivers/net/amt.c +0
-0@@ -3461,10 +3547,31 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
[ ... ]
Quoted 4 lines
drivers/net/amt.c +4
-0+/* IPv4 input refuses a source that is one of this host's own +* addresses as a martian (accept_local is 0) when it arrives from +* the wire, but IPv6 input delivers it. A relay answers a Discovery +* and a Request to their source, so a forged one would make it send
drivers/net/amt.c static int amt_rcv(struct sock *sk, struct sk_buff *skb) · line 3574
Quoted 10 lines
drivers/net/amt.c +10
-0+* to itself over lo, where a rule such as "-i lo -j ACCEPT" lets it +* in. A packet that arrives over lo comes from this host, as for +* IPv4, so a gateway on the relay's host still reaches it. +*/ +if (amt_v6 (amt) && amt->mode ==AMT_MODE_RELAY && + skb->skb_iif != amt->net->loopback_dev->ifindex && +ipv6_chk_addr (amt->net, &saddr.ip6,NULL ,0 )) { + err = true; + goto drop; + }
[Severity: High]
Does this check cover anycast addresses that the relay delivers locally? ipv6_chk_addr() only walks the unicast list, net->ipv6.inet6_addr_lst.
With forwarding enabled on stream_dev, addrconf_join_anycast() joins the Subnet-Router anycast (prefix::) of each prefix. An admin may also add an anycast Relay Discovery Address, which RFC 7450 anticipates. These get an RTF_ANYCAST route, and ip6_rt_get_dev_rcu() sends traffic for them through loopback:
net/ipv6/route.c:ip6_rt_get_dev_rcu() {
...
if (res->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) {
...
else if (!netif_is_l3_master(dev))
dev = dev_net(dev)->loopback_dev;
...
}ip6_rcv_core() doesn't refuse an anycast source. A forged Discovery or Request from the wire with source prefix:: would pass this check:
amt_rcv()
ipv6_chk_addr() /* returns 0 for the anycast address */
amt_discovery_handler() / amt_request_handler()
amt_route6() /* oif = stream_dev, matches the RTF_ANYCAST route */
reply delivered over lo to local UDP listeners on ::
Isn't that the same self-reflection past "-i lo -j ACCEPT" that the commit message says this check prevents? IPv4 refuses both local and broadcast sources as martians.
Would adding an anycast lookup close it? For example, ipv6_chk_acast_addr() on &saddr.ip6, with NULL or amt->stream_dev as the device.
[Severity: Medium]
Can this drop a legitimate gateway that uses a link-local source? ipv6_chk_addr() passes skip_dev_check = !dev. With a NULL device, the match in __ipv6_chk_addr_and_flags() accepts an equal address of any scope on any device in the namespace:
net/ipv6/addrconf.c:__ipv6_chk_addr_and_flags() {
...
if (ipv6_addr_equal(&ifp->addr, addr) &&
!(ifp_flags&banned_flags) &&
(!dev || ndev == dev ||
!(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
...
}Link-local addresses are only unique per link, and a static fe80::1 on several interfaces is common on routers. Suppose a gateway on the stream_dev link sources from fe80::X, and the relay has fe80::X on another interface. Then every Discovery, Request and Membership Update from that gateway is dropped here and counted in rx_dropped.
In that case the drop doesn't prevent any reflection. amt_route6() routes the reply with oif = stream_dev on a device-bound socket, so the reply goes out the stream_dev link. The comment in amt_create_sock() also explicitly supports link-local peers on stream_dev.
Would passing amt->stream_dev as the device, without skip_dev_check, fix this? It would still match global-scope addresses, but would only match stream_dev's own link-local addresses.
[Severity: Medium]
What happens here when stream_dev is enslaved to a VRF? In __ipv6_chk_addr_and_flags(), l3mdev is taken from the dev argument before skip_dev_check clears it:
net/ipv6/addrconf.c:__ipv6_chk_addr_and_flags() {
...
l3mdev = l3mdev_master_dev_rcu(dev);
if (skip_dev_check)
dev = NULL;
hlist_for_each_entry_rcu(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) {
ndev = ifp->idev->dev;
if (l3mdev_master_dev_rcu(ndev) != l3mdev)
continue;
...
}With a NULL dev, l3mdev is NULL, so every address on a VRF slave is skipped. That includes the relay's own addresses on stream_dev. A forged Discovery or Request from the wire with one of those as its source would pass this check, and the reply would follow this path:
amt_discovery_handler() / amt_request_handler()
amt_route6() /* oif = stream_dev, finds the RTF_LOCAL route */
ip6_rt_get_dev_rcu() /* dst dev becomes the VRF master */ reply delivered locally to UDP listeners in that VRF
The commit message notes "An address on a VRF slave or a tentative one is not found". Isn't this still the self-reflection the check is meant to close? IPv4's fib_validate_source() looks the source up in the l3mdev table.
Would something like this keep the L3 domain and cover this case?
ipv6_chk_addr_and_flags(amt->net, &saddr.ip6, amt->stream_dev, false, 0, IFA_F_TENTATIVE)
The findings above were generated by an automated review.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130064249.1874523-1-omar%40blockcast.net
PATCH v5 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
@@ -3976,6 +3976,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 },
@@ -3984,6 +3985,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[],
@@ -4010,16 +4015,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 ; }
@@ -4070,13 +4112,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],
@@ -4099,24 +4153,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 +
@@ -4170,7 +4235,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)
@@ -4187,15 +4273,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, };
PATCH v5 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]>
PATCH v5 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 script needs the same tools. It does not repeat the send_mcast_torture4 and send_mcast_torture6 runs of amt.sh. 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;
- the relay counts the tunnels of one source per /64. Created with max_tunnels 16 it allows two per source, which the first two gateways use up, so a third gateway in their /64, with an address of its own, gets no tunnel and no multicast, while a gateway in another /64 gets both;
- the relay's General Queries leave through the stream device and never through amtr: its egress counters see no IGMP packet and no MLD query;
- 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;
- a Relay Discovery that arrives from the wire with one of the relay's own addresses as its source, sent from a namespace that holds the address on its lo only, is dropped and counted in rx_dropped and draws no answer on the relay's lo, while the same Discovery sent over lo, as a gateway on the relay's host would, is answered;
- 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 has no amt link type ("Unknown device type"), or when iproute2 cannot pass the address, as amt.sh checks that iproute2 knows amt at all. That includes an iproute2 that packs the IPv6 literal into the 4-byteIFLA_AMT_LOCAL_IP: this kernel refuses it with "binary attribute size out of range", 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.
A listener that must get nothing has to be alive at the end, which the status of its timeout shows, so one that never started cannot pass that check.
The script skips when /proc/net/if_inet6 is missing, that is without CONFIG_IPV6, before it creates any link. disc_answer() waits until tcpdump reports that it is listening, and returns a distinct status when it fails to start, is not listening after five seconds, or a send fails. 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 | 564 ++++++++++++++++++++++++++ 2 files changed, 565 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 +564 -0
564 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH net-next v5 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] In tools/testing/selftests/net/amt_v6.sh, test_local_source() takes [ $((d1 - d0)) -ge 3 ] (line 504) on amtr's rx_dropped as…
- [Medium] In disc_answer() (line 371) and local_src_answers() (line 443), the tcpdump capture runs under timeout 6, which starts…
- [Low] In amt_v6.sh, the main body runs set -E and trap 'setup_fail $LINENO' ERR (lines 541-542, 546) around setup_topology().
--
selftests: net: add amt_v6.sh for an IPv6 outer transport
This adds amt_v6.sh, a variant of amt.sh that moves the AMT gateway<->relay link to IPv6 and adds more gateways on that link to exercise the per-/64 tunnel cap. It also checks Packet Too Big handling, that Discoveries sent to ff02::1 or from the relay's own address get no answer, and that the gateway rediscovers the relay after down/up.
Quoted 6 lines
tools/testing/selftests/net/amt_v6.sh new file +0
-0@@ -0,0 +1,564 @@
[ ... ]
tools/testing/selftests/net/amt_v6.sh line 192
Quoted 3 lines
tools/testing/selftests/net/amt_v6.sh new file +3
-0+ SMCDIR=$(mktemp -d) + ip netns exec "$RELAY" smcrouted -P "$SMCDIR/pid" -u "$SMCDIR/sock" + slowwait 5 test -S "$SMCDIR/sock"
[Severity: Low]
Can this print false setup failures on a run that passes?
The main body runs setup_topology() with errtrace on and the ERR trap set:
set -E
trap 'setup_fail $LINENO' ERR
With set -E, command substitutions inherit the ERR trap. slowwait goes through loopy_wait() in lib.sh, which runs the probe like this:
if out=$("$@"); thenThe if only suppresses the trap for the assignment in the parent shell. Inside the $(...) subshell, a failing test -S is an ordinary command, so the inherited trap fires. setup_fail then prints "FAIL: setup failed at line N" to stderr and exits only that subshell.
smcrouted creates its socket after it daemonizes, so the first polls usually fail. Each failed poll prints a false FAIL line, even though setup succeeds and the exit status does not change.
Could this wait run outside the ERR trap, or without set -E?
Quoted 2 lines
tools/testing/selftests/net/amt_v6.sh new file +2
-0+ ip netns exec "$RELAY" smcroutectl -u "$SMCDIR/sock" \ + a relay_src 172.17.0.2 239.0.0.1 amtr
[ ... ]
Quoted 18 lines
tools/testing/selftests/net/amt_v6.sh new file +18
-0+disc_answer() +{ + local dst=$1 filter=$2 pid i rc cap + local to="UDP6-SENDTO:[$dst]:2268,sourceport=40000" + + cap=$(mktemp) + ip netns exec "$GATEWAY" timeout 6 \ + tcpdump -nni gw_relay -c 1 "$filter" > /dev/null 2> "$cap" & + pid=$! + # The capture is ready once tcpdump says it is listening. If it does + # not, whether it is gone or still starting, nothing it reports means + # anything. + for i in $(seq 50); do + grep -q "listening on" "$cap" && break + kill -0 "$pid" 2> /dev/null || break + sleep 0.1 + done + if ! grep -q "listening on" "$cap"; then
[ ... ]
tools/testing/selftests/net/amt_v6.sh line 402
Quoted 7 lines
tools/testing/selftests/net/amt_v6.sh new file +7
-0+ wait "$pid" + case $? in + 0) return "${rc:-0}" ;; + 124) return "${rc:-1}" ;; + *) return 2 ;; + esac +}
[Severity: Medium]
Does the capture always last long enough to cover the sends?
The timeout 6 clock starts when tcpdump is launched. The readiness loop can take 5 s or more of wall time by itself: 50 iterations, each forking grep and sleep 0.1. The three sends with 0.5 s sleeps come after that.
The readiness check only greps a file. It still passes if timeout has already killed tcpdump. In that case the Discoveries go out after the capture has ended, wait returns 124, and disc_answer() returns 1.
test_mcast_discovery() then treats that as the expected result for ff02::1:
disc_answer ff02::1 "udp and src port 2268 and dst port 40000"
[ $? -eq 1 ]The commit message says:
The ff02::1 check accepts only "no reply", so a broken capture cannot pass it.
Is that still true when tcpdump reports listening late? The unicast positive control runs in a separate, earlier tcpdump instance, so it says nothing about this capture's window.
local_src_answers() has the same overlap with its own timeout 6. If tcpdump is gone before the sends, this gives 0 with status 0:
ANSWERS=$(grep -c "UDP" "$cap")
The "not answered" check in test_local_source() then passes without having observed anything. The same timing would also make the positive checks fail spuriously.
Could the deadline start once tcpdump reports listening, or could the capture be stopped explicitly after the sends?
[ ... ]
Quoted 10 lines
tools/testing/selftests/net/amt_v6.sh new file +10
-0+# A Discovery that comes in from the wire with one of the relay's own +# addresses as its source is not answered: the Advertisement would go to this +# host over lo, where a rule such as "-i lo -j ACCEPT" lets it in. IPv4 input +# refuses such a source as a martian; IPv6 input does not. SPOOF holds the +# address on its lo only, so nothing on the link announces it, and sends from +# it out of its own veth. The relay counts each drop in rx_dropped, which shows +# that the Discovery got there. The same address over lo is a gateway on the +# relay's own host, which IPv4 accepts too, and is answered. +test_local_source() +{
[ ... ]
tools/testing/selftests/net/amt_v6.sh line 505
Quoted 8 lines
tools/testing/selftests/net/amt_v6.sh new file +8
-0+ d0=$(rx_dropped) + local_src_answers "$SPOOF" ",so-bindtodevice=spoof_relay" + check_err $? "the capture on lo did not start, or a send failed" + d1=$(rx_dropped) + [ "$ANSWERS" -eq 0 ] + check_err $? "the relay answered its own address, $ANSWERS times" + [ $((d1 - d0)) -ge 3 ] + check_err $? "the relay dropped $((d1 - d0)) of the 3 Discoveries"
[Severity: Medium]
Does the rx_dropped delta really show that the spoofed Discoveries reached the relay?
amtr's rx_dropped also counts other drops, and test_source_cap() leaves one of them running. It creates amtg4 when 2001:db8:a::/64 is already at its per-source cap, and nothing deletes it:
ip -n "$GATEWAY2" link add amtg4 type amt mode gateway \
local "$GW4_6" discovery "$DISC6" dev gw4_relay \
gateway_port 2268 relay_port 2268amtg4 keeps running amt_event_send_request(). Each cycle sends an IGMP Request and an MLD Request, with a 2/4/8/16 s backoff. It then rediscovers the relay and starts over.
On the relay, amt_request_handler() rejects each of these Requests:
if (!have && (full || per_src >= amt_max_tunnels_per_src(amt)))
return true;amt_rcv() then increments amt->dev->stats.rx_dropped, the same counter that rx_dropped() reads.
The d0/d1 window here lasts a few seconds, so one or two amtg4 cycles can add 2 or 4 drops. Suppose the SPOOF Discoveries never reach the relay, for example because the SPOOF veth or bridge setup is broken. Couldn't the delta still reach 3? ANSWERS would stay 0, and the check would pass without testing anything.
Would it help to delete amtg4 at the end of test_source_cap(), or to check something specific to this drop?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130064249.1874523-1-omar%40blockcast.net
PATCH v5 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 16-byte IPv6 literal into the IPv4 attribute. This kernel refuses that with the exact length of the attribute ("binary attribute size out of range"), which is logged as a passing test before the probe skips, since it is the rule an older iproute2 exercises. A kernel without that rule builds an IPv4 gateway from the first four bytes instead, so discovery 2001:db8:a::2 becomes 32.1.13.184; the probe skips on that readback only, as four truncated bytes cannot be told from an IPv4 address. Any other readback without a colon is amt_fill_info() failing, and a FAIL. The probe
also skips on an iproute2 that rejects the literal or does not know amt, on a kernel that ignores the attributes ("Local attribute is required"), on one without amt ("Unknown device type") and on one 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 | 221 +++++++++++++++++++++++ 2 files changed, 222 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 +221 -0
221 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH net-next v5 12/12] selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes
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] Four rejection cases in amt_gw_v6.sh only test the kernel rule they are named after if iproute2 sends an unspecified or multicast…
- [Low] probe_v6_gateway() in amt_gw_v6.sh also skips on any probe- creation error containing "Operation not supported" (line 70).
--
selftests: net: add amt_gw_v6.sh for the IPv6 netlink attributes
This adds a netlink-only selftest for the AMT IPv6 attributes IFLA_AMT_LOCAL_IP6 and IFLA_AMT_DISCOVERY_IP6. It checks that IPv6 and IPv4 gateways and relays read back correctly through amt_fill_info(). It also checks that each new link-creation rule rejects bad input with the expected extack message, and a probe skips the test when iproute2 or the kernel lacks IPv6 AMT support.
Quoted 6 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +0
-0@@ -0,0 +1,221 @@
[ ... ]
Quoted 3 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +3
-0+ if ! add_amt amtprobe mode gateway local "$V6_LOCAL" \ + discovery "$V6_DISC"; then + case "$ADD_ERR" in
[ ... ]
tools/testing/selftests/net/amt_gw_v6.sh line 76
Quoted 9 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +9
-0+ *"Local attribute is required"*|*"expected rather than"*|\ + *"IPv6 support is disabled"*|*"Unknown device type"*|\ + *"Operation not supported"*) + echo "SKIP: no IPv6 AMT support: $ADD_ERR" + exit "$ksft_skip" + ;; + esac + echo "FAIL: cannot create an IPv6 gateway: $ADD_ERR" + exit "$ksft_fail"
[Severity: Low]
Is the "Operation not supported" pattern in probe_v6_gateway() intended? The commit message lists the probe's skip conditions one by one and then says:
"Any other failure to create the probe link is a FAIL."
"Operation not supported" is not in that list.
When amt is missing, __rtnl_newlink() already sets an extack, and the script matches that message separately:
net/core/rtnetlink.c:__rtnl_newlink() {
...
if (!ops) {
NL_SET_ERR_MSG(extack, "Unknown device type");
return -EOPNOTSUPP;
}
...
}With an iproute2 that supports extended ACK, the strerror match mostly catches an EOPNOTSUPP that has no extack message. One example is a netdev notifier failing during register_netdevice() or netdev_upper_dev_link() in amt_newlink().
This is unlikely on a dummy device in a fresh netns. Still, wouldn't such a create failure become a SKIP instead of a FAIL? You could either drop the pattern or list it in the commit message.
[ ... ]
Quoted 12 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +12
-0+expect_reject() +{ + local desc=$1 want=$2; shift 2 + + RET=0 + add_amt amtbad "$@" + check_fail $? "link was created but should have been rejected" + ip -n "$GW" link del amtbad 2>/dev/null + grep -qi -- "$want" <<< "$ADD_ERR" + check_err $? "rejected for the wrong reason: $ADD_ERR" + log_test "$desc" +}
[ ... ]
Quoted 3 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +3
-0+expect_reject "unspecified v6 local is rejected" \ + "Invalid Local IPv6" \ + mode relay local ::
[ ... ]
Quoted 6 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +6
-0+expect_reject "multicast v6 local is rejected" \ + "Invalid Local IPv6" \ + mode relay local ff02::1 +expect_reject "multicast v6 discovery is rejected" \ + "must be unicast" \ + mode gateway local "$V6_LOCAL" discovery ff02::1
[ ... ]
tools/testing/selftests/net/amt_gw_v6.sh line 216
Quoted 3 lines
tools/testing/selftests/net/amt_gw_v6.sh new file +3
-0+expect_reject "unspecified v6 discovery is rejected" \ + "must be unicast" \ + mode gateway local "$V6_LOCAL" discovery ::
[Severity: Medium]
Do these four cases only work if iproute2 passes :: or a multicast address to the kernel unchanged?
expect_reject() passes only if ADD_ERR contains the kernel's extack text. amt_newlink() is the only source of "Invalid Local IPv6 address" and "discovery must be unicast". It emits them only when IFLA_AMT_LOCAL_IP6 or IFLA_AMT_DISCOVERY_IP6 actually reaches the kernel.
The existing iproute2 amt parser follows the vxlan pattern and filters these addresses itself:
- It rejects multicast addresses through is_addrtype_inet_not_multi(), with invarg("invalid local address") or
invarg("invalid discovery address").
- It adds the attribute only when is_addrtype_inet_not_unspec() holds, so :: is quietly left out.
Suppose the IPv6-capable iproute2 keeps that filtering. Then:
local ff02::1, discovery ff02::1
fail with iproute2's own message
local ::
the attribute is left out and amt_validate() reports:
drivers/net/amt.c:amt_validate() {
...
if (!data[IFLA_AMT_LOCAL_IP] && !data[IFLA_AMT_LOCAL_IP6]) {
NL_SET_ERR_MSG_MOD(extack, "Local attribute is required");
...
} discovery ::
amt_validate() reports "Discovery attribute of the local family is required"
None of these messages match the grep in expect_reject(). Each case would report "rejected for the wrong reason" and fail on a correct kernel. The kernel's unspecified and multicast checks would never run.
The IPv6 iproute2 changes are not in this tree, so I could not confirm whether they keep the filtering.
The commit message says the test checks:
"an unspecified, loopback, multicast or IPv4-mapped IPv6 local or discovery address."
It names only three cases that iproute2 "cannot express". Could the commit message or the script say which iproute2 behaviour these cases need? Another option is to skip them when the error comes from iproute2 or from the missing-attribute path.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130064249.1874523-1-omar%40blockcast.net
Hi Omar,
On 30/11/2026 07:42, Omar Ramadan wrote:
(...)
Quoted 3 lines
The iproute2 support is a separate iproute2-next patch, now at v2:
https://lore.kernel.org/netdev/[email protected]/
The selftests skip when iproute2 or the kernel lacks the attributes.
Thank you for that. Please next time also include a patch in this series with the update of the UAPI headers: this patch can be removed after the sync, but at least it is easier to test your modifications while the kernel modifications are still WIP.
@net maintainers: the CI should now stop skipping the new tests.
Cheers,
Matt
Hi Omar,
Quoted 9 lines · Matthieu Baerts
Hi Omar,
On 30/11/2026 07:42, Omar Ramadan wrote:
(...)
Quoted 3 lines
The iproute2 support is a separate iproute2-next patch, now at v2:
https://lore.kernel.org/netdev/[email protected]/
The selftests skip when iproute2 or the kernel lacks the attributes.
Quoted 6 lines
Thank you for that. Please next time also include a patch in this series with the update of the UAPI headers: this patch can be removed after the sync, but at least it is easier to test your modifications while the kernel modifications are still WIP.
@net maintainers: the CI should now stop skipping the new tests.
It looks like the new tests are very unstable on the CI side:
https://netdev.bots.linux.dev/contest.html?remote=virt-net&executor=vmksft-net&test=amt-v6-sh
https://netdev.bots.linux.dev/contest.html?remote=virt-net-dbg&executor=vmksft-net-dbg&test=amt-v6-sh
Please have a look and fix this.
pw-bot: cr
(side note: you might need to tell your LLM to avoid long/useless comments, and very long descriptions in the changelog, commit message, cover letter, etc. → straight to the point, and comments only when needed)
Cheers,
Matt