Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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), |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 60 | SNMP_MIB_ITEM("SctpT1InitExpireds", SCTP_MIB_T1_INIT_EXPIREDS), |
| 61 | SNMP_MIB_ITEM("SctpT1CookieExpireds", SCTP_MIB_T1_COOKIE_EXPIREDS), |
| 62 | SNMP_MIB_ITEM("SctpT2ShutdownExpireds", SCTP_MIB_T2_SHUTDOWN_EXPIREDS), |
| 63 | SNMP_MIB_ITEM("SctpT3RtxExpireds", SCTP_MIB_T3_RTX_EXPIREDS), |
| 64 | SNMP_MIB_ITEM("SctpT4RtoExpireds", SCTP_MIB_T4_RTO_EXPIREDS), |
| 65 | SNMP_MIB_ITEM("SctpT5ShutdownGuardExpireds", SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS), |
| 66 | SNMP_MIB_ITEM("SctpDelaySackExpireds", SCTP_MIB_DELAY_SACK_EXPIREDS), |
| 67 | SNMP_MIB_ITEM("SctpAutocloseExpireds", SCTP_MIB_AUTOCLOSE_EXPIREDS), |
| 68 | SNMP_MIB_ITEM("SctpT3Retransmits", SCTP_MIB_T3_RETRANSMITS), |
| 69 | SNMP_MIB_ITEM("SctpPmtudRetransmits", SCTP_MIB_PMTUD_RETRANSMITS), |
| 70 | SNMP_MIB_ITEM("SctpFastRetransmits", SCTP_MIB_FAST_RETRANSMITS), |
| 71 | SNMP_MIB_ITEM("SctpInPktSoftirq", SCTP_MIB_IN_PKT_SOFTIRQ), |
| 72 | SNMP_MIB_ITEM("SctpInPktBacklog", SCTP_MIB_IN_PKT_BACKLOG), |
| 73 | SNMP_MIB_ITEM("SctpInPktDiscards", SCTP_MIB_IN_PKT_DISCARDS), |
| 74 | SNMP_MIB_ITEM("SctpInDataChunkDiscards", SCTP_MIB_IN_DATA_CHUNK_DISCARDS), |
Vlad Yasevich | d2287f8 | 2005-08-23 10:12:04 -0700 | [diff] [blame] | 75 | SNMP_MIB_SENTINEL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | /* Return the current value of a particular entry in the mib by adding its |
| 79 | * per cpu counters. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 80 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | static unsigned long |
| 82 | fold_field(void *mib[], int nr) |
| 83 | { |
| 84 | unsigned long res = 0; |
| 85 | int i; |
| 86 | |
KAMEZAWA Hiroyuki | 6f91204 | 2006-04-10 22:52:50 -0700 | [diff] [blame] | 87 | for_each_possible_cpu(i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | res += |
| 89 | *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) + |
| 90 | sizeof (unsigned long) * nr)); |
| 91 | res += |
| 92 | *((unsigned long *) (((void *) per_cpu_ptr(mib[1], i)) + |
| 93 | sizeof (unsigned long) * nr)); |
| 94 | } |
| 95 | return res; |
| 96 | } |
| 97 | |
| 98 | /* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */ |
| 99 | static int sctp_snmp_seq_show(struct seq_file *seq, void *v) |
| 100 | { |
| 101 | int i; |
| 102 | |
| 103 | for (i = 0; sctp_snmp_list[i].name != NULL; i++) |
| 104 | seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 105 | fold_field((void **)sctp_statistics, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | sctp_snmp_list[i].entry)); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | /* Initialize the seq file operations for 'snmp' object. */ |
| 112 | static int sctp_snmp_seq_open(struct inode *inode, struct file *file) |
| 113 | { |
| 114 | return single_open(file, sctp_snmp_seq_show, NULL); |
| 115 | } |
| 116 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 117 | static const struct file_operations sctp_snmp_seq_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | .owner = THIS_MODULE, |
| 119 | .open = sctp_snmp_seq_open, |
| 120 | .read = seq_read, |
| 121 | .llseek = seq_lseek, |
| 122 | .release = single_release, |
| 123 | }; |
| 124 | |
| 125 | /* Set up the proc fs entry for 'snmp' object. */ |
| 126 | int __init sctp_snmp_proc_init(void) |
| 127 | { |
| 128 | struct proc_dir_entry *p; |
| 129 | |
| 130 | p = create_proc_entry("snmp", S_IRUGO, proc_net_sctp); |
| 131 | if (!p) |
| 132 | return -ENOMEM; |
| 133 | |
| 134 | p->proc_fops = &sctp_snmp_seq_fops; |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | /* Cleanup the proc fs entry for 'snmp' object. */ |
| 140 | void sctp_snmp_proc_exit(void) |
| 141 | { |
| 142 | remove_proc_entry("snmp", proc_net_sctp); |
| 143 | } |
| 144 | |
| 145 | /* Dump local addresses of an association/endpoint. */ |
| 146 | static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_common *epb) |
| 147 | { |
| 148 | struct list_head *pos; |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 149 | struct sctp_association *asoc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | struct sctp_sockaddr_entry *laddr; |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 151 | struct sctp_transport *peer; |
| 152 | union sctp_addr *addr, *primary = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | struct sctp_af *af; |
| 154 | |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 155 | if (epb->type == SCTP_EP_TYPE_ASSOCIATION) { |
| 156 | asoc = sctp_assoc(epb); |
| 157 | peer = asoc->peer.primary_path; |
Al Viro | 5f242a1 | 2006-11-20 17:05:23 -0800 | [diff] [blame] | 158 | primary = &peer->saddr; |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | list_for_each(pos, &epb->bind_addr.address_list) { |
| 162 | laddr = list_entry(pos, struct sctp_sockaddr_entry, list); |
Al Viro | 5f242a1 | 2006-11-20 17:05:23 -0800 | [diff] [blame] | 163 | addr = &laddr->a; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | af = sctp_get_af_specific(addr->sa.sa_family); |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 165 | if (primary && af->cmp_addr(addr, primary)) { |
| 166 | seq_printf(seq, "*"); |
| 167 | } |
Al Viro | 5f242a1 | 2006-11-20 17:05:23 -0800 | [diff] [blame] | 168 | af->seq_dump_addr(seq, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
| 172 | /* Dump remote addresses of an association. */ |
| 173 | static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc) |
| 174 | { |
| 175 | struct list_head *pos; |
| 176 | struct sctp_transport *transport; |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 177 | union sctp_addr *addr, *primary; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | struct sctp_af *af; |
| 179 | |
Al Viro | acd2bc9 | 2006-11-20 17:06:04 -0800 | [diff] [blame] | 180 | primary = &assoc->peer.primary_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | list_for_each(pos, &assoc->peer.transport_addr_list) { |
| 182 | transport = list_entry(pos, struct sctp_transport, transports); |
Al Viro | 5f242a1 | 2006-11-20 17:05:23 -0800 | [diff] [blame] | 183 | addr = &transport->ipaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | af = sctp_get_af_specific(addr->sa.sa_family); |
Al Viro | acd2bc9 | 2006-11-20 17:06:04 -0800 | [diff] [blame] | 185 | if (af->cmp_addr(addr, primary)) { |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 186 | seq_printf(seq, "*"); |
| 187 | } |
Al Viro | 5f242a1 | 2006-11-20 17:05:23 -0800 | [diff] [blame] | 188 | af->seq_dump_addr(seq, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 192 | static void * sctp_eps_seq_start(struct seq_file *seq, loff_t *pos) |
| 193 | { |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 194 | if (*pos >= sctp_ep_hashsize) |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 195 | return NULL; |
| 196 | |
| 197 | if (*pos < 0) |
| 198 | *pos = 0; |
| 199 | |
| 200 | if (*pos == 0) |
| 201 | seq_printf(seq, " ENDPT SOCK STY SST HBKT LPORT UID INODE LADDRS\n"); |
| 202 | |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 203 | return (void *)pos; |
| 204 | } |
| 205 | |
| 206 | static void sctp_eps_seq_stop(struct seq_file *seq, void *v) |
| 207 | { |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | |
| 212 | static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 213 | { |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 214 | if (++*pos >= sctp_ep_hashsize) |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 215 | return NULL; |
| 216 | |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 217 | return pos; |
| 218 | } |
| 219 | |
| 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | /* Display sctp endpoints (/proc/net/sctp/eps). */ |
| 222 | static int sctp_eps_seq_show(struct seq_file *seq, void *v) |
| 223 | { |
| 224 | struct sctp_hashbucket *head; |
| 225 | struct sctp_ep_common *epb; |
| 226 | struct sctp_endpoint *ep; |
| 227 | struct sock *sk; |
Vlad Yasevich | 38b0e42 | 2006-01-17 11:54:06 -0800 | [diff] [blame] | 228 | int hash = *(loff_t *)v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 230 | if (hash >= sctp_ep_hashsize) |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 231 | return -ENOMEM; |
| 232 | |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 233 | head = &sctp_ep_hashtable[hash]; |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 234 | sctp_local_bh_disable(); |
| 235 | read_lock(&head->lock); |
| 236 | for (epb = head->chain; epb; epb = epb->next) { |
| 237 | ep = sctp_ep(epb); |
| 238 | sk = epb->sk; |
| 239 | seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk, |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 240 | sctp_sk(sk)->type, sk->sk_state, hash, |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 241 | epb->bind_addr.port, |
| 242 | sock_i_uid(sk), sock_i_ino(sk)); |
| 243 | |
| 244 | sctp_seq_dump_local_addrs(seq, epb); |
| 245 | seq_printf(seq, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 247 | read_unlock(&head->lock); |
| 248 | sctp_local_bh_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 253 | static const struct seq_operations sctp_eps_ops = { |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 254 | .start = sctp_eps_seq_start, |
| 255 | .next = sctp_eps_seq_next, |
| 256 | .stop = sctp_eps_seq_stop, |
| 257 | .show = sctp_eps_seq_show, |
| 258 | }; |
| 259 | |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | /* Initialize the seq file operations for 'eps' object. */ |
| 262 | static int sctp_eps_seq_open(struct inode *inode, struct file *file) |
| 263 | { |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 264 | return seq_open(file, &sctp_eps_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 267 | static const struct file_operations sctp_eps_seq_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | .open = sctp_eps_seq_open, |
| 269 | .read = seq_read, |
| 270 | .llseek = seq_lseek, |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 271 | .release = seq_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | /* Set up the proc fs entry for 'eps' object. */ |
| 275 | int __init sctp_eps_proc_init(void) |
| 276 | { |
| 277 | struct proc_dir_entry *p; |
| 278 | |
| 279 | p = create_proc_entry("eps", S_IRUGO, proc_net_sctp); |
| 280 | if (!p) |
| 281 | return -ENOMEM; |
| 282 | |
| 283 | p->proc_fops = &sctp_eps_seq_fops; |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | /* Cleanup the proc fs entry for 'eps' object. */ |
| 289 | void sctp_eps_proc_exit(void) |
| 290 | { |
| 291 | remove_proc_entry("eps", proc_net_sctp); |
| 292 | } |
| 293 | |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 294 | |
| 295 | static void * sctp_assocs_seq_start(struct seq_file *seq, loff_t *pos) |
| 296 | { |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 297 | if (*pos >= sctp_assoc_hashsize) |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 298 | return NULL; |
| 299 | |
| 300 | if (*pos < 0) |
| 301 | *pos = 0; |
| 302 | |
| 303 | if (*pos == 0) |
| 304 | seq_printf(seq, " ASSOC SOCK STY SST ST HBKT ASSOC-ID TX_QUEUE RX_QUEUE UID INODE LPORT " |
| 305 | "RPORT LADDRS <-> RADDRS\n"); |
| 306 | |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 307 | return (void *)pos; |
| 308 | } |
| 309 | |
| 310 | static void sctp_assocs_seq_stop(struct seq_file *seq, void *v) |
| 311 | { |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | |
| 316 | static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 317 | { |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 318 | if (++*pos >= sctp_assoc_hashsize) |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 319 | return NULL; |
| 320 | |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 321 | return pos; |
| 322 | } |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* Display sctp associations (/proc/net/sctp/assocs). */ |
| 325 | static int sctp_assocs_seq_show(struct seq_file *seq, void *v) |
| 326 | { |
| 327 | struct sctp_hashbucket *head; |
| 328 | struct sctp_ep_common *epb; |
| 329 | struct sctp_association *assoc; |
| 330 | struct sock *sk; |
Vlad Yasevich | 38b0e42 | 2006-01-17 11:54:06 -0800 | [diff] [blame] | 331 | int hash = *(loff_t *)v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 333 | if (hash >= sctp_assoc_hashsize) |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 334 | return -ENOMEM; |
| 335 | |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 336 | head = &sctp_assoc_hashtable[hash]; |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 337 | sctp_local_bh_disable(); |
| 338 | read_lock(&head->lock); |
| 339 | for (epb = head->chain; epb; epb = epb->next) { |
| 340 | assoc = sctp_assoc(epb); |
| 341 | sk = epb->sk; |
| 342 | seq_printf(seq, |
| 343 | "%8p %8p %-3d %-3d %-2d %-4d %4d %8d %8d %7d %5lu %-5d %5d ", |
| 344 | assoc, sk, sctp_sk(sk)->type, sk->sk_state, |
Vlad Yasevich | 49392e5 | 2006-01-17 11:53:06 -0800 | [diff] [blame] | 345 | assoc->state, hash, assoc->assoc_id, |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 346 | assoc->sndbuf_used, |
Vlad Yasevich | 6aa2551 | 2006-10-09 21:34:26 -0700 | [diff] [blame] | 347 | atomic_read(&assoc->rmem_alloc), |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 348 | sock_i_uid(sk), sock_i_ino(sk), |
| 349 | epb->bind_addr.port, |
| 350 | assoc->peer.port); |
| 351 | |
| 352 | seq_printf(seq, " "); |
| 353 | sctp_seq_dump_local_addrs(seq, epb); |
| 354 | seq_printf(seq, "<-> "); |
| 355 | sctp_seq_dump_remote_addrs(seq, assoc); |
| 356 | seq_printf(seq, "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 358 | read_unlock(&head->lock); |
| 359 | sctp_local_bh_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 364 | static const struct seq_operations sctp_assoc_ops = { |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 365 | .start = sctp_assocs_seq_start, |
| 366 | .next = sctp_assocs_seq_next, |
| 367 | .stop = sctp_assocs_seq_stop, |
| 368 | .show = sctp_assocs_seq_show, |
| 369 | }; |
| 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | /* Initialize the seq file operations for 'assocs' object. */ |
| 372 | static int sctp_assocs_seq_open(struct inode *inode, struct file *file) |
| 373 | { |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 374 | return seq_open(file, &sctp_assoc_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 377 | static const struct file_operations sctp_assocs_seq_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | .open = sctp_assocs_seq_open, |
| 379 | .read = seq_read, |
| 380 | .llseek = seq_lseek, |
Vladislav Yasevich | bca735b | 2005-06-13 15:11:57 -0700 | [diff] [blame] | 381 | .release = seq_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | }; |
| 383 | |
| 384 | /* Set up the proc fs entry for 'assocs' object. */ |
| 385 | int __init sctp_assocs_proc_init(void) |
| 386 | { |
| 387 | struct proc_dir_entry *p; |
| 388 | |
| 389 | p = create_proc_entry("assocs", S_IRUGO, proc_net_sctp); |
| 390 | if (!p) |
| 391 | return -ENOMEM; |
| 392 | |
| 393 | p->proc_fops = &sctp_assocs_seq_fops; |
| 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | /* Cleanup the proc fs entry for 'assocs' object. */ |
| 399 | void sctp_assocs_proc_exit(void) |
| 400 | { |
| 401 | remove_proc_entry("assocs", proc_net_sctp); |
| 402 | } |