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 F0357C282CE for ; Tue, 9 Apr 2019 21:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B87432082A for ; Tue, 9 Apr 2019 21:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554846078; bh=qr/pmRKuYzhWFtWFXkuM74hmN2TGAjMrqALb74Ew0ZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0yJa5fuSATHqMX3T3cs2gJmh0oZ0TbozLFQYw+BdAJkYYRA+H8JDh9FEi+2UsMc/r niLGBjBn06lFMMd8dX2WMrdvNU444Bj1V4H5fguMm4KWSTbDe3NaEtidsFehJO+z4B fIwM7EEgxh2vDm1I9b/Cx/s+cYd4WmNZBv3Tgabo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726981AbfDIVlS (ORCPT ); Tue, 9 Apr 2019 17:41:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:56084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726689AbfDIVlC (ORCPT ); Tue, 9 Apr 2019 17:41:02 -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 06C2721904; Tue, 9 Apr 2019 21:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554846061; bh=qr/pmRKuYzhWFtWFXkuM74hmN2TGAjMrqALb74Ew0ZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ImrYV8zHcMUFwl65e1NoKx9hqj2jwMQDKydWvND53ghEp8LZhJ4MPmdFwqPOhpHN7 XW7mIBv1ajK6QuZglLS0fECRXCwGDVceBo9sGjLAyvC88cVfufJ1yG1mTlezZDPNpq wtKuc2i4+dWK3CxFHNfgMiICAlWsrsfeO7RQtHLc= From: David Ahern To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@mellanox.com, David Ahern Subject: [PATCH net-next 10/10] ipv6: Refactor __ip6_route_redirect Date: Tue, 9 Apr 2019 14:41:19 -0700 Message-Id: <20190409214119.15258-11-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 Move the nexthop evaluation of a fib entry to a helper that can be leveraged for each fib6_nh in a multipath nexthop object. In the move, 'continue' statements means the helper returns false (loop should continue) and 'break' means return true (found the entry of interest). Signed-off-by: David Ahern --- net/ipv6/route.c | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 0e8becb1e455..d555edaaff13 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2407,6 +2407,35 @@ void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst, NULL); } +static bool ip6_redirect_nh_match(struct fib6_info *f6i, + struct fib6_nh *nh, + struct flowi6 *fl6, + const struct in6_addr *gw, + struct rt6_info **ret) +{ + if (nh->fib_nh_flags & RTNH_F_DEAD || !nh->fib_nh_gw_family || + fl6->flowi6_oif != nh->fib_nh_dev->ifindex) + return false; + + /* rt_cache's gateway might be different from its 'parent' + * in the case of an ip redirect. + * So we keep searching in the exception table if the gateway + * is different. + */ + if (!ipv6_addr_equal(gw, &nh->fib_nh_gw6)) { + struct rt6_info *rt_cache; + + rt_cache = rt6_find_cached_rt(f6i, &fl6->daddr, &fl6->saddr); + if (rt_cache && + ipv6_addr_equal(gw, &rt_cache->rt6i_gateway)) { + *ret = rt_cache; + return true; + } + return false; + } + return true; +} + /* Handle redirects */ struct ip6rd_flowi { struct flowi6 fl6; @@ -2420,7 +2449,7 @@ static struct rt6_info *__ip6_route_redirect(struct net *net, int flags) { struct ip6rd_flowi *rdfl = (struct ip6rd_flowi *)fl6; - struct rt6_info *ret = NULL, *rt_cache; + struct rt6_info *ret = NULL; struct fib6_info *rt; struct fib6_node *fn; @@ -2438,34 +2467,15 @@ static struct rt6_info *__ip6_route_redirect(struct net *net, fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); restart: for_each_fib6_node_rt_rcu(fn) { - if (rt->fib6_nh.fib_nh_flags & RTNH_F_DEAD) - continue; if (fib6_check_expired(rt)) continue; if (rt->fib6_flags & RTF_REJECT) break; - if (!rt->fib6_nh.fib_nh_gw_family) - continue; if (fl6->flowi6_oif != rt->fib6_nh.fib_nh_dev->ifindex) continue; - /* rt_cache's gateway might be different from its 'parent' - * in the case of an ip redirect. - * So we keep searching in the exception table if the gateway - * is different. - */ - if (!ipv6_addr_equal(&rdfl->gateway, &rt->fib6_nh.fib_nh_gw6)) { - rt_cache = rt6_find_cached_rt(rt, - &fl6->daddr, - &fl6->saddr); - if (rt_cache && - ipv6_addr_equal(&rdfl->gateway, - &rt_cache->rt6i_gateway)) { - ret = rt_cache; - break; - } - continue; - } - break; + if (ip6_redirect_nh_match(rt, &rt->fib6_nh, fl6, + &rdfl->gateway, &ret)) + goto out; } if (!rt) -- 2.11.0