Skip to content

Commit f8a1b43

Browse files
dsaherndavem330
authored andcommitted
net/ipv6: Create a neigh_lookup for FIB entries
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> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3b6761d commit f8a1b43

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

include/net/ip6_route.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,7 @@ static inline bool rt6_duplicate_nexthop(struct rt6_info *a, struct rt6_info *b)
279279
!lwtunnel_cmp_encap(a->fib6_nh.nh_lwtstate, b->fib6_nh.nh_lwtstate);
280280
}
281281

282+
struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw,
283+
struct net_device *dev, struct sk_buff *skb,
284+
const void *daddr);
282285
#endif

net/ipv6/ndisc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,9 @@ static void ndisc_router_discovery(struct sk_buff *skb)
12761276
rt = rt6_get_dflt_router(net, &ipv6_hdr(skb)->saddr, skb->dev);
12771277

12781278
if (rt) {
1279-
neigh = dst_neigh_lookup(&rt->dst, &ipv6_hdr(skb)->saddr);
1279+
neigh = ip6_neigh_lookup(&rt->fib6_nh.nh_gw,
1280+
rt->fib6_nh.nh_dev, NULL,
1281+
&ipv6_hdr(skb)->saddr);
12801282
if (!neigh) {
12811283
ND_PRINTK(0, err,
12821284
"RA: %s got default router without neighbour\n",
@@ -1304,7 +1306,9 @@ static void ndisc_router_discovery(struct sk_buff *skb)
13041306
return;
13051307
}
13061308

1307-
neigh = dst_neigh_lookup(&rt->dst, &ipv6_hdr(skb)->saddr);
1309+
neigh = ip6_neigh_lookup(&rt->fib6_nh.nh_gw,
1310+
rt->fib6_nh.nh_dev, NULL,
1311+
&ipv6_hdr(skb)->saddr);
13081312
if (!neigh) {
13091313
ND_PRINTK(0, err,
13101314
"RA: %s got default router without neighbour\n",

net/ipv6/route.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,39 +182,46 @@ static void rt6_uncached_list_flush_dev(struct net *net, struct net_device *dev)
182182
}
183183
}
184184

185-
static inline const void *choose_neigh_daddr(struct rt6_info *rt,
185+
static inline const void *choose_neigh_daddr(const struct in6_addr *p,
186186
struct sk_buff *skb,
187187
const void *daddr)
188188
{
189-
struct in6_addr *p = &rt->rt6i_gateway;
190-
191189
if (!ipv6_addr_any(p))
192190
return (const void *) p;
193191
else if (skb)
194192
return &ipv6_hdr(skb)->daddr;
195193
return daddr;
196194
}
197195

198-
static struct neighbour *ip6_neigh_lookup(const struct dst_entry *dst,
199-
struct sk_buff *skb,
200-
const void *daddr)
196+
struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw,
197+
struct net_device *dev,
198+
struct sk_buff *skb,
199+
const void *daddr)
201200
{
202-
struct rt6_info *rt = (struct rt6_info *) dst;
203201
struct neighbour *n;
204202

205-
daddr = choose_neigh_daddr(rt, skb, daddr);
206-
n = __ipv6_neigh_lookup(dst->dev, daddr);
203+
daddr = choose_neigh_daddr(gw, skb, daddr);
204+
n = __ipv6_neigh_lookup(dev, daddr);
207205
if (n)
208206
return n;
209-
return neigh_create(&nd_tbl, daddr, dst->dev);
207+
return neigh_create(&nd_tbl, daddr, dev);
208+
}
209+
210+
static struct neighbour *ip6_dst_neigh_lookup(const struct dst_entry *dst,
211+
struct sk_buff *skb,
212+
const void *daddr)
213+
{
214+
const struct rt6_info *rt = container_of(dst, struct rt6_info, dst);
215+
216+
return ip6_neigh_lookup(&rt->rt6i_gateway, dst->dev, skb, daddr);
210217
}
211218

212219
static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr)
213220
{
214221
struct net_device *dev = dst->dev;
215222
struct rt6_info *rt = (struct rt6_info *)dst;
216223

217-
daddr = choose_neigh_daddr(rt, NULL, daddr);
224+
daddr = choose_neigh_daddr(&rt->rt6i_gateway, NULL, daddr);
218225
if (!daddr)
219226
return;
220227
if (dev->flags & (IFF_NOARP | IFF_LOOPBACK))
@@ -239,7 +246,7 @@ static struct dst_ops ip6_dst_ops_template = {
239246
.update_pmtu = ip6_rt_update_pmtu,
240247
.redirect = rt6_do_redirect,
241248
.local_out = __ip6_local_out,
242-
.neigh_lookup = ip6_neigh_lookup,
249+
.neigh_lookup = ip6_dst_neigh_lookup,
243250
.confirm_neigh = ip6_confirm_neigh,
244251
};
245252

@@ -269,7 +276,7 @@ static struct dst_ops ip6_dst_blackhole_ops = {
269276
.update_pmtu = ip6_rt_blackhole_update_pmtu,
270277
.redirect = ip6_rt_blackhole_redirect,
271278
.cow_metrics = dst_cow_metrics_generic,
272-
.neigh_lookup = ip6_neigh_lookup,
279+
.neigh_lookup = ip6_dst_neigh_lookup,
273280
};
274281

275282
static const u32 ip6_template_metrics[RTAX_MAX] = {

0 commit comments

Comments
 (0)