Skip to content

Commit afd05e5

Browse files
idoschgregkh
authored andcommitted
nexthop: Emit a notification when a nexthop is added
[ Upstream commit 732d167 ] 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: 390b3a3 ("nexthop: Forbid FDB status change while nexthop is in a group") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent bdcad48 commit afd05e5

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

include/net/nexthop.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ struct nexthop {
105105
};
106106

107107
enum nexthop_event_type {
108-
NEXTHOP_EVENT_DEL
108+
NEXTHOP_EVENT_DEL,
109+
NEXTHOP_EVENT_REPLACE,
109110
};
110111

111112
int register_nexthop_notifier(struct net *net, struct notifier_block *nb);

net/ipv4/nexthop.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,11 @@ static int insert_nexthop(struct net *net, struct nexthop *new_nh,
11911191

11921192
rb_link_node_rcu(&new_nh->rb_node, parent, pp);
11931193
rb_insert_color(&new_nh->rb_node, root);
1194-
rc = 0;
1194+
1195+
rc = call_nexthop_notifiers(net, NEXTHOP_EVENT_REPLACE, new_nh, extack);
1196+
if (rc)
1197+
rb_erase(&new_nh->rb_node, &net->nexthop.rb_root);
1198+
11951199
out:
11961200
if (!rc) {
11971201
nh_base_seq_inc(net);

0 commit comments

Comments
 (0)