Skip to content

Commit

Permalink
nexthop: Dispatch notifier init()/fini() by group type
Browse files Browse the repository at this point in the history
After there are several next-hop group types, initialization and
finalization of notifier type needs to reflect the actual type. Transform
nh_notifier_grp_info_init() and _fini() to make extending them easier.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Petr Machata authored and Jakub Kicinski committed Jan 29, 2021
1 parent 09ad6be commit da23050
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions net/ipv4/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ static void nh_notifier_single_info_fini(struct nh_notifier_info *info)
kfree(info->nh);
}

static int nh_notifier_grp_info_init(struct nh_notifier_info *info,
const struct nexthop *nh)
static int nh_notifier_mp_info_init(struct nh_notifier_info *info,
struct nh_group *nhg)
{
struct nh_group *nhg = rtnl_dereference(nh->nh_grp);
u16 num_nh = nhg->num_nh;
int i;

Expand All @@ -114,9 +113,23 @@ static int nh_notifier_grp_info_init(struct nh_notifier_info *info,
return 0;
}

static void nh_notifier_grp_info_fini(struct nh_notifier_info *info)
static int nh_notifier_grp_info_init(struct nh_notifier_info *info,
const struct nexthop *nh)
{
kfree(info->nh_grp);
struct nh_group *nhg = rtnl_dereference(nh->nh_grp);

if (nhg->mpath)
return nh_notifier_mp_info_init(info, nhg);
return -EINVAL;
}

static void nh_notifier_grp_info_fini(struct nh_notifier_info *info,
const struct nexthop *nh)
{
struct nh_group *nhg = rtnl_dereference(nh->nh_grp);

if (nhg->mpath)
kfree(info->nh_grp);
}

static int nh_notifier_info_init(struct nh_notifier_info *info,
Expand All @@ -134,7 +147,7 @@ static void nh_notifier_info_fini(struct nh_notifier_info *info,
const struct nexthop *nh)
{
if (nh->is_group)
nh_notifier_grp_info_fini(info);
nh_notifier_grp_info_fini(info, nh);
else
nh_notifier_single_info_fini(info);
}
Expand Down

0 comments on commit da23050

Please sign in to comment.