This source file includes following definitions.
- min
- dev_add_pack
- dev_remove_pack
- get_dev
- dev_queue_xmit
- dev_rint
- dev_transmit
- inet_bh
- dev_tint
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 #include <asm/segment.h>
69 #include <asm/system.h>
70 #include <linux/config.h>
71 #include <linux/types.h>
72 #include <linux/kernel.h>
73 #include <linux/sched.h>
74 #include <linux/string.h>
75 #include <linux/mm.h>
76 #include <linux/socket.h>
77 #include <netinet/in.h>
78 #include "dev.h"
79 #include "eth.h"
80 #include "timer.h"
81 #include "ip.h"
82 #include "tcp.h"
83 #include "sock.h"
84 #include <linux/errno.h>
85 #include <linux/interrupt.h>
86 #include "arp.h"
87
88 #undef DEV_DEBUG
89 #ifdef DEV_DEBUG
90 #define PRINTK(x) printk x
91 #else
92 #define PRINTK(x)
93 #endif
94
95
96 static unsigned long
97 min(unsigned long a, unsigned long b)
98 {
99 if (a < b) return (a);
100 return (b);
101 }
102
103 void
104 dev_add_pack (struct packet_type *pt)
105 {
106 struct packet_type *p1;
107 pt->next = ptype_base;
108
109
110 for (p1 = ptype_base; p1 != NULL; p1 = p1->next)
111 {
112 if (p1->type == pt->type)
113 {
114 pt->copy = 1;
115 break;
116 }
117 }
118
119 ptype_base = pt;
120
121 }
122
123 void
124 dev_remove_pack (struct packet_type *pt)
125 {
126 struct packet_type *lpt, *pt1;
127 if (pt == ptype_base)
128 {
129 ptype_base = pt->next;
130 return;
131 }
132
133 lpt = NULL;
134
135 for (pt1 = ptype_base; pt1->next != NULL; pt1=pt1->next)
136 {
137 if (pt1->next == pt )
138 {
139 cli();
140 if (!pt->copy && lpt)
141 lpt->copy = 0;
142 pt1->next = pt->next;
143 sti();
144 return;
145 }
146
147 if (pt1->next -> type == pt ->type)
148 {
149 lpt = pt1->next;
150 }
151 }
152 }
153
154 struct device *
155 get_dev (char *name)
156 {
157 struct device *dev;
158 for (dev = dev_base; dev != NULL; dev=dev->next)
159 {
160 if (strcmp (dev->name, name) == 0) return (dev);
161 }
162 return (NULL);
163 }
164
165 void
166 dev_queue_xmit (struct sk_buff *skb, struct device *dev, int pri)
167 {
168 struct sk_buff *skb2;
169 int where=0;
170
171
172 PRINTK (("dev_queue_xmit (skb=%X, dev=%X, pri = %d)\n", skb, dev, pri));
173
174 if (dev == NULL)
175 {
176 printk ("dev.c: dev_queue_xmit: dev = NULL\n");
177 return;
178 }
179
180 skb->dev = dev;
181 if (skb->next != NULL)
182 {
183
184 dev->hard_start_xmit (NULL, dev);
185 return;
186 }
187
188 if (pri < 0)
189 {
190 pri = -pri-1;
191 where = 1;
192 }
193
194 if ( pri >= DEV_NUMBUFFS)
195 {
196 printk ("bad priority in dev_queue_xmit.\n");
197 pri = 1;
198 }
199
200 if (dev->hard_start_xmit(skb, dev) == 0)
201 {
202 return;
203 }
204
205
206 PRINTK (("dev_queue_xmit dev->buffs[%d]=%X\n",pri, dev->buffs[pri]));
207
208 cli();
209 if (dev->buffs[pri] == NULL)
210 {
211 dev->buffs[pri]=skb;
212 skb->next = skb;
213 skb->prev = skb;
214 }
215 else
216 {
217 if (where)
218 {
219 skb->next = (struct sk_buff *)dev->buffs[pri];
220 skb->prev = (struct sk_buff *)dev->buffs[pri]->prev;
221 skb->prev->next = skb;
222 skb->next->prev = skb;
223 dev->buffs[pri] = skb;
224 }
225 else
226 {
227 skb2= (struct sk_buff *)dev->buffs[pri];
228 skb->next = skb2;
229 skb->prev = skb2->prev;
230 skb->next->prev = skb;
231 skb->prev->next = skb;
232 }
233 }
234 skb->magic = DEV_QUEUE_MAGIC;
235 sti();
236
237 }
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253 static volatile struct sk_buff * volatile backlog = NULL;
254
255 int
256 dev_rint(unsigned char *buff, long len, int flags,
257 struct device * dev)
258 {
259 struct sk_buff *skb=NULL;
260 unsigned char *to;
261 int amount;
262
263 if (dev == NULL || buff == NULL || len <= 0) return (1);
264
265 if (flags & IN_SKBUFF)
266 {
267 skb = (struct sk_buff *)buff;
268 }
269 else
270 {
271 skb = kmalloc (sizeof (*skb) + len, GFP_ATOMIC);
272 if (skb == NULL)
273 {
274 printk ("dev_rint:dropping packet due to lack of memory.\n");
275 return (1);
276 }
277 skb->lock = 0;
278 skb->mem_len = sizeof (*skb) + len;
279 skb->mem_addr = (struct sk_buff *)skb;
280
281
282 to = (unsigned char *)(skb+1);
283 while (len > 0)
284 {
285 amount = min (len, (unsigned long) dev->rmem_end -
286 (unsigned long) buff);
287 memcpy (to, buff, amount);
288 len -= amount;
289 buff += amount;
290 to += amount;
291 if ((unsigned long)buff == dev->rmem_end)
292 buff = (unsigned char *)dev->rmem_start;
293 }
294 }
295
296 skb->len = len;
297 skb->dev = dev;
298 skb->sk = NULL;
299
300
301 cli();
302 if (backlog == NULL)
303 {
304 skb->prev = skb;
305 skb->next = skb;
306 backlog = skb;
307 }
308 else
309 {
310 skb->prev = (struct sk_buff *)backlog->prev;
311 skb->next = (struct sk_buff *)backlog;
312 skb->next->prev = skb;
313 skb->prev->next = skb;
314 }
315 sti();
316
317 if (backlog != NULL)
318 mark_bh(INET_BH);
319
320 return (0);
321 }
322
323 void
324 dev_transmit(void)
325 {
326 struct device *dev;
327
328 for (dev = dev_base; dev != NULL; dev=dev->next)
329 {
330 if (!dev->tbusy)
331 {
332 dev_tint (dev);
333 }
334 }
335 }
336
337 void
338 inet_bh(void *tmp)
339 {
340 struct sk_buff *skb;
341 struct packet_type *ptype;
342 unsigned short type;
343 unsigned char flag =0;
344 static volatile int in_bh=0;
345
346 cli();
347 if (in_bh != 0)
348 {
349 sti();
350 return;
351 }
352 in_bh=1;
353 sti();
354
355 dev_transmit();
356
357
358 cli();
359 while (backlog != NULL)
360 {
361 skb= (struct sk_buff *)backlog;
362 if (skb->next == skb)
363 {
364 backlog = NULL;
365 }
366 else
367 {
368 backlog = skb->next;
369 skb->next->prev = skb->prev;
370 skb->prev->next = skb->next;
371 }
372 sti();
373
374
375 skb->h.raw = (unsigned char *)(skb+1) + skb->dev->hard_header_len;
376 skb->len -= skb->dev->hard_header_len;
377
378
379 type = skb->dev->type_trans ((struct sk_buff *)skb, skb->dev);
380
381
382
383 for (ptype = ptype_base; ptype != NULL; ptype=ptype->next)
384 {
385 if (ptype->type == type)
386 {
387 struct sk_buff *skb2;
388
389 if (ptype->copy)
390 {
391 skb2 = kmalloc (skb->mem_len, GFP_ATOMIC);
392 if (skb2 == NULL) continue;
393 memcpy (skb2, (const void *) skb, skb->mem_len);
394 skb2->mem_addr = skb2;
395 skb2->lock = 0;
396 skb2->h.raw = (void *)((unsigned long)skb2
397 + (unsigned long)skb->h.raw
398 - (unsigned long)skb);
399
400 }
401 else
402 {
403 skb2 = (struct sk_buff *)skb;
404 flag = 1;
405 }
406
407 ptype->func (skb2, skb->dev, ptype);
408 }
409 }
410
411 if (!flag)
412 {
413 PRINTK (("discarding packet type = %X\n", type));
414 kfree_skb ((struct sk_buff *)skb, FREE_READ);
415 }
416 dev_transmit();
417 cli();
418 }
419 in_bh = 0;
420 sti();
421 }
422
423
424
425
426
427
428
429
430
431 void
432 dev_tint( struct device *dev)
433 {
434 int i;
435 struct sk_buff *skb;
436 for (i=0; i < DEV_NUMBUFFS; i++)
437 {
438 while (dev->buffs[i]!=NULL)
439 {
440 cli();
441 skb=(struct sk_buff *)dev->buffs[i];
442 if (skb->magic != DEV_QUEUE_MAGIC)
443 {
444 printk ("dev.c skb with bad magic-%X: squashing queue\n",
445 skb->magic);
446 cli();
447 dev->buffs[i] = NULL;
448 sti();
449 continue;
450 }
451
452 skb->magic = 0;
453
454 if (skb->next == skb)
455 {
456 dev->buffs[i] = NULL;
457 }
458 else
459 {
460
461 if (skb->next == NULL
462 #ifdef CONFIG_MAX_16M
463 || (unsigned long)(skb->next) > 16*1024*1024
464 #endif
465 )
466
467 {
468 printk ("dev.c: *** bug bad skb->next, squashing queue \n");
469 cli();
470 dev->buffs[i] = NULL;
471 }
472 else
473 {
474 dev->buffs[i]= skb->next;
475 skb->prev->next = skb->next;
476 skb->next->prev = skb->prev;
477 }
478 }
479 skb->next = NULL;
480 skb->prev = NULL;
481 sti();
482
483 dev->queue_xmit (skb, dev, -i-1);
484 if (dev->tbusy)
485 return;
486 }
487 }
488 }