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 #include <linux/autoconf.h>
24
25 #include <asm/segment.h>
26
27 #include <linux/errno.h>
28 #include <linux/sched.h>
29 #include <linux/proc_fs.h>
30 #include <linux/stat.h>
31
32
33 static int proc_readnet(struct inode * inode, struct file * file,
34 char * buf, int count);
35 static int proc_readnetdir(struct inode *, struct file *,
36 struct dirent *, int);
37 static int proc_lookupnet(struct inode *,const char *,int,struct inode **);
38
39
40
41 extern int unix_get_info(char *, char **, off_t, int);
42 #ifdef CONFIG_INET
43 extern int tcp_get_info(char *, char **, off_t, int);
44 extern int udp_get_info(char *, char **, off_t, int);
45 extern int raw_get_info(char *, char **, off_t, int);
46 extern int arp_get_info(char *, char **, off_t, int);
47 extern int dev_get_info(char *, char **, off_t, int);
48 extern int rt_get_info(char *, char **, off_t, int);
49 #endif
50 #ifdef CONFIG_IPX
51 extern int ipx_get_info(char *, char **, off_t, int);
52 extern int ipx_rt_get_info(char *, char **, off_t, int);
53 #endif
54
55 static struct file_operations proc_net_operations = {
56 NULL,
57 proc_readnet,
58 NULL,
59 proc_readnetdir,
60 NULL,
61 NULL,
62 NULL,
63 NULL,
64 NULL,
65 NULL
66 };
67
68
69
70
71 struct inode_operations proc_net_inode_operations = {
72 &proc_net_operations,
73 NULL,
74 proc_lookupnet,
75 NULL,
76 NULL,
77 NULL,
78 NULL,
79 NULL,
80 NULL,
81 NULL,
82 NULL,
83 NULL,
84 NULL,
85 NULL,
86 NULL
87 };
88
89 static struct proc_dir_entry net_dir[] = {
90 { 1,2,".." },
91 { 8,1,"." },
92 { 128,4,"unix" }
93 #ifdef CONFIG_INET
94 ,{ 129,3,"arp" },
95 { 130,5,"route" },
96 { 131,3,"dev" },
97 { 132,3,"raw" },
98 { 133,3,"tcp" },
99 { 134,3,"udp" }
100 #endif
101 #ifdef CONFIG_IPX
102 ,{ 135,9,"ipx_route" },
103 { 136,3,"ipx" }
104 #endif
105 };
106
107 #define NR_NET_DIRENTRY ((sizeof (net_dir))/(sizeof (net_dir[0])))
108
109
110 static int proc_lookupnet(struct inode * dir,const char * name, int len,
111 struct inode ** result)
112 {
113 unsigned int ino;
114 int i;
115
116 *result = NULL;
117 if (!dir)
118 return -ENOENT;
119 if (!S_ISDIR(dir->i_mode)) {
120 iput(dir);
121 return -ENOENT;
122 }
123 i = NR_NET_DIRENTRY;
124 while (i-- > 0 && !proc_match(len,name,net_dir+i))
125 ;
126 if (i < 0) {
127 iput(dir);
128 return -ENOENT;
129 }
130 ino = net_dir[i].low_ino;
131 if (!(*result = iget(dir->i_sb,ino))) {
132 iput(dir);
133 return -ENOENT;
134 }
135 iput(dir);
136 return 0;
137 }
138
139 static int proc_readnetdir(struct inode * inode, struct file * filp,
140 struct dirent * dirent, int count)
141 {
142 struct proc_dir_entry * de;
143 unsigned int ino;
144 int i,j;
145
146 if (!inode || !S_ISDIR(inode->i_mode))
147 return -EBADF;
148 ino = inode->i_ino;
149 if (((unsigned) filp->f_pos) < NR_NET_DIRENTRY) {
150 de = net_dir + filp->f_pos;
151 filp->f_pos++;
152 i = de->namelen;
153 ino = de->low_ino;
154 put_fs_long(ino, &dirent->d_ino);
155 put_fs_word(i,&dirent->d_reclen);
156 put_fs_byte(0,i+dirent->d_name);
157 j = i;
158 while (i--)
159 put_fs_byte(de->name[i], i+dirent->d_name);
160 return j;
161 }
162 return 0;
163 }
164
165
166 #define PROC_BLOCK_SIZE (3*1024)
167
168 static int proc_readnet(struct inode * inode, struct file * file,
169 char * buf, int count)
170 {
171 char * page;
172 int length;
173 unsigned int ino;
174 int bytes=count;
175 int thistime;
176 int copied=0;
177 char *start;
178
179 if (count < 0)
180 return -EINVAL;
181 if (!(page = (char*) __get_free_page(GFP_KERNEL)))
182 return -ENOMEM;
183 ino = inode->i_ino;
184
185 while(bytes>0)
186 {
187 thistime=bytes;
188 if(bytes>PROC_BLOCK_SIZE)
189 thistime=PROC_BLOCK_SIZE;
190
191 switch (ino)
192 {
193 case 128:
194 length = unix_get_info(page,&start,file->f_pos,thistime);
195 break;
196 #ifdef CONFIG_INET
197 case 129:
198 length = arp_get_info(page,&start,file->f_pos,thistime);
199 break;
200 case 130:
201 length = rt_get_info(page,&start,file->f_pos,thistime);
202 break;
203 case 131:
204 length = dev_get_info(page,&start,file->f_pos,thistime);
205 break;
206 case 132:
207 length = raw_get_info(page,&start,file->f_pos,thistime);
208 break;
209 case 133:
210 length = tcp_get_info(page,&start,file->f_pos,thistime);
211 break;
212 case 134:
213 length = udp_get_info(page,&start,file->f_pos,thistime);
214 break;
215 #endif
216 #ifdef CONFIG_IPX
217 case 135:
218 length = ipx_rt_get_info(page,&start,file->f_pos,thistime);
219 break;
220 case 136:
221 length = ipx_get_info(page,&start,file->f_pos,thistime);
222 break;
223 #endif
224 default:
225 free_page((unsigned long) page);
226 return -EBADF;
227 }
228
229
230
231
232
233
234
235
236
237
238 memcpy_tofs(buf+copied, start, length);
239 file->f_pos+=length;
240 bytes-=length;
241 copied+=length;
242 if(length<thistime)
243 break;
244 }
245 free_page((unsigned long) page);
246 return copied;
247
248 }