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 6C179C282CE for ; Tue, 9 Apr 2019 21:41:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CB5B2082A for ; Tue, 9 Apr 2019 21:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554846095; bh=69OFB0YAL73TCOFV+adUkLX3Lhni1H02WvbgcocYje8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ardWKgNMzXePveDZkkvx1X8okt7L9iwWaRXcPFsJCUj/qVRO+xGgN8lOWfdXVGwD2 FWpTFeNxcrkQFgAi1OrRABteBMuoeU+ynFyJrtDBPpTLdNmuwwWrKdcy4EU+dG5apt JvcBl7XT3CYXlKyN4kU/EN8a/Bb9hQA66CvqmAlU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727064AbfDIVle (ORCPT ); Tue, 9 Apr 2019 17:41:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:56042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726760AbfDIVlA (ORCPT ); Tue, 9 Apr 2019 17:41:00 -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 D47EC21841; Tue, 9 Apr 2019 21:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554846060; bh=69OFB0YAL73TCOFV+adUkLX3Lhni1H02WvbgcocYje8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=au461hh3BB56NvAUGxRivcHZGc+8OdmXksltQPsr8C8nfaA2uqxxX2v6AdJO4LjRC 5AzPggV8gDT5kc0URfuLcH0Aq5t8N1+1tfJhL5ow+7ywam0AR7MuxEaFAxis/da0M7 K7jKmXAS60tF71l3zqJjJQiQBMZ7V9fmWzYIfqaM= From: David Ahern To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@mellanox.com, David Ahern Subject: [PATCH net-next 05/10] ipv6: Refactor find_match Date: Tue, 9 Apr 2019 14:41:14 -0700 Message-Id: <20190409214119.15258-6-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_match primarily needs a fib6_nh (and fib6_flags which it passes through to rt6_score_route). Move fib6_check_expired up to the call sites so find_match is only called for relevant entries. Remove the match argument which is mostly a pass through and use the return boolean to decide if match gets set in the call sites. The end result is a helper that can be called per fib6_nh struct which is needed once fib entries reference nexthop objects that have more than one fib6_nh. Signed-off-by: David Ahern --- net/ipv6/route.c | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 22d1933278ae..200bd5bb56bf 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -632,25 +632,22 @@ static int rt6_score_route(const struct fib6_nh *nh, u32 fib6_flags, int oif, return m; } -static struct fib6_info *find_match(struct fib6_info *rt, int oif, int strict, - int *mpri, struct fib6_info *match, - bool *do_rr) +static bool find_match(struct fib6_nh *nh, u32 fib6_flags, + int oif, int strict, int *mpri, bool *do_rr) { - int m; bool match_do_rr = false; + bool rc = false; + int m; - if (rt->fib6_nh.fib_nh_flags & RTNH_F_DEAD) + if (nh->fib_nh_flags & RTNH_F_DEAD) goto out; - if (ip6_ignore_linkdown(rt->fib6_nh.fib_nh_dev) && - rt->fib6_nh.fib_nh_flags & RTNH_F_LINKDOWN && + if (ip6_ignore_linkdown(nh->fib_nh_dev) && + nh->fib_nh_flags & RTNH_F_LINKDOWN && !(strict & RT6_LOOKUP_F_IGNORE_LINKSTATE)) goto out; - if (fib6_check_expired(rt)) - goto out; - - m = rt6_score_route(&rt->fib6_nh, rt->fib6_flags, oif, strict); + m = rt6_score_route(nh, fib6_flags, oif, strict); if (m == RT6_NUD_FAIL_DO_RR) { match_do_rr = true; m = 0; /* lowest valid score */ @@ -659,16 +656,16 @@ static struct fib6_info *find_match(struct fib6_info *rt, int oif, int strict, } if (strict & RT6_LOOKUP_F_REACHABLE) - rt6_probe(&rt->fib6_nh); + rt6_probe(nh); /* note that m can be RT6_NUD_FAIL_PROBE at this point */ if (m > *mpri) { *do_rr = match_do_rr; *mpri = m; - match = rt; + rc = true; } out: - return match; + return rc; } static struct fib6_info *find_rr_leaf(struct fib6_node *fn, @@ -678,6 +675,7 @@ static struct fib6_info *find_rr_leaf(struct fib6_node *fn, bool *do_rr) { struct fib6_info *rt, *match, *cont; + struct fib6_nh *nh; int mpri = -1; match = NULL; @@ -688,7 +686,12 @@ static struct fib6_info *find_rr_leaf(struct fib6_node *fn, break; } - match = find_match(rt, oif, strict, &mpri, match, do_rr); + if (fib6_check_expired(rt)) + continue; + + nh = &rt->fib6_nh; + if (find_match(nh, rt->fib6_flags, oif, strict, &mpri, do_rr)) + match = rt; } for (rt = leaf; rt && rt != rr_head; @@ -698,14 +701,25 @@ static struct fib6_info *find_rr_leaf(struct fib6_node *fn, break; } - match = find_match(rt, oif, strict, &mpri, match, do_rr); + 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 (match || !cont) return match; - for (rt = cont; rt; rt = rcu_dereference(rt->fib6_next)) - match = find_match(rt, oif, strict, &mpri, match, do_rr); + 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; + } return match; } -- 2.11.0