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