Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / net / sctp / proc.c
index 633569b..5b3b0e0 100644 (file)
 #include <linux/init.h>
 #include <net/sctp/sctp.h>
 
-static char *sctp_snmp_list[] = {
-#define SCTP_SNMP_ENTRY(x) #x 
-       SCTP_SNMP_ENTRY(SctpCurrEstab),
-       SCTP_SNMP_ENTRY(SctpActiveEstabs),
-       SCTP_SNMP_ENTRY(SctpPassiveEstabs),
-       SCTP_SNMP_ENTRY(SctpAborteds),
-       SCTP_SNMP_ENTRY(SctpShutdowns),
-       SCTP_SNMP_ENTRY(SctpOutOfBlues),
-       SCTP_SNMP_ENTRY(SctpChecksumErrors),
-       SCTP_SNMP_ENTRY(SctpOutCtrlChunks),
-       SCTP_SNMP_ENTRY(SctpOutOrderChunks),
-       SCTP_SNMP_ENTRY(SctpOutUnorderChunks),
-       SCTP_SNMP_ENTRY(SctpInCtrlChunks),
-       SCTP_SNMP_ENTRY(SctpInOrderChunks),
-       SCTP_SNMP_ENTRY(SctpInUnorderChunks),
-       SCTP_SNMP_ENTRY(SctpFragUsrMsgs),
-       SCTP_SNMP_ENTRY(SctpReasmUsrMsgs),
-       SCTP_SNMP_ENTRY(SctpOutSCTPPacks),
-       SCTP_SNMP_ENTRY(SctpInSCTPPacks),
-#undef SCTP_SNMP_ENTRY
+static struct snmp_mib sctp_snmp_list[] = {
+       SNMP_MIB_ITEM("SctpCurrEstab", SCTP_MIB_CURRESTAB),
+       SNMP_MIB_ITEM("SctpActiveEstabs", SCTP_MIB_ACTIVEESTABS),
+       SNMP_MIB_ITEM("SctpPassiveEstabs", SCTP_MIB_PASSIVEESTABS),
+       SNMP_MIB_ITEM("SctpAborteds", SCTP_MIB_ABORTEDS),
+       SNMP_MIB_ITEM("SctpShutdowns", SCTP_MIB_SHUTDOWNS),
+       SNMP_MIB_ITEM("SctpOutOfBlues", SCTP_MIB_OUTOFBLUES),
+       SNMP_MIB_ITEM("SctpChecksumErrors", SCTP_MIB_CHECKSUMERRORS),
+       SNMP_MIB_ITEM("SctpOutCtrlChunks", SCTP_MIB_OUTCTRLCHUNKS),
+       SNMP_MIB_ITEM("SctpOutOrderChunks", SCTP_MIB_OUTORDERCHUNKS),
+       SNMP_MIB_ITEM("SctpOutUnorderChunks", SCTP_MIB_OUTUNORDERCHUNKS),
+       SNMP_MIB_ITEM("SctpInCtrlChunks", SCTP_MIB_INCTRLCHUNKS),
+       SNMP_MIB_ITEM("SctpInOrderChunks", SCTP_MIB_INORDERCHUNKS),
+       SNMP_MIB_ITEM("SctpInUnorderChunks", SCTP_MIB_INUNORDERCHUNKS),
+       SNMP_MIB_ITEM("SctpFragUsrMsgs", SCTP_MIB_FRAGUSRMSGS),
+       SNMP_MIB_ITEM("SctpReasmUsrMsgs", SCTP_MIB_REASMUSRMSGS),
+       SNMP_MIB_ITEM("SctpOutSCTPPacks", SCTP_MIB_OUTSCTPPACKS),
+       SNMP_MIB_ITEM("SctpInSCTPPacks", SCTP_MIB_INSCTPPACKS),
+       SNMP_MIB_SENTINEL
 };
 
 /* Return the current value of a particular entry in the mib by adding its
@@ -70,9 +69,7 @@ fold_field(void *mib[], int nr)
        unsigned long res = 0;
        int i;
 
-       for (i = 0; i < NR_CPUS; i++) {
-               if (!cpu_possible(i))
-                       continue;
+       for_each_possible_cpu(i) {
                res +=
                    *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) +
                                         sizeof (unsigned long) * nr));
@@ -88,9 +85,10 @@ static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
 {
        int i;
 
-       for (i = 0; i < sizeof(sctp_snmp_list) / sizeof(char *); i++)
-               seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i],
-                          fold_field((void **)sctp_statistics, i));
+       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, 
+                                     sctp_snmp_list[i].entry));
 
        return 0;
 }
@@ -133,14 +131,25 @@ void sctp_snmp_proc_exit(void)
 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;
-       union sctp_addr *addr;
+       struct sctp_transport *peer;
+       union sctp_addr *addr, *primary = NULL;
        struct sctp_af *af;
 
+       if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
+           asoc = sctp_assoc(epb);
+           peer = asoc->peer.primary_path;
+           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;
                af = sctp_get_af_specific(addr->sa.sa_family);
+               if (primary && af->cmp_addr(addr, primary)) {
+                       seq_printf(seq, "*");
+               }
                af->seq_dump_addr(seq, addr);
        }
 }
@@ -150,17 +159,50 @@ static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_associa
 {
        struct list_head *pos;
        struct sctp_transport *transport;
-       union sctp_addr *addr;
+       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;
                af = sctp_get_af_specific(addr->sa.sa_family);
+               if (af->cmp_addr(addr, primary)) {
+                       seq_printf(seq, "*");
+               }
                af->seq_dump_addr(seq, addr);
        }
 }
 
+static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
+{
+       if (*pos >= sctp_ep_hashsize)
+               return NULL;
+
+       if (*pos < 0)
+               *pos = 0;
+
+       if (*pos == 0)
+               seq_printf(seq, " ENDPT     SOCK   STY SST HBKT LPORT   UID INODE LADDRS\n");
+
+       return (void *)pos;
+}
+
+static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
+{
+       return;
+}
+
+
+static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+       if (++*pos >= sctp_ep_hashsize)
+               return NULL;
+
+       return pos;
+}
+
+
 /* Display sctp endpoints (/proc/net/sctp/eps). */
 static int sctp_eps_seq_show(struct seq_file *seq, void *v)
 {
@@ -168,38 +210,50 @@ 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;
-
-       seq_printf(seq, " ENDPT     SOCK   STY SST HBKT LPORT LADDRS\n");
-       for (hash = 0; hash < sctp_ep_hashsize; hash++) {
-               head = &sctp_ep_hashtable[hash];
-               read_lock(&head->lock);
-               for (epb = head->chain; epb; epb = epb->next) {
-                       ep = sctp_ep(epb);
-                       sk = epb->sk;
-                       seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d ", ep, sk,
-                                  sctp_sk(sk)->type, sk->sk_state, hash,
-                                  epb->bind_addr.port);
-                       sctp_seq_dump_local_addrs(seq, epb);
-                       seq_printf(seq, "\n");
-               }
-               read_unlock(&head->lock);
+       int    hash = *(loff_t *)v;
+
+       if (hash >= sctp_ep_hashsize)
+               return -ENOMEM;
+
+       head = &sctp_ep_hashtable[hash];
+       sctp_local_bh_disable();
+       read_lock(&head->lock);
+       for (epb = head->chain; epb; epb = epb->next) {
+               ep = sctp_ep(epb);
+               sk = epb->sk;
+               seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
+                          sctp_sk(sk)->type, sk->sk_state, hash,
+                          epb->bind_addr.port,
+                          sock_i_uid(sk), sock_i_ino(sk));
+
+               sctp_seq_dump_local_addrs(seq, epb);
+               seq_printf(seq, "\n");
        }
+       read_unlock(&head->lock);
+       sctp_local_bh_enable();
 
        return 0;
 }
 
