]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nexthop: Emit a notification when a nexthop is added
authorIdo Schimmel <idosch@nvidia.com>
Wed, 4 Nov 2020 13:30:29 +0000 (15:30 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Oct 2025 11:35:46 +0000 (13:35 +0200)
[ Upstream commit 732d167bf5f53a8c1e8c53cf7dbffe2a13f63752 ]

Emit a notification in the nexthop notification chain when a new nexthop
is added (not replaced). The nexthop can either be a new group or a
single nexthop.

The notification is sent after the nexthop is inserted into the
red-black tree, as listeners might need to callback into the nexthop
code with the nexthop ID in order to mark the nexthop as offloaded.

A 'REPLACE' notification is emitted instead of 'ADD' as the distinction
between the two is not important for in-kernel listeners. In case the
listener is not familiar with the encoded nexthop ID, it can simply
treat it as a new one. This is also consistent with the route offload
API.

Changes since RFC:
* Reword commit message

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: 390b3a300d78 ("nexthop: Forbid FDB status change while nexthop is in a group")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/nexthop.h
net/ipv4/nexthop.c

index fd87d727aa217c9fecc3cade07abd0f5d6d0f761..aa19809bfd733ed3ebcba12c1da37e49233a9acd 100644 (file)
@@ -105,7 +105,8 @@ struct nexthop {
 };
 
 enum nexthop_event_type {
-       NEXTHOP_EVENT_DEL
+       NEXTHOP_EVENT_DEL,
+       NEXTHOP_EVENT_REPLACE,
 };
 
 int register_nexthop_notifier(struct net *net, struct notifier_block *nb);
index 0653aa518648ce742f486d4dfa5c81c631e08df3..3063aa1914b1f36603491216af175a8aa02b12c0 100644 (file)
@@ -1191,7 +1191,11 @@ static int insert_nexthop(struct net *net, struct nexthop *new_nh,
 
        rb_link_node_rcu(&new_nh->rb_node, parent, pp);
        rb_insert_color(&new_nh->rb_node, root);
-       rc = 0;
+
+       rc = call_nexthop_notifiers(net, NEXTHOP_EVENT_REPLACE, new_nh, extack);
+       if (rc)
+               rb_erase(&new_nh->rb_node, &net->nexthop.rb_root);
+
 out:
        if (!rc) {
                nh_base_seq_inc(net);