netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, idosch@idosch.org,
	roopa@cumulusnetworks.com, eric.dumazet@gmail.com,
	weiwan@google.com, kafai@fb.com, yoshfuji@linux-ipv6.org,
	David Ahern <dsahern@gmail.com>
Subject: [PATCH RFC v2 net-next 15/21] net/ipv6: Create a neigh_lookup for FIB entries
Date: Sun, 18 Mar 2018 20:36:16 -0700	[thread overview]
Message-ID: <20180319033622.16693-16-dsahern@gmail.com> (raw)
In-Reply-To: <20180319033622.16693-1-dsahern@gmail.com>

The router discovery code has a FIB entry and wants to validate the
gateway has a neighbor entry. Refactor the existing dst_neigh_lookup
for IPv6 and create a new function that takes the gateway and device
and returns a neighbor entry. Use the new function in
ndisc_router_discovery to validate the gateway.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 include/net/ip6_route.h |  3 +++
 net/ipv6/ndisc.c        |  8 ++++++--
 net/ipv6/route.c        | 33 ++++++++++++++++++++-------------
 3 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 8b07c3fcd32d..8e50e9f10158 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -273,4 +273,7 @@ static inline bool rt6_duplicate_nexthop(struct rt6_info *a, struct rt6_info *b)
 	       !lwtunnel_cmp_encap(a->fib6_nh.nh_lwtstate, b->fib6_nh.nh_lwtstate);
 }
 
+struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw,
+				   struct net_device *dev, struct sk_buff *skb,
+				   const void *daddr);
 #endif
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 848f518d48d4..9ae194cb400a 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -1276,7 +1276,9 @@ static void ndisc_router_discovery(struct sk_buff *skb)
 	rt = rt6_get_dflt_router(net, &ipv6_hdr(skb)->saddr, skb->dev);
 
 	if (rt) {
-		neigh = dst_neigh_lookup(&rt->dst, &ipv6_hdr(skb)->saddr);
+		neigh = ip6_neigh_lookup(&rt->fib6_nh.nh_gw,
+					 rt->fib6_nh.nh_dev, NULL,
+					  &ipv6_hdr(skb)->saddr);
 		if (!neigh) {
 			ND_PRINTK(0, err,
 				  "RA: %s got default router without neighbour\n",
@@ -1304,7 +1306,9 @@ static void ndisc_router_discovery(struct sk_buff *skb)
 			return;
 		}
 
-		neigh = dst_neigh_lookup(&rt->dst, &ipv6_hdr(skb)->saddr);
+		neigh = ip6_neigh_lookup(&rt->fib6_nh.nh_gw,
+					 rt->fib6_nh.nh_dev, NULL,
+					  &ipv6_hdr(skb)->saddr);
 		if (!neigh) {
 			ND_PRINTK(0, err,
 				  "RA: %s got default router without neighbour\n",
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index d2c146790d70..0eadef74c815 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -182,12 +182,10 @@ static void rt6_uncached_list_flush_dev(struct net *net, struct net_device *dev)
 	}
 }
 
-static inline const void *choose_neigh_daddr(struct rt6_info *rt,
+static inline const void *choose_neigh_daddr(const struct in6_addr *p,
 					     struct sk_buff *skb,
 					     const void *daddr)
 {
-	struct in6_addr *p = &rt->rt6i_gateway;
-
 	if (!ipv6_addr_any(p))
 		return (const void *) p;
 	else if (skb)
@@ -195,18 +193,27 @@ static inline const void *choose_neigh_daddr(struct rt6_info *rt,
 	return daddr;
 }
 
-static struct neighbour *ip6_neigh_lookup(const struct dst_entry *dst,
-					  struct sk_buff *skb,
-					  const void *daddr)
+struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw,
+				   struct net_device *dev,
+				   struct sk_buff *skb,
+				   const void *daddr)
 {
-	struct rt6_info *rt = (struct rt6_info *) dst;
 	struct neighbour *n;
 
-	daddr = choose_neigh_daddr(rt, skb, daddr);
-	n = __ipv6_neigh_lookup(dst->dev, daddr);
+	daddr = choose_neigh_daddr(gw, skb, daddr);
+	n = __ipv6_neigh_lookup(dev, daddr);
 	if (n)
 		return n;
-	return neigh_create(&nd_tbl, daddr, dst->dev);
+	return neigh_create(&nd_tbl, daddr, dev);
+}
+
+static struct neighbour *ip6_dst_neigh_lookup(const struct dst_entry *dst,
+					      struct sk_buff *skb,
+					      const void *daddr)
+{
+	const struct rt6_info *rt = container_of(dst, struct rt6_info, dst);
+
+	return ip6_neigh_lookup(&rt->rt6i_gateway, dst->dev, skb, daddr);
 }
 
 static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr)
@@ -214,7 +221,7 @@ static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr)
 	struct net_device *dev = dst->dev;
 	struct rt6_info *rt = (struct rt6_info *)dst;
 
-	daddr = choose_neigh_daddr(rt, NULL, daddr);
+	daddr = choose_neigh_daddr(&rt->rt6i_gateway, NULL, daddr);
 	if (!daddr)
 		return;
 	if (dev->flags & (IFF_NOARP | IFF_LOOPBACK))
@@ -239,7 +246,7 @@ static struct dst_ops ip6_dst_ops_template = {
 	.update_pmtu		=	ip6_rt_update_pmtu,
 	.redirect		=	rt6_do_redirect,
 	.local_out		=	__ip6_local_out,
-	.neigh_lookup		=	ip6_neigh_lookup,
+	.neigh_lookup		=	ip6_dst_neigh_lookup,
 	.confirm_neigh		=	ip6_confirm_neigh,
 };
 
@@ -269,7 +276,7 @@ static struct dst_ops ip6_dst_blackhole_ops = {
 	.update_pmtu		=	ip6_rt_blackhole_update_pmtu,
 	.redirect		=	ip6_rt_blackhole_redirect,
 	.cow_metrics		=	dst_cow_metrics_generic,
-	.neigh_lookup		=	ip6_neigh_lookup,
+	.neigh_lookup		=	ip6_dst_neigh_lookup,
 };
 
 static const u32 ip6_template_metrics[RTAX_MAX] = {
-- 
2.11.0

  parent reply	other threads:[~2018-03-19  3:37 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-19  3:36 [PATCH RFC v2 net-next 00/21] net/ipv6: Separate data structures for FIB and data path David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 01/21] net: Move fib_convert_metrics to metrics file David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 02/21] net: Handle null dst in rtnl_put_cacheinfo David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 03/21] vrf: Move fib6_table into net_vrf David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 04/21] net/ipv6: Pass net to fib6_update_sernum David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 05/21] net/ipv6: Pass net namespace to route functions David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 06/21] net/ipv6: Move support functions up in route.c David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 07/21] net/ipv6: Save route type in rt6_info David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 08/21] net/ipv6: Move nexthop data to fib6_nh David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 09/21] net/ipv6: Defer initialization of dst to data path David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 10/21] net/ipv6: move metrics from dst to rt6_info David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 11/21] net/ipv6: move expires into rt6_info David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 12/21] net/ipv6: Add fib6_null_entry David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 13/21] net/ipv6: Add rt6_info create function for ip6_pol_route_lookup David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 14/21] net/ipv6: Move dst flags to booleans in fib entries David Ahern
2018-03-19  3:36 ` David Ahern [this message]
2018-03-19  3:36 ` [PATCH RFC v2 net-next 16/21] net/ipv6: Add gfp_flags to route add functions David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 17/21] net/ipv6: Cleanup exception and cache route handling David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 18/21] net/ipv6: introduce fib6_info struct and helpers David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 19/21] net/ipv6: separate handling of FIB entries from dst based routes David Ahern
2018-03-24 14:31   ` Ido Schimmel
2018-03-24 15:31     ` David Ahern
2018-03-24 16:02       ` Ido Schimmel
2018-03-25 14:49         ` David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 20/21] net/ipv6: Flip FIB entries to fib6_info David Ahern
2018-03-19  3:36 ` [PATCH RFC v2 net-next 21/21] net/ipv6: Remove unused code and variables for rt6_info David Ahern
2018-03-19 14:23 ` [PATCH RFC v2 net-next 00/21] net/ipv6: Separate data structures for FIB and data path David Miller
2018-03-24 15:05 ` Ido Schimmel
2018-03-24 15:28   ` David Ahern
2018-03-24 15:59     ` Ido Schimmel
2018-03-25 15:09       ` 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=20180319033622.16693-16-dsahern@gmail.com \
    --to=dsahern@gmail.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=idosch@idosch.org \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@cumulusnetworks.com \
    --cc=weiwan@google.com \
    --cc=yoshfuji@linux-ipv6.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).