nfsd: simplify fh_verify access checks
[safe/jmp/linux-2.6] / net / sctp / proc.c
index 1b5e5b1..d093cbf 100644 (file)
@@ -1,15 +1,15 @@
-/* SCTP kernel reference Implementation
+/* SCTP kernel implementation
  * Copyright (c) 2003 International Business Machines, Corp.
  *
- * This file is part of the SCTP kernel reference Implementation
+ * This file is part of the SCTP kernel implementation
  *
- * The SCTP reference implementation is free software;
+ * This SCTP implementation is free software;
  * you can redistribute it and/or modify it under the terms of
  * the GNU General Public License as published by
  * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
  *
- * The SCTP reference implementation is distributed in the hope that it
+ * This SCTP implementation is distributed in the hope that it
  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  *                 ************************
  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@@ -38,6 +38,7 @@
 #include <linux/seq_file.h>
 #include <linux/init.h>
 #include <net/sctp/sctp.h>
+#include <net/ip.h> /* for snmp_fold_field */
 
 static struct snmp_mib sctp_snmp_list[] = {
        SNMP_MIB_ITEM("SctpCurrEstab", SCTP_MIB_CURRESTAB),
@@ -57,29 +58,24 @@ static struct snmp_mib sctp_snmp_list[] = {
        SNMP_MIB_ITEM("SctpReasmUsrMsgs", SCTP_MIB_REASMUSRMSGS),
        SNMP_MIB_ITEM("SctpOutSCTPPacks", SCTP_MIB_OUTSCTPPACKS),
        SNMP_MIB_ITEM("SctpInSCTPPacks", SCTP_MIB_INSCTPPACKS),
+       SNMP_MIB_ITEM("SctpT1InitExpireds", SCTP_MIB_T1_INIT_EXPIREDS),
+       SNMP_MIB_ITEM("SctpT1CookieExpireds", SCTP_MIB_T1_COOKIE_EXPIREDS),
+       SNMP_MIB_ITEM("SctpT2ShutdownExpireds", SCTP_MIB_T2_SHUTDOWN_EXPIREDS),
+       SNMP_MIB_ITEM("SctpT3RtxExpireds", SCTP_MIB_T3_RTX_EXPIREDS),
+       SNMP_MIB_ITEM("SctpT4RtoExpireds", SCTP_MIB_T4_RTO_EXPIREDS),
+       SNMP_MIB_ITEM("SctpT5ShutdownGuardExpireds", SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS),
+       SNMP_MIB_ITEM("SctpDelaySackExpireds", SCTP_MIB_DELAY_SACK_EXPIREDS),
+       SNMP_MIB_ITEM("SctpAutocloseExpireds", SCTP_MIB_AUTOCLOSE_EXPIREDS),
+       SNMP_MIB_ITEM("SctpT3Retransmits", SCTP_MIB_T3_RETRANSMITS),
+       SNMP_MIB_ITEM("SctpPmtudRetransmits", SCTP_MIB_PMTUD_RETRANSMITS),
+       SNMP_MIB_ITEM("SctpFastRetransmits", SCTP_MIB_FAST_RETRANSMITS),
+       SNMP_MIB_ITEM("SctpInPktSoftirq", SCTP_MIB_IN_PKT_SOFTIRQ),
+       SNMP_MIB_ITEM("SctpInPktBacklog", SCTP_MIB_IN_PKT_BACKLOG),
+       SNMP_MIB_ITEM("SctpInPktDiscards", SCTP_MIB_IN_PKT_DISCARDS),
+       SNMP_MIB_ITEM("SctpInDataChunkDiscards", SCTP_MIB_IN_DATA_CHUNK_DISCARDS),
        SNMP_MIB_SENTINEL
 };
 
-/* Return the current value of a particular entry in the mib by adding its
- * per cpu counters.
- */ 
-static unsigned long
-fold_field(void *mib[], int nr)
-{
-       unsigned long res = 0;
-       int i;
-
-       for_each_cpu(i) {
-               res +=
-                   *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) +
-                                        sizeof (unsigned long) * nr));
-               res +=
-                   *((unsigned long *) (((void *) per_cpu_ptr(mib[1], i)) +
-                                        sizeof (unsigned long) * nr));
-       }
-       return res;
-}
-
 /* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
 static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
 {
@@ -87,7 +83,7 @@ static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
 
        for (i = 0; sctp_snmp_list[i].name != NULL; i++)
                seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
-                          fold_field((void **)sctp_statistics, 
+                          snmp_fold_field((void **)sctp_statistics,
                                      sctp_snmp_list[i].entry));
 
        return 0;
@@ -99,7 +95,7 @@ static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
        return single_open(file, sctp_snmp_seq_show, NULL);
 }
 
-static struct file_operations sctp_snmp_seq_fops = {
+static const struct file_operations sctp_snmp_seq_fops = {
        .owner   = THIS_MODULE,
        .open    = sctp_snmp_seq_open,
        .read    = seq_read,
@@ -112,12 +108,10 @@ int __init sctp_snmp_proc_init(void)
 {
        struct proc_dir_entry *p;
 
-       p = create_proc_entry("snmp", S_IRUGO, proc_net_sctp);
+       p = proc_create("snmp", S_IRUGO, proc_net_sctp, &sctp_snmp_seq_fops);
        if (!p)
                return -ENOMEM;
 
-       p->proc_fops = &sctp_snmp_seq_fops;
-
        return 0;
 }
 
@@ -130,7 +124,6 @@ void sctp_snmp_proc_exit(void)
 /* Dump local addresses of an association/endpoint. */
 static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
 {
-       struct list_head *pos;
        struct sctp_association *asoc;
        struct sctp_sockaddr_entry *laddr;
        struct sctp_transport *peer;
@@ -143,9 +136,8 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commo
            primary = &peer->saddr;
        }
 
