blob: a1839c004357a854ca7ee50592584fb66617b441 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070015#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>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040020#include <linux/export.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020021#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <net/sock.h>
23#include <net/llc.h>
24#include <net/llc_c_ac.h>
25#include <net/llc_c_ev.h>
26#include <net/llc_c_st.h>
27#include <net/llc_conn.h>
28
Joe Perches0795af52007-10-03 17:59:30 -070029static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Johannes Berge1749612008-10-27 15:59:26 -070031 seq_printf(seq, "%pM", addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032}
33
34static struct sock *llc_get_sk_idx(loff_t pos)
35{
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 struct llc_sap *sap;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 struct sock *sk = NULL;
Octavian Purdila52d58ae2009-12-26 11:51:05 +000038 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Octavian Purdila8beb9ab2009-12-26 11:51:06 +000040 list_for_each_entry_rcu(sap, &llc_sap_list, node) {
Octavian Purdilab76f5a82009-12-26 11:51:02 +000041 spin_lock_bh(&sap->sk_lock);
Octavian Purdila52d58ae2009-12-26 11:51:05 +000042 for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) {
43 struct hlist_nulls_head *head = &sap->sk_laddr_hash[i];
44 struct hlist_nulls_node *node;
45
46 sk_nulls_for_each(sk, node, head) {
47 if (!pos)
48 goto found; /* keep the lock */
49 --pos;
50 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 }
Octavian Purdilab76f5a82009-12-26 11:51:02 +000052 spin_unlock_bh(&sap->sk_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 }
54 sk = NULL;
55found:
56 return sk;
57}
58
59static void *llc_seq_start(struct seq_file *seq, loff_t *pos)
60{
61 loff_t l = *pos;
62
Octavian Purdila8beb9ab2009-12-26 11:51:06 +000063 rcu_read_lock_bh();
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN;
65}
66
Octavian Purdila52d58ae2009-12-26 11:51:05 +000067static struct sock *laddr_hash_next(struct llc_sap *sap, int bucket)
68{
69 struct hlist_nulls_node *node;
70 struct sock *sk = NULL;
71
72 while (++bucket < LLC_SK_LADDR_HASH_ENTRIES)
73 sk_nulls_for_each(sk, node, &sap->sk_laddr_hash[bucket])
74 goto out;
75
76out:
77 return sk;
78}
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
81{
82 struct sock* sk, *next;
83 struct llc_sock *llc;
84 struct llc_sap *sap;
85
86 ++*pos;
87 if (v == SEQ_START_TOKEN) {
88 sk = llc_get_sk_idx(0);
89 goto out;
90 }
91 sk = v;
Octavian Purdilab76f5a82009-12-26 11:51:02 +000092 next = sk_nulls_next(sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (next) {
94 sk = next;
95 goto out;
96 }
97 llc = llc_sk(sk);
98 sap = llc->sap;
Octavian Purdila52d58ae2009-12-26 11:51:05 +000099 sk = laddr_hash_next(sap, llc_sk_laddr_hashfn(sap, &llc->laddr));
100 if (sk)
101 goto out;
Octavian Purdilab76f5a82009-12-26 11:51:02 +0000102 spin_unlock_bh(&sap->sk_lock);
Octavian Purdila8beb9ab2009-12-26 11:51:06 +0000103 list_for_each_entry_continue_rcu(sap, &llc_sap_list, node) {
Octavian Purdilab76f5a82009-12-26 11:51:02 +0000104 spin_lock_bh(&sap->sk_lock);
Octavian Purdila52d58ae2009-12-26 11:51:05 +0000105 sk = laddr_hash_next(sap, -1);
106 if (sk)
107 break; /* keep the lock */
Octavian Purdilab76f5a82009-12-26 11:51:02 +0000108 spin_unlock_bh(&sap->sk_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 }
110out:
111 return sk;
112}
113
114static void llc_seq_stop(struct seq_file *seq, void *v)
115{
116 if (v && v != SEQ_START_TOKEN) {
117 struct sock *sk = v;
118 struct llc_sock *llc = llc_sk(sk);
119 struct llc_sap *sap = llc->sap;
120
Octavian Purdilab76f5a82009-12-26 11:51:02 +0000121 spin_unlock_bh(&sap->sk_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
Octavian Purdila8beb9ab2009-12-26 11:51:06 +0000123 rcu_read_unlock_bh();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
126static int llc_seq_socket_show(struct seq_file *seq, void *v)
127{
128 struct sock* sk;
129 struct llc_sock *llc;
130
131 if (v == SEQ_START_TOKEN) {
132 seq_puts(seq, "SKt Mc local_mac_sap remote_mac_sap "
133 " tx_queue rx_queue st uid link\n");
134 goto out;
135 }
136 sk = v;
137 llc = llc_sk(sk);
138
139 /* FIXME: check if the address is multicast */
140 seq_printf(seq, "%2X %2X ", sk->sk_type, 0);
141
142 if (llc->dev)
143 llc_ui_format_mac(seq, llc->dev->dev_addr);
Joe Perches0795af52007-10-03 17:59:30 -0700144 else {
145 u8 addr[6] = {0,0,0,0,0,0};
146 llc_ui_format_mac(seq, addr);
147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 seq_printf(seq, "@%02X ", llc->sap->laddr.lsap);
149 llc_ui_format_mac(seq, llc->daddr.mac);
150 seq_printf(seq, "@%02X %8d %8d %2d %3d %4d\n", llc->daddr.lsap,
Eric Dumazet31e6d362009-06-17 19:05:41 -0700151 sk_wmem_alloc_get(sk),
152 sk_rmem_alloc_get(sk) - llc->copied_seq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 sk->sk_state,
154 sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : -1,
155 llc->link);
156out:
157 return 0;
158}
159
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700160static const char *const llc_conn_state_names[] = {
YOSHIFUJI Hideakid57b1862007-02-09 23:25:01 +0900161 [LLC_CONN_STATE_ADM] = "adm",
162 [LLC_CONN_STATE_SETUP] = "setup",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 [LLC_CONN_STATE_NORMAL] = "normal",
YOSHIFUJI Hideakid57b1862007-02-09 23:25:01 +0900164 [LLC_CONN_STATE_BUSY] = "busy",
165 [LLC_CONN_STATE_REJ] = "rej",
166 [LLC_CONN_STATE_AWAIT] = "await",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 [LLC_CONN_STATE_AWAIT_BUSY] = "await_busy",
168 [LLC_CONN_STATE_AWAIT_REJ] = "await_rej",
169 [LLC_CONN_STATE_D_CONN] = "d_conn",
YOSHIFUJI Hideakid57b1862007-02-09 23:25:01 +0900170 [LLC_CONN_STATE_RESET] = "reset",
171 [LLC_CONN_STATE_ERROR] = "error",
172 [LLC_CONN_STATE_TEMP] = "temp",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
175static int llc_seq_core_show(struct seq_file *seq, void *v)
176{
177 struct sock* sk;
178 struct llc_sock *llc;
179
180 if (v == SEQ_START_TOKEN) {
181 seq_puts(seq, "Connection list:\n"
182 "dsap state retr txw rxw pf ff sf df rs cs "
183 "tack tpfc trs tbs blog busr\n");
184 goto out;
185 }
186 sk = v;
187 llc = llc_sk(sk);
188
189 seq_printf(seq, " %02X %-10s %3d %3d %3d %2d %2d %2d %2d %2d %2d "
190 "%4d %4d %3d %3d %4d %4d\n",
191 llc->daddr.lsap, llc_conn_state_names[llc->state],
192 llc->retry_count, llc->k, llc->rw, llc->p_flag, llc->f_flag,
193 llc->s_flag, llc->data_flag, llc->remote_busy_flag,
194 llc->cause_flag, timer_pending(&llc->ack_timer.timer),
195 timer_pending(&llc->pf_cycle_timer.timer),
196 timer_pending(&llc->rej_sent_timer.timer),
197 timer_pending(&llc->busy_state_timer.timer),
198 !!sk->sk_backlog.tail, !!sock_owned_by_user(sk));
199out:
200 return 0;
201}
202
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700203static const struct seq_operations llc_seq_socket_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 .start = llc_seq_start,
205 .next = llc_seq_next,
206 .stop = llc_seq_stop,
207 .show = llc_seq_socket_show,
208};
209
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700210static const struct seq_operations llc_seq_core_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 .start = llc_seq_start,
212 .next = llc_seq_next,
213 .stop = llc_seq_stop,
214 .show = llc_seq_core_show,
215};
216
217static int llc_seq_socket_open(struct inode *inode, struct file *file)
218{
219 return seq_open(file, &llc_seq_socket_ops);
220}
221
222static int llc_seq_core_open(struct inode *inode, struct file *file)
223{
224 return seq_open(file, &llc_seq_core_ops);
225}
226
Arjan van de Venda7071d2007-02-12 00:55:36 -0800227static const struct file_operations llc_seq_socket_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 .owner = THIS_MODULE,
229 .open = llc_seq_socket_open,
230 .read = seq_read,
231 .llseek = seq_lseek,
232 .release = seq_release,
233};
234
Arjan van de Venda7071d2007-02-12 00:55:36 -0800235static const struct file_operations llc_seq_core_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 .owner = THIS_MODULE,
237 .open = llc_seq_core_open,
238 .read = seq_read,
239 .llseek = seq_lseek,
240 .release = seq_release,
241};
242
243static struct proc_dir_entry *llc_proc_dir;
244
245int __init llc_proc_init(void)
246{
247 int rc = -ENOMEM;
248 struct proc_dir_entry *p;
249
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200250 llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (!llc_proc_dir)
252 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Wang Chen7e021802008-02-28 14:08:54 -0800254 p = proc_create("socket", S_IRUGO, llc_proc_dir, &llc_seq_socket_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 if (!p)
256 goto out_socket;
257
Wang Chen7e021802008-02-28 14:08:54 -0800258 p = proc_create("core", S_IRUGO, llc_proc_dir, &llc_seq_core_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 if (!p)
260 goto out_core;
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 rc = 0;
263out:
264 return rc;
265out_core:
266 remove_proc_entry("socket", llc_proc_dir);
267out_socket:
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200268 remove_proc_entry("llc", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 goto out;
270}
271
272void llc_proc_exit(void)
273{
274 remove_proc_entry("socket", llc_proc_dir);
275 remove_proc_entry("core", llc_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200276 remove_proc_entry("llc", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}