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