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