2002-10-20 16:11:47

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: [PATCH] move /proc/net/udp support back to net/ipv4/udp.c

David,

Please pull from:

master.kernel.org:/home/acme/BK/net-2.5

Best regards,

- 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.

===================================================================


[email protected], 2002-10-20 13:15:42-03:00, [email protected]
o ipv4: move /proc/net/udp support back to net/ipv4/udp.c


include/net/udp.h | 2
net/ipv4/af_inet.c | 1
net/ipv4/ip_proc.c | 142 -----------------------------------------------
net/ipv4/udp.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 162 insertions(+), 143 deletions(-)


diff -Nru a/include/net/udp.h b/include/net/udp.h
--- a/include/net/udp.h Sun Oct 20 13:16:16 2002
+++ b/include/net/udp.h Sun Oct 20 13:16:16 2002
@@ -76,4 +76,6 @@
#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 Sun Oct 20 13:16:16 2002
+++ b/net/ipv4/af_inet.c Sun Oct 20 13:16:16 2002
@@ -1218,6 +1218,7 @@
#endif

ipv4_proc_init();
+ udp_proc_init();
fib_proc_init();
return 0;
}
diff -Nru a/net/ipv4/ip_proc.c b/net/ipv4/ip_proc.c
--- a/net/ipv4/ip_proc.c Sun Oct 20 13:16:16 2002
+++ b/net/ipv4/ip_proc.c Sun Oct 20 13:16:16 2002
@@ -18,9 +18,6 @@
#include <linux/netdevice.h>
#include <net/neighbour.h>
#include <net/arp.h>
-#include <net/udp.h>
-#include <linux/rtnetlink.h>
-#include <linux/route.h>
#include <linux/seq_file.h>
#include <linux/proc_fs.h>

@@ -249,101 +246,6 @@

/* ------------------------------------------------------------------------ */

-struct udp_iter_state {
- int bucket;
-};
-
-static __inline__ struct sock *udp_get_bucket(struct seq_file *seq, loff_t *pos)
-{
- int i;
- struct sock *sk = NULL;
- loff_t l = *pos;
- struct udp_iter_state *state = seq->private;
-
- for (; state->bucket < UDP_HTABLE_SIZE; ++state->bucket)
- for (i = 0, sk = udp_hash[state->bucket]; sk; ++i, sk = sk->next) {
- if (sk->family != PF_INET)
- continue;
- if (l--)
- continue;
- *pos = i;
- goto out;
- }
-out:
- return sk;
-}
-
-static void *udp_seq_start(struct seq_file *seq, loff_t *pos)
-{
- read_lock(&udp_hash_lock);
- return *pos ? udp_get_bucket(seq, pos) : (void *)1;
-}
-
-static void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
-{
- struct sock *sk;
- struct udp_iter_state *state;
-
- if (v == (void *)1) {
- sk = udp_get_bucket(seq, pos);
- goto out;
- }
-
- sk = v;
- sk = sk->next;
- if (sk)
- goto out;
-
- state = seq->private;
- if (++state->bucket >= UDP_HTABLE_SIZE)
- goto out;
-
- *pos = 0;
- sk = udp_get_bucket(seq, pos);
-out:
- ++*pos;
- return sk;
-}
-
-static void udp_seq_stop(struct seq_file *seq, void *v)
-{
- read_unlock(&udp_hash_lock);
-}
-
-static void udp_format_sock(struct sock *sp, char *tmpbuf, int bucket)
-{
- struct inet_opt *inet = inet_sk(sp);
- unsigned int dest = inet->daddr;
- unsigned int src = inet->rcv_saddr;
- __u16 destp = ntohs(inet->dport);
- __u16 srcp = ntohs(inet->sport);
-
- sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
- " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
- bucket, 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),
- atomic_read(&sp->refcnt), sp);
-}
-
-static int udp_seq_show(struct seq_file *seq, void *v)
-{
- 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");
- else {
- char tmpbuf[129];
- struct udp_iter_state *state = seq->private;
-
- udp_format_sock(v, tmpbuf, state->bucket);
- seq_printf(seq, "%-127s\n", tmpbuf);
- }
- return 0;
-}
-/* ------------------------------------------------------------------------ */
-
static struct seq_operations arp_seq_ops = {
.start = arp_seq_start,
.next = arp_seq_next,
@@ -351,13 +253,6 @@
.show = arp_seq_show,
};

