net/ipv6: Introduce accept_unsolicited_na knob to implement router-side changes for RFC9131
Subsystems (5)
PATCH v3 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 | 23 ++ 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.py | 255 ++++++++++++++++++ 7 files changed, 310 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/net/ndisc_unsolicited_na_test.py
Documentation/networking/ip-sysctl.rst +23 -0
@@ -2467,6 +2467,29 @@ 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.py 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.py new file +255 -0
255 lines not on this page · raw message
Signature · 25 lines
2.27.0
---
Changes from v2:
1. Address David Ahern's review comments
- Remove Tested-by from commit description
- Add limits to new sysctl with extra1 and extra2
- Add an unit test, added to TEST_PROGS
Test output:
# time ./ndisc_unsolicited_na_test.py
TEST: test_unsolicited_na: drop_unsolicited_na=0 accept_unsolicited_na=1 forwarding=1 [ OK ]
TEST: test_unsolicited_na: drop_unsolicited_na=0 accept_unsolicited_na=0 forwarding=0 [ OK ]
TEST: test_unsolicited_na: drop_unsolicited_na=0 accept_unsolicited_na=0 forwarding=1 [ OK ]
TEST: test_unsolicited_na: drop_unsolicited_na=0 accept_unsolicited_na=1 forwarding=0 [ OK ]
TEST: test_unsolicited_na: drop_unsolicited_na=1 accept_unsolicited_na=0 forwarding=0 [ OK ]
TEST: test_unsolicited_na: drop_unsolicited_na=1 accept_unsolicited_na=0 forwarding=1 [ OK ]
TEST: test_unsolicited_na: drop_unsolicited_na=1 accept_unsolicited_na=1 forwarding=0 [ OK ]
TEST: test_unsolicited_na: drop_unsolicited_na=1 accept_unsolicited_na=1 forwarding=1 [ OK ]
Tests passed: 8
Tests failed: 0
real 0m21.700s
user 0m1.365s
sys 0m0.049sQuoted 6 lines · Arun Ajith S
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 thearp_acceptconfiguration for IPv4.
A new sysctl endpoint is created to turn on this behaviour:/proc/sys/net/ipv6/conf/interface/accept_unsolicited_na.
Do we really need to expose this to /proc/sys, for every interface added in the host ?
/proc files creations/deletion cost a lot in environments adding/deleting netns very often.
I would prefer using NETLINK attributes, a single recvmsg() syscall can fetch/set hundreds of them.
David Ahern
maintainerQuoted 10 lines · Eric Dumazet
Quoted 6 lines · Arun Ajith S
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 thearp_acceptconfiguration for IPv4.
A new sysctl endpoint is created to turn on this behaviour:/proc/sys/net/ipv6/conf/interface/accept_unsolicited_na.
Quoted 5 lines
Do we really need to expose this to
/proc/sys, for every interface added in the host ?/proc files creations/deletion cost a lot in environments adding/deleting netns very often.
agree with the general intent (along with the increasing memory costs). I do think this case should be done as a /proc/sys entry for consistency with both ARP and existing related NA settings.
Quoted 3 lines
I would prefer using NETLINK attributes, a single
recvmsg()syscall can fetch/set hundreds of them.
What do you have in mind here? A link attribute managed through ip link set?
Quoted 14 lines · David Ahern
Quoted 8 lines · Eric Dumazet
Quoted 6 lines · Arun Ajith S
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 thearp_acceptconfiguration for IPv4.
A new sysctl endpoint is created to turn on this behaviour:/proc/sys/net/ipv6/conf/interface/accept_unsolicited_na.Quoted 5 lines
Do we really need to expose this to
/proc/sys, for every interface added in the host ?/proc files creations/deletion cost a lot in environments adding/deleting netns very often.
Quoted 8 lines
agree with the general intent (along with the increasing memory costs). I do think this case should be done as a
/proc/sysentry for consistency with both ARP and existing related NA settings.Quoted 2 lines
I would prefer using NETLINK attributes, a single
recvmsg()syscall can fetch/set hundreds of them.What do you have in mind here? A link attribute managed through
ip link set?
Yes, something like that, if this is a netdevice/link attribute.
tools/testing/selftests/net/ndisc_unsolicited_na_test.py line 1
Quoted 7 lines · Arun Ajith S
tools/testing/selftests/net/ndisc_unsolicited_na_test.py new file +1
-0@@ -0,0 +1,255 @@ +#!/bin/bash
that file name suffix should be .sh since it is a bash script; not .py
other than that looks good to me.
Quoted 12 lines · David Ahern
tools/testing/selftests/net/ndisc_unsolicited_na_test.py line 1
Quoted 7 lines · Arun Ajith S
tools/testing/selftests/net/ndisc_unsolicited_na_test.py new file +1
-0@@ -0,0 +1,255 @@ +#!/bin/bashthat file name suffix should be .sh since it is a bash script; not .py
Quoted 3 lines
other than that looks good to me.
Reviewed-by David Ahern <[email protected]>
Hi David,
It has been pointed out to me that I might have read RFC9131 in a narrower sense than what was intended.
The behavior of adding a new entry in the neighbour cache on receiving a NA if none exists presently
shouldn't be limited to unsolicited NAs like in my original patch, rather it should extend to all NAs.
I am quoting from the RFC below
| When a valid Neighbor Advertisement is received (either solicited | or unsolicited), the Neighbor Cache is searched for the target's | entry. If no entry exists: | | * Hosts SHOULD silently discard the advertisement. There is no | need to create an entry if none exists, since the recipient has | apparently not initiated any communication with the target. | | * Routers SHOULD create a new entry for the target address with | the link-layer address set to the Target Link-Layer Address | Option (if supplied). The entry's reachability state MUST be | set to STALE. If the received Neighbor Advertisement does not | contain the Target Link-Layer Address Option, the advertisement | SHOULD be silently discarded.
I want to fix this, but this would mean the sysctl name accept_unsolicited_na is no longer appropriate
I see that the net-next window for 5.19 is still open and changing the sysctl name
wouldn't mean changing an existing interface.
I was thinking of renaming the sysctl to accept_untracked_na to highlight that we are accepting NAs even if there is
no corresponding entry tracked in the neighbor cache.
Also, there's an error in my comment, where I say "pass up the stack" as we don't pass NAs up the stack.
The comment can be updated as:
/* 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.
*
* 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
*/
In summary
1. accept=0 keeps original(5.18) behavior for all cases.
2. accept=1 changes original behavior for entry=asbent, fwding=1 case provided the NA had specified target link-layer address.
Please let me know what you think.
Thanks,
Arun
David Ahern
maintainerQuoted 69 lines · Arun Ajith S
Quoted 12 lines · David Ahern
tools/testing/selftests/net/ndisc_unsolicited_na_test.py line 1
Quoted 7 lines · Arun Ajith S
tools/testing/selftests/net/ndisc_unsolicited_na_test.py new file +1
-0@@ -0,0 +1,255 @@ +#!/bin/bashthat file name suffix should be .sh since it is a bash script; not .py
Quoted 3 lines
other than that looks good to me.
Reviewed-by David Ahern <[email protected]>Hi David,
It has been pointed out to me that I might have read RFC9131 in a narrower sense than what was intended.
The behavior of adding a new entry in the neighbour cache on receiving a NA if none exists presently
shouldn't be limited to unsolicited NAs like in my original patch, rather it should extend to all NAs.I am quoting from the RFC below
| When a valid Neighbor Advertisement is received (either solicited | or unsolicited), the Neighbor Cache is searched for the target's | entry. If no entry exists: | | * Hosts SHOULD silently discard the advertisement. There is no | need to create an entry if none exists, since the recipient has | apparently not initiated any communication with the target. | | * Routers SHOULD create a new entry for the target address with | the link-layer address set to the Target Link-Layer Address | Option (if supplied). The entry's reachability state MUST be | set to STALE. If the received Neighbor Advertisement does not | contain the Target Link-Layer Address Option, the advertisement | SHOULD be silently discarded.I want to fix this, but this would mean the sysctl name
accept_unsolicited_nais no longer appropriate
I see that the net-next window for 5.19 is still open and changing the sysctl name
wouldn't mean changing an existing interface.
I was thinking of renaming the sysctl toaccept_untracked_nato highlight that we are accepting NAs even if there is
no corresponding entry tracked in the neighbor cache.Also, there's an error in my comment, where I say "pass up the stack" as we don't pass NAs up the stack.
The comment can be updated as:
/* 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.
*
* 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
*/
Quoted 7 lines
In summary
1. accept=0 keeps original(5.18) behavior for all cases.
2. accept=1 changes original behavior for entry=asbent, fwding=1 case provided the NA had specified target link-layer address.Please let me know what you think.
Changes can be made until it is in a released kernel to users. This feature has many weeks before it hits that level.
Quoted 76 lines · David Ahern
Quoted 74 lines · Arun Ajith S
Quoted 12 lines · David Ahern
tools/testing/selftests/net/ndisc_unsolicited_na_test.py line 1
Quoted 7 lines · Arun Ajith S
tools/testing/selftests/net/ndisc_unsolicited_na_test.py new file +1
-0@@ -0,0 +1,255 @@ +#!/bin/bashthat file name suffix should be .sh since it is a bash script; not .py
Quoted 3 lines
other than that looks good to me.
Reviewed-by David Ahern <[email protected]>Hi David,
It has been pointed out to me that I might have read RFC9131 in a narrower sense than what was intended.
The behavior of adding a new entry in the neighbour cache on receiving a NA if none exists presently
shouldn't be limited to unsolicited NAs like in my original patch, rather it should extend to all NAs.I am quoting from the RFC below
| When a valid Neighbor Advertisement is received (either solicited | or unsolicited), the Neighbor Cache is searched for the target's | entry. If no entry exists: | | * Hosts SHOULD silently discard the advertisement. There is no | need to create an entry if none exists, since the recipient has | apparently not initiated any communication with the target. | | * Routers SHOULD create a new entry for the target address with | the link-layer address set to the Target Link-Layer Address | Option (if supplied). The entry's reachability state MUST be | set to STALE. If the received Neighbor Advertisement does not | contain the Target Link-Layer Address Option, the advertisement | SHOULD be silently discarded.I want to fix this, but this would mean the sysctl name
accept_unsolicited_nais no longer appropriate
I see that the net-next window for 5.19 is still open and changing the sysctl name
wouldn't mean changing an existing interface.
I was thinking of renaming the sysctl toaccept_untracked_nato highlight that we are accepting NAs even if there is
no corresponding entry tracked in the neighbor cache.Also, there's an error in my comment, where I say "pass up the stack" as we don't pass NAs up the stack.
The comment can be updated as:
/* 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.
*
* 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
*/In summary
1. accept=0 keeps original(5.18) behavior for all cases.
2. accept=1 changes original behavior for entry=asbent, fwding=1 case provided the NA had specified target link-layer address.
Quoted 5 lines
Quoted 2 lines
Please let me know what you think.
Changes can be made until it is in a released kernel to users. This feature has many weeks before it hits that level.
Thanks, I have made the proposed changes here:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/