This source file includes following definitions.
- min
- dev_add_pack
- dev_remove_pack
- dev_get
- dev_open
- dev_close
- register_netdevice_notifier
- unregister_netdevice_notifier
- dev_queue_xmit
- netif_rx
- dev_rint
- dev_transmit
- in_net_bh
- net_bh
- dev_tint
- dev_ifconf
- sprintf_stats
- dev_get_info
- bad_mask
- dev_ifsioc
- dev_ioctl
- dev_init
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 #include <asm/segment.h>
49 #include <asm/system.h>
50 #include <asm/bitops.h>
51 #include <linux/config.h>
52 #include <linux/types.h>
53 #include <linux/kernel.h>
54 #include <linux/sched.h>
55 #include <linux/string.h>
56 #include <linux/mm.h>
57 #include <linux/socket.h>
58 #include <linux/sockios.h>
59 #include <linux/in.h>
60 #include <linux/errno.h>
61 #include <linux/interrupt.h>
62 #include <linux/if_ether.h>
63 #include <linux/inet.h>
64 #include <linux/netdevice.h>
65 #include <linux/etherdevice.h>
66 #include <linux/notifier.h>
67 #include <net/ip.h>
68 #include <net/route.h>
69 #include <linux/skbuff.h>
70 #include <net/sock.h>
71 #include <net/arp.h>
72 #include <linux/proc_fs.h>
73 #include <linux/stat.h>
74
75
76
77
78
79
80 struct packet_type *ptype_base[16];
81 struct packet_type *ptype_all = NULL;
82
83
84
85
86
87 struct notifier_block *netdev_chain=NULL;
88
89
90
91
92
93
94 static struct sk_buff_head backlog =
95 {
96 (struct sk_buff *)&backlog, (struct sk_buff *)&backlog
97 #if CONFIG_SKB_CHECK
98 ,SK_HEAD_SKB
99 #endif
100 };
101
102
103
104
105
106 static int backlog_size = 0;
107
108
109
110
111
112 static __inline__ unsigned long min(unsigned long a, unsigned long b)
113 {
114 return (a < b)? a : b;
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128 static int dev_nit=0;
129
130
131
132
133
134
135
136 void dev_add_pack(struct packet_type *pt)
137 {
138 int hash;
139 if(pt->type==htons(ETH_P_ALL))
140 {
141 dev_nit++;
142 pt->next=ptype_all;
143 ptype_all=pt;
144 }
145 else
146 {
147 hash=ntohs(pt->type)&15;
148 pt->next = ptype_base[hash];
149 ptype_base[hash] = pt;
150 }
151 }
152
153
154
155
156
157
158 void dev_remove_pack(struct packet_type *pt)
159 {
160 struct packet_type **pt1;
161 if(pt->type==htons(ETH_P_ALL))
162 {
163 dev_nit--;
164 pt1=&ptype_all;
165 }
166 else
167 pt1=&ptype_base[ntohs(pt->type)&15];
168 for(; (*pt1)!=NULL; pt1=&((*pt1)->next))
169 {
170 if(pt==(*pt1))
171 {
172 *pt1=pt->next;
173 return;
174 }
175 }
176 printk("dev_remove_pack: %p not found.\n", pt);
177 }
178
179
180
181
182
183
184
185
186
187
188
189 struct device *dev_get(const char *name)
190 {
191 struct device *dev;
192
193 for (dev = dev_base; dev != NULL; dev = dev->next)
194 {
195 if (strcmp(dev->name, name) == 0)
196 return(dev);
197 }
198 return(NULL);
199 }
200
201
202
203
204
205
206 int dev_open(struct device *dev)
207 {
208 int ret = 0;
209
210
211
212
213 if (dev->open)
214 ret = dev->open(dev);
215
216
217
218
219
220 if (ret == 0)
221 {
222 dev->flags |= (IFF_UP | IFF_RUNNING);
223
224
225
226 #ifdef CONFIG_IP_MULTICAST
227
228
229
230 ip_mc_allhost(dev);
231 #endif
232 dev_mc_upload(dev);
233 notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
234 }
235 return(ret);
236 }
237
238
239
240
241
242
243 int dev_close(struct device *dev)
244 {
245
246
247
248
249 if (dev->flags != 0)
250 {
251 int ct=0;
252 dev->flags = 0;
253
254
255
256 if (dev->stop)
257 dev->stop(dev);
258
259
260
261 notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
262
263
264
265 dev_mc_discard(dev);
266
267
268
269 dev->pa_addr = 0;
270 dev->pa_dstaddr = 0;
271 dev->pa_brdaddr = 0;
272 dev->pa_mask = 0;
273
274
275
276 while(ct<DEV_NUMBUFFS)
277 {
278 struct sk_buff *skb;
279 while((skb=skb_dequeue(&dev->buffs[ct]))!=NULL)
280 if(skb->free)
281 kfree_skb(skb,FREE_WRITE);
282 ct++;
283 }
284 }
285 return(0);
286 }
287
288
289
290
291
292
293
294 int register_netdevice_notifier(struct notifier_block *nb)
295 {
296 return notifier_chain_register(&netdev_chain, nb);
297 }
298
299 int unregister_netdevice_notifier(struct notifier_block *nb)
300 {
301 return notifier_chain_unregister(&netdev_chain,nb);
302 }
303
304
305
306
307
308
309
310
311
312
313
314 void dev_queue_xmit(struct sk_buff *skb, struct device *dev, int pri)
315 {
316 unsigned long flags;
317 struct packet_type *ptype;
318 int where = 0;
319
320
321
322 if(pri>=0 && !skb_device_locked(skb))
323 skb_device_lock(skb);
324 #if CONFIG_SKB_CHECK
325 IS_SKB(skb);
326 #endif
327 skb->dev = dev;
328
329
330
331
332
333
334
335 if (pri < 0)
336 {
337 pri = -pri-1;
338 where = 1;
339 }
340
341 #ifdef CONFIG_NET_DEBUG
342 if (pri >= DEV_NUMBUFFS)
343 {
344 printk("bad priority in dev_queue_xmit.\n");
345 pri = 1;
346 }
347 #endif
348
349
350
351
352
353
354 if (!skb->arp && dev->rebuild_header(skb->data, dev, skb->raddr, skb)) {
355 return;
356 }
357
358 save_flags(flags);
359 cli();
360 if (!where)
361
362 {
363 skb_queue_tail(dev->buffs + pri,skb);
364 skb_device_unlock(skb);
365 skb = skb_dequeue(dev->buffs + pri);
366 skb_device_lock(skb);
367 }
368 restore_flags(flags);
369
370
371 if(!where && dev_nit)
372 {
373 skb->stamp=xtime;
374 for (ptype = ptype_all; ptype!=NULL; ptype = ptype->next)
375 {
376
377
378
379 if ((ptype->dev == dev || !ptype->dev) &&
380 ((struct sock *)ptype->data != skb->sk))
381 {
382 struct sk_buff *skb2;
383 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL)
384 break;
385 skb2->h.raw = skb2->data + dev->hard_header_len;
386 skb2->mac.raw = skb2->data;
387 ptype->func(skb2, skb->dev, ptype);
388 }
389 }
390 }
391 start_bh_atomic();
392 if (dev->hard_start_xmit(skb, dev) == 0) {
393
394
395
396 end_bh_atomic();
397 return;
398 }
399 end_bh_atomic();
400
401
402
403
404
405 cli();
406 skb_device_unlock(skb);
407 skb_queue_head(dev->buffs + pri,skb);
408 restore_flags(flags);
409 }
410
411
412
413
414
415
416
417 void netif_rx(struct sk_buff *skb)
418 {
419 static int dropping = 0;
420
421
422
423
424
425
426 skb->sk = NULL;
427 skb->free = 1;
428 if(skb->stamp.tv_sec==0)
429 skb->stamp = xtime;
430
431
432
433
434
435 if (!backlog_size)
436 dropping = 0;
437 else if (backlog_size > 300)
438 dropping = 1;
439
440 if (dropping)
441 {
442 kfree_skb(skb, FREE_READ);
443 return;
444 }
445
446
447
448
449 #if CONFIG_SKB_CHECK
450 IS_SKB(skb);
451 #endif
452 skb_queue_tail(&backlog,skb);
453 backlog_size++;
454
455
456
457
458
459
460 #ifdef CONFIG_NET_RUNONIRQ
461 net_bh();
462 #else
463 mark_bh(NET_BH);
464 #endif
465 return;
466 }
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483 int dev_rint(unsigned char *buff, long len, int flags, struct device *dev)
484 {
485 static int dropping = 0;
486 struct sk_buff *skb = NULL;
487 unsigned char *to;
488 int amount, left;
489 int len2;
490
491 if (dev == NULL || buff == NULL || len <= 0)
492 return(1);
493
494 if (flags & IN_SKBUFF)
495 {
496 skb = (struct sk_buff *) buff;
497 }
498 else
499 {
500 if (dropping)
501 {
502 if (skb_peek(&backlog) != NULL)
503 return(1);
504 printk("INET: dev_rint: no longer dropping packets.\n");
505 dropping = 0;
506 }
507
508 skb = alloc_skb(len, GFP_ATOMIC);
509 if (skb == NULL)
510 {
511 printk("dev_rint: packet dropped on %s (no memory) !\n",
512 dev->name);
513 dropping = 1;
514 return(1);
515 }
516
517
518
519
520
521
522 to = skb_put(skb,len);
523 left = len;
524
525 len2 = len;
526 while (len2 > 0)
527 {
528 amount = min(len2, (unsigned long) dev->rmem_end -
529 (unsigned long) buff);
530 memcpy(to, buff, amount);
531 len2 -= amount;
532 left -= amount;
533 buff += amount;
534 to += amount;
535 if ((unsigned long) buff == dev->rmem_end)
536 buff = (unsigned char *) dev->rmem_start;
537 }
538 }
539
540
541
542
543
544 skb->dev = dev;
545 skb->free = 1;
546
547 netif_rx(skb);
548
549
550
551 return(0);
552 }
553
554
555
556
557
558
559 void dev_transmit(void)
560 {
561 struct device *dev;
562
563 for (dev = dev_base; dev != NULL; dev = dev->next)
564 {
565 if (dev->flags != 0 && !dev->tbusy) {
566
567
568
569 dev_tint(dev);
570 }
571 }
572 }
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587 volatile char in_bh = 0;
588
589 int in_net_bh()
590 {
591 return(in_bh==0?0:1);
592 }
593
594
595
596
597
598
599
600
601
602 void net_bh(void *tmp)
603 {
604 struct sk_buff *skb;
605 struct packet_type *ptype;
606 struct packet_type *pt_prev;
607 unsigned short type;
608
609
610
611
612
613 if (set_bit(1, (void*)&in_bh))
614 return;
615
616
617
618
619
620
621
622
623 dev_transmit();
624
625
626
627
628
629
630
631 cli();
632
633
634
635
636
637 while((skb=skb_dequeue(&backlog))!=NULL)
638 {
639
640
641
642 backlog_size--;
643
644 sti();
645
646
647
648
649
650
651
652
653 skb->h.raw = skb->data;
654
655
656
657
658
659 type = skb->protocol;
660
661
662
663
664
665
666 pt_prev = NULL;
667 for (ptype = ptype_all; ptype!=NULL; ptype=ptype->next)
668 {
669 if(pt_prev)
670 {
671 struct sk_buff *skb2=skb_clone(skb, GFP_ATOMIC);
672 if(skb2)
673 pt_prev->func(skb2,skb->dev, pt_prev);
674 }
675 pt_prev=ptype;
676 }
677
678 for (ptype = ptype_base[ntohs(type)&15]; ptype != NULL; ptype = ptype->next)
679 {
680 if (ptype->type == type && (!ptype->dev || ptype->dev==skb->dev))
681 {
682
683
684
685
686 if(pt_prev)
687 {
688 struct sk_buff *skb2;
689
690 skb2=skb_clone(skb, GFP_ATOMIC);
691
692
693
694
695
696
697 if(skb2)
698 pt_prev->func(skb2, skb->dev, pt_prev);
699 }
700
701 pt_prev=ptype;
702 }
703 }
704
705
706
707
708
709 if(pt_prev)
710 pt_prev->func(skb, skb->dev, pt_prev);
711
712
713
714
715 else
716 kfree_skb(skb, FREE_WRITE);
717
718
719
720
721
722
723 #ifdef CONFIG_XMIT_EVERY
724 dev_transmit();
725 #endif
726 cli();
727 }
728
729
730
731
732
733 in_bh = 0;
734 sti();
735
736
737
738
739
740 dev_transmit();
741 }
742
743
744
745
746
747
748
749 void dev_tint(struct device *dev)
750 {
751 int i;
752 struct sk_buff *skb;
753 unsigned long flags;
754
755 save_flags(flags);
756
757
758
759
760 for(i = 0;i < DEV_NUMBUFFS; i++)
761 {
762
763
764
765
766
767 cli();
768 while((skb=skb_dequeue(&dev->buffs[i]))!=NULL)
769 {
770
771
772
773 skb_device_lock(skb);
774 restore_flags(flags);
775
776
777
778
779 dev_queue_xmit(skb,dev,-i - 1);
780
781
782
783 if (dev->tbusy)
784 return;
785 cli();
786 }
787 }
788 restore_flags(flags);
789 }
790
791
792
793
794
795
796
797
798 static int dev_ifconf(char *arg)
799 {
800 struct ifconf ifc;
801 struct ifreq ifr;
802 struct device *dev;
803 char *pos;
804 int len;
805 int err;
806
807
808
809
810
811 err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifconf));
812 if(err)
813 return err;
814 memcpy_fromfs(&ifc, arg, sizeof(struct ifconf));
815 len = ifc.ifc_len;
816 pos = ifc.ifc_buf;
817
818
819
820
821
822
823 err=verify_area(VERIFY_WRITE,pos,len);
824 if(err)
825 return err;
826
827
828
829
830
831 for (dev = dev_base; dev != NULL; dev = dev->next)
832 {
833 if(!(dev->flags & IFF_UP))
834 continue;
835 memset(&ifr, 0, sizeof(struct ifreq));
836 strcpy(ifr.ifr_name, dev->name);
837 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_family = dev->family;
838 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
839
840
841
842
843
844 if (len < sizeof(struct ifreq))
845 break;
846
847
848
849
850
851 memcpy_tofs(pos, &ifr, sizeof(struct ifreq));
852 pos += sizeof(struct ifreq);
853 len -= sizeof(struct ifreq);
854 }
855
856
857
858
859
860 ifc.ifc_len = (pos - ifc.ifc_buf);
861 ifc.ifc_req = (struct ifreq *) ifc.ifc_buf;
862 memcpy_tofs(arg, &ifc, sizeof(struct ifconf));
863
864
865
866
867
868 return(pos - arg);
869 }
870
871
872
873
874
875
876
877 static int sprintf_stats(char *buffer, struct device *dev)
878 {
879 struct enet_statistics *stats = (dev->get_stats ? dev->get_stats(dev): NULL);
880 int size;
881
882 if (stats)
883 size = sprintf(buffer, "%6s:%7d %4d %4d %4d %4d %8d %4d %4d %4d %5d %4d\n",
884 dev->name,
885 stats->rx_packets, stats->rx_errors,
886 stats->rx_dropped + stats->rx_missed_errors,
887 stats->rx_fifo_errors,
888 stats->rx_length_errors + stats->rx_over_errors
889 + stats->rx_crc_errors + stats->rx_frame_errors,
890 stats->tx_packets, stats->tx_errors, stats->tx_dropped,
891 stats->tx_fifo_errors, stats->collisions,
892 stats->tx_carrier_errors + stats->tx_aborted_errors
893 + stats->tx_window_errors + stats->tx_heartbeat_errors);
894 else
895 size = sprintf(buffer, "%6s: No statistics available.\n", dev->name);
896
897 return size;
898 }
899
900
901
902
903
904
905 int dev_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
906 {
907 int len=0;
908 off_t begin=0;
909 off_t pos=0;
910 int size;
911
912 struct device *dev;
913
914
915 size = sprintf(buffer, "Inter-| Receive | Transmit\n"
916 " face |packets errs drop fifo frame|packets errs drop fifo colls carrier\n");
917
918 pos+=size;
919 len+=size;
920
921
922 for (dev = dev_base; dev != NULL; dev = dev->next)
923 {
924 size = sprintf_stats(buffer+len, dev);
925 len+=size;
926 pos=begin+len;
927
928 if(pos<offset)
929 {
930 len=0;
931 begin=pos;
932 }
933 if(pos>offset+length)
934 break;
935 }
936
937 *start=buffer+(offset-begin);
938 len-=(offset-begin);
939 if(len>length)
940 len=length;
941 return len;
942 }
943
944
945
946
947
948
949 static inline int bad_mask(unsigned long mask, unsigned long addr)
950 {
951 if (addr & (mask = ~mask))
952 return 1;
953 mask = ntohl(mask);
954 if (mask & (mask+1))
955 return 1;
956 return 0;
957 }
958
959
960
961
962
963
964
965
966 static int dev_ifsioc(void *arg, unsigned int getset)
967 {
968 struct ifreq ifr;
969 struct device *dev;
970 int ret;
971
972
973
974
975
976 int err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifreq));
977 if(err)
978 return err;
979
980 memcpy_fromfs(&ifr, arg, sizeof(struct ifreq));
981
982
983
984
985
986 if ((dev = dev_get(ifr.ifr_name)) == NULL)
987 return(-ENODEV);
988
989 switch(getset)
990 {
991 case SIOCGIFFLAGS:
992 ifr.ifr_flags = dev->flags;
993 goto rarok;
994
995 case SIOCSIFFLAGS:
996 {
997 int old_flags = dev->flags;
998 dev->flags = ifr.ifr_flags & (
999 IFF_UP | IFF_BROADCAST | IFF_DEBUG | IFF_LOOPBACK |
1000 IFF_POINTOPOINT | IFF_NOTRAILERS | IFF_RUNNING |
1001 IFF_NOARP | IFF_PROMISC | IFF_ALLMULTI | IFF_SLAVE | IFF_MASTER
1002 | IFF_MULTICAST);
1003
1004
1005
1006
1007 dev_mc_upload(dev);
1008
1009
1010
1011
1012
1013 if ((old_flags & IFF_UP) && ((dev->flags & IFF_UP) == 0))
1014 {
1015 ret = dev_close(dev);
1016 }
1017 else
1018 {
1019
1020
1021
1022
1023 ret = (! (old_flags & IFF_UP) && (dev->flags & IFF_UP))
1024 ? dev_open(dev) : 0;
1025
1026
1027
1028 if(ret<0)
1029 dev->flags&=~IFF_UP;
1030 }
1031 }
1032 break;
1033
1034 case SIOCGIFADDR:
1035 (*(struct sockaddr_in *)
1036 &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
1037 (*(struct sockaddr_in *)
1038 &ifr.ifr_addr).sin_family = dev->family;
1039 (*(struct sockaddr_in *)
1040 &ifr.ifr_addr).sin_port = 0;
1041 goto rarok;
1042
1043 case SIOCSIFADDR:
1044 dev->pa_addr = (*(struct sockaddr_in *)
1045 &ifr.ifr_addr).sin_addr.s_addr;
1046 dev->family = ifr.ifr_addr.sa_family;
1047
1048 #ifdef CONFIG_INET
1049
1050
1051 dev->pa_mask = ip_get_mask(dev->pa_addr);
1052 #endif
1053 dev->pa_brdaddr = dev->pa_addr | ~dev->pa_mask;
1054 ret = 0;
1055 break;
1056
1057 case SIOCGIFBRDADDR:
1058 (*(struct sockaddr_in *)
1059 &ifr.ifr_broadaddr).sin_addr.s_addr = dev->pa_brdaddr;
1060 (*(struct sockaddr_in *)
1061 &ifr.ifr_broadaddr).sin_family = dev->family;
1062 (*(struct sockaddr_in *)
1063 &ifr.ifr_broadaddr).sin_port = 0;
1064 goto rarok;
1065
1066 case SIOCSIFBRDADDR:
1067 dev->pa_brdaddr = (*(struct sockaddr_in *)
1068 &ifr.ifr_broadaddr).sin_addr.s_addr;
1069 ret = 0;
1070 break;
1071
1072 case SIOCGIFDSTADDR:
1073 (*(struct sockaddr_in *)
1074 &ifr.ifr_dstaddr).sin_addr.s_addr = dev->pa_dstaddr;
1075 (*(struct sockaddr_in *)
1076 &ifr.ifr_dstaddr).sin_family = dev->family;
1077 (*(struct sockaddr_in *)
1078 &ifr.ifr_dstaddr).sin_port = 0;
1079 goto rarok;
1080
1081 case SIOCSIFDSTADDR:
1082 dev->pa_dstaddr = (*(struct sockaddr_in *)
1083 &ifr.ifr_dstaddr).sin_addr.s_addr;
1084 ret = 0;
1085 break;
1086
1087 case SIOCGIFNETMASK:
1088 (*(struct sockaddr_in *)
1089 &ifr.ifr_netmask).sin_addr.s_addr = dev->pa_mask;
1090 (*(struct sockaddr_in *)
1091 &ifr.ifr_netmask).sin_family = dev->family;
1092 (*(struct sockaddr_in *)
1093 &ifr.ifr_netmask).sin_port = 0;
1094 goto rarok;
1095
1096 case SIOCSIFNETMASK:
1097 {
1098 unsigned long mask = (*(struct sockaddr_in *)
1099 &ifr.ifr_netmask).sin_addr.s_addr;
1100 ret = -EINVAL;
1101
1102
1103
1104 if (bad_mask(mask,0))
1105 break;
1106 dev->pa_mask = mask;
1107 ret = 0;
1108 }
1109 break;
1110
1111 case SIOCGIFMETRIC:
1112
1113 ifr.ifr_metric = dev->metric;
1114 goto rarok;
1115
1116 case SIOCSIFMETRIC:
1117 dev->metric = ifr.ifr_metric;
1118 ret=0;
1119 break;
1120
1121 case SIOCGIFMTU:
1122 ifr.ifr_mtu = dev->mtu;
1123 goto rarok;
1124
1125 case SIOCSIFMTU:
1126
1127
1128
1129
1130
1131 if(ifr.ifr_mtu<68)
1132 return -EINVAL;
1133 dev->mtu = ifr.ifr_mtu;
1134 ret = 0;
1135 break;
1136
1137 case SIOCGIFMEM:
1138
1139 ret = -EINVAL;
1140 break;
1141
1142 case SIOCSIFMEM:
1143 ret = -EINVAL;
1144 break;
1145
1146 case OLD_SIOCGIFHWADDR:
1147 memcpy(ifr.old_ifr_hwaddr,dev->dev_addr, MAX_ADDR_LEN);
1148 goto rarok;
1149
1150 case SIOCGIFHWADDR:
1151 memcpy(ifr.ifr_hwaddr.sa_data,dev->dev_addr, MAX_ADDR_LEN);
1152 ifr.ifr_hwaddr.sa_family=dev->type;
1153 goto rarok;
1154
1155 case SIOCSIFHWADDR:
1156 if(dev->set_mac_address==NULL)
1157 return -EOPNOTSUPP;
1158 if(ifr.ifr_hwaddr.sa_family!=dev->type)
1159 return -EINVAL;
1160 ret=dev->set_mac_address(dev,ifr.ifr_hwaddr.sa_data);
1161 break;
1162
1163 case SIOCGIFMAP:
1164 ifr.ifr_map.mem_start=dev->mem_start;
1165 ifr.ifr_map.mem_end=dev->mem_end;
1166 ifr.ifr_map.base_addr=dev->base_addr;
1167 ifr.ifr_map.irq=dev->irq;
1168 ifr.ifr_map.dma=dev->dma;
1169 ifr.ifr_map.port=dev->if_port;
1170 goto rarok;
1171
1172 case SIOCSIFMAP:
1173 if(dev->set_config==NULL)
1174 return -EOPNOTSUPP;
1175 return dev->set_config(dev,&ifr.ifr_map);
1176
1177 case SIOCADDMULTI:
1178 if(dev->set_multicast_list==NULL)
1179 return -EINVAL;
1180 if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1181 return -EINVAL;
1182 dev_mc_add(dev,ifr.ifr_hwaddr.sa_data, dev->addr_len, 1);
1183 return 0;
1184
1185 case SIOCDELMULTI:
1186 if(dev->set_multicast_list==NULL)
1187 return -EINVAL;
1188 if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1189 return -EINVAL;
1190 dev_mc_delete(dev,ifr.ifr_hwaddr.sa_data,dev->addr_len, 1);
1191 return 0;
1192
1193
1194
1195
1196 default:
1197 if((getset >= SIOCDEVPRIVATE) &&
1198 (getset <= (SIOCDEVPRIVATE + 15))) {
1199 if(dev->do_ioctl==NULL)
1200 return -EOPNOTSUPP;
1201 ret=dev->do_ioctl(dev, &ifr, getset);
1202 memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1203 break;
1204 }
1205
1206 ret = -EINVAL;
1207 }
1208 return(ret);
1209
1210
1211
1212 rarok:
1213 memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1214 return 0;
1215 }
1216
1217
1218
1219
1220
1221
1222
1223 int dev_ioctl(unsigned int cmd, void *arg)
1224 {
1225 switch(cmd)
1226 {
1227 case SIOCGIFCONF:
1228 (void) dev_ifconf((char *) arg);
1229 return 0;
1230
1231
1232
1233
1234
1235 case SIOCGIFFLAGS:
1236 case SIOCGIFADDR:
1237 case SIOCGIFDSTADDR:
1238 case SIOCGIFBRDADDR:
1239 case SIOCGIFNETMASK:
1240 case SIOCGIFMETRIC:
1241 case SIOCGIFMTU:
1242 case SIOCGIFMEM:
1243 case SIOCGIFHWADDR:
1244 case SIOCSIFHWADDR:
1245 case OLD_SIOCGIFHWADDR:
1246 case SIOCGIFSLAVE:
1247 case SIOCGIFMAP:
1248 return dev_ifsioc(arg, cmd);
1249
1250
1251
1252
1253
1254 case SIOCSIFFLAGS:
1255 case SIOCSIFADDR:
1256 case SIOCSIFDSTADDR:
1257 case SIOCSIFBRDADDR:
1258 case SIOCSIFNETMASK:
1259 case SIOCSIFMETRIC:
1260 case SIOCSIFMTU:
1261 case SIOCSIFMEM:
1262 case SIOCSIFMAP:
1263 case SIOCSIFSLAVE:
1264 case SIOCADDMULTI:
1265 case SIOCDELMULTI:
1266 if (!suser())
1267 return -EPERM;
1268 return dev_ifsioc(arg, cmd);
1269
1270 case SIOCSIFLINK:
1271 return -EINVAL;
1272
1273
1274
1275
1276
1277 default:
1278 if((cmd >= SIOCDEVPRIVATE) &&
1279 (cmd <= (SIOCDEVPRIVATE + 15))) {
1280 return dev_ifsioc(arg, cmd);
1281 }
1282 return -EINVAL;
1283 }
1284 }
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294 void dev_init(void)
1295 {
1296 struct device *dev, *dev2;
1297
1298
1299
1300
1301
1302
1303
1304
1305 dev2 = NULL;
1306 for (dev = dev_base; dev != NULL; dev=dev->next)
1307 {
1308 if (dev->init && dev->init(dev))
1309 {
1310
1311
1312
1313
1314 if (dev2 == NULL)
1315 dev_base = dev->next;
1316 else
1317 dev2->next = dev->next;
1318 }
1319 else
1320 {
1321 dev2 = dev;
1322 }
1323 }
1324 proc_net_register(&(struct proc_dir_entry) {
1325 PROC_NET_DEV, 3, "dev",
1326 S_IFREG | S_IRUGO, 1, 0, 0,
1327 0, &proc_net_inode_operations,
1328 dev_get_info
1329 });
1330
1331 }
1332