Skip to contentSkip to conversation

net/ipv6: Introduce accept_unsolicited_na knob to implement router-side changes for RFC9131

PATCH Applied Arun Ajith S 3 participants 4 messages Apr 15, 2022 – Apr 17, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 net/ipv6: Introduce accept_unsolicited_na knob to implement router-side changes for RFC9131

Add a new neighbour cache entry in STALE state for routers on receiving an unsolicited (gratuitous) neighbour advertisement with target link-layer-address option specified.
This is similar to the arp_accept configuration for IPv4.
A new sysctl endpoint is created to turn on this behaviour:
/proc/sys/net/ipv6/conf/interface/accept_unsolicited_na.

---
 Documentation/networking/ip-sysctl.rst        |  27 ++
 include/linux/ipv6.h                          |   1 +
 include/uapi/linux/ipv6.h                     |   1 +
 net/ipv6/addrconf.c                           |  10 +
 net/ipv6/ndisc.c                              |  20 +-
 tools/testing/selftests/net/Makefile          |   1 +
 .../net/ndisc_unsolicited_na_test.sh          | 255 ++++++++++++++++++
 7 files changed, 314 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/ndisc_unsolicited_na_test.sh
Documentation/networking/ip-sysctl.rst +27 -0
index b0024aa7b051..433f2e4a5fed 100644
@@ -2467,6 +2467,33 @@ drop_unsolicited_na - BOOLEAN
 
 	By default this is turned off.
 
+accept_unsolicited_na - BOOLEAN
+	Add a new neighbour cache entry in STALE state for routers on receiving an
+	unsolicited neighbour advertisement with target link-layer address option
+	specified. This is as per router-side behavior documented in RFC9131.
+	This has lower precedence than drop_unsolicited_na.
+
+	 ====   ======  ======  ==============================================
+	 drop   accept  fwding                   behaviour
+	 ----   ------  ------  ----------------------------------------------
+	    1        X       X  Drop NA packet and don't pass up the stack
+	    0        0       X  Pass NA packet up the stack, don't update NC
+	    0        1       0  Pass NA packet up the stack, don't update NC
+	    0        1       1  Pass NA packet up the stack, and add a STALE
+	                        NC entry
+	 ====   ======  ======  ==============================================
+
+	This will optimize the return path for the initial off-link communication
+	that is initiated by a directly connected host, by ensuring that
+	the first-hop router which turns on this setting doesn't have to
+	buffer the initial return packets to do neighbour-solicitation.
+	The prerequisite is that the host is configured to send
+	unsolicited neighbour advertisements on interface bringup.
+	This setting should be used in conjunction with the ndisc_notify setting
+	on the host to satisfy this prerequisite.
+
+	By default this is turned off.
+
 enhanced_dad - BOOLEAN
 	Include a nonce option in the IPv6 neighbor solicitation messages used for
 	duplicate address detection per RFC7527. A received DAD NS will only signal
