2 * proc_llc.c - proc interface for LLC
4 * Copyright (c) 2001 by Jay Schulist <jschlst@samba.org>
5 * 2002-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
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.
12 * See the GNU General Public License for more details.
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>
20 #include <net/net_namespace.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>
28 static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)
30 seq_printf(seq, "%pM", addr);
33 static struct sock *llc_get_sk_idx(loff_t pos)
35 struct list_head *sap_entry;
37 struct sock *sk = NULL;
40 list_for_each(sap_entry, &llc_sap_list) {
41 sap = list_entry(sap_entry, struct llc_sap, node);
43 spin_lock_bh(&sap->sk_lock);
44 for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) {
45 struct hlist_nulls_head *head = &sap->sk_laddr_hash[i];
46 struct hlist_nulls_node *node;
48 sk_nulls_for_each(sk, node, head) {
50 goto found; /* keep the lock */
54 spin_unlock_bh(&sap->sk_lock);
61 static void *llc_seq_start(struct seq_file *seq, loff_t *pos)
65 read_lock_bh(&llc_sap_list_lock);
66 return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN;
69 static struct sock *laddr_hash_next(struct llc_sap *sap, int bucket)
71 struct hlist_nulls_node *node;
72 struct sock *sk = NULL;
74 while (++bucket < LLC_SK_LADDR_HASH_ENTRIES)
75 sk_nulls_for_each(sk, node, &sap->sk_laddr_hash[bucket])
82 static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
84 struct sock* sk, *next;
89 if (v == SEQ_START_TOKEN) {
90 sk = llc_get_sk_idx(0);
94 next = sk_nulls_next(sk);
101 sk = laddr_hash_next(sap, llc_sk_laddr_hashfn(sap, &llc->laddr));
104 spin_unlock_bh(&sap->sk_lock);
105 list_for_each_entry_continue(sap, &llc_sap_list, node) {
106 spin_lock_bh(&sap->sk_lock);
107 sk = laddr_hash_next(sap, -1);
109 break; /* keep the lock */
110 spin_unlock_bh(&sap->sk_lock);
116 static void llc_seq_stop(struct seq_file *seq, void *v)
118 if (v && v != SEQ_START_TOKEN) {
120 struct llc_sock *llc = llc_sk(sk);
121 struct llc_sap *sap = llc->sap;
123 spin_unlock_bh(&sap->sk_lock);
125 read_unlock_bh(&llc_sap_list_lock);
128 static int llc_seq_socket_show(struct seq_file *seq, void *v)
131 struct llc_sock *llc;
133 if (v == SEQ_START_TOKEN) {
134 seq_puts(seq, "SKt Mc local_mac_sap remote_mac_sap "
135 " tx_queue rx_queue st uid link\n");
141 /* FIXME: check if the address is multicast */
142 seq_printf(seq, "%2X %2X ", sk->sk_type, 0);
145 llc_ui_format_mac(seq, llc->dev->dev_addr);
147 u8 addr[6] = {0,0,0,0,0,0};
148 llc_ui_format_mac(seq, addr);
150 seq_printf(seq, "@%02X ", llc->sap->laddr.lsap);
151 llc_ui_format_mac(seq, llc->daddr.mac);
152 seq_printf(seq, "@%02X %8d %8d %2d %3d %4d\n", llc->daddr.lsap,
153 sk_wmem_alloc_get(sk),
154 sk_rmem_alloc_get(sk) - llc->copied_seq,
156 sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : -1,
162 static const char *const llc_conn_state_names[] = {
163 [LLC_CONN_STATE_ADM] = "adm",
164 [LLC_CONN_STATE_SETUP] = "setup",
165 [LLC_CONN_STATE_NORMAL] = "normal",
166 [LLC_CONN_STATE_BUSY] = "busy",
167 [LLC_CONN_STATE_REJ] = "rej",
168 [LLC_CONN_STATE_AWAIT] = "await",
169 [LLC_CONN_STATE_AWAIT_BUSY] = "await_busy",
170 [LLC_CONN_STATE_AWAIT_REJ] = "await_rej",
171 [LLC_CONN_STATE_D_CONN] = "d_conn",
172 [LLC_CONN_STATE_RESET] = "reset",
173 [LLC_CONN_STATE_ERROR] = "error",
174 [LLC_CONN_STATE_TEMP] = "temp",
177 static int llc_seq_core_show(struct seq_file *seq, void *v)
180 struct llc_sock *llc;
182 if (v == SEQ_START_TOKEN) {
183 seq_puts(seq, "Connection list:\n"
184 "dsap state retr txw rxw pf ff sf df rs cs "
185 "tack tpfc trs tbs blog busr\n");
191 seq_printf(seq, " %02X %-10s %3d %3d %3d %2d %2d %2d %2d %2d %2d "
192 "%4d %4d %3d %3d %4d %4d\n",
193 llc->daddr.lsap, llc_conn_state_names[llc->state],
194 llc->retry_count, llc->k, llc->rw, llc->p_flag, llc->f_flag,
195 llc->s_flag, llc->data_flag, llc->remote_busy_flag,
196 llc->cause_flag, timer_pending(&llc->ack_timer.timer),
197 timer_pending(&llc->pf_cycle_timer.timer),
198 timer_pending(&llc->rej_sent_timer.timer),
199 timer_pending(&llc->busy_state_timer.timer),
200 !!sk->sk_backlog.tail, !!sock_owned_by_user(sk));
205 static const struct seq_operations llc_seq_socket_ops = {
206 .start = llc_seq_start,
207 .next = llc_seq_next,
208 .stop = llc_seq_stop,
209 .show = llc_seq_socket_show,
212 static const struct seq_operations llc_seq_core_ops = {
213 .start = llc_seq_start,
214 .next = llc_seq_next,
215 .stop = llc_seq_stop,
216 .show = llc_seq_core_show,
219 static int llc_seq_socket_open(struct inode *inode, struct file *file)
221 return seq_open(file, &llc_seq_socket_ops);
224 static int llc_seq_core_open(struct inode *inode, struct file *file)
226 return seq_open(file, &llc_seq_core_ops);
229 static const struct file_operations llc_seq_socket_fops = {
230 .owner = THIS_MODULE,
231 .open = llc_seq_socket_open,
234 .release = seq_release,
237 static const struct file_operations llc_seq_core_fops = {
238 .owner = THIS_MODULE,
239 .open = llc_seq_core_open,
242 .release = seq_release,
245 static struct proc_dir_entry *llc_proc_dir;
247 int __init llc_proc_init(void)
250 struct proc_dir_entry *p;
252 llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
256 p = proc_create("socket", S_IRUGO, llc_proc_dir, &llc_seq_socket_fops);
260 p = proc_create("core", S_IRUGO, llc_proc_dir, &llc_seq_core_fops);
268 remove_proc_entry("socket", llc_proc_dir);
270 remove_proc_entry("llc", init_net.proc_net);
274 void llc_proc_exit(void)
276 remove_proc_entry("socket", llc_proc_dir);
277 remove_proc_entry("core", llc_proc_dir);
278 remove_proc_entry("llc", init_net.proc_net);