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