diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2009-11-08 05:17:58 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-11-08 23:53:06 -0500 |
commit | 512615b6b843ff3ff5ad583f34c39b3f302f5f26 (patch) | |
tree | 7420705a314bc691bc478225148935dc67f71904 /include/net | |
parent | d4cada4ae1c012815f95fa507eb86a0ae9d607d7 (diff) |
udp: secondary hash on (local port, local address)
Extends udp_table to contain a secondary hash table.
socket anchor for this second hash is free, because UDP
doesnt use skc_bind_node : We define an union to hold
both skc_bind_node & a new hlist_nulls_node udp_portaddr_node
udp_lib_get_port() inserts sockets into second hash chain
(additional cost of one atomic op)
udp_lib_unhash() deletes socket from second hash chain
(additional cost of one atomic op)
Note : No spinlock lockdep annotation is needed, because
lock for the secondary hash chain is always get after
lock for primary hash chain.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net')
-rw-r--r-- | include/net/sock.h | 8 | ||||
-rw-r--r-- | include/net/udp.h | 22 |
2 files changed, 26 insertions, 4 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index 827366b62680..3f1a4804bb3f 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -105,7 +105,7 @@ struct net; | |||
105 | /** | 105 | /** |
106 | * struct sock_common - minimal network layer representation of sockets | 106 | * struct sock_common - minimal network layer representation of sockets |
107 | * @skc_node: main hash linkage for various protocol lookup tables | 107 | * @skc_node: main hash linkage for various protocol lookup tables |
108 | * @skc_nulls_node: main hash linkage for UDP/UDP-Lite protocol | 108 | * @skc_nulls_node: main hash linkage for TCP/UDP/UDP-Lite protocol |
109 | * @skc_refcnt: reference count | 109 | * @skc_refcnt: reference count |
110 | * @skc_tx_queue_mapping: tx queue number for this connection | 110 | * @skc_tx_queue_mapping: tx queue number for this connection |
111 | * @skc_hash: hash value used with various protocol lookup tables | 111 | * @skc_hash: hash value used with various protocol lookup tables |
@@ -115,6 +115,7 @@ struct net; | |||
115 | * @skc_reuse: %SO_REUSEADDR setting | 115 | * @skc_reuse: %SO_REUSEADDR setting |
116 | * @skc_bound_dev_if: bound device index if != 0 | 116 | * @skc_bound_dev_if: bound device index if != 0 |
117 | * @skc_bind_node: bind hash linkage for various protocol lookup tables | 117 | * @skc_bind_node: bind hash linkage for various protocol lookup tables |
118 | * @skc_portaddr_node: second hash linkage for UDP/UDP-Lite protocol | ||
118 | * @skc_prot: protocol handlers inside a network family | 119 | * @skc_prot: protocol handlers inside a network family |
119 | * @skc_net: reference to the network namespace of this socket | 120 | * @skc_net: reference to the network namespace of this socket |
120 | * | 121 | * |
@@ -140,7 +141,10 @@ struct sock_common { | |||
140 | volatile unsigned char skc_state; | 141 | volatile unsigned char skc_state; |
141 | unsigned char skc_reuse; | 142 | unsigned char skc_reuse; |
142 | int skc_bound_dev_if; | 143 | int skc_bound_dev_if; |
143 | struct hlist_node skc_bind_node; | 144 | union { |
145 | struct hlist_node skc_bind_node; | ||
146 | struct hlist_nulls_node skc_portaddr_node; | ||
147 | }; | ||
144 | struct proto *skc_prot; | 148 | struct proto *skc_prot; |
145 | #ifdef CONFIG_NET_NS | 149 | #ifdef CONFIG_NET_NS |
146 | struct net *skc_net; | 150 | struct net *skc_net; |
diff --git a/include/net/udp.h b/include/net/udp.h index 9167281e47dc..af41850f742a 100644 --- a/include/net/udp.h +++ b/include/net/udp.h | |||
@@ -63,10 +63,19 @@ struct udp_hslot { | |||
63 | spinlock_t lock; | 63 | spinlock_t lock; |
64 | } __attribute__((aligned(2 * sizeof(long)))); | 64 | } __attribute__((aligned(2 * sizeof(long)))); |
65 | 65 | ||
66 | /** | ||
67 | * struct udp_table - UDP table | ||
68 | * | ||
69 | * @hash: hash table, sockets are hashed on (local port) | ||
70 | * @hash2: hash table, sockets are hashed on (local port, local address) | ||
71 | * @mask: number of slots in hash tables, minus 1 | ||
72 | * @log: log2(number of slots in hash table) | ||
73 | */ | ||
66 | struct udp_table { | 74 | struct udp_table { |
67 | struct udp_hslot *hash; | 75 | struct udp_hslot *hash; |
68 | unsigned int mask; | 76 | struct udp_hslot *hash2; |
69 | unsigned int log; | 77 | unsigned int mask; |
78 | unsigned int log; | ||
70 | }; | 79 | }; |
71 | extern struct udp_table udp_table; | 80 | extern struct udp_table udp_table; |
72 | extern void udp_table_init(struct udp_table *, const char *); | 81 | extern void udp_table_init(struct udp_table *, const char *); |
@@ -75,6 +84,15 @@ static inline struct udp_hslot *udp_hashslot(struct udp_table *table, | |||
75 | { | 84 | { |
76 | return &table->hash[udp_hashfn(net, num, table->mask)]; | 85 | return &table->hash[udp_hashfn(net, num, table->mask)]; |
77 | } | 86 | } |
87 | /* | ||
88 | * For secondary hash, net_hash_mix() is performed before calling | ||
89 | * udp_hashslot2(), this explains difference with udp_hashslot() | ||
90 | */ | ||
91 | static inline struct udp_hslot *udp_hashslot2(struct udp_table *table, | ||
92 | unsigned int hash) | ||
93 | { | ||
94 | return &table->hash2[hash & table->mask]; | ||
95 | } | ||
78 | 96 | ||
79 | /* Note: this must match 'valbool' in sock_setsockopt */ | 97 | /* Note: this must match 'valbool' in sock_setsockopt */ |
80 | #define UDP_CSUM_NOXMIT 1 | 98 | #define UDP_CSUM_NOXMIT 1 |