aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/ndisc.h27
-rw-r--r--net/ipv6/route.c41
2 files changed, 49 insertions, 19 deletions
diff --git a/include/net/ndisc.h b/include/net/ndisc.h
index e9c30023b784..e3133c23980e 100644
--- a/include/net/ndisc.h
+++ b/include/net/ndisc.h
@@ -89,6 +89,33 @@ static inline u32 ndisc_hashfn(const void *pkey, const struct net_device *dev, _
89 (p32[3] * hash_rnd[3])); 89 (p32[3] * hash_rnd[3]));
90} 90}
91 91
92static inline struct neighbour *__ipv6_neigh_lookup(struct neigh_table *tbl, struct net_device *dev, const void *pkey)
93{
94 struct neigh_hash_table *nht;
95 const u32 *p32 = pkey;
96 struct neighbour *n;
97 u32 hash_val;
98
99 rcu_read_lock_bh();
100 nht = rcu_dereference_bh(tbl->nht);
101 hash_val = ndisc_hashfn(pkey, dev, nht->hash_rnd) >> (32 - nht->hash_shift);
102 for (n = rcu_dereference_bh(nht->hash_buckets[hash_val]);
103 n != NULL;
104 n = rcu_dereference_bh(n->next)) {
105 u32 *n32 = (u32 *) n->primary_key;
106 if (n->dev == dev &&
107 ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
108 (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0) {
109 if (!atomic_inc_not_zero(&n->refcnt))
110 n = NULL;
111 break;
112 }
113 }
114 rcu_read_unlock_bh();
115
116 return n;
117}
118
92extern int ndisc_init(void); 119extern int ndisc_init(void);
93 120
94extern void ndisc_cleanup(void); 121extern void ndisc_cleanup(void);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 35b07cc33aad..6bf60946698a 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -123,7 +123,20 @@ static u32 *ipv6_cow_metrics(struct dst_entry *dst, unsigned long old)
123 123
124static struct neighbour *ip6_neigh_lookup(const struct dst_entry *dst, const void *daddr) 124static struct neighbour *ip6_neigh_lookup(const struct dst_entry *dst, const void *daddr)
125{ 125{
126 return __neigh_lookup_errno(&nd_tbl, daddr, dst->dev); 126 struct neighbour *n = __ipv6_neigh_lookup(&nd_tbl, dst->dev, daddr);
127 if (n)
128 return n;
129 return neigh_create(&nd_tbl, daddr, dst->dev);
130}
131
132static int rt6_bind_neighbour(struct rt6_info *rt)
133{
134 struct neighbour *n = ip6_neigh_lookup(&rt->dst, &rt->rt6i_gateway);
135 if (IS_ERR(n))
136 return PTR_ERR(n);
137 dst_set_neighbour(&rt->dst, n);
138
139 return 0;
127} 140}
128 141
129static struct dst_ops ip6_dst_ops_template = { 142static struct dst_ops ip6_dst_ops_template = {
@@ -714,7 +727,6 @@ static struct rt6_info *rt6_alloc_cow(const struct rt6_info *ort,
714 rt = ip6_rt_copy(ort, daddr); 727 rt = ip6_rt_copy(ort, daddr);
715 728
716 if (rt) { 729 if (rt) {
717 struct neighbour *neigh;
718 int attempts = !in_softirq(); 730 int attempts = !in_softirq();
719 731
720 if (!(rt->rt6i_flags & RTF_GATEWAY)) { 732 if (!(rt->rt6i_flags & RTF_GATEWAY)) {
@@ -734,9 +746,7 @@ static struct rt6_info *rt6_alloc_cow(const struct rt6_info *ort,
734#endif 746#endif
735 747
736 retry: 748 retry:
737 neigh = __neigh_lookup_errno(&nd_tbl, &rt->rt6i_gateway, 749 if (rt6_bind_neighbour(rt)) {
738 rt->rt6i_dev);
739 if (IS_ERR(neigh)) {
740 struct net *net = dev_net(rt->rt6i_dev); 750 struct net *net = dev_net(rt->rt6i_dev);
741 int saved_rt_min_interval = 751 int saved_rt_min_interval =
742 net->ipv6.sysctl.ip6_rt_gc_min_interval; 752 net->ipv6.sysctl.ip6_rt_gc_min_interval;
@@ -762,8 +772,6 @@ static struct rt6_info *rt6_alloc_cow(const struct rt6_info *ort,
762 dst_free(&rt->dst); 772 dst_free(&rt->dst);
763 return NULL; 773 return NULL;
764 } 774 }
765 dst_set_neighbour(&rt->dst, neigh);
766
767 } 775 }
768 776
769 return rt; 777 return rt;
@@ -1078,7 +1086,7 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
1078 if (neigh) 1086 if (neigh)
1079 neigh_hold(neigh); 1087 neigh_hold(neigh);
1080 else { 1088 else {
1081 neigh = __neigh_lookup_errno(&nd_tbl, &fl6->daddr, dev); 1089 neigh = ip6_neigh_lookup(&rt->dst, &fl6->daddr);
1082 if (IS_ERR(neigh)) { 1090 if (IS_ERR(neigh)) {
1083 dst_free(&rt->dst); 1091 dst_free(&rt->dst);
1084 return ERR_CAST(neigh); 1092 return ERR_CAST(neigh);
@@ -1389,12 +1397,9 @@ int ip6_route_add(struct fib6_config *cfg)
1389 rt->rt6i_prefsrc.plen = 0; 1397 rt->rt6i_prefsrc.plen = 0;
1390 1398
1391 if (cfg->fc_flags & (RTF_GATEWAY | RTF_NONEXTHOP)) { 1399 if (cfg->fc_flags & (RTF_GATEWAY | RTF_NONEXTHOP)) {
1392 struct neighbour *n = __neigh_lookup_errno(&nd_tbl, &rt->rt6i_gateway, dev); 1400 err = rt6_bind_neighbour(rt);
1393 if (IS_ERR(n)) { 1401 if (err)
1394 err = PTR_ERR(n);
1395 goto out; 1402 goto out;
1396 }
1397 dst_set_neighbour(&rt->dst, n);
1398 } 1403 }
1399 1404
1400 rt->rt6i_flags = cfg->fc_flags; 1405 rt->rt6i_flags = cfg->fc_flags;
@@ -2057,7 +2062,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
2057 struct net *net = dev_net(idev->dev); 2062 struct net *net = dev_net(idev->dev);
2058 struct rt6_info *rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops, 2063 struct rt6_info *rt = ip6_dst_alloc(&net->ipv6.ip6_dst_ops,
2059 net->loopback_dev, 0); 2064 net->loopback_dev, 0);
2060 struct neighbour *neigh; 2065 int err;
2061 2066
2062 if (!rt) { 2067 if (!rt) {
2063 if (net_ratelimit()) 2068 if (net_ratelimit())
@@ -2079,13 +2084,11 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
2079 rt->rt6i_flags |= RTF_ANYCAST; 2084 rt->rt6i_flags |= RTF_ANYCAST;
2080 else 2085 else
2081 rt->rt6i_flags |= RTF_LOCAL; 2086 rt->rt6i_flags |= RTF_LOCAL;
2082 neigh = __neigh_lookup_errno(&nd_tbl, &rt->rt6i_gateway, rt->rt6i_dev); 2087 err = rt6_bind_neighbour(rt);
2083 if (IS_ERR(neigh)) { 2088 if (err) {
2084 dst_free(&rt->dst); 2089 dst_free(&rt->dst);
2085 2090 return ERR_PTR(err);
2086 return ERR_CAST(neigh);
2087 } 2091 }
2088 dst_set_neighbour(&rt->dst, neigh);
2089 2092
2090 rt->rt6i_dst.addr = *addr; 2093 rt->rt6i_dst.addr = *addr;
2091 rt->rt6i_dst.plen = 128; 2094 rt->rt6i_dst.plen = 128;