aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/inet6_hashtables.c
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2013-10-03 18:42:29 -0400
committerDavid S. Miller <davem@davemloft.net>2013-10-09 00:01:25 -0400
commitefe4208f47f907b86f528788da711e8ab9dea44d (patch)
tree8246b487be087877ba26d166f629d8c53d553ec1 /net/ipv6/inet6_hashtables.c
parent05dbc7b59481ca891bbcfe6799a562d48159fbf7 (diff)
ipv6: make lookups simpler and faster
TCP listener refactoring, part 4 : To speed up inet lookups, we moved IPv4 addresses from inet to struct sock_common Now is time to do the same for IPv6, because it permits us to have fast lookups for all kind of sockets, including upcoming SYN_RECV. Getting IPv6 addresses in TCP lookups currently requires two extra cache lines, plus a dereference (and memory stall). inet6_sk(sk) does the dereference of inet_sk(__sk)->pinet6 This patch is way bigger than its IPv4 counter part, because for IPv4, we could add aliases (inet_daddr, inet_rcv_saddr), while on IPv6, it's not doable easily. inet6_sk(sk)->daddr becomes sk->sk_v6_daddr inet6_sk(sk)->rcv_saddr becomes sk->sk_v6_rcv_saddr And timewait socket also have tw->tw_v6_daddr & tw->tw_v6_rcv_saddr at the same offset. We get rid of INET6_TW_MATCH() as INET6_MATCH() is now the generic macro. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/inet6_hashtables.c')
-rw-r--r--net/ipv6/inet6_hashtables.c58
1 files changed, 19 insertions, 39 deletions
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 46440777e1c5..842d833dfc18 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -89,30 +89,16 @@ begin:
89 sk_nulls_for_each_rcu(sk, node, &head->chain) { 89 sk_nulls_for_each_rcu(sk, node, &head->chain) {
90 if (sk->sk_hash != hash) 90 if (sk->sk_hash != hash)
91 continue; 91 continue;
92 if (sk->sk_state == TCP_TIME_WAIT) { 92 if (!INET6_MATCH(sk, net, saddr, daddr, ports, dif))
93 if (!INET6_TW_MATCH(sk, net, saddr, daddr, ports, dif)) 93 continue;
94 continue;
95 } else {
96 if (!INET6_MATCH(sk, net, saddr, daddr, ports, dif))
97 continue;
98 }
99 if (unlikely(!atomic_inc_not_zero(&sk->sk_refcnt))) 94 if (unlikely(!atomic_inc_not_zero(&sk->sk_refcnt)))
100 goto out; 95 goto out;
101 96
102 if (sk->sk_state == TCP_TIME_WAIT) { 97 if (unlikely(!INET6_MATCH(sk, net, saddr, daddr, ports, dif))) {
103 if (unlikely(!INET6_TW_MATCH(sk, net, saddr, daddr, 98 sock_gen_put(sk);
104 ports, dif))) { 99 goto begin;
105 sock_gen_put(sk);
106 goto begin;
107 }
108 } else {
109 if (unlikely(!INET6_MATCH(sk, net, saddr, daddr,
110 ports, dif))) {
111 sock_put(sk);
112 goto begin;
113 }
114 goto found;
115 } 100 }
101 goto found;
116 } 102 }
117 if (get_nulls_value(node) != slot) 103 if (get_nulls_value(node) != slot)
118 goto begin; 104 goto begin;
@@ -133,11 +119,10 @@ static inline int compute_score(struct sock *sk, struct net *net,
133 119
134 if (net_eq(sock_net(sk), net) && inet_sk(sk)->inet_num == hnum && 120 if (net_eq(sock_net(sk), net) && inet_sk(sk)->inet_num == hnum &&
135 sk->sk_family == PF_INET6) { 121 sk->sk_family == PF_INET6) {
136 const struct ipv6_pinfo *np = inet6_sk(sk);
137 122
138 score = 1; 123 score = 1;
139 if (!ipv6_addr_any(&np->rcv_saddr)) { 124 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
140 if (!ipv6_addr_equal(&np->rcv_saddr, daddr)) 125 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
141 return -1; 126 return -1;
142 score++; 127 score++;
143 } 128 }
@@ -229,9 +214,8 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
229{ 214{
230 struct inet_hashinfo *hinfo = death_row->hashinfo; 215 struct inet_hashinfo *hinfo = death_row->hashinfo;
231 struct inet_sock *inet = inet_sk(sk); 216 struct inet_sock *inet = inet_sk(sk);
232 const struct ipv6_pinfo *np = inet6_sk(sk); 217 const struct in6_addr *daddr = &sk->sk_v6_rcv_saddr;
233 const struct in6_addr *daddr = &np->rcv_saddr; 218 const struct in6_addr *saddr = &sk->sk_v6_daddr;
234 const struct in6_addr *saddr = &np->daddr;
235 const int dif = sk->sk_bound_dev_if; 219 const int dif = sk->sk_bound_dev_if;
236 const __portpair ports = INET_COMBINED_PORTS(inet->inet_dport, lport); 220 const __portpair ports = INET_COMBINED_PORTS(inet->inet_dport, lport);
237 struct net *net = sock_net(sk); 221 struct net *net = sock_net(sk);
@@ -250,23 +234,19 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,
250 if (sk2->sk_hash != hash) 234 if (sk2->sk_hash != hash)
251 continue; 235 continue;
252 236
253 if (sk2->sk_state == TCP_TIME_WAIT) { 237 if (likely(INET6_MATCH(sk2, net, saddr, daddr, ports, dif))) {
254 if (likely(INET6_TW_MATCH(sk2, net, saddr, daddr, 238 if (sk2->sk_state == TCP_TIME_WAIT) {
255 ports, dif))) {
256 tw = inet_twsk(sk2); 239 tw = inet_twsk(sk2);
257 if (twsk_unique(sk, sk2, twp)) 240 if (twsk_unique(sk, sk2, twp))
258 goto unique; 241 break;
259 else
260 goto not_unique;
261 } 242 }
262 }
263 if (likely(INET6_MATCH(sk2, net, saddr, daddr, ports, dif)))
264 goto not_unique; 243 goto not_unique;
244 }
265 } 245 }
266 246
267unique:
268 /* Must record num and sport now. Otherwise we will see 247 /* Must record num and sport now. Otherwise we will see
269 * in hash table socket with a funny identity. */ 248 * in hash table socket with a funny identity.
249 */
270 inet->inet_num = lport; 250 inet->inet_num = lport;
271 inet->inet_sport = htons(lport); 251 inet->inet_sport = htons(lport);
272 sk->sk_hash = hash; 252 sk->sk_hash = hash;
@@ -299,9 +279,9 @@ not_unique:
299static inline u32 inet6_sk_port_offset(const struct sock *sk) 279static inline u32 inet6_sk_port_offset(const struct sock *sk)
300{ 280{
301 const struct inet_sock *inet = inet_sk(sk); 281 const struct inet_sock *inet = inet_sk(sk);
302 const struct ipv6_pinfo *np = inet6_sk(sk); 282
303 return secure_ipv6_port_ephemeral(np->rcv_saddr.s6_addr32, 283 return secure_ipv6_port_ephemeral(sk->sk_v6_rcv_saddr.s6_addr32,
304 np->daddr.s6_addr32, 284 sk->sk_v6_daddr.s6_addr32,
305 inet->inet_dport); 285 inet->inet_dport);
306} 286}
307 287