From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795924029; b=JwVCOElVmVBxWeRTH/gbd1mEKjkGdSWxT9Bf8/lUp8SC9tNYXTApNRO9r4SX5ttSS18l wnPGCcZvH67v6aTGE2acxZxDs+qAvneXo0abPAuQeCfpJA/upjeb9U9VRUhUTFKMg7j81 xYWYWSz0u7XoaURSAC7/eAGrGJmc0FRz6yILhutMTAGpVX6K/5yF2KwhPOi0dOw3MR7Ge QXhqjEJVxeZxnLviJjY+7RlB6Wys956LnFYKz+LQm4U9A3La+fpndVTbVjIZ3QhuXx+6b gHk/iF3moIOoyPUywrAx4ASsymGt7FnLH7CSEVDS2fhchMd5+Joh4w1+QTISFayNhxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795924029; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=wyepgLkwlrRKYRTMBa/Aw26rZ6lI/FKDZl/PcOBkmvs=; b=nkvI1mw2yD4nMNUh9tDaVJeNuMqItXIsj64IpPo7xHoL0e36roqlkmWHLskUkCVxK3s7 Sn5VpNT2WayNOHShtR8ZXE+uYgtPMiHi832eP501+KrP8+tIxbWSQ92A+/eTWOEEO8RN0 nSEvrfmXKNuSZx0BQpj0O7/0HAJoP9+yIb/iI1EIDN9jmFWRa8eNEJyZdYlXsETtu2JAQ bHlqL5veyB9bJQ6bC61Ny/HVQqPSqgWJs3MAAeHkoE4HiF/zK7DcQvax0521QnA8MaSlF eXWkTPkGwZ2vD9Gdr25uDaiRoGtTGLxwJ8dex6IU9AwE/es5jXP6YgqUIDdpmqo021A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=blockcast.net; spf=pass smtp.mailfrom=blockcast.net; dkim=pass header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b="Mv8JOn/j"; arc=none smtp.remote-ip=74.125.82.54 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E05B60A2639 for ; Sun, 29 Nov 2026 03:47:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4E05B60A2639 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=blockcast.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blockcast.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=Mv8JOn/j Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-1b546061d58so1198754c88.1 for ; Sat, 28 Nov 2026 19:47:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1795924028; x=1796528828; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wyepgLkwlrRKYRTMBa/Aw26rZ6lI/FKDZl/PcOBkmvs=; b=Mv8JOn/jCfUebQ6jb+Af1k7tlD0BrOpDTKPpO3W8OHG88RxjyVuUZcluiYuc16EW8S x86FhXFVKX6uaPe4e2dXsLGHFn8gStOMsQ3JkLH9sPfodf0LO9r1yh7SJVraYRkmeJ3J bxHU108EHFJHlYuDdmXG7NzGncA9sAXcsKKTkdsOzCD+Yw8v8R/QrJBr+pDs1S4UROxH NvDj8amkVvB4o+Se/3iLv2t7Y6XTUpJpJxOBeDQm+PFBiuHyanZezSRjbzNpMVriAI68 pim0HxB3wz0tunMMHuimIxGlsGQszz0VCJTyBuQuS4DoWaUmkRMLcvZD0VH6B69DM7kd NwzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795924028; x=1796528828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=wyepgLkwlrRKYRTMBa/Aw26rZ6lI/FKDZl/PcOBkmvs=; b=sYZ0QNrOWC3QmY4WUAM5wwrlx/r+lig6anw9eYZUU0ECNTg5izgUcqAKBB6EumVkM6 T/EG7VGbzR3KufSzoopAXWNj9y/V3a/b3ovjEfWNCu2BbTCZjecTpOEOH0ozntRKCUR6 F24cv4YWCvjAer9/ugY7o4FXpiSytBAM5z9UTWJJdjm/V30YF9xWV5RmYFlj9AL8Sey4 9zauURO0rb4kkWLBtYxmbW65oG2EQmSMXMKtf0ZihBZxZ55IE+Yw+tiUlDsbiqw05XY3 OzQTBJcHiRO5o7+ClHmXgb1YgXGCi6R2vreWS0Tf9F7OcnBI0Lifltkuo7z16Wo074Qq G6jQ== X-Forwarded-Encrypted: i=1; AL+hErHPr+lY4xoaPsJqgSskrshLMjfMZtVNpll7OGd61rF2wG5SRaNrVc625WKAe56XNGAJfPL9p6A=@vger.kernel.org X-Gm-Message-State: APuU4Z9IS2H5hEj15pGGtri1Yg4ZaMEaMuD+85FxIfXPDEdR0dW/DhJh 1/cUxixq2leP0q+62r1AQzWe+cBDzGt0QGaN+n5OJteOtr2i/vpo0tXahr446VyaVks= X-Gm-Gg: AZFdTZfIKSQcEnwINUFXN0ytSLOfXmkfFJ/vq/A/+EbFqAS+4a75Q4m/ne8x5uLjq7m x1n03VplMRcYR4IdPSs5R8cr607jI4+hfWsyDuFLjB26AHQAz1N1d/CIA7SwxQjelM226YB1rAQ a5p/9zS04+uVOxnXx0yXDG+95LyzVimEa5fAKhQP8wLCoIL2jVQof8jVt42U3ogAV/xXfwRnQUo g/jzfY6ZCrxQfmCB/kW5+87m79YE/B9+n/kp68uXzFUj7154cedc2roRvissr2Eu4GWn5iybkJF cCD9u/2c2vSA9d+WzNQqNmsW0UK/md7nKyigllT8yV6auu6xp6tKw0GsUp2iQEde92zE98l+ew1 IKoYq5LcvXKpbdEhVvRSEcylsYLhZgoGf7ZaBrrxvLbJVDSIep1cx2fV42d1HFR9y5SCLHKBN1L 6qwjLOgVMKECNUyOXYQM89JQzVmgTT370cTYA7oTOhrT/EKu6kCzf/IOhRIl+Pn4GiHsPDZPHUm 2b8Cx/YIeLZwV4cNMucqfI5GwZ3M+XhMTRFeJAqqm3zC7kSS86JbvttkPbpn91TpnCIj9/0ZscU c6xG9Nscf0sNLDme3THM4PKAQPOTvNqcWjU5Q2iPDCTUvH1dfUi84elu7DJyaXowZRGQ1AL7onj YEqPJdcGnfJOt6f31uQ0rFF7PskQ= X-Received: by 2002:a05:7022:ea8d:b0:1a7:216d:157c with SMTP id a92af1059eb24-1b556902db6mr27823863c88.34.1795924028361; Sat, 28 Nov 2026 19:47:08 -0800 (PST) Received: from devbox.ts.blockcast.net ([2602:f74d:1::32]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b56ef9fd16sm61119077c88.4.2026.11.28.19.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 19:47:07 -0800 (PST) From: Omar Ramadan To: Taehee Yoo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: Simon Horman , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Willem de Bruijn Subject: [PATCH net-next v4 08/12] amt: receive the AMT gateway control plane over IPv6 Date: Sun, 29 Nov 2026 03:46:48 +0000 Message-ID: <20261129034652.1853485-9-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261129034652.1853485-1-omar@blockcast.net> References: <20261129034652.1853485-1-omar@blockcast.net> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit An 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. 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. Assisted-by: LLM Signed-off-by: Omar Ramadan --- drivers/net/amt.c | 158 ++++++++++++++++++++++++++++++++++++++-------- include/net/amt.h | 2 + 2 files changed, 134 insertions(+), 26 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 78d1e00e3..4dfe0a075 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -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, @@ -2698,27 +2761,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); @@ -2803,6 +2888,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; @@ -2816,7 +2902,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) @@ -3447,9 +3534,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; @@ -3460,10 +3546,17 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb) kfree_skb(skb); goto out; } - remote_ip = READ_ONCE(amt->remote_ip); skb->dev = amt->dev; - saddr = ip_hdr(skb)->saddr; + /* Snapshot the outer source before amt_parse_type() pulls. */ + amt_outer_saddr(amt, skb, &saddr); + /* 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; + } type = amt_parse_type(skb); if (type == -1) { err = true; @@ -3471,9 +3564,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; @@ -3485,7 +3586,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; @@ -3496,7 +3597,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; @@ -3635,13 +3736,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; @@ -3710,7 +3815,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; @@ -3759,7 +3864,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 @@ -3929,6 +4034,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; diff --git a/include/net/amt.h b/include/net/amt.h index 9d27bc6a3..b690c8788 100644 --- a/include/net/amt.h +++ b/include/net/amt.h @@ -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,