Skip to content

Commit 9f26b3a

Browse files
xemuldavem330
authored andcommitted
inet: add struct net argument to inet_ehashfn
Although this hash takes addresses into account, the ehash chains can also be too long when, for instance, communications via lo occur. So, prepare the inet_hashfn to take struct net into account. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2086a65 commit 9f26b3a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

include/net/inet_sock.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ extern int inet_sk_rebuild_header(struct sock *sk);
171171
extern u32 inet_ehash_secret;
172172
extern void build_ehash_secret(void);
173173

174-
static inline unsigned int inet_ehashfn(const __be32 laddr, const __u16 lport,
174+
static inline unsigned int inet_ehashfn(struct net *net,
175+
const __be32 laddr, const __u16 lport,
175176
const __be32 faddr, const __be16 fport)
176177
{
177178
return jhash_3words((__force __u32) laddr,
@@ -187,8 +188,9 @@ static inline int inet_sk_ehashfn(const struct sock *sk)
187188
const __u16 lport = inet->num;
188189
const __be32 faddr = inet->daddr;
189190
const __be16 fport = inet->dport;
191+
struct net *net = sock_net(sk);
190192

191-
return inet_ehashfn(laddr, lport, faddr, fport);
193+
return inet_ehashfn(net, laddr, lport, faddr, fport);
192194
}
193195

194196

net/ipv4/inet_hashtables.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ struct sock * __inet_lookup_established(struct net *net,
227227
/* Optimize here for direct hit, only listening connections can
228228
* have wildcards anyways.
229229
*/
230-
unsigned int hash = inet_ehashfn(daddr, hnum, saddr, sport);
230+
unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport);
231231
struct inet_ehash_bucket *head = inet_ehash_bucket(hashinfo, hash);
232232
rwlock_t *lock = inet_ehash_lockp(hashinfo, hash);
233233

@@ -267,13 +267,13 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
267267
int dif = sk->sk_bound_dev_if;
268268
INET_ADDR_COOKIE(acookie, saddr, daddr)
269269
const __portpair ports = INET_COMBINED_PORTS(inet->dport, lport);
270-
unsigned int hash = inet_ehashfn(daddr, lport, saddr, inet->dport);
270+
struct net *net = sock_net(sk);
271+
unsigned int hash = inet_ehashfn(net, daddr, lport, saddr, inet->dport);
271272
struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
272273
rwlock_t *lock = inet_ehash_lockp(hinfo, hash);
273274
struct sock *sk2;
274275
const struct hlist_node *node;
275276
struct inet_timewait_sock *tw;
276-
struct net *net = sock_net(sk);
277277

278278
prefetch(head->chain.first);
279279
write_lock(lock);

0 commit comments

Comments
 (0)