Skip to contentSkip to conversation

Consolidate proc interface

PATCH Applied Pavel Emelyanov 2 participants 3 messages Nov 16, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 6/6 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.

Make the ->open store the needed hash table on the allocated raw_iter_state and make the start/next/stop callbacks work with it.

This removes most of the code.

---

include/net/raw.h +12 -0
index 81a1773..c55d11e 100644
@@ -37,6 +37,18 @@ struct raw_hashinfo {
 #ifdef CONFIG_PROC_FS
 extern int  raw_proc_init(void);
 extern void raw_proc_exit(void);
+
+struct raw_iter_state {
+	int bucket;
+	struct raw_hashinfo *h;
+};
+
+#define raw_seq_private(seq) ((struct raw_iter_state *)(seq)->private)
+void *raw_seq_start(struct seq_file *seq, loff_t *pos);
+void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos);
+void raw_seq_stop(struct seq_file *seq, void *v);
+int raw_seq_open(struct file *file, struct raw_hashinfo *h);
+
 #endif
 
 void raw_hash_sk(struct sock *sk, struct raw_hashinfo *h);
net/ipv4/raw.c +30 -16

95 lines not on this page · raw message

net/ipv6/raw.c +5 -77

103 lines not on this page · raw message

#1 lore raw

NAK.

In article <[email protected]> (at Fri, 16 Nov 2007 17:19:27 +0300), Pavel Emelyanov <[email protected]> says:

net/ipv4/raw.c static struct sock *raw_get_first(struct seq_file *seq) · line 858

Quoted 9 lines
net/ipv4/raw.c +1 -1
@@ -858,7 +852,7 @@ static struct sock *raw_get_first(struct seq_file *seq)
 			++state->bucket) {
 		struct hlist_node *node;
 
-		sk_for_each(sk, node, &raw_v4_hashinfo.ht[state->bucket])
+		sk_for_each(sk, node, &state->h->ht[state->bucket])
 			if (sk->sk_family == PF_INET)
 				goto found;
 	}

This and

Quoted 6 lines
net/ipv6/raw.c +0 -6
-static struct sock *raw6_get_first(struct seq_file *seq)
-{
-	struct sock *sk;
-	struct hlist_node *node;
-	struct raw6_iter_state* state = raw6_seq_private(seq);
-

net/ipv6/raw.c struct proto rawv6_prot = { · line 1224

Quoted 10 lines
net/ipv6/raw.c +0 -10
-	for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
-			++state->bucket)
-		sk_for_each(sk, node, &raw_v6_hashinfo.ht[state->bucket])
-			if (sk->sk_family == PF_INET6)
-				goto out;
-	sk = NULL;
-out:
-	return sk;
-}
-

this are different.

--yoshfuji

#2 lore raw
Quoted 26 lines · YOSHIFUJI Hideaki

NAK.

In article <[email protected]> (at Fri, 16 Nov 2007 17:19:27 +0300), Pavel Emelyanov <[email protected]> says:

net/ipv4/raw.c static struct sock *raw_get_first(struct seq_file *seq) · line 858

Quoted 9 lines
net/ipv4/raw.c +1 -1
@@ -858,7 +852,7 @@ static struct sock *raw_get_first(struct seq_file *seq)
 			++state->bucket) {
 		struct hlist_node *node;
 
-		sk_for_each(sk, node, &raw_v4_hashinfo.ht[state->bucket])
+		sk_for_each(sk, node, &state->h->ht[state->bucket])
 			if (sk->sk_family == PF_INET)
 				goto found;
 	}

This and

Quoted 10 lines
net/ipv6/raw.c +0 -10
-static struct sock *raw6_get_first(struct seq_file *seq)
-{
-	struct sock *sk;
-	struct hlist_node *node;
-	struct raw6_iter_state* state = raw6_seq_private(seq);
-
-	for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
-			++state->bucket)
-		sk_for_each(sk, node, &raw_v6_hashinfo.ht[state->bucket])
-			if (sk->sk_family == PF_INET6)
Quoted 8 lines

net/ipv6/raw.c struct proto rawv6_prot = { · line 1224

Quoted 6 lines
net/ipv6/raw.c +0 -6
-				goto out;
-	sk = NULL;
-out:
-	return sk;
-}
-

this are different.

Oops... Indeed. Thanks for noticing. I've overlooked this :(

Quoted 2 lines

--yoshfuji