Skip to contentSkip to conversation

nexthop: Small changes

PATCH In review Ido Schimmel 2 participants 7 messages Sep 15, 2020 – Sep 16, 2020

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

cover nexthop: Small changes

From: Ido Schimmel <[email protected]>

This patch set contains a few small changes that I split out of the RFC I sent last week [1]. Main change is the conversion of the nexthop notification chain to a blocking chain so that it could be reused by device drivers for nexthop objects programming in the future.

Tested with fib_nexthops.sh:

Tests passed: 164
Tests failed: 0

[1] https://lore.kernel.org/netdev/[email protected]/

Ido Schimmel (5):
nexthop: Remove unused function declaration from header file
nexthop: Remove NEXTHOP_EVENT_ADD
nexthop: Convert to blocking notification chain
nexthop: Only emit a notification when nexthop is actually deleted
selftests: fib_nexthops: Test cleanup of FDB entries following nexthop
deletion

 include/net/netns/nexthop.h                 |  2 +-
 include/net/nexthop.h                       |  4 ----
 net/ipv4/nexthop.c                          | 17 +++++++++--------
 tools/testing/selftests/net/fib_nexthops.sh | 14 ++++++++++++++
 4 files changed, 24 insertions(+), 13 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/5 nexthop: Remove unused function declaration from header file

From: Ido Schimmel <[email protected]>

Not used or implemented anywhere.

---
 include/net/nexthop.h | 3 ---
 1 file changed, 3 deletions(-)
include/net/nexthop.h +0 -3
index 3a4f9e3b91a5..2e44efe5709b 100644
@@ -109,9 +109,6 @@ enum nexthop_event_type {
 	NEXTHOP_EVENT_DEL
 };
 
-int call_nexthop_notifier(struct notifier_block *nb, struct net *net,
-			  enum nexthop_event_type event_type,
-			  struct nexthop *nh);
 int register_nexthop_notifier(struct net *net, struct notifier_block *nb);
 int unregister_nexthop_notifier(struct net *net, struct notifier_block *nb);
 
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/5 nexthop: Remove NEXTHOP_EVENT_ADD

In reply to Ido Schimmel

From: Ido Schimmel <[email protected]>

Not used anywhere.

---
 include/net/nexthop.h | 1 -
 1 file changed, 1 deletion(-)
include/net/nexthop.h +0 -1
index 2e44efe5709b..2fd76a9b6dc8 100644
@@ -105,7 +105,6 @@ struct nexthop {
 };
 
 enum nexthop_event_type {
-	NEXTHOP_EVENT_ADD,
 	NEXTHOP_EVENT_DEL
 };
 
Signature · 1 line
2.26.2
maintainer
#3 lore raw
In reply to Ido Schimmel

From: Ido Schimmel <[email protected]>
Date: Tue, 15 Sep 2020 14:40:58 +0300

Quoted 7 lines

From: Ido Schimmel <[email protected]>

This patch set contains a few small changes that I split out of the RFC I sent last week [1]. Main change is the conversion of the nexthop notification chain to a blocking chain so that it could be reused by device drivers for nexthop objects programming in the future.

Quoted 6 lines

Tested with fib_nexthops.sh:

Tests passed: 164
Tests failed: 0

[1] https://lore.kernel.org/netdev/[email protected]/

Series applied, thank you.

#4 lore raw

PATCH 3/5 nexthop: Convert to blocking notification chain

In reply to Ido Schimmel

From: Ido Schimmel <[email protected]>

Currently, the only listener of the nexthop notification chain is the VXLAN driver. Subsequent patches will add more listeners (e.g., device drivers such as netdevsim) that need to be able to block when processing notifications.

Therefore, convert the notification chain to a blocking one. This is safe as notifications are always emitted from process context.

---
 include/net/netns/nexthop.h |  2 +-
 net/ipv4/nexthop.c          | 13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
include/net/netns/nexthop.h +1 -1
index 1937476c94a0..1849e77eb68a 100644
@@ -14,6 +14,6 @@ struct netns_nexthop {
 
 	unsigned int		seq;		/* protected by rtnl_mutex */
 	u32			last_id_allocated;
-	struct atomic_notifier_head notifier_chain;
+	struct blocking_notifier_head notifier_chain;
 };
 #endif