-static struct seq_operations udp_seq_ops = {
- .start = udp_seq_start,
- .next = udp_seq_next,
- .stop = udp_seq_stop,
- .show = udp_seq_show,
-};
-
static int arp_seq_open(struct inode *inode, struct file *file)
{
struct seq_file *seq;
@@ -391,29 +286,6 @@
return seq_release(inode, file);
}

-static int udp_seq_open(struct inode *inode, struct file *file)
-{
- struct seq_file *seq;
- int rc = -ENOMEM;
- struct udp_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
-
- if (!s)
- goto out;
-
- rc = seq_open(file, &udp_seq_ops);
- if (rc)
- goto out_kfree;
-
- seq = file->private_data;
- seq->private = s;
- memset(s, 0, sizeof(*s));
-out:
- return rc;
-out_kfree:
- kfree(s);
- goto out;
-}
-
static struct file_operations arp_seq_fops = {
.open = arp_seq_open,
.read = seq_read,
@@ -421,13 +293,6 @@
.release = ip_seq_release,
};

-static struct file_operations udp_seq_fops = {
- .open = udp_seq_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = ip_seq_release,
-};
-
/* ------------------------------------------------------------------------ */

int __init ipv4_proc_init(void)
@@ -450,11 +315,6 @@
if (!proc_net_create("tcp", 0, tcp_get_info))
goto out_tcp;

- p = create_proc_entry("udp", S_IRUGO, proc_net);
- if (!p)
- goto out_udp;
- p->proc_fops = &udp_seq_fops;
-
p = create_proc_entry("arp", S_IRUGO, proc_net);
if (!p)
goto out_arp;
@@ -463,8 +323,6 @@
out:
return rc;
out_arp:
- remove_proc_entry("udp", proc_net);
-out_udp:
proc_net_remove("tcp");
out_tcp:
proc_net_remove("sockstat");
diff -Nru a/net/ipv4/udp.c b/net/ipv4/udp.c
--- a/net/ipv4/udp.c Sun Oct 20 13:16:16 2002
+++ b/net/ipv4/udp.c Sun Oct 20 13:16:16 2002
@@ -62,10 +62,10 @@
* return ENOTCONN for unconnected sockets (POSIX)
* Janos Farkas : don't deliver multi/broadcasts to a different
* bound-to-device socket
- * Arnaldo C. Melo : move proc routines to ip_proc.c.
* Hirokazu Takahashi : HW checksumming for outgoing UDP
* datagrams.
* Hirokazu Takahashi : sendfile() on UDP works now.
+ * Arnaldo C. Melo : convert /proc/net/udp to seq_file
*
*
* This program is free software; you can redistribute it and/or
@@ -92,6 +92,8 @@
#include <net/tcp.h>
#include <net/protocol.h>
#include <linux/skbuff.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
#include <net/sock.h>
#include <net/udp.h>
#include <net/icmp.h>
@@ -1208,3 +1210,159 @@
.unhash = udp_v4_unhash,
.get_port = udp_v4_get_port,
};
+
+/* ------------------------------------------------------------------------ */
+#ifdef CONFIG_PROC_FS
+
+struct udp_iter_state {
+ int bucket;
+};
+
+static __inline__ struct sock *udp_get_bucket(struct seq_file *seq, loff_t *pos)
+{
+ int i;
+ struct sock *sk = NULL;
+ loff_t l = *pos;
+ struct udp_iter_state *state = seq->private;
+
+ for (; state->bucket < UDP_HTABLE_SIZE; ++state->bucket)
+ for (i = 0, sk = udp_hash[state->bucket]; sk; ++i, sk = sk->next) {
+ if (sk->family != PF_INET)
+ continue;
+ if (l--)
+ continue;
+ *pos = i;
+ goto out;
+ }
+out:
+ return sk;
+}
+
+static void *udp_seq_start(struct seq_file *seq, loff_t *pos)
+{
+ read_lock(&udp_hash_lock);
+ return *pos ? udp_get_bucket(seq, pos) : (void *)1;
+}
+
+static void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+ struct sock *sk;
+ struct udp_iter_state *state;
+
+ if (v == (void *)1) {
+ sk = udp_get_bucket(seq, pos);
+ goto out;
+ }
+
+ sk = v;
+ sk = sk->next;
+ if (sk)
+ goto out;
+
+ state = seq->private;
+ if (++state->bucket >= UDP_HTABLE_SIZE)
+ goto out;
+
+ *pos = 0;
+ sk = udp_get_bucket(seq, pos);
+out:
+ ++*pos;
+ return sk;
+}
+
+static void udp_seq_stop(struct seq_file *seq, void *v)
+{
+ read_unlock(&udp_hash_lock);
+}
+
+static void udp_format_sock(struct sock *sp, char *tmpbuf, int bucket)
+{
+ struct inet_opt *inet = inet_sk(sp);
+ unsigned int dest = inet->daddr;
+ unsigned int src = inet->rcv_saddr;
+ __u16 destp = ntohs(inet->dport);
+ __u16 srcp = ntohs(inet->sport);
+
+ sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
+ " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
+ bucket, 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),
+ atomic_read(&sp->refcnt), sp);
+}
+
+static int udp_seq_show(struct seq_file *seq, void *v)
+{
+ 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");
+ else {
+ char tmpbuf[129];
+ struct udp_iter_state *state = seq->private;
+
+ udp_format_sock(v, tmpbuf, state->bucket);
+ seq_printf(seq, "%-127s\n", tmpbuf);
+ }
+ return 0;
+}
+/* ------------------------------------------------------------------------ */
+
+static struct seq_operations udp_seq_ops = {
+ .start = udp_seq_start,
+ .next = udp_seq_next,
+ .stop = udp_seq_stop,
+ .show = udp_seq_show,
+};
+
+static int udp_seq_open(struct inode *inode, struct file *file)
+{
+ struct seq_file *seq;
+ int rc = -ENOMEM;
+ struct udp_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
+
+ if (!s)
+ goto out;
+
+ rc = seq_open(file, &udp_seq_ops);
+ if (rc)
+ goto out_kfree;
+
+ seq = file->private_data;
+ seq->private = s;
+ memset(s, 0, sizeof(*s));
+out:
+ return rc;
+out_kfree:
+ kfree(s);
+ goto out;
+}
+
+static struct file_operations udp_seq_fops = {
+ .open = udp_seq_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = ip_seq_release,
+};
+
+/* ------------------------------------------------------------------------ */
+
+int __init udp_proc_init(void)
+{
+ struct proc_dir_entry *p;
+ int rc = 0;
+
+ p = create_proc_entry("udp", S_IRUGO, proc_net);
+ if (p)
+ p->proc_fops = &udp_seq_fops;
+ else
+ rc = -ENOMEM;
+ return rc;
+}
+#else /* CONFIG_PROC_FS */
+int __init udp_proc_init(void)
+{
+ return 0;
+}
+#endif /* CONFIG_PROC_FS */

