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