Linux 2.6.14.3
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / sctp / proc.c
blobb74f7772b576b131b34b25c33fa544d4d6b84c8d
1 /* SCTP kernel reference Implementation
2 * Copyright (c) 2003 International Business Machines, Corp.
4 * This file is part of the SCTP kernel reference Implementation
6 * The SCTP reference implementation is free software;
7 * you can redistribute it and/or modify it under the terms of
8 * the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * The SCTP reference implementation is distributed in the hope that it
13 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
14 * ************************
15 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GNU CC; see the file COPYING. If not, write to
20 * the Free Software Foundation, 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
23 * Please send any bug reports or fixes you make to the
24 * email address(es):
25 * lksctp developers <lksctp-developers@lists.sourceforge.net>
27 * Or submit a bug report through the following website:
28 * http://www.sf.net/projects/lksctp
30 * Written or modified by:
31 * Sridhar Samudrala <sri@us.ibm.com>
33 * Any bugs reported given to us we will try to fix... any fixes shared will
34 * be incorporated into the next SCTP release.
37 #include <linux/types.h>
38 #include <linux/seq_file.h>
39 #include <linux/init.h>
40 #include <net/sctp/sctp.h>
42 static struct snmp_mib sctp_snmp_list[] = {
43 SNMP_MIB_ITEM("SctpCurrEstab", SCTP_MIB_CURRESTAB),
44 SNMP_MIB_ITEM("SctpActiveEstabs", SCTP_MIB_ACTIVEESTABS),
45 SNMP_MIB_ITEM("SctpPassiveEstabs", SCTP_MIB_PASSIVEESTABS),
46 SNMP_MIB_ITEM("SctpAborteds", SCTP_MIB_ABORTEDS),
47 SNMP_MIB_ITEM("SctpShutdowns", SCTP_MIB_SHUTDOWNS),
48 SNMP_MIB_ITEM("SctpOutOfBlues", SCTP_MIB_OUTOFBLUES),
49 SNMP_MIB_ITEM("SctpChecksumErrors", SCTP_MIB_CHECKSUMERRORS),
50 SNMP_MIB_ITEM("SctpOutCtrlChunks", SCTP_MIB_OUTCTRLCHUNKS),
51 SNMP_MIB_ITEM("SctpOutOrderChunks", SCTP_MIB_OUTORDERCHUNKS),
52 SNMP_MIB_ITEM("SctpOutUnorderChunks", SCTP_MIB_OUTUNORDERCHUNKS),
53 SNMP_MIB_ITEM("SctpInCtrlChunks", SCTP_MIB_INCTRLCHUNKS),
54 SNMP_MIB_ITEM("SctpInOrderChunks", SCTP_MIB_INORDERCHUNKS),
55 SNMP_MIB_ITEM("SctpInUnorderChunks", SCTP_MIB_INUNORDERCHUNKS),
56 SNMP_MIB_ITEM("SctpFragUsrMsgs", SCTP_MIB_FRAGUSRMSGS),
57 SNMP_MIB_ITEM("SctpReasmUsrMsgs", SCTP_MIB_REASMUSRMSGS),
58 SNMP_MIB_ITEM("SctpOutSCTPPacks", SCTP_MIB_OUTSCTPPACKS),
59 SNMP_MIB_ITEM("SctpInSCTPPacks", SCTP_MIB_INSCTPPACKS),
60 SNMP_MIB_SENTINEL
63 /* Return the current value of a particular entry in the mib by adding its
64 * per cpu counters.
65 */
66 static unsigned long
67 fold_field(void *mib[], int nr)
69 unsigned long res = 0;
70 int i;
72 for (i = 0; i < NR_CPUS; i++) {
73 if (!cpu_possible(i))
74 continue;
75 res +=
76 *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) +
77 sizeof (unsigned long) * nr));
78 res +=
79 *((unsigned long *) (((void *) per_cpu_ptr(mib[1], i)) +
80 sizeof (unsigned long) * nr));
82 return res;
85 /* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
86 static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
88 int i;
90 for (i = 0; sctp_snmp_list[i].name != NULL; i++)
91 seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
92 fold_field((void **)sctp_statistics,
93 sctp_snmp_list[i].entry));
95 return 0;
98 /* Initialize the seq file operations for 'snmp' object. */
99 static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
101 return single_open(file, sctp_snmp_seq_show, NULL);
104 static struct file_operations sctp_snmp_seq_fops = {
105 .owner = THIS_MODULE,
106 .open = sctp_snmp_seq_open,
107 .read = seq_read,
108 .llseek = seq_lseek,
109 .release = single_release,
112 /* Set up the proc fs entry for 'snmp' object. */
113 int __init sctp_snmp_proc_init(void)
115 struct proc_dir_entry *p;
117 p = create_proc_entry("snmp", S_IRUGO, proc_net_sctp);
118 if (!p)
119 return -ENOMEM;
121 p->proc_fops = &sctp_snmp_seq_fops;
123 return 0;
126 /* Cleanup the proc fs entry for 'snmp' object. */
127 void sctp_snmp_proc_exit(void)
129 remove_proc_entry("snmp", proc_net_sctp);
132 /* Dump local addresses of an association/endpoint. */
133 static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
135 struct list_head *pos;
136 struct sctp_association *asoc;
137 struct sctp_sockaddr_entry *laddr;
138 struct sctp_transport *peer;
139 union sctp_addr *addr, *primary = NULL;
140 struct sctp_af *af;
142 if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
143 asoc = sctp_assoc(epb);
144 peer = asoc->peer.primary_path;
145 primary = &peer->saddr;
148 list_for_each(pos, &epb->bind_addr.address_list) {
149 laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
150 addr = (union sctp_addr *)&laddr->a;
151 af = sctp_get_af_specific(addr->sa.sa_family);
152 if (primary && af->cmp_addr(addr, primary)) {
153 seq_printf(seq, "*");
155 af->seq_dump_addr(seq, addr);
159 /* Dump remote addresses of an association. */
160 static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
162 struct list_head *pos;
163 struct sctp_transport *transport;
164 union sctp_addr *addr, *primary;
165 struct sctp_af *af;
167 primary = &(assoc->peer.primary_addr);
168 list_for_each(pos, &assoc->peer.transport_addr_list) {
169 transport = list_entry(pos, struct sctp_transport, transports);
170 addr = (union sctp_addr *)&transport->ipaddr;
171 af = sctp_get_af_specific(addr->sa.sa_family);
172 if (af->cmp_addr(addr, primary)) {
173 seq_printf(seq, "*");
175 af->seq_dump_addr(seq, addr);
179 static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
181 if (*pos > sctp_ep_hashsize)
182 return NULL;
184 if (*pos < 0)
185 *pos = 0;
187 if (*pos == 0)
188 seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS\n");
190 ++*pos;
192 return (void *)pos;
195 static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
197 return;
201 static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
203 if (*pos > sctp_ep_hashsize)
204 return NULL;
206 ++*pos;
208 return pos;
212 /* Display sctp endpoints (/proc/net/sctp/eps). */
213 static int sctp_eps_seq_show(struct seq_file *seq, void *v)
215 struct sctp_hashbucket *head;
216 struct sctp_ep_common *epb;
217 struct sctp_endpoint *ep;
218 struct sock *sk;
219 int hash = *(int *)v;
221 if (hash > sctp_ep_hashsize)
222 return -ENOMEM;
224 head = &sctp_ep_hashtable[hash-1];
225 sctp_local_bh_disable();
226 read_lock(&head->lock);
227 for (epb = head->chain; epb; epb = epb->next) {
228 ep = sctp_ep(epb);
229 sk = epb->sk;
230 seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
231 sctp_sk(sk)->type, sk->sk_state, hash-1,
232 epb->bind_addr.port,
233 sock_i_uid(sk), sock_i_ino(sk));
235 sctp_seq_dump_local_addrs(seq, epb);
236 seq_printf(seq, "\n");
238 read_unlock(&head->lock);
239 sctp_local_bh_enable();
241 return 0;
244 static struct seq_operations sctp_eps_ops = {
245 .start = sctp_eps_seq_start,
246 .next = sctp_eps_seq_next,
247 .stop = sctp_eps_seq_stop,
248 .show = sctp_eps_seq_show,
252 /* Initialize the seq file operations for 'eps' object. */
253 static int sctp_eps_seq_open(struct inode *inode, struct file *file)
255 return seq_open(file, &sctp_eps_ops);
258 static struct file_operations sctp_eps_seq_fops = {
259 .open = sctp_eps_seq_open,
260 .read = seq_read,
261 .llseek = seq_lseek,
262 .release = seq_release,
265 /* Set up the proc fs entry for 'eps' object. */
266 int __init sctp_eps_proc_init(void)
268 struct proc_dir_entry *p;
270 p = create_proc_entry("eps", S_IRUGO, proc_net_sctp);
271 if (!p)
272 return -ENOMEM;
274 p->proc_fops = &sctp_eps_seq_fops;
276 return 0;
279 /* Cleanup the proc fs entry for 'eps' object. */
280 void sctp_eps_proc_exit(void)
282 remove_proc_entry("eps", proc_net_sctp);
286 static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
288 if (*pos > sctp_assoc_hashsize)
289 return NULL;
291 if (*pos < 0)
292 *pos = 0;
294 if (*pos == 0)
295 seq_printf(seq, " ASSOC SOCK STY SST ST HBKT ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
296 "RPORT LADDRS <-> RADDRS\n");
298 ++*pos;
300 return (void *)pos;
303 static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
305 return;
309 static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
311 if (*pos > sctp_assoc_hashsize)
312 return NULL;
314 ++*pos;
316 return pos;
319 /* Display sctp associations (/proc/net/sctp/assocs). */
320 static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
322 struct sctp_hashbucket *head;
323 struct sctp_ep_common *epb;
324 struct sctp_association *assoc;
325 struct sock *sk;
326 int hash = *(int *)v;
328 if (hash > sctp_assoc_hashsize)
329 return -ENOMEM;
331 head = &sctp_assoc_hashtable[hash-1];
332 sctp_local_bh_disable();
333 read_lock(&head->lock);
334 for (epb = head->chain; epb; epb = epb->next) {
335 assoc = sctp_assoc(epb);
336 sk = epb->sk;
337 seq_printf(seq,
338 "%8p %8p %-3d %-3d %-2d %-4d %4d %8d %8d %7d %5lu %-5d %5d ",
339 assoc, sk, sctp_sk(sk)->type, sk->sk_state,
340 assoc->state, hash-1, assoc->assoc_id,
341 (sk->sk_rcvbuf - assoc->rwnd),
342 assoc->sndbuf_used,
343 sock_i_uid(sk), sock_i_ino(sk),
344 epb->bind_addr.port,
345 assoc->peer.port);
347 seq_printf(seq, " ");
348 sctp_seq_dump_local_addrs(seq, epb);
349 seq_printf(seq, "<-> ");
350 sctp_seq_dump_remote_addrs(seq, assoc);
351 seq_printf(seq, "\n");
353 read_unlock(&head->lock);
354 sctp_local_bh_enable();
356 return 0;
359 static struct seq_operations sctp_assoc_ops = {
360 .start = sctp_assocs_seq_start,
361 .next = sctp_assocs_seq_next,
362 .stop = sctp_assocs_seq_stop,
363 .show = sctp_assocs_seq_show,
366 /* Initialize the seq file operations for 'assocs' object. */
367 static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
369 return seq_open(file, &sctp_assoc_ops);
372 static struct file_operations sctp_assocs_seq_fops = {
373 .open = sctp_assocs_seq_open,
374 .read = seq_read,
375 .llseek = seq_lseek,
376 .release = seq_release,
379 /* Set up the proc fs entry for 'assocs' object. */
380 int __init sctp_assocs_proc_init(void)
382 struct proc_dir_entry *p;
384 p = create_proc_entry("assocs", S_IRUGO, proc_net_sctp);
385 if (!p)
386 return -ENOMEM;
388 p->proc_fops = &sctp_assocs_seq_fops;
390 return 0;
393 /* Cleanup the proc fs entry for 'assocs' object. */
394 void sctp_assocs_proc_exit(void)
396 remove_proc_entry("assocs", proc_net_sctp);