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 <linux/export.h>
13 #include <net/net_namespace.h>
14 #include <net/tcp_states.h>
17 static void *ipx_seq_interface_start(struct seq_file
*seq
, loff_t
*pos
)
19 spin_lock_bh(&ipx_interfaces_lock
);
20 return seq_list_start_head(&ipx_interfaces
, *pos
);
23 static void *ipx_seq_interface_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
25 return seq_list_next(v
, &ipx_interfaces
, pos
);
28 static void ipx_seq_interface_stop(struct seq_file
*seq
, void *v
)
30 spin_unlock_bh(&ipx_interfaces_lock
);
33 static int ipx_seq_interface_show(struct seq_file
*seq
, void *v
)
35 struct ipx_interface
*i
;
37 if (v
== &ipx_interfaces
) {
38 seq_puts(seq
, "Network Node_Address Primary Device "
40 #ifdef IPX_REFCNT_DEBUG
41 seq_puts(seq
, " refcnt");
47 i
= list_entry(v
, struct ipx_interface
, node
);
48 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
));
63 static void *ipx_seq_route_start(struct seq_file
*seq
, loff_t
*pos
)
65 read_lock_bh(&ipx_routes_lock
);
66 return seq_list_start_head(&ipx_routes
, *pos
);
69 static void *ipx_seq_route_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
71 return seq_list_next(v
, &ipx_routes
, pos
);
74 static void ipx_seq_route_stop(struct seq_file
*seq
, void *v
)
76 read_unlock_bh(&ipx_routes_lock
);
79 static int ipx_seq_route_show(struct seq_file
*seq
, void *v
)
83 if (v
== &ipx_routes
) {
84 seq_puts(seq
, "Network Router_Net Router_Node\n");
88 rt
= list_entry(v
, struct ipx_route
, node
);
90 seq_printf(seq
, "%08lX ", (unsigned long int)ntohl(rt
->ir_net
));
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]);
98 seq_puts(seq
, "Directly Connected\n");
103 static __inline__
struct sock
*ipx_get_socket_idx(loff_t pos
)
105 struct sock
*s
= NULL
;
106 struct hlist_node
*node
;
107 struct ipx_interface
*i
;
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
) {
116 spin_unlock_bh(&i
->if_sklist_lock
);
128 static void *ipx_seq_socket_start(struct seq_file
*seq
, loff_t
*pos
)
132 spin_lock_bh(&ipx_interfaces_lock
);
133 return l
? ipx_get_socket_idx(--l
) : SEQ_START_TOKEN
;
136 static void *ipx_seq_socket_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
138 struct sock
* sk
, *next
;
139 struct ipx_interface
*i
;
140 struct ipx_sock
*ipxs
;
143 if (v
== SEQ_START_TOKEN
) {
145 i
= ipx_interfaces_head();
148 sk
= sk_head(&i
->if_sklist
);
150 spin_lock_bh(&i
->if_sklist_lock
);
161 spin_unlock_bh(&i
->if_sklist_lock
);
164 if (i
->node
.next
== &ipx_interfaces
)
166 i
= list_entry(i
->node
.next
, struct ipx_interface
, node
);
167 spin_lock_bh(&i
->if_sklist_lock
);
168 if (!hlist_empty(&i
->if_sklist
)) {
169 sk
= sk_head(&i
->if_sklist
);
172 spin_unlock_bh(&i
->if_sklist_lock
);
178 static int ipx_seq_socket_show(struct seq_file
*seq
, void *v
)
181 struct ipx_sock
*ipxs
;
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");
189 seq_puts(seq
, "Local_Address Remote_Address "
190 "Tx_Queue Rx_Queue State Uid\n");
197 #ifdef CONFIG_IPX_INTERN
198 seq_printf(seq
, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
199 (unsigned long)ntohl(ipxs
->intrfc
->if_netnum
),
200 ipxs
->node
[0], ipxs
->node
[1], ipxs
->node
[2], ipxs
->node
[3],
201 ipxs
->node
[4], ipxs
->node
[5], ntohs(ipxs
->port
));
203 seq_printf(seq
, "%08lX:%04X ", (unsigned long) ntohl(ipxs
->intrfc
->if_netnum
),
205 #endif /* CONFIG_IPX_INTERN */
206 if (s
->sk_state
!= TCP_ESTABLISHED
)
207 seq_printf(seq
, "%-28s", "Not_Connected");
209 seq_printf(seq
, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
210 (unsigned long)ntohl(ipxs
->dest_addr
.net
),
211 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],
214 ntohs(ipxs
->dest_addr
.sock
));
217 seq_printf(seq
, "%08X %08X %02X %03d\n",
218 sk_wmem_alloc_get(s
),
219 sk_rmem_alloc_get(s
),
220 s
->sk_state
, SOCK_INODE(s
->sk_socket
)->i_uid
);
225 static const struct seq_operations ipx_seq_interface_ops
= {
226 .start
= ipx_seq_interface_start
,
227 .next
= ipx_seq_interface_next
,
228 .stop
= ipx_seq_interface_stop
,
229 .show
= ipx_seq_interface_show
,
232 static const struct seq_operations ipx_seq_route_ops
= {
233 .start
= ipx_seq_route_start
,
234 .next
= ipx_seq_route_next
,
235 .stop
= ipx_seq_route_stop
,
236 .show
= ipx_seq_route_show
,
239 static const struct seq_operations ipx_seq_socket_ops
= {
240 .start
= ipx_seq_socket_start
,
241 .next
= ipx_seq_socket_next
,
242 .stop
= ipx_seq_interface_stop
,
243 .show
= ipx_seq_socket_show
,
246 static int ipx_seq_route_open(struct inode
*inode
, struct file
*file
)
248 return seq_open(file
, &ipx_seq_route_ops
);
251 static int ipx_seq_interface_open(struct inode
*inode
, struct file
*file
)
253 return seq_open(file
, &ipx_seq_interface_ops
);
256 static int ipx_seq_socket_open(struct inode
*inode
, struct file
*file
)
258 return seq_open(file
, &ipx_seq_socket_ops
);
261 static const struct file_operations ipx_seq_interface_fops
= {
262 .owner
= THIS_MODULE
,
263 .open
= ipx_seq_interface_open
,
266 .release
= seq_release
,
269 static const struct file_operations ipx_seq_route_fops
= {
270 .owner
= THIS_MODULE
,
271 .open
= ipx_seq_route_open
,
274 .release
= seq_release
,
277 static const struct file_operations ipx_seq_socket_fops
= {
278 .owner
= THIS_MODULE
,
279 .open
= ipx_seq_socket_open
,
282 .release
= seq_release
,
285 static struct proc_dir_entry
*ipx_proc_dir
;
287 int __init
ipx_proc_init(void)
289 struct proc_dir_entry
*p
;
292 ipx_proc_dir
= proc_mkdir("ipx", init_net
.proc_net
);
296 p
= proc_create("interface", S_IRUGO
,
297 ipx_proc_dir
, &ipx_seq_interface_fops
);
301 p
= proc_create("route", S_IRUGO
, ipx_proc_dir
, &ipx_seq_route_fops
);
305 p
= proc_create("socket", S_IRUGO
, ipx_proc_dir
, &ipx_seq_socket_fops
);
313 remove_proc_entry("route", ipx_proc_dir
);
315 remove_proc_entry("interface", ipx_proc_dir
);
317 remove_proc_entry("ipx", init_net
.proc_net
);
321 void __exit
ipx_proc_exit(void)
323 remove_proc_entry("interface", ipx_proc_dir
);
324 remove_proc_entry("route", ipx_proc_dir
);
325 remove_proc_entry("socket", ipx_proc_dir
);
326 remove_proc_entry("ipx", init_net
.proc_net
);
329 #else /* CONFIG_PROC_FS */
331 int __init
ipx_proc_init(void)
336 void __exit
ipx_proc_exit(void)
340 #endif /* CONFIG_PROC_FS */