aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/raw.c
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2007-11-20 01:38:33 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 17:54:32 -0500
commit42a73808ed4f30b739eb52bcbb33a02fe62ceef5 (patch)
tree3bd75f0afd1277d9340aa416ff79eec0be040392 /net/ipv6/raw.c
parentab70768ec78c6784958bab3b58fbe3f4150006df (diff)
[RAW]: Consolidate proc interface.
Both ipv6/raw.c and ipv4/raw.c use the seq files to walk through the raw sockets hash and show them. The "walking" code is rather huge, but is identical in both cases. The difference is the hash table to walk over and the protocol family to check (this was not in the first virsion of the patch, which was noticed by YOSHIFUJI) Make the ->open store the needed hash table and the family on the allocated raw_iter_state and make the start/next/stop callbacks work with it. This removes most of the code. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/raw.c')
-rw-r--r--net/ipv6/raw.c82
1 files changed, 5 insertions, 77 deletions
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 422d27cfbe16..b34631e1b015 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -1200,77 +1200,6 @@ struct proto rawv6_prot = {
1200}; 1200};
1201 1201
1202#ifdef CONFIG_PROC_FS 1202#ifdef CONFIG_PROC_FS
1203struct raw6_iter_state {
1204 int bucket;
1205};
1206
1207#define raw6_seq_private(seq) ((struct raw6_iter_state *)(seq)->private)
1208
1209static struct sock *raw6_get_first(struct seq_file *seq)
1210{
1211 struct sock *sk;
1212 struct hlist_node *node;
1213 struct raw6_iter_state* state = raw6_seq_private(seq);
1214
1215 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
1216 ++state->bucket)
1217 sk_for_each(sk, node, &raw_v6_hashinfo.ht[state->bucket])
1218 if (sk->sk_family == PF_INET6)
1219 goto out;
1220 sk = NULL;
1221out:
1222 return sk;
1223}
1224
1225static struct sock *raw6_get_next(struct seq_file *seq, struct sock *sk)
1226{
1227 struct raw6_iter_state* state = raw6_seq_private(seq);
1228
1229 do {
1230 sk = sk_next(sk);
1231try_again:
1232 ;
1233 } while (sk && sk->sk_family != PF_INET6);
1234
1235 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
1236 sk = sk_head(&raw_v6_hashinfo.ht[state->bucket]);
1237 goto try_again;
1238 }
1239 return sk;
1240}
1241
1242static struct sock *raw6_get_idx(struct seq_file *seq, loff_t pos)
1243{
1244 struct sock *sk = raw6_get_first(seq);
1245 if (sk)
1246 while (pos && (sk = raw6_get_next(seq, sk)) != NULL)
1247 --pos;
1248 return pos ? NULL : sk;
1249}
1250
1251static void *raw6_seq_start(struct seq_file *seq, loff_t *pos)
1252{
1253 read_lock(&raw_v6_hashinfo.lock);
1254 return *pos ? raw6_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
1255}
1256
1257static void *raw6_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1258{
1259 struct sock *sk;
1260
1261 if (v == SEQ_START_TOKEN)
1262 sk = raw6_get_first(seq);
1263 else
1264 sk = raw6_get_next(seq, v);
1265 ++*pos;
1266 return sk;
1267}
1268
1269static void raw6_seq_stop(struct seq_file *seq, void *v)
1270{
1271 read_unlock(&raw_v6_hashinfo.lock);
1272}
1273
1274static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i) 1203static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
1275{ 1204{
1276 struct ipv6_pinfo *np = inet6_sk(sp); 1205 struct ipv6_pinfo *np = inet6_sk(sp);
@@ -1308,21 +1237,20 @@ static int raw6_seq_show(struct seq_file *seq, void *v)
1308 "st tx_queue rx_queue tr tm->when retrnsmt" 1237 "st tx_queue rx_queue tr tm->when retrnsmt"
1309 " uid timeout inode drops\n"); 1238 " uid timeout inode drops\n");
1310 else 1239 else
1311 raw6_sock_seq_show(seq, v, raw6_seq_private(seq)->bucket); 1240 raw6_sock_seq_show(seq, v, raw_seq_private(seq)->bucket);
1312 return 0; 1241 return 0;
1313} 1242}
1314 1243
1315static const struct seq_operations raw6_seq_ops = { 1244static const struct seq_operations raw6_seq_ops = {
1316 .start = raw6_seq_start, 1245 .start = raw_seq_start,
1317 .next = raw6_seq_next, 1246 .next = raw_seq_next,
1318 .stop = raw6_seq_stop, 1247 .stop = raw_seq_stop,
1319 .show = raw6_seq_show, 1248 .show = raw6_seq_show,
1320}; 1249};
1321 1250
1322static int raw6_seq_open(struct inode *inode, struct file *file) 1251static int raw6_seq_open(struct inode *inode, struct file *file)
1323{ 1252{
1324 return seq_open_private(file, &raw6_seq_ops, 1253 return raw_seq_open(file, &raw_v6_hashinfo, PF_INET6);
1325 sizeof(struct raw6_iter_state));
1326} 1254}
1327 1255
1328static const struct file_operations raw6_seq_fops = { 1256static const struct file_operations raw6_seq_fops = {