+static struct seq_operations sctp_eps_ops = {
+       .start = sctp_eps_seq_start,
+       .next  = sctp_eps_seq_next,
+       .stop  = sctp_eps_seq_stop,
+       .show  = sctp_eps_seq_show,
+};
+
+
 /* Initialize the seq file operations for 'eps' object. */
 static int sctp_eps_seq_open(struct inode *inode, struct file *file)
 {
-       return single_open(file, sctp_eps_seq_show, NULL);
+       return seq_open(file, &sctp_eps_ops);
 }
 
 static struct file_operations sctp_eps_seq_fops = {
        .open    = sctp_eps_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = single_release,
+       .release = seq_release,
 };
 
 /* Set up the proc fs entry for 'eps' object. */
@@ -222,6 +276,36 @@ void sctp_eps_proc_exit(void)
        remove_proc_entry("eps", proc_net_sctp);
 }
 
+
+static void * sctp_assocs_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, " ASSOC     SOCK   STY SST ST HBKT ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
+                               "RPORT LADDRS <-> RADDRS\n");
+
+       return (void *)pos;
+}
+
+static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
+{
+       return;
+}
+
+
+static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+       if (++*pos >= sctp_assoc_hashsize)
+               return NULL;
+
+       return pos;
+}
+
 /* Display sctp associations (/proc/net/sctp/assocs). */
 static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
 {
@@ -229,43 +313,57 @@ 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;
-
-       seq_printf(seq, " ASSOC     SOCK   STY SST ST HBKT LPORT RPORT "
-                       "LADDRS <-> RADDRS\n");
-       for (hash = 0; hash < sctp_assoc_hashsize; hash++) {
-               head = &sctp_assoc_hashtable[hash];
-               read_lock(&head->lock);
-               for (epb = head->chain; epb; epb = epb->next) {
-                       assoc = sctp_assoc(epb);
-                       sk = epb->sk;
-                       seq_printf(seq,
-                                  "%8p %8p %-3d %-3d %-2d %-4d %-5d %-5d ",
-                                  assoc, sk, sctp_sk(sk)->type, sk->sk_state,
-                                  assoc->state, hash, epb->bind_addr.port,
-                                  assoc->peer.port);
-                       sctp_seq_dump_local_addrs(seq, epb);
-                       seq_printf(seq, "<-> ");
-                       sctp_seq_dump_remote_addrs(seq, assoc);
-                       seq_printf(seq, "\n");
-               }
-               read_unlock(&head->lock);
+       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);
+       for (epb = head->chain; epb; epb = epb->next) {
+               assoc = sctp_assoc(epb);
+               sk = epb->sk;
+               seq_printf(seq,
+                          "%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->sndbuf_used,
+                          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, "\n");
        }
+       read_unlock(&head->lock);
+       sctp_local_bh_enable();
 
        return 0;
 }
 
+static struct seq_operations sctp_assoc_ops = {
+       .start = sctp_assocs_seq_start,
+       .next  = sctp_assocs_seq_next,
+       .stop  = sctp_assocs_seq_stop,
+       .show  = sctp_assocs_seq_show,
+};
+
 /* Initialize the seq file operations for 'assocs' object. */
 static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
 {
-       return single_open(file, sctp_assocs_seq_show, NULL);
+       return seq_open(file, &sctp_assoc_ops);
 }
 
 static struct file_operations sctp_assocs_seq_fops = {
        .open    = sctp_assocs_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = single_release,
+       .release = seq_release,
 };
 
 /* Set up the proc fs entry for 'assocs' object. */