Skip to content

Commit 5b441f7

Browse files
edumazetdavem330
authored andcommitted
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: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6eada01 commit 5b441f7

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

include/net/inet_hashtables.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ static inline struct sock *__inet_lookup_skb(struct inet_hashinfo *hashinfo,
383383
iph->daddr, dport, inet_iif(skb));
384384
}
385385

386+
u32 sk_ehashfn(const struct sock *sk);
387+
386388
int __inet_hash_connect(struct inet_timewait_death_row *death_row,
387389
struct sock *sk, u32 port_offset,
388390
int (*check_established)(struct inet_timewait_death_row *,

net/ipv4/inet_hashtables.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,11 @@ static u32 inet_ehashfn(const struct net *net, const __be32 laddr,
3737
}
3838

3939

40-
static unsigned int inet_sk_ehashfn(const struct sock *sk)
40+
u32 sk_ehashfn(const struct sock *sk)
4141
{
42-
const struct inet_sock *inet = inet_sk(sk);
43-
const __be32 laddr = inet->inet_rcv_saddr;
44-
const __u16 lport = inet->inet_num;
45-
const __be32 faddr = inet->inet_daddr;
46-
const __be16 fport = inet->inet_dport;
47-
struct net *net = sock_net(sk);
48-
49-
return inet_ehashfn(net, laddr, lport, faddr, fport);
42+
return inet_ehashfn(sock_net(sk),
43+
sk->sk_rcv_saddr, sk->sk_num,
44+
sk->sk_daddr, sk->sk_dport);
5045
}
5146

5247
/*
@@ -407,13 +402,13 @@ int __inet_hash_nolisten(struct sock *sk, struct inet_timewait_sock *tw)
407402
{
408403
struct inet_hashinfo *hashinfo = sk->sk_prot->h.hashinfo;
409404
struct hlist_nulls_head *list;
410-
spinlock_t *lock;
411405
struct inet_ehash_bucket *head;
406+
spinlock_t *lock;
412407
int twrefcnt = 0;
413408

414409
WARN_ON(!sk_unhashed(sk));
415410

416-
sk->sk_hash = inet_sk_ehashfn(sk);
411+
sk->sk_hash = sk_ehashfn(sk);
417412
head = inet_ehash_bucket(hashinfo, sk->sk_hash);
418413
list = &head->chain;
419414
lock = inet_ehash_lockp(hashinfo, sk->sk_hash);

0 commit comments

Comments
 (0)