-       list_for_each(pos, &epb->bind_addr.address_list) {
-               laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
-               addr = (union sctp_addr *)&laddr->a;
+       list_for_each_entry(laddr, &epb->bind_addr.address_list, list) {
+               addr = &laddr->a;
                af = sctp_get_af_specific(addr->sa.sa_family);
                if (primary && af->cmp_addr(addr, primary)) {
                        seq_printf(seq, "*");
@@ -157,15 +149,14 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commo
 /* Dump remote addresses of an association. */
 static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
 {
-       struct list_head *pos;
        struct sctp_transport *transport;
        union sctp_addr *addr, *primary;
        struct sctp_af *af;
 
-       primary = &(assoc->peer.primary_addr);
-       list_for_each(pos, &assoc->peer.transport_addr_list) {
-               transport = list_entry(pos, struct sctp_transport, transports);
-               addr = (union sctp_addr *)&transport->ipaddr;
+       primary = &assoc->peer.primary_addr;
+       list_for_each_entry(transport, &assoc->peer.transport_addr_list,
+                       transports) {
+               addr = &transport->ipaddr;
                af = sctp_get_af_specific(addr->sa.sa_family);
                if (af->cmp_addr(addr, primary)) {
                        seq_printf(seq, "*");
@@ -210,7 +201,8 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
        struct sctp_ep_common *epb;
        struct sctp_endpoint *ep;
        struct sock *sk;
-       int    hash = *(int *)v;
+       struct hlist_node *node;
+       int    hash = *(loff_t *)v;
 
        if (hash >= sctp_ep_hashsize)
                return -ENOMEM;
@@ -218,7 +210,7 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
        head = &sctp_ep_hashtable[hash];
        sctp_local_bh_disable();
        read_lock(&head->lock);
-       for (epb = head->chain; epb; epb = epb->next) {
+       sctp_for_each_hentry(epb, node, &head->chain) {
                ep = sctp_ep(epb);
                sk = epb->sk;
                seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
@@ -235,7 +227,7 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations sctp_eps_ops = {
+static const struct seq_operations sctp_eps_ops = {
        .start = sctp_eps_seq_start,
        .next  = sctp_eps_seq_next,
        .stop  = sctp_eps_seq_stop,
@@ -249,7 +241,7 @@ static int sctp_eps_seq_open(struct inode *inode, struct file *file)
        return seq_open(file, &sctp_eps_ops);
 }
 
-static struct file_operations sctp_eps_seq_fops = {
+static const struct file_operations sctp_eps_seq_fops = {
        .open    = sctp_eps_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
@@ -261,12 +253,10 @@ int __init sctp_eps_proc_init(void)
 {
        struct proc_dir_entry *p;
 
-       p = create_proc_entry("eps", S_IRUGO, proc_net_sctp);
+       p = proc_create("eps", S_IRUGO, proc_net_sctp, &sctp_eps_seq_fops);
        if (!p)
                return -ENOMEM;
 
-       p->proc_fops = &sctp_eps_seq_fops;
-
        return 0;
 }
 
@@ -286,8 +276,10 @@ static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
                *pos = 0;
 
        if (*pos == 0)
-               seq_printf(seq, " ASSOC     SOCK   STY SST ST HBKT ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
-                               "RPORT LADDRS <-> RADDRS\n");
+               seq_printf(seq, " ASSOC     SOCK   STY SST ST HBKT "
+                               "ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
+                               "RPORT LADDRS <-> RADDRS "
+                               "HBINT INS OUTS MAXRT T1X T2X RTXC\n");
 
        return (void *)pos;
 }
@@ -313,7 +305,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
        struct sctp_ep_common *epb;
        struct sctp_association *assoc;
        struct sock *sk;
-       int    hash = *(int *)v;
+       struct hlist_node *node;
+       int    hash = *(loff_t *)v;
 
        if (hash >= sctp_assoc_hashsize)
                return -ENOMEM;
@@ -321,23 +314,29 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
        head = &sctp_assoc_hashtable[hash];
        sctp_local_bh_disable();
        read_lock(&head->lock);
-       for (epb = head->chain; epb; epb = epb->next) {
+       sctp_for_each_hentry(epb, node, &head->chain) {
                assoc = sctp_assoc(epb);
                sk = epb->sk;
                seq_printf(seq,
-                          "%8p %8p %-3d %-3d %-2d %-4d %4d %8d %8d %7d %5lu %-5d %5d ",
+                          "%8p %8p %-3d %-3d %-2d %-4d "
+                          "%4d %8d %8d %7d %5lu %-5d %5d ",
                           assoc, sk, sctp_sk(sk)->type, sk->sk_state,
-                          assoc->state, hash, assoc->assoc_id,
-                          (sk->sk_rcvbuf - assoc->rwnd),
+                          assoc->state, hash,
+                          assoc->assoc_id,
                           assoc->sndbuf_used,
+                          atomic_read(&assoc->rmem_alloc),
                           sock_i_uid(sk), sock_i_ino(sk),
                           epb->bind_addr.port,
                           assoc->peer.port);
-
                seq_printf(seq, " ");
                sctp_seq_dump_local_addrs(seq, epb);
                seq_printf(seq, "<-> ");
                sctp_seq_dump_remote_addrs(seq, assoc);
+               seq_printf(seq, "\t%8lu %5d %5d %4d %4d %4d %8d ",
+                       assoc->hbinterval, assoc->c.sinit_max_instreams,
+                       assoc->c.sinit_num_ostreams, assoc->max_retrans,
+                       assoc->init_retries, assoc->shutdown_retries,
+                       assoc->rtx_data_chunks);
                seq_printf(seq, "\n");
        }
        read_unlock(&head->lock);
@@ -346,7 +345,7 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations sctp_assoc_ops = {
+static const struct seq_operations sctp_assoc_ops = {
        .start = sctp_assocs_seq_start,
        .next  = sctp_assocs_seq_next,
        .stop  = sctp_assocs_seq_stop,
@@ -359,7 +358,7 @@ static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
        return seq_open(file, &sctp_assoc_ops);
 }
 
-static struct file_operations sctp_assocs_seq_fops = {
+static const struct file_operations sctp_assocs_seq_fops = {
        .open    = sctp_assocs_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
@@ -371,12 +370,11 @@ int __init sctp_assocs_proc_init(void)
 {
        struct proc_dir_entry *p;
 
-       p = create_proc_entry("assocs", S_IRUGO, proc_net_sctp);
+       p = proc_create("assocs", S_IRUGO, proc_net_sctp,
+                       &sctp_assocs_seq_fops);
        if (!p)
                return -ENOMEM;
 
-       p->proc_fops = &sctp_assocs_seq_fops;
-
        return 0;
 }
 
@@ -385,3 +383,137 @@ void sctp_assocs_proc_exit(void)
 {
        remove_proc_entry("assocs", proc_net_sctp);
 }
+
+static void *sctp_remaddr_seq_start(struct seq_file *seq, loff_t *pos)
+{
+       if (*pos >= sctp_assoc_hashsize)
+               return NULL;
+
+       if (*pos < 0)
+               *pos = 0;
+
+       if (*pos == 0)
+               seq_printf(seq, "ADDR ASSOC_ID HB_ACT RTO MAX_PATH_RTX "
+                               "REM_ADDR_RTX  START\n");
+
+       return (void *)pos;
+}
+
+static void *sctp_remaddr_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+       if (++*pos >= sctp_assoc_hashsize)
+               return NULL;
+
+       return pos;
+}
+
+static void sctp_remaddr_seq_stop(struct seq_file *seq, void *v)
+{
+       return;
+}
+
+static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
+{
+       struct sctp_hashbucket *head;
+       struct sctp_ep_common *epb;
+       struct sctp_association *assoc;
+       struct hlist_node *node;
+       struct sctp_transport *tsp;
+       int    hash = *(loff_t *)v;
+
+       if (hash >= sctp_assoc_hashsize)
+               return -ENOMEM;
+
+       head = &sctp_assoc_hashtable[hash];
+       sctp_local_bh_disable();
+       read_lock(&head->lock);
+       sctp_for_each_hentry(epb, node, &head->chain) {
+               assoc = sctp_assoc(epb);
+               list_for_each_entry(tsp, &assoc->peer.transport_addr_list,
+                                       transports) {
+                       /*
+                        * The remote address (ADDR)
+                        */
+                       tsp->af_specific->seq_dump_addr(seq, &tsp->ipaddr);
+                       seq_printf(seq, " ");
+
+                       /*
+                        * The association ID (ASSOC_ID)
+                        */
+                       seq_printf(seq, "%d ", tsp->asoc->assoc_id);
+
+                       /*
+                        * If the Heartbeat is active (HB_ACT)
+                        * Note: 1 = Active, 0 = Inactive
+                        */
+                       seq_printf(seq, "%d ", timer_pending(&tsp->hb_timer));
+
+                       /*
+                        * Retransmit time out (RTO)
+                        */
+                       seq_printf(seq, "%lu ", tsp->rto);
+
+                       /*
+                        * Maximum path retransmit count (PATH_MAX_RTX)
+                        */
+                       seq_printf(seq, "%d ", tsp->pathmaxrxt);
+
+                       /*
+                        * remote address retransmit count (REM_ADDR_RTX)
+                        * Note: We don't have a way to tally this at the moment
+                        * so lets just leave it as zero for the moment
+                        */
+                       seq_printf(seq, "0 ");
+
+                       /*
+                        * remote address start time (START).  This is also not
+                        * currently implemented, but we can record it with a
+                        * jiffies marker in a subsequent patch
+                        */
+                       seq_printf(seq, "0");
+
+                       seq_printf(seq, "\n");
+               }
+       }
+
+       read_unlock(&head->lock);
+       sctp_local_bh_enable();
+
+       return 0;
+
+}
+
+static const struct seq_operations sctp_remaddr_ops = {
+       .start = sctp_remaddr_seq_start,
+       .next  = sctp_remaddr_seq_next,
+       .stop  = sctp_remaddr_seq_stop,
+       .show  = sctp_remaddr_seq_show,
+};
+
+/* Cleanup the proc fs entry for 'remaddr' object. */
+void sctp_remaddr_proc_exit(void)
+{
+       remove_proc_entry("remaddr", proc_net_sctp);
+}
+
+static int sctp_remaddr_seq_open(struct inode *inode, struct file *file)
+{
+       return seq_open(file, &sctp_remaddr_ops);
+}
+
+static const struct file_operations sctp_remaddr_seq_fops = {
+       .open = sctp_remaddr_seq_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = seq_release,
+};
+
+int __init sctp_remaddr_proc_init(void)
+{
+       struct proc_dir_entry *p;
+
+       p = proc_create("remaddr", S_IRUGO, proc_net_sctp, &sctp_remaddr_seq_fops);
+       if (!p)
+               return -ENOMEM;
+       return 0;
+}