瀏覽代碼

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>
Pavel Emelyanov 17 年之前
父節點
當前提交
9f26b3add3
共有 2 個文件被更改,包括 7 次插入5 次删除
  1. 4 2
      include/net/inet_sock.h
  2. 3 3
      net/ipv4/inet_hashtables.c

+ 4 - 2
include/net/inet_sock.h

@@ -171,7 +171,8 @@ extern int inet_sk_rebuild_header(struct sock *sk);
 extern u32 inet_ehash_secret;
 extern u32 inet_ehash_secret;
 extern void build_ehash_secret(void);
 extern void build_ehash_secret(void);
 
 
-static inline unsigned int inet_ehashfn(const __be32 laddr, const __u16 lport,
+static inline unsigned int inet_ehashfn(struct net *net,
+					const __be32 laddr, const __u16 lport,
 					const __be32 faddr, const __be16 fport)
 					const __be32 faddr, const __be16 fport)
 {
 {
 	return jhash_3words((__force __u32) laddr,
 	return jhash_3words((__force __u32) laddr,
@@ -187,8 +188,9 @@ static inline int inet_sk_ehashfn(const struct sock *sk)
 	const __u16 lport = inet->num;
 	const __u16 lport = inet->num;
 	const __be32 faddr = inet->daddr;
 	const __be32 faddr = inet->daddr;
 	const __be16 fport = inet->dport;
 	const __be16 fport = inet->dport;
+	struct net *net = sock_net(sk);
 
 
-	return inet_ehashfn(laddr, lport, faddr, fport);
+	return inet_ehashfn(net, laddr, lport, faddr, fport);
 }
 }
 
 
 
 

+ 3 - 3
net/ipv4/inet_hashtables.c

@@ -227,7 +227,7 @@ struct sock * __inet_lookup_established(struct net *net,
 	/* Optimize here for direct hit, only listening connections can
 	/* Optimize here for direct hit, only listening connections can
 	 * have wildcards anyways.
 	 * have wildcards anyways.
 	 */
 	 */
-	unsigned int hash = inet_ehashfn(daddr, hnum, saddr, sport);
+	unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport);
 	struct inet_ehash_bucket *head = inet_ehash_bucket(hashinfo, hash);
 	struct inet_ehash_bucket *head = inet_ehash_bucket(hashinfo, hash);
 	rwlock_t *lock = inet_ehash_lockp(hashinfo, hash);
 	rwlock_t *lock = inet_ehash_lockp(hashinfo, hash);
 
 
@@ -267,13 +267,13 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
 	int dif = sk->sk_bound_dev_if;
 	int dif = sk->sk_bound_dev_if;
 	INET_ADDR_COOKIE(acookie, saddr, daddr)
 	INET_ADDR_COOKIE(acookie, saddr, daddr)
 	const __portpair ports = INET_COMBINED_PORTS(inet->dport, lport);
 	const __portpair ports = INET_COMBINED_PORTS(inet->dport, lport);
-	unsigned int hash = inet_ehashfn(daddr, lport, saddr, inet->dport);
+	struct net *net = sock_net(sk);
+	unsigned int hash = inet_ehashfn(net, daddr, lport, saddr, inet->dport);
 	struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
 	struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash);
 	rwlock_t *lock = inet_ehash_lockp(hinfo, hash);
 	rwlock_t *lock = inet_ehash_lockp(hinfo, hash);
 	struct sock *sk2;
 	struct sock *sk2;
 	const struct hlist_node *node;
 	const struct hlist_node *node;
 	struct inet_timewait_sock *tw;
 	struct inet_timewait_sock *tw;
-	struct net *net = sock_net(sk);
 
 
 	prefetch(head->chain.first);
 	prefetch(head->chain.first);
 	write_lock(lock);
 	write_lock(lock);