This source file includes following definitions.
- get_protocol
- add_ip_protocol
- delete_ip_protocol
- ip_addr_match
- my_ip_addr
- strict_route
- loose_route
- print_rt
- print_ipprot
- ip_route
- add_route
- ip_set_dev
- ip_route_check
- build_options
- ip_build_header
- do_options
- ip_compute_csum
- ip_csum
- ip_send_check
- ip_rcv
- ip_queue_xmit
- ip_retransmit
- print_iph
- ip_handoff
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 #include <asm/segment.h>
53 #include <asm/system.h>
54 #include <linux/types.h>
55 #include <linux/kernel.h>
56 #include <linux/sched.h>
57 #include <linux/string.h>
58 #include <linux/socket.h>
59 #include <netinet/in.h>
60 #include "timer.h"
61 #include "ip.h"
62 #include "tcp.h"
63 #include "sock.h"
64 #include <linux/errno.h>
65 #include "arp.h"
66 #include "icmp.h"
67
68 unsigned long ip_addr[MAX_IP_ADDRES]={0,0,0};
69
70 #undef IP_DEBUG
71
72 #ifdef IP_DEBUG
73 #define PRINTK(X) printk X
74 #else
75 #define PRINTK(X)
76 #endif
77
78 static struct rtable *rt_base=NULL;
79
80 struct ip_protocol *ip_protos[MAX_IP_PROTOS] = { NULL, };
81
82 #if 0
83 static struct ip_protocol *
84 get_protocol(unsigned char prot)
85 {
86 unsigned char hash;
87 struct ip_protocol *p;
88 PRINTK (("get_protocol (%d)\n ", prot));
89 hash = prot & (MAX_IP_PROTOS -1);
90 for (p = ip_protos[hash] ; p != NULL; p=p->next)
91 {
92 PRINTK (("trying protocol %d\n", p->protocol));
93 if (p->protocol == prot)
94 return (p);
95 }
96 return (NULL);
97
98 }
99 #endif
100
101 void
102 add_ip_protocol (struct ip_protocol *prot)
103 {
104 unsigned char hash;
105 struct ip_protocol *p2;
106 hash = prot->protocol & (MAX_IP_PROTOS-1);
107 prot ->next = ip_protos[hash];
108 ip_protos[hash] = prot;
109 prot->copy = 0;
110
111 for (p2 = prot->next; p2 != NULL; p2=p2->next)
112 {
113 if (p2->protocol == prot->protocol)
114 {
115 prot->copy = 1;
116 break;
117 }
118 }
119
120 }
121
122 int
123 delete_ip_protocol (struct ip_protocol *prot)
124 {
125 struct ip_protocol *p;
126 struct ip_protocol *lp=NULL;
127 unsigned char hash;
128
129
130 hash = prot->protocol & (MAX_IP_PROTOS -1);
131 if (prot == ip_protos[hash])
132 {
133 ip_protos[hash]=ip_protos[hash]->next;
134 return (0);
135 }
136
137 for (p = ip_protos[hash]; p != NULL; p = p->next)
138 {
139
140
141
142 if (p->next != NULL && p->next == prot)
143 {
144
145
146
147 if (p->copy == 0 && lp != NULL)
148 lp->copy = 0;
149 p->next = prot->next;
150 return (0);
151 }
152
153 if (p->next != NULL && p->next->protocol == prot->protocol)
154 {
155 lp = p;
156 }
157 }
158 return (-1);
159 }
160
161
162
163
164 int
165 ip_addr_match (unsigned long addr1, unsigned long addr2)
166 {
167 int i;
168 if (addr1 == addr2) return (1);
169 for (i = 0; i < 4; i++, addr1 >>= 8, addr2 >>= 8)
170 {
171 if ((addr1 & 0xff) != (addr2 & 0xff))
172 {
173
174
175 if (addr1 != 0)
176 {
177 return (0);
178 }
179 return (1);
180 }
181 }
182 return (1);
183 }
184
185 int
186 my_ip_addr(unsigned long addr)
187 {
188 int i;
189 for (i = 0; i < MAX_IP_ADDRES; i++)
190 {
191 if (ip_addr[i] == 0) return (0);
192 if (ip_addr_match (addr, ip_addr[i])) return (1);
193 }
194 return (0);
195 }
196
197
198 static void
199 strict_route(struct ip_header *iph, struct options *opt)
200 {
201 }
202
203 static void
204 loose_route(struct ip_header *iph, struct options *opt)
205 {
206 }
207
208 void
209 print_rt(struct rtable *rt)
210 {
211 PRINTK (("net = %08X router = %08X\n",rt->net, rt->router));
212 PRINTK (("dev = %X, next = %X\n",rt->dev, rt->next));
213 }
214
215 void
216 print_ipprot (struct ip_protocol *ipprot)
217 {
218 PRINTK (("handler = %X, protocol = %d, copy=%d \n",
219 ipprot->handler, ipprot->protocol, ipprot->copy));
220 }
221
222
223 static struct device *
224 ip_route(struct options *opt, unsigned long daddr, unsigned long *raddr)
225 {
226 struct rtable *rt;
227
228
229 for (rt=rt_base; rt != NULL; rt=rt->next)
230 {
231
232 if (ip_addr_match (rt->net, daddr))
233 {
234 PRINTK (("IP: %X via %s (%X)\n", daddr, rt->dev->name, rt->router));
235 *raddr = rt->router;
236 return (rt->dev);
237 }
238 }
239 return (NULL);
240 };
241
242 void
243 add_route (struct rtable *rt)
244 {
245 int mask;
246 struct rtable *r;
247 struct rtable *r1;
248 PRINTK (("add_route (rt=%X):\n",rt));
249 print_rt(rt);
250
251 if (rt_base == NULL)
252 {
253 rt->next = NULL;
254 rt_base = rt;
255 return;
256 }
257
258
259
260
261 for (mask = 0xff000000; mask != 0xffffffff; mask = (mask >> 8) | mask)
262 {
263 if (mask & rt->net)
264 {
265 mask = mask << 8;
266 break;
267 }
268 }
269 PRINTK (("mask = %X\n",mask));
270 r1=rt_base;
271 for (r=rt_base; r != NULL; r=r->next)
272 {
273
274 if (r->net == rt->net)
275 {
276 if (r == rt_base)
277 {
278 rt->next = r->next;
279 rt_base = rt;
280 }
281 else
282 {
283 rt->next = r->next;
284 r1->next = rt;
285 }
286 kfree_s (r, sizeof (*r));
287 return;
288 }
289
290 if (!(r->net & mask))
291 {
292 PRINTK (("adding before r=%X\n",r));
293 print_rt(r);
294 if (r == rt_base)
295 {
296 rt->next = rt_base;
297 rt_base = rt;
298 return;
299 }
300 rt->next = r;
301 r1->next = rt;
302 return;
303 }
304 r1 = r;
305 }
306 PRINTK (("adding after r1=%X\n",r1));
307 print_rt(r1);
308
309 rt->next = NULL;
310 r1->next = rt;
311 }
312
313 int
314 ip_set_dev (struct ip_config *u_ipc)
315 {
316 struct rtable *rt;
317 struct device *dev;
318 struct ip_config ipc;
319 static int ip_ads = 0;
320
321 if (ip_ads >= MAX_IP_ADDRES) return (-EINVAL);
322
323
324 memcpy_fromfs(&ipc, u_ipc, sizeof (ipc));
325 ipc.name[MAX_IP_NAME-1] = 0;
326 dev = get_dev (ipc.name);
327
328 if (dev == NULL) return (-EINVAL);
329
330
331 if (ipc.net != -1)
332 {
333 PRINTK (("new broadcast for %s: %08X\n", dev->name, ipc.net));
334 arp_add_broad (ipc.net, dev);
335 rt = kmalloc (sizeof (*rt), GFP_KERNEL);
336 if (rt == NULL) return (-ENOMEM);
337 rt->net = ipc.net;
338 rt->dev = dev;
339 rt->router = 0;
340 add_route (rt);
341
342 }
343
344 if (ipc.router != -1)
345 {
346 PRINTK (("new router for %s: %08X\n", dev->name, ipc.router));
347 rt = kmalloc (sizeof (*rt),GFP_KERNEL);
348 if (rt == NULL) return (-ENOMEM);
349 rt->net = 0;
350 rt->dev = dev;
351 rt->router = ipc.router;
352 add_route (rt);
353 }
354
355 if (dev->loopback)
356 {
357 PRINTK (("new loopback addr: %08X\n", ipc.paddr));
358 rt = kmalloc (sizeof (*rt), GFP_KERNEL);
359 if (rt == NULL) return (-ENOMEM);
360 rt->net = ipc.paddr;
361 rt->dev = dev;
362 rt->router = 0;
363 add_route (rt);
364 }
365
366
367 if (!my_ip_addr (ipc.paddr))
368 {
369 PRINTK (("new identity: %08X\n", ipc.paddr));
370 ip_addr[ip_ads++] = ipc.paddr;
371 }
372
373 dev->up = ipc.up;
374 if (dev->up)
375 {
376 if (dev->open)
377 dev->open(dev);
378 }
379 else
380 {
381 if (dev->stop)
382 dev->stop(dev);
383 }
384
385 return (0);
386 }
387
388
389 void
390 ip_route_check (unsigned long daddr)
391 {
392 }
393
394 #if 0
395
396 static int
397 build_options (struct ip_header *iph, struct options *opt)
398 {
399 unsigned char *ptr;
400
401 ptr = (unsigned char *)(iph+1);
402 *ptr = 0;
403 return (4);
404 }
405 #endif
406
407
408
409
410
411
412 int
413 ip_build_header (struct sk_buff *skb, unsigned long saddr,
414 unsigned long daddr, struct device **dev, int type,
415 struct options *opt, int len)
416 {
417 static struct options optmem;
418 struct ip_header *iph;
419 unsigned char *buff;
420 static int count = 0;
421 unsigned long raddr;
422 int tmp;
423 if (saddr == 0) saddr = MY_IP_ADDR;
424 PRINTK (("ip_build_header (skb=%X, saddr=%X, daddr=%X, *dev=%X,\n"
425 " type=%d, opt=%X, len = %d)\n",
426 skb, saddr, daddr, *dev, type, opt, len));
427 buff = (unsigned char *)(skb + 1);
428
429 if (*dev == NULL)
430 {
431 *dev = ip_route(&optmem,daddr, &raddr);
432 if (*dev == NULL)
433 {
434 return (-ENETUNREACH);
435 }
436 opt = &optmem;
437 }
438 else
439 {
440
441 ip_route (&optmem, daddr, &raddr);
442 }
443 if (raddr == 0) raddr = daddr;
444
445
446
447
448 if ((*dev)->hard_header)
449 {
450 tmp = (*dev)->hard_header(buff, *dev, ETHERTYPE_IP, raddr, saddr, len);
451 }
452 else
453 {
454 tmp = 0;
455 }
456 if (tmp < 0)
457 {
458 tmp = -tmp;
459 skb->arp = 0;
460 }
461 else
462 {
463 skb->arp = 1;
464 }
465 buff += tmp;
466 len -= tmp;
467 skb->dev = *dev;
468
469 iph = (struct ip_header *)buff;
470 iph->version = 4;
471 iph->tos = 0;
472 iph->frag_off = 0;
473 iph->ttl = 32;
474 iph->daddr = daddr;
475 iph->saddr = saddr;
476 iph->protocol=type;
477 iph->ihl = 5;
478 iph->id = net16(count++);
479
480 return (20+tmp);
481 }
482
483 static int
484 do_options(struct ip_header *iph, struct options *opt)
485 {
486 unsigned char *buff;
487 int done = 0;
488 int len=sizeof (*iph);
489 int i;
490
491 opt->record_route.route_size = 0;
492 opt->loose_route.route_size = 0;
493 opt->strict_route.route_size = 0;
494 opt->tstamp.ptr = 0;
495 opt->security = 0;
496 opt->compartment = 0;
497 opt->handling = 0;
498 opt->stream = 0;
499 opt->tcc = 0;
500 return (0);
501
502 buff = (unsigned char *)(iph + 1);
503
504
505 while (!done && len < iph->ihl*4)
506 {
507 switch (*buff)
508 {
509 case IPOPT_END:
510 done=1;
511 break;
512
513 case IPOPT_NOOP:
514 buff++;
515 len ++;
516 break;
517
518 case IPOPT_SEC:
519 buff++;
520 if (*buff != 11)
521 return (1);
522 buff++;
523 opt->security = net16(*(unsigned short *)buff);
524 buff += 2;
525 opt->compartment = net16(*(unsigned short *)buff);
526 buff += 2;
527 opt-> handling = net16(*(unsigned short *)buff);
528 buff += 2;
529 opt->tcc = ((*buff) << 16) + net16(*(unsigned short *)(buff+1));
530 buff += 3;
531 len += 11;
532 break;
533
534 case IPOPT_LSRR:
535 buff ++;
536 if ((*buff - 3)% 4 != 0) return (1);
537 len += *buff;
538 opt->loose_route.route_size = (*buff -3)/4;
539 buff ++;
540 if (*buff % 4 != 0) return (1);
541 opt->loose_route.pointer = *buff/4 - 1;
542 buff ++;
543 buff ++;
544 for (i = 0; i < opt->loose_route.route_size; i++)
545 {
546 opt->loose_route.route[i]=*(unsigned long *)buff;
547 buff += 4;
548 }
549 break;
550
551
552 case IPOPT_SSRR:
553 buff ++;
554 if ((*buff - 3)% 4 != 0) return (1);
555 len += *buff;
556 opt->strict_route.route_size = (*buff -3)/4;
557 buff ++;
558 if (*buff % 4 != 0) return (1);
559 opt->strict_route.pointer = *buff/4 - 1;
560 buff ++;
561 buff ++;
562 for (i = 0; i < opt->strict_route.route_size; i++)
563 {
564 opt->strict_route.route[i]=*(unsigned long *)buff;
565 buff += 4;
566 }
567 break;
568
569 case IPOPT_RR:
570 buff ++;
571 if ((*buff - 3)% 4 != 0) return (1);
572 len += *buff;
573 opt->record_route.route_size = (*buff -3)/4;
574 buff ++;
575 if (*buff % 4 != 0) return (1);
576 opt->record_route.pointer = *buff/4 - 1;
577 buff ++;
578 buff ++;
579 for (i = 0; i < opt->record_route.route_size; i++)
580 {
581 opt->record_route.route[i]=*(unsigned long *)buff;
582 buff += 4;
583 }
584 break;
585
586 case IPOPT_SID:
587 len += 4;
588 buff +=2;
589 opt->stream = *(unsigned short *)buff;
590 buff += 2;
591 break;
592
593 case IPOPT_TIMESTAMP:
594 buff ++;
595 len += *buff;
596 if (*buff % 4 != 0) return (1);
597 opt->tstamp.len = *buff / 4 - 1;
598 buff ++;
599 if ((*buff - 1) % 4 != 0) return (1);
600 opt->tstamp.ptr = (*buff-1)/4;
601 buff ++;
602 opt->tstamp.x.full_char = *buff;
603 buff ++;
604 for (i = 0; i < opt->tstamp.len; i++)
605 {
606 opt->tstamp.data[i] = *(unsigned long *)buff;
607 buff += 4;
608 }
609 break;
610
611 default:
612 return (1);
613 }
614 }
615 if (opt->record_route.route_size == 0)
616 {
617 if (opt->strict_route.route_size != 0)
618 {
619 memcpy (&(opt->record_route), &(opt->strict_route),
620 sizeof (opt->record_route));
621 }
622 else if (opt->loose_route.route_size != 0)
623 {
624 memcpy (&(opt->record_route), &(opt->loose_route),
625 sizeof (opt->record_route));
626 }
627 }
628
629 if (opt->strict_route.route_size != 0 &&
630 opt->strict_route.route_size != opt->strict_route.pointer)
631 {
632 strict_route (iph, opt);
633 return (0);
634 }
635
636 if (opt->loose_route.route_size != 0 &&
637 opt->loose_route.route_size != opt->loose_route.pointer)
638 {
639 loose_route (iph, opt);
640 return (0);
641 }
642
643 return (0);
644 }
645
646
647
648
649
650 unsigned short
651 ip_compute_csum(unsigned char * buff, int len)
652 {
653 unsigned long sum = 0;
654 if (len > 3)
655 {
656
657 __asm__("\t clc\n"
658 "1:\n"
659 "\t lodsl\n"
660 "\t adcl %%eax, %%ebx\n"
661 "\t loop 1b\n"
662 "\t adcl $0, %%ebx\n"
663 "\t movl %%ebx, %%eax\n"
664 "\t shrl $16, %%eax\n"
665 "\t addw %%ax, %%bx\n"
666 "\t adcw $0, %%bx\n"
667 : "=b" (sum) , "=S" (buff)
668 : "0" (sum), "c" (len >> 2) ,"1" (buff)
669 : "ax", "cx", "si", "bx" );
670 }
671 if (len & 2)
672 {
673 __asm__("\t lodsw\n"
674 "\t addw %%ax, %%bx\n"
675 "\t adcw $0, %%bx\n"
676 : "=b" (sum), "=S" (buff)
677 : "0" (sum), "1" (buff)
678 : "bx", "ax", "si");
679 }
680 if (len & 1)
681 {
682 __asm__("\t lodsb\n"
683 "\t movb $0, %%ah\n"
684 "\t addw %%ax, %%bx\n"
685 "\t adcw $0, %%bx\n"
686 : "=b" (sum), "=S" (buff)
687 : "0" (sum), "1" (buff)
688 : "bx", "ax", "si");
689 }
690 sum =~sum;
691 return (sum&0xffff);
692 }
693
694 static int
695 ip_csum(struct ip_header *iph)
696 {
697 if (iph->check == 0) return (0);
698 if (ip_compute_csum((unsigned char *)iph, iph->ihl*4) == 0) return (0);
699 return (1);
700 }
701
702 static void
703 ip_send_check(struct ip_header *iph)
704 {
705 iph->check = 0;
706 iph->check = ip_compute_csum((unsigned char *)iph, iph->ihl*4);
707 }
708
709 int
710 ip_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
711 {
712 struct ip_header *iph;
713 unsigned char hash;
714 unsigned char flag=0;
715 static struct options opt;
716
717 struct ip_protocol *ipprot;
718
719 iph=skb->h.iph;
720
721 PRINTK (("<<\n"));
722 print_iph(iph);
723
724 if (ip_csum (iph) || do_options (iph,&opt) || iph->version != 4)
725 {
726 PRINTK (("ip packet thrown out. \n"));
727 skb->sk = NULL;
728 kfree_skb(skb, 0);
729 return (0);
730 }
731
732
733 if (!my_ip_addr(iph->daddr))
734 {
735 PRINTK (("packet meant for someone else.\n"));
736 skb->sk = NULL;
737 kfree_skb(skb, 0);
738 return (0);
739 }
740
741
742 if ((iph->frag_off & 32) || (net16(iph->frag_off)&0x1fff))
743 {
744 printk ("packet fragmented. \n");
745 skb->sk = NULL;
746 kfree_skb(skb, 0);
747 return(0);
748 }
749
750 skb->h.raw += iph->ihl*4;
751
752 hash = iph->protocol & (MAX_IP_PROTOS -1);
753 for (ipprot = ip_protos[hash]; ipprot != NULL; ipprot=ipprot->next)
754 {
755 struct sk_buff *skb2;
756 if (ipprot->protocol != iph->protocol) continue;
757 PRINTK (("Using protocol = %X:\n", ipprot));
758 print_ipprot (ipprot);
759
760
761
762
763
764
765 if (ipprot->copy)
766 {
767 skb2 = kmalloc (skb->mem_len, GFP_ATOMIC);
768 if (skb2 == NULL) continue;
769 memcpy (skb2, skb, skb->mem_len);
770 skb2->mem_addr = skb2;
771 skb2->lock = 0;
772 skb2->h.raw = (void *)((unsigned long)skb2
773 + (unsigned long)skb->h.raw
774 - (unsigned long)skb);
775 }
776 else
777 {
778 skb2 = skb;
779 }
780 flag = 1;
781 ipprot->handler (skb2, dev, &opt, iph->daddr,
782 net16(iph->tot_len) - iph->ihl*4,
783 iph->saddr, 0, ipprot);
784
785 }
786 if (!flag)
787 {
788 icmp_reply (skb, ICMP_DEST_UNREACH, ICMP_PROT_UNREACH, dev);
789 skb->sk = NULL;
790 kfree_skb (skb, 0);
791 }
792
793
794 return (0);
795 }
796
797
798
799
800
801
802
803 void
804 ip_queue_xmit (volatile struct sock *sk, struct device *dev,
805 struct sk_buff *skb, int free)
806 {
807 struct ip_header *iph;
808 unsigned char *ptr;
809 if (sk == NULL) free = 1;
810
811 if (dev == NULL)
812 {
813 printk ("ip.c: ip_queue_xmit dev = NULL\n");
814 return;
815 }
816
817 skb->free = free;
818 skb->dev = dev;
819 skb->when = jiffies;
820 PRINTK ((">>\n"));
821 ptr = (unsigned char *)(skb + 1);
822 ptr += dev->hard_header_len;
823 iph = (struct ip_header *)ptr;
824 iph->tot_len = net16(skb->len-dev->hard_header_len);
825 ip_send_check (iph);
826 print_iph(iph);
827 skb->next = NULL;
828
829
830
831 skb->magic = 1;
832
833 if (!free)
834 {
835 skb->link3 = NULL;
836 sk->packets_out++;
837 cli();
838 if (sk->send_tail == NULL)
839 {
840 sk->send_tail = skb;
841 sk->send_head = skb;
842 }
843 else
844 {
845 sk->send_tail->link3 = skb;
846 sk->send_tail = skb;
847 }
848 sti();
849 sk->time_wait.len = sk->rtt*2;
850 sk->timeout=TIME_WRITE;
851 reset_timer ((struct timer *)&sk->time_wait);
852 }
853 else
854 {
855 skb->sk = sk;
856 }
857 if (dev->up)
858 {
859 if (sk != NULL)
860 {
861 dev->queue_xmit(skb, dev, sk->priority);
862 }
863 else
864 {
865 dev->queue_xmit (skb, dev, SOPRI_NORMAL);
866 }
867 }
868 else
869 {
870 if (free)
871 kfree_skb (skb, FREE_WRITE);
872 }
873 }
874
875 void
876 ip_retransmit (volatile struct sock *sk, int all)
877 {
878 struct sk_buff * skb;
879 struct proto *prot;
880 struct device *dev;
881
882 prot = sk->prot;
883 skb = sk->send_head;
884 while (skb != NULL)
885 {
886 dev = skb->dev;
887
888
889 if (!skb->arp)
890 {
891 if (dev->rebuild_header ((struct enet_header *)(skb+1),dev))
892 {
893 if (!all) break;
894 skb=skb->link3;
895 continue;
896 }
897 }
898 skb->arp = 1;
899 skb->when = jiffies;
900
901 if (dev->up)
902 if (sk)
903 dev->queue_xmit(skb, dev, sk->priority);
904 else
905 dev->queue_xmit(skb, dev, SOPRI_NORMAL );
906
907 sk->retransmits++;
908 sk->prot->retransmits ++;
909 if (!all) break;
910
911
912
913 if (sk->retransmits > sk->cong_window) break;
914 skb=skb->link3;
915 }
916
917
918
919
920
921
922 sk->rtt *= 2;
923 sk->time_wait.len = sk->rtt;
924 sk->timeout = TIME_WRITE;
925 reset_timer ((struct timer *)&sk->time_wait);
926 }
927
928 void
929 print_iph (struct ip_header *ip)
930 {
931 PRINTK (("ip header:\n"));
932 PRINTK ((" ihl = %d, version = %d, tos = %d, tot_len = %d\n",
933 ip->ihl, ip->version, ip->tos, net16(ip->tot_len)));
934 PRINTK ((" id = %x, ttl = %d, prot = %d, check=%x\n",
935 ip->id, ip->ttl, ip->protocol, ip->check));
936 PRINTK ((" frag_off=%d\n", ip->frag_off));
937 PRINTK ((" saddr = %X, daddr = %X\n",ip->saddr, ip->daddr));
938 }
939
940 #if 0
941 int
942 ip_handoff (volatile struct sock *sk)
943 {
944 struct ip_protocol *p;
945 struct sk_buff *skb;
946 p = get_protocol (sk->protocol);
947
948 if (p == NULL)
949 {
950
951 printk ("sock_ioctl: protocol not found. \n");
952
953 return (-EIO);
954 }
955
956 while (p->handler != sk->prot->rcv)
957 {
958 p=p->next;
959 if (p == NULL)
960 {
961
962 printk ("sock_ioctl: protocol not found. \n");
963
964 return (-EIO);
965 }
966 }
967 p = p-> next;
968 sk->inuse = 1;
969
970
971
972 if (sk->rqueue == NULL) return (0);
973 skb = sk->rqueue;
974 if (skb->next == skb)
975 {
976 sk->rqueue = NULL;
977 }
978 else
979 {
980 sk->rqueue = skb->next;
981 skb->next->prev = skb->prev;
982 skb->prev->next = skb->next;
983 }
984 if (p != NULL)
985 {
986 p->handler ((unsigned char *)(skb+1), skb->dev, NULL, skb->saddr,
987 skb->len, skb->daddr, p->protocol, 0);
988 }
989 kfree_skb (skb, FREE_READ);
990 release_sock (sk);
991 return (0);
992 }
993
994 #endif