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/net_namespace.h>
13 #include <net/tcp_states.h>
16 static void *ipx_seq_interface_start(struct seq_file
*seq
, loff_t
*pos
)
18 spin_lock_bh(&ipx_interfaces_lock
);
19 return seq_list_start_head(&ipx_interfaces
, *pos
);
22 static void *ipx_seq_interface_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
24 return seq_list_next(v
, &ipx_interfaces
, pos
);
27 static void ipx_seq_interface_stop(struct seq_file
*seq
, void *v
)
29 spin_unlock_bh(&ipx_interfaces_lock
);
32 static int ipx_seq_interface_show(struct seq_file
*seq
, void *v
)
34 struct ipx_interface
*i
;
36 if (v
== &ipx_interfaces
) {
37 seq_puts(seq
, "Network Node_Address Primary Device "
39 #ifdef IPX_REFCNT_DEBUG
40 seq_puts(seq
, " refcnt");
46 i
= list_entry(v
, struct ipx_interface
, node
);
47 seq_printf(seq
, "%08lX ", (unsigned long int)ntohl(i
->if_netnum
));
48 seq_printf(seq
, "%02X%02X%02X%02X%02X%02X ",
49 i
->if_node
[0], i
->if_node
[1], i
->if_node
[2],
50 i
->if_node
[3], i
->if_node
[4], i
->if_node
[5]);
51 seq_printf(seq
, "%-9s", i
== ipx_primary_net
? "Yes" : "No");
52 seq_printf(seq
, "%-11s", ipx_device_name(i
));
53 seq_printf(seq
, "%-9s", ipx_frame_name(i
->if_dlink_type
));
54 #ifdef IPX_REFCNT_DEBUG
55 seq_printf(seq
, "%6d", atomic_read(&i
->refcnt
));
62 static void *ipx_seq_route_start(struct seq_file
*seq
, loff_t
*pos
)
64 read_lock_bh(&ipx_routes_lock
);
65 return seq_list_start_head(&ipx_routes
, *pos
);
68 static void *ipx_seq_route_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
70 return seq_list_next(v
, &ipx_routes
, pos
);
73 static void ipx_seq_route_stop(struct seq_file
*seq
, void *v
)
75 read_unlock_bh(&ipx_routes_lock
);
78 static int ipx_seq_route_show(struct seq_file
*seq
, void *v
)
82 if (v
== &ipx_routes
) {
83 seq_puts(seq
, "Network Router_Net Router_Node\n");
87 rt
= list_entry(v
, struct ipx_route
, node
);
89 seq_printf(seq
, "%08lX ", (unsigned long int)ntohl(rt
->ir_net
));
91 seq_printf(seq
, "%08lX %02X%02X%02X%02X%02X%02X\n",
92 (long unsigned int)ntohl(rt
->ir_intrfc
->if_netnum
),
93 rt
->ir_router_node
[0], rt
->ir_router_node
[1],
94 rt
->ir_router_node
[2], rt
->ir_router_node
[3],
95 rt
->ir_router_node
[4], rt
->ir_router_node
[5]);
97 seq_puts(seq
, "Directly Connected\n");
102 static __inline__
struct sock
*ipx_get_socket_idx(loff_t pos
)
104 struct sock
*s
= NULL
;
105 struct hlist_node
*node
;
106 struct ipx_interface
*i
;
108 list_for_each_entry(i
, &ipx_interfaces
, node
) {
109 spin_lock_bh(&i
->if_sklist_lock
);
110 sk_for_each(s
, node
, &i
->if_sklist
) {
115 spin_unlock_bh(&i
->if_sklist_lock
);
127 static void *ipx_seq_socket_start(struct seq_file
*seq
, loff_t
*pos
)
131 spin_lock_bh(&ipx_interfaces_lock
);
132 return l
? ipx_get_socket_idx(--l
) : SEQ_START_TOKEN
;
135 static void *ipx_seq_socket_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
137 struct sock
* sk
, *next
;
138 struct ipx_interface
*i
;
139 struct ipx_sock
*ipxs
;
142 if (v
== SEQ_START_TOKEN
) {
144 i
= ipx_interfaces_head();
147 sk
= sk_head(&i
->if_sklist
);
149 spin_lock_bh(&i
->if_sklist_lock
);
160 spin_unlock_bh(&i
->if_sklist_lock
);
163 if (i
->node
.next
== &ipx_interfaces
)
165 i
= list_entry(i
->node
.next
, struct ipx_interface
, node
);
166 spin_lock_bh(&i
->if_sklist_lock
);
167 if (!hlist_empty(&i
->if_sklist
)) {
168 sk
= sk_head(&i
->if_sklist
);
171 spin_unlock_bh(&i
->if_sklist_lock
);
177 static int ipx_seq_socket_show(struct seq_file
*seq
, void *v
)
180 struct ipx_sock
*ipxs
;
182 if (v
== SEQ_START_TOKEN
) {
183 #ifdef CONFIG_IPX_INTERN
184 seq_puts(seq
, "Local_Address "
185 "Remote_Address Tx_Queue "
186 "Rx_Queue State Uid\n");
188 seq_puts(seq
, "Local_Address Remote_Address "
189 "Tx_Queue Rx_Queue State Uid\n");
196 #ifdef CONFIG_IPX_INTERN
197 seq_printf(seq
, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
198 (unsigned long)ntohl(ipxs
->intrfc
->if_netnum
),
199 ipxs
->node
[0], ipxs
->node
[1], ipxs
->node
[2], ipxs
->node
[3],
200 ipxs
->node
[4], ipxs
->node
[5], ntohs(ipxs
->port
));
202 seq_printf(seq
, "%08lX:%04X ", (unsigned long) ntohl(ipxs
->intrfc
->if_netnum
),
204 #endif /* CONFIG_IPX_INTERN */
205 if (s
->sk_state
!= TCP_ESTABLISHED
)
206 seq_printf(seq
, "%-28s", "Not_Connected");
208 seq_printf(seq
, "%08lX:%02X%02X%02X%02X%02X%02X:%04X ",
209 (unsigned long)ntohl(ipxs
->dest_addr
.net
),
210 ipxs
->dest_addr
.node
[0], ipxs
->dest_addr
.node
[1],
211 ipxs
->dest_addr
.node
[2], ipxs
->dest_addr
.node
[3],
212 ipxs
->dest_addr
.node
[4], ipxs
->dest_addr
.node
[5],
213 ntohs(ipxs
->dest_addr
.sock
));
216 seq_printf(seq
, "%08X %08X %02X %03d\n",
217 sk_wmem_alloc_get(s
),
218 sk_rmem_alloc_get(s
),
219 s
->sk_state
, SOCK_INODE(s
->sk_socket
)->i_uid
);
224 static const struct seq_operations ipx_seq_interface_ops
= {
225 .start
= ipx_seq_interface_start
,
226 .next
= ipx_seq_interface_next
,
227 .stop
= ipx_seq_interface_stop
,
228 .show
= ipx_seq_interface_show
,
231 static const struct seq_operations ipx_seq_route_ops
= {
232 .start
= ipx_seq_route_start
,
233 .next
= ipx_seq_route_next
,
234 .stop
= ipx_seq_route_stop
,
235 .show
= ipx_seq_route_show
,
238 static const struct seq_operations ipx_seq_socket_ops
= {
239 .start
= ipx_seq_socket_start
,
240 .next
= ipx_seq_socket_next
,
241 .stop
= ipx_seq_interface_stop
,
242 .show
= ipx_seq_socket_show
,
245 static int ipx_seq_route_open(struct inode
*inode
, struct file
*file
)
247 return seq_open(file
, &ipx_seq_route_ops
);
250 static int ipx_seq_interface_open(struct inode
*inode
, struct file
*file
)
252 return seq_open(file
, &ipx_seq_interface_ops
);
255 static int ipx_seq_socket_open(struct inode
*inode
, struct file
*file
)
257 return seq_open(file
, &ipx_seq_socket_ops
);
260 static const struct file_operations ipx_seq_interface_fops
= {
261 .owner
= THIS_MODULE
,
262 .open
= ipx_seq_interface_open
,
265 .release
= seq_release
,
268 static const struct file_operations ipx_seq_route_fops
= {
269 .owner
= THIS_MODULE
,
270 .open
= ipx_seq_route_open
,
273 .release
= seq_release
,
276 static const struct file_operations ipx_seq_socket_fops
= {
277 .owner
= THIS_MODULE
,
278 .open
= ipx_seq_socket_open
,
281 .release
= seq_release
,
284 static struct proc_dir_entry
*ipx_proc_dir
;
286 int __init
ipx_proc_init(void)
288 struct proc_dir_entry
*p
;
291 ipx_proc_dir
= proc_mkdir("ipx", init_net
.proc_net
);
295 p
= proc_create("interface", S_IRUGO
,
296 ipx_proc_dir
, &ipx_seq_interface_fops
);
300 p
= proc_create("route", S_IRUGO
, ipx_proc_dir
, &ipx_seq_route_fops
);
304 p
= proc_create("socket", S_IRUGO
, ipx_proc_dir
, &ipx_seq_socket_fops
);
312 remove_proc_entry("route", ipx_proc_dir
);
314 remove_proc_entry("interface", ipx_proc_dir
);
316 remove_proc_entry("ipx", init_net
.proc_net
);
320 void __exit
ipx_proc_exit(void)
322 remove_proc_entry("interface", ipx_proc_dir
);
323 remove_proc_entry("route", ipx_proc_dir
);
324 remove_proc_entry("socket", ipx_proc_dir
);
325 remove_proc_entry("ipx", init_net
.proc_net
);
328 #else /* CONFIG_PROC_FS */
330 int __init
ipx_proc_init(void)
335 void __exit
ipx_proc_exit(void)
339 #endif /* CONFIG_PROC_FS */