blob: f8ba30dfecae430df85199c547a6884bc1461022 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IPX proc routines
3 *
4 * Copyright(C) Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 2002
5 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/init.h>
8#ifdef CONFIG_PROC_FS
9#include <linux/proc_fs.h>
10#include <linux/spinlock.h>
11#include <linux/seq_file.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040012#include <linux/export.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020013#include <net/net_namespace.h>
Arnaldo Carvalho de Meloc752f072005-08-09 20:08:28 -070014#include <net/tcp_states.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <net/ipx.h>
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017static void *ipx_seq_interface_start(struct seq_file *seq, loff_t *pos)
18{
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 spin_lock_bh(&ipx_interfaces_lock);
Li Zefana2b79b42010-02-08 23:21:22 +000020 return seq_list_start_head(&ipx_interfaces, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021}
22
23static void *ipx_seq_interface_next(struct seq_file *seq, void *v, loff_t *pos)
24{
Li Zefana2b79b42010-02-08 23:21:22 +000025 return seq_list_next(v, &ipx_interfaces, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026}
27
28static void ipx_seq_interface_stop(struct seq_file *seq, void *v)
29{
30 spin_unlock_bh(&ipx_interfaces_lock);
31}
32
33static int ipx_seq_interface_show(struct seq_file *seq, void *v)
34{
35 struct ipx_interface *i;
36
Li Zefana2b79b42010-02-08 23:21:22 +000037 if (v == &ipx_interfaces) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 seq_puts(seq, "Network Node_Address Primary Device "
39 "Frame_Type");
40#ifdef IPX_REFCNT_DEBUG
41 seq_puts(seq, " refcnt");
42#endif
43 seq_puts(seq, "\n");
44 goto out;
45 }
46
Li Zefana2b79b42010-02-08 23:21:22 +000047 i = list_entry(v, struct ipx_interface, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 seq_printf(seq, "%08lX ", (unsigned long int)ntohl(i->if_netnum));
49 seq_printf(seq, "%02X%02X%02X%02X%02X%02X ",
50 i->if_node[0], i->if_node[1], i->if_node[2],
51 i->if_node[3], i->if_node[4], i->if_node[5]);
52 seq_printf(seq, "%-9s", i == ipx_primary_net ? "Yes" : "No");
53 seq_printf(seq, "%-11s", ipx_device_name(i));
54 seq_printf(seq, "%-9s", ipx_frame_name(i->if_dlink_type));
55#ifdef IPX_REFCNT_DEBUG
56 seq_printf(seq, "%6d", atomic_read(&i->refcnt));
57#endif
58 seq_puts(seq, "\n");
59out:
60 return 0;
61}
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static void *ipx_seq_route_start(struct seq_file *seq, loff_t *pos)
64{
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 read_lock_bh(&ipx_routes_lock);
Li Zefana2b79b42010-02-08 23:21:22 +000066 return seq_list_start_head(&ipx_routes, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}
68
69static void *ipx_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
70{
Li Zefana2b79b42010-02-08 23:21:22 +000071 return seq_list_next(v, &ipx_routes, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
74static void ipx_seq_route_stop(struct seq_file *seq, void *v)
75{
76 read_unlock_bh(&ipx_routes_lock);
77}
78
79static int ipx_seq_route_show(struct seq_file *seq, void *v)
80{
81 struct ipx_route *rt;
82
Li Zefana2b79b42010-02-08 23:21:22 +000083 if (v == &ipx_routes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 seq_puts(seq, "Network Router_Net Router_Node\n");
85 goto out;
86 }
Li Zefana2b79b42010-02-08 23:21:22 +000087
88 rt = list_entry(v, struct ipx_route, node);
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 seq_printf(seq, "%08lX ", (unsigned long int)ntohl(rt->ir_net));
91 if (rt->ir_routed)
92 seq_printf(seq, "%08lX %02X%02X%02X%02X%02X%02X\n",
93 (long unsigned int)ntohl(rt->ir_intrfc->if_netnum),
94 rt->ir_router_node[0], rt->ir_router_node[1],
95 rt->ir_router_node[2], rt->ir_router_node[3],
96 rt->ir_router_node[4], rt->ir_router_node[5]);
97 else
98 seq_puts(seq, "Directly Connected\n");
99out:
100 return 0;
101}
102
103static __inline__ struct sock *ipx_get_socket_idx(loff_t pos)
104{
105 struct sock *s = NULL;
106 struct hlist_node *node;
107 struct ipx_interface *i;
108
109 list_for_each_entry(i, &ipx_interfaces, node) {
110 spin_lock_bh(&i->if_sklist_lock);
111 sk_for_each(s, node, &i->if_sklist) {
112 if (!pos)
113 break;
114 --pos;
115 }
116 spin_unlock_bh(&i->if_sklist_lock);
117 if (!pos) {
118 if (node)
119 goto found;
120 break;
121 }
122 }
123 s = NULL;
124found:
125 return s;
126}
127
128static void *ipx_seq_socket_start(struct seq_file *seq, loff_t *pos)
129{
130 loff_t l = *pos;
131
132 spin_lock_bh(&ipx_interfaces_lock);
133 return l ? ipx_get_socket_idx(--l) : SEQ_START_TOKEN;
134}
135
136static void *ipx_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
137{
138 struct sock* sk, *next;
139 struct ipx_interface *i;
140 struct ipx_sock *ipxs;
141
142 ++*pos;
143 if (v == SEQ_START_TOKEN) {
144 sk = NULL;
145 i = ipx_interfaces_head();
146 if (!i)
147 goto out;
148 sk = sk_head(&i->if_sklist);
149 if (sk)
150 spin_lock_bh(&i->if_sklist_lock);
151 goto out;
152 }
153 sk = v;
154 next = sk_next(sk);
155 if (next) {
156 sk = next;
157 goto out;
158 }
159 ipxs = ipx_sk(sk);
160 i = ipxs->intrfc;
161 spin_unlock_bh(&i->if_sklist_lock);
162 sk = NULL;
163 for (;;) {
Li Zefana2b79b42010-02-08 23:21:22 +0000164 if (i->node.next == &ipx_interfaces)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 break;
Li Zefana2b79b42010-02-08 23:21:22 +0000166 i = list_entry(i->node.next, struct ipx_interface, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 spin_lock_bh(&i->if_sklist_lock);
168 if (!hlist_empty(&i->if_sklist)) {
169 sk = sk_head(&i->if_sklist);
170 break;
171 }
172 spin_unlock_bh(&i->if_sklist_lock);
173 }
174out:
175 return sk;
176}
177
178static int ipx_seq_socket_show(struct seq_file *seq, void *v)
179{
180 struct sock *s;
181 struct ipx_sock *ipxs;
182
183 if (v == SEQ_START_TOKEN) {
184#ifdef CONFIG_IPX_INTERN
185 seq_puts(seq, "Local_Address "
186 "Remote_Address Tx_Queue "
187 "Rx_Queue State Uid\n");
188#else
189 seq_puts(seq, "Local_Address Remote_Address "
190 "Tx_Queue Rx_Queue State Uid\n");
191#endif
192 goto out;
193 }
194
195 s = v;
196 ipxs = ipx_sk(s);
197#ifdef CONFIG_IPX_INTERN
198 seq_printf(seq, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
Al Viro4833ed02006-11-03 00:27:06 -0800199 (unsigned long)ntohl(ipxs->intrfc->if_netnum),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 ipxs->node[0], ipxs->node[1], ipxs->node[2], ipxs->node[3],
Al Viro4833ed02006-11-03 00:27:06 -0800201 ipxs->node[4], ipxs->node[5], ntohs(ipxs->port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#else
Al Viro4833ed02006-11-03 00:27:06 -0800203 seq_printf(seq, "%08lX:%04X ", (unsigned long) ntohl(ipxs->intrfc->if_netnum),
204 ntohs(ipxs->port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#endif /* CONFIG_IPX_INTERN */
206 if (s->sk_state != TCP_ESTABLISHED)
207 seq_printf(seq, "%-28s", "Not_Connected");
208 else {
209 seq_printf(seq, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
Al Viro4833ed02006-11-03 00:27:06 -0800210 (unsigned long)ntohl(ipxs->dest_addr.net),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 ipxs->dest_addr.node[0], ipxs->dest_addr.node[1],
212 ipxs->dest_addr.node[2], ipxs->dest_addr.node[3],
213 ipxs->dest_addr.node[4], ipxs->dest_addr.node[5],
Al Viro4833ed02006-11-03 00:27:06 -0800214 ntohs(ipxs->dest_addr.sock));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
217 seq_printf(seq, "%08X %08X %02X %03d\n",
Eric Dumazet31e6d362009-06-17 19:05:41 -0700218 sk_wmem_alloc_get(s),
219 sk_rmem_alloc_get(s),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 s->sk_state, SOCK_INODE(s->sk_socket)->i_uid);
221out:
222 return 0;
223}
224
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700225static const struct seq_operations ipx_seq_interface_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 .start = ipx_seq_interface_start,
227 .next = ipx_seq_interface_next,
228 .stop = ipx_seq_interface_stop,
229 .show = ipx_seq_interface_show,
230};
231
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700232static const struct seq_operations ipx_seq_route_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 .start = ipx_seq_route_start,
234 .next = ipx_seq_route_next,
235 .stop = ipx_seq_route_stop,
236 .show = ipx_seq_route_show,
237};
238
Philippe De Muyter56b3d972007-07-10 23:07:31 -0700239static const struct seq_operations ipx_seq_socket_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .start = ipx_seq_socket_start,
241 .next = ipx_seq_socket_next,
242 .stop = ipx_seq_interface_stop,
243 .show = ipx_seq_socket_show,
244};
245
246static int ipx_seq_route_open(struct inode *inode, struct file *file)
247{
248 return seq_open(file, &ipx_seq_route_ops);
249}
250
251static int ipx_seq_interface_open(struct inode *inode, struct file *file)
252{
253 return seq_open(file, &ipx_seq_interface_ops);
254}
255
256static int ipx_seq_socket_open(struct inode *inode, struct file *file)
257{
258 return seq_open(file, &ipx_seq_socket_ops);
259}
260
Arjan van de Ven9a321442007-02-12 00:55:35 -0800261static const struct file_operations ipx_seq_interface_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 .owner = THIS_MODULE,
263 .open = ipx_seq_interface_open,
264 .read = seq_read,
265 .llseek = seq_lseek,
266 .release = seq_release,
267};
268
Arjan van de Ven9a321442007-02-12 00:55:35 -0800269static const struct file_operations ipx_seq_route_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 .owner = THIS_MODULE,
271 .open = ipx_seq_route_open,
272 .read = seq_read,
273 .llseek = seq_lseek,
274 .release = seq_release,
275};
276
Arjan van de Ven9a321442007-02-12 00:55:35 -0800277static const struct file_operations ipx_seq_socket_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 .owner = THIS_MODULE,
279 .open = ipx_seq_socket_open,
280 .read = seq_read,
281 .llseek = seq_lseek,
282 .release = seq_release,
283};
284
285static struct proc_dir_entry *ipx_proc_dir;
286
287int __init ipx_proc_init(void)
288{
289 struct proc_dir_entry *p;
290 int rc = -ENOMEM;
YOSHIFUJI Hideaki981c0ff2007-02-09 23:24:51 +0900291
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200292 ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 if (!ipx_proc_dir)
295 goto out;
Wang Chen1e15dc92008-02-28 14:06:14 -0800296 p = proc_create("interface", S_IRUGO,
297 ipx_proc_dir, &ipx_seq_interface_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (!p)
299 goto out_interface;
300
Wang Chen1e15dc92008-02-28 14:06:14 -0800301 p = proc_create("route", S_IRUGO, ipx_proc_dir, &ipx_seq_route_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 if (!p)
303 goto out_route;
304
Wang Chen1e15dc92008-02-28 14:06:14 -0800305 p = proc_create("socket", S_IRUGO, ipx_proc_dir, &ipx_seq_socket_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (!p)
307 goto out_socket;
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 rc = 0;
310out:
311 return rc;
312out_socket:
313 remove_proc_entry("route", ipx_proc_dir);
314out_route:
315 remove_proc_entry("interface", ipx_proc_dir);
316out_interface:
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200317 remove_proc_entry("ipx", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 goto out;
319}
320
321void __exit ipx_proc_exit(void)
322{
323 remove_proc_entry("interface", ipx_proc_dir);
324 remove_proc_entry("route", ipx_proc_dir);
325 remove_proc_entry("socket", ipx_proc_dir);
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200326 remove_proc_entry("ipx", init_net.proc_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327}
328
329#else /* CONFIG_PROC_FS */
330
331int __init ipx_proc_init(void)
332{
333 return 0;
334}
335
336void __exit ipx_proc_exit(void)
337{
338}
339
340#endif /* CONFIG_PROC_FS */