From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0EEAC282CE for ; Tue, 9 Apr 2019 21:41:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7F50C2082A for ; Tue, 9 Apr 2019 21:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554846089; bh=5Msib1yFHiuHkJNcQUTnyqpTCbUE+Eim505Ek5zJlLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=a8PWJJVlxLolHfcRgVFi8NsSKydbqteQB/Vx3jNsq6GnzDdQnj9XxdA2qLY5YSPM7 TaXAJBKPIyGMpTcjEocwtmKt7PuYHF1dWmFHYm77bFu1erm3B5vC5qFBnKsBnD/WYL VBwtsjP/4qpo5wyda442NMQG4vIsRXNJHGuMMqLg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727023AbfDIVlZ (ORCPT ); Tue, 9 Apr 2019 17:41:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:56048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726774AbfDIVlB (ORCPT ); Tue, 9 Apr 2019 17:41:01 -0400 Received: from kenny.it.cumulusnetworks.com. (fw.cumulusnetworks.com [216.129.126.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 18762218D2; Tue, 9 Apr 2019 21:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554846060; bh=5Msib1yFHiuHkJNcQUTnyqpTCbUE+Eim505Ek5zJlLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SGkYf3SRHE9t56ZBzlYVx6QJ+xVOt488/8HsHB2VcQWk2cCBuJJYxXYqPQq6hKIEj PMog+h6YjqVK3munHZ503/dAzSvkU8Th/+Mn0MpXoH87XW1+L+Zy2IMjKCP/s7hpT7 5K2azkp70SDJiQGaTpBJNZHJVzepRt2mu1gOczEw= From: David Ahern To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@mellanox.com, David Ahern Subject: [PATCH net-next 06/10] ipv6: Refactor find_rr_leaf Date: Tue, 9 Apr 2019 14:41:15 -0700 Message-Id: <20190409214119.15258-7-dsahern@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190409214119.15258-1-dsahern@kernel.org> References: <20190409214119.15258-1-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: David Ahern 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 --- 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