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>
22 #include <net/llc_c_ac.h>
23 #include <net/llc_c_ev.h>
24 #include <net/llc_c_st.h>
25 #include <net/llc_conn.h>
27 static void llc_ui_format_mac(struct seq_file *seq, unsigned char *mac)
29 seq_printf(seq, "%02X:%02X:%02X:%02X:%02X:%02X",
30 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
33 static struct sock *llc_get_sk_idx(loff_t pos)
35 struct list_head *sap_entry;
37 struct hlist_node *node;
38 struct sock *sk = NULL;
40 list_for_each(sap_entry, &llc_sap_list) {
41 sap = list_entry(sap_entry, struct llc_sap, node);
43 read_lock_bh(&sap->sk_list.lock);
44 sk_for_each(sk, node, &sap->sk_list.list) {
49 read_unlock_bh(&sap->sk_list.lock);
56 static void *llc_seq_start(struct seq_file *seq, loff_t *pos)
60 read_lock_bh(&llc_sap_list_lock);
61 return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN;
64 static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
66 struct sock* sk, *next;
71 if (v == SEQ_START_TOKEN) {
72 sk = llc_get_sk_idx(0);
83 read_unlock_bh(&sap->sk_list.lock);
86 if (sap->node.next == &llc_sap_list)
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);
94 read_unlock_bh(&sap->sk_list.lock);
100 static void llc_seq_stop(struct seq_file *seq, void *v)
102 if (v && v != SEQ_START_TOKEN) {
104 struct llc_sock *llc = llc_sk(sk);
105 struct llc_sap *sap = llc->sap;
107 read_unlock_bh(&sap->sk_list.lock);
109 read_unlock_bh(&llc_sap_list_lock);
112 static int llc_seq_socket_show(struct seq_file *seq, void *v)
115 struct llc_sock *llc;
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");
125 /* FIXME: check if the address is multicast */
126 seq_printf(seq, "%2X %2X ", sk->sk_type, 0);
129 llc_ui_format_mac(seq, llc->dev->dev_addr);
131 seq_printf(seq, "00:00:00:00:00:00");
132 seq_printf(seq, "@%02X ", llc->sap->laddr.lsap);
133 llc_ui_format_mac(seq, llc->daddr.mac);
134 seq_printf(seq, "@%02X %8d %8d %2d %3d %4d\n", llc->daddr.lsap,
135 atomic_read(&sk->sk_wmem_alloc),
136 atomic_read(&sk->sk_rmem_alloc) - llc->copied_seq,
138 sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : -1,
144 static char *llc_conn_state_names[] = {
145 [LLC_CONN_STATE_ADM] = "adm",
146 [LLC_CONN_STATE_SETUP] = "setup",
147 [LLC_CONN_STATE_NORMAL] = "normal",
148 [LLC_CONN_STATE_BUSY] = "busy",
149 [LLC_CONN_STATE_REJ] = "rej",
150 [LLC_CONN_STATE_AWAIT] = "await",
151 [LLC_CONN_STATE_AWAIT_BUSY] = "await_busy",
152 [LLC_CONN_STATE_AWAIT_REJ] = "await_rej",
153 [LLC_CONN_STATE_D_CONN] = "d_conn",
154 [LLC_CONN_STATE_RESET] = "reset",
155 [LLC_CONN_STATE_ERROR] = "error",
156 [LLC_CONN_STATE_TEMP] = "temp",
159 static int llc_seq_core_show(struct seq_file *seq, void *v)
162 struct llc_sock *llc;
164 if (v == SEQ_START_TOKEN) {
165 seq_puts(seq, "Connection list:\n"
166 "dsap state retr txw rxw pf ff sf df rs cs "
167 "tack tpfc trs tbs blog busr\n");
173 seq_printf(seq, " %02X %-10s %3d %3d %3d %2d %2d %2d %2d %2d %2d "
174 "%4d %4d %3d %3d %4d %4d\n",
175 llc->daddr.lsap, llc_conn_state_names[llc->state],
176 llc->retry_count, llc->k, llc->rw, llc->p_flag, llc->f_flag,
177 llc->s_flag, llc->data_flag, llc->remote_busy_flag,
178 llc->cause_flag, timer_pending(&llc->ack_timer.timer),
179 timer_pending(&llc->pf_cycle_timer.timer),
180 timer_pending(&llc->rej_sent_timer.timer),
181 timer_pending(&llc->busy_state_timer.timer),
182 !!sk->sk_backlog.tail, !!sock_owned_by_user(sk));
187 static const struct seq_operations llc_seq_socket_ops = {
188 .start = llc_seq_start,
189 .next = llc_seq_next,
190 .stop = llc_seq_stop,
191 .show = llc_seq_socket_show,
194 static const struct seq_operations llc_seq_core_ops = {
195 .start = llc_seq_start,
196 .next = llc_seq_next,
197 .stop = llc_seq_stop,
198 .show = llc_seq_core_show,
201 static int llc_seq_socket_open(struct inode *inode, struct file *file)
203 return seq_open(file, &llc_seq_socket_ops);
206 static int llc_seq_core_open(struct inode *inode, struct file *file)
208 return seq_open(file, &llc_seq_core_ops);
211 static const struct file_operations llc_seq_socket_fops = {
212 .owner = THIS_MODULE,
213 .open = llc_seq_socket_open,
216 .release = seq_release,
219 static const struct file_operations llc_seq_core_fops = {
220 .owner = THIS_MODULE,
221 .open = llc_seq_core_open,
224 .release = seq_release,
227 static struct proc_dir_entry *llc_proc_dir;
229 int __init llc_proc_init(void)
232 struct proc_dir_entry *p;
234 llc_proc_dir = proc_mkdir("llc", proc_net);
237 llc_proc_dir->owner = THIS_MODULE;
239 p = create_proc_entry("socket", S_IRUGO, llc_proc_dir);
243 p->proc_fops = &llc_seq_socket_fops;
245 p = create_proc_entry("core", S_IRUGO, llc_proc_dir);
249 p->proc_fops = &llc_seq_core_fops;
255 remove_proc_entry("socket", llc_proc_dir);
257 remove_proc_entry("llc", proc_net);
261 void llc_proc_exit(void)
263 remove_proc_entry("socket", llc_proc_dir);
264 remove_proc_entry("core", llc_proc_dir);
265 remove_proc_entry("llc", proc_net);