Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Thu, 14 Nov 2002 11:59:41 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Thu, 14 Nov 2002 11:59:40 -0500 Received: from orion.netbank.com.br ([200.203.199.90]:48134 "EHLO orion.netbank.com.br") by vger.kernel.org with ESMTP id ; Thu, 14 Nov 2002 11:59:23 -0500 Date: Thu, 14 Nov 2002 13:07:23 -0200 From: Arnaldo Carvalho de Melo To: "David S. Miller" Cc: Linux Kernel Mailing List Subject: [PATCH] ipv4: convert /proc/net/raw to seq_file Message-ID: <20021114150723.GC13379@conectiva.com.br> Mail-Followup-To: Arnaldo Carvalho de Melo , "David S. Miller" , Linux Kernel Mailing List Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-Url: http://advogato.org/person/acme Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 14465 Lines: 498 Hi David, Please pull from: master.kernel.org:/home/acme/BK/net-2.5 Now there are three outstanding changesets there. - Arnaldo You can import this changeset into BK by piping this whole message to: '| bk receive [path to repository]' or apply the patch as usual. =================================================================== ChangeSet@1.827, 2002-11-14 12:48:56-02:00, acme@conectiva.com.br o ipv4: convert /proc/net/raw to seq_file Also: . prototypes for _proc_init functions only needed in af_inet.c, and only if CONFIG_PROC_FS is set. . net/socket.c needs include . review raw.c needed includes include/linux/udp.h | 3 include/net/ip_fib.h | 3 include/net/udp.h | 2 net/ipv4/af_inet.c | 16 ++- net/ipv4/fib_hash.c | 12 -- net/ipv4/raw.c | 213 +++++++++++++++++++++++++++++++++++++-------------- net/ipv4/udp.c | 12 -- net/socket.c | 1 8 files changed, 166 insertions(+), 96 deletions(-) diff -Nru a/include/linux/udp.h b/include/linux/udp.h --- a/include/linux/udp.h Thu Nov 14 12:55:45 2002 +++ b/include/linux/udp.h Thu Nov 14 12:55:45 2002 @@ -57,7 +57,4 @@ #define udp_sk(__sk) (&((struct udp_sock *)__sk)->udp) -extern int udp_proc_init(void); -extern void udp_proc_exit(void); - #endif /* _LINUX_UDP_H */ diff -Nru a/include/net/ip_fib.h b/include/net/ip_fib.h --- a/include/net/ip_fib.h Thu Nov 14 12:55:45 2002 +++ b/include/net/ip_fib.h Thu Nov 14 12:55:45 2002 @@ -276,7 +276,4 @@ #endif } -extern int fib_proc_init(void); -extern void fib_proc_exit(void); - #endif /* _NET_FIB_H */ diff -Nru a/include/net/udp.h b/include/net/udp.h --- a/include/net/udp.h Thu Nov 14 12:55:45 2002 +++ b/include/net/udp.h Thu Nov 14 12:55:45 2002 @@ -76,6 +76,4 @@ #define UDP_INC_STATS_BH(field) SNMP_INC_STATS_BH(udp_statistics, field) #define UDP_INC_STATS_USER(field) SNMP_INC_STATS_USER(udp_statistics, field) -extern int udp_proc_init(void); - #endif /* _UDP_H */ diff -Nru a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c --- a/net/ipv4/af_inet.c Thu Nov 14 12:55:45 2002 +++ b/net/ipv4/af_inet.c Thu Nov 14 12:55:45 2002 @@ -1160,16 +1160,20 @@ /* ------------------------------------------------------------------------ */ #ifdef CONFIG_PROC_FS - -extern int ip_misc_proc_init(void); -extern int raw_get_info(char *, char **, off_t, int); -extern int tcp_get_info(char *, char **, off_t, int); +extern int fib_proc_init(void); +extern void fib_proc_exit(void); +extern int ip_misc_proc_init(void); +extern int raw_proc_init(void); +extern void raw_proc_exit(void); +extern int tcp_get_info(char *buffer, char **start, off_t offset, int length); +extern int udp_proc_init(void); +extern void udp_proc_exit(void); int __init ipv4_proc_init(void) { int rc = 0; - if (!proc_net_create("raw", 0, raw_get_info)) + if (raw_proc_init()) goto out_raw; if (!proc_net_create("tcp", 0, tcp_get_info)) goto out_tcp; @@ -1188,7 +1192,7 @@ out_udp: proc_net_remove("tcp"); out_tcp: - proc_net_remove("raw"); + raw_proc_exit(); out_raw: rc = -ENOMEM; goto out; diff -Nru a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c --- a/net/ipv4/fib_hash.c Thu Nov 14 12:55:45 2002 +++ b/net/ipv4/fib_hash.c Thu Nov 14 12:55:45 2002 @@ -1092,16 +1092,4 @@ { remove_proc_entry("route", proc_net); } - -#else /* CONFIG_PROC_FS */ - -int __init fib_proc_init(void) -{ - return 0; -} - -void __init fib_proc_exit(void) -{ - return 0; -} #endif /* CONFIG_PROC_FS */ diff -Nru a/net/ipv4/raw.c b/net/ipv4/raw.c --- a/net/ipv4/raw.c Thu Nov 14 12:55:45 2002 +++ b/net/ipv4/raw.c Thu Nov 14 12:55:45 2002 @@ -40,31 +40,42 @@ */ #include -#include +#include +#include +#include #include #include #include -#include +#include +#include #include -#include -#include +#include #include -#include +#include +#include #include #include -#include #include -#include -#include -#include +#include +#include +#include #include +#include #include +#include +#include +#include #include #include #include +#include #include #include #include +#include +#include +#include +#include #include struct sock *raw_v4_htable[RAWV4_HTABLE_SIZE]; @@ -656,7 +667,95 @@ } } -static void get_raw_sock(struct sock *sp, char *tmpbuf, int i) +struct proto raw_prot = { + .name = "RAW", + .close = raw_close, + .connect = udp_connect, + .disconnect = udp_disconnect, + .ioctl = raw_ioctl, + .init = raw_init, + .setsockopt = raw_setsockopt, + .getsockopt = raw_getsockopt, + .sendmsg = raw_sendmsg, + .recvmsg = raw_recvmsg, + .bind = raw_bind, + .backlog_rcv = raw_rcv_skb, + .hash = raw_v4_hash, + .unhash = raw_v4_unhash, +}; + +#ifdef CONFIG_PROC_FS +struct raw_iter_state { + int bucket; +}; + +#define raw_seq_private(seq) ((struct raw_iter_state *)&seq->private) + +static struct sock *raw_get_first(struct seq_file *seq) +{ + struct sock *sk = NULL; + struct raw_iter_state* state = raw_seq_private(seq); + + for (state->bucket = 0; state->bucket < RAWV4_HTABLE_SIZE; ++state->bucket) { + sk = raw_v4_htable[state->bucket]; + while (sk && sk->family != PF_INET) + sk = sk->next; + if (sk) + break; + } + return sk; +} + +static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk) +{ + struct raw_iter_state* state = raw_seq_private(seq); + + do { + sk = sk->next; +try_again: + } while (sk && sk->family != PF_INET); + + if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) { + sk = raw_v4_htable[state->bucket]; + goto try_again; + } + return sk; +} + +static struct sock *raw_get_idx(struct seq_file *seq, loff_t pos) +{ + struct sock *sk = raw_get_first(seq); + + if (sk) + while (pos && (sk = raw_get_next(seq, sk)) != NULL) + --pos; + return pos ? NULL : sk; +} + +static void *raw_seq_start(struct seq_file *seq, loff_t *pos) +{ + read_lock(&raw_v4_lock); + return *pos ? raw_get_idx(seq, *pos) : (void *)1; +} + +static void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos) +{ + struct sock *sk; + + if (v == (void *)1) + sk = raw_get_first(seq); + else + sk = raw_get_next(seq, v); + ++*pos; + return sk; +} + +static void raw_seq_stop(struct seq_file *seq, void *v) +{ + read_unlock(&raw_v4_lock); +} + +static __inline__ char *get_raw_sock(struct sock *sp, char *tmpbuf, int i) { struct inet_opt *inet = inet_sk(sp); unsigned int dest = inet->daddr, @@ -668,65 +767,63 @@ " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p", i, src, srcp, dest, destp, sp->state, atomic_read(&sp->wmem_alloc), atomic_read(&sp->rmem_alloc), - 0, 0L, 0, - sock_i_uid(sp), 0, - sock_i_ino(sp), + 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp), atomic_read(&sp->refcnt), sp); + return tmpbuf; } -int raw_get_info(char *buffer, char **start, off_t offset, int length) +static int raw_seq_show(struct seq_file *seq, void *v) { - int len = 0, num = 0, i; - off_t pos = 128; - off_t begin; char tmpbuf[129]; - if (offset < 128) - len += sprintf(buffer, "%-127s\n", + if (v == (void *)1) + seq_printf(seq, "%-127s\n", " sl local_address rem_address st tx_queue " "rx_queue tr tm->when retrnsmt uid timeout " "inode"); - read_lock(&raw_v4_lock); - for (i = 0; i < RAWV4_HTABLE_SIZE; i++) { - struct sock *sk; + else { + struct raw_iter_state *state = raw_seq_private(seq); - for (sk = raw_v4_htable[i]; sk; sk = sk->next, num++) { - if (sk->family != PF_INET) - continue; - pos += 128; - if (pos <= offset) - continue; - get_raw_sock(sk, tmpbuf, i); - len += sprintf(buffer + len, "%-127s\n", tmpbuf); - if (len >= length) - goto out; - } + seq_printf(seq, "%-127s\n", + get_raw_sock(v, tmpbuf, state->bucket)); } -out: - read_unlock(&raw_v4_lock); - begin = len - (pos - offset); - *start = buffer + begin; - len -= begin; - if (len > length) - len = length; - if (len < 0) - len = 0; - return len; + return 0; } -struct proto raw_prot = { - .name = "RAW", - .close = raw_close, - .connect = udp_connect, - .disconnect = udp_disconnect, - .ioctl = raw_ioctl, - .init = raw_init, - .setsockopt = raw_setsockopt, - .getsockopt = raw_getsockopt, - .sendmsg = raw_sendmsg, - .recvmsg = raw_recvmsg, - .bind = raw_bind, - .backlog_rcv = raw_rcv_skb, - .hash = raw_v4_hash, - .unhash = raw_v4_unhash, +static struct seq_operations raw_seq_ops = { + .start = raw_seq_start, + .next = raw_seq_next, + .stop = raw_seq_stop, + .show = raw_seq_show, +}; + +static int raw_seq_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &raw_seq_ops); +} + +static struct file_operations raw_seq_fops = { + .open = raw_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, }; + +int __init raw_proc_init(void) +{ + struct proc_dir_entry *p; + int rc = 0; + + p = create_proc_entry("raw", S_IRUGO, proc_net); + if (p) + p->proc_fops = &raw_seq_fops; + else + rc = -ENOMEM; + return rc; +} + +void __init raw_proc_exit(void) +{ + remove_proc_entry("raw", proc_net); +} +#endif /* CONFIG_PROC_FS */ diff -Nru a/net/ipv4/udp.c b/net/ipv4/udp.c --- a/net/ipv4/udp.c Thu Nov 14 12:55:45 2002 +++ b/net/ipv4/udp.c Thu Nov 14 12:55:45 2002 @@ -1377,16 +1377,4 @@ { remove_proc_entry("udp", proc_net); } - -#else /* CONFIG_PROC_FS */ - -int __init udp_proc_init(void) -{ - return 0; -} - -void __init udp_proc_exit(void) -{ - return 0; -} #endif /* CONFIG_PROC_FS */ diff -Nru a/net/socket.c b/net/socket.c --- a/net/socket.c Thu Nov 14 12:55:45 2002 +++ b/net/socket.c Thu Nov 14 12:55:45 2002 @@ -66,6 +66,7 @@ #include #include #include +#include #include #include #include =================================================================== This BitKeeper patch contains the following changesets: 1.827 ## Wrapped with gzip_uu ## begin 664 bkpatch3671 M'XL(`'&YTST``^U:ZW/:2!+_C/Z*V:3.!83'C-ZRU[D\[&1=FTU2R>:NZFZO M5$(:&14@L9(@R1WYWZ][1H`D!!B7Z^Z+=PE(TST]_?A-=X^LI^1+QM/SEN?/ MN/*4_))D^7G+3V+NY]'2&_C);#!*@?`I28`P'"5\=&`I0/GJY M/R9+GF;G+3;0-B/Y]SD_;WVZ?OOEWM,@ M>^'EXVD2#_+4B[,9S\6:JPWK2J54A?\-9FG4,%?,I+JU\EG`F*6:3/E5>D8#@BPY@FZ/"-ADA(7I[I1'.4D7,2@?Q)G)(FGWTG,><`#$L7$"X&! MYP._1[PX$%0014@4DM>M^_/3AM?OF,XDR6#H?B(50G2SQ)SA1",M` MEC]=!)S\/(WBQ;?A6LO!^+F8D?)EQ+\2L*&8(9874S+E5Z+:#M.4CUMT*/T3 M_U,4ZE'E^9&(E!4O!\4QK)6I6Y:Q\FEHJ:87&H85CE3';P;`KB``ELYTW3;H MBC*'6D=5*:P7H5T$\\&XHH]NKTS**'P'OF,X(\Y]3BVF[5&G65A))Q,NU9-T MBN80P-&N6M1T=&-EF79H!Z%M:JH>C)P]^V2_P))JFJ$Q\TZ1PYTQ!!GNV,O& M]0#:*]UP8&^-0D<-+:[:7/.981@'`M@DKZ08LQQ#O[//).X;(@D6.B:U5H9& MF:?!N.79CL.L(RZKRRL#3%79W;`N+$09.\[25-!GQ:GCAY:IVQJHY(?.,6=M M19744:EE',?[1H;(`3OJ:*IF0T9DFL5UJGH:-SS'/J;.5E093Q;LG+NKL\F` M=954PV8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9"M87WMM6UT"]^`!#2[79DD0R@B-NETT%VX`P0F^GV8<;&Q`J?_ M55#)>=TD<;CJK@,H#FV'K>FNS0'-2#T.+3C-<9M@Y?(LNS9]V*EYL< MN_5K,C]LQM:EB[C)J27)+A0GJ*W<=8NS-BHG5L)Y5>OGZ_-X/IO#`5V>P",X M$YL6]AC0!F!_UVK1'J'OX%]/3'0C=Q$%[6S>*0]%<2*&<)8NSM'2<"GZ`F6* MID[^%,KB>ALOC).OQ[P`0K#3NC)M'5L\TS;@9U_X9,J)\U"&Y]%LP(@)94)R5R,0]@JXW!?-!(-00:=XG60`3'0"';%SZ:PR*CC M=X%YN7O64Y'0(VSI-.1C9FNP/MPY`<:V2WG@O>R\OP'$(5Y+..%YQ@EO1!QYGE%^(0(D@2RFKC1J.?+-LH87RQZ? MK?UO_W0N7D[9]S1#A.]>C]4TFY8?JVUTOA,(3WL%;<]?)9M>09/O-C(0Y*S_ M_F.<_$3M\=7&!WVXBY%HP-]ZD7N@#YJ9AN=59;TV+^#Z8^Y/LL7LTK3-D6=[ +NO)?6)Z$4NTK```` ` end - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/