Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * proc_llc.c - proc interface for LLC |
| 3 | * |
| 4 | * Copyright (c) 2001 by Jay Schulist <jschlst@samba.org> |
| 5 | * 2002-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 6 | * |
| 7 | * This program can be redistributed or modified under the terms of the |
| 8 | * GNU General Public License as published by the Free Software Foundation. |
| 9 | * This program is distributed without any warranty or implied warranty |
| 10 | * of merchantability or fitness for a particular purpose. |
| 11 | * |
| 12 | * See the GNU General Public License for more details. |
| 13 | */ |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/proc_fs.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/seq_file.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 20 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <net/sock.h> |
| 22 | #include <net/llc.h> |
| 23 | #include <net/llc_c_ac.h> |
| 24 | #include <net/llc_c_ev.h> |
| 25 | #include <net/llc_c_st.h> |
| 26 | #include <net/llc_conn.h> |
| 27 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 28 | static void llc_ui_format_mac(struct seq_file *seq, u8 *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 30 | seq_printf(seq, "%pM", addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static struct sock *llc_get_sk_idx(loff_t pos) |
| 34 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct llc_sap *sap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | struct sock *sk = NULL; |
Octavian Purdila | 52d58ae | 2009-12-26 11:51:05 +0000 | [diff] [blame] | 37 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Octavian Purdila | 8beb9ab | 2009-12-26 11:51:06 +0000 | [diff] [blame] | 39 | list_for_each_entry_rcu(sap, &llc_sap_list, node) { |
Octavian Purdila | b76f5a8 | 2009-12-26 11:51:02 +0000 | [diff] [blame] | 40 | spin_lock_bh(&sap->sk_lock); |
Octavian Purdila | 52d58ae | 2009-12-26 11:51:05 +0000 | [diff] [blame] | 41 | for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) { |
| 42 | struct hlist_nulls_head *head = &sap->sk_laddr_hash[i]; |
| 43 | struct hlist_nulls_node *node; |
| 44 | |
| 45 | sk_nulls_for_each(sk, node, head) { |
| 46 | if (!pos) |
| 47 | goto found; /* keep the lock */ |
| 48 | --pos; |
| 49 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
Octavian Purdila | b76f5a8 | 2009-12-26 11:51:02 +0000 | [diff] [blame] | 51 | spin_unlock_bh(&sap->sk_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | sk = NULL; |
| 54 | found: |
| 55 | return sk; |
| 56 | } |
| 57 | |
| 58 | static void *llc_seq_start(struct seq_file *seq, loff_t *pos) |
| 59 | { |
| 60 | loff_t l = *pos; |
| 61 | |
Octavian Purdila | 8beb9ab | 2009-12-26 11:51:06 +0000 | [diff] [blame] | 62 | rcu_read_lock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN; |
| 64 | } |
| 65 | |
Octavian Purdila | 52d58ae | 2009-12-26 11:51:05 +0000 | [diff] [blame] | 66 | static struct sock *laddr_hash_next(struct llc_sap *sap, int bucket) |
| 67 | { |
| 68 | struct hlist_nulls_node *node; |
| 69 | struct sock *sk = NULL; |
| 70 | |
| 71 | while (++bucket < LLC_SK_LADDR_HASH_ENTRIES) |
| 72 | sk_nulls_for_each(sk, node, &sap->sk_laddr_hash[bucket]) |
| 73 | goto out; |
| 74 | |
| 75 | out: |
| 76 | return sk; |
| 77 | } |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 80 | { |
| 81 | struct sock* sk, *next; |
| 82 | struct llc_sock *llc; |
| 83 | struct llc_sap *sap; |
| 84 | |
| 85 | ++*pos; |
| 86 | if (v == SEQ_START_TOKEN) { |
| 87 | sk = llc_get_sk_idx(0); |
| 88 | goto out; |
| 89 | } |
| 90 | sk = v; |
Octavian Purdila | b76f5a8 | 2009-12-26 11:51:02 +0000 | [diff] [blame] | 91 | next = sk_nulls_next(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (next) { |
| 93 | sk = next; |
| 94 | goto out; |
| 95 | } |
| 96 | llc = llc_sk(sk); |
| 97 | sap = llc->sap; |
Octavian Purdila | 52d58ae | 2009-12-26 11:51:05 +0000 | [diff] [blame] | 98 | sk = laddr_hash_next(sap, llc_sk_laddr_hashfn(sap, &llc->laddr)); |
| 99 | if (sk) |
| 100 | goto out; |
Octavian Purdila | b76f5a8 | 2009-12-26 11:51:02 +0000 | [diff] [blame] | 101 | spin_unlock_bh(&sap->sk_lock); |
Octavian Purdila | 8beb9ab | 2009-12-26 11:51:06 +0000 | [diff] [blame] | 102 | list_for_each_entry_continue_rcu(sap, &llc_sap_list, node) { |
Octavian Purdila | b76f5a8 | 2009-12-26 11:51:02 +0000 | [diff] [blame] | 103 | spin_lock_bh(&sap->sk_lock); |
Octavian Purdila | 52d58ae | 2009-12-26 11:51:05 +0000 | [diff] [blame] | 104 | sk = laddr_hash_next(sap, -1); |
| 105 | if (sk) |
| 106 | break; /* keep the lock */ |
Octavian Purdila | b76f5a8 | 2009-12-26 11:51:02 +0000 | [diff] [blame] | 107 | spin_unlock_bh(&sap->sk_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | out: |
| 110 | return sk; |
| 111 | } |
| 112 | |
| 113 | static void llc_seq_stop(struct seq_file *seq, void *v) |
| 114 | { |
| 115 | if (v && v != SEQ_START_TOKEN) { |
| 116 | struct sock *sk = v; |
| 117 | struct llc_sock *llc = llc_sk(sk); |
| 118 | struct llc_sap *sap = llc->sap; |
| 119 | |
Octavian Purdila | b76f5a8 | 2009-12-26 11:51:02 +0000 | [diff] [blame] | 120 | spin_unlock_bh(&sap->sk_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
Octavian Purdila | 8beb9ab | 2009-12-26 11:51:06 +0000 | [diff] [blame] | 122 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static int llc_seq_socket_show(struct seq_file *seq, void *v) |
| 126 | { |
| 127 | struct sock* sk; |
| 128 | struct llc_sock *llc; |
| 129 | |
| 130 | if (v == SEQ_START_TOKEN) { |
| 131 | seq_puts(seq, "SKt Mc local_mac_sap remote_mac_sap " |
| 132 | " tx_queue rx_queue st uid link\n"); |
| 133 | goto out; |
| 134 | } |
| 135 | sk = v; |
| 136 | llc = llc_sk(sk); |
| 137 | |
| 138 | /* FIXME: check if the address is multicast */ |
| 139 | seq_printf(seq, "%2X %2X ", sk->sk_type, 0); |
| 140 | |
| 141 | if (llc->dev) |
| 142 | llc_ui_format_mac(seq, llc->dev->dev_addr); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 143 | else { |
| 144 | u8 addr[6] = {0,0,0,0,0,0}; |
| 145 | llc_ui_format_mac(seq, addr); |
| 146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | seq_printf(seq, "@%02X ", llc->sap->laddr.lsap); |
| 148 | llc_ui_format_mac(seq, llc->daddr.mac); |
| 149 | seq_printf(seq, "@%02X %8d %8d %2d %3d %4d\n", llc->daddr.lsap, |
Eric Dumazet | 31e6d36 | 2009-06-17 19:05:41 -0700 | [diff] [blame] | 150 | sk_wmem_alloc_get(sk), |
| 151 | sk_rmem_alloc_get(sk) - llc->copied_seq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | sk->sk_state, |
| 153 | sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : -1, |
| 154 | llc->link); |
| 155 | out: |
| 156 | return 0; |
| 157 | } |
| 158 | |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 159 | static const char *const llc_conn_state_names[] = { |
YOSHIFUJI Hideaki | d57b186 | 2007-02-09 23:25:01 +0900 | [diff] [blame] | 160 | [LLC_CONN_STATE_ADM] = "adm", |
| 161 | [LLC_CONN_STATE_SETUP] = "setup", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | [LLC_CONN_STATE_NORMAL] = "normal", |
YOSHIFUJI Hideaki | d57b186 | 2007-02-09 23:25:01 +0900 | [diff] [blame] | 163 | [LLC_CONN_STATE_BUSY] = "busy", |
| 164 | [LLC_CONN_STATE_REJ] = "rej", |
| 165 | [LLC_CONN_STATE_AWAIT] = "await", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | [LLC_CONN_STATE_AWAIT_BUSY] = "await_busy", |
| 167 | [LLC_CONN_STATE_AWAIT_REJ] = "await_rej", |
| 168 | [LLC_CONN_STATE_D_CONN] = "d_conn", |
YOSHIFUJI Hideaki | d57b186 | 2007-02-09 23:25:01 +0900 | [diff] [blame] | 169 | [LLC_CONN_STATE_RESET] = "reset", |
| 170 | [LLC_CONN_STATE_ERROR] = "error", |
| 171 | [LLC_CONN_STATE_TEMP] = "temp", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | static int llc_seq_core_show(struct seq_file *seq, void *v) |
| 175 | { |
| 176 | struct sock* sk; |
| 177 | struct llc_sock *llc; |
| 178 | |
| 179 | if (v == SEQ_START_TOKEN) { |
| 180 | seq_puts(seq, "Connection list:\n" |
| 181 | "dsap state retr txw rxw pf ff sf df rs cs " |
| 182 | "tack tpfc trs tbs blog busr\n"); |
| 183 | goto out; |
| 184 | } |
| 185 | sk = v; |
| 186 | llc = llc_sk(sk); |
| 187 | |
| 188 | seq_printf(seq, " %02X %-10s %3d %3d %3d %2d %2d %2d %2d %2d %2d " |
| 189 | "%4d %4d %3d %3d %4d %4d\n", |
| 190 | llc->daddr.lsap, llc_conn_state_names[llc->state], |
| 191 | llc->retry_count, llc->k, llc->rw, llc->p_flag, llc->f_flag, |
| 192 | llc->s_flag, llc->data_flag, llc->remote_busy_flag, |
| 193 | llc->cause_flag, timer_pending(&llc->ack_timer.timer), |
| 194 | timer_pending(&llc->pf_cycle_timer.timer), |
| 195 | timer_pending(&llc->rej_sent_timer.timer), |
| 196 | timer_pending(&llc->busy_state_timer.timer), |
| 197 | !!sk->sk_backlog.tail, !!sock_owned_by_user(sk)); |
| 198 | out: |
| 199 | return 0; |
| 200 | } |
| 201 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 202 | static const struct seq_operations llc_seq_socket_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | .start = llc_seq_start, |
| 204 | .next = llc_seq_next, |
| 205 | .stop = llc_seq_stop, |
| 206 | .show = llc_seq_socket_show, |
| 207 | }; |
| 208 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 209 | static const struct seq_operations llc_seq_core_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | .start = llc_seq_start, |
| 211 | .next = llc_seq_next, |
| 212 | .stop = llc_seq_stop, |
| 213 | .show = llc_seq_core_show, |
| 214 | }; |
| 215 | |
| 216 | static int llc_seq_socket_open(struct inode *inode, struct file *file) |
| 217 | { |
| 218 | return seq_open(file, &llc_seq_socket_ops); |
| 219 | } |
| 220 | |
| 221 | static int llc_seq_core_open(struct inode *inode, struct file *file) |
| 222 | { |
| 223 | return seq_open(file, &llc_seq_core_ops); |
| 224 | } |
| 225 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 226 | static const struct file_operations llc_seq_socket_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | .owner = THIS_MODULE, |
| 228 | .open = llc_seq_socket_open, |
| 229 | .read = seq_read, |
| 230 | .llseek = seq_lseek, |
| 231 | .release = seq_release, |
| 232 | }; |
| 233 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 234 | static const struct file_operations llc_seq_core_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | .owner = THIS_MODULE, |
| 236 | .open = llc_seq_core_open, |
| 237 | .read = seq_read, |
| 238 | .llseek = seq_lseek, |
| 239 | .release = seq_release, |
| 240 | }; |
| 241 | |
| 242 | static struct proc_dir_entry *llc_proc_dir; |
| 243 | |
| 244 | int __init llc_proc_init(void) |
| 245 | { |
| 246 | int rc = -ENOMEM; |
| 247 | struct proc_dir_entry *p; |
| 248 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 249 | llc_proc_dir = proc_mkdir("llc", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | if (!llc_proc_dir) |
| 251 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Wang Chen | 7e02180 | 2008-02-28 14:08:54 -0800 | [diff] [blame] | 253 | p = proc_create("socket", S_IRUGO, llc_proc_dir, &llc_seq_socket_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | if (!p) |
| 255 | goto out_socket; |
| 256 | |
Wang Chen | 7e02180 | 2008-02-28 14:08:54 -0800 | [diff] [blame] | 257 | p = proc_create("core", S_IRUGO, llc_proc_dir, &llc_seq_core_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (!p) |
| 259 | goto out_core; |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | rc = 0; |
| 262 | out: |
| 263 | return rc; |
| 264 | out_core: |
| 265 | remove_proc_entry("socket", llc_proc_dir); |
| 266 | out_socket: |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 267 | remove_proc_entry("llc", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | goto out; |
| 269 | } |
| 270 | |
| 271 | void llc_proc_exit(void) |
| 272 | { |
| 273 | remove_proc_entry("socket", llc_proc_dir); |
| 274 | remove_proc_entry("core", llc_proc_dir); |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 275 | remove_proc_entry("llc", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |