aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/raw.c
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2007-11-20 01:36:45 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 17:54:30 -0500
commitb673e4dfc8f29e5bfe4d342029b793e9d504f6dd (patch)
treee0282a3819176b9f28eb7e2021c55c70bdbda50e /net/ipv4/raw.c
parent69d6da0b0faa70249a243a14e6066c013e9294e5 (diff)
[RAW]: Introduce raw_hashinfo structure
The ipv4/raw.c and ipv6/raw.c contain many common code (most of which is proc interface) which can be consolidated. Most of the places to consolidate deal with the raw sockets hashtable, so introduce a struct raw_hashinfo which describes the raw sockets hash. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/raw.c')
-rw-r--r--net/ipv4/raw.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 8a506618b912..dd9f00b3ab42 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -80,28 +80,27 @@
80#include <linux/netfilter.h> 80#include <linux/netfilter.h>
81#include <linux/netfilter_ipv4.h> 81#include <linux/netfilter_ipv4.h>
82 82
83#define RAWV4_HTABLE_SIZE MAX_INET_PROTOS 83static struct raw_hashinfo raw_v4_hashinfo = {
84 84 .lock = __RW_LOCK_UNLOCKED(),
85static struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE]; 85};
86static DEFINE_RWLOCK(raw_v4_lock);
87 86
88static void raw_v4_hash(struct sock *sk) 87static void raw_v4_hash(struct sock *sk)
89{ 88{
90 struct hlist_head *head = &raw_v4_htable[inet_sk(sk)->num & 89 struct hlist_head *head = &raw_v4_hashinfo.ht[inet_sk(sk)->num &
91 (RAWV4_HTABLE_SIZE - 1)]; 90 (RAW_HTABLE_SIZE - 1)];
92 91
93 write_lock_bh(&raw_v4_lock); 92 write_lock_bh(&raw_v4_hashinfo.lock);
94 sk_add_node(sk, head); 93 sk_add_node(sk, head);
95 sock_prot_inc_use(sk->sk_prot); 94 sock_prot_inc_use(sk->sk_prot);
96 write_unlock_bh(&raw_v4_lock); 95 write_unlock_bh(&raw_v4_hashinfo.lock);
97} 96}
98 97
99static void raw_v4_unhash(struct sock *sk) 98static void raw_v4_unhash(struct sock *sk)
100{ 99{
101 write_lock_bh(&raw_v4_lock); 100 write_lock_bh(&raw_v4_hashinfo.lock);
102 if (sk_del_node_init(sk)) 101 if (sk_del_node_init(sk))
103 sock_prot_dec_use(sk->sk_prot); 102 sock_prot_dec_use(sk->sk_prot);
104 write_unlock_bh(&raw_v4_lock); 103 write_unlock_bh(&raw_v4_hashinfo.lock);
105} 104}
106 105
107static struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num, 106static struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
@@ -158,8 +157,8 @@ static int raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash)
158 struct hlist_head *head; 157 struct hlist_head *head;
159 int delivered = 0; 158 int delivered = 0;
160 159
161 read_lock(&raw_v4_lock); 160 read_lock(&raw_v4_hashinfo.lock);
162 head = &raw_v4_htable[hash]; 161 head = &raw_v4_hashinfo.ht[hash];
163 if (hlist_empty(head)) 162 if (hlist_empty(head))
164 goto out; 163 goto out;
165 sk = __raw_v4_lookup(__sk_head(head), iph->protocol, 164 sk = __raw_v4_lookup(__sk_head(head), iph->protocol,
@@ -180,7 +179,7 @@ static int raw_v4_input(struct sk_buff *skb, struct iphdr *iph, int hash)
180 skb->dev->ifindex); 179 skb->dev->ifindex);
181 } 180 }
182out: 181out:
183 read_unlock(&raw_v4_lock); 182 read_unlock(&raw_v4_hashinfo.lock);
184 return delivered; 183 return delivered;
185} 184}
186 185
@@ -189,8 +188,8 @@ int raw_local_deliver(struct sk_buff *skb, int protocol)
189 int hash; 188 int hash;
190 struct sock *raw_sk; 189 struct sock *raw_sk;
191 190
192 hash = protocol & (RAWV4_HTABLE_SIZE - 1); 191 hash = protocol & (RAW_HTABLE_SIZE - 1);
193 raw_sk = sk_head(&raw_v4_htable[hash]); 192 raw_sk = sk_head(&raw_v4_hashinfo.ht[hash]);
194 193
195 /* If there maybe a raw socket we must check - if not we 194 /* If there maybe a raw socket we must check - if not we
196 * don't care less 195 * don't care less
@@ -262,10 +261,10 @@ void raw_icmp_error(struct sk_buff *skb, int protocol, u32 info)
262 struct sock *raw_sk; 261 struct sock *raw_sk;
263 struct iphdr *iph; 262 struct iphdr *iph;
264 263
265 hash = protocol & (RAWV4_HTABLE_SIZE - 1); 264 hash = protocol & (RAW_HTABLE_SIZE - 1);
266 265
267 read_lock(&raw_v4_lock); 266 read_lock(&raw_v4_hashinfo.lock);
268 raw_sk = sk_head(&raw_v4_htable[hash]); 267 raw_sk = sk_head(&raw_v4_hashinfo.ht[hash]);
269 if (raw_sk != NULL) { 268 if (raw_sk != NULL) {
270 iph = (struct iphdr *)skb->data; 269 iph = (struct iphdr *)skb->data;
271 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr, 270 while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
@@ -276,7 +275,7 @@ void raw_icmp_error(struct sk_buff *skb, int protocol, u32 info)
276 iph = (struct iphdr *)skb->data; 275 iph = (struct iphdr *)skb->data;
277 } 276 }
278 } 277 }
279 read_unlock(&raw_v4_lock); 278 read_unlock(&raw_v4_hashinfo.lock);
280} 279}
281 280
282static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb) 281static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
@@ -844,10 +843,11 @@ static struct sock *raw_get_first(struct seq_file *seq)
844 struct sock *sk; 843 struct sock *sk;
845 struct raw_iter_state* state = raw_seq_private(seq); 844 struct raw_iter_state* state = raw_seq_private(seq);
846 845
847 for (state->bucket = 0; state->bucket < RAWV4_HTABLE_SIZE; ++state->bucket) { 846 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
847 ++state->bucket) {
848 struct hlist_node *node; 848 struct hlist_node *node;
849 849
850 sk_for_each(sk, node, &raw_v4_htable[state->bucket]) 850 sk_for_each(sk, node, &raw_v4_hashinfo.ht[state->bucket])
851 if (sk->sk_family == PF_INET) 851 if (sk->sk_family == PF_INET)
852 goto found; 852 goto found;
853 } 853 }
@@ -866,8 +866,8 @@ try_again:
866 ; 866 ;
867 } while (sk && sk->sk_family != PF_INET); 867 } while (sk && sk->sk_family != PF_INET);
868 868
869 if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) { 869 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
870 sk = sk_head(&raw_v4_htable[state->bucket]); 870 sk = sk_head(&raw_v4_hashinfo.ht[state->bucket]);
871 goto try_again; 871 goto try_again;
872 } 872 }
873 return sk; 873 return sk;
@@ -885,7 +885,7 @@ static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos)
885 885
886static void *raw_seq_start(struct seq_file *seq, loff_t *pos) 886static void *raw_seq_start(struct seq_file *seq, loff_t *pos)
887{ 887{
888 read_lock(&raw_v4_lock); 888 read_lock(&raw_v4_hashinfo.lock);
889 return *pos ? raw_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; 889 return *pos ? raw_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
890} 890}
891 891
@@ -903,7 +903,7 @@ static void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos)
903 903
904static void raw_seq_stop(struct seq_file *seq, void *v) 904static void raw_seq_stop(struct seq_file *seq, void *v)
905{ 905{
906 read_unlock(&raw_v4_lock); 906 read_unlock(&raw_v4_hashinfo.lock);
907} 907}
908 908
909static __inline__ char *get_raw_sock(struct sock *sp, char *tmpbuf, int i) 909static __inline__ char *get_raw_sock(struct sock *sp, char *tmpbuf, int i)