From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, assogba.emery@gmail.com,
dsahern@gmail.com, David Ahern <dsahern@kernel.org>
Subject: [PATCH RFC net-next 3/8] nexthop: Refactor nexthop_for_each_fib6_nh
Date: Tue, 9 Jun 2020 21:49:48 -0600 [thread overview]
Message-ID: <20200610034953.28861-4-dsahern@kernel.org> (raw)
In-Reply-To: <20200610034953.28861-1-dsahern@kernel.org>
Refactor nexthop_for_each_fib6_nh moving standalone and group processing
into helpers. Prepatory patch for adding active-backup group.
Signed-off-by: David Ahern <dsahern@kernel.org>
---
net/ipv4/nexthop.c | 48 +++++++++++++++++++++++++++++++---------------
1 file changed, 33 insertions(+), 15 deletions(-)
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 7d0a170821f3..940f46a7d533 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -588,34 +588,52 @@ struct nexthop *nexthop_select_path(struct nexthop *nh, int hash)
}
EXPORT_SYMBOL_GPL(nexthop_select_path);
+static int nexthop_fib6_nh_cb(struct nexthop *nh,
+ int (*cb)(struct fib6_nh *nh, void *arg),
+ void *arg)
+{
+ struct nh_info *nhi;
+
+ nhi = rcu_dereference_rtnl(nh->nh_info);
+
+ return cb(&nhi->fib6_nh, arg);
+}
+
+static int nexthop_fib6_nhg_cb(struct nh_group *nhg,
+ int (*cb)(struct fib6_nh *nh, void *arg),
+ void *arg)
+{
+ int err;
+ int i;
+
+ for (i = 0; i < nhg->num_nh; i++) {
+ struct nh_grp_entry *nhge = &nhg->nh_entries[i];
+ struct nexthop *nh = nhge->nh;
+
+ err = nexthop_fib6_nh_cb(nh, cb, arg);
+ if (err)
+ return err;
+ }
+
+ return 0;
+}
+
int nexthop_for_each_fib6_nh(struct nexthop *nh,
int (*cb)(struct fib6_nh *nh, void *arg),
void *arg)
{
- struct nh_info *nhi;
int err;
if (nh->is_group) {
struct nh_group *nhg;
- int i;
nhg = rcu_dereference_rtnl(nh->nh_grp);
- for (i = 0; i < nhg->num_nh; i++) {
- struct nh_grp_entry *nhge = &nhg->nh_entries[i];
-
- nhi = rcu_dereference_rtnl(nhge->nh->nh_info);
- err = cb(&nhi->fib6_nh, arg);
- if (err)
- return err;
- }
+ err = nexthop_fib6_nhg_cb(nhg, cb, arg);
} else {
- nhi = rcu_dereference_rtnl(nh->nh_info);
- err = cb(&nhi->fib6_nh, arg);
- if (err)
- return err;
+ err = nexthop_fib6_nh_cb(nh, cb, arg);
}
- return 0;
+ return err;
}
EXPORT_SYMBOL_GPL(nexthop_for_each_fib6_nh);
--
2.21.1 (Apple Git-122.3)
next prev parent reply other threads:[~2020-06-10 3:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-10 3:49 [PATCH RFC net-next 0/8] nexthop: Add support for active-backup nexthop type David Ahern
2020-06-10 3:49 ` [PATCH RFC net-next 1/8] nexthop: Rename nexthop_free_mpath David Ahern
2020-06-10 3:49 ` [PATCH RFC net-next 2/8] nexthop: Refactor nexthop_select_path David Ahern
2020-06-10 3:49 ` David Ahern [this message]
2020-06-10 3:49 ` [PATCH RFC net-next 4/8] nexthop: Move nexthop_get_nhc_lookup to nexthop.c David Ahern
2020-06-10 3:49 ` [PATCH RFC net-next 5/8] nexthop: Move nexthop_uses_dev " David Ahern
2020-06-10 3:49 ` [PATCH RFC net-next 6/8] nexthop: Add primary_only argument to nexthop_for_each_fib6_nh David Ahern
2020-06-10 3:49 ` [PATCH RFC net-next 7/8] nexthop: Add support for active-backup nexthop type David Ahern
2020-06-10 3:49 ` [PATCH RFC net-next 8/8] selftests: Add active-backup nexthop tests David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200610034953.28861-4-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=assogba.emery@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).