net/ipv4/nexthop.c +7 -6
index bf9d4cd2d6e5..13d9219a9aa1 100644
@@ -42,8 +42,8 @@ static int call_nexthop_notifiers(struct net *net,
 {
 	int err;
 
-	err = atomic_notifier_call_chain(&net->nexthop.notifier_chain,
-					 event_type, nh);
+	err = blocking_notifier_call_chain(&net->nexthop.notifier_chain,
+					   event_type, nh);
 	return notifier_to_errno(err);
 }
 
@@ -1959,14 +1959,15 @@ static struct notifier_block nh_netdev_notifier = {
 
 int register_nexthop_notifier(struct net *net, struct notifier_block *nb)
 {
-	return atomic_notifier_chain_register(&net->nexthop.notifier_chain, nb);
+	return blocking_notifier_chain_register(&net->nexthop.notifier_chain,
+						nb);
 }
 EXPORT_SYMBOL(register_nexthop_notifier);
 
 int unregister_nexthop_notifier(struct net *net, struct notifier_block *nb)
 {
-	return atomic_notifier_chain_unregister(&net->nexthop.notifier_chain,
-						nb);
+	return blocking_notifier_chain_unregister(&net->nexthop.notifier_chain,
+						  nb);
 }
 EXPORT_SYMBOL(unregister_nexthop_notifier);
 
@@ -1986,7 +1987,7 @@ static int __net_init nexthop_net_init(struct net *net)
 	net->nexthop.devhash = kzalloc(sz, GFP_KERNEL);
 	if (!net->nexthop.devhash)
 		return -ENOMEM;
-	ATOMIC_INIT_NOTIFIER_HEAD(&net->nexthop.notifier_chain);
+	BLOCKING_INIT_NOTIFIER_HEAD(&net->nexthop.notifier_chain);
 
 	return 0;
 }
Signature · 1 line
2.26.2
#5 lore raw

PATCH 4/5 nexthop: Only emit a notification when nexthop is actually deleted

In reply to Ido Schimmel

From: Ido Schimmel <[email protected]>

Currently, the in-kernel delete notification is emitted from the error path of nexthop_add() and replace_nexthop(), which can be confusing to in-kernel listeners as they are not familiar with the nexthop.

Instead, only emit the notification when the nexthop is actually deleted. The following sub-cases are covered:

1. User space deletes the nexthop
2. The nexthop is deleted by the kernel due to a netdev event (e.g., nexthop device going down)
3. A group is deleted because its last nexthop is being deleted
4. The network namespace of the nexthop device is deleted

---
 net/ipv4/nexthop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/nexthop.c +2 -2
index 13d9219a9aa1..8c0f17c6863c 100644
@@ -870,8 +870,6 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh)
 	bool do_flush = false;
 	struct fib_info *fi;
 
-	call_nexthop_notifiers(net, NEXTHOP_EVENT_DEL, nh);
-
 	list_for_each_entry(fi, &nh->fi_list, nh_list) {
 		fi->fib_flags |= RTNH_F_DEAD;
 		do_flush = true;
@@ -909,6 +907,8 @@ static void __remove_nexthop(struct net *net, struct nexthop *nh,
 static void remove_nexthop(struct net *net, struct nexthop *nh,
 			   struct nl_info *nlinfo)
 {
+	call_nexthop_notifiers(net, NEXTHOP_EVENT_DEL, nh);
+
 	/* remove from the tree */
 	rb_erase(&nh->rb_node, &net->nexthop.rb_root);
 
Signature · 1 line
2.26.2
#6 lore raw

PATCH 5/5 selftests: fib_nexthops: Test cleanup of FDB entries following nexthop deletion

In reply to Ido Schimmel

From: Ido Schimmel <[email protected]>

Commit c7cdbe2efc40 ("vxlan: support for nexthop notifiers") registered a listener in the VXLAN driver to the nexthop notification chain. Its purpose is to cleanup FDB entries that use a nexthop that is being deleted.

Test that such FDB entries are removed when the nexthop group that they use is deleted. Test that entries are not deleted when a single nexthop in the group is deleted.

---
 tools/testing/selftests/net/fib_nexthops.sh | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tools/testing/selftests/net/fib_nexthops.sh +14 -0
index b74884d52913..eb693a3b7b4a 100755
@@ -411,9 +411,16 @@ ipv6_fdb_grp_fcnal()
 	run_cmd "$IP -6 ro add 2001:db8:101::1/128 nhid 103"
 	log_test $? 2 "Route add with fdb nexthop group"
 
+	run_cmd "$IP nexthop del id 61"
+	run_cmd "$BRIDGE fdb get to 02:02:00:00:00:13 dev vx10 self"
+	log_test $? 0 "Fdb entry after deleting a single nexthop"
+
 	run_cmd "$IP nexthop del id 102"
 	log_test $? 0 "Fdb nexthop delete"
 
+	run_cmd "$BRIDGE fdb get to 02:02:00:00:00:13 dev vx10 self"
+	log_test $? 254 "Fdb entry after deleting a nexthop group"
+
 	$IP link del dev vx10
 }
 
@@ -484,9 +491,16 @@ ipv4_fdb_grp_fcnal()
 	run_cmd "$IP ro add 172.16.0.0/22 nhid 103"
 	log_test $? 2 "Route add with fdb nexthop group"
 
+	run_cmd "$IP nexthop del id 12"
+	run_cmd "$BRIDGE fdb get to 02:02:00:00:00:13 dev vx10 self"
+	log_test $? 0 "Fdb entry after deleting a single nexthop"
+
 	run_cmd "$IP nexthop del id 102"
 	log_test $? 0 "Fdb nexthop delete"
 
+	run_cmd "$BRIDGE fdb get to 02:02:00:00:00:13 dev vx10 self"
+	log_test $? 254 "Fdb entry after deleting a nexthop group"
+
 	$IP link del dev vx10
 }
 
Signature · 1 line
2.26.2