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
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.
17 * 2002/10/06 Arnaldo Carvalho de Melo seq_file support
20 #include <linux/config.h>
21 #include <linux/init.h>
22 #include <linux/proc_fs.h>
23 #include <linux/seq_file.h>
28 static __inline__
struct x25_route
*x25_get_route_idx(loff_t pos
)
30 struct list_head
*route_entry
;
31 struct x25_route
*rt
= NULL
;
33 list_for_each(route_entry
, &x25_route_list
) {
34 rt
= list_entry(route_entry
, struct x25_route
, node
);
43 static void *x25_seq_route_start(struct seq_file
*seq
, loff_t
*pos
)
47 read_lock_bh(&x25_route_list_lock
);
48 return l
? x25_get_route_idx(--l
) : SEQ_START_TOKEN
;
51 static void *x25_seq_route_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
56 if (v
== SEQ_START_TOKEN
) {
58 if (!list_empty(&x25_route_list
))
59 rt
= list_entry(x25_route_list
.next
,
60 struct x25_route
, node
);
64 if (rt
->node
.next
!= &x25_route_list
)
65 rt
= list_entry(rt
->node
.next
, struct x25_route
, node
);
72 static void x25_seq_route_stop(struct seq_file
*seq
, void *v
)
74 read_unlock_bh(&x25_route_list_lock
);
77 static int x25_seq_route_show(struct seq_file
*seq
, void *v
)
81 if (v
== SEQ_START_TOKEN
) {
82 seq_puts(seq
, "Address Digits Device\n");
87 seq_printf(seq
, "%-15s %-6d %-5s\n",
88 rt
->address
.x25_addr
, rt
->sigdigits
,
89 rt
->dev
? rt
->dev
->name
: "???");
94 static __inline__
struct sock
*x25_get_socket_idx(loff_t pos
)
97 struct hlist_node
*node
;
99 sk_for_each(s
, node
, &x25_list
)
107 static void *x25_seq_socket_start(struct seq_file
*seq
, loff_t
*pos
)
111 read_lock_bh(&x25_list_lock
);
112 return l
? x25_get_socket_idx(--l
) : SEQ_START_TOKEN
;
115 static void *x25_seq_socket_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
120 if (v
== SEQ_START_TOKEN
) {
121 s
= sk_head(&x25_list
);
129 static void x25_seq_socket_stop(struct seq_file
*seq
, void *v
)
131 read_unlock_bh(&x25_list_lock
);
134 static int x25_seq_socket_show(struct seq_file
*seq
, void *v
)
137 struct x25_sock
*x25
;
138 struct net_device
*dev
;
141 if (v
== SEQ_START_TOKEN
) {
142 seq_printf(seq
, "dest_addr src_addr dev lci st vs vr "
143 "va t t2 t21 t22 t23 Snd-Q Rcv-Q inode\n");
150 if (!x25
->neighbour
|| (dev
= x25
->neighbour
->dev
) == NULL
)
153 devname
= x25
->neighbour
->dev
->name
;
155 seq_printf(seq
, "%-10s %-10s %-5s %3.3X %d %d %d %d %3lu %3lu "
156 "%3lu %3lu %3lu %5d %5d %ld\n",
157 !x25
->dest_addr
.x25_addr
[0] ? "*" : x25
->dest_addr
.x25_addr
,
158 !x25
->source_addr
.x25_addr
[0] ? "*" : x25
->source_addr
.x25_addr
,
159 devname
, x25
->lci
& 0x0FFF, x25
->state
, x25
->vs
, x25
->vr
,
160 x25
->va
, x25_display_timer(s
) / HZ
, x25
->t2
/ HZ
,
161 x25
->t21
/ HZ
, x25
->t22
/ HZ
, x25
->t23
/ HZ
,
162 atomic_read(&s
->sk_wmem_alloc
),
163 atomic_read(&s
->sk_rmem_alloc
),
164 s
->sk_socket
? SOCK_INODE(s
->sk_socket
)->i_ino
: 0L);
169 static struct seq_operations x25_seq_route_ops
= {
170 .start
= x25_seq_route_start
,
171 .next
= x25_seq_route_next
,
172 .stop
= x25_seq_route_stop
,
173 .show
= x25_seq_route_show
,
176 static struct seq_operations x25_seq_socket_ops
= {
177 .start
= x25_seq_socket_start
,
178 .next
= x25_seq_socket_next
,
179 .stop
= x25_seq_socket_stop
,
180 .show
= x25_seq_socket_show
,
183 static int x25_seq_socket_open(struct inode
*inode
, struct file
*file
)
185 return seq_open(file
, &x25_seq_socket_ops
);
188 static int x25_seq_route_open(struct inode
*inode
, struct file
*file
)
190 return seq_open(file
, &x25_seq_route_ops
);
193 static struct file_operations x25_seq_socket_fops
= {
194 .owner
= THIS_MODULE
,
195 .open
= x25_seq_socket_open
,
198 .release
= seq_release
,
201 static struct file_operations x25_seq_route_fops
= {
202 .owner
= THIS_MODULE
,
203 .open
= x25_seq_route_open
,
206 .release
= seq_release
,
209 static struct proc_dir_entry
*x25_proc_dir
;
211 int __init
x25_proc_init(void)
213 struct proc_dir_entry
*p
;
216 x25_proc_dir
= proc_mkdir("x25", proc_net
);
220 p
= create_proc_entry("route", S_IRUGO
, x25_proc_dir
);
223 p
->proc_fops
= &x25_seq_route_fops
;
225 p
= create_proc_entry("socket", S_IRUGO
, x25_proc_dir
);
228 p
->proc_fops
= &x25_seq_socket_fops
;
233 remove_proc_entry("route", x25_proc_dir
);
235 remove_proc_entry("x25", proc_net
);
239 void __exit
x25_proc_exit(void)
241 remove_proc_entry("route", x25_proc_dir
);
242 remove_proc_entry("socket", x25_proc_dir
);
243 remove_proc_entry("x25", proc_net
);
246 #else /* CONFIG_PROC_FS */
248 int __init
x25_proc_init(void)
253 void __exit
x25_proc_exit(void)
256 #endif /* CONFIG_PROC_FS */