Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * proc_llc.c - proc interface for LLC
0003  *
0004  * Copyright (c) 2001 by Jay Schulist <jschlst@samba.org>
0005  *       2002-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
0006  *
0007  * This program can be redistributed or modified under the terms of the
0008  * GNU General Public License as published by the Free Software Foundation.
0009  * This program is distributed without any warranty or implied warranty
0010  * of merchantability or fitness for a particular purpose.
0011  *
0012  * See the GNU General Public License for more details.
0013  */
0014 
0015 #include <linux/init.h>
0016 #include <linux/kernel.h>
0017 #include <linux/proc_fs.h>
0018 #include <linux/errno.h>
0019 #include <linux/seq_file.h>
0020 #include <linux/export.h>
0021 #include <net/net_namespace.h>
0022 #include <net/sock.h>
0023 #include <net/llc.h>
0024 #include <net/llc_c_ac.h>
0025 #include <net/llc_c_ev.h>
0026 #include <net/llc_c_st.h>
0027 #include <net/llc_conn.h>
0028 
0029 static void llc_ui_format_mac(struct seq_file *seq, const u8 *addr)
0030 {
0031     seq_printf(seq, "%pM", addr);
0032 }
0033 
0034 static struct sock *llc_get_sk_idx(loff_t pos)
0035 {
0036     struct llc_sap *sap;
0037     struct sock *sk = NULL;
0038     int i;
0039 
0040     list_for_each_entry_rcu(sap, &llc_sap_list, node) {
0041         spin_lock_bh(&sap->sk_lock);
0042         for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) {
0043             struct hlist_nulls_head *head = &sap->sk_laddr_hash[i];
0044             struct hlist_nulls_node *node;
0045 
0046             sk_nulls_for_each(sk, node, head) {
0047                 if (!pos)
0048                     goto found; /* keep the lock */
0049                 --pos;
0050             }
0051         }
0052         spin_unlock_bh(&sap->sk_lock);
0053     }
0054     sk = NULL;
0055 found:
0056     return sk;
0057 }
0058 
0059 static void *llc_seq_start(struct seq_file *seq, loff_t *pos) __acquires(RCU)
0060 {
0061     loff_t l = *pos;
0062 
0063     rcu_read_lock_bh();
0064     return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN;
0065 }
0066 
0067 static struct sock *laddr_hash_next(struct llc_sap *sap, int bucket)
0068 {
0069     struct hlist_nulls_node *node;
0070     struct sock *sk = NULL;
0071 
0072     while (++bucket < LLC_SK_LADDR_HASH_ENTRIES)
0073         sk_nulls_for_each(sk, node, &sap->sk_laddr_hash[bucket])
0074             goto out;
0075 
0076 out:
0077     return sk;
0078 }
0079 
0080 static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
0081 {
0082     struct sock* sk, *next;
0083     struct llc_sock *llc;
0084     struct llc_sap *sap;
0085 
0086     ++*pos;
0087     if (v == SEQ_START_TOKEN) {
0088         sk = llc_get_sk_idx(0);
0089         goto out;
0090     }
0091     sk = v;
0092     next = sk_nulls_next(sk);
0093     if (next) {
0094         sk = next;
0095         goto out;
0096     }
0097     llc = llc_sk(sk);
0098     sap = llc->sap;
0099     sk = laddr_hash_next(sap, llc_sk_laddr_hashfn(sap, &llc->laddr));
0100     if (sk)
0101         goto out;
0102     spin_unlock_bh(&sap->sk_lock);
0103     list_for_each_entry_continue_rcu(sap, &llc_sap_list, node) {
0104         spin_lock_bh(&sap->sk_lock);
0105         sk = laddr_hash_next(sap, -1);
0106         if (sk)
0107             break; /* keep the lock */
0108         spin_unlock_bh(&sap->sk_lock);
0109     }
0110 out:
0111     return sk;
0112 }
0113 
0114 static void llc_seq_stop(struct seq_file *seq, void *v)
0115 {
0116     if (v && v != SEQ_START_TOKEN) {
0117         struct sock *sk = v;
0118         struct llc_sock *llc = llc_sk(sk);
0119         struct llc_sap *sap = llc->sap;
0120 
0121         spin_unlock_bh(&sap->sk_lock);
0122     }
0123     rcu_read_unlock_bh();
0124 }
0125 
0126 static int llc_seq_socket_show(struct seq_file *seq, void *v)
0127 {
0128     struct sock* sk;
0129     struct llc_sock *llc;
0130 
0131     if (v == SEQ_START_TOKEN) {
0132         seq_puts(seq, "SKt Mc local_mac_sap        remote_mac_sap   "
0133                   "    tx_queue rx_queue st uid link\n");
0134         goto out;
0135     }
0136     sk = v;
0137     llc = llc_sk(sk);
0138 
0139     /* FIXME: check if the address is multicast */
0140     seq_printf(seq, "%2X  %2X ", sk->sk_type, 0);
0141 
0142     if (llc->dev)
0143         llc_ui_format_mac(seq, llc->dev->dev_addr);
0144     else {
0145         u8 addr[6] = {0,0,0,0,0,0};
0146         llc_ui_format_mac(seq, addr);
0147     }
0148     seq_printf(seq, "@%02X ", llc->sap->laddr.lsap);
0149     llc_ui_format_mac(seq, llc->daddr.mac);
0150     seq_printf(seq, "@%02X %8d %8d %2d %3u %4d\n", llc->daddr.lsap,
0151            sk_wmem_alloc_get(sk),
0152            sk_rmem_alloc_get(sk) - llc->copied_seq,
0153            sk->sk_state,
0154            from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
0155            llc->link);
0156 out:
0157     return 0;
0158 }
0159 
0160 static const char *const llc_conn_state_names[] = {
0161     [LLC_CONN_STATE_ADM] =        "adm",
0162     [LLC_CONN_STATE_SETUP] =      "setup",
0163     [LLC_CONN_STATE_NORMAL] =     "normal",
0164     [LLC_CONN_STATE_BUSY] =       "busy",
0165     [LLC_CONN_STATE_REJ] =        "rej",
0166     [LLC_CONN_STATE_AWAIT] =      "await",
0167     [LLC_CONN_STATE_AWAIT_BUSY] = "await_busy",
0168     [LLC_CONN_STATE_AWAIT_REJ] =  "await_rej",
0169     [LLC_CONN_STATE_D_CONN] =     "d_conn",
0170     [LLC_CONN_STATE_RESET] =      "reset",
0171     [LLC_CONN_STATE_ERROR] =      "error",
0172     [LLC_CONN_STATE_TEMP] =       "temp",
0173 };
0174 
0175 static int llc_seq_core_show(struct seq_file *seq, void *v)
0176 {
0177     struct sock* sk;
0178     struct llc_sock *llc;
0179 
0180     if (v == SEQ_START_TOKEN) {
0181         seq_puts(seq, "Connection list:\n"
0182                   "dsap state      retr txw rxw pf ff sf df rs cs "
0183                   "tack tpfc trs tbs blog busr\n");
0184         goto out;
0185     }
0186     sk = v;
0187     llc = llc_sk(sk);
0188 
0189     seq_printf(seq, " %02X  %-10s %3d  %3d %3d %2d %2d %2d %2d %2d %2d "
0190             "%4d %4d %3d %3d %4d %4d\n",
0191            llc->daddr.lsap, llc_conn_state_names[llc->state],
0192            llc->retry_count, llc->k, llc->rw, llc->p_flag, llc->f_flag,
0193            llc->s_flag, llc->data_flag, llc->remote_busy_flag,
0194            llc->cause_flag, timer_pending(&llc->ack_timer.timer),
0195            timer_pending(&llc->pf_cycle_timer.timer),
0196            timer_pending(&llc->rej_sent_timer.timer),
0197            timer_pending(&llc->busy_state_timer.timer),
0198            !!sk->sk_backlog.tail, sock_owned_by_user_nocheck(sk));
0199 out:
0200     return 0;
0201 }
0202 
0203 static const struct seq_operations llc_seq_socket_ops = {
0204     .start  = llc_seq_start,
0205     .next   = llc_seq_next,
0206     .stop   = llc_seq_stop,
0207     .show   = llc_seq_socket_show,
0208 };
0209 
0210 static const struct seq_operations llc_seq_core_ops = {
0211     .start  = llc_seq_start,
0212     .next   = llc_seq_next,
0213     .stop   = llc_seq_stop,
0214     .show   = llc_seq_core_show,
0215 };
0216 
0217 static struct proc_dir_entry *llc_proc_dir;
0218 
0219 int __init llc_proc_init(void)
0220 {
0221     int rc = -ENOMEM;
0222     struct proc_dir_entry *p;
0223 
0224     llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
0225     if (!llc_proc_dir)
0226         goto out;
0227 
0228     p = proc_create_seq("socket", 0444, llc_proc_dir, &llc_seq_socket_ops);
0229     if (!p)
0230         goto out_socket;
0231 
0232     p = proc_create_seq("core", 0444, llc_proc_dir, &llc_seq_core_ops);
0233     if (!p)
0234         goto out_core;
0235 
0236     rc = 0;
0237 out:
0238     return rc;
0239 out_core:
0240     remove_proc_entry("socket", llc_proc_dir);
0241 out_socket:
0242     remove_proc_entry("llc", init_net.proc_net);
0243     goto out;
0244 }
0245 
0246 void llc_proc_exit(void)
0247 {
0248     remove_proc_entry("socket", llc_proc_dir);
0249     remove_proc_entry("core", llc_proc_dir);
0250     remove_proc_entry("llc", init_net.proc_net);
0251 }