netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, assogba.emery@gmail.com,
	dsahern@gmail.com, David Ahern <dsahern@kernel.org>
Subject: [PATCH RFC net-next 5/8] nexthop: Move nexthop_uses_dev to nexthop.c
Date: Tue,  9 Jun 2020 21:49:50 -0600	[thread overview]
Message-ID: <20200610034953.28861-6-dsahern@kernel.org> (raw)
In-Reply-To: <20200610034953.28861-1-dsahern@kernel.org>

nexthop_uses_dev is long enough for an inline and the a-b checks are
going to make it worse. Move to nexthop.c and in the process refactor
so that mpath code reuses single nh lookup. Prepatory patch for adding
active-backup group.

Signed-off-by: David Ahern <dsahern@kernel.org>
---
 include/net/nexthop.h | 25 +------------------------
 net/ipv4/nexthop.c    | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/include/net/nexthop.h b/include/net/nexthop.h
index e95800798aa5..271d2cb92954 100644
--- a/include/net/nexthop.h
+++ b/include/net/nexthop.h
@@ -266,30 +266,7 @@ struct fib_nh_common *nexthop_get_nhc_lookup(const struct nexthop *nh,
 					     const struct flowi4 *flp,
 					     int *nhsel);
 
-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;
-}
+bool nexthop_uses_dev(const struct nexthop *nh, const struct net_device *dev);
 
 static inline unsigned int fib_info_num_path(const struct fib_info *fi)
 {
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index c58ecc86b7a1..0020ea2ecc9f 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -638,6 +638,41 @@ struct fib_nh_common *nexthop_get_nhc_lookup(const struct nexthop *nh,
 	return nhc_lookup_single(nh, fib_flags, flp, nhsel);
 }
 
+static bool nh_uses_dev_single(const struct nexthop *nh,
+			       const struct net_device *dev)
+{
+	const struct nh_info *nhi;
+
+	nhi = rcu_dereference(nh->nh_info);
+	return nhc_l3mdev_matches_dev(&nhi->fib_nhc, dev);
+}
+
+static bool nh_uses_dev_mpath(const struct nh_group *nhg,
+			      const struct net_device *dev)
+{
+	int i;
+
+	for (i = 0; i < nhg->num_nh; i++) {
+		struct nexthop *nhe = nhg->nh_entries[i].nh;
+
+		if (nh_uses_dev_single(nhe, dev))
+			return true;
+	}
+
+	return false;
+}
+
+bool nexthop_uses_dev(const struct nexthop *nh, const struct net_device *dev)
+{
+	if (nh->is_group) {
+		const struct nh_group *nhg = rcu_dereference(nh->nh_grp);
+
+		return nh_uses_dev_mpath(nhg, dev);
+	}
+
+	return nh_uses_dev_single(nh, dev);
+}
+
 static int nexthop_fib6_nh_cb(struct nexthop *nh,
 			      int (*cb)(struct fib6_nh *nh, void *arg),
 			      void *arg)
-- 
2.21.1 (Apple Git-122.3)


  parent reply	other threads:[~2020-06-10  3:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10  3:49 [PATCH RFC net-next 0/8] nexthop: Add support for active-backup nexthop type David Ahern
2020-06-10  3:49 ` [PATCH RFC net-next 1/8] nexthop: Rename nexthop_free_mpath David Ahern
2020-06-10  3:49 ` [PATCH RFC net-next 2/8] nexthop: Refactor nexthop_select_path David Ahern
2020-06-10  3:49 ` [PATCH RFC net-next 3/8] nexthop: Refactor nexthop_for_each_fib6_nh David Ahern
2020-06-10  3:49 ` [PATCH RFC net-next 4/8] nexthop: Move nexthop_get_nhc_lookup to nexthop.c David Ahern
2020-06-10  3:49 ` David Ahern [this message]
2020-06-10  3:49 ` [PATCH RFC net-next 6/8] nexthop: Add primary_only argument to nexthop_for_each_fib6_nh David Ahern
2020-06-10  3:49 ` [PATCH RFC net-next 7/8] nexthop: Add support for active-backup nexthop type David Ahern
2020-06-10  3:49 ` [PATCH RFC net-next 8/8] selftests: Add active-backup nexthop tests David Ahern

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=20200610034953.28861-6-dsahern@kernel.org \
    --to=dsahern@kernel.org \
    --cc=assogba.emery@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=kuba@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).