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