netfilter: nf_tables: use call_rcu in netlink dumps
[linux/fpc-iii.git] / net / appletalk / atalk_proc.c
blob7214aea14cb371bd991625e15ed9c1bda4518dd7
1 /*
2 * atalk_proc.c - proc support for Appletalk
4 * Copyright(c) Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, version 2.
9 */
11 #include <linux/init.h>
12 #include <linux/proc_fs.h>
13 #include <linux/seq_file.h>
14 #include <net/net_namespace.h>
15 #include <net/sock.h>
16 #include <linux/atalk.h>
17 #include <linux/export.h>
20 static __inline__ struct atalk_iface *atalk_get_interface_idx(loff_t pos)
22 struct atalk_iface *i;
24 for (i = atalk_interfaces; pos && i; i = i->next)
25 --pos;
27 return i;
30 static void *atalk_seq_interface_start(struct seq_file *seq, loff_t *pos)
31 __acquires(atalk_interfaces_lock)
33 loff_t l = *pos;
35 read_lock_bh(&atalk_interfaces_lock);
36 return l ? atalk_get_interface_idx(--l) : SEQ_START_TOKEN;
39 static void *atalk_seq_interface_next(struct seq_file *seq, void *v, loff_t *pos)
41 struct atalk_iface *i;
43 ++*pos;
44 if (v == SEQ_START_TOKEN) {
45 i = NULL;
46 if (atalk_interfaces)
47 i = atalk_interfaces;
48 goto out;
50 i = v;
51 i = i->next;
52 out:
53 return i;
56 static void atalk_seq_interface_stop(struct seq_file *seq, void *v)
57 __releases(atalk_interfaces_lock)
59 read_unlock_bh(&atalk_interfaces_lock);
62 static int atalk_seq_interface_show(struct seq_file *seq, void *v)
64 struct atalk_iface *iface;
66 if (v == SEQ_START_TOKEN) {
67 seq_puts(seq, "Interface Address Networks "
68 "Status\n");
69 goto out;
72 iface = v;
73 seq_printf(seq, "%-16s %04X:%02X %04X-%04X %d\n",
74 iface->dev->name, ntohs(iface->address.s_net),
75 iface->address.s_node, ntohs(iface->nets.nr_firstnet),
76 ntohs(iface->nets.nr_lastnet), iface->status);
77 out:
78 return 0;
81 static __inline__ struct atalk_route *atalk_get_route_idx(loff_t pos)
83 struct atalk_route *r;
85 for (r = atalk_routes; pos && r; r = r->next)
86 --pos;
88 return r;
91 static void *atalk_seq_route_start(struct seq_file *seq, loff_t *pos)
92 __acquires(atalk_routes_lock)
94 loff_t l = *pos;
96 read_lock_bh(&atalk_routes_lock);
97 return l ? atalk_get_route_idx(--l) : SEQ_START_TOKEN;
100 static void *atalk_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
102 struct atalk_route *r;
104 ++*pos;
105 if (v == SEQ_START_TOKEN) {
106 r = NULL;
107 if (atalk_routes)
108 r = atalk_routes;
109 goto out;
111 r = v;
112 r = r->next;
113 out:
114 return r;
117 static void atalk_seq_route_stop(struct seq_file *seq, void *v)
118 __releases(atalk_routes_lock)
120 read_unlock_bh(&atalk_routes_lock);
123 static int atalk_seq_route_show(struct seq_file *seq, void *v)
125 struct atalk_route *rt;
127 if (v == SEQ_START_TOKEN) {
128 seq_puts(seq, "Target Router Flags Dev\n");
129 goto out;
132 if (atrtr_default.dev) {
133 rt = &atrtr_default;
134 seq_printf(seq, "Default %04X:%02X %-4d %s\n",
135 ntohs(rt->gateway.s_net), rt->gateway.s_node,
136 rt->flags, rt->dev->name);
139 rt = v;
140 seq_printf(seq, "%04X:%02X %04X:%02X %-4d %s\n",
141 ntohs(rt->target.s_net), rt->target.s_node,
142 ntohs(rt->gateway.s_net), rt->gateway.s_node,
143 rt->flags, rt->dev->name);
144 out:
145 return 0;
148 static void *atalk_seq_socket_start(struct seq_file *seq, loff_t *pos)
149 __acquires(atalk_sockets_lock)
151 read_lock_bh(&atalk_sockets_lock);
152 return seq_hlist_start_head(&atalk_sockets, *pos);
155 static void *atalk_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
157 return seq_hlist_next(v, &atalk_sockets, pos);
160 static void atalk_seq_socket_stop(struct seq_file *seq, void *v)
161 __releases(atalk_sockets_lock)
163 read_unlock_bh(&atalk_sockets_lock);
166 static int atalk_seq_socket_show(struct seq_file *seq, void *v)
168 struct sock *s;
169 struct atalk_sock *at;
171 if (v == SEQ_START_TOKEN) {
172 seq_printf(seq, "Type Local_addr Remote_addr Tx_queue "
173 "Rx_queue St UID\n");
174 goto out;
177 s = sk_entry(v);
178 at = at_sk(s);
180 seq_printf(seq, "%02X %04X:%02X:%02X %04X:%02X:%02X %08X:%08X "
181 "%02X %u\n",
182 s->sk_type, ntohs(at->src_net), at->src_node, at->src_port,
183 ntohs(at->dest_net), at->dest_node, at->dest_port,
184 sk_wmem_alloc_get(s),
185 sk_rmem_alloc_get(s),
186 s->sk_state,
187 from_kuid_munged(seq_user_ns(seq), sock_i_uid(s)));
188 out:
189 return 0;
192 static const struct seq_operations atalk_seq_interface_ops = {
193 .start = atalk_seq_interface_start,
194 .next = atalk_seq_interface_next,
195 .stop = atalk_seq_interface_stop,
196 .show = atalk_seq_interface_show,
199 static const struct seq_operations atalk_seq_route_ops = {
200 .start = atalk_seq_route_start,
201 .next = atalk_seq_route_next,
202 .stop = atalk_seq_route_stop,
203 .show = atalk_seq_route_show,
206 static const struct seq_operations atalk_seq_socket_ops = {
207 .start = atalk_seq_socket_start,
208 .next = atalk_seq_socket_next,
209 .stop = atalk_seq_socket_stop,
210 .show = atalk_seq_socket_show,
213 static int atalk_seq_interface_open(struct inode *inode, struct file *file)
215 return seq_open(file, &atalk_seq_interface_ops);
218 static int atalk_seq_route_open(struct inode *inode, struct file *file)
220 return seq_open(file, &atalk_seq_route_ops);
223 static int atalk_seq_socket_open(struct inode *inode, struct file *file)
225 return seq_open(file, &atalk_seq_socket_ops);
228 static const struct file_operations atalk_seq_interface_fops = {
229 .open = atalk_seq_interface_open,
230 .read = seq_read,
231 .llseek = seq_lseek,
232 .release = seq_release,
235 static const struct file_operations atalk_seq_route_fops = {
236 .open = atalk_seq_route_open,
237 .read = seq_read,
238 .llseek = seq_lseek,
239 .release = seq_release,
242 static const struct file_operations atalk_seq_socket_fops = {
243 .open = atalk_seq_socket_open,
244 .read = seq_read,
245 .llseek = seq_lseek,
246 .release = seq_release,
249 static struct proc_dir_entry *atalk_proc_dir;
251 int __init atalk_proc_init(void)
253 struct proc_dir_entry *p;
254 int rc = -ENOMEM;
256 atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
257 if (!atalk_proc_dir)
258 goto out;
260 p = proc_create("interface", 0444, atalk_proc_dir,
261 &atalk_seq_interface_fops);
262 if (!p)
263 goto out_interface;
265 p = proc_create("route", 0444, atalk_proc_dir,
266 &atalk_seq_route_fops);
267 if (!p)
268 goto out_route;
270 p = proc_create("socket", 0444, atalk_proc_dir,
271 &atalk_seq_socket_fops);
272 if (!p)
273 goto out_socket;
275 p = proc_create("arp", 0444, atalk_proc_dir, &atalk_seq_arp_fops);
276 if (!p)
277 goto out_arp;
279 rc = 0;
280 out:
281 return rc;
282 out_arp:
283 remove_proc_entry("socket", atalk_proc_dir);
284 out_socket:
285 remove_proc_entry("route", atalk_proc_dir);
286 out_route:
287 remove_proc_entry("interface", atalk_proc_dir);
288 out_interface:
289 remove_proc_entry("atalk", init_net.proc_net);
290 goto out;
293 void __exit atalk_proc_exit(void)
295 remove_proc_entry("interface", atalk_proc_dir);
296 remove_proc_entry("route", atalk_proc_dir);
297 remove_proc_entry("socket", atalk_proc_dir);
298 remove_proc_entry("arp", atalk_proc_dir);
299 remove_proc_entry("atalk", init_net.proc_net);