include/linux/ipv6.h +1 -0
index 16870f86c74d..918bfea4ef5f 100644
@@ -61,6 +61,7 @@ struct ipv6_devconf {
 	__s32		suppress_frag_ndisc;
 	__s32		accept_ra_mtu;
 	__s32		drop_unsolicited_na;
+	__s32		accept_unsolicited_na;
 	struct ipv6_stable_secret {
 		bool initialized;
 		struct in6_addr secret;
include/uapi/linux/ipv6.h +1 -0
index d4178dace0bf..549ddeaf788b 100644
@@ -194,6 +194,7 @@ enum {
 	DEVCONF_IOAM6_ID,
 	DEVCONF_IOAM6_ID_WIDE,
 	DEVCONF_NDISC_EVICT_NOCARRIER,
+	DEVCONF_ACCEPT_UNSOLICITED_NA,
 	DEVCONF_MAX
 };
 
net/ipv6/addrconf.c +10 -0
index 1afc4c024981..6473dc84b71d 100644
@@ -5587,6 +5587,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
 	array[DEVCONF_IOAM6_ID] = cnf->ioam6_id;
 	array[DEVCONF_IOAM6_ID_WIDE] = cnf->ioam6_id_wide;
 	array[DEVCONF_NDISC_EVICT_NOCARRIER] = cnf->ndisc_evict_nocarrier;
+	array[DEVCONF_ACCEPT_UNSOLICITED_NA] = cnf->accept_unsolicited_na;
 }
 
 static inline size_t inet6_ifla6_size(void)
@@ -7037,6 +7038,15 @@ static const struct ctl_table addrconf_sysctl[] = {
 		.extra1		= (void *)SYSCTL_ZERO,
 		.extra2		= (void *)SYSCTL_ONE,
 	},
+	{
+		.procname	= "accept_unsolicited_na",
+		.data		= &ipv6_devconf.accept_unsolicited_na,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+		.extra1		= (void *)SYSCTL_ZERO,
+		.extra2		= (void *)SYSCTL_ONE,
+	},
 	{
 		/* sentinel */
 	}
net/ipv6/ndisc.c +19 -1
index fcb288b0ae13..254addad0dd3 100644
@@ -979,6 +979,7 @@ static void ndisc_recv_na(struct sk_buff *skb)
 	struct inet6_dev *idev = __in6_dev_get(dev);
 	struct inet6_ifaddr *ifp;
 	struct neighbour *neigh;
+	bool create_neigh;
 
 	if (skb->len < sizeof(struct nd_msg)) {
 		ND_PRINTK(2, warn, "NA: packet too short\n");
@@ -999,6 +1000,7 @@ static void ndisc_recv_na(struct sk_buff *skb)
 	/* For some 802.11 wireless deployments (and possibly other networks),
 	 * there will be a NA proxy and unsolicitd packets are attacks
 	 * and thus should not be accepted.
+	 * drop_unsolicited_na takes precedence over accept_unsolicited_na
 	 */
 	if (!msg->icmph.icmp6_solicited && idev &&
 	    idev->cnf.drop_unsolicited_na)
@@ -1039,7 +1041,23 @@ static void ndisc_recv_na(struct sk_buff *skb)
 		in6_ifa_put(ifp);
 		return;
 	}
-	neigh = neigh_lookup(&nd_tbl, &msg->target, dev);
+	/* RFC 9131 updates original Neighbour Discovery RFC 4861.
+	 * An unsolicited NA can now create a neighbour cache entry
+	 * on routers if it has Target LL Address option.
+	 *
+	 * drop   accept  fwding                   behaviour
+	 * ----   ------  ------  ----------------------------------------------
+	 *    1        X       X  Drop NA packet and don't pass up the stack
+	 *    0        0       X  Pass NA packet up the stack, don't update NC
+	 *    0        1       0  Pass NA packet up the stack, don't update NC
+	 *    0        1       1  Pass NA packet up the stack, and add a STALE
+	 *                          NC entry
+	 * Note that we don't do a (daddr == all-routers-mcast) check.
+	 */
+	create_neigh = !msg->icmph.icmp6_solicited && lladdr &&
+		       idev && idev->cnf.forwarding &&
+		       idev->cnf.accept_unsolicited_na;
+	neigh = __neigh_lookup(&nd_tbl, &msg->target, dev, create_neigh);
 
 	if (neigh) {
 		u8 old_flags = neigh->flags;
tools/testing/selftests/net/Makefile +1 -0
index 3fe2515aa616..af7f6e6ff182 100644
@@ -36,6 +36,7 @@ TEST_PROGS += srv6_end_dt4_l3vpn_test.sh
 TEST_PROGS += srv6_end_dt6_l3vpn_test.sh
 TEST_PROGS += vrf_strict_mode_test.sh
 TEST_PROGS += arp_ndisc_evict_nocarrier.sh
+TEST_PROGS += ndisc_unsolicited_na_test.sh
 TEST_PROGS_EXTENDED := in_netns.sh setup_loopback.sh setup_veth.sh
 TEST_PROGS_EXTENDED += toeplitz_client.sh toeplitz.sh
 TEST_GEN_FILES =  socket nettest
tools/testing/selftests/net/ndisc_unsolicited_na_test.sh new file +255 -0

255 lines not on this page · raw message

Signature · 5 lines
2.27.0
---
Changes from v5:
Fixed simple table syntax in ip-sysctl.rst to include the missing tab.
Ran "make htmldocs SPHINXDIRS=networking" and verified the generated ip-sysctl.html to ensure that the table is rendered correctly.
Reviewed-by on v6 1/1
#1 lore raw
Quoted 17 lines · Arun Ajith S
Documentation/networking/ip-sysctl.rst +17 -0
+accept_unsolicited_na - BOOLEAN
+	Add a new neighbour cache entry in STALE state for routers on receiving an
+	unsolicited neighbour advertisement with target link-layer address option
+	specified. This is as per router-side behavior documented in RFC9131.
+	This has lower precedence than drop_unsolicited_na.
+
+	 ====   ======  ======  ==============================================
+	 drop   accept  fwding                   behaviour
+	 ----   ------  ------  ----------------------------------------------
+	    1        X       X  Drop NA packet and don't pass up the stack
+	    0        0       X  Pass NA packet up the stack, don't update NC
+	    0        1       0  Pass NA packet up the stack, don't update NC
+	    0        1       1  Pass NA packet up the stack, and add a STALE
+	                        NC entry
+	 ====   ======  ======  ==============================================
+
+	This will optimize the return path for the initial off-link communication

Documentation/networking/ip-sysctl.rst drop_unsolicited_na - BOOLEAN · line 2496

Quoted 10 lines
Documentation/networking/ip-sysctl.rst +10 -0
+	that is initiated by a directly connected host, by ensuring that
+	the first-hop router which turns on this setting doesn't have to
+	buffer the initial return packets to do neighbour-solicitation.
+	The prerequisite is that the host is configured to send
+	unsolicited neighbour advertisements on interface bringup.
+	This setting should be used in conjunction with the ndisc_notify setting
+	on the host to satisfy this prerequisite.
+
+	By default this is turned off.
+

Looks good. htmldocs builds successfully and the table displayed properly.

However, I remind you the following:

- The patch changelogs should be put between the dashes (---) and diffstat. I don't see the changelogs when I hit reply-all because you put them as message signature (at very bottom of patch message).
- DON'T DO top-posting, DO configure your MUA to make reply text below the quoted text instead.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#2 lore raw
Quoted 36 lines · Bagas Sanjaya
Quoted 17 lines · Arun Ajith S
Documentation/networking/ip-sysctl.rst +17 -0
+accept_unsolicited_na - BOOLEAN
+     Add a new neighbour cache entry in STALE state for routers on receiving an
+     unsolicited neighbour advertisement with target link-layer address option
+     specified. This is as per router-side behavior documented in RFC9131.
+     This has lower precedence than drop_unsolicited_na.
+
+      ====   ======  ======  ==============================================
+      drop   accept  fwding                   behaviour
+      ----   ------  ------  ----------------------------------------------
+         1        X       X  Drop NA packet and don't pass up the stack
+         0        0       X  Pass NA packet up the stack, don't update NC
+         0        1       0  Pass NA packet up the stack, don't update NC
+         0        1       1  Pass NA packet up the stack, and add a STALE
+                             NC entry
+      ====   ======  ======  ==============================================
+
+     This will optimize the return path for the initial off-link communication

Documentation/networking/ip-sysctl.rst drop_unsolicited_na - BOOLEAN · line 2496

Quoted 10 lines
Documentation/networking/ip-sysctl.rst +10 -0
+     that is initiated by a directly connected host, by ensuring that
+     the first-hop router which turns on this setting doesn't have to
+     buffer the initial return packets to do neighbour-solicitation.
+     The prerequisite is that the host is configured to send
+     unsolicited neighbour advertisements on interface bringup.
+     This setting should be used in conjunction with the ndisc_notify setting
+     on the host to satisfy this prerequisite.
+
+     By default this is turned off.
+

Looks good. htmldocs builds successfully and the table displayed properly.

However, I remind you the following:

Quoted 8 lines

- The patch changelogs should be put between the dashes (---) and diffstat. I don't see the changelogs when I hit reply-all because you put them as message signature (at very bottom of patch message).
- DON'T DO top-posting, DO configure your MUA to make reply text below the quoted text instead.

--
An old man doll... just what I always wanted! - Clara

Thank you.
I will keep the tips for the Changelog in my mind for my next patch.

#3 lore raw
In reply to Arun Ajith S
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 8 lines · On Fri, 15 Apr 2022 08:34:02 +0000 you wrote:

Add a new neighbour cache entry in STALE state for routers on receiving an unsolicited (gratuitous) neighbour advertisement with target link-layer-address option specified.
This is similar to the arp_accept configuration for IPv4.
A new sysctl endpoint is created to turn on this behaviour:
/proc/sys/net/ipv6/conf/interface/accept_unsolicited_na.

[...]

Here is the summary with links:
- [net-next,v6] net/ipv6: Introduce accept_unsolicited_na knob to implement router-side changes for RFC9131

    https://git.kernel.org/netdev/net-next/c/f9a2fb73318e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html