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