diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2007-11-20 01:38:33 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-28 17:54:32 -0500 |
commit | 42a73808ed4f30b739eb52bcbb33a02fe62ceef5 (patch) | |
tree | 3bd75f0afd1277d9340aa416ff79eec0be040392 /net/ipv4/raw.c | |
parent | ab70768ec78c6784958bab3b58fbe3f4150006df (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/ipv4/raw.c')
-rw-r--r-- | net/ipv4/raw.c | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index d24501a342a4..2ff8214a530b 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -845,12 +845,6 @@ struct proto raw_prot = { | |||
845 | }; | 845 | }; |
846 | 846 | ||
847 | #ifdef CONFIG_PROC_FS | 847 | #ifdef CONFIG_PROC_FS |
848 | struct raw_iter_state { | ||
849 | int bucket; | ||
850 | }; | ||
851 | |||
852 | #define raw_seq_private(seq) ((struct raw_iter_state *)(seq)->private) | ||
853 | |||
854 | static struct sock *raw_get_first(struct seq_file *seq) | 848 | static struct sock *raw_get_first(struct seq_file *seq) |
855 | { | 849 | { |
856 | struct sock *sk; | 850 | struct sock *sk; |
@@ -860,8 +854,8 @@ static struct sock *raw_get_first(struct seq_file *seq) | |||
860 | ++state->bucket) { | 854 | ++state->bucket) { |
861 | struct hlist_node *node; | 855 | struct hlist_node *node; |
862 | 856 | ||
863 | sk_for_each(sk, node, &raw_v4_hashinfo.ht[state->bucket]) | 857 | sk_for_each(sk, node, &state->h->ht[state->bucket]) |
864 | if (sk->sk_family == PF_INET) | 858 | if (sk->sk_family == state->family) |
865 | goto found; | 859 | goto found; |
866 | } | 860 | } |
867 | sk = NULL; | 861 | sk = NULL; |
@@ -877,10 +871,10 @@ static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk) | |||
877 | sk = sk_next(sk); | 871 | sk = sk_next(sk); |
878 | try_again: | 872 | try_again: |
879 | ; | 873 | ; |
880 | } while (sk && sk->sk_family != PF_INET); | 874 | } while (sk && sk->sk_family != state->family); |
881 | 875 | ||
882 | if (!sk && ++state->bucket < RAW_HTABLE_SIZE) { | 876 | if (!sk && ++state->bucket < RAW_HTABLE_SIZE) { |
883 | sk = sk_head(&raw_v4_hashinfo.ht[state->bucket]); | 877 | sk = sk_head(&state->h->ht[state->bucket]); |
884 | goto try_again; | 878 | goto try_again; |
885 | } | 879 | } |
886 | return sk; | 880 | return sk; |
@@ -896,13 +890,16 @@ static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos) | |||
896 | return pos ? NULL : sk; | 890 | return pos ? NULL : sk; |
897 | } | 891 | } |
898 | 892 | ||
899 | static void *raw_seq_start(struct seq_file *seq, loff_t *pos) | 893 | void *raw_seq_start(struct seq_file *seq, loff_t *pos) |
900 | { | 894 | { |
901 | read_lock(&raw_v4_hashinfo.lock); | 895 | struct raw_iter_state *state = raw_seq_private(seq); |
896 | |||
897 | read_lock(&state->h->lock); | ||
902 | return *pos ? raw_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; | 898 | return *pos ? raw_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; |
903 | } | 899 | } |
900 | EXPORT_SYMBOL_GPL(raw_seq_start); | ||
904 | 901 | ||
905 | static void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 902 | void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
906 | { | 903 | { |
907 | struct sock *sk; | 904 | struct sock *sk; |
908 | 905 | ||
@@ -913,11 +910,15 @@ static void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
913 | ++*pos; | 910 | ++*pos; |
914 | return sk; | 911 | return sk; |
915 | } | 912 | } |
913 | EXPORT_SYMBOL_GPL(raw_seq_next); | ||
916 | 914 | ||
917 | static void raw_seq_stop(struct seq_file *seq, void *v) | 915 | void raw_seq_stop(struct seq_file *seq, void *v) |
918 | { | 916 | { |
919 | read_unlock(&raw_v4_hashinfo.lock); | 917 | struct raw_iter_state *state = raw_seq_private(seq); |
918 | |||
919 | read_unlock(&state->h->lock); | ||
920 | } | 920 | } |
921 | EXPORT_SYMBOL_GPL(raw_seq_stop); | ||
921 | 922 | ||
922 | static __inline__ char *get_raw_sock(struct sock *sp, char *tmpbuf, int i) | 923 | static __inline__ char *get_raw_sock(struct sock *sp, char *tmpbuf, int i) |
923 | { | 924 | { |
@@ -964,15 +965,30 @@ static const struct seq_operations raw_seq_ops = { | |||
964 | .show = raw_seq_show, | 965 | .show = raw_seq_show, |
965 | }; | 966 | }; |
966 | 967 | ||
967 | static int raw_seq_open(struct inode *inode, struct file *file) | 968 | int raw_seq_open(struct file *file, struct raw_hashinfo *h, |
969 | unsigned short family) | ||
968 | { | 970 | { |
969 | return seq_open_private(file, &raw_seq_ops, | 971 | struct raw_iter_state *i; |
972 | |||
973 | i = __seq_open_private(file, &raw_seq_ops, | ||
970 | sizeof(struct raw_iter_state)); | 974 | sizeof(struct raw_iter_state)); |
975 | if (i == NULL) | ||
976 | return -ENOMEM; | ||
977 | |||
978 | i->h = h; | ||
979 | i->family = family; | ||
980 | return 0; | ||
981 | } | ||
982 | EXPORT_SYMBOL_GPL(raw_seq_open); | ||
983 | |||
984 | static int raw_v4_seq_open(struct inode *inode, struct file *file) | ||
985 | { | ||
986 | return raw_seq_open(file, &raw_v4_hashinfo, PF_INET); | ||
971 | } | 987 | } |
972 | 988 | ||
973 | static const struct file_operations raw_seq_fops = { | 989 | static const struct file_operations raw_seq_fops = { |
974 | .owner = THIS_MODULE, | 990 | .owner = THIS_MODULE, |
975 | .open = raw_seq_open, | 991 | .open = raw_v4_seq_open, |
976 | .read = seq_read, | 992 | .read = seq_read, |
977 | .llseek = seq_lseek, | 993 | .llseek = seq_lseek, |
978 | .release = seq_release_private, | 994 | .release = seq_release_private, |