diff mbox series

[net-next,11/12] nexthop: Add a callback parameter to rtm_dump_walk_nexthops()

Message ID 8f895fa4bb87f623226aaf681faec62da3ce0432.1611836479.git.petrm@nvidia.com (mailing list archive)
State Accepted
Commit e948217d258f35b248578f7b400d6df23ac562da
Delegated to: Netdev Maintainers
Headers show
Series nexthop: Preparations for resilient next-hop groups | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 1 maintainers not CCed: yoshfuji@linux-ipv6.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 58 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Petr Machata Jan. 28, 2021, 12:49 p.m. UTC
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>
---
 net/ipv4/nexthop.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

Comments

David Ahern Jan. 29, 2021, 3:20 a.m. UTC | #1
On 1/28/21 5:49 AM, Petr Machata wrote:
> 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>
> ---
>  net/ipv4/nexthop.c | 32 ++++++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 10 deletions(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>
diff mbox series

Patch

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index e5175f531ffb..9536cf2f6aca 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -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;
@@ -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++;
@@ -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)
 {
@@ -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;