diff mbox series

[RFC,net-next,4/8] nexthop: Move nexthop_get_nhc_lookup to nexthop.c

Message ID 20200610034953.28861-5-dsahern@kernel.org
State New
Headers show
Series None | expand

Commit Message

David Ahern June 10, 2020, 3:49 a.m. UTC
nexthop_get_nhc_lookup 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 | 29 +------------------------
 net/ipv4/nexthop.c    | 50 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 28 deletions(-)
diff mbox series

Patch

diff --git a/include/net/nexthop.h b/include/net/nexthop.h
index e5122ba78efe..e95800798aa5 100644
--- a/include/net/nexthop.h
+++ b/include/net/nexthop.h
@@ -261,37 +261,10 @@  struct fib_nh_common *nexthop_fib_nhc(struct nexthop *nh, int nhsel)
 }
 
 /* called from fib_table_lookup with rcu_lock */
-static inline
 struct fib_nh_common *nexthop_get_nhc_lookup(const struct nexthop *nh,
 					     int fib_flags,
 					     const struct flowi4 *flp,
-					     int *nhsel)
-{
-	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 (fib_lookup_good_nhc(&nhi->fib_nhc, fib_flags, flp)) {
-				*nhsel = i;
-				return &nhi->fib_nhc;
-			}
-		}
-	} else {
-		nhi = rcu_dereference(nh->nh_info);
-		if (fib_lookup_good_nhc(&nhi->fib_nhc, fib_flags, flp)) {
-			*nhsel = 0;
-			return &nhi->fib_nhc;
-		}
-	}
-
-	return NULL;
-}
+					     int *nhsel);
 
 static inline bool nexthop_uses_dev(const struct nexthop *nh,
 				    const struct net_device *dev)
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 940f46a7d533..c58ecc86b7a1 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -588,6 +588,56 @@  struct nexthop *nexthop_select_path(struct nexthop *nh, int hash)
 }
 EXPORT_SYMBOL_GPL(nexthop_select_path);
 
+static struct fib_nh_common *nhc_lookup_single(const struct nexthop *nh,
+					       int fib_flags,
+					       const struct flowi4 *flp,
+					       int *nhsel)
+{
+	struct nh_info *nhi;
+
+	nhi = rcu_dereference(nh->nh_info);
+	if (fib_lookup_good_nhc(&nhi->fib_nhc, fib_flags, flp)) {
+		*nhsel = 0;
+		return &nhi->fib_nhc;
+	}
+	return NULL;
+}
+
+static struct fib_nh_common *nhc_lookup_mpath(const struct nh_group *nhg,
+					      int fib_flags,
+					      const struct flowi4 *flp,
+					      int *nhsel)
+{
+	struct fib_nh_common *nhc;
+	int i;
+
+	for (i = 0; i < nhg->num_nh; i++) {
+		struct nexthop *nhe = nhg->nh_entries[i].nh;
+
+		nhc = nhc_lookup_single(nhe, fib_flags, flp, nhsel);
+		if (nhc) {
+			*nhsel = i;
+			return nhc;
+		}
+	}
+
+	return NULL;
+}
+
+struct fib_nh_common *nexthop_get_nhc_lookup(const struct nexthop *nh,
+					     int fib_flags,
+					     const struct flowi4 *flp,
+					     int *nhsel)
+{
+	if (nh->is_group) {
+		const struct nh_group *nhg = rcu_dereference(nh->nh_grp);
+
+		return nhc_lookup_mpath(nhg, fib_flags, flp, nhsel);
+	}
+
+	return nhc_lookup_single(nh, fib_flags, flp, nhsel);
+}
+
 static int nexthop_fib6_nh_cb(struct nexthop *nh,
 			      int (*cb)(struct fib6_nh *nh, void *arg),
 			      void *arg)