diff options
author | David Miller <davem@davemloft.net> | 2011-07-11 18:44:24 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-07-13 04:12:28 -0400 |
commit | 3769cffb1c48f64640ffab7ce3bffe867342c0f0 (patch) | |
tree | 8f6fcf2d822bf3a170a534e8540faa34fe9258ef | |
parent | e5b1de1f5ebe0200e988e195fefb6c7396de6e20 (diff) |
ipv4: Inline neigh binding.
Get rid of all of the useless and costly indirection
by doing the neigh hash table lookup directly inside
of the neighbour binding.
Rename from arp_bind_neighbour to rt_bind_neighbour.
Use new helpers {__,}ipv4_neigh_lookup()
In rt_bind_neighbour() get rid of useless tests which
are never true in the context this function is called,
namely dev is never NULL and the dst->neighbour is
always NULL.
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/arp.h | 33 | ||||
-rw-r--r-- | net/ipv4/arp.c | 24 | ||||
-rw-r--r-- | net/ipv4/route.c | 30 |
3 files changed, 59 insertions, 28 deletions
diff --git a/include/net/arp.h b/include/net/arp.h index 723bde501c64..5e669e6ffb42 100644 --- a/include/net/arp.h +++ b/include/net/arp.h | |||
@@ -15,6 +15,38 @@ static inline u32 arp_hashfn(u32 key, const struct net_device *dev, u32 hash_rnd | |||
15 | return val * hash_rnd; | 15 | return val * hash_rnd; |
16 | } | 16 | } |
17 | 17 | ||
18 | static inline struct neighbour *__ipv4_neigh_lookup(struct neigh_table *tbl, struct net_device *dev, u32 key) | ||
19 | { | ||
20 | struct neigh_hash_table *nht; | ||
21 | struct neighbour *n; | ||
22 | u32 hash_val; | ||
23 | |||
24 | rcu_read_lock_bh(); | ||
25 | nht = rcu_dereference_bh(tbl->nht); | ||
26 | hash_val = arp_hashfn(key, dev, nht->hash_rnd) >> (32 - nht->hash_shift); | ||
27 | for (n = rcu_dereference_bh(nht->hash_buckets[hash_val]); | ||
28 | n != NULL; | ||
29 | n = rcu_dereference_bh(n->next)) { | ||
30 | if (n->dev == dev && *(u32 *)n->primary_key == key) { | ||
31 | if (!atomic_inc_not_zero(&n->refcnt)) | ||
32 | n = NULL; | ||
33 | break; | ||
34 | } | ||
35 | } | ||
36 | rcu_read_unlock_bh(); | ||
37 | |||
38 | return n; | ||
39 | } | ||
40 | |||
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 | |||
18 | extern void arp_init(void); | 50 | extern void arp_init(void); |
19 | extern int arp_find(unsigned char *haddr, struct sk_buff *skb); | 51 | extern int arp_find(unsigned char *haddr, struct sk_buff *skb); |
20 | extern int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg); | 52 | extern int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg); |
@@ -22,7 +54,6 @@ extern void arp_send(int type, int ptype, __be32 dest_ip, | |||
22 | struct net_device *dev, __be32 src_ip, | 54 | struct net_device *dev, __be32 src_ip, |
23 | const unsigned char *dest_hw, | 55 | const unsigned char *dest_hw, |
24 | const unsigned char *src_hw, const unsigned char *th); | 56 | const unsigned char *src_hw, const unsigned char *th); |
25 | extern int arp_bind_neighbour(struct dst_entry *dst); | ||
26 | extern int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir); | 57 | extern int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir); |
27 | extern void arp_ifdown(struct net_device *dev); | 58 | extern void arp_ifdown(struct net_device *dev); |
28 | 59 | ||
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 4412b57f6ff6..3e5545675ccf 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c | |||
@@ -517,30 +517,6 @@ EXPORT_SYMBOL(arp_find); | |||
517 | 517 | ||
518 | /* END OF OBSOLETE FUNCTIONS */ | 518 | /* END OF OBSOLETE FUNCTIONS */ |
519 | 519 | ||
520 | int arp_bind_neighbour(struct dst_entry *dst) | ||
521 | { | ||
522 | struct net_device *dev = dst->dev; | ||
523 | struct neighbour *n = dst->neighbour; | ||
524 | |||
525 | if (dev == NULL) | ||
526 | return -EINVAL; | ||
527 | if (n == NULL) { | ||
528 | __be32 nexthop = ((struct rtable *)dst)->rt_gateway; | ||
529 | if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) | ||
530 | nexthop = 0; | ||
531 | n = __neigh_lookup_errno( | ||
532 | #if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) | ||
533 | dev->type == ARPHRD_ATM ? | ||
534 | clip_tbl_hook : | ||
535 | #endif | ||
536 | &arp_tbl, &nexthop, dev); | ||
537 | if (IS_ERR(n)) | ||
538 | return PTR_ERR(n); | ||
539 | dst->neighbour = n; | ||
540 | } | ||
541 | return 0; | ||
542 | } | ||
543 | |||
544 | /* | 520 | /* |
545 | * Check if we can use proxy ARP for this path | 521 | * Check if we can use proxy ARP for this path |
546 | */ | 522 | */ |
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index a8ccd9bca09c..c6388e825ed3 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -108,6 +108,7 @@ | |||
108 | #ifdef CONFIG_SYSCTL | 108 | #ifdef CONFIG_SYSCTL |
109 | #include <linux/sysctl.h> | 109 | #include <linux/sysctl.h> |
110 | #endif | 110 | #endif |
111 | #include <net/atmclip.h> | ||
111 | 112 | ||
112 | #define RT_FL_TOS(oldflp4) \ | 113 | #define RT_FL_TOS(oldflp4) \ |
113 | ((u32)(oldflp4->flowi4_tos & (IPTOS_RT_MASK | RTO_ONLINK))) | 114 | ((u32)(oldflp4->flowi4_tos & (IPTOS_RT_MASK | RTO_ONLINK))) |
@@ -1006,6 +1007,29 @@ static int slow_chain_length(const struct rtable *head) | |||
1006 | return length >> FRACT_BITS; | 1007 | return length >> FRACT_BITS; |
1007 | } | 1008 | } |
1008 | 1009 | ||
1010 | static int rt_bind_neighbour(struct rtable *rt) | ||
1011 | { | ||
1012 | static const __be32 inaddr_any = 0; | ||
1013 | struct net_device *dev = rt->dst.dev; | ||
1014 | struct neigh_table *tbl = &arp_tbl; | ||
1015 | const __be32 *nexthop; | ||
1016 | struct neighbour *n; | ||
1017 | |||
1018 | #if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE) | ||
1019 | if (dev->type == ARPHRD_ATM) | ||
1020 | tbl = clip_tbl_hook; | ||
1021 | #endif | ||
1022 | nexthop = &rt->rt_gateway; | ||
1023 | if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) | ||
1024 | nexthop = &inaddr_any; | ||
1025 | n = ipv4_neigh_lookup(tbl, dev, nexthop); | ||
1026 | if (IS_ERR(n)) | ||
1027 | return PTR_ERR(n); | ||
1028 | rt->dst.neighbour = n; | ||
1029 | |||
1030 | return 0; | ||
1031 | } | ||
1032 | |||
1009 | static struct rtable *rt_intern_hash(unsigned hash, struct rtable *rt, | 1033 | static struct rtable *rt_intern_hash(unsigned hash, struct rtable *rt, |
1010 | struct sk_buff *skb, int ifindex) | 1034 | struct sk_buff *skb, int ifindex) |
1011 | { | 1035 | { |
@@ -1042,7 +1066,7 @@ restart: | |||
1042 | 1066 | ||
1043 | rt->dst.flags |= DST_NOCACHE; | 1067 | rt->dst.flags |= DST_NOCACHE; |
1044 | if (rt->rt_type == RTN_UNICAST || rt_is_output_route(rt)) { | 1068 | if (rt->rt_type == RTN_UNICAST || rt_is_output_route(rt)) { |
1045 | int err = arp_bind_neighbour(&rt->dst); | 1069 | int err = rt_bind_neighbour(rt); |
1046 | if (err) { | 1070 | if (err) { |
1047 | if (net_ratelimit()) | 1071 | if (net_ratelimit()) |
1048 | printk(KERN_WARNING | 1072 | printk(KERN_WARNING |
@@ -1138,7 +1162,7 @@ restart: | |||
1138 | route or unicast forwarding path. | 1162 | route or unicast forwarding path. |
1139 | */ | 1163 | */ |
1140 | if (rt->rt_type == RTN_UNICAST || rt_is_output_route(rt)) { | 1164 | if (rt->rt_type == RTN_UNICAST || rt_is_output_route(rt)) { |
1141 | int err = arp_bind_neighbour(&rt->dst); | 1165 | int err = rt_bind_neighbour(rt); |
1142 | if (err) { | 1166 | if (err) { |
1143 | spin_unlock_bh(rt_hash_lock_addr(hash)); | 1167 | spin_unlock_bh(rt_hash_lock_addr(hash)); |
1144 | 1168 | ||
@@ -1599,7 +1623,7 @@ static int check_peer_redir(struct dst_entry *dst, struct inet_peer *peer) | |||
1599 | rt->dst.neighbour = NULL; | 1623 | rt->dst.neighbour = NULL; |
1600 | 1624 | ||
1601 | rt->rt_gateway = peer->redirect_learned.a4; | 1625 | rt->rt_gateway = peer->redirect_learned.a4; |
1602 | if (arp_bind_neighbour(&rt->dst) || | 1626 | if (rt_bind_neighbour(rt) || |
1603 | !(rt->dst.neighbour->nud_state & NUD_VALID)) { | 1627 | !(rt->dst.neighbour->nud_state & NUD_VALID)) { |
1604 | if (rt->dst.neighbour) | 1628 | if (rt->dst.neighbour) |
1605 | neigh_event_send(rt->dst.neighbour, NULL); | 1629 | neigh_event_send(rt->dst.neighbour, NULL); |