diff options
author | Eric Dumazet <edumazet@google.com> | 2013-10-03 18:42:29 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-10-09 00:01:25 -0400 |
commit | efe4208f47f907b86f528788da711e8ab9dea44d (patch) | |
tree | 8246b487be087877ba26d166f629d8c53d553ec1 /net/ipv4/ping.c | |
parent | 05dbc7b59481ca891bbcfe6799a562d48159fbf7 (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/ipv4/ping.c')
-rw-r--r-- | net/ipv4/ping.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index a62610443152..ccefc07beacd 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c | |||
@@ -202,15 +202,14 @@ static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident) | |||
202 | #if IS_ENABLED(CONFIG_IPV6) | 202 | #if IS_ENABLED(CONFIG_IPV6) |
203 | } else if (skb->protocol == htons(ETH_P_IPV6) && | 203 | } else if (skb->protocol == htons(ETH_P_IPV6) && |
204 | sk->sk_family == AF_INET6) { | 204 | sk->sk_family == AF_INET6) { |
205 | struct ipv6_pinfo *np = inet6_sk(sk); | ||
206 | 205 | ||
207 | pr_debug("found: %p: num=%d, daddr=%pI6c, dif=%d\n", sk, | 206 | pr_debug("found: %p: num=%d, daddr=%pI6c, dif=%d\n", sk, |
208 | (int) isk->inet_num, | 207 | (int) isk->inet_num, |
209 | &inet6_sk(sk)->rcv_saddr, | 208 | &sk->sk_v6_rcv_saddr, |
210 | sk->sk_bound_dev_if); | 209 | sk->sk_bound_dev_if); |
211 | 210 | ||
212 | if (!ipv6_addr_any(&np->rcv_saddr) && | 211 | if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr) && |
213 | !ipv6_addr_equal(&np->rcv_saddr, | 212 | !ipv6_addr_equal(&sk->sk_v6_rcv_saddr, |
214 | &ipv6_hdr(skb)->daddr)) | 213 | &ipv6_hdr(skb)->daddr)) |
215 | continue; | 214 | continue; |
216 | #endif | 215 | #endif |
@@ -362,7 +361,7 @@ static void ping_set_saddr(struct sock *sk, struct sockaddr *saddr) | |||
362 | } else if (saddr->sa_family == AF_INET6) { | 361 | } else if (saddr->sa_family == AF_INET6) { |
363 | struct sockaddr_in6 *addr = (struct sockaddr_in6 *) saddr; | 362 | struct sockaddr_in6 *addr = (struct sockaddr_in6 *) saddr; |
364 | struct ipv6_pinfo *np = inet6_sk(sk); | 363 | struct ipv6_pinfo *np = inet6_sk(sk); |
365 | np->rcv_saddr = np->saddr = addr->sin6_addr; | 364 | sk->sk_v6_rcv_saddr = np->saddr = addr->sin6_addr; |
366 | #endif | 365 | #endif |
367 | } | 366 | } |
368 | } | 367 | } |
@@ -376,7 +375,7 @@ static void ping_clear_saddr(struct sock *sk, int dif) | |||
376 | #if IS_ENABLED(CONFIG_IPV6) | 375 | #if IS_ENABLED(CONFIG_IPV6) |
377 | } else if (sk->sk_family == AF_INET6) { | 376 | } else if (sk->sk_family == AF_INET6) { |
378 | struct ipv6_pinfo *np = inet6_sk(sk); | 377 | struct ipv6_pinfo *np = inet6_sk(sk); |
379 | memset(&np->rcv_saddr, 0, sizeof(np->rcv_saddr)); | 378 | memset(&sk->sk_v6_rcv_saddr, 0, sizeof(sk->sk_v6_rcv_saddr)); |
380 | memset(&np->saddr, 0, sizeof(np->saddr)); | 379 | memset(&np->saddr, 0, sizeof(np->saddr)); |
381 | #endif | 380 | #endif |
382 | } | 381 | } |
@@ -418,7 +417,7 @@ int ping_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
418 | err = 0; | 417 | err = 0; |
419 | if ((sk->sk_family == AF_INET && isk->inet_rcv_saddr) || | 418 | if ((sk->sk_family == AF_INET && isk->inet_rcv_saddr) || |
420 | (sk->sk_family == AF_INET6 && | 419 | (sk->sk_family == AF_INET6 && |
421 | !ipv6_addr_any(&inet6_sk(sk)->rcv_saddr))) | 420 | !ipv6_addr_any(&sk->sk_v6_rcv_saddr))) |
422 | sk->sk_userlocks |= SOCK_BINDADDR_LOCK; | 421 | sk->sk_userlocks |= SOCK_BINDADDR_LOCK; |
423 | 422 | ||
424 | if (snum) | 423 | if (snum) |
@@ -429,7 +428,7 @@ int ping_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
429 | 428 | ||
430 | #if IS_ENABLED(CONFIG_IPV6) | 429 | #if IS_ENABLED(CONFIG_IPV6) |
431 | if (sk->sk_family == AF_INET6) | 430 | if (sk->sk_family == AF_INET6) |
432 | memset(&inet6_sk(sk)->daddr, 0, sizeof(inet6_sk(sk)->daddr)); | 431 | memset(&sk->sk_v6_daddr, 0, sizeof(sk->sk_v6_daddr)); |
433 | #endif | 432 | #endif |
434 | 433 | ||
435 | sk_dst_reset(sk); | 434 | sk_dst_reset(sk); |