Commit 5b441f76 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: introduce sk_ehashfn() helper

Goal is to unify IPv4/IPv6 inet_hash handling, and use common helpers
for all kind of sockets (full sockets, timewait and request sockets)

inet_sk_ehashfn() becomes sk_ehashfn() but still only copes with IPv4
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6eada011
...@@ -383,6 +383,8 @@ static inline struct sock *__inet_lookup_skb(struct inet_hashinfo *hashinfo, ...@@ -383,6 +383,8 @@ static inline struct sock *__inet_lookup_skb(struct inet_hashinfo *hashinfo,
iph->daddr, dport, inet_iif(skb)); iph->daddr, dport, inet_iif(skb));
} }
u32 sk_ehashfn(const struct sock *sk);
int __inet_hash_connect(struct inet_timewait_death_row *death_row, int __inet_hash_connect(struct inet_timewait_death_row *death_row,
struct sock *sk, u32 port_offset, struct sock *sk, u32 port_offset,
int (*check_established)(struct inet_timewait_death_row *, int (*check_established)(struct inet_timewait_death_row *,
......
...@@ -37,16 +37,11 @@ static u32 inet_ehashfn(const struct net *net, const __be32 laddr, ...@@ -37,16 +37,11 @@ static u32 inet_ehashfn(const struct net *net, const __be32 laddr,
} }
static unsigned int inet_sk_ehashfn(const struct sock *sk) u32 sk_ehashfn(const struct sock *sk)
{ {
const struct inet_sock *inet = inet_sk(sk); return inet_ehashfn(sock_net(sk),
const __be32 laddr = inet->inet_rcv_saddr; sk->sk_rcv_saddr, sk->sk_num,
const __u16 lport = inet->inet_num; sk->sk_daddr, sk->sk_dport);
const __be32 faddr = inet->inet_daddr;
const __be16 fport = inet->inet_dport;
struct net *net = sock_net(sk);
return inet_ehashfn(net, laddr, lport, faddr, fport);
} }
/* /*
...@@ -407,13 +402,13 @@ int __inet_hash_nolisten(struct sock *sk, struct inet_timewait_sock *tw) ...@@ -407,13 +402,13 @@ int __inet_hash_nolisten(struct sock *sk, struct inet_timewait_sock *tw)
{ {
struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo; struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
struct hlist_nulls_head *list; struct hlist_nulls_head *list;
spinlock_t *lock;
struct inet_ehash_bucket *head; struct inet_ehash_bucket *head;
spinlock_t *lock;
int twrefcnt = 0; int twrefcnt = 0;
WARN_ON(!sk_unhashed(sk)); WARN_ON(!sk_unhashed(sk));
sk->sk_hash = inet_sk_ehashfn(sk); sk->sk_hash = sk_ehashfn(sk);
head = inet_ehash_bucket(hashinfo, sk->sk_hash); head = inet_ehash_bucket(hashinfo, sk->sk_hash);
list = &head->chain; list = &head->chain;
lock = inet_ehash_lockp(hashinfo, sk->sk_hash); lock = inet_ehash_lockp(hashinfo, sk->sk_hash);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment