From: David Ahern <dsahern@kernel.org>
To: davem@davemloft.net, netdev@vger.kernel.org
Cc: idosch@mellanox.com, David Ahern <dsahern@gmail.com>
Subject: [PATCH net-next 06/10] ipv6: Refactor find_rr_leaf
Date: Tue, 9 Apr 2019 14:41:15 -0700 [thread overview]
Message-ID: <20190409214119.15258-7-dsahern@kernel.org> (raw)
In-Reply-To: <20190409214119.15258-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
find_rr_leaf has 3 loops over fib_entries calling find_match. The loops
are very similar with differences in start point and whether the metric
is evaluated:
1. start at rr_head, no extra loop compare, check fib metric
2. start at leaf, compare rt against rr_head, check metric
3. start at cont (potential saved point from earlier loops), no
extra loop compare, no metric check
Create 1 loop that is called 3 different times. This will make a
later change with multipath nexthop objects much simpler.
Signed-off-by: David Ahern <dsahern@gmail.com>
---
net/ipv6/route.c | 66 ++++++++++++++++++++++++++------------------------------
1 file changed, 30 insertions(+), 36 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 200bd5bb56bf..52aa48a8dbda 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -668,58 +668,52 @@ static bool find_match(struct fib6_nh *nh, u32 fib6_flags,
return rc;
}
-static struct fib6_info *find_rr_leaf(struct fib6_node *fn,
- struct fib6_info *leaf,
- struct fib6_info *rr_head,
- u32 metric, int oif, int strict,
- bool *do_rr)
+static void __find_rr_leaf(struct fib6_info *rt_start,
+ struct fib6_info *nomatch, u32 metric,
+ struct fib6_info **match, struct fib6_info **cont,
+ int oif, int strict, bool *do_rr, int *mpri)
{
- struct fib6_info *rt, *match, *cont;
- struct fib6_nh *nh;
- int mpri = -1;
+ struct fib6_info *rt;
- match = NULL;
- cont = NULL;
- for (rt = rr_head; rt; rt = rcu_dereference(rt->fib6_next)) {
- if (rt->fib6_metric != metric) {
- cont = rt;
- break;
+ for (rt = rt_start;
+ rt && rt != nomatch;
+ rt = rcu_dereference(rt->fib6_next)) {
+ struct fib6_nh *nh;
+
+ if (cont && rt->fib6_metric != metric) {
+ *cont = rt;
+ return;
}
if (fib6_check_expired(rt))
continue;
nh = &rt->fib6_nh;
- if (find_match(nh, rt->fib6_flags, oif, strict, &mpri, do_rr))
- match = rt;
+ if (find_match(nh, rt->fib6_flags, oif, strict, mpri, do_rr))
+ *match = rt;
}
+}
- for (rt = leaf; rt && rt != rr_head;
- rt = rcu_dereference(rt->fib6_next)) {
- if (rt->fib6_metric != metric) {
- cont = rt;
- break;
- }
+static struct fib6_info *find_rr_leaf(struct fib6_node *fn,
+ struct fib6_info *leaf,
+ struct fib6_info *rr_head,
+ u32 metric, int oif, int strict,
+ bool *do_rr)
+{
+ struct fib6_info *match = NULL, *cont = NULL;
+ int mpri = -1;
- if (fib6_check_expired(rt))
- continue;
+ __find_rr_leaf(rr_head, NULL, metric, &match, &cont,
+ oif, strict, do_rr, &mpri);
- nh = &rt->fib6_nh;
- if (find_match(nh, rt->fib6_flags, oif, strict, &mpri, do_rr))
- match = rt;
- }
+ __find_rr_leaf(leaf, rr_head, metric, &match, &cont,
+ oif, strict, do_rr, &mpri);
if (match || !cont)
return match;
- for (rt = cont; rt; rt = rcu_dereference(rt->fib6_next)) {
- if (fib6_check_expired(rt))
- continue;
-
- nh = &rt->fib6_nh;
- if (find_match(nh, rt->fib6_flags, oif, strict, &mpri, do_rr))
- match = rt;
- }
+ __find_rr_leaf(cont, NULL, metric, &match, NULL,
+ oif, strict, do_rr, &mpri);
return match;
}
--
2.11.0
next prev parent reply other threads:[~2019-04-09 21:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-09 21:41 [PATCH net-next 00/10] ipv6: Refactor nexthop selection helpers during a fib lookup David Ahern
2019-04-09 21:41 ` [PATCH net-next 01/10] ipv6: Only call rt6_check_neigh for nexthop with gateway David Ahern
2019-04-09 21:41 ` [PATCH net-next 02/10] ipv6: Remove rt6_check_dev David Ahern
2019-04-09 21:41 ` [PATCH net-next 03/10] ipv6: Change rt6_probe to take a fib6_nh David Ahern
2019-04-09 21:41 ` [PATCH net-next 04/10] ipv6: Pass fib6_nh and flags to rt6_score_route David Ahern
2019-04-09 21:41 ` [PATCH net-next 05/10] ipv6: Refactor find_match David Ahern
2019-04-09 21:41 ` David Ahern [this message]
2019-04-09 21:41 ` [PATCH net-next 07/10] ipv6: Be smarter with null_entry handling in ip6_pol_route_lookup David Ahern
2019-04-09 21:41 ` [PATCH net-next 08/10] ipv6: Move fib6_multipath_select down in ip6_pol_route David Ahern
2019-04-09 21:41 ` [PATCH net-next 09/10] ipv6: Refactor rt6_device_match David Ahern
2019-04-09 21:41 ` [PATCH net-next 10/10] ipv6: Refactor __ip6_route_redirect David Ahern
2019-04-10 17:36 ` Martin Lau
2019-04-10 18:45 ` David Ahern
2019-04-10 20:45 ` Martin Lau
2019-04-11 4:54 ` David Ahern
2019-04-11 21:24 ` [PATCH net-next 00/10] ipv6: Refactor nexthop selection helpers during a fib lookup David Miller
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=20190409214119.15258-7-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=idosch@mellanox.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.