浏览代码

[RAW]: Consolidate proto->hash callback

Having the raw_hashinfo it's easy to consolidate the
raw[46]_hash functions.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Pavel Emelyanov 17 年之前
父节点
当前提交
65b4c50b47
共有 3 个文件被更改,包括 15 次插入12 次删除
  1. 2 0
      include/net/raw.h
  2. 12 5
      net/ipv4/raw.c
  3. 1 7
      net/ipv6/raw.c

+ 2 - 0
include/net/raw.h

@@ -39,4 +39,6 @@ extern int  raw_proc_init(void);
 extern void raw_proc_exit(void);
 #endif
 
+void raw_hash_sk(struct sock *sk, struct raw_hashinfo *h);
+
 #endif	/* _RAW_H */

+ 12 - 5
net/ipv4/raw.c

@@ -84,15 +84,22 @@ static struct raw_hashinfo raw_v4_hashinfo = {
 	.lock = __RW_LOCK_UNLOCKED(),
 };
 
-static void raw_v4_hash(struct sock *sk)
+void raw_hash_sk(struct sock *sk, struct raw_hashinfo *h)
 {
-	struct hlist_head *head = &raw_v4_hashinfo.ht[inet_sk(sk)->num &
-						 (RAW_HTABLE_SIZE - 1)];
+	struct hlist_head *head;
 
-	write_lock_bh(&raw_v4_hashinfo.lock);
+	head = &h->ht[inet_sk(sk)->num & (RAW_HTABLE_SIZE - 1)];
+
+	write_lock_bh(&h->lock);
 	sk_add_node(sk, head);
 	sock_prot_inc_use(sk->sk_prot);
-	write_unlock_bh(&raw_v4_hashinfo.lock);
+	write_unlock_bh(&h->lock);
+}
+EXPORT_SYMBOL_GPL(raw_hash_sk);
+
+static void raw_v4_hash(struct sock *sk)
+{
+	raw_hash_sk(sk, &raw_v4_hashinfo);
 }
 
 static void raw_v4_unhash(struct sock *sk)

+ 1 - 7
net/ipv6/raw.c

@@ -67,13 +67,7 @@ static struct raw_hashinfo raw_v6_hashinfo = {
 
 static void raw_v6_hash(struct sock *sk)
 {
-	struct hlist_head *list = &raw_v6_hashinfo.ht[inet_sk(sk)->num &
-						 (RAW_HTABLE_SIZE - 1)];
-
-	write_lock_bh(&raw_v6_hashinfo.lock);
-	sk_add_node(sk, list);
-	sock_prot_inc_use(sk->sk_prot);
-	write_unlock_bh(&raw_v6_hashinfo.lock);
+	raw_hash_sk(sk, &raw_v6_hashinfo);
 }
 
 static void raw_v6_unhash(struct sock *sk)