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>
This commit is contained in:
committed by
David S. Miller
parent
05dbc7b594
commit
efe4208f47
@@ -202,15 +202,14 @@ static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident)
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
} else if (skb->protocol == htons(ETH_P_IPV6) &&
|
||||
sk->sk_family == AF_INET6) {
|
||||
struct ipv6_pinfo *np = inet6_sk(sk);
|
||||
|
||||
pr_debug("found: %p: num=%d, daddr=%pI6c, dif=%d\n", sk,
|
||||
(int) isk->inet_num,
|
||||
&inet6_sk(sk)->rcv_saddr,
|
||||
&sk->sk_v6_rcv_saddr,
|
||||
sk->sk_bound_dev_if);
|
||||
|
||||
if (!ipv6_addr_any(&np->rcv_saddr) &&
|
||||
!ipv6_addr_equal(&np->rcv_saddr,
|
||||
if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr) &&
|
||||
!ipv6_addr_equal(&sk->sk_v6_rcv_saddr,
|
||||
&ipv6_hdr(skb)->daddr))
|
||||
continue;
|
||||
#endif
|
||||
@@ -362,7 +361,7 @@ static void ping_set_saddr(struct sock *sk, struct sockaddr *saddr)
|
||||
} else if (saddr->sa_family == AF_INET6) {
|
||||
struct sockaddr_in6 *addr = (struct sockaddr_in6 *) saddr;
|
||||
struct ipv6_pinfo *np = inet6_sk(sk);
|
||||
np->rcv_saddr = np->saddr = addr->sin6_addr;
|
||||
sk->sk_v6_rcv_saddr = np->saddr = addr->sin6_addr;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -376,7 +375,7 @@ static void ping_clear_saddr(struct sock *sk, int dif)
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
} else if (sk->sk_family == AF_INET6) {
|
||||
struct ipv6_pinfo *np = inet6_sk(sk);
|
||||
memset(&np->rcv_saddr, 0, sizeof(np->rcv_saddr));
|
||||
memset(&sk->sk_v6_rcv_saddr, 0, sizeof(sk->sk_v6_rcv_saddr));
|
||||
memset(&np->saddr, 0, sizeof(np->saddr));
|
||||
#endif
|
||||
}
|
||||
@@ -418,7 +417,7 @@ int ping_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
|
||||
err = 0;
|
||||
if ((sk->sk_family == AF_INET && isk->inet_rcv_saddr) ||
|
||||
(sk->sk_family == AF_INET6 &&
|
||||
!ipv6_addr_any(&inet6_sk(sk)->rcv_saddr)))
|
||||
!ipv6_addr_any(&sk->sk_v6_rcv_saddr)))
|
||||
sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
|
||||
|
||||
if (snum)
|
||||
@@ -429,7 +428,7 @@ int ping_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
|
||||
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
if (sk->sk_family == AF_INET6)
|
||||
memset(&inet6_sk(sk)->daddr, 0, sizeof(inet6_sk(sk)->daddr));
|
||||
memset(&sk->sk_v6_daddr, 0, sizeof(sk->sk_v6_daddr));
|
||||
#endif
|
||||
|
||||
sk_dst_reset(sk);
|
||||
|
||||
Reference in New Issue
Block a user