nexthop: Emit a notification when a nexthop group is replaced
authorIdo Schimmel <idosch@nvidia.com>
Wed, 4 Nov 2020 13:30:30 +0000 (15:30 +0200)
committerJakub Kicinski <kuba@kernel.org>
Fri, 6 Nov 2020 19:28:49 +0000 (11:28 -0800)
Emit a notification in the nexthop notification chain when an existing
nexthop group is replaced.

The notification is emitted after all the validation checks were
performed, but before the new configuration (i.e., 'struct nh_grp') is
pointed at by the old shell (i.e., 'struct nexthop'). This prevents the
need to perform rollback in case the notification is vetoed.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/nexthop.c

index 4e9d0395f959b0d270a454c2ccf2b4d6843a5244..3f43693498ee8227549e4ddcd8e15595e5334063 100644 (file)
@@ -1050,13 +1050,17 @@ static int replace_nexthop_grp(struct net *net, struct nexthop *old,
                               struct netlink_ext_ack *extack)
 {
        struct nh_group *oldg, *newg;
-       int i;
+       int i, err;
 
        if (!new->is_group) {
                NL_SET_ERR_MSG(extack, "Can not replace a nexthop group with a nexthop.");
                return -EINVAL;
        }
 
+       err = call_nexthop_notifiers(net, NEXTHOP_EVENT_REPLACE, new, extack);
+       if (err)
+               return err;
+
        oldg = rtnl_dereference(old->nh_grp);
        newg = rtnl_dereference(new->nh_grp);