4 * Copyright(C) Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 2002
7 #include <linux/init.h>
9 #include <linux/proc_fs.h>
10 #include <linux/spinlock.h>
11 #include <linux/seq_file.h>
12 #include <net/tcp_states.h>
15 static __inline__ struct ipx_interface *ipx_get_interface_idx(loff_t pos)
17 struct ipx_interface *i;
19 list_for_each_entry(i, &ipx_interfaces, node)
27 static struct ipx_interface *ipx_interfaces_next(struct ipx_interface *i)
29 struct ipx_interface *rc = NULL;
31 if (i->node.next != &ipx_interfaces)
32 rc = list_entry(i->node.next, struct ipx_interface, node);
36 static void *ipx_seq_interface_start(struct seq_file *seq, loff_t *pos)
40 spin_lock_bh(&ipx_interfaces_lock);
41 return l ? ipx_get_interface_idx(--l) : SEQ_START_TOKEN;
44 static void *ipx_seq_interface_next(struct seq_file *seq, void *v, loff_t *pos)
46 struct ipx_interface *i;
49 if (v == SEQ_START_TOKEN)
50 i = ipx_interfaces_head();
52 i = ipx_interfaces_next(v);
56 static void ipx_seq_interface_stop(struct seq_file *seq, void *v)
58 spin_unlock_bh(&ipx_interfaces_lock);
61 static int ipx_seq_interface_show(struct seq_file *seq, void *v)
63 struct ipx_interface *i;
65 if (v == SEQ_START_TOKEN) {
66 seq_puts(seq, "Network Node_Address Primary Device "
68 #ifdef IPX_REFCNT_DEBUG
69 seq_puts(seq, " refcnt");
76 seq_printf(seq, "%08lX ", (unsigned long int)ntohl(i->if_netnum));
77 seq_printf(seq, "%02X%02X%02X%02X%02X%02X ",
78 i->if_node[0], i->if_node[1], i->if_node[2],
79 i->if_node[3], i->if_node[4], i->if_node[5]);
80 seq_printf(seq, "%-9s", i == ipx_primary_net ? "Yes" : "No");
81 seq_printf(seq, "%-11s", ipx_device_name(i));
82 seq_printf(seq, "%-9s", ipx_frame_name(i->if_dlink_type));
83 #ifdef IPX_REFCNT_DEBUG
84 seq_printf(seq, "%6d", atomic_read(&i->refcnt));
91 static struct ipx_route *ipx_routes_head(void)
93 struct ipx_route *rc = NULL;
95 if (!list_empty(&ipx_routes))
96 rc = list_entry(ipx_routes.next, struct ipx_route, node);
100 static struct ipx_route *ipx_routes_next(struct ipx_route *r)
102 struct ipx_route *rc = NULL;
104 if (r->node.next != &ipx_routes)
105 rc = list_entry(r->node.next, struct ipx_route, node);
109 static __inline__ struct ipx_route *ipx_get_route_idx(loff_t pos)
113 list_for_each_entry(r, &ipx_routes, node)
121 static void *ipx_seq_route_start(struct seq_file *seq, loff_t *pos)
124 read_lock_bh(&ipx_routes_lock);
125 return l ? ipx_get_route_idx(--l) : SEQ_START_TOKEN;
128 static void *ipx_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
133 if (v == SEQ_START_TOKEN)
134 r = ipx_routes_head();
136 r = ipx_routes_next(v);
140 static void ipx_seq_route_stop(struct seq_file *seq, void *v)
142 read_unlock_bh(&ipx_routes_lock);
145 static int ipx_seq_route_show(struct seq_file *seq, void *v)
147 struct ipx_route *rt;
149 if (v == SEQ_START_TOKEN) {
150 seq_puts(seq, "Network Router_Net Router_Node\n");
154 seq_printf(seq, "%08lX ", (unsigned long int)ntohl(rt->ir_net));
156 seq_printf(seq, "%08lX %02X%02X%02X%02X%02X%02X\n",
157 (long unsigned int)ntohl(rt->ir_intrfc->if_netnum),
158 rt->ir_router_node[0], rt->ir_router_node[1],
159 rt->ir_router_node[2], rt->ir_router_node[3],
160 rt->ir_router_node[4], rt->ir_router_node[5]);
162 seq_puts(seq, "Directly Connected\n");
167 static __inline__ struct sock *ipx_get_socket_idx(loff_t pos)
169 struct sock *s = NULL;
170 struct hlist_node *node;
171 struct ipx_interface *i;
173 list_for_each_entry(i, &ipx_interfaces, node) {
174 spin_lock_bh(&i->if_sklist_lock);
175 sk_for_each(s, node, &i->if_sklist) {
180 spin_unlock_bh(&i->if_sklist_lock);
192 static void *ipx_seq_socket_start(struct seq_file *seq, loff_t *pos)
196 spin_lock_bh(&ipx_interfaces_lock);
197 return l ? ipx_get_socket_idx(--l) : SEQ_START_TOKEN;
200 static void *ipx_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
202 struct sock* sk, *next;
203 struct ipx_interface *i;
204 struct ipx_sock *ipxs;
207 if (v == SEQ_START_TOKEN) {
209 i = ipx_interfaces_head();
212 sk = sk_head(&i->if_sklist);
214 spin_lock_bh(&i->if_sklist_lock);
225 spin_unlock_bh(&i->if_sklist_lock);
228 i = ipx_interfaces_next(i);
231 spin_lock_bh(&i->if_sklist_lock);
232 if (!hlist_empty(&i->if_sklist)) {
233 sk = sk_head(&i->if_sklist);
236 spin_unlock_bh(&i->if_sklist_lock);
242 static int ipx_seq_socket_show(struct seq_file *seq, void *v)
245 struct ipx_sock *ipxs;
247 if (v == SEQ_START_TOKEN) {
248 #ifdef CONFIG_IPX_INTERN
249 seq_puts(seq, "Local_Address "
250 "Remote_Address Tx_Queue "
251 "Rx_Queue State Uid\n");
253 seq_puts(seq, "Local_Address Remote_Address "
254 "Tx_Queue Rx_Queue State Uid\n");
261 #ifdef CONFIG_IPX_INTERN
262 seq_printf(seq, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
263 (unsigned long)ntohl(ipxs->intrfc->if_netnum),
264 ipxs->node[0], ipxs->node[1], ipxs->node[2], ipxs->node[3],
265 ipxs->node[4], ipxs->node[5], ntohs(ipxs->port));
267 seq_printf(seq, "%08lX:%04X ", (unsigned long) ntohl(ipxs->intrfc->if_netnum),
269 #endif /* CONFIG_IPX_INTERN */
270 if (s->sk_state != TCP_ESTABLISHED)
271 seq_printf(seq, "%-28s", "Not_Connected");
273 seq_printf(seq, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
274 (unsigned long)ntohl(ipxs->dest_addr.net),
275 ipxs->dest_addr.node[0], ipxs->dest_addr.node[1],
276 ipxs->dest_addr.node[2], ipxs->dest_addr.node[3],
277 ipxs->dest_addr.node[4], ipxs->dest_addr.node[5],
278 ntohs(ipxs->dest_addr.sock));
281 seq_printf(seq, "%08X %08X %02X %03d\n",
282 atomic_read(&s->sk_wmem_alloc),
283 atomic_read(&s->sk_rmem_alloc),
284 s->sk_state, SOCK_INODE(s->sk_socket)->i_uid);
289 static struct seq_operations ipx_seq_interface_ops = {
290 .start = ipx_seq_interface_start,
291 .next = ipx_seq_interface_next,
292 .stop = ipx_seq_interface_stop,
293 .show = ipx_seq_interface_show,
296 static struct seq_operations ipx_seq_route_ops = {
297 .start = ipx_seq_route_start,
298 .next = ipx_seq_route_next,
299 .stop = ipx_seq_route_stop,
300 .show = ipx_seq_route_show,
303 static struct seq_operations ipx_seq_socket_ops = {
304 .start = ipx_seq_socket_start,
305 .next = ipx_seq_socket_next,
306 .stop = ipx_seq_interface_stop,
307 .show = ipx_seq_socket_show,
310 static int ipx_seq_route_open(struct inode *inode, struct file *file)
312 return seq_open(file, &ipx_seq_route_ops);
315 static int ipx_seq_interface_open(struct inode *inode, struct file *file)
317 return seq_open(file, &ipx_seq_interface_ops);
320 static int ipx_seq_socket_open(struct inode *inode, struct file *file)
322 return seq_open(file, &ipx_seq_socket_ops);
325 static const struct file_operations ipx_seq_interface_fops = {
326 .owner = THIS_MODULE,
327 .open = ipx_seq_interface_open,
330 .release = seq_release,
333 static const struct file_operations ipx_seq_route_fops = {
334 .owner = THIS_MODULE,
335 .open = ipx_seq_route_open,
338 .release = seq_release,
341 static const struct file_operations ipx_seq_socket_fops = {
342 .owner = THIS_MODULE,
343 .open = ipx_seq_socket_open,
346 .release = seq_release,
349 static struct proc_dir_entry *ipx_proc_dir;
351 int __init ipx_proc_init(void)
353 struct proc_dir_entry *p;
356 ipx_proc_dir = proc_mkdir("ipx", proc_net);
360 p = create_proc_entry("interface", S_IRUGO, ipx_proc_dir);
364 p->proc_fops = &ipx_seq_interface_fops;
365 p = create_proc_entry("route", S_IRUGO, ipx_proc_dir);
369 p->proc_fops = &ipx_seq_route_fops;
370 p = create_proc_entry("socket", S_IRUGO, ipx_proc_dir);
374 p->proc_fops = &ipx_seq_socket_fops;
380 remove_proc_entry("route", ipx_proc_dir);
382 remove_proc_entry("interface", ipx_proc_dir);
384 remove_proc_entry("ipx", proc_net);
388 void __exit ipx_proc_exit(void)
390 remove_proc_entry("interface", ipx_proc_dir);
391 remove_proc_entry("route", ipx_proc_dir);
392 remove_proc_entry("socket", ipx_proc_dir);
393 remove_proc_entry("ipx", proc_net);
396 #else /* CONFIG_PROC_FS */
398 int __init ipx_proc_init(void)
403 void __exit ipx_proc_exit(void)
407 #endif /* CONFIG_PROC_FS */