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)
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
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),
63 /* Return the current value of a particular entry in the mib by adding its
67 fold_field(void *mib[], int nr)
69 unsigned long res = 0;
74 *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) +
75 sizeof (unsigned long) * nr));
77 *((unsigned long *) (((void *) per_cpu_ptr(mib[1], i)) +
78 sizeof (unsigned long) * nr));
83 /* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
84 static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
88 for (i = 0; sctp_snmp_list[i].name != NULL; i++)
89 seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
90 fold_field((void **)sctp_statistics,
91 sctp_snmp_list[i].entry));
96 /* Initialize the seq file operations for 'snmp' object. */
97 static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
99 return single_open(file, sctp_snmp_seq_show, NULL);
102 static struct file_operations sctp_snmp_seq_fops = {
103 .owner = THIS_MODULE,
104 .open = sctp_snmp_seq_open,
107 .release = single_release,
110 /* Set up the proc fs entry for 'snmp' object. */
111 int __init sctp_snmp_proc_init(void)
113 struct proc_dir_entry *p;
115 p = create_proc_entry("snmp", S_IRUGO, proc_net_sctp);
119 p->proc_fops = &sctp_snmp_seq_fops;
124 /* Cleanup the proc fs entry for 'snmp' object. */
125 void sctp_snmp_proc_exit(void)
127 remove_proc_entry("snmp", proc_net_sctp);
130 /* Dump local addresses of an association/endpoint. */
131 static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
133 struct list_head *pos;
134 struct sctp_association *asoc;
135 struct sctp_sockaddr_entry *laddr;
136 struct sctp_transport *peer;
137 union sctp_addr *addr, *primary = NULL;
140 if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
141 asoc = sctp_assoc(epb);
142 peer = asoc->peer.primary_path;
143 primary = &peer->saddr;
146 list_for_each(pos, &epb->bind_addr.address_list) {
147 laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
148 addr = (union sctp_addr *)&laddr->a;
149 af = sctp_get_af_specific(addr->sa.sa_family);
150 if (primary && af->cmp_addr(addr, primary)) {
151 seq_printf(seq, "*");
153 af->seq_dump_addr(seq, addr);
157 /* Dump remote addresses of an association. */
158 static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
160 struct list_head *pos;
161 struct sctp_transport *transport;
162 union sctp_addr *addr, *primary;
165 primary = &(assoc->peer.primary_addr);
166 list_for_each(pos, &assoc->peer.transport_addr_list) {
167 transport = list_entry(pos, struct sctp_transport, transports);
168 addr = (union sctp_addr *)&transport->ipaddr;
169 af = sctp_get_af_specific(addr->sa.sa_family);
170 if (af->cmp_addr(addr, primary)) {
171 seq_printf(seq, "*");
173 af->seq_dump_addr(seq, addr);
177 static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
179 if (*pos > sctp_ep_hashsize)
186 seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS\n");
193 static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
199 static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
201 if (*pos > sctp_ep_hashsize)
210 /* Display sctp endpoints (/proc/net/sctp/eps). */
211 static int sctp_eps_seq_show(struct seq_file *seq, void *v)
213 struct sctp_hashbucket *head;
214 struct sctp_ep_common *epb;
215 struct sctp_endpoint *ep;
217 int hash = *(int *)v;
219 if (hash > sctp_ep_hashsize)
222 head = &sctp_ep_hashtable[hash-1];
223 sctp_local_bh_disable();
224 read_lock(&head->lock);
225 for (epb = head->chain; epb; epb = epb->next) {
228 seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
229 sctp_sk(sk)->type, sk->sk_state, hash-1,
231 sock_i_uid(sk), sock_i_ino(sk));
233 sctp_seq_dump_local_addrs(seq, epb);
234 seq_printf(seq, "\n");
236 read_unlock(&head->lock);
237 sctp_local_bh_enable();
242 static struct seq_operations sctp_eps_ops = {
243 .start = sctp_eps_seq_start,
244 .next = sctp_eps_seq_next,
245 .stop = sctp_eps_seq_stop,
246 .show = sctp_eps_seq_show,
250 /* Initialize the seq file operations for 'eps' object. */
251 static int sctp_eps_seq_open(struct inode *inode, struct file *file)
253 return seq_open(file, &sctp_eps_ops);
256 static struct file_operations sctp_eps_seq_fops = {
257 .open = sctp_eps_seq_open,
260 .release = seq_release,
263 /* Set up the proc fs entry for 'eps' object. */
264 int __init sctp_eps_proc_init(void)
266 struct proc_dir_entry *p;
268 p = create_proc_entry("eps", S_IRUGO, proc_net_sctp);
272 p->proc_fops = &sctp_eps_seq_fops;
277 /* Cleanup the proc fs entry for 'eps' object. */
278 void sctp_eps_proc_exit(void)
280 remove_proc_entry("eps", proc_net_sctp);
284 static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
286 if (*pos > sctp_assoc_hashsize)
293 seq_printf(seq, " ASSOC SOCK STY SST ST HBKT ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
294 "RPORT LADDRS <-> RADDRS\n");
301 static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
307 static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
309 if (*pos > sctp_assoc_hashsize)
317 /* Display sctp associations (/proc/net/sctp/assocs). */
318 static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
320 struct sctp_hashbucket *head;
321 struct sctp_ep_common *epb;
322 struct sctp_association *assoc;
324 int hash = *(int *)v;
326 if (hash > sctp_assoc_hashsize)
329 head = &sctp_assoc_hashtable[hash-1];
330 sctp_local_bh_disable();
331 read_lock(&head->lock);
332 for (epb = head->chain; epb; epb = epb->next) {
333 assoc = sctp_assoc(epb);
336 "%8p %8p %-3d %-3d %-2d %-4d %4d %8d %8d %7d %5lu %-5d %5d ",
337 assoc, sk, sctp_sk(sk)->type, sk->sk_state,
338 assoc->state, hash-1, assoc->assoc_id,
339 (sk->sk_rcvbuf - assoc->rwnd),
341 sock_i_uid(sk), sock_i_ino(sk),
345 seq_printf(seq, " ");
346 sctp_seq_dump_local_addrs(seq, epb);
347 seq_printf(seq, "<-> ");
348 sctp_seq_dump_remote_addrs(seq, assoc);
349 seq_printf(seq, "\n");
351 read_unlock(&head->lock);
352 sctp_local_bh_enable();
357 static struct seq_operations sctp_assoc_ops = {
358 .start = sctp_assocs_seq_start,
359 .next = sctp_assocs_seq_next,
360 .stop = sctp_assocs_seq_stop,
361 .show = sctp_assocs_seq_show,
364 /* Initialize the seq file operations for 'assocs' object. */
365 static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
367 return seq_open(file, &sctp_assoc_ops);
370 static struct file_operations sctp_assocs_seq_fops = {
371 .open = sctp_assocs_seq_open,
374 .release = seq_release,
377 /* Set up the proc fs entry for 'assocs' object. */
378 int __init sctp_assocs_proc_init(void)
380 struct proc_dir_entry *p;
382 p = create_proc_entry("assocs", S_IRUGO, proc_net_sctp);
386 p->proc_fops = &sctp_assocs_seq_fops;
391 /* Cleanup the proc fs entry for 'assocs' object. */
392 void sctp_assocs_proc_exit(void)
394 remove_proc_entry("assocs", proc_net_sctp);