Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp690013ybg; Mon, 1 Jun 2020 11:46:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgL2tQe6yL3gpmvMVkSQzLg6L8IUa0VgVn3KYYx/T3FB1OXNYpuZ4E5loFGCaiAFjvM7kb X-Received: by 2002:a17:906:e0c:: with SMTP id l12mr19963279eji.435.1591037165315; Mon, 01 Jun 2020 11:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591037165; cv=none; d=google.com; s=arc-20160816; b=oox2tAv7ZuJIDqNJmfxowKKn+B8PtHxrRrCtIpfwStx4TAN2PE/VB/MjcsXEktN9Za qcJ7P3YFzXzngW/s72/f2frdKvb/A6R34XAP7bRDlhCPTVdqgSU05qXtRh+ue99eGAmZ 1VCcfX0SVxztj6Zcr8rHmzLPzy2rtkcNaOr2FU59zvuplApzpjywYCIa5vkhexnfo/RZ qcngNRxI8lpFCE9zkNdoNZ40GwqwApwWNsIrbpYsjscnYHhzf4uFlFDkLr8V3nGeJkql FYXZxvHNKVFZPox2qSv9PVeRniWMjRAxiuNgKUmJMFmJ6qtGxYV0cuW7EkgHfZko49bv 22bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fN/NOCUHe6w192oaJKivlud3DyIEQpjXg6EdB2po4aQ=; b=0YfvVPo3B3eBDtWLfSKbK2FgK5Cx7U1WzY5tg2WHw7h1tuvqrT+RDbgJWZW7TMwCaL kEsIrc2zEsL/pPoB+0x13PpiJdUTdupdQsVP4QO5icRLoiJhtWv9zhHIWjCqYitnNOBV P5mG4cvPHnPQh7oCxnkXjbRN8lSZ4fVpk3t0yKcehaMSgEV/YCthGdFouv8O7TIEKJMi IZHCmMPzAy1S+SEWY3dQCSmXl773GckZ/cvZWxmzPZxTDmAyDJL2Lv3H8dqiiOlwr5kS oLfoqj60qwjsPJNbjjuLtD3b0m46PcikDXrugRHSaVq5LoaIvOxYzIRkzPwV6FQ7prpJ OImg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M5JRm0jM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h19si127920edq.313.2020.06.01.11.45.42; Mon, 01 Jun 2020 11:46:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M5JRm0jM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731077AbgFASn7 (ORCPT + 99 others); Mon, 1 Jun 2020 14:43:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:58160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730477AbgFASLF (ORCPT ); Mon, 1 Jun 2020 14:11:05 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2F61F206E2; Mon, 1 Jun 2020 18:11:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591035064; bh=Ku7SeBRPKctbDs9kFxC9F7jkNt5OLICrrA9kqwMBLac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M5JRm0jMySJ50SLCZlsO4Z1qe9RS7USPREx9o2a99orurZvMc7EJTpeHjn+qvwdMQ PZiWyp2JkbBU5E7OSAR/uYtITCTL1CKTt+Lklggd1YTz2HJ+xnzayQl04bk45yI4bw LpsbJthSoHrYLm980AkjFPCWdsZunCjB888dnSOs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Ahern , Nikolay Aleksandrov , "David S. Miller" Subject: [PATCH 5.4 135/142] ipv4: nexthop version of fib_info_nh_uses_dev Date: Mon, 1 Jun 2020 19:54:53 +0200 Message-Id: <20200601174051.690845158@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174037.904070960@linuxfoundation.org> References: <20200601174037.904070960@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Ahern commit 1fd1c768f3624a5e66766e7b4ddb9b607cd834a5 upstream. Similar to the last path, need to fix fib_info_nh_uses_dev for external nexthops to avoid referencing multiple nh_grp structs. Move the device check in fib_info_nh_uses_dev to a helper and create a nexthop version that is called if the fib_info uses an external nexthop. Fixes: 430a049190de ("nexthop: Add support for nexthop groups") Signed-off-by: David Ahern Acked-by: Nikolay Aleksandrov Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/ip_fib.h | 10 ++++++++++ include/net/nexthop.h | 25 +++++++++++++++++++++++++ net/ipv4/fib_frontend.c | 19 ++++++++++--------- 3 files changed, 45 insertions(+), 9 deletions(-) --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -422,6 +422,16 @@ static inline int fib_num_tclassid_users #endif int fib_unmerge(struct net *net); +static inline bool nhc_l3mdev_matches_dev(const struct fib_nh_common *nhc, +const struct net_device *dev) +{ + if (nhc->nhc_dev == dev || + l3mdev_master_ifindex_rcu(nhc->nhc_dev) == dev->ifindex) + return true; + + return false; +} + /* Exported by fib_semantics.c */ int ip_fib_check_default(__be32 gw, struct net_device *dev); int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force); --- a/include/net/nexthop.h +++ b/include/net/nexthop.h @@ -233,6 +233,31 @@ struct fib_nh_common *nexthop_fib_nhc(st return &nhi->fib_nhc; } +static inline bool nexthop_uses_dev(const struct nexthop *nh, + const struct net_device *dev) +{ + struct nh_info *nhi; + + if (nh->is_group) { + struct nh_group *nhg = rcu_dereference(nh->nh_grp); + int i; + + for (i = 0; i < nhg->num_nh; i++) { + struct nexthop *nhe = nhg->nh_entries[i].nh; + + nhi = rcu_dereference(nhe->nh_info); + if (nhc_l3mdev_matches_dev(&nhi->fib_nhc, dev)) + return true; + } + } else { + nhi = rcu_dereference(nh->nh_info); + if (nhc_l3mdev_matches_dev(&nhi->fib_nhc, dev)) + return true; + } + + return false; +} + static inline unsigned int fib_info_num_path(const struct fib_info *fi) { if (unlikely(fi->nh)) --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -319,17 +319,18 @@ bool fib_info_nh_uses_dev(struct fib_inf { bool dev_match = false; #ifdef CONFIG_IP_ROUTE_MULTIPATH - int ret; + if (unlikely(fi->nh)) { + dev_match = nexthop_uses_dev(fi->nh, dev); + } else { + int ret; - for (ret = 0; ret < fib_info_num_path(fi); ret++) { - const struct fib_nh_common *nhc = fib_info_nhc(fi, ret); + for (ret = 0; ret < fib_info_num_path(fi); ret++) { + const struct fib_nh_common *nhc = fib_info_nhc(fi, ret); - if (nhc->nhc_dev == dev) { - dev_match = true; - break; - } else if (l3mdev_master_ifindex_rcu(nhc->nhc_dev) == dev->ifindex) { - dev_match = true; - break; + if (nhc_l3mdev_matches_dev(nhc, dev)) { + dev_match = true; + break; + } } } #else