blob: be47ac427f6b23afc23888081ab1edf89346c280 [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>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020020#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#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 Perches0795af52007-10-03 17:59:30 -070028static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
Johannes Berge1749612008-10-27 15:59:26 -070030 seq_printf(seq, "%pM", addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031}
32
33static struct sock *llc_get_sk_idx(loff_t pos)
34{
35 struct list_head *sap_entry;
36 struct llc_sap *sap;
37 struct hlist_node *node;
38 struct sock *sk = NULL;
39
40 list_for_each(sap_entry, &llc_sap_list) {
41 sap = list_entry(sap_entry, struct llc_sap, node);
42
43 read_lock_bh(&sap->sk_list.lock);
44 sk_for_each(sk, node, &sap->sk_list.list) {
45 if (!pos)
46 goto found;
47 --pos;
48 }
49 read_unlock_bh(&sap->sk_list.lock);
50 }
51 sk = NULL;
52found:
53 return sk;
54}
55
56static void *llc_seq_start(struct seq_file *seq, loff_t *pos)
57{
58 loff_t l = *pos;
59
60 read_lock_bh(&llc_sap_list_lock);
61 return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN;
62}
63
64static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
65{
66 struct sock* sk, *next;
67 struct llc_sock *llc;
68 struct llc_sap *sap;
69
70 ++*pos;
71 if (v == SEQ_START_TOKEN) {
72 sk = llc_get_sk_idx(0);
73 goto out;
74 }
75 sk = v;
76 next = sk_next(sk);
77 if (next) {
78 sk = next;
79 goto out;
80 }
81 llc = llc_sk(sk);
82 sap = llc->sap;
83 read_unlock_bh(&sap->sk_list.lock);
84 sk = NULL;
85 for (;;) {
86 if (sap->node.next == &llc_sap_list)
87 break;
88 sap = list_entry(sap->node.next, struct llc_sap, node);
89 read_lock_bh(&sap->sk_list.lock);
90 if (!hlist_empty(&sap->sk_list.list)) {
91 sk = sk_head(&sap->sk_list.list);
92 break;
93 }
94 read_unlock_bh(&sap->sk_list.lock);
95 }
96out:
97 return sk;
98}
99
100static void llc_seq_stop(struct seq_file *seq, void *v)
101{
102 if (v && v != SEQ_START_TOKEN) {
103 struct sock *sk = v;
104 struct llc_sock *llc = llc_sk(sk);
105 struct llc_sap *sap = llc->sap;
106
107 read_unlock_bh(&sap->sk_list.lock);
108 }
109 read_unlock_bh(&llc_sap_list_lock);
110}
111
112static int llc_seq_socket_show(struct seq_file *seq, void *v)
113{
114 struct sock* sk;
115 struct llc_sock *llc;
116
117 if (v == SEQ_START_TOKEN) {
118 seq_puts(seq, "SKt Mc local_mac_sap remote_mac_sap "
119 " tx_queue rx_queue st uid link\n");
120 goto out;
121 }
122 sk = v;
123 llc = llc_sk(sk);
124
125 /* FIXME: check if the address is multicast */
126 seq_printf(seq, "%2X %2X ", sk->sk_type, 0);
127
128 if (llc->dev)
129 llc_ui_format_mac(seq, llc->dev->dev_addr);
Joe Perches0795af52007-10-03 17:59:30 -0700130 else {
131 u8 addr[6] = {0,0,0,0,0,0};
132 llc_ui_format_mac(seq, addr);
133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 seq_printf(seq, "@%02X ", llc->sap->laddr.lsap);
135 llc_ui_format_mac(seq, llc->daddr.mac);
136 seq_printf(seq, "@%02X %8d %8d %2d %3d %4d\n", llc->daddr.lsap,
Eric Dumazet31e6d362009-06-17 19:05:41 -0700137 sk_wmem_alloc_get(sk),
138 sk_rmem_alloc_get(sk) - llc->copied_seq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 sk->sk_state,
140 sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : -1,
141 llc->link);
142out:
143 return 0;
144}
145
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700146static const char *const llc_conn_state_names[] = {
YOSHIFUJI Hideakid57b1862007-02-09 23:25:01 +0900147 [LLC_CONN_STATE_ADM] = "adm",
148 [LLC_CONN_STATE_SETUP] = "setup",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 [LLC_CONN_STATE_NORMAL] = "normal",
YOSHIFUJI Hideakid57b1862007-02-09 23:25:01 +0900150 [LLC_CONN_STATE_BUSY] = "busy",
151 [LLC_CONN_STATE_REJ] = "rej",
152 [LLC_CONN_STATE_AWAIT] = "await",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 [LLC_CONN_STATE_AWAIT_BUSY] = "await_busy",
154 [LLC_CONN_STATE_AWAIT_REJ] = "await_rej",
155 [LLC_CONN_STATE_D_CONN] = "d_conn",
YOSHIFUJI Hideakid57b1862007-02-09 23:25:01 +0900156 [LLC_CONN_STATE_RESET] = "reset",
157 [LLC_CONN_STATE_ERROR] = "error",
158 [LLC_CONN_STATE_TEMP] = "temp",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
161static int llc_seq_core_show(struct seq_file *seq, void *v)
162{
163 struct sock* sk;
164 struct llc_sock *llc;
165
166 if (v == SEQ_START_TOKEN) {
167 seq_puts(seq, "Connection list:\n"
168 "dsap state retr txw rxw pf ff sf df rs cs "
169 "tack tpfc trs tbs blog busr\n");
170 goto out;
171 }
172 sk = v;
173 llc = llc_sk(sk);
174
175 seq_printf(seq, " %02X %-10s %3d %3d %3d %2d %2d %2d %2d %2d %2d "
176 "%4d %4d %3d %3d %4d %4d\n",
177 llc->daddr.lsap, llc_conn_state_names[llc->state],
178 llc->retry_count, llc->k, llc->rw, llc->p_flag, llc->f_flag,
179 llc->s_flag, llc->data_flag, llc->remote_busy_flag,
180 llc->cause_flag, timer_pending(&llc->ack_timer.timer),
181 timer_pending(&llc->pf_cycle_timer.timer),
182 timer_pending(&llc->rej_sent_timer.timer),
183 timer_pending(&llc->busy_state_timer.timer),
184 !!sk->sk_backlog.tail, !!sock_owned_by_user(sk));
185out:
186 return 0;
187}
188
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700189static const struct seq_operations llc_seq_socket_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 .start = llc_seq_start,
191 .next = llc_seq_next,
192 .stop = llc_seq_stop,
193 .show = llc_seq_socket_show,
194};
195
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700196static const struct seq_operations llc_seq_core_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 .start = llc_seq_start,
198 .next = llc_seq_next,
199 .stop = llc_seq_stop,
200 .show = llc_seq_core_show,
201};
202
203static int llc_seq_socket_open(struct inode *inode, struct file *file)
204{
205 return seq_open(file, &llc_seq_socket_ops);
206}
207
208static int llc_seq_core_open(struct inode *inode, struct file *file)
209{
210 return seq_open(file, &llc_seq_core_ops);
211}
212
Arjan van de Venda7071d2007-02-12 00:55:36 -0800213static const struct file_operations llc_seq_socket_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .owner = THIS_MODULE,
215 .open = llc_seq_socket_open,
216 .read = seq_read,
217 .llseek = seq_lseek,
218 .release = seq_release,
219};
220
Arjan van de Venda7071d2007-02-12 00:55:36 -0800221static const struct file_operations llc_seq_core_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 .owner = THIS_MODULE,
223 .open = llc_seq_core_open,
224 .read = seq_read,
225 .llseek = seq_lseek,
226 .release = seq_release,
227};
228
229static struct proc_dir_entry *llc_proc_dir;
230
231int __init llc_proc_init(void)
232{
233 int rc = -ENOMEM;
234 struct proc_dir_entry *p;
235
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200236 llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 if (!llc_proc_dir)
238 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Wang Chen7e021802008-02-28 14:08:54 -0800240 p = proc_create("socket", S_IRUGO, llc_proc_dir, &llc_seq_socket_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if (!p)
242 goto out_socket;
243
Wang Chen7e021802008-02-28 14:08:54 -0800244 p = proc_create("core", S_IRUGO, llc_proc_dir, &llc_seq_core_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 if (!p)
246 goto out_core;
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 rc = 0;
249out:
250 return rc;
251out_core:
252 remove_proc_entry("socket", llc_proc_dir);
253out_socket:
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200254 remove_proc_entry("llc", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 goto out;
256}
257
258void llc_proc_exit(void)
259{
260 remove_proc_entry("socket", llc_proc_dir);
261 remove_proc_entry("core", llc_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200262 remove_proc_entry("llc", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}