]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* |
3 | * IPX proc routines | |
4 | * | |
5 | * Copyright(C) Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 2002 | |
6 | */ | |
7 | ||
1da177e4 LT |
8 | #include <linux/init.h> |
9 | #ifdef CONFIG_PROC_FS | |
10 | #include <linux/proc_fs.h> | |
11 | #include <linux/spinlock.h> | |
12 | #include <linux/seq_file.h> | |
bc3b2d7f | 13 | #include <linux/export.h> |
457c4cbc | 14 | #include <net/net_namespace.h> |
c752f073 | 15 | #include <net/tcp_states.h> |
1da177e4 LT |
16 | #include <net/ipx.h> |
17 | ||
1da177e4 LT |
18 | static void *ipx_seq_interface_start(struct seq_file *seq, loff_t *pos) |
19 | { | |
1da177e4 | 20 | spin_lock_bh(&ipx_interfaces_lock); |
a2b79b41 | 21 | return seq_list_start_head(&ipx_interfaces, *pos); |
1da177e4 LT |
22 | } |
23 | ||
24 | static void *ipx_seq_interface_next(struct seq_file *seq, void *v, loff_t *pos) | |
25 | { | |
a2b79b41 | 26 | return seq_list_next(v, &ipx_interfaces, pos); |
1da177e4 LT |
27 | } |
28 | ||
29 | static void ipx_seq_interface_stop(struct seq_file *seq, void *v) | |
30 | { | |
31 | spin_unlock_bh(&ipx_interfaces_lock); | |
32 | } | |
33 | ||
34 | static int ipx_seq_interface_show(struct seq_file *seq, void *v) | |
35 | { | |
36 | struct ipx_interface *i; | |
37 | ||
a2b79b41 | 38 | if (v == &ipx_interfaces) { |
1da177e4 LT |
39 | seq_puts(seq, "Network Node_Address Primary Device " |
40 | "Frame_Type"); | |
41 | #ifdef IPX_REFCNT_DEBUG | |
42 | seq_puts(seq, " refcnt"); | |
43 | #endif | |
44 | seq_puts(seq, "\n"); | |
45 | goto out; | |
46 | } | |
47 | ||
a2b79b41 | 48 | i = list_entry(v, struct ipx_interface, node); |
e7b6658e | 49 | seq_printf(seq, "%08X ", ntohl(i->if_netnum)); |
1da177e4 LT |
50 | seq_printf(seq, "%02X%02X%02X%02X%02X%02X ", |
51 | i->if_node[0], i->if_node[1], i->if_node[2], | |
52 | i->if_node[3], i->if_node[4], i->if_node[5]); | |
53 | seq_printf(seq, "%-9s", i == ipx_primary_net ? "Yes" : "No"); | |
54 | seq_printf(seq, "%-11s", ipx_device_name(i)); | |
55 | seq_printf(seq, "%-9s", ipx_frame_name(i->if_dlink_type)); | |
56 | #ifdef IPX_REFCNT_DEBUG | |
d25189ca | 57 | seq_printf(seq, "%6d", refcount_read(&i->refcnt)); |
1da177e4 LT |
58 | #endif |
59 | seq_puts(seq, "\n"); | |
60 | out: | |
61 | return 0; | |
62 | } | |
63 | ||
1da177e4 LT |
64 | static void *ipx_seq_route_start(struct seq_file *seq, loff_t *pos) |
65 | { | |
1da177e4 | 66 | read_lock_bh(&ipx_routes_lock); |
a2b79b41 | 67 | return seq_list_start_head(&ipx_routes, *pos); |
1da177e4 LT |
68 | } |
69 | ||
70 | static void *ipx_seq_route_next(struct seq_file *seq, void *v, loff_t *pos) | |
71 | { | |
a2b79b41 | 72 | return seq_list_next(v, &ipx_routes, pos); |
1da177e4 LT |
73 | } |
74 | ||
75 | static void ipx_seq_route_stop(struct seq_file *seq, void *v) | |
76 | { | |
77 | read_unlock_bh(&ipx_routes_lock); | |
78 | } | |
79 | ||
80 | static int ipx_seq_route_show(struct seq_file *seq, void *v) | |
81 | { | |
82 | struct ipx_route *rt; | |
83 | ||
a2b79b41 | 84 | if (v == &ipx_routes) { |
1da177e4 LT |
85 | seq_puts(seq, "Network Router_Net Router_Node\n"); |
86 | goto out; | |
87 | } | |
a2b79b41 LZ |
88 | |
89 | rt = list_entry(v, struct ipx_route, node); | |
90 | ||
e7b6658e | 91 | seq_printf(seq, "%08X ", ntohl(rt->ir_net)); |
1da177e4 | 92 | if (rt->ir_routed) |
e0f36310 FF |
93 | seq_printf(seq, "%08X %02X%02X%02X%02X%02X%02X\n", |
94 | ntohl(rt->ir_intrfc->if_netnum), | |
1da177e4 LT |
95 | rt->ir_router_node[0], rt->ir_router_node[1], |
96 | rt->ir_router_node[2], rt->ir_router_node[3], | |
97 | rt->ir_router_node[4], rt->ir_router_node[5]); | |
98 | else | |
99 | seq_puts(seq, "Directly Connected\n"); | |
100 | out: | |
101 | return 0; | |
102 | } | |
103 | ||
104 | static __inline__ struct sock *ipx_get_socket_idx(loff_t pos) | |
105 | { | |
106 | struct sock *s = NULL; | |
1da177e4 LT |
107 | struct ipx_interface *i; |
108 | ||
109 | list_for_each_entry(i, &ipx_interfaces, node) { | |
110 | spin_lock_bh(&i->if_sklist_lock); | |
b67bfe0d | 111 | sk_for_each(s, &i->if_sklist) { |
1da177e4 LT |
112 | if (!pos) |
113 | break; | |
114 | --pos; | |
115 | } | |
116 | spin_unlock_bh(&i->if_sklist_lock); | |
117 | if (!pos) { | |
b67bfe0d | 118 | if (s) |
1da177e4 LT |
119 | goto found; |
120 | break; | |
121 | } | |
122 | } | |
123 | s = NULL; | |
124 | found: | |
125 | return s; | |
126 | } | |
127 | ||
128 | static 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 | ||
136 | static 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 (;;) { | |
a2b79b41 | 164 | if (i->node.next == &ipx_interfaces) |
1da177e4 | 165 | break; |
a2b79b41 | 166 | i = list_entry(i->node.next, struct ipx_interface, node); |
1da177e4 LT |
167 | 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 | } | |
174 | out: | |
175 | return sk; | |
176 | } | |
177 | ||
178 | static 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 | |
e7b6658e FF |
198 | seq_printf(seq, "%08X:%02X%02X%02X%02X%02X%02X:%04X ", |
199 | ntohl(ipxs->intrfc->if_netnum), | |
1da177e4 | 200 | ipxs->node[0], ipxs->node[1], ipxs->node[2], ipxs->node[3], |
4833ed09 | 201 | ipxs->node[4], ipxs->node[5], ntohs(ipxs->port)); |
1da177e4 | 202 | #else |
e7b6658e | 203 | seq_printf(seq, "%08X:%04X ", ntohl(ipxs->intrfc->if_netnum), |
4833ed09 | 204 | ntohs(ipxs->port)); |
1da177e4 LT |
205 | #endif /* CONFIG_IPX_INTERN */ |
206 | if (s->sk_state != TCP_ESTABLISHED) | |
207 | seq_printf(seq, "%-28s", "Not_Connected"); | |
208 | else { | |
e7b6658e FF |
209 | seq_printf(seq, "%08X:%02X%02X%02X%02X%02X%02X:%04X ", |
210 | ntohl(ipxs->dest_addr.net), | |
1da177e4 LT |
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], | |
4833ed09 | 214 | ntohs(ipxs->dest_addr.sock)); |
1da177e4 LT |
215 | } |
216 | ||
d14c5ab6 | 217 | seq_printf(seq, "%08X %08X %02X %03u\n", |
31e6d363 ED |
218 | sk_wmem_alloc_get(s), |
219 | sk_rmem_alloc_get(s), | |
a7cb5a49 EB |
220 | s->sk_state, |
221 | from_kuid_munged(seq_user_ns(seq), sock_i_uid(s))); | |
1da177e4 LT |
222 | out: |
223 | return 0; | |
224 | } | |
225 | ||
56b3d975 | 226 | static const struct seq_operations ipx_seq_interface_ops = { |
1da177e4 LT |
227 | .start = ipx_seq_interface_start, |
228 | .next = ipx_seq_interface_next, | |
229 | .stop = ipx_seq_interface_stop, | |
230 | .show = ipx_seq_interface_show, | |
231 | }; | |
232 | ||
56b3d975 | 233 | static const struct seq_operations ipx_seq_route_ops = { |
1da177e4 LT |
234 | .start = ipx_seq_route_start, |
235 | .next = ipx_seq_route_next, | |
236 | .stop = ipx_seq_route_stop, | |
237 | .show = ipx_seq_route_show, | |
238 | }; | |
239 | ||
56b3d975 | 240 | static const struct seq_operations ipx_seq_socket_ops = { |
1da177e4 LT |
241 | .start = ipx_seq_socket_start, |
242 | .next = ipx_seq_socket_next, | |
243 | .stop = ipx_seq_interface_stop, | |
244 | .show = ipx_seq_socket_show, | |
245 | }; | |
246 | ||
247 | static int ipx_seq_route_open(struct inode *inode, struct file *file) | |
248 | { | |
249 | return seq_open(file, &ipx_seq_route_ops); | |
250 | } | |
251 | ||
252 | static int ipx_seq_interface_open(struct inode *inode, struct file *file) | |
253 | { | |
254 | return seq_open(file, &ipx_seq_interface_ops); | |
255 | } | |
256 | ||
257 | static int ipx_seq_socket_open(struct inode *inode, struct file *file) | |
258 | { | |
259 | return seq_open(file, &ipx_seq_socket_ops); | |
260 | } | |
261 | ||
9a32144e | 262 | static const struct file_operations ipx_seq_interface_fops = { |
1da177e4 LT |
263 | .owner = THIS_MODULE, |
264 | .open = ipx_seq_interface_open, | |
265 | .read = seq_read, | |
266 | .llseek = seq_lseek, | |
267 | .release = seq_release, | |
268 | }; | |
269 | ||
9a32144e | 270 | static const struct file_operations ipx_seq_route_fops = { |
1da177e4 LT |
271 | .owner = THIS_MODULE, |
272 | .open = ipx_seq_route_open, | |
273 | .read = seq_read, | |
274 | .llseek = seq_lseek, | |
275 | .release = seq_release, | |
276 | }; | |
277 | ||
9a32144e | 278 | static const struct file_operations ipx_seq_socket_fops = { |
1da177e4 LT |
279 | .owner = THIS_MODULE, |
280 | .open = ipx_seq_socket_open, | |
281 | .read = seq_read, | |
282 | .llseek = seq_lseek, | |
283 | .release = seq_release, | |
284 | }; | |
285 | ||
286 | static struct proc_dir_entry *ipx_proc_dir; | |
287 | ||
288 | int __init ipx_proc_init(void) | |
289 | { | |
290 | struct proc_dir_entry *p; | |
291 | int rc = -ENOMEM; | |
981c0ff6 | 292 | |
457c4cbc | 293 | ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net); |
1da177e4 LT |
294 | |
295 | if (!ipx_proc_dir) | |
296 | goto out; | |
1e15dc98 WC |
297 | p = proc_create("interface", S_IRUGO, |
298 | ipx_proc_dir, &ipx_seq_interface_fops); | |
1da177e4 LT |
299 | if (!p) |
300 | goto out_interface; | |
301 | ||
1e15dc98 | 302 | p = proc_create("route", S_IRUGO, ipx_proc_dir, &ipx_seq_route_fops); |
1da177e4 LT |
303 | if (!p) |
304 | goto out_route; | |
305 | ||
1e15dc98 | 306 | p = proc_create("socket", S_IRUGO, ipx_proc_dir, &ipx_seq_socket_fops); |
1da177e4 LT |
307 | if (!p) |
308 | goto out_socket; | |
309 | ||
1da177e4 LT |
310 | rc = 0; |
311 | out: | |
312 | return rc; | |
313 | out_socket: | |
314 | remove_proc_entry("route", ipx_proc_dir); | |
315 | out_route: | |
316 | remove_proc_entry("interface", ipx_proc_dir); | |
317 | out_interface: | |
457c4cbc | 318 | remove_proc_entry("ipx", init_net.proc_net); |
1da177e4 LT |
319 | goto out; |
320 | } | |
321 | ||
322 | void __exit ipx_proc_exit(void) | |
323 | { | |
324 | remove_proc_entry("interface", ipx_proc_dir); | |
325 | remove_proc_entry("route", ipx_proc_dir); | |
326 | remove_proc_entry("socket", ipx_proc_dir); | |
457c4cbc | 327 | remove_proc_entry("ipx", init_net.proc_net); |
1da177e4 LT |
328 | } |
329 | ||
330 | #else /* CONFIG_PROC_FS */ | |
331 | ||
332 | int __init ipx_proc_init(void) | |
333 | { | |
334 | return 0; | |
335 | } | |
336 | ||
337 | void __exit ipx_proc_exit(void) | |
338 | { | |
339 | } | |
340 | ||
341 | #endif /* CONFIG_PROC_FS */ |