mac80211: fix modprobe deadlock by not calling wep_init under rtnl_lock
[safe/jmp/linux-2.6] / net / ipv4 / proc.c
index 9dee70e..cf0cdee 100644 (file)
@@ -7,8 +7,6 @@
  *             PROC file system.  It is mainly used for debugging and
  *             statistics.
  *
- * Version:    $Id: proc.c,v 1.45 2001/05/16 16:45:35 davem Exp $
- *
  * Authors:    Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Gerald J. Heim, <heim@peanuts.informatik.uni-tuebingen.de>
  *             Fred Baumgarten, <dc6iq@insu1.etec.uni-karlsruhe.de>
 #include <net/tcp.h>
 #include <net/udp.h>
 #include <net/udplite.h>
+#include <linux/bottom_half.h>
 #include <linux/inetdevice.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <net/sock.h>
 #include <net/raw.h>
 
-static int fold_prot_inuse(struct proto *proto)
-{
-       int res = 0;
-       int cpu;
-
-       for_each_possible_cpu(cpu)
-               res += proto->stats[cpu].inuse;
-
-       return res;
-}
-
 /*
  *     Report socket allocation statistics [mea@utu.fi]
  */
 static int sockstat_seq_show(struct seq_file *seq, void *v)
 {
+       struct net *net = seq->private;
+       int orphans, sockets;
+
+       local_bh_disable();
+       orphans = percpu_counter_sum_positive(&tcp_orphan_count);
+       sockets = percpu_counter_sum_positive(&tcp_sockets_allocated);
+       local_bh_enable();
+
        socket_seq_show(seq);
        seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n",
-                  fold_prot_inuse(&tcp_prot), atomic_read(&tcp_orphan_count),
-                  tcp_death_row.tw_count, atomic_read(&tcp_sockets_allocated),
+                  sock_prot_inuse_get(net, &tcp_prot), orphans,
+                  tcp_death_row.tw_count, sockets,
                   atomic_read(&tcp_memory_allocated));
