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