blob: d47a52c303a81da44da5f8d8c478f77049e69483 [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
John Hawkes670c02c2005-10-13 09:30:31 -070072 for_each_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 res +=
74 *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) +
75 sizeof (unsigned long) * nr));
76 res +=
77 *((unsigned long *) (((void *) per_cpu_ptr(mib[1], i)) +
78 sizeof (unsigned long) * nr));
79 }
80 return res;
81}
82
83/* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
84static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
85{
86 int i;
87
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));
92
93 return 0;
94}
95
96/* Initialize the seq file operations for 'snmp' object. */
97static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
98{
99 return single_open(file, sctp_snmp_seq_show, NULL);
100}
101
102static struct file_operations sctp_snmp_seq_fops = {
103 .owner = THIS_MODULE,
104 .open = sctp_snmp_seq_open,
105 .read = seq_read,
106 .llseek = seq_lseek,
107 .release = single_release,
108};
109
110/* Set up the proc fs entry for 'snmp' object. */
111int __init sctp_snmp_proc_init(void)
112{
113 struct proc_dir_entry *p;
114
115 p = create_proc_entry("snmp", S_IRUGO, proc_net_sctp);
116 if (!p)
117 return -ENOMEM;
118
119 p->proc_fops = &sctp_snmp_seq_fops;
120
121 return 0;
122}
123
124/* Cleanup the proc fs entry for 'snmp' object. */
125void sctp_snmp_proc_exit(void)
126{
127 remove_proc_entry("snmp", proc_net_sctp);
128}
129
130/* Dump local addresses of an association/endpoint. */
131static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb)
132{
133 struct list_head *pos;
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700134 struct sctp_association *asoc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 struct sctp_sockaddr_entry *laddr;
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700136 struct sctp_transport *peer;
137 union sctp_addr *addr, *primary = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 struct sctp_af *af;
139
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700140 if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
141 asoc = sctp_assoc(epb);
142 peer = asoc->peer.primary_path;
143 primary = &peer->saddr;
144 }
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 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);
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700150 if (primary && af->cmp_addr(addr, primary)) {
151 seq_printf(seq, "*");
152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 af->seq_dump_addr(seq, addr);
154 }
155}
156
157/* Dump remote addresses of an association. */
158static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
159{
160 struct list_head *pos;
161 struct sctp_transport *transport;
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700162 union sctp_addr *addr, *primary;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 struct sctp_af *af;
164
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700165 primary = &(assoc->peer.primary_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 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);
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700170 if (af->cmp_addr(addr, primary)) {
171 seq_printf(seq, "*");
172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 af->seq_dump_addr(seq, addr);
174 }
175}
176
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700177static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos)
178{
Vlad Yasevich49392e52006-01-17 11:53:06 -0800179 if (*pos >= sctp_ep_hashsize)
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700180 return NULL;
181
182 if (*pos < 0)
183 *pos = 0;
184
185 if (*pos == 0)
186 seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS\n");
187
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700188 return (void *)pos;
189}
190
191static void sctp_eps_seq_stop(struct seq_file *seq, void *v)
192{
193 return;
194}
195
196
197static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
198{
Vlad Yasevich49392e52006-01-17 11:53:06 -0800199 if (++*pos >= sctp_ep_hashsize)
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700200 return NULL;
201
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700202 return pos;
203}
204
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/* Display sctp endpoints (/proc/net/sctp/eps). */
207static int sctp_eps_seq_show(struct seq_file *seq, void *v)
208{
209 struct sctp_hashbucket *head;
210 struct sctp_ep_common *epb;
211 struct sctp_endpoint *ep;
212 struct sock *sk;
Vlad Yasevich38b0e422006-01-17 11:54:06 -0800213 int hash = *(loff_t *)v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Vlad Yasevich49392e52006-01-17 11:53:06 -0800215 if (hash >= sctp_ep_hashsize)
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700216 return -ENOMEM;
217
Vlad Yasevich49392e52006-01-17 11:53:06 -0800218 head = &sctp_ep_hashtable[hash];
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700219 sctp_local_bh_disable();
220 read_lock(&head->lock);
221 for (epb = head->chain; epb; epb = epb->next) {
222 ep = sctp_ep(epb);
223 sk = epb->sk;
224 seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
Vlad Yasevich49392e52006-01-17 11:53:06 -0800225 sctp_sk(sk)->type, sk->sk_state, hash,
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700226 epb->bind_addr.port,
227 sock_i_uid(sk), sock_i_ino(sk));
228
229 sctp_seq_dump_local_addrs(seq, epb);
230 seq_printf(seq, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700232 read_unlock(&head->lock);
233 sctp_local_bh_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 return 0;
236}
237
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700238static struct seq_operations sctp_eps_ops = {
239 .start = sctp_eps_seq_start,
240 .next = sctp_eps_seq_next,
241 .stop = sctp_eps_seq_stop,
242 .show = sctp_eps_seq_show,
243};
244
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246/* Initialize the seq file operations for 'eps' object. */
247static int sctp_eps_seq_open(struct inode *inode, struct file *file)
248{
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700249 return seq_open(file, &sctp_eps_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
252static struct file_operations sctp_eps_seq_fops = {
253 .open = sctp_eps_seq_open,
254 .read = seq_read,
255 .llseek = seq_lseek,
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700256 .release = seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257};
258
259/* Set up the proc fs entry for 'eps' object. */
260int __init sctp_eps_proc_init(void)
261{
262 struct proc_dir_entry *p;
263
264 p = create_proc_entry("eps", S_IRUGO, proc_net_sctp);
265 if (!p)
266 return -ENOMEM;
267
268 p->proc_fops = &sctp_eps_seq_fops;
269
270 return 0;
271}
272
273/* Cleanup the proc fs entry for 'eps' object. */
274void sctp_eps_proc_exit(void)
275{
276 remove_proc_entry("eps", proc_net_sctp);
277}
278
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700279
280static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos)
281{
Vlad Yasevich49392e52006-01-17 11:53:06 -0800282 if (*pos >= sctp_assoc_hashsize)
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700283 return NULL;
284
285 if (*pos < 0)
286 *pos = 0;
287
288 if (*pos == 0)
289 seq_printf(seq, " ASSOC SOCK STY SST ST HBKT ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT "
290 "RPORT LADDRS <-> RADDRS\n");
291
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700292 return (void *)pos;
293}
294
295static void sctp_assocs_seq_stop(struct seq_file *seq, void *v)
296{
297 return;
298}
299
300
301static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
302{
Vlad Yasevich49392e52006-01-17 11:53:06 -0800303 if (++*pos >= sctp_assoc_hashsize)
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700304 return NULL;
305
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700306 return pos;
307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/* Display sctp associations (/proc/net/sctp/assocs). */
310static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
311{
312 struct sctp_hashbucket *head;
313 struct sctp_ep_common *epb;
314 struct sctp_association *assoc;
315 struct sock *sk;
Vlad Yasevich38b0e422006-01-17 11:54:06 -0800316 int hash = *(loff_t *)v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Vlad Yasevich49392e52006-01-17 11:53:06 -0800318 if (hash >= sctp_assoc_hashsize)
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700319 return -ENOMEM;
320
Vlad Yasevich49392e52006-01-17 11:53:06 -0800321 head = &sctp_assoc_hashtable[hash];
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700322 sctp_local_bh_disable();
323 read_lock(&head->lock);
324 for (epb = head->chain; epb; epb = epb->next) {
325 assoc = sctp_assoc(epb);
326 sk = epb->sk;
327 seq_printf(seq,
328 "%8p %8p %-3d %-3d %-2d %-4d %4d %8d %8d %7d %5lu %-5d %5d ",
329 assoc, sk, sctp_sk(sk)->type, sk->sk_state,
Vlad Yasevich49392e52006-01-17 11:53:06 -0800330 assoc->state, hash, assoc->assoc_id,
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700331 (sk->sk_rcvbuf - assoc->rwnd),
332 assoc->sndbuf_used,
333 sock_i_uid(sk), sock_i_ino(sk),
334 epb->bind_addr.port,
335 assoc->peer.port);
336
337 seq_printf(seq, " ");
338 sctp_seq_dump_local_addrs(seq, epb);
339 seq_printf(seq, "<-> ");
340 sctp_seq_dump_remote_addrs(seq, assoc);
341 seq_printf(seq, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 }
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700343 read_unlock(&head->lock);
344 sctp_local_bh_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 return 0;
347}
348
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700349static struct seq_operations sctp_assoc_ops = {
350 .start = sctp_assocs_seq_start,
351 .next = sctp_assocs_seq_next,
352 .stop = sctp_assocs_seq_stop,
353 .show = sctp_assocs_seq_show,
354};
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356/* Initialize the seq file operations for 'assocs' object. */
357static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
358{
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700359 return seq_open(file, &sctp_assoc_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
362static struct file_operations sctp_assocs_seq_fops = {
363 .open = sctp_assocs_seq_open,
364 .read = seq_read,
365 .llseek = seq_lseek,
Vladislav Yasevichbca735b2005-06-13 15:11:57 -0700366 .release = seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367};
368
369/* Set up the proc fs entry for 'assocs' object. */
370int __init sctp_assocs_proc_init(void)
371{
372 struct proc_dir_entry *p;
373
374 p = create_proc_entry("assocs", S_IRUGO, proc_net_sctp);
375 if (!p)
376 return -ENOMEM;
377
378 p->proc_fops = &sctp_assocs_seq_fops;
379
380 return 0;
381}
382
383/* Cleanup the proc fs entry for 'assocs' object. */
384void sctp_assocs_proc_exit(void)
385{
386 remove_proc_entry("assocs", proc_net_sctp);
387}