Skip to content

Commit

Permalink
nexthop: Add a callback parameter to rtm_dump_walk_nexthops()
Browse files Browse the repository at this point in the history
In order to allow different handling for next-hop tree dumper and for
bucket dumper, parameterize the next-hop tree walker with a callback. Add
rtm_dump_nexthop_cb() with just the bits relevant for next-hop tree
dumping.

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 cbee180 commit e948217
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions net/ipv4/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -2083,9 +2083,11 @@ static int rtm_dump_walk_nexthops(struct sk_buff *skb,
struct netlink_callback *cb,
struct rb_root *root,
struct rtm_dump_nh_ctx *ctx,
struct nh_dump_filter *filter)
int (*nh_cb)(struct sk_buff *skb,
struct netlink_callback *cb,
struct nexthop *nh, void *data),
void *data)
{
struct nhmsg *nhm = nlmsg_data(cb->nlh);
struct rb_node *node;
int idx = 0, s_idx;
int err;
Expand All @@ -2098,14 +2100,9 @@ static int rtm_dump_walk_nexthops(struct sk_buff *skb,
goto cont;

nh = rb_entry(node, struct nexthop, rb_node);
if (nh_dump_filtered(nh, filter, nhm->nh_family))
goto cont;

ctx->idx = idx;
err = nh_fill_node(skb, nh, RTM_NEWNEXTHOP,
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, NLM_F_MULTI);
if (err < 0)
err = nh_cb(skb, cb, nh, data);
if (err)
return err;
cont:
idx++;
Expand All @@ -2115,6 +2112,20 @@ static int rtm_dump_walk_nexthops(struct sk_buff *skb,
return 0;
}

static int rtm_dump_nexthop_cb(struct sk_buff *skb, struct netlink_callback *cb,
struct nexthop *nh, void *data)
{
struct nhmsg *nhm = nlmsg_data(cb->nlh);
struct nh_dump_filter *filter = data;

if (nh_dump_filtered(nh, filter, nhm->nh_family))
return 0;

return nh_fill_node(skb, nh, RTM_NEWNEXTHOP,
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, NLM_F_MULTI);
}

/* rtnl */
static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb)
{
Expand All @@ -2128,7 +2139,8 @@ static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb)
if (err < 0)
return err;

err = rtm_dump_walk_nexthops(skb, cb, root, ctx, &filter);
err = rtm_dump_walk_nexthops(skb, cb, root, ctx,
&rtm_dump_nexthop_cb, &filter);
if (err < 0) {
if (likely(skb->len))
goto out;
Expand Down

0 comments on commit e948217

Please sign in to comment.