llc_proc.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  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. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/proc_fs.h>
  17. #include <linux/errno.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/export.h>
  20. #include <net/net_namespace.h>
  21. #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. static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)
  28. {
  29. seq_printf(seq, "%pM", addr);
  30. }
  31. static struct sock *llc_get_sk_idx(loff_t pos)
  32. {
  33. struct llc_sap *sap;
  34. struct sock *sk = NULL;
  35. int i;
  36. list_for_each_entry_rcu(sap, &llc_sap_list, node) {
  37. spin_lock_bh(&sap->sk_lock);
  38. for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) {
  39. struct hlist_nulls_head *head = &sap->sk_laddr_hash[i];
  40. struct hlist_nulls_node *node;
  41. sk_nulls_for_each(sk, node, head) {
  42. if (!pos)
  43. goto found; /* keep the lock */
  44. --pos;
  45. }
  46. }
  47. spin_unlock_bh(&sap->sk_lock);
  48. }
  49. sk = NULL;
  50. found:
  51. return sk;
  52. }
  53. static void *llc_seq_start(struct seq_file *seq, loff_t *pos)
  54. {
  55. loff_t l = *pos;
  56. rcu_read_lock_bh();
  57. return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN;
  58. }
  59. static struct sock *laddr_hash_next(struct llc_sap *sap, int bucket)
  60. {
  61. struct hlist_nulls_node *node;
  62. struct sock *sk = NULL;
  63. while (++bucket < LLC_SK_LADDR_HASH_ENTRIES)
  64. sk_nulls_for_each(sk, node, &sap->sk_laddr_hash[bucket])
  65. goto out;
  66. out:
  67. return sk;
  68. }
  69. static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  70. {
  71. struct sock* sk, *next;
  72. struct llc_sock *llc;
  73. struct llc_sap *sap;
  74. ++*pos;
  75. if (v == SEQ_START_TOKEN) {
  76. sk = llc_get_sk_idx(0);
  77. goto out;
  78. }
  79. sk = v;
  80. next = sk_nulls_next(sk);
  81. if (next) {
  82. sk = next;
  83. goto out;
  84. }
  85. llc = llc_sk(sk);
  86. sap = llc->sap;
  87. sk = laddr_hash_next(sap, llc_sk_laddr_hashfn(sap, &llc->laddr));
  88. if (sk)
  89. goto out;
  90. spin_unlock_bh(&sap->sk_lock);
  91. list_for_each_entry_continue_rcu(sap, &llc_sap_list, node) {
  92. spin_lock_bh(&sap->sk_lock);
  93. sk = laddr_hash_next(sap, -1);
  94. if (sk)
  95. break; /* keep the lock */
  96. spin_unlock_bh(&sap->sk_lock);
  97. }
  98. out:
  99. return sk;
  100. }
  101. static void llc_seq_stop(struct seq_file *seq, void *v)
  102. {
  103. if (v && v != SEQ_START_TOKEN) {
  104. struct sock *sk = v;
  105. struct llc_sock *llc = llc_sk(sk);
  106. struct llc_sap *sap = llc->sap;
  107. spin_unlock_bh(&sap->sk_lock);
  108. }
  109. rcu_read_unlock_bh();
  110. }
  111. static int llc_seq_socket_show(struct seq_file *seq, void *v)
  112. {
  113. struct sock* sk;
  114. struct llc_sock *llc;
  115. if (v == SEQ_START_TOKEN) {
  116. seq_puts(seq, "SKt Mc local_mac_sap remote_mac_sap "
  117. " tx_queue rx_queue st uid link\n");
  118. goto out;
  119. }
  120. sk = v;
  121. llc = llc_sk(sk);
  122. /* FIXME: check if the address is multicast */
  123. seq_printf(seq, "%2X %2X ", sk->sk_type, 0);
  124. if (llc->dev)
  125. llc_ui_format_mac(seq, llc->dev->dev_addr);
  126. else {
  127. u8 addr[6] = {0,0,0,0,0,0};
  128. llc_ui_format_mac(seq, addr);
  129. }
  130. seq_printf(seq, "@%02X ", llc->sap->laddr.lsap);
  131. llc_ui_format_mac(seq, llc->daddr.mac);
  132. seq_printf(seq, "@%02X %8d %8d %2d %3u %4d\n", llc->daddr.lsap,
  133. sk_wmem_alloc_get(sk),
  134. sk_rmem_alloc_get(sk) - llc->copied_seq,
  135. sk->sk_state,
  136. from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
  137. llc->link);
  138. out:
  139. return 0;
  140. }
  141. static const char *const llc_conn_state_names[] = {
  142. [LLC_CONN_STATE_ADM] = "adm",
  143. [LLC_CONN_STATE_SETUP] = "setup",
  144. [LLC_CONN_STATE_NORMAL] = "normal",
  145. [LLC_CONN_STATE_BUSY] = "busy",
  146. [LLC_CONN_STATE_REJ] = "rej",
  147. [LLC_CONN_STATE_AWAIT] = "await",
  148. [LLC_CONN_STATE_AWAIT_BUSY] = "await_busy",
  149. [LLC_CONN_STATE_AWAIT_REJ] = "await_rej",
  150. [LLC_CONN_STATE_D_CONN] = "d_conn",
  151. [LLC_CONN_STATE_RESET] = "reset",
  152. [LLC_CONN_STATE_ERROR] = "error",
  153. [LLC_CONN_STATE_TEMP] = "temp",
  154. };
  155. static int llc_seq_core_show(struct seq_file *seq, void *v)
  156. {
  157. struct sock* sk;
  158. struct llc_sock *llc;
  159. if (v == SEQ_START_TOKEN) {
  160. seq_puts(seq, "Connection list:\n"
  161. "dsap state retr txw rxw pf ff sf df rs cs "
  162. "tack tpfc trs tbs blog busr\n");
  163. goto out;
  164. }
  165. sk = v;
  166. llc = llc_sk(sk);
  167. seq_printf(seq, " %02X %-10s %3d %3d %3d %2d %2d %2d %2d %2d %2d "
  168. "%4d %4d %3d %3d %4d %4d\n",
  169. llc->daddr.lsap, llc_conn_state_names[llc->state],
  170. llc->retry_count, llc->k, llc->rw, llc->p_flag, llc->f_flag,
  171. llc->s_flag, llc->data_flag, llc->remote_busy_flag,
  172. llc->cause_flag, timer_pending(&llc->ack_timer.timer),
  173. timer_pending(&llc->pf_cycle_timer.timer),
  174. timer_pending(&llc->rej_sent_timer.timer),
  175. timer_pending(&llc->busy_state_timer.timer),
  176. !!sk->sk_backlog.tail, !!sock_owned_by_user(sk));
  177. out:
  178. return 0;
  179. }
  180. static const struct seq_operations llc_seq_socket_ops = {
  181. .start = llc_seq_start,
  182. .next = llc_seq_next,
  183. .stop = llc_seq_stop,
  184. .show = llc_seq_socket_show,
  185. };
  186. static const struct seq_operations llc_seq_core_ops = {
  187. .start = llc_seq_start,
  188. .next = llc_seq_next,
  189. .stop = llc_seq_stop,
  190. .show = llc_seq_core_show,
  191. };
  192. static int llc_seq_socket_open(struct inode *inode, struct file *file)
  193. {
  194. return seq_open(file, &llc_seq_socket_ops);
  195. }
  196. static int llc_seq_core_open(struct inode *inode, struct file *file)
  197. {
  198. return seq_open(file, &llc_seq_core_ops);
  199. }
  200. static const struct file_operations llc_seq_socket_fops = {
  201. .owner = THIS_MODULE,
  202. .open = llc_seq_socket_open,
  203. .read = seq_read,
  204. .llseek = seq_lseek,
  205. .release = seq_release,
  206. };
  207. static const struct file_operations llc_seq_core_fops = {
  208. .owner = THIS_MODULE,
  209. .open = llc_seq_core_open,
  210. .read = seq_read,
  211. .llseek = seq_lseek,
  212. .release = seq_release,
  213. };
  214. static struct proc_dir_entry *llc_proc_dir;
  215. int __init llc_proc_init(void)
  216. {
  217. int rc = -ENOMEM;
  218. struct proc_dir_entry *p;
  219. llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
  220. if (!llc_proc_dir)
  221. goto out;
  222. p = proc_create("socket", S_IRUGO, llc_proc_dir, &llc_seq_socket_fops);
  223. if (!p)
  224. goto out_socket;
  225. p = proc_create("core", S_IRUGO, llc_proc_dir, &llc_seq_core_fops);
  226. if (!p)
  227. goto out_core;
  228. rc = 0;
  229. out:
  230. return rc;
  231. out_core:
  232. remove_proc_entry("socket", llc_proc_dir);
  233. out_socket:
  234. remove_proc_entry("llc", init_net.proc_net);
  235. goto out;
  236. }
  237. void llc_proc_exit(void)
  238. {
  239. remove_proc_entry("socket", llc_proc_dir);
  240. remove_proc_entry("core", llc_proc_dir);
  241. remove_proc_entry("llc", init_net.proc_net);
  242. }