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