Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* 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 | ||
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), | |
d2287f84 | 60 | SNMP_MIB_SENTINEL |
1da177e4 LT |
61 | }; |
62 | ||
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) | |
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). */ | |
86 | static 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. */ | |
99 | static int sctp_snmp_seq_open(struct inode *inode, struct file *file) | |
100 | { | |
101 | return single_open(file, sctp_snmp_seq_show, NULL); | |
102 | } | |
103 | ||
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, | |
110 | }; | |
111 | ||
112 | /* Set up the proc fs entry for 'snmp' object. */ | |
113 | int __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. */ | |
127 | void sctp_snmp_proc_exit(void) | |
128 | { | |
129 | remove_proc_entry("snmp", proc_net_sctp); | |
130 | } | |
131 | ||
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) | |
134 | { | |
135 | struct list_head *pos; | |
bca735bd | 136 | struct sctp_association *asoc; |
1da177e4 | 137 | struct sctp_sockaddr_entry *laddr; |
bca735bd VY |
138 | struct sctp_transport *peer; |
139 | union sctp_addr *addr, *primary = NULL; | |
1da177e4 LT |
140 | struct sctp_af *af; |
141 | ||
bca735bd VY |
142 | if (epb->type == SCTP_EP_TYPE_ASSOCIATION) { |
143 | asoc = sctp_assoc(epb); | |
144 | peer = asoc->peer.primary_path; | |
145 | primary = &peer->saddr; | |
146 | } | |
147 | ||
1da177e4 LT |
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); | |
bca735bd VY |
152 | if (primary && af->cmp_addr(addr, primary)) { |
153 | seq_printf(seq, "*"); | |
154 | } | |
1da177e4 LT |
155 | af->seq_dump_addr(seq, addr); |
156 | } | |
157 | } | |
158 | ||
159 | /* Dump remote addresses of an association. */ | |
160 | static 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; | |
bca735bd | 164 | union sctp_addr *addr, *primary; |
1da177e4 LT |
165 | struct sctp_af *af; |
166 | ||
bca735bd | 167 | primary = &(assoc->peer.primary_addr); |
1da177e4 LT |
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); | |
bca735bd VY |
172 | if (af->cmp_addr(addr, primary)) { |
173 | seq_printf(seq, "*"); | |
174 | } | |
1da177e4 LT |
175 | af->seq_dump_addr(seq, addr); |
176 | } | |
177 | } | |
178 | ||
bca735bd VY |
179 | static 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 | ||
195 | static void sctp_eps_seq_stop(struct seq_file *seq, void *v) | |
196 | { | |
197 | return; | |
198 | } | |
199 | ||
200 | ||
201 | static 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 | ||
1da177e4 LT |
212 | /* Display sctp endpoints (/proc/net/sctp/eps). */ |
213 | static 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; | |
bca735bd VY |
219 | int hash = *(int *)v; |
220 | ||
221 | 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"); | |
1da177e4 | 237 | } |
bca735bd VY |
238 | read_unlock(&head->lock); |
239 | sctp_local_bh_enable(); | |
1da177e4 LT |
240 | |
241 | return 0; | |
242 | } | |
243 | ||
bca735bd VY |
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, | |
249 | }; | |
250 | ||
251 | ||
1da177e4 LT |
252 | /* Initialize the seq file operations for 'eps' object. */ |
253 | static int sctp_eps_seq_open(struct inode *inode, struct file *file) | |
254 | { | |
bca735bd | 255 | return seq_open(file, &sctp_eps_ops); |
1da177e4 LT |
256 | } |
257 | ||
258 | static struct file_operations sctp_eps_seq_fops = { | |
259 | .open = sctp_eps_seq_open, | |
260 | .read = seq_read, | |
261 | .llseek = seq_lseek, | |
bca735bd | 262 | .release = seq_release, |
1da177e4 LT |
263 | }; |
264 | ||
265 | /* Set up the proc fs entry for 'eps' object. */ | |
266 | int __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. */ | |
280 | void sctp_eps_proc_exit(void) | |
281 | { | |
282 | remove_proc_entry("eps", proc_net_sctp); | |
283 | } | |
284 | ||
bca735bd VY |
285 | |
286 | static 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 | ||
303 | static void sctp_assocs_seq_stop(struct seq_file *seq, void *v) | |
304 | { | |
305 | return; | |
306 | } | |
307 | ||
308 | ||
309 | static 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 | ||
1da177e4 LT |
319 | /* Display sctp associations (/proc/net/sctp/assocs). */ |
320 | static 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; | |
bca735bd VY |
326 | int hash = *(int *)v; |
327 | ||
328 | 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"); | |
1da177e4 | 352 | } |
bca735bd VY |
353 | read_unlock(&head->lock); |
354 | sctp_local_bh_enable(); | |
1da177e4 LT |
355 | |
356 | return 0; | |
357 | } | |
358 | ||
bca735bd VY |
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, | |
364 | }; | |
365 | ||
1da177e4 LT |
366 | /* Initialize the seq file operations for 'assocs' object. */ |
367 | static int sctp_assocs_seq_open(struct inode *inode, struct file *file) | |
368 | { | |
bca735bd | 369 | return seq_open(file, &sctp_assoc_ops); |
1da177e4 LT |
370 | } |
371 | ||
372 | static struct file_operations sctp_assocs_seq_fops = { | |
373 | .open = sctp_assocs_seq_open, | |
374 | .read = seq_read, | |
375 | .llseek = seq_lseek, | |
bca735bd | 376 | .release = seq_release, |
1da177e4 LT |
377 | }; |
378 | ||
379 | /* Set up the proc fs entry for 'assocs' object. */ | |
380 | int __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. */ | |
394 | void sctp_assocs_proc_exit(void) | |
395 | { | |
396 | remove_proc_entry("assocs", proc_net_sctp); | |
397 | } |