diff options
author | David S. Miller <davem@davemloft.net> | 2015-03-18 22:00:44 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-18 22:00:44 -0400 |
commit | fdf9ef8999c0758bf622899e049f2be45ab1f4da (patch) | |
tree | 6ef039c1602a24c64549663d734d10d2a382f08e /net/ipv6 | |
parent | 8f6320de5f6a817ba360be6ae39f721c7f9b26fb (diff) | |
parent | 08d2cc3b26554cae21f279b520ae5c2a3b2be421 (diff) |
Merge branch 'listen_refactor_part_13'
Eric Dumazet says:
====================
inet: tcp listener refactoring, part 13
inet_hash functions are in a bad state : Too much IPv6/IPv4 copy/pasting.
Lets refactor a bit.
Idea is that we do not want to have an equivalent of inet_csk(sk)->icsk_af_ops
for request socks in order to be able to use the right variant.
In this patch series, I started to let IPv6/IPv4 converge to common helpers.
Idea is to use ipv6_addr_set_v4mapped() even for AF_INET sockets, so that
we can test
if (sk->sk_family == AF_INET6 &&
!ipv6_addr_v4mapped(&sk->sk_v6_daddr))
to tell if we deal with an IPv6 socket, or IPv4 one, at least in slow paths.
Ideally, we could save 8 bytes per struct sock_common, if we
alias skc_daddr & skc_rcv_saddr to skc_v6_daddr[3]/skc_v6_rcv_saddr[3].
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/inet6_hashtables.c | 58 | ||||
-rw-r--r-- | net/ipv6/tcp_ipv6.c | 28 | ||||
-rw-r--r-- | net/ipv6/udp.c | 16 |
3 files changed, 16 insertions, 86 deletions
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index 051dffb49c90..033f17816ef4 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c | |||
@@ -23,11 +23,9 @@ | |||
23 | #include <net/secure_seq.h> | 23 | #include <net/secure_seq.h> |
24 | #include <net/ip.h> | 24 | #include <net/ip.h> |
25 | 25 | ||
26 | static unsigned int inet6_ehashfn(struct net *net, | 26 | u32 inet6_ehashfn(const struct net *net, |
27 | const struct in6_addr *laddr, | 27 | const struct in6_addr *laddr, const u16 lport, |
28 | const u16 lport, | 28 | const struct in6_addr *faddr, const __be16 fport) |
29 | const struct in6_addr *faddr, | ||
30 | const __be16 fport) | ||
31 | { | 29 | { |
32 | static u32 inet6_ehash_secret __read_mostly; | 30 | static u32 inet6_ehash_secret __read_mostly; |
33 | static u32 ipv6_hash_secret __read_mostly; | 31 | static u32 ipv6_hash_secret __read_mostly; |
@@ -44,54 +42,6 @@ static unsigned int inet6_ehashfn(struct net *net, | |||
44 | inet6_ehash_secret + net_hash_mix(net)); | 42 | inet6_ehash_secret + net_hash_mix(net)); |
45 | } | 43 | } |
46 | 44 | ||
47 | static int inet6_sk_ehashfn(const struct sock *sk) | ||
48 | { | ||
49 | const struct inet_sock *inet = inet_sk(sk); | ||
50 | const struct in6_addr *laddr = &sk->sk_v6_rcv_saddr; | ||
51 | const struct in6_addr *faddr = &sk->sk_v6_daddr; | ||
52 | const __u16 lport = inet->inet_num; | ||
53 | const __be16 fport = inet->inet_dport; | ||
54 | struct net *net = sock_net(sk); | ||
55 | |||
56 | return inet6_ehashfn(net, laddr, lport, faddr, fport); | ||
57 | } | ||
58 | |||
59 | int __inet6_hash(struct sock *sk, struct inet_timewait_sock *tw) | ||
60 | { | ||
61 | struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; | ||
62 | int twrefcnt = 0; | ||
63 | |||
64 | WARN_ON(!sk_unhashed(sk)); | ||
65 | |||
66 | if (sk->sk_state == TCP_LISTEN) { | ||
67 | struct inet_listen_hashbucket *ilb; | ||
68 | |||
69 | ilb = &hashinfo->listening_hash[inet_sk_listen_hashfn(sk)]; | ||
70 | spin_lock(&ilb->lock); | ||
71 | __sk_nulls_add_node_rcu(sk, &ilb->head); | ||
72 | spin_unlock(&ilb->lock); | ||
73 | } else { | ||
74 | unsigned int hash; | ||
75 | struct hlist_nulls_head *list; | ||
76 | spinlock_t *lock; | ||
77 | |||
78 | sk->sk_hash = hash = inet6_sk_ehashfn(sk); | ||
79 | list = &inet_ehash_bucket(hashinfo, hash)->chain; | ||
80 | lock = inet_ehash_lockp(hashinfo, hash); | ||
81 | spin_lock(lock); | ||
82 | __sk_nulls_add_node_rcu(sk, list); | ||
83 | if (tw) { | ||
84 | WARN_ON(sk->sk_hash != tw->tw_hash); | ||
85 | twrefcnt = inet_twsk_unhash(tw); | ||
86 | } | ||
87 | spin_unlock(lock); | ||
88 | } | ||
89 | |||
90 | sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); | ||
91 | return twrefcnt; | ||
92 | } | ||
93 | EXPORT_SYMBOL(__inet6_hash); | ||
94 | |||
95 | /* | 45 | /* |
96 | * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so | 46 | * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so |
97 | * we need not check it for TCP lookups anymore, thanks Alexey. -DaveM | 47 | * we need not check it for TCP lookups anymore, thanks Alexey. -DaveM |
@@ -320,6 +270,6 @@ int inet6_hash_connect(struct inet_timewait_death_row *death_row, | |||
320 | struct sock *sk) | 270 | struct sock *sk) |
321 | { | 271 | { |
322 | return __inet_hash_connect(death_row, sk, inet6_sk_port_offset(sk), | 272 | return __inet_hash_connect(death_row, sk, inet6_sk_port_offset(sk), |
323 | __inet6_check_established, __inet6_hash); | 273 | __inet6_check_established); |
324 | } | 274 | } |
325 | EXPORT_SYMBOL_GPL(inet6_hash_connect); | 275 | EXPORT_SYMBOL_GPL(inet6_hash_connect); |
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index e4761b22307b..720676d073d9 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c | |||
@@ -104,19 +104,6 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb) | |||
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | static void tcp_v6_hash(struct sock *sk) | ||
108 | { | ||
109 | if (sk->sk_state != TCP_CLOSE) { | ||
110 | if (inet_csk(sk)->icsk_af_ops == &ipv6_mapped) { | ||
111 | tcp_prot.hash(sk); | ||
112 | return; | ||
113 | } | ||
114 | local_bh_disable(); | ||
115 | __inet6_hash(sk, NULL); | ||
116 | local_bh_enable(); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | static __u32 tcp_v6_init_sequence(const struct sk_buff *skb) | 107 | static __u32 tcp_v6_init_sequence(const struct sk_buff *skb) |
121 | { | 108 | { |
122 | return secure_tcpv6_sequence_number(ipv6_hdr(skb)->daddr.s6_addr32, | 109 | return secure_tcpv6_sequence_number(ipv6_hdr(skb)->daddr.s6_addr32, |
@@ -233,11 +220,8 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr, | |||
233 | tp->af_specific = &tcp_sock_ipv6_specific; | 220 | tp->af_specific = &tcp_sock_ipv6_specific; |
234 | #endif | 221 | #endif |
235 | goto failure; | 222 | goto failure; |
236 | } else { | ||
237 | ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr); | ||
238 | ipv6_addr_set_v4mapped(inet->inet_rcv_saddr, | ||
239 | &sk->sk_v6_rcv_saddr); | ||
240 | } | 223 | } |
224 | np->saddr = sk->sk_v6_rcv_saddr; | ||
241 | 225 | ||
242 | return err; | 226 | return err; |
243 | } | 227 | } |
@@ -1078,11 +1062,7 @@ static struct sock *tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, | |||
1078 | 1062 | ||
1079 | memcpy(newnp, np, sizeof(struct ipv6_pinfo)); | 1063 | memcpy(newnp, np, sizeof(struct ipv6_pinfo)); |
1080 | 1064 | ||
1081 | ipv6_addr_set_v4mapped(newinet->inet_daddr, &newsk->sk_v6_daddr); | 1065 | newnp->saddr = newsk->sk_v6_rcv_saddr; |
1082 | |||
1083 | ipv6_addr_set_v4mapped(newinet->inet_saddr, &newnp->saddr); | ||
1084 | |||
1085 | newsk->sk_v6_rcv_saddr = newnp->saddr; | ||
1086 | 1066 | ||
1087 | inet_csk(newsk)->icsk_af_ops = &ipv6_mapped; | 1067 | inet_csk(newsk)->icsk_af_ops = &ipv6_mapped; |
1088 | newsk->sk_backlog_rcv = tcp_v4_do_rcv; | 1068 | newsk->sk_backlog_rcv = tcp_v4_do_rcv; |
@@ -1231,7 +1211,7 @@ static struct sock *tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, | |||
1231 | tcp_done(newsk); | 1211 | tcp_done(newsk); |
1232 | goto out; | 1212 | goto out; |
1233 | } | 1213 | } |
1234 | __inet6_hash(newsk, NULL); | 1214 | __inet_hash(newsk, NULL); |
1235 | 1215 | ||
1236 | return newsk; | 1216 | return newsk; |
1237 | 1217 | ||
@@ -1890,7 +1870,7 @@ struct proto tcpv6_prot = { | |||
1890 | .sendpage = tcp_sendpage, | 1870 | .sendpage = tcp_sendpage, |
1891 | .backlog_rcv = tcp_v6_do_rcv, | 1871 | .backlog_rcv = tcp_v6_do_rcv, |
1892 | .release_cb = tcp_release_cb, | 1872 | .release_cb = tcp_release_cb, |
1893 | .hash = tcp_v6_hash, | 1873 | .hash = inet_hash, |
1894 | .unhash = inet_unhash, | 1874 | .unhash = inet_unhash, |
1895 | .get_port = inet_csk_get_port, | 1875 | .get_port = inet_csk_get_port, |
1896 | .enter_memory_pressure = tcp_enter_memory_pressure, | 1876 | .enter_memory_pressure = tcp_enter_memory_pressure, |
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 70568a4548e4..7fe0329c0d37 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -53,11 +53,11 @@ | |||
53 | #include <trace/events/skb.h> | 53 | #include <trace/events/skb.h> |
54 | #include "udp_impl.h" | 54 | #include "udp_impl.h" |
55 | 55 | ||
56 | static unsigned int udp6_ehashfn(struct net *net, | 56 | static u32 udp6_ehashfn(const struct net *net, |
57 | const struct in6_addr *laddr, | 57 | const struct in6_addr *laddr, |
58 | const u16 lport, | 58 | const u16 lport, |
59 | const struct in6_addr *faddr, | 59 | const struct in6_addr *faddr, |
60 | const __be16 fport) | 60 | const __be16 fport) |
61 | { | 61 | { |
62 | static u32 udp6_ehash_secret __read_mostly; | 62 | static u32 udp6_ehash_secret __read_mostly; |
63 | static u32 udp_ipv6_hash_secret __read_mostly; | 63 | static u32 udp_ipv6_hash_secret __read_mostly; |
@@ -104,9 +104,9 @@ int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2) | |||
104 | return 0; | 104 | return 0; |
105 | } | 105 | } |
106 | 106 | ||
107 | static unsigned int udp6_portaddr_hash(struct net *net, | 107 | static u32 udp6_portaddr_hash(const struct net *net, |
108 | const struct in6_addr *addr6, | 108 | const struct in6_addr *addr6, |
109 | unsigned int port) | 109 | unsigned int port) |
110 | { | 110 | { |
111 | unsigned int hash, mix = net_hash_mix(net); | 111 | unsigned int hash, mix = net_hash_mix(net); |
112 | 112 | ||