===================================================================


This BitKeeper patch contains the following changesets:
1.810
## Wrapped with gzip_uu ##


begin 664 bkpatch16608
M'XL(`-#6LCT``\U9;7/:1A#^+/V*C3W.@`U8IS<$%#>)[:2>.+;'J6<R?1F-
M+!U!`TBJ=)"DQ?^]NR?Q(L`F>/(AI!'2[<OM[O/<KDCWX2[C:5OQ_!%7]^&W
M.!-MQ8\C[HMPXC7\>-2X3U%P&\<H..['(W[\YOUQQ$5=;U@J2FX\X?=APM.L
MK;"&,5\1WQ+>5F[/W]U=OKY5U6X73OM>])E_Y`*Z757$Z<0;!MDK3_2'<=00
MJ1=E(R[DGM.YZE37-!W_6*QI:)8]9;9F-J<^"QCS3,8#33<=VU0I_%>K8:]X
M8>A&LS6#M::ZX>B6>@:LX3`--/V8:<>Z!LQH,ZMMZG7-:&L:;'0*1R;4-?4-
M_-@$3E4?8@B3B=F&43SA<)RDL4]U/AX'"63C)(E3`?>>/\"=@=9)F80-7WT/
MF!%CZLVBQFI]QX^J:IZFGFS)*XS\X3C@L\`:_>7\6J8SM36FX37P6U;KGG.?
M:TUF;"[E(\X()V8SRT`W)G-,C&FS^;P(8>)2M1I^8<\8LRW+,*::UL22^X[N
M.(;5<W3#-NYU:U=WBW`8IKBU1&5L2O6QG*FA6X8VY5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%&4=PFB1D+,2`AD^JV25_GE<M6+/H9:*\1>`OI!W9>]#NM3_JE!
H66[/<;D'[?,HP+@V>IK_OQ6_S_U!-AYUF68YGNGIZO\-\`\,R!D`````
`
end


2002-10-20 22:56:49

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] move /proc/net/udp support back to net/ipv4/udp.c

From: Arnaldo Carvalho de Melo <[email protected]>
Date: Sun, 20 Oct 2002 13:17:38 -0300

Please pull from:

master.kernel.org:/home/acme/BK/net-2.5

Pulled, thanks.