Skip to content

Commit cbee180

Browse files
pmachatakuba-moo
authored andcommitted
nexthop: Extract a helper for walking the next-hop tree
Extract from rtm_dump_nexthop() a helper to walk the next hop tree. A separate function for this will be reusable from the bucket dumper. Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a6fbbaa commit cbee180

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

net/ipv4/nexthop.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,22 +2079,17 @@ rtm_dump_nh_ctx(struct netlink_callback *cb)
20792079
return ctx;
20802080
}
20812081

2082-
/* rtnl */
2083-
static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb)
2082+
static int rtm_dump_walk_nexthops(struct sk_buff *skb,
2083+
struct netlink_callback *cb,
2084+
struct rb_root *root,
2085+
struct rtm_dump_nh_ctx *ctx,
2086+
struct nh_dump_filter *filter)
20842087
{
2085-
struct rtm_dump_nh_ctx *ctx = rtm_dump_nh_ctx(cb);
20862088
struct nhmsg *nhm = nlmsg_data(cb->nlh);
2087-
struct net *net = sock_net(skb->sk);
2088-
struct rb_root *root = &net->nexthop.rb_root;
2089-
struct nh_dump_filter filter = {};
20902089
struct rb_node *node;
20912090
int idx = 0, s_idx;
20922091
int err;
20932092

2094-
err = nh_valid_dump_req(cb->nlh, &filter, cb);
2095-
if (err < 0)
2096-
return err;
2097-
20982093
s_idx = ctx->idx;
20992094
for (node = rb_first(root); node; node = rb_next(node)) {
21002095
struct nexthop *nh;
@@ -2103,29 +2098,48 @@ static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb)
21032098
goto cont;
21042099

21052100
nh = rb_entry(node, struct nexthop, rb_node);
2106-
if (nh_dump_filtered(nh, &filter, nhm->nh_family))
2101+
if (nh_dump_filtered(nh, filter, nhm->nh_family))
21072102
goto cont;
21082103

2104+
ctx->idx = idx;
21092105
err = nh_fill_node(skb, nh, RTM_NEWNEXTHOP,
21102106
NETLINK_CB(cb->skb).portid,
21112107
cb->nlh->nlmsg_seq, NLM_F_MULTI);
2112-
if (err < 0) {
2113-
if (likely(skb->len))
2114-
goto out;
2115-
2116-
goto out_err;
2117-
}
2108+
if (err < 0)
2109+
return err;
21182110
cont:
21192111
idx++;
21202112
}
21212113

2114+
ctx->idx = idx;
2115+
return 0;
2116+
}
2117+
2118+
/* rtnl */
2119+
static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb)
2120+
{
2121+
struct rtm_dump_nh_ctx *ctx = rtm_dump_nh_ctx(cb);
2122+
struct net *net = sock_net(skb->sk);
2123+
struct rb_root *root = &net->nexthop.rb_root;
2124+
struct nh_dump_filter filter = {};
2125+
int err;
2126+
2127+
err = nh_valid_dump_req(cb->nlh, &filter, cb);
2128+
if (err < 0)
2129+
return err;
2130+
2131+
err = rtm_dump_walk_nexthops(skb, cb, root, ctx, &filter);
2132+
if (err < 0) {
2133+
if (likely(skb->len))
2134+
goto out;
2135+
goto out_err;
2136+
}
2137+
21222138
out:
21232139
err = skb->len;
21242140
out_err:
2125-
ctx->idx = idx;
21262141
cb->seq = net->nexthop.seq;
21272142
nl_dump_check_consistent(cb, nlmsg_hdr(skb));
2128-
21292143
return err;
21302144
}
21312145

0 commit comments

Comments
 (0)