aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/route.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2011-12-28 15:41:23 -0500
committerDavid S. Miller <davem@davemloft.net>2011-12-28 15:41:23 -0500
commitf83c7790dc0025fffbd8684f3803a7571f624baa (patch)
tree9e745f6b44b1947033a143423560af6a3157fce7 /net/ipv6/route.c
parent2c2aba6c561ac425602f4a0be61422224cb87151 (diff)
ipv6: Create fast inline ipv6 neigh lookup just like ipv4.
Also, create and use an rt6_bind_neighbour() in net/ipv6/route.c to consolidate some common logic. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/route.c')
-rw-r--r--net/ipv6/route.c41
1 files changed, 22 insertions, 19 deletions
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;