blob: b74f7772b576b131b34b25c33fa544d4d6b84c8d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* SCTP kernel reference Implementation
2 * Copyright (c) 2003 International Business Machines, Corp.
3 *
4 * This file is part of the SCTP kernel reference Implementation
5 *
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.
11 *
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.
17 *
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.
22 *
23 * Please send any bug reports or fixes you make to the
24 * email address(es):
25 * lksctp developers <lksctp-developers@lists.sourceforge.net>
26 *
27 * Or submit a bug report through the following website:
28 * http://www.sf.net/projects/lksctp
29 *
30 * Written or modified by:
31 * Sridhar Samudrala <sri@us.ibm.com>
32 *
33 * Any bugs reported given to us we will try to fix... any fixes shared will
34 * be incorporated into the next SCTP release.
35 */
36
37#include <linux/types.h>
38#include <linux/seq_file.h>
39#include <linux/init.h>
40#include <net/sctp/sctp.h>
41
42static 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),
Vlad Yasevichd2287f82005-08-23 10:12:04 -070060 SNMP_MIB_SENTINEL
Linus Torvalds1da177e2005-04-16 15:20:36 -070061};
62
63/* Return the current value of a particular entry in the mib by adding its
64 * per cpu counters.
65 */
66static unsigned long
67fold_field(void *mib[], int nr)
68{
69 unsigned long res = 0;
70 int i;
71
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));
81 }
82 return res;
83}
84
85/* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
86static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
87{
88 int i;
89
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));
94
95 return 0;
96}
97
98/* Initialize the seq file operations for 'snmp' object. */
99static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
100{
101 return single_open(file, sctp_snmp_seq_show, NULL);
102}
103
104static 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,
110};
111
112/* Set up the proc fs entry for 'snmp' object. */
113int __init sctp_snmp_proc_init(void)
114{
115 struct proc_dir_entry *p;
116
117 p = create_proc_entry("snmp", S_IRUGO, proc_net_sctp);
118 if (!p)
119 return -ENOMEM;
120
121 p->proc_fops = &sctp_snmp_seq_fops;
122
123 return 0;
124}
125
126/* Cleanup the proc fs entry for 'snmp' object. */
127void sctp_snmp_proc_exit(void)
128{
129 remove_proc_entry("snmp", proc_net_sctp);
130}
131
132/* Dump local addresses of an association/endpoint. */
133static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
134{
135 struct list_head *pos;
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700136 struct sctp_association *asoc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 struct sctp_sockaddr_entry *laddr;
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700138 struct sctp_transport *peer;
139 union sctp_addr *addr, *primary = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 struct sctp_af *af;
141
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700142 if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
143 asoc = sctp_assoc(epb);
144 peer = asoc->peer.primary_path;
145 primary = &peer->saddr;
146 }
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 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);
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700152 if (primary && af->cmp_addr(addr, primary)) {
153 seq_printf(seq, "*");
154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 af->seq_dump_addr(seq, addr);
156 }
157}
158
159/* Dump remote addresses of an association. */
160static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
161{
162 struct list_head *pos;
163 struct sctp_transport *transport;
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700164 union sctp_addr *addr, *primary;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 struct sctp_af *af;
166
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700167 primary = &(assoc->peer.primary_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 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);
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700172 if (af->cmp_addr(addr, primary)) {
173 seq_printf(seq, "*");
174 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 af->seq_dump_addr(seq, addr);
176 }
177}
178
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700179static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
180{
181 if (*pos > sctp_ep_hashsize)
182 return NULL;
183
184 if (*pos < 0)
185 *pos = 0;
186
187 if (*pos == 0)
188 seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS\n");
189
190 ++*pos;
191
192 return (void *)pos;
193}
194
195static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
196{
197 return;
198}
199
200
201static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
202{
203 if (*pos > sctp_ep_hashsize)
204 return NULL;
205
206 ++*pos;
207
208 return pos;
209}
210
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212/* Display sctp endpoints (/proc/net/sctp/eps). */
213static int sctp_eps_seq_show(struct seq_file *seq, void *v)
214{
215 struct sctp_hashbucket *head;
216 struct sctp_ep_common *epb;
217 struct sctp_endpoint *ep;
218 struct sock *sk;
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700219 int hash = *(int *)v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700221 if (hash > sctp_ep_hashsize)
222 return -ENOMEM;
223
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));
234
235 sctp_seq_dump_local_addrs(seq, epb);
236 seq_printf(seq, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700238 read_unlock(&head->lock);
239 sctp_local_bh_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 return 0;
242}
243
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700244static 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,
249};
250
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252/* Initialize the seq file operations for 'eps' object. */
253static int sctp_eps_seq_open(struct inode *inode, struct file *file)
254{
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700255 return seq_open(file, &sctp_eps_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256}
257
258static struct file_operations sctp_eps_seq_fops = {
259 .open = sctp_eps_seq_open,
260 .read = seq_read,
261 .llseek = seq_lseek,
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700262 .release = seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263};
264
265/* Set up the proc fs entry for 'eps' object. */
266int __init sctp_eps_proc_init(void)
267{
268 struct proc_dir_entry *p;
269
270 p = create_proc_entry("eps", S_IRUGO, proc_net_sctp);
271 if (!p)
272 return -ENOMEM;
273
274 p->proc_fops = &sctp_eps_seq_fops;
275
276 return 0;
277}
278
279/* Cleanup the proc fs entry for 'eps' object. */
280void sctp_eps_proc_exit(void)
281{
282 remove_proc_entry("eps", proc_net_sctp);
283}
284
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700285
286static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
287{
288 if (*pos > sctp_assoc_hashsize)
289 return NULL;
290
291 if (*pos < 0)
292 *pos = 0;
293
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");
297
298 ++*pos;
299
300 return (void *)pos;
301}
302
303static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
304{
305 return;
306}
307
308
309static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
310{
311 if (*pos > sctp_assoc_hashsize)
312 return NULL;
313
314 ++*pos;
315
316 return pos;
317}
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319/* Display sctp associations (/proc/net/sctp/assocs). */
320static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
321{
322 struct sctp_hashbucket *head;
323 struct sctp_ep_common *epb;
324 struct sctp_association *assoc;
325 struct sock *sk;
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700326 int hash = *(int *)v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700328 if (hash > sctp_assoc_hashsize)
329 return -ENOMEM;
330
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);
346
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");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700353 read_unlock(&head->lock);
354 sctp_local_bh_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 return 0;
357}
358
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700359static 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,
364};
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366/* Initialize the seq file operations for 'assocs' object. */
367static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
368{
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700369 return seq_open(file, &sctp_assoc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
371
372static struct file_operations sctp_assocs_seq_fops = {
373 .open = sctp_assocs_seq_open,
374 .read = seq_read,
375 .llseek = seq_lseek,
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700376 .release = seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377};
378
379/* Set up the proc fs entry for 'assocs' object. */
380int __init sctp_assocs_proc_init(void)
381{
382 struct proc_dir_entry *p;
383
384 p = create_proc_entry("assocs", S_IRUGO, proc_net_sctp);
385 if (!p)
386 return -ENOMEM;
387
388 p->proc_fops = &sctp_assocs_seq_fops;
389
390 return 0;
391}
392
393/* Cleanup the proc fs entry for 'assocs' object. */
394void sctp_assocs_proc_exit(void)
395{
396 remove_proc_entry("assocs", proc_net_sctp);
397}