-       seq_printf(seq, "UDP: inuse %d\n", fold_prot_inuse(&udp_prot));
-       seq_printf(seq, "UDPLITE: inuse %d\n", fold_prot_inuse(&udplite_prot));
-       seq_printf(seq, "RAW: inuse %d\n", fold_prot_inuse(&raw_prot));
-       seq_printf(seq,  "FRAG: inuse %d memory %d\n", ip_frag_nqueues,
-                  atomic_read(&ip_frag_mem));
+       seq_printf(seq, "UDP: inuse %d mem %d\n",
+                  sock_prot_inuse_get(net, &udp_prot),
+                  atomic_read(&udp_memory_allocated));
+       seq_printf(seq, "UDPLITE: inuse %d\n",
+                  sock_prot_inuse_get(net, &udplite_prot));
+       seq_printf(seq, "RAW: inuse %d\n",
+                  sock_prot_inuse_get(net, &raw_prot));
+       seq_printf(seq,  "FRAG: inuse %d memory %d\n",
+                       ip_frag_nqueues(net), ip_frag_mem(net));
        return 0;
 }
 
 static int sockstat_seq_open(struct inode *inode, struct file *file)
 {
-       return single_open(file, sockstat_seq_show, NULL);
+       return single_open_net(inode, file, sockstat_seq_show);
 }
 
 static const struct file_operations sockstat_seq_fops = {
@@ -85,7 +85,7 @@ static const struct file_operations sockstat_seq_fops = {
        .open    = sockstat_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = single_release,
+       .release = single_release_net,
 };
 
 /* snmp items */
@@ -121,14 +121,6 @@ static const struct snmp_mib snmp4_ipextstats_list[] = {
        SNMP_MIB_SENTINEL
 };
 
-static const struct snmp_mib snmp4_icmp_list[] = {
-       SNMP_MIB_ITEM("InMsgs", ICMP_MIB_INMSGS),
-       SNMP_MIB_ITEM("InErrors", ICMP_MIB_INERRORS),
-       SNMP_MIB_ITEM("OutMsgs", ICMP_MIB_OUTMSGS),
-       SNMP_MIB_ITEM("OutErrors", ICMP_MIB_OUTERRORS),
-       SNMP_MIB_SENTINEL
-};
-
 static struct {
        char *name;
        int index;
@@ -144,7 +136,7 @@ static struct {
        { "TimestampReps", ICMP_TIMESTAMPREPLY },
        { "AddrMasks", ICMP_ADDRESS },
        { "AddrMaskReps", ICMP_ADDRESSREPLY },
-       { 0, 0 }
+       { NULL, 0 }
 };
 
 
@@ -246,45 +238,53 @@ static const struct snmp_mib snmp4_net_list[] = {
        SNMP_MIB_ITEM("TCPDSACKIgnoredOld", LINUX_MIB_TCPDSACKIGNOREDOLD),
        SNMP_MIB_ITEM("TCPDSACKIgnoredNoUndo", LINUX_MIB_TCPDSACKIGNOREDNOUNDO),
        SNMP_MIB_ITEM("TCPSpuriousRTOs", LINUX_MIB_TCPSPURIOUSRTOS),
+       SNMP_MIB_ITEM("TCPMD5NotFound", LINUX_MIB_TCPMD5NOTFOUND),
+       SNMP_MIB_ITEM("TCPMD5Unexpected", LINUX_MIB_TCPMD5UNEXPECTED),
+       SNMP_MIB_ITEM("TCPSackShifted", LINUX_MIB_SACKSHIFTED),
+       SNMP_MIB_ITEM("TCPSackMerged", LINUX_MIB_SACKMERGED),
+       SNMP_MIB_ITEM("TCPSackShiftFallback", LINUX_MIB_SACKSHIFTFALLBACK),
        SNMP_MIB_SENTINEL
 };
 
-static void icmpmsg_put(struct seq_file *seq)
+static void icmpmsg_put_line(struct seq_file *seq, unsigned long *vals,
+                            unsigned short *type, int count)
 {
-#define PERLINE        16
+       int j;
 
-       int j, i, count;
-       static int out[PERLINE];
-
-       count = 0;
-       for (i = 0; i < ICMPMSG_MIB_MAX; i++) {
-
-               if (snmp_fold_field((void **) icmpmsg_statistics, i))
-                       out[count++] = i;
-               if (count < PERLINE)
-                       continue;
-
-               seq_printf(seq, "\nIcmpMsg:");
-               for (j = 0; j < PERLINE; ++j)
-                       seq_printf(seq, " %sType%u", i & 0x100 ? "Out" : "In",
-                                       i & 0xff);
-               seq_printf(seq, "\nIcmpMsg: ");
-               for (j = 0; j < PERLINE; ++j)
-                       seq_printf(seq, " %lu",
-                               snmp_fold_field((void **) icmpmsg_statistics,
-                               out[j]));
-               seq_putc(seq, '\n');
-       }
        if (count) {
                seq_printf(seq, "\nIcmpMsg:");
                for (j = 0; j < count; ++j)
-                       seq_printf(seq, " %sType%u", out[j] & 0x100 ? "Out" :
-                               "In", out[j] & 0xff);
+                       seq_printf(seq, " %sType%u",
+                               type[j] & 0x100 ? "Out" : "In",
+                               type[j] & 0xff);
                seq_printf(seq, "\nIcmpMsg:");
                for (j = 0; j < count; ++j)
-                       seq_printf(seq, " %lu", snmp_fold_field((void **)
-                               icmpmsg_statistics, out[j]));
+                       seq_printf(seq, " %lu", vals[j]);
+       }
+}
+
+static void icmpmsg_put(struct seq_file *seq)
+{
+#define PERLINE        16
+
+       int i, count;
+       unsigned short type[PERLINE];
+       unsigned long vals[PERLINE], val;
+       struct net *net = seq->private;
+
+       count = 0;
+       for (i = 0; i < ICMPMSG_MIB_MAX; i++) {
+               val = snmp_fold_field((void **) net->mib.icmpmsg_statistics, i);
+               if (val) {
+                       type[count] = i;
+                       vals[count++] = val;
+               }
+               if (count == PERLINE) {
+                       icmpmsg_put_line(seq, vals, type, count);
+                       count = 0;
+               }
        }
+       icmpmsg_put_line(seq, vals, type, count);
 
 #undef PERLINE
 }
@@ -292,6 +292,7 @@ static void icmpmsg_put(struct seq_file *seq)
 static void icmp_put(struct seq_file *seq)
 {
        int i;
+       struct net *net = seq->private;
 
        seq_puts(seq, "\nIcmp: InMsgs InErrors");
        for (i=0; icmpmibmap[i].name != NULL; i++)
@@ -300,19 +301,19 @@ static void icmp_put(struct seq_file *seq)
        for (i=0; icmpmibmap[i].name != NULL; i++)
                seq_printf(seq, " Out%s", icmpmibmap[i].name);
        seq_printf(seq, "\nIcmp: %lu %lu",
-               snmp_fold_field((void **) icmp_statistics, ICMP_MIB_INMSGS),
-               snmp_fold_field((void **) icmp_statistics, ICMP_MIB_INERRORS));
+               snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_INMSGS),
+               snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_INERRORS));
        for (i=0; icmpmibmap[i].name != NULL; i++)
                seq_printf(seq, " %lu",
-                       snmp_fold_field((void **) icmpmsg_statistics,
+                       snmp_fold_field((void **) net->mib.icmpmsg_statistics,
                                icmpmibmap[i].index));
        seq_printf(seq, " %lu %lu",
-               snmp_fold_field((void **) icmp_statistics, ICMP_MIB_OUTMSGS),
-               snmp_fold_field((void **) icmp_statistics, ICMP_MIB_OUTERRORS));
+               snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_OUTMSGS),
+               snmp_fold_field((void **) net->mib.icmp_statistics, ICMP_MIB_OUTERRORS));
        for (i=0; icmpmibmap[i].name != NULL; i++)
                seq_printf(seq, " %lu",
-                       snmp_fold_field((void **) icmpmsg_statistics,
-                               icmpmibmap[i].index));
+                       snmp_fold_field((void **) net->mib.icmpmsg_statistics,
+                               icmpmibmap[i].index | 0x100));
 }
 
 /*
@@ -321,6 +322,7 @@ static void icmp_put(struct seq_file *seq)
 static int snmp_seq_show(struct seq_file *seq, void *v)
 {
        int i;
+       struct net *net = seq->private;
 
        seq_puts(seq, "Ip: Forwarding DefaultTTL");
 
@@ -328,11 +330,12 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
                seq_printf(seq, " %s", snmp4_ipstats_list[i].name);
 
        seq_printf(seq, "\nIp: %d %d",
-                  IPV4_DEVCONF_ALL(FORWARDING) ? 1 : 2, sysctl_ip_default_ttl);
+                  IPV4_DEVCONF_ALL(net, FORWARDING) ? 1 : 2,
+                  sysctl_ip_default_ttl);
 
        for (i = 0; snmp4_ipstats_list[i].name != NULL; i++)
                seq_printf(seq, " %lu",
-                          snmp_fold_field((void **)ip_statistics,
+                          snmp_fold_field((void **)net->mib.ip_statistics,
                                           snmp4_ipstats_list[i].entry));
 
        icmp_put(seq);  /* RFC 2011 compatibility */
