summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@gmail.com>2020-05-26 21:56:18 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-06-03 09:21:37 +0300
commit35c0a6e7ef5524bd58a66d42d5859ec3ce1baf48 (patch)
tree7d62ba807d6f2c102a90d68f13ca136d040c48d8 /include
parent568c159356d1ae93f5273dc511d0fa375305f0e7 (diff)
downloadlinux-35c0a6e7ef5524bd58a66d42d5859ec3ce1baf48.tar.xz
ipv4: nexthop version of fib_info_nh_uses_dev
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 <dsahern@gmail.com> Acked-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/net/ip_fib.h10
-rw-r--r--include/net/nexthop.h25
2 files changed, 35 insertions, 0 deletions
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 72bcfdcb25e0..ffbae7683450 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -422,6 +422,16 @@ static inline int fib_num_tclassid_users(struct net *net)
#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);
diff --git a/include/net/nexthop.h b/include/net/nexthop.h
index caca3d336b37..3bb618e5ecf7 100644
--- a/include/net/nexthop.h
+++ b/include/net/nexthop.h
@@ -233,6 +233,31 @@ struct fib_nh_common *nexthop_fib_nhc(struct nexthop *nh, int nhsel)
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))