[NETFILTER]: ipt_TCPMSS: reformat
[hh.org.git] / net / x25 / x25_proc.c
bloba11837d361d2dd7582794be5c56ef4ce744b031e
1 /*
2 * X.25 Packet Layer release 002
4 * This is ALPHA test software. This code may break your machine,
5 * randomly fail to work with new releases, misbehave and/or generally
6 * screw up. It might even work.
8 * This code REQUIRES 2.4 with seq_file support
10 * This module:
11 * This module is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
16 * History
17 * 2002/10/06 Arnaldo Carvalho de Melo seq_file support
20 #include <linux/init.h>
21 #include <linux/proc_fs.h>
22 #include <linux/seq_file.h>
23 #include <net/sock.h>
24 #include <net/x25.h>
26 #ifdef CONFIG_PROC_FS
27 static __inline__ struct x25_route *x25_get_route_idx(loff_t pos)
29 struct list_head *route_entry;
30 struct x25_route *rt = NULL;
32 list_for_each(route_entry, &x25_route_list) {
33 rt = list_entry(route_entry, struct x25_route, node);
34 if (!pos--)
35 goto found;
37 rt = NULL;
38 found:
39 return rt;
42 static void *x25_seq_route_start(struct seq_file *seq, loff_t *pos)
44 loff_t l = *pos;
46 read_lock_bh(&x25_route_list_lock);
47 return l ? x25_get_route_idx(--l) : SEQ_START_TOKEN;
50 static void *x25_seq_route_next(struct seq_file *seq, void *v, loff_t *pos)
52 struct x25_route *rt;
54 ++*pos;
55 if (v == SEQ_START_TOKEN) {
56 rt = NULL;
57 if (!list_empty(&x25_route_list))
58 rt = list_entry(x25_route_list.next,
59 struct x25_route, node);
60 goto out;
62 rt = v;
63 if (rt->node.next != &x25_route_list)
64 rt = list_entry(rt->node.next, struct x25_route, node);
65 else
66 rt = NULL;
67 out:
68 return rt;
71 static void x25_seq_route_stop(struct seq_file *seq, void *v)
73 read_unlock_bh(&x25_route_list_lock);
76 static int x25_seq_route_show(struct seq_file *seq, void *v)
78 struct x25_route *rt;
80 if (v == SEQ_START_TOKEN) {
81 seq_puts(seq, "Address Digits Device\n");
82 goto out;
85 rt = v;
86 seq_printf(seq, "%-15s %-6d %-5s\n",
87 rt->address.x25_addr, rt->sigdigits,
88 rt->dev ? rt->dev->name : "???");
89 out:
90 return 0;
93 static __inline__ struct sock *x25_get_socket_idx(loff_t pos)
95 struct sock *s;
96 struct hlist_node *node;
98 sk_for_each(s, node, &x25_list)
99 if (!pos--)
100 goto found;
101 s = NULL;
102 found:
103 return s;
106 static void *x25_seq_socket_start(struct seq_file *seq, loff_t *pos)
108 loff_t l = *pos;
110 read_lock_bh(&x25_list_lock);
111 return l ? x25_get_socket_idx(--l) : SEQ_START_TOKEN;
114 static void *x25_seq_socket_next(struct seq_file *seq, void *v, loff_t *pos)
116 struct sock *s;
118 ++*pos;
119 if (v == SEQ_START_TOKEN) {
120 s = sk_head(&x25_list);
121 goto out;
123 s = sk_next(v);
124 out:
125 return s;
128 static void x25_seq_socket_stop(struct seq_file *seq, void *v)
130 read_unlock_bh(&x25_list_lock);
133 static int x25_seq_socket_show(struct seq_file *seq, void *v)
135 struct sock *s;
136 struct x25_sock *x25;
137 struct net_device *dev;
138 const char *devname;
140 if (v == SEQ_START_TOKEN) {
141 seq_printf(seq, "dest_addr src_addr dev lci st vs vr "
142 "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
143 goto out;
146 s = v;
147 x25 = x25_sk(s);
149 if (!x25->neighbour || (dev = x25->neighbour->dev) == NULL)
150 devname = "???";
151 else
152 devname = x25->neighbour->dev->name;
154 seq_printf(seq, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
155 "%3lu %3lu %3lu %5d %5d %ld\n",
156 !x25->dest_addr.x25_addr[0] ? "*" : x25->dest_addr.x25_addr,
157 !x25->source_addr.x25_addr[0] ? "*" : x25->source_addr.x25_addr,
158 devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
159 x25->va, x25_display_timer(s) / HZ, x25->t2 / HZ,
160 x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
161 atomic_read(&s->sk_wmem_alloc),
162 atomic_read(&s->sk_rmem_alloc),
163 s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
164 out:
165 return 0;
168 static struct seq_operations x25_seq_route_ops = {
169 .start = x25_seq_route_start,
170 .next = x25_seq_route_next,
171 .stop = x25_seq_route_stop,
172 .show = x25_seq_route_show,
175 static struct seq_operations x25_seq_socket_ops = {
176 .start = x25_seq_socket_start,
177 .next = x25_seq_socket_next,
178 .stop = x25_seq_socket_stop,
179 .show = x25_seq_socket_show,
182 static int x25_seq_socket_open(struct inode *inode, struct file *file)
184 return seq_open(file, &x25_seq_socket_ops);
187 static int x25_seq_route_open(struct inode *inode, struct file *file)
189 return seq_open(file, &x25_seq_route_ops);
192 static struct file_operations x25_seq_socket_fops = {
193 .owner = THIS_MODULE,
194 .open = x25_seq_socket_open,
195 .read = seq_read,
196 .llseek = seq_lseek,
197 .release = seq_release,
200 static struct file_operations x25_seq_route_fops = {
201 .owner = THIS_MODULE,
202 .open = x25_seq_route_open,
203 .read = seq_read,
204 .llseek = seq_lseek,
205 .release = seq_release,
208 static struct proc_dir_entry *x25_proc_dir;
210 int __init x25_proc_init(void)
212 struct proc_dir_entry *p;
213 int rc = -ENOMEM;
215 x25_proc_dir = proc_mkdir("x25", proc_net);
216 if (!x25_proc_dir)
217 goto out;
219 p = create_proc_entry("route", S_IRUGO, x25_proc_dir);
220 if (!p)
221 goto out_route;
222 p->proc_fops = &x25_seq_route_fops;
224 p = create_proc_entry("socket", S_IRUGO, x25_proc_dir);
225 if (!p)
226 goto out_socket;
227 p->proc_fops = &x25_seq_socket_fops;
228 rc = 0;
229 out:
230 return rc;
231 out_socket:
232 remove_proc_entry("route", x25_proc_dir);
233 out_route:
234 remove_proc_entry("x25", proc_net);
235 goto out;
238 void __exit x25_proc_exit(void)
240 remove_proc_entry("route", x25_proc_dir);
241 remove_proc_entry("socket", x25_proc_dir);
242 remove_proc_entry("x25", proc_net);
245 #else /* CONFIG_PROC_FS */
247 int __init x25_proc_init(void)
249 return 0;
252 void __exit x25_proc_exit(void)
255 #endif /* CONFIG_PROC_FS */