This source file includes following definitions.
- proc_lookupnet
- proc_readnetdir
- proc_readnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #include <linux/autoconf.h>
28
29 #include <asm/segment.h>
30
31 #include <linux/errno.h>
32 #include <linux/sched.h>
33 #include <linux/proc_fs.h>
34 #include <linux/stat.h>
35 #include <linux/config.h>
36 #include <linux/mm.h>
37
38
39 static int proc_readnet(struct inode * inode, struct file * file,
40 char * buf, int count);
41 static int proc_readnetdir(struct inode *, struct file *,
42 struct dirent *, int);
43 static int proc_lookupnet(struct inode *,const char *,int,struct inode **);
44
45
46
47 extern int unix_get_info(char *, char **, off_t, int);
48 #ifdef CONFIG_INET
49 extern int tcp_get_info(char *, char **, off_t, int);
50 extern int udp_get_info(char *, char **, off_t, int);
51 extern int raw_get_info(char *, char **, off_t, int);
52 extern int arp_get_info(char *, char **, off_t, int);
53 extern int rarp_get_info(char *, char **, off_t, int);
54 extern int dev_get_info(char *, char **, off_t, int);
55 extern int rt_get_info(char *, char **, off_t, int);
56 extern int snmp_get_info(char *, char **, off_t, int);
57 extern int afinet_get_info(char *, char **, off_t, int);
58 #if defined(CONFIG_WAVELAN)
59 extern int wavelan_get_info(char *, char **, off_t, int);
60 #endif
61 #ifdef CONFIG_IP_ACCT
62 extern int ip_acct_procinfo(char *, char **, off_t, int);
63 extern int ip_acct0_procinfo(char *, char **, off_t, int);
64 #endif
65 #ifdef CONFIG_IP_FIREWALL
66 extern int ip_fw_blk_procinfo(char *, char **, off_t, int);
67 extern int ip_fw_blk0_procinfo(char *, char **, off_t, int);
68 extern int ip_fw_fwd_procinfo(char *, char **, off_t, int);
69 extern int ip_fw_fwd0_procinfo(char *, char **, off_t, int);
70 #endif
71 extern int ip_msqhst_procinfo(char *, char **, off_t, int);
72 extern int ip_mc_procinfo(char *, char **, off_t, int);
73 #endif
74 #ifdef CONFIG_IPX
75 extern int ipx_get_info(char *, char **, off_t, int);
76 extern int ipx_rt_get_info(char *, char **, off_t, int);
77 extern int ipx_get_interface_info(char *, char **, off_t , int);
78 #endif
79 #ifdef CONFIG_AX25
80 extern int ax25_get_info(char *, char **, off_t, int);
81 extern int ax25_rt_get_info(char *, char **, off_t, int);
82 #ifdef CONFIG_NETROM
83 extern int nr_get_info(char *, char **, off_t, int);
84 extern int nr_nodes_get_info(char *, char **, off_t, int);
85 extern int nr_neigh_get_info(char *, char **, off_t, int);
86 #endif
87 #endif
88 #ifdef CONFIG_ATALK
89 extern int atalk_get_info(char *, char **, off_t, int);
90 extern int atalk_rt_get_info(char *, char **, off_t, int);
91 extern int atalk_if_get_info(char *, char **, off_t, int);
92 #endif
93
94
95 static struct file_operations proc_net_operations = {
96 NULL,
97 proc_readnet,
98 NULL,
99 proc_readnetdir,
100 NULL,
101 NULL,
102 NULL,
103 NULL,
104 NULL,
105 NULL
106 };
107
108
109
110
111 struct inode_operations proc_net_inode_operations = {
112 &proc_net_operations,
113 NULL,
114 proc_lookupnet,
115 NULL,
116 NULL,
117 NULL,
118 NULL,
119 NULL,
120 NULL,
121 NULL,
122 NULL,
123 NULL,
124 NULL,
125 NULL,
126 NULL
127 };
128
129 static struct proc_dir_entry net_dir[] = {
130 { PROC_NET, 1, "." },
131 { PROC_ROOT_INO, 2, ".." },
132 { PROC_NET_UNIX, 4, "unix" },
133 #ifdef CONFIG_INET
134 { PROC_NET_ARP, 3, "arp" },
135 { PROC_NET_ROUTE, 5, "route" },
136 { PROC_NET_DEV, 3, "dev" },
137 { PROC_NET_RAW, 3, "raw" },
138 { PROC_NET_TCP, 3, "tcp" },
139 { PROC_NET_UDP, 3, "udp" },
140 { PROC_NET_SNMP, 4, "snmp" },
141 { PROC_NET_SOCKSTAT, 8, "sockstat" },
142 #ifdef CONFIG_INET_RARP
143 { PROC_NET_RARP, 4, "rarp"},
144 #endif
145 #ifdef CONFIG_IP_MULTICAST
146 { PROC_NET_IGMP, 4, "igmp"},
147 #endif
148 #ifdef CONFIG_IP_FIREWALL
149 { PROC_NET_IPFWFWD, 10, "ip_forward"},
150 { PROC_NET_IPFWFWD0, 12, "ip_forward_0"},
151 { PROC_NET_IPFWBLK, 8, "ip_block"},
152 { PROC_NET_IPFWBLK0, 10, "ip_block_0"},
153 #endif
154 #ifdef CONFIG_IP_MASQUERADE
155 { PROC_NET_IPMSQHST, 13, "ip_masquerade"},
156 #endif
157 #ifdef CONFIG_IP_ACCT
158 { PROC_NET_IPACCT, 7, "ip_acct"},
159 { PROC_NET_IPACCT0, 9, "ip_acct_0"},
160 #endif
161 #if defined(CONFIG_WAVELAN)
162 { PROC_NET_WAVELAN, 7, "wavelan" },
163 #endif
164 #endif
165 #ifdef CONFIG_IPX
166 { PROC_NET_IPX_ROUTE, 9, "ipx_route" },
167 { PROC_NET_IPX, 3, "ipx" },
168 { PROC_NET_IPX_INTERFACE, 13, "ipx_interface" },
169 #endif
170 #ifdef CONFIG_AX25
171 { PROC_NET_AX25_ROUTE, 10, "ax25_route" },
172 { PROC_NET_AX25, 4, "ax25" },
173 #ifdef CONFIG_NETROM
174 { PROC_NET_NR_NODES, 8, "nr_nodes" },
175 { PROC_NET_NR_NEIGH, 8, "nr_neigh" },
176 { PROC_NET_NR, 2, "nr" },
177 #endif
178 #endif
179 #ifdef CONFIG_ATALK
180 { PROC_NET_ATALK, 9, "appletalk" },
181 { PROC_NET_AT_ROUTE, 11,"atalk_route" },
182 { PROC_NET_ATIF, 11,"atalk_iface" },
183 #endif
184 { 0, 0, NULL }
185 };
186
187 #define NR_NET_DIRENTRY ((sizeof (net_dir))/(sizeof (net_dir[0])) - 1)
188
189 static int proc_lookupnet(struct inode * dir,const char * name, int len,
190 struct inode ** result)
191 {
192 struct proc_dir_entry *de;
193
194 *result = NULL;
195 if (!dir)
196 return -ENOENT;
197 if (!S_ISDIR(dir->i_mode)) {
198 iput(dir);
199 return -ENOENT;
200 }
201 for (de = net_dir ; de->name ; de++) {
202 if (!proc_match(len, name, de))
203 continue;
204 *result = iget(dir->i_sb, de->low_ino);
205 iput(dir);
206 if (!*result)
207 return -ENOENT;
208 return 0;
209 }
210 iput(dir);
211 return -ENOENT;
212 }
213
214 static int proc_readnetdir(struct inode * inode, struct file * filp,
215 struct dirent * dirent, int count)
216 {
217 struct proc_dir_entry * de;
218 unsigned int ino;
219 int i,j;
220
221 if (!inode || !S_ISDIR(inode->i_mode))
222 return -EBADF;
223 ino = inode->i_ino;
224 if (((unsigned) filp->f_pos) < NR_NET_DIRENTRY) {
225 de = net_dir + filp->f_pos;
226 filp->f_pos++;
227 i = de->namelen;
228 ino = de->low_ino;
229 put_fs_long(ino, &dirent->d_ino);
230 put_fs_word(i,&dirent->d_reclen);
231 put_fs_byte(0,i+dirent->d_name);
232 j = i;
233 while (i--)
234 put_fs_byte(de->name[i], i+dirent->d_name);
235 return j;
236 }
237 return 0;
238 }
239
240
241 #define PROC_BLOCK_SIZE (3*1024)
242
243 static int proc_readnet(struct inode * inode, struct file * file,
244 char * buf, int count)
245 {
246 char * page;
247 int length;
248 unsigned int ino;
249 int bytes=count;
250 int thistime;
251 int copied=0;
252 char *start;
253
254 if (count < 0)
255 return -EINVAL;
256 if (!(page = (char*) __get_free_page(GFP_KERNEL)))
257 return -ENOMEM;
258 ino = inode->i_ino;
259
260 while(bytes>0)
261 {
262 thistime=bytes;
263 if(bytes>PROC_BLOCK_SIZE)
264 thistime=PROC_BLOCK_SIZE;
265
266 switch (ino)
267 {
268 case PROC_NET_UNIX:
269 length = unix_get_info(page,&start,file->f_pos,thistime);
270 break;
271 #ifdef CONFIG_INET
272 case PROC_NET_SOCKSTAT:
273 length = afinet_get_info(page,&start,file->f_pos,thistime);
274 break;
275 case PROC_NET_ARP:
276 length = arp_get_info(page,&start,file->f_pos,thistime);
277 break;
278 case PROC_NET_ROUTE:
279 length = rt_get_info(page,&start,file->f_pos,thistime);
280 break;
281 case PROC_NET_DEV:
282 length = dev_get_info(page,&start,file->f_pos,thistime);
283 break;
284 case PROC_NET_RAW:
285 length = raw_get_info(page,&start,file->f_pos,thistime);
286 break;
287 case PROC_NET_TCP:
288 length = tcp_get_info(page,&start,file->f_pos,thistime);
289 break;
290 case PROC_NET_UDP:
291 length = udp_get_info(page,&start,file->f_pos,thistime);
292 break;
293 case PROC_NET_SNMP:
294 length = snmp_get_info(page, &start, file->f_pos,thistime);
295 break;
296 #ifdef CONFIG_IP_MULTICAST
297 case PROC_NET_IGMP:
298 length = ip_mc_procinfo(page, &start, file->f_pos,thistime);
299 break;
300 #endif
301 #ifdef CONFIG_IP_FIREWALL
302 case PROC_NET_IPFWFWD:
303 length = ip_fw_fwd_procinfo(page, &start, file->f_pos,thistime);
304 break;
305 case PROC_NET_IPFWFWD0:
306 length = ip_fw_fwd0_procinfo(page, &start, file->f_pos,thistime);
307 break;
308 case PROC_NET_IPFWBLK:
309 length = ip_fw_blk_procinfo(page, &start, file->f_pos,thistime);
310 break;
311 case PROC_NET_IPFWBLK0:
312 length = ip_fw_blk0_procinfo(page, &start, file->f_pos,thistime);
313 break;
314 #endif
315 #ifdef CONFIG_IP_ACCT
316 case PROC_NET_IPACCT:
317 length = ip_acct_procinfo(page, &start, file->f_pos,thistime);
318 break;
319 case PROC_NET_IPACCT0:
320 length = ip_acct0_procinfo(page, &start, file->f_pos,thistime);
321 break;
322 #endif
323 #ifdef CONFIG_IP_MASQUERADE
324 case PROC_NET_IPMSQHST:
325 length = ip_msqhst_procinfo(page, &start, file->f_pos,thistime);
326 break;
327 #endif
328 #ifdef CONFIG_INET_RARP
329 case PROC_NET_RARP:
330 length = rarp_get_info(page,&start,file->f_pos,thistime);
331 break;
332 #endif
333 #if defined(CONFIG_WAVELAN)
334 case PROC_NET_WAVELAN:
335 length = wavelan_get_info(page, &start, file->f_pos, thistime);
336 break;
337 #endif
338 #endif
339 #ifdef CONFIG_IPX
340 case PROC_NET_IPX_INTERFACE:
341 length = ipx_get_interface_info(page, &start, file->f_pos, thistime);
342 break;
343 case PROC_NET_IPX_ROUTE:
344 length = ipx_rt_get_info(page,&start,file->f_pos,thistime);
345 break;
346 case PROC_NET_IPX:
347 length = ipx_get_info(page,&start,file->f_pos,thistime);
348 break;
349 #endif
350 #ifdef CONFIG_ATALK
351 case PROC_NET_ATALK:
352 length = atalk_get_info(page, &start, file->f_pos, thistime);
353 break;
354 case PROC_NET_AT_ROUTE:
355 length = atalk_rt_get_info(page, &start, file->f_pos, thistime);
356 break;
357 case PROC_NET_ATIF:
358 length = atalk_if_get_info(page, &start, file->f_pos, thistime);
359 break;
360 #endif
361 #ifdef CONFIG_AX25
362 case PROC_NET_AX25_ROUTE:
363 length = ax25_rt_get_info(page,&start,file->f_pos,thistime);
364 break;
365 case PROC_NET_AX25:
366 length = ax25_get_info(page,&start,file->f_pos,thistime);
367 break;
368 #ifdef CONFIG_NETROM
369 case PROC_NET_NR_NODES:
370 length = nr_nodes_get_info(page,&start,file->f_pos,thistime);
371 break;
372 case PROC_NET_NR_NEIGH:
373 length = nr_neigh_get_info(page,&start,file->f_pos,thistime);
374 break;
375 case PROC_NET_NR:
376 length = nr_get_info(page,&start,file->f_pos,thistime);
377 break;
378 #endif
379 #endif
380
381 default:
382 free_page((unsigned long) page);
383 return -EBADF;
384 }
385
386
387
388
389
390
391
392 if (length <= 0)
393 break;
394
395
396
397 memcpy_tofs(buf+copied, start, length);
398 file->f_pos+=length;
399 bytes-=length;
400 copied+=length;
401 if(length<thistime)
402 break;
403 }
404 free_page((unsigned long) page);
405 return copied;
406
407 }