Skip to content

Commit d3aaeb3

Browse files
committed
net: Add ->neigh_lookup() operation to dst_ops
In the future dst entries will be neigh-less. In that environment we need to have an easy transition point for current users of dst->neighbour outside of the packet output fast path. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 69cce1d commit d3aaeb3

8 files changed

Lines changed: 52 additions & 16 deletions

File tree

‎include/net/arp.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ static inline struct neighbour *__ipv4_neigh_lookup(struct neigh_table *tbl, str
3838
return n;
3939
}
4040

41-
static inline struct neighbour *ipv4_neigh_lookup(struct neigh_table *tbl, struct net_device *dev, const __be32 *pkey)
42-
{
43-
struct neighbour *n = __ipv4_neigh_lookup(tbl, dev,
44-
*(__force u32 *)pkey);
45-
if (n)
46-
return n;
47-
return neigh_create(tbl, pkey, dev);
48-
}
49-
5041
extern void arp_init(void);
5142
extern int arp_find(unsigned char *haddr, struct sk_buff *skb);
5243
extern int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg);

‎include/net/dst.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ static inline void dst_confirm(struct dst_entry *dst)
387387
}
388388
}
389389

390+
static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr)
391+
{
392+
return dst->ops->neigh_lookup(dst, daddr);
393+
}
394+
390395
static inline void dst_link_failure(struct sk_buff *skb)
391396
{
392397
struct dst_entry *dst = skb_dst(skb);

‎include/net/dst_ops.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct dst_ops {
2626
void (*link_failure)(struct sk_buff *);
2727
void (*update_pmtu)(struct dst_entry *dst, u32 mtu);
2828
int (*local_out)(struct sk_buff *skb);
29+
struct neighbour * (*neigh_lookup)(const struct dst_entry *dst, const void *daddr);
2930

3031
struct kmem_cache *kmem_cachep;
3132

‎net/bridge/br_netfilter.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,17 @@ static u32 *fake_cow_metrics(struct dst_entry *dst, unsigned long old)
109109
return NULL;
110110
}
111111

112+
static struct neighbour *fake_neigh_lookup(const struct dst_entry *dst, const void *daddr)
113+
{
114+
return NULL;
115+
}
116+
112117
static struct dst_ops fake_dst_ops = {
113118
.family = AF_INET,
114119
.protocol = cpu_to_be16(ETH_P_IP),
115120
.update_pmtu = fake_update_pmtu,
116121
.cow_metrics = fake_cow_metrics,
122+
.neigh_lookup = fake_neigh_lookup,
117123
};
118124

119125
/*

‎net/decnet/dn_route.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static void dn_dst_destroy(struct dst_entry *);
116116
static struct dst_entry *dn_dst_negative_advice(struct dst_entry *);
117117
static void dn_dst_link_failure(struct sk_buff *);
118118
static void dn_dst_update_pmtu(struct dst_entry *dst, u32 mtu);
119+
static struct neighbour *dn_dst_neigh_lookup(const struct dst_entry *dst, const void *daddr);
119120
static int dn_route_input(struct sk_buff *);
120121
static void dn_run_flush(unsigned long dummy);
121122

@@ -139,6 +140,7 @@ static struct dst_ops dn_dst_ops = {
139140
.negative_advice = dn_dst_negative_advice,
140141
.link_failure = dn_dst_link_failure,
141142
.update_pmtu = dn_dst_update_pmtu,
143+
.neigh_lookup = dn_dst_neigh_lookup,
142144
};
143145

144146
static void dn_dst_destroy(struct dst_entry *dst)
@@ -827,6 +829,11 @@ static unsigned int dn_dst_default_mtu(const struct dst_entry *dst)
827829
return dst->dev->mtu;
828830
}
829831

832+
static struct neighbour *dn_dst_neigh_lookup(const struct dst_entry *dst, const void *daddr)
833+
{
834+
return __neigh_lookup_errno(&dn_neigh_table, daddr, dst->dev);
835+
}
836+
830837
static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
831838
{
832839
struct dn_fib_info *fi = res->fi;

‎net/ipv4/route.c‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ static u32 *ipv4_cow_metrics(struct dst_entry *dst, unsigned long old)
185185
return p;
186186
}
187187

188+
static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst, const void *daddr);
189+
188190
static struct dst_ops ipv4_dst_ops = {
189191
.family = AF_INET,
190192
.protocol = cpu_to_be16(ETH_P_IP),
@@ -199,6 +201,7 @@ static struct dst_ops ipv4_dst_ops = {
199201
.link_failure = ipv4_link_failure,
200202
.update_pmtu = ip_rt_update_pmtu,
201203
.local_out = __ip_local_out,
204+
.neigh_lookup = ipv4_neigh_lookup,
202205
};
203206

204207
#define ECN_OR_COST(class) TC_PRIO_##class
@@ -1008,22 +1011,30 @@ static int slow_chain_length(const struct rtable *head)
10081011
return length >> FRACT_BITS;
10091012
}
10101013

1011-
static int rt_bind_neighbour(struct rtable *rt)
1014+
static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst, const void *daddr)
10121015
{
1013-
static const __be32 inaddr_any = 0;
1014-
struct net_device *dev = rt->dst.dev;
10151016
struct neigh_table *tbl = &arp_tbl;
1016-
const __be32 *nexthop;
1017+
static const __be32 inaddr_any = 0;
1018+
struct net_device *dev = dst->dev;
1019+
const __be32 *pkey = daddr;
10171020
struct neighbour *n;
10181021

10191022
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
10201023
if (dev->type == ARPHRD_ATM)
10211024
tbl = clip_tbl_hook;
10221025
#endif
1023-
nexthop = &rt->rt_gateway;
10241026
if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))
1025-
nexthop = &inaddr_any;
1026-
n = ipv4_neigh_lookup(tbl, dev, nexthop);
1027+
pkey = &inaddr_any;
1028+
1029+
n = __ipv4_neigh_lookup(tbl, dev, *(__force u32 *)pkey);
1030+
if (n)
1031+
return n;
1032+
return neigh_create(tbl, pkey, dev);
1033+
}
1034+
1035+
static int rt_bind_neighbour(struct rtable *rt)
1036+
{
1037+
struct neighbour *n = ipv4_neigh_lookup(&rt->dst, &rt->rt_gateway);
10271038
if (IS_ERR(n))
10281039
return PTR_ERR(n);
10291040
dst_set_neighbour(&rt->dst, n);
@@ -2734,6 +2745,7 @@ static struct dst_ops ipv4_dst_blackhole_ops = {
27342745
.default_advmss = ipv4_default_advmss,
27352746
.update_pmtu = ipv4_rt_blackhole_update_pmtu,
27362747
.cow_metrics = ipv4_rt_blackhole_cow_metrics,
2748+
.neigh_lookup = ipv4_neigh_lookup,
27372749
};
27382750

27392751
struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig)

‎net/ipv6/route.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ static u32 *ipv6_cow_metrics(struct dst_entry *dst, unsigned long old)
127127
return p;
128128
}
129129

130+
static struct neighbour *ip6_neigh_lookup(const struct dst_entry *dst, const void *daddr)
131+
{
132+
return __neigh_lookup_errno(&nd_tbl, daddr, dst->dev);
133+
}
134+
130135
static struct dst_ops ip6_dst_ops_template = {
131136
.family = AF_INET6,
132137
.protocol = cpu_to_be16(ETH_P_IPV6),
@@ -142,6 +147,7 @@ static struct dst_ops ip6_dst_ops_template = {
142147
.link_failure = ip6_link_failure,
143148
.update_pmtu = ip6_rt_update_pmtu,
144149
.local_out = __ip6_local_out,
150+
.neigh_lookup = ip6_neigh_lookup,
145151
};
146152

147153
static unsigned int ip6_blackhole_default_mtu(const struct dst_entry *dst)
@@ -168,6 +174,7 @@ static struct dst_ops ip6_dst_blackhole_ops = {
168174
.default_advmss = ip6_default_advmss,
169175
.update_pmtu = ip6_rt_blackhole_update_pmtu,
170176
.cow_metrics = ip6_rt_blackhole_cow_metrics,
177+
.neigh_lookup = ip6_neigh_lookup,
171178
};
172179

173180
static const u32 ip6_template_metrics[RTAX_MAX] = {

‎net/xfrm/xfrm_policy.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,11 @@ static unsigned int xfrm_default_mtu(const struct dst_entry *dst)
23852385
return dst_mtu(dst->path);
23862386
}
23872387

2388+
static struct neighbour *xfrm_neigh_lookup(const struct dst_entry *dst, const void *daddr)
2389+
{
2390+
return dst_neigh_lookup(dst->path, daddr);
2391+
}
2392+
23882393
int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
23892394
{
23902395
struct net *net;
@@ -2410,6 +2415,8 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
24102415
dst_ops->negative_advice = xfrm_negative_advice;
24112416
if (likely(dst_ops->link_failure == NULL))
24122417
dst_ops->link_failure = xfrm_link_failure;
2418+
if (likely(dst_ops->neigh_lookup == NULL))
2419+
dst_ops->neigh_lookup = xfrm_neigh_lookup;
24132420
if (likely(afinfo->garbage_collect == NULL))
24142421
afinfo->garbage_collect = __xfrm_garbage_collect;
24152422
xfrm_policy_afinfo[afinfo->family] = afinfo;

0 commit comments

Comments
 (0)