@@ -347,11 +350,11 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
                /* MaxConn field is signed, RFC 2012 */
                if (snmp4_tcp_list[i].entry == TCP_MIB_MAXCONN)
                        seq_printf(seq, " %ld",
-                                  snmp_fold_field((void **)tcp_statistics,
+                                  snmp_fold_field((void **)net->mib.tcp_statistics,
                                                   snmp4_tcp_list[i].entry));
                else
                        seq_printf(seq, " %lu",
-                                  snmp_fold_field((void **)tcp_statistics,
+                                  snmp_fold_field((void **)net->mib.tcp_statistics,
                                                   snmp4_tcp_list[i].entry));
        }
 
@@ -362,7 +365,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
        seq_puts(seq, "\nUdp:");
        for (i = 0; snmp4_udp_list[i].name != NULL; i++)
                seq_printf(seq, " %lu",
-                          snmp_fold_field((void **)udp_statistics,
+                          snmp_fold_field((void **)net->mib.udp_statistics,
                                           snmp4_udp_list[i].entry));
 
        /* the UDP and UDP-Lite MIBs are the same */
@@ -373,7 +376,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
        seq_puts(seq, "\nUdpLite:");
        for (i = 0; snmp4_udp_list[i].name != NULL; i++)
                seq_printf(seq, " %lu",
-                          snmp_fold_field((void **)udplite_statistics,
+                          snmp_fold_field((void **)net->mib.udplite_statistics,
                                           snmp4_udp_list[i].entry));
 
        seq_putc(seq, '\n');
@@ -382,7 +385,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
 
 static int snmp_seq_open(struct inode *inode, struct file *file)
 {
-       return single_open(file, snmp_seq_show, NULL);
+       return single_open_net(inode, file, snmp_seq_show);
 }
 
 static const struct file_operations snmp_seq_fops = {
@@ -390,7 +393,7 @@ static const struct file_operations snmp_seq_fops = {
        .open    = snmp_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = single_release,
+       .release = single_release_net,
 };
 
 
@@ -401,6 +404,7 @@ static const struct file_operations snmp_seq_fops = {
 static int netstat_seq_show(struct seq_file *seq, void *v)
 {
        int i;
+       struct net *net = seq->private;
 
        seq_puts(seq, "TcpExt:");
        for (i = 0; snmp4_net_list[i].name != NULL; i++)
@@ -409,7 +413,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
        seq_puts(seq, "\nTcpExt:");
        for (i = 0; snmp4_net_list[i].name != NULL; i++)
                seq_printf(seq, " %lu",
-                          snmp_fold_field((void **)net_statistics,
+                          snmp_fold_field((void **)net->mib.net_statistics,
                                           snmp4_net_list[i].entry));
 
        seq_puts(seq, "\nIpExt:");
@@ -419,7 +423,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
        seq_puts(seq, "\nIpExt:");
        for (i = 0; snmp4_ipextstats_list[i].name != NULL; i++)
                seq_printf(seq, " %lu",
-                          snmp_fold_field((void **)ip_statistics,
+                          snmp_fold_field((void **)net->mib.ip_statistics,
                                           snmp4_ipextstats_list[i].entry));
 
        seq_putc(seq, '\n');
@@ -428,7 +432,7 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
 
 static int netstat_seq_open(struct inode *inode, struct file *file)
 {
-       return single_open(file, netstat_seq_show, NULL);
+       return single_open_net(inode, file, netstat_seq_show);
 }
 
 static const struct file_operations netstat_seq_fops = {
@@ -436,29 +440,42 @@ static const struct file_operations netstat_seq_fops = {
        .open    = netstat_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = single_release,
+       .release = single_release_net,
 };
 
-int __init ip_misc_proc_init(void)
+static __net_init int ip_proc_init_net(struct net *net)
 {
-       int rc = 0;
-
-       if (!proc_net_fops_create(&init_net, "netstat", S_IRUGO, &netstat_seq_fops))
+       if (!proc_net_fops_create(net, "sockstat", S_IRUGO, &sockstat_seq_fops))
+               goto out_sockstat;
+       if (!proc_net_fops_create(net, "netstat", S_IRUGO, &netstat_seq_fops))
                goto out_netstat;
-
-       if (!proc_net_fops_create(&init_net, "snmp", S_IRUGO, &snmp_seq_fops))
+       if (!proc_net_fops_create(net, "snmp", S_IRUGO, &snmp_seq_fops))
                goto out_snmp;
 
-       if (!proc_net_fops_create(&init_net, "sockstat", S_IRUGO, &sockstat_seq_fops))
-               goto out_sockstat;
-out:
-       return rc;
-out_sockstat:
-       proc_net_remove(&init_net, "snmp");
+       return 0;
+
 out_snmp:
-       proc_net_remove(&init_net, "netstat");
+       proc_net_remove(net, "netstat");
 out_netstat:
-       rc = -ENOMEM;
-       goto out;
+       proc_net_remove(net, "sockstat");
+out_sockstat:
+       return -ENOMEM;
+}
+
+static __net_exit void ip_proc_exit_net(struct net *net)
+{
+       proc_net_remove(net, "snmp");
+       proc_net_remove(net, "netstat");
+       proc_net_remove(net, "sockstat");
+}
+
+static __net_initdata struct pernet_operations ip_proc_ops = {
+       .init = ip_proc_init_net,
+       .exit = ip_proc_exit_net,
+};
+
+int __init ip_misc_proc_init(void)
+{
+       return register_pernet_subsys(&ip_proc_ops);
 }