aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2015-03-18 17:05:35 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-18 22:00:34 -0400
commitd1e559d0b1b0d02f76a6bd5b768a99dc834ae926 (patch)
tree283048c1921aeec1c2dfb25e72e6e67cddffcb23 /net/ipv6
parent5b441f76f1b83591e8cd9d60ba1df3a2aacde27f (diff)
inet: add IPv6 support to sk_ehashfn()
Intent is to converge IPv4 & IPv6 inet_hash functions to factorize code. IPv4 sockets initialize sk_rcv_saddr and sk_v6_daddr in this patch, thanks to new sk_daddr_set() and sk_rcv_saddr_set() helpers. __inet6_hash can now use sk_ehashfn() instead of a private inet6_sk_ehashfn() and will simply use __inet_hash() in a following patch. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
-rw-r--r--net/ipv6/inet6_hashtables.c22
-rw-r--r--net/ipv6/tcp_ipv6.c11
2 files changed, 6 insertions, 27 deletions
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index df7df99d1d7e..ed5787b20192 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
26static u32 inet6_ehashfn(const struct net *net, 26u32 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,18 +42,6 @@ static u32 inet6_ehashfn(const struct net *net,
44 inet6_ehash_secret + net_hash_mix(net)); 42 inet6_ehash_secret + net_hash_mix(net));
45} 43}
46 44
47static 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
59int __inet6_hash(struct sock *sk, struct inet_timewait_sock *tw) 45int __inet6_hash(struct sock *sk, struct inet_timewait_sock *tw)
60{ 46{
61 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; 47 struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
@@ -75,7 +61,7 @@ int __inet6_hash(struct sock *sk, struct inet_timewait_sock *tw)
75 struct hlist_nulls_head *list; 61 struct hlist_nulls_head *list;
76 spinlock_t *lock; 62 spinlock_t *lock;
77 63
78 sk->sk_hash = hash = inet6_sk_ehashfn(sk); 64 sk->sk_hash = hash = sk_ehashfn(sk);
79 list = &inet_ehash_bucket(hashinfo, hash)->chain; 65 list = &inet_ehash_bucket(hashinfo, hash)->chain;
80 lock = inet_ehash_lockp(hashinfo, hash); 66 lock = inet_ehash_lockp(hashinfo, hash);
81 spin_lock(lock); 67 spin_lock(lock);
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index e4761b22307b..5546df074583 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -233,11 +233,8 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
233 tp->af_specific = &tcp_sock_ipv6_specific; 233 tp->af_specific = &tcp_sock_ipv6_specific;
234#endif 234#endif
235 goto failure; 235 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 } 236 }
237 np->saddr = sk->sk_v6_rcv_saddr;
241 238
242 return err; 239 return err;
243 } 240 }
@@ -1078,11 +1075,7 @@ static struct sock *tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1078 1075
1079 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 1076 memcpy(newnp, np, sizeof(struct ipv6_pinfo));
1080 1077
1081 ipv6_addr_set_v4mapped(newinet->inet_daddr, &newsk->sk_v6_daddr); 1078 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 1079
1087 inet_csk(newsk)->icsk_af_ops = &ipv6_mapped; 1080 inet_csk(newsk)->icsk_af_ops = &ipv6_mapped;
1088 newsk->sk_backlog_rcv = tcp_v4_do_rcv; 1081 newsk->sk_backlog_rcv = tcp_v4_do_rcv;