From nobody Thu Sep 24 22:56:13 2026 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E80F3B7746 for ; Fri, 18 Sep 2026 22:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789769612; cv=none; b=QxvJ82rhofBOXpJfpx+PUJHH4u/MrBqgo+gLt3P/aWL4eEUwklabDCeoU7+WJCC8jFpyCdA4WwoZ2qOCQjubjC9OJTvQZnI4vntt3iMjV9yQ4UlC0V8vOTRL02hY5/0H0euesEBBrhe3wG2Dmup3hCWSnb3MWsVCy1RW77olftM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789769612; c=relaxed/simple; bh=lMhWyqDKU8tuhSb63S6z46HY7Dg7FOFh3EIVXTTzpPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uN4nk2rwXOCWQpfRQoeyHpqNxupMjB2stdHVC303tb7bXA2HLGitoNwAhBPlVzhuehB7Kz2m4e2fLokfumnlfOeilomxzR0dVRp8bxNPFDI8o5BUbrkZpfj2bDM/jFh/f89cc0CYRSK/yJjDKSThvXj9Dv8iG0qOCvjfGPmPnB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lF4qAbm/; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lF4qAbm/" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2caced6038eso10888595ad.0 for ; Fri, 18 Sep 2026 15:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789769609; x=1790374409; 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=eOwaBnnM/eJvrLcA+Skp3S3cmP/0pzGWTCv//0JXzxA=; b=lF4qAbm/BLdITdpanQGFmjZhWxCS3ksn889qJJr+BiqHSqZZzuIoMTd3HOPW7nS5CO 6+XShZWVhtBG/73n33Vz2Z7b1GNZlK09jqSwUs2U8ZYWKYxqchbqOCn+ldzFdP+Low1E dmLE0IiO3i0eD5HfmducbY2BhGDtAIv2XsUlFX7M2XRPaID3f+bDUbYwY/u0XZ36L2D2 wZ3H9ZoX7GvcEFaRvFY9ovUmWp+tRYDT6IqSuBwRljOLdKwSLMh0JSmoUaIoWTlAeqRg oOulOk+m/+msi30+uFQu8Fl4ahBJnGqmk0eXT8vabCKM9pWQ0FOSsqF0fBfPrFkhkAqD WW1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789769609; x=1790374409; 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=eOwaBnnM/eJvrLcA+Skp3S3cmP/0pzGWTCv//0JXzxA=; b=Kom1ac+ycq8sjNuvRi++nhh4SmK79iKdMuYslhePjAiAZB+dEpMJfC2mrDoAbNwevy HD9TEd9q6NE/TE7Mcx4qSVysbYJn9B6c8HmId4tFKQW2V6BUgdX4b2sX53sxQ/xLjue3 fp/9Zx6l22qW6iygQH6g17YpbcRkqfoziiq4Z/IbrbOXgQmtWO9AZKICv1ucXOXgv7TE JQtY1X2vJ08hbMEkHfSTUX3XbCGg9yqDL0Ih7dJbd/yZQkxKLEkCLCxLzc8DKxae8Iby NaiUEvCyD8/1i3Qwbov81APlJcP6rSfW/qSYiwShiroht6o/RwathgtU7OkqMl7LEDEo M1YA== X-Forwarded-Encrypted: i=1; AKwUvBzdEFTcwEh+4zjJXc5xXwjVTSqUH5heQ1vsXqoWddHPYeTpAF+llcRRJtdEuOQlm8rPoGO+O/YMQ45L1yM=@vger.kernel.org X-Gm-Message-State: AFuF++lSBOo6Qy4+Gc9OZaR1GHEodeE+V6NJM5PiQwsmXkYfokVq0zYu yxtKBKauHZbdkNmNPgsQ1qpvZqM9xnLSk3orXnuS/ztI0eL8GKkc7Qhs X-Gm-Gg: AYBFou1AHUsX6R1diT6uWuz7WmpS12po8Tube02KaSHfZW3vukQ7N+aaVD5yZCa7qoL Nn67rJAKb62BwauwnWuCrBjwWOSWnfE9TeCmDzA065Y20aElzyxfvu/AuvbiwNt36/3JaqRB+Rm zeVIixsOwlYqZ9gax6pRJBCuhAzECDaJ1Olvu36KEWpDTY48CCNEhMEPjoRTRBJEYAvC3fo/U1g 6cr03FijibupV/bEbqUPuc0pB3/WRyrr8GpUN2SjMCIHIA494nd5hLQ0CVUJcx/02YaFRvVncN4 dbfO7KhpBMNEXmuc283btFdLXj4tScke5+RLf3sFudSixk/ozuO2ure2MBa5Pfxw0hvqbm+SMIb C8z8nE0EjnRwac9UDDAUhhoOOT984Bq3nUWD4cl1s501To9P+NAwc4377xgjoc4JyQ/E8or0rWd 9oJWykuLCR4T0g1gIQL7AGeo82bb3ushnwOx4JyHaP87keXuNFc6dUBflplz7obPkr/5nIVuAP1 YuQf4L6/5jSQ3TMbnbJbHaLRxEtE5F/rQecKPPjskMAZKHIszrPObhqqptqKVVAy4XkywgG/SsN ddYSE7z5m88JXvwayGHn X-Received: by 2002:a17:903:1103:b0:2dd:ad7d:72e1 with SMTP id d9443c01a7336-2ddad7d753amr64644185ad.24.1789769608714; Fri, 18 Sep 2026 15:13:28 -0700 (PDT) Received: from lawlee-vm0.d4y3nv5wwgfelhhopdxv1tqjld.dx.internal.cloudapp.net ([13.93.150.60]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-33c3311a716sm1553671eec.8.2026.09.18.15.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 15:13:28 -0700 (PDT) From: Lawrence Lee To: David Ahern , Ido Schimmel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Simon Horman , Randy Dunlap , netdev@vger.kernel.org, Arun Ajith S , Roopa Prabhu , Jaehee Park , Jonathan Corbet , Shuah Khan , Shuah Khan , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 1/2] ipv6: update NUD_FAILED neighbors from NA messages Date: Fri, 18 Sep 2026 22:13:23 +0000 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Transition a FAILED neighbor entry to STALE upon receipt of an NA message on routers when accept_untracked_na is enabled. This extends the RFC 9131 accept_untracked_na behavior so that FAILED entries are treated the same as non-existent entries. RFC 4861 section 7.3.3 says that an entry should be deleted when address resolution fails. Linux instead retains the entry in NUD_FAILED, so treating it as untracked is consistent with the protocol model. Trying to resolve FAILED neighbors via periodic probing (e.g. using NTF_EXT_MANAGED) is more work compared to this approach which uses information in NAs that the kernel may already be receiving. Note that because this behavior in IPv6 is dependent on the accept_untracked_na sysctl setting, this approach is more conservative than IPv4 which transitions FAILED neighbors to STALE by default upon receiving GARPs. Link: https://lore.kernel.org/r/20260813233344.445265-1-lfqlee314@gmail.com Assisted-by: LLM Sashiko sparse Signed-off-by: Lawrence Lee Reviewed-by: Ido Schimmel --- The existing 6LoWPAN override-only handling also applies to INCOMPLETE entries and is intentionally left unchanged. The existing rt6_clean_tohost() source-versus-target behavior applies to all neighbor states and is also left unchanged. Documentation/networking/ip-sysctl.rst | 28 ++++++++------- net/ipv6/ndisc.c | 47 ++++++++++++++------------ 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/network= ing/ip-sysctl.rst index f7af0286341c..685c84cf543d 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -3225,18 +3225,19 @@ drop_unsolicited_na - BOOLEAN Default: 0 (disabled). =20 accept_untracked_na - INTEGER - Define behavior for accepting neighbor advertisements from devices that - are absent in the neighbor cache: + Define behavior for accepting neighbor advertisements for IPv6 addresses + that are absent from the neighbor cache or whose entries are in FAILED + state: =20 - - 0 - (default) Do not accept unsolicited and untracked neighbor - advertisements. + - 0 - (default) Do not create new neighbor cache entries or update + FAILED entries from neighbor advertisements. =20 - - 1 - Add a new neighbor cache entry in STALE state for routers on - receiving a neighbor advertisement (either solicited or unsolicited) - with target link-layer address option specified if no neighbor entry - is already present for the advertised IPv6 address. Without this knob, - NAs received for untracked addresses (absent in neighbor cache) are - silently ignored. + - 1 - For routers, add a new neighbor cache entry or update an existing + FAILED entry to STALE upon receiving a neighbor advertisement (either + solicited or unsolicited) with the target link-layer address option + specified. Without this knob, NAs received for untracked addresses + (absent from the neighbor cache or in FAILED state) are silently + ignored. =20 This is as per router-side behavior documented in RFC9131. =20 @@ -3251,9 +3252,10 @@ accept_untracked_na - INTEGER used in conjunction with the ndisc_notify setting on the host to satisfy this prerequisite. =20 - - 2 - Extend option (1) to add a new neighbor cache entry only if the - source IP address is in the same subnet as an address configured on - the interface that received the neighbor advertisement. + - 2 - Extend option (1) to add a new neighbor cache entry or update a + FAILED entry only if the source IP address is in the same subnet as + an address configured on the interface that received the neighbor + advertisement. =20 enhanced_dad - BOOLEAN Include a nonce option in the IPv6 neighbor solicitation messages used for diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 90cd5d852569..12d85d7f8234 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -973,13 +973,13 @@ static enum skb_drop_reason ndisc_recv_ns(struct sk_b= uff *skb) static int accept_untracked_na(struct inet6_dev *idev, struct in6_addr *sa= ddr) { switch (READ_ONCE(idev->cnf.accept_untracked_na)) { - case 0: /* Don't accept untracked na (absent in neighbor cache) */ + case 0: /* Don't accept untracked NA (absent or FAILED) */ return 0; - case 1: /* Create new entries from na if currently untracked */ + case 1: /* Create new or update FAILED entries from NA */ return 1; - case 2: /* Create new entries from untracked na only if saddr is in the + case 2: /* Create new or update FAILED entries only if saddr is in the * same subnet as an address configured on the interface that - * received the na + * received the NA */ return !!ipv6_chk_prefix(saddr, idev->dev); default: @@ -1067,34 +1067,39 @@ static enum skb_drop_reason ndisc_recv_na(struct sk= _buff *skb) neigh =3D neigh_lookup(tbl, &msg->target, dev); =20 /* RFC 9131 updates original Neighbour Discovery RFC 4861. - * NAs with Target LL Address option without a corresponding - * entry in the neighbour cache can now create a STALE neighbour - * cache entry on routers. + * NAs with Target LL Address option can now create a STALE neighbor + * cache entry on routers if the NA does not have a corresponding entry + * in the neighbour cache or has a corresponding FAILED entry. * - * entry accept fwding solicited behaviour - * ------- ------ ------ --------- ---------------------- - * present X X 0 Set state to STALE - * present X X 1 Set state to REACHABLE - * absent 0 X X Do nothing - * absent 1 0 X Do nothing - * absent 1 1 X Add a new STALE entry + * entry accept fwding solicited behaviour + * ----------- ------ ------ --------- ---------------------- + * non-FAILED X X 0 Set state to STALE + * non-FAILED X X 1 Set state to REACHABLE + * FAILED 0 X X Do nothing + * FAILED 1 0 X Do nothing + * FAILED 1 1 X Set state to STALE + * absent 0 X X Do nothing + * absent 1 0 X Do nothing + * absent 1 1 X Add a new STALE entry * * Note that we don't do a (daddr =3D=3D all-routers-mcast) check. */ new_state =3D msg->icmph.icmp6_solicited ? NUD_REACHABLE : NUD_STALE; - if (!neigh && lladdr && idev && READ_ONCE(idev->cnf.forwarding)) { - if (accept_untracked_na(idev, saddr)) { - neigh =3D neigh_create(tbl, &msg->target, dev); - new_state =3D NUD_STALE; + if (!neigh || (READ_ONCE(neigh->nud_state) & NUD_FAILED)) { + if (!lladdr || !idev || !READ_ONCE(idev->cnf.forwarding) || + !accept_untracked_na(idev, saddr)) { + if (neigh) + neigh_release(neigh); + return reason; } + if (!neigh) + neigh =3D neigh_create(tbl, &msg->target, dev); + new_state =3D NUD_STALE; } =20 if (neigh && !IS_ERR(neigh)) { u8 old_flags =3D neigh->flags; =20 - if (READ_ONCE(neigh->nud_state) & NUD_FAILED) - goto out; - /* * Don't update the neighbor cache entry on a proxy NA from * ourselves because either the proxied node is off link or it --=20 2.43.0 From nobody Thu Sep 24 22:56:13 2026 Received: from mail-pj2-f34.google.com (mail-pj2-f34.google.com [74.125.227.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DC563D7D72 for ; Fri, 18 Sep 2026 22:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.162 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789769614; cv=none; b=u6eRZ1goolT1Uk+jEEB7CPVvKY6LcVtixUe9whqS+nSYodJoIl8efKip5+iC/S5IaOXU+dSUreq5XH1LzuFGTIn9NbI96EKD7bih2Muem7MlESdEAAVXbv2BNnrGLUIcEwXuXglxonxkcD/HiJcj2u/RNAX/f8Yxivn2+2AYSus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789769614; c=relaxed/simple; bh=a8MxLalV/Tc88FlPfcLwKhMqY1j+NFMNNs6ids+FTFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zo4bunF6R2Tr95THeVjkJrkRtFLZNvtWX6LpYSOhxUSrrSHr2qgVsiD2p2Tf0Rmdd8qI/ygYvtVXGMUS0vVFRzTVqyRyXXgzszPN8svwqZYjptVq2Vo2tRfvloFpcz4LFKXrpQmEpWe5KMPoIrR6K50eYnZSMuN5fkupoHnC8o8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fHpdhWEd; arc=none smtp.client-ip=74.125.227.162 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fHpdhWEd" Received: by mail-pj2-f34.google.com with SMTP id d9443c01a7336-2d747eb79f7so8954775ad.1 for ; Fri, 18 Sep 2026 15:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789769610; x=1790374410; 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=rm8cjM3ck/qNptPFhHqG5DJOS8JXLRC+n1adrw2QUvg=; b=fHpdhWEdcJdkbkUj3qf5Q8kGRFocINSTU+pcxIY3fY2IgbYe3aIsHLMbR+jLNzmN0Q K071VhCM9s0OzNuR5ltQO+oV4Va44jc0SvRa6mgbiHhG6J5A1zj9yV/6Hofjq9kMA2uv gla1HpCK2T+Nho+Jrl5tIl+WQMNke+k8jnpYvLgB/yWI/VwiRp8Ox5sWYyCOlkQcFqAe Z5ohRRFLk3GNyzCIYXK72SyAmay24g8l3P+G9w3hCQh6I05sLnRE0Qn2nGlS++Zlvdtk 465eJArPZnc27dqESftLHhjn3Fwd3caPcCN0UzbDOdDo/n8PpPI12DiqhK8oE60N5m4z KymA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789769610; x=1790374410; 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=rm8cjM3ck/qNptPFhHqG5DJOS8JXLRC+n1adrw2QUvg=; b=ZDWoS+IYDFKteXH1tK4tr8xtf/sTMPs8+5Lb7N6mMLo46ZUYFkzuvfOb6YQR6qhQ2e AePuk6JAvS6sAVAQwOqekKxO7nH9daCzqYOkdn9ohMkkf/oa9wM05ALDbVTxw5ZSHNBH xM7xCjdCJhZg/uvAcnaB2gaj7NTkbe5hio9uHAUAEsHxyKq3ITdfEYzm+eUjalwDOWNJ 0nttiLAK/ObUYYjiuGY2k2I02zbjaAOoXQ57o18E2An92PdXfoR5zzGHKVlr2QtNv98B CiMSDbCc7huctsXB6piHhx5dH+D3pUTf0ajWuo+4GsjLsOq4JAKjGIS7NKrelCvoOO3T p5Yw== X-Forwarded-Encrypted: i=1; AKwUvBwHC6peLJ0zEtsO9wXIIR+ZxaOg4Qs+YmBBLIbSVObzVePxeeDtg/tZQAz17d/hq7tsVNgVqtZrSo2pNMo=@vger.kernel.org X-Gm-Message-State: AFuF++mytuezrpuEH3x2EMAWjlcb825A39x+HoTL6V8sNDDVI0wr0HC1 Vdp95S6xKMFuavRtp3pBM25hb8OFgiDtH0EGcdMGbxjg6r/yiqhjoJ6O X-Gm-Gg: AYBFou36xAxzjH+HUi9cvxW2fXE2ceiAz7lc2J+4BSo9K0RmcLC8R9F6/RXoqvIT+oq JmpcVZfV/r1gp3O6P9BloIP3NTlEjBsNinK85KpP7kC3jgnIGEn1TdNC1NyVBQtvGFSwr3H/lZS 67XEcZVXKM8Qzj3V6YMxKD+WOxxYvjOOD5uhfMfv7CiSlew2YRrzS+qLMf4C7qTOMFQh4YhcTz3 YgGf+a6ufj1YfdeokFKbs6WvqCbpHvQdjvNvnLml5ub1VBZvzMbJqM7HZUo8mtV6vu06NLoNrJL EyE40nY25+H0NZfLkymbMRNL1a2bqQ0kGOoykgIsZvHN6QWHVylMJ+DILG1YKswjAtMCsNyZUmg AcVk7a2Dbie+eh+PVXm+uYOhFAA0VXubDS5qPNztfoXf7RisfjgL+3ZANFf3RqPnlxig58ZoZ9x /9dA3SQ46gdVoNzOqBLq/22eh56O9H16S9q8H0wsNfiIC+4globdDDn20QGL9EAg7HGjfLJQD0L Z1jSZBsCSmov9mmpy/CGTeDQlCMivignmeVlL6nf2Twa3aos6yRwNN4G99y/6Y7TCWALqZKGJwz kwQy4MS2H5vXVaaTbLD1DR+lNDj6Ft4= X-Received: by 2002:a17:903:19e6:b0:2dd:ad73:c98b with SMTP id d9443c01a7336-2ddb1bd8866mr65289185ad.35.1789769610351; Fri, 18 Sep 2026 15:13:30 -0700 (PDT) Received: from lawlee-vm0.d4y3nv5wwgfelhhopdxv1tqjld.dx.internal.cloudapp.net ([13.93.150.60]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-33c3311a716sm1553671eec.8.2026.09.18.15.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 15:13:29 -0700 (PDT) From: Lawrence Lee To: David Ahern , Ido Schimmel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Simon Horman , Randy Dunlap , netdev@vger.kernel.org, Arun Ajith S , Roopa Prabhu , Jaehee Park , Jonathan Corbet , Shuah Khan , Shuah Khan , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 2/2] selftests: net: test untracked NA recovery of FAILED neighbors Date: Fri, 18 Sep 2026 22:13:24 +0000 Message-ID: <7285b55a1e29d2f04de4e3fe1e723a9724e0377e.1789734885.git.lfqlee314@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Seed a FAILED neighbor before triggering an unsolicited NA. Verify that the entry transitions to STALE and learns the advertised link-layer address only when drop_unsolicited_na is disabled, accept_untracked_na mode 1 or in-prefix mode 2 is enabled, and IPv6 forwarding is enabled. Verify that disabling each gate keeps the entry in FAILED without a link-layer address. Mark the seed externally learned and disable carrier-based eviction so the entry cannot be garbage-collected before the NA arrives. Require the marker after processing to prove that a recovered entry was updated in place instead of deleted and recreated. Keep the NA source, target, and neighbor key fixed for the mode 2 cases. Vary the prefix configured on the router to exercise the source-prefix check without changing the entry under test. Arm packet capture before bringing up the host interface and starting DAD. Wait for the capture to become ready and for tcpdump to exit so the NA cannot be missed and receive processing is complete before checking the neighbor entry. Link: https://lore.kernel.org/r/20260813233344.445265-1-lfqlee314@gmail.com Assisted-by: LLM Sashiko sparse Signed-off-by: Lawrence Lee --- .../net/ndisc_unsolicited_na_test.sh | 195 ++++++++++++++---- 1 file changed, 160 insertions(+), 35 deletions(-) diff --git a/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh b/too= ls/testing/selftests/net/ndisc_unsolicited_na_test.sh index 5db69dad0cfc..ba9e670b5149 100755 --- a/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh +++ b/tools/testing/selftests/net/ndisc_unsolicited_na_test.sh @@ -3,12 +3,18 @@ =20 # This test is for the accept_untracked_na feature to # enable RFC9131 behaviour. The following is the test-matrix. -# drop accept fwding behaviour -# ---- ------ ------ ---------------------------------------------- -# 1 X X Don't update NC -# 0 0 X Don't update NC -# 0 1 0 Don't update NC -# 0 1 1 Add a STALE NC entry +# state drop accept fwding behaviour +# ------ ---- ------ ------ -----------------------------------------= ----- +# absent 1 X X Don't update NC +# absent 0 0 X Don't update NC +# absent 0 1 0 Don't update NC +# absent 0 1 1 Add a STALE NC entry +# failed 1 X X Keep the NC entry in FAILED state +# failed 0 0 X Keep the NC entry in FAILED state +# failed 0 1 0 Keep the NC entry in FAILED state +# failed 0 1 1 Update the NC entry to STALE +# failed 0 2 1 Update the NC entry to STALE if in-network +# failed 0 2 1 Keep the NC entry FAILED if out-of-network =20 source lib.sh ret=3D0 @@ -19,14 +25,18 @@ PAUSE=3Dno HOST_INTF=3D"veth-host" ROUTER_INTF=3D"veth-router" =20 -ROUTER_ADDR=3D"2000:20::1" +ROUTER_ADDR_IN_NETWORK=3D"2000:20::1" +ROUTER_ADDR_OUT_OF_NETWORK=3D"2000:21::1" +ROUTER_ADDR=3D"${ROUTER_ADDR_IN_NETWORK}" HOST_ADDR=3D"2000:20::2" +HOST_LLADDR=3D"02:00:00:00:00:02" SUBNET_WIDTH=3D64 ROUTER_ADDR_WITH_MASK=3D"${ROUTER_ADDR}/${SUBNET_WIDTH}" HOST_ADDR_WITH_MASK=3D"${HOST_ADDR}/${SUBNET_WIDTH}" =20 tcpdump_stdout=3D tcpdump_stderr=3D +tcpdump_pid=3D =20 log_test() { @@ -75,6 +85,7 @@ setup() =20 ${IP_ROUTER} link add ${ROUTER_INTF} type veth \ peer name ${HOST_INTF} netns ${HOST_NS} + ${IP_HOST} link set dev "${HOST_INTF}" address "${HOST_LLADDR}" =20 # Enable IPv6 on both router and host, and configure static addresses. # The router here is the DUT @@ -88,6 +99,8 @@ setup() ${ROUTER_CONF}.drop_unsolicited_na=3D${drop_unsolicited_na} ${IP_ROUTER_EXEC} sysctl -qw \ ${ROUTER_CONF}.accept_untracked_na=3D${accept_untracked_na} + ${IP_ROUTER_EXEC} sysctl -qw \ + ${ROUTER_CONF}.ndisc_evict_nocarrier=3D0 ${IP_ROUTER_EXEC} sysctl -qw ${ROUTER_CONF}.disable_ipv6=3D0 ${IP_ROUTER} addr add ${ROUTER_ADDR_WITH_MASK} dev ${ROUTER_INTF} =20 @@ -102,24 +115,39 @@ setup() } =20 start_tcpdump() { - set -e - tcpdump_stdout=3D`mktemp` - tcpdump_stderr=3D`mktemp` + tcpdump_stdout=3D$(mktemp) || return 1 + tcpdump_stderr=3D$(mktemp) || return 1 ${IP_ROUTER_EXEC} timeout 15s \ tcpdump --immediate-mode -tpni ${ROUTER_INTF} -c 1 \ "icmp6 && icmp6[0] =3D=3D 136 && src ${HOST_ADDR}" \ - > ${tcpdump_stdout} 2> /dev/null - set +e + > "${tcpdump_stdout}" 2> "${tcpdump_stderr}" & + tcpdump_pid=3D$! + + slowwait 5 grep -q "listening on ${ROUTER_INTF}" "${tcpdump_stderr}" +} + +wait_tcpdump() +{ + local rc + + wait "${tcpdump_pid}" + rc=3D$? + tcpdump_pid=3D + + return "${rc}" } =20 cleanup_tcpdump() { - set -e - [[ ! -z ${tcpdump_stdout} ]] && rm -f ${tcpdump_stdout} - [[ ! -z ${tcpdump_stderr} ]] && rm -f ${tcpdump_stderr} + if [ -n "${tcpdump_pid}" ]; then + kill "${tcpdump_pid}" 2> /dev/null + wait "${tcpdump_pid}" 2> /dev/null + fi + [ -n "${tcpdump_stdout}" ] && rm -f "${tcpdump_stdout}" + [ -n "${tcpdump_stderr}" ] && rm -f "${tcpdump_stderr}" tcpdump_stdout=3D tcpdump_stderr=3D - set +e + tcpdump_pid=3D } =20 cleanup() @@ -129,58 +157,145 @@ cleanup() ip netns del ${ROUTER_NS} } =20 -link_up() { - set -e +router_link_up() +{ ${IP_ROUTER} link set dev ${ROUTER_INTF} up +} + +host_link_up() +{ ${IP_HOST} link set dev ${HOST_INTF} up - set +e } =20 verify_ndisc() { local drop_unsolicited_na=3D$1 local accept_untracked_na=3D$2 local forwarding=3D$3 + local initial_state=3D${4:-absent} + local same_subnet=3D${5:-1} + local expected_lladdr + local neigh_show_output + local expected_state + + if [ "${drop_unsolicited_na}" -eq 0 ] && + [ "${forwarding}" -eq 1 ]; then + case "${accept_untracked_na}" in + 1) + expected_state=3DSTALE + expected_lladdr=3D"${HOST_LLADDR}" + ;; + 2) + if [ "${same_subnet}" -eq 1 ]; then + expected_state=3DSTALE + expected_lladdr=3D"${HOST_LLADDR}" + fi + ;; + esac + fi + if [ -z "${expected_state}" ] && + [ "${initial_state}" =3D "failed" ]; then + expected_state=3DFAILED + fi =20 - neigh_show_output=3D$(${IP_ROUTER} neigh show \ - to ${HOST_ADDR} dev ${ROUTER_INTF} nud stale) - if [ ${drop_unsolicited_na} -eq 0 ] && \ - [ ${accept_untracked_na} -eq 1 ] && \ - [ ${forwarding} -eq 1 ]; then - # Neighbour entry expected to be present for 011 case - [[ ${neigh_show_output} ]] + if [ -n "${expected_state}" ]; then + neigh_show_output=3D$(${IP_ROUTER} neigh show \ + to "${HOST_ADDR}" dev "${ROUTER_INTF}") + if [[ " ${neigh_show_output} " !=3D \ + *" ${expected_state} "* ]]; then + return 1 + fi + if [ -n "${expected_lladdr}" ] && + [[ " ${neigh_show_output} " !=3D \ + *" lladdr ${expected_lladdr} "* ]]; then + return 1 + fi + if [[ "${expected_state}" =3D=3D "FAILED" && + "${neigh_show_output}" =3D=3D *"lladdr"* ]]; then + return 1 + fi + if [ "${initial_state}" =3D "failed" ]; then + [[ "${neigh_show_output}" =3D=3D *"extern_learn"* ]] + fi else - # Neighbour entry expected to be absent for all other cases + neigh_show_output=3D$(${IP_ROUTER} neigh show \ + to "${HOST_ADDR}" dev "${ROUTER_INTF}") [[ -z ${neigh_show_output} ]] fi } =20 test_unsolicited_na_common() { + local same_subnet=3D${5:-1} + local neigh_show_output + + if [ "${same_subnet}" -eq 1 ]; then + ROUTER_ADDR=3D"${ROUTER_ADDR_IN_NETWORK}" + else + ROUTER_ADDR=3D"${ROUTER_ADDR_OUT_OF_NETWORK}" + fi + ROUTER_ADDR_WITH_MASK=3D"${ROUTER_ADDR}/${SUBNET_WIDTH}" + # Setup the test bed, but keep links down - setup $1 $2 $3 + setup "$1" "$2" "$3" + + if [ "${4:-absent}" =3D "failed" ]; then + if ! ${IP_ROUTER} neigh replace "${HOST_ADDR}" \ + dev "${ROUTER_INTF}" \ + nud failed extern_learn; then + echo "Unable to create NUD_FAILED neighbor entry" + return 1 + fi + neigh_show_output=3D$(${IP_ROUTER} neigh show \ + to "${HOST_ADDR}" dev "${ROUTER_INTF}") + if [[ " ${neigh_show_output} " !=3D *" FAILED "* ]]; then + echo "Unable to verify NUD_FAILED neighbor entry" + return 1 + fi + if [[ "${neigh_show_output}" !=3D *"extern_learn"* ]]; then + echo "Neighbor entry is not externally learned" + return 1 + fi + fi =20 - # Bring the link up, wait for the NA, - # and add a delay to ensure neighbour processing is done. - link_up - start_tcpdump + # Arm the capture before bringing up the host and starting DAD. + router_link_up || return 1 + start_tcpdump || return 1 + host_link_up || return 1 + + # Closing tcpdump's packet socket calls synchronize_net(), so waiting + # for it also waits for receive processing of the captured NA. + wait_tcpdump || return 1 =20 # Verify the neighbour table - verify_ndisc $1 $2 $3 + verify_ndisc "$1" "$2" "$3" "$4" "${same_subnet}" =20 } =20 test_unsolicited_na_combination() { - test_unsolicited_na_common $1 $2 $3 + local initial_state=3D${4:-absent} + local same_subnet=3D${5:-1} + local rc + + test_unsolicited_na_common "$1" "$2" "$3" "${initial_state}" \ + "${same_subnet}" + rc=3D$? test_msg=3D("test_unsolicited_na: " "drop_unsolicited_na=3D$1 " "accept_untracked_na=3D$2 " "forwarding=3D$3") - log_test $? 0 "${test_msg[*]}" + if [ "${initial_state}" =3D "failed" ]; then + test_msg+=3D("initial_state=3Dfailed") + fi + if [ "$2" -eq 2 ]; then + test_msg+=3D("same_subnet=3D${same_subnet}") + fi + log_test "${rc}" 0 "${test_msg[*]}" cleanup } =20 test_unsolicited_na_combinations() { # Args: drop_unsolicited_na accept_untracked_na forwarding + # [initial_state] [same_subnet] =20 # Expect entry test_unsolicited_na_combination 0 1 1 @@ -193,6 +308,16 @@ test_unsolicited_na_combinations() { test_unsolicited_na_combination 1 0 1 test_unsolicited_na_combination 1 1 0 test_unsolicited_na_combination 1 1 1 + + # Expect FAILED entry to become STALE + test_unsolicited_na_combination 0 1 1 failed + test_unsolicited_na_combination 0 2 1 failed 1 + + # Expect FAILED entry to remain FAILED + test_unsolicited_na_combination 0 0 1 failed + test_unsolicited_na_combination 0 1 0 failed + test_unsolicited_na_combination 1 1 1 failed + test_unsolicited_na_combination 0 2 1 failed 0 } =20 ##########################################################################= ##### --=20 2.43.0