2 * NET3 Protocol independent device support routines. 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 7 * 2 of the License, or (at your option) any later version. 9 * Derived from the non IP parts of dev.c 1.0.19 10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu> 11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 12 * Mark Evans, <evansmp@uhura.aston.ac.uk> 15 * Florian la Roche <rzsfl@rz.uni-sb.de> 16 * Alan Cox <gw4pts@gw4pts.ampr.org> 17 * David Hinds <dhinds@allegro.stanford.edu> 20 * Alan Cox : device private ioctl copies fields back. 21 * Alan Cox : Transmit queue code does relevant stunts to 22 * keep the queue safe. 23 * Alan Cox : Fixed double lock. 24 * Alan Cox : Fixed promisc NULL pointer trap 25 * ???????? : Support the full private ioctl range 26 * Alan Cox : Moved ioctl permission check into drivers 27 * Tim Kordas : SIOCADDMULTI/SIOCDELMULTI 28 * Alan Cox : 100 backlog just doesn't cut it when 29 * you start doing multicast video 8) 30 * Alan Cox : Rewrote net_bh and list manager. 31 * Alan Cox : Fix ETH_P_ALL echoback lengths. 32 * Alan Cox : Took out transmit every packet pass 33 * Saved a few bytes in the ioctl handler 34 * Alan Cox : Network driver sets packet type before calling netif_rx. Saves 35 * a function call a packet. 36 * Alan Cox : Hashed net_bh() 37 * Richard Kooijman: Timestamp fixes. 38 * Alan Cox : Wrong field in SIOCGIFDSTADDR 39 * Alan Cox : Device lock protection. 40 * Alan Cox : Fixed nasty side effect of device close changes. 41 * Rudi Cilibrasi : Pass the right thing to set_mac_address() 42 * Dave Miller : 32bit quantity for the device lock to make it work out 44 * Bjorn Ekwall : Added KERNELD hack. 45 * Alan Cox : Cleaned up the backlog initialise. 46 * Craig Metz : SIOCGIFCONF fix if space for under 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> 60 #include <linux/socket.h> 61 #include <linux/sockios.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> 71 #include <net/route.h> 72 #include <linux/skbuff.h> 76 #include <linux/proc_fs.h> 77 #include <linux/stat.h> 78 #ifdef CONFIG_NET_ALIAS 79 #include <linux/net_alias.h> 82 #include <linux/kerneld.h> 86 * The list of packet types we will receive (as opposed to discard) 87 * and the routines to invoke. 90 struct packet_type
*ptype_base
[16]; 91 struct packet_type
*ptype_all
= NULL
;/* Taps */ 103 struct notifier_block
*netdev_chain
=NULL
; 106 * Device drivers call our routines to queue packets here. We empty the 107 * queue in the bottom half handler. 110 static struct sk_buff_head backlog
; 113 * We don't overdo the queue or we will thrash memory badly. 116 static int backlog_size
=0; 119 * Return the lesser of the two values. 122 static __inline__
unsigned longmin(unsigned long a
,unsigned long b
) 124 return(a
< b
)? a
: b
; 128 /****************************************************************************************** 130 Protocol management and registration routines 132 *******************************************************************************************/ 138 static int dev_nit
=0; 141 * Add a protocol ID to the list. Now that the input handler is 142 * smarter we can dispense with all the messy stuff that used to be 146 voiddev_add_pack(struct packet_type
*pt
) 149 if(pt
->type
==htons(ETH_P_ALL
)) 157 hash
=ntohs(pt
->type
)&15; 158 pt
->next
= ptype_base
[hash
]; 159 ptype_base
[hash
] = pt
; 165 * Remove a protocol ID from the list. 168 voiddev_remove_pack(struct packet_type
*pt
) 170 struct packet_type
**pt1
; 171 if(pt
->type
==htons(ETH_P_ALL
)) 177 pt1
=&ptype_base
[ntohs(pt
->type
)&15]; 178 for(; (*pt1
)!=NULL
; pt1
=&((*pt1
)->next
)) 186 printk("dev_remove_pack: %p not found.\n", pt
); 189 /***************************************************************************************** 191 Device Interface Subroutines 193 ******************************************************************************************/ 196 * Find an interface by name. 199 struct device
*dev_get(const char*name
) 203 for(dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
) 205 if(strcmp(dev
->name
, name
) ==0) 212 * Find and possibly load an interface. 215 #ifdef CONFIG_KERNELD 217 extern __inline__
voiddev_load(const char*name
) 220 #ifdef CONFIG_NET_ALIAS 223 for(sptr
=name
; *sptr
; sptr
++)if(*sptr
==':')break; 224 if(!(*sptr
&& *(sptr
+1))) 226 request_module(name
); 233 * Prepare an interface for use. 236 intdev_open(struct device
*dev
) 241 * Call device private open method 244 ret
= dev
->open(dev
); 247 * If it went open OK then set the flags 252 dev
->flags
|= (IFF_UP
| IFF_RUNNING
); 254 * Initialise multicasting status 257 notifier_call_chain(&netdev_chain
, NETDEV_UP
, dev
); 264 * Completely shutdown an interface. 267 intdev_close(struct device
*dev
) 272 * Call the device specific close. This cannot fail. 273 * Only if device is UP 276 if((dev
->flags
& IFF_UP
) && dev
->stop
) 280 * Device is now down. 283 dev
->flags
&=~(IFF_UP
|IFF_RUNNING
); 286 * Tell people we are going down 288 notifier_call_chain(&netdev_chain
, NETDEV_DOWN
, dev
); 290 * Flush the multicast chain 294 * Blank the IP addresses 301 * Purge any queued packets when we down the link 303 while(ct
<DEV_NUMBUFFS
) 306 while((skb
=skb_dequeue(&dev
->buffs
[ct
]))!=NULL
) 308 kfree_skb(skb
,FREE_WRITE
); 316 * Device change register/unregister. These are not inline or static 317 * as we export them to the world. 320 intregister_netdevice_notifier(struct notifier_block
*nb
) 322 returnnotifier_chain_register(&netdev_chain
, nb
); 325 intunregister_netdevice_notifier(struct notifier_block
*nb
) 327 returnnotifier_chain_unregister(&netdev_chain
,nb
); 331 * Send (or queue for sending) a packet. 333 * IMPORTANT: When this is called to resend frames. The caller MUST 334 * already have locked the sk_buff. Apart from that we do the 338 voiddev_queue_xmit(struct sk_buff
*skb
,struct device
*dev
,int pri
) 341 struct sk_buff_head
*list
; 342 int retransmission
=0;/* used to say if the packet should go */ 343 /* at the front or the back of the */ 344 /* queue - front is a retransmit try */ 346 if(pri
>=0&& !skb_device_locked(skb
)) 347 skb_device_lock(skb
);/* Shove a lock on the frame */ 354 * Negative priority is used to flag a frame that is being pulled from the 355 * queue front as a retransmit attempt. It therefore goes back on the queue 356 * start on a failure. 365 #ifdef CONFIG_NET_DEBUG 366 if(pri
>= DEV_NUMBUFFS
) 368 printk("bad priority in dev_queue_xmit.\n"); 374 * If the address has not been resolved. Call the device header rebuilder. 375 * This can cover all protocols and technically not just ARP either. 378 if(!skb
->arp
&& dev
->rebuild_header(skb
->data
, dev
, skb
->raddr
, skb
)) { 384 * If dev is an alias, switch to its main device. 385 * "arp" resolution has been made with alias device, so 386 * arp entries refer to alias, not main. 390 #ifdef CONFIG_NET_ALIAS 391 if(net_alias_is(dev
)) 392 skb
->dev
= dev
=net_alias_main_dev(dev
); 394 list
= dev
->buffs
+ pri
; 397 /* if this isn't a retransmission, use the first packet instead... */ 398 if(!retransmission
) { 399 if(skb_queue_len(list
)) { 400 /* avoid overrunning the device queue.. */ 401 if(skb_queue_len(list
) > dev
->tx_queue_len
) { 402 dev_kfree_skb(skb
, FREE_WRITE
); 406 skb_device_unlock(skb
);/* Buffer is on the device queue and can be freed safely */ 407 __skb_queue_tail(list
, skb
); 408 skb
=__skb_dequeue(list
); 409 skb_device_lock(skb
);/* New buffer needs locking down */ 410 restore_flags(flags
); 413 /* copy outgoing packets to any sniffer packet handlers */ 415 struct packet_type
*ptype
; 417 for(ptype
= ptype_all
; ptype
!=NULL
; ptype
= ptype
->next
) 419 /* Never send packets back to the socket 420 * they originated from - MvS (miquels@drinkel.ow.org) 422 if((ptype
->dev
== dev
|| !ptype
->dev
) && 423 ((struct sock
*)ptype
->data
!= skb
->sk
)) 425 struct sk_buff
*skb2
; 426 if((skb2
=skb_clone(skb
, GFP_ATOMIC
)) == NULL
) 428 skb2
->h
.raw
= skb2
->data
+ dev
->hard_header_len
; 429 skb2
->mac
.raw
= skb2
->data
; 430 ptype
->func(skb2
, skb
->dev
, ptype
); 436 if(dev
->hard_start_xmit(skb
, dev
) ==0) { 438 * Packet is now solely the responsibility of the driver 446 * Transmission failed, put skb back into a list. Once on the list it's safe and 447 * no longer device locked (it can be freed safely from the device queue) 450 skb_device_unlock(skb
); 451 __skb_queue_head(list
,skb
); 452 restore_flags(flags
); 456 * Receive a packet from a device driver and queue it for the upper 457 * (protocol) levels. It always succeeds. This is the recommended 461 voidnetif_rx(struct sk_buff
*skb
) 463 static int dropping
=0; 466 * Any received buffers are un-owned and should be discarded 467 * when freed. These will be updated later as the frames get 473 if(skb
->stamp
.tv_sec
==0) 477 * Check that we aren't overdoing things. 482 else if(backlog_size
>300) 487 kfree_skb(skb
, FREE_READ
); 492 * Add it to the "backlog" queue. 497 skb_queue_tail(&backlog
,skb
); 501 * If any packet arrived, mark it for processing after the 502 * hardware interrupt returns. 505 #ifdef CONFIG_NET_RUNONIRQ/* Dont enable yet, needs some driver mods */ 514 * This routine causes all interfaces to try to send some data. 517 voiddev_transmit(void) 521 for(dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
) 523 if(dev
->flags
!=0&& !dev
->tbusy
) { 533 /********************************************************************************** 535 Receive Queue Processor 537 ***********************************************************************************/ 540 * When we are called the queue is ready to grab, the interrupts are 541 * on and hardware can interrupt and queue to the receive queue a we 542 * run with no problems. 543 * This is run as a bottom half after an interrupt handler that does 549 struct packet_type
*ptype
; 550 struct packet_type
*pt_prev
; 554 * Can we send anything now? We want to clear the 555 * decks for any more sends that get done as we 556 * process the input. This also minimises the 557 * latency on a transmit interrupt bh. 563 * Any data left to process. This may occur because a 564 * mark_bh() is done after we empty the queue including 565 * that from the device which does a mark_bh() just after 569 * While the queue is not empty.. 571 * Note that the queue never shrinks due to 572 * an interrupt, so we can do this test without 573 * disabling interrupts. 576 while(!skb_queue_empty(&backlog
)) { 577 struct sk_buff
* skb
= backlog
.next
; 580 * We have a packet. Therefore the queue has shrunk 583 __skb_unlink(skb
, &backlog
); 588 * Bump the pointer to the next structure. 590 * On entry to the protocol layer. skb->data and 591 * skb->h.raw point to the MAC and encapsulated data 594 skb
->h
.raw
= skb
->data
; 597 * Fetch the packet protocol ID. 600 type
= skb
->protocol
; 603 * We got a packet ID. Now loop over the "known protocols" 604 * list. There are two lists. The ptype_all list of taps (normally empty) 605 * and the main protocol list which is hashed perfectly for normal protocols. 608 for(ptype
= ptype_all
; ptype
!=NULL
; ptype
=ptype
->next
) 612 struct sk_buff
*skb2
=skb_clone(skb
, GFP_ATOMIC
); 614 pt_prev
->func(skb2
,skb
->dev
, pt_prev
); 619 for(ptype
= ptype_base
[ntohs(type
)&15]; ptype
!= NULL
; ptype
= ptype
->next
) 621 if(ptype
->type
== type
&& (!ptype
->dev
|| ptype
->dev
==skb
->dev
)) 624 * We already have a match queued. Deliver 625 * to it and then remember the new match 629 struct sk_buff
*skb2
; 631 skb2
=skb_clone(skb
, GFP_ATOMIC
); 634 * Kick the protocol handler. This should be fast 635 * and efficient code. 639 pt_prev
->func(skb2
, skb
->dev
, pt_prev
); 641 /* Remember the current last to do */ 644 }/* End of protocol list loop */ 647 * Is there a last item to send to ? 651 pt_prev
->func(skb
, skb
->dev
, pt_prev
); 653 * Has an unknown packet has been received ? 657 kfree_skb(skb
, FREE_WRITE
); 659 * Again, see if we can transmit anything now. 660 * [Ought to take this out judging by tests it slows 661 * us down not speeds us up] 666 }/* End of queue loop */ 669 * We have emptied the queue 673 * One last output flush. 683 * This routine is called when an device driver (i.e. an 684 * interface) is ready to transmit a packet. 687 voiddev_tint(struct device
*dev
) 691 struct sk_buff_head
* head
; 694 * aliases do not transmit (for now :) ) 697 #ifdef CONFIG_NET_ALIAS 698 if(net_alias_is(dev
))return; 705 * Work the queues in priority order 707 for(i
=0;i
< DEV_NUMBUFFS
; i
++,head
++) 710 while(!skb_queue_empty(head
)) { 714 __skb_unlink(skb
, head
); 716 * Stop anyone freeing the buffer while we retransmit it 718 skb_device_lock(skb
); 719 restore_flags(flags
); 721 * Feed them to the output stage and if it fails 722 * indicate they re-queue at the front. 724 dev_queue_xmit(skb
,dev
,-i
-1); 726 * If we can take no more then stop here. 733 restore_flags(flags
); 738 * Perform a SIOCGIFCONF call. This structure will change 739 * size shortly, and there is nothing I can do about it. 740 * Thus we will need a 'compatibility mode'. 743 static intdev_ifconf(char*arg
) 753 * Fetch the caller's info block. 756 err
=verify_area(VERIFY_WRITE
, arg
,sizeof(struct ifconf
)); 759 memcpy_fromfs(&ifc
, arg
,sizeof(struct ifconf
)); 764 * We now walk the device list filling each active device 768 err
=verify_area(VERIFY_WRITE
,pos
,len
); 773 * Loop over the interfaces, and write an info block for each. 776 for(dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
) 778 if(!(dev
->flags
& IFF_UP
))/* Downed devices don't count */ 781 * Have we run out of space here ? 784 if(len
<sizeof(struct ifreq
)) 787 memset(&ifr
,0,sizeof(struct ifreq
)); 788 strcpy(ifr
.ifr_name
, dev
->name
); 789 (*(struct sockaddr_in
*) &ifr
.ifr_addr
).sin_family
= dev
->family
; 790 (*(struct sockaddr_in
*) &ifr
.ifr_addr
).sin_addr
.s_addr
= dev
->pa_addr
; 794 * Write this block to the caller's space. 797 memcpy_tofs(pos
, &ifr
,sizeof(struct ifreq
)); 798 pos
+=sizeof(struct ifreq
); 799 len
-=sizeof(struct ifreq
); 803 * All done. Write the updated control block back to the caller. 806 ifc
.ifc_len
= (pos
- ifc
.ifc_buf
); 807 ifc
.ifc_req
= (struct ifreq
*) ifc
.ifc_buf
; 808 memcpy_tofs(arg
, &ifc
,sizeof(struct ifconf
)); 811 * Report how much was filled in 819 * This is invoked by the /proc filesystem handler to display a device 823 #ifdef CONFIG_PROC_FS 824 static intsprintf_stats(char*buffer
,struct device
*dev
) 826 struct enet_statistics
*stats
= (dev
->get_stats
? dev
->get_stats(dev
): NULL
); 830 size
=sprintf(buffer
,"%6s:%7d %4d %4d %4d %4d %8d %4d %4d %4d %5d %4d\n", 832 stats
->rx_packets
, stats
->rx_errors
, 833 stats
->rx_dropped
+ stats
->rx_missed_errors
, 834 stats
->rx_fifo_errors
, 835 stats
->rx_length_errors
+ stats
->rx_over_errors
836 + stats
->rx_crc_errors
+ stats
->rx_frame_errors
, 837 stats
->tx_packets
, stats
->tx_errors
, stats
->tx_dropped
, 838 stats
->tx_fifo_errors
, stats
->collisions
, 839 stats
->tx_carrier_errors
+ stats
->tx_aborted_errors
840 + stats
->tx_window_errors
+ stats
->tx_heartbeat_errors
); 842 size
=sprintf(buffer
,"%6s: No statistics available.\n", dev
->name
); 848 * Called from the PROCfs module. This now uses the new arbitrary sized /proc/net interface 849 * to create /proc/net/dev 852 intdev_get_info(char*buffer
,char**start
, off_t offset
,int length
,int dummy
) 862 size
=sprintf(buffer
,"Inter-| Receive | Transmit\n" 863 " face |packets errs drop fifo frame|packets errs drop fifo colls carrier\n"); 869 for(dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
) 871 size
=sprintf_stats(buffer
+len
, dev
); 880 if(pos
>offset
+length
) 884 *start
=buffer
+(offset
-begin
);/* Start of wanted data */ 885 len
-=(offset
-begin
);/* Start slop */ 887 len
=length
;/* Ending slop */ 890 #endif/* CONFIG_PROC_FS */ 894 * This checks bitmasks for the ioctl calls for devices. 897 staticinlineintbad_mask(unsigned long mask
,unsigned long addr
) 899 if(addr
& (mask
= ~mask
)) 908 * Perform the SIOCxIFxxx calls. 910 * The socket layer has seen an ioctl the address family thinks is 911 * for the device. At this point we get invoked to make a decision 914 static intdev_ifsioc(void*arg
,unsigned int getset
) 921 * Fetch the caller's info block into kernel space 924 int err
=verify_area(VERIFY_WRITE
, arg
,sizeof(struct ifreq
)); 928 memcpy_fromfs(&ifr
, arg
,sizeof(struct ifreq
)); 931 * See which interface the caller is talking about. 936 * net_alias_dev_get(): dev_get() with added alias naming magic. 937 * only allow alias creation/deletion if (getset==SIOCSIFADDR) 941 #ifdef CONFIG_KERNELD 942 dev_load(ifr
.ifr_name
); 945 #ifdef CONFIG_NET_ALIAS 946 if((dev
=net_alias_dev_get(ifr
.ifr_name
, getset
== SIOCSIFADDR
, &err
, NULL
, NULL
)) == NULL
) 949 if((dev
=dev_get(ifr
.ifr_name
)) == NULL
) 954 case SIOCGIFFLAGS
:/* Get interface flags */ 955 ifr
.ifr_flags
= dev
->flags
; 958 case SIOCSIFFLAGS
:/* Set interface flags */ 960 int old_flags
= dev
->flags
; 963 * We are not allowed to potentially close/unload 964 * a device until we get this lock. 970 * Set the flags on our device. 973 dev
->flags
= (ifr
.ifr_flags
& ( 974 IFF_BROADCAST
| IFF_DEBUG
| IFF_LOOPBACK
| 975 IFF_POINTOPOINT
| IFF_NOTRAILERS
| IFF_RUNNING
| 976 IFF_NOARP
| IFF_PROMISC
| IFF_ALLMULTI
| IFF_SLAVE
| IFF_MASTER
977 | IFF_MULTICAST
)) | (dev
->flags
& IFF_UP
); 979 * Load in the correct multicast list now the flags have changed. 985 * Have we downed the interface. We handle IFF_UP ourselves 986 * according to user attempts to set it, rather than blindly 990 if((old_flags
^ifr
.ifr_flags
)&IFF_UP
)/* Bit is different ? */ 992 if(old_flags
&IFF_UP
)/* Gone down */ 998 dev
->flags
&=~IFF_UP
;/* Open failed */ 1004 * Load in the correct multicast list now the flags have changed. 1011 case SIOCGIFADDR
:/* Get interface address (and family) */ 1012 if(ifr
.ifr_addr
.sa_family
==AF_UNSPEC
) 1014 memcpy(ifr
.ifr_hwaddr
.sa_data
,dev
->dev_addr
, MAX_ADDR_LEN
); 1015 ifr
.ifr_hwaddr
.sa_family
=dev
->type
; 1020 (*(struct sockaddr_in
*) 1021 &ifr
.ifr_addr
).sin_addr
.s_addr
= dev
->pa_addr
; 1022 (*(struct sockaddr_in
*) 1023 &ifr
.ifr_addr
).sin_family
= dev
->family
; 1024 (*(struct sockaddr_in
*) 1025 &ifr
.ifr_addr
).sin_port
=0; 1029 case SIOCSIFADDR
:/* Set interface address (and family) */ 1032 * BSDism. SIOCSIFADDR family=AF_UNSPEC sets the 1033 * physical address. We can cope with this now. 1036 if(ifr
.ifr_addr
.sa_family
==AF_UNSPEC
) 1038 if(dev
->set_mac_address
==NULL
) 1040 ret
=dev
->set_mac_address(dev
,&ifr
.ifr_addr
); 1046 * if dev is an alias, must rehash to update 1050 #ifdef CONFIG_NET_ALIAS 1051 if(net_alias_is(dev
)) 1052 net_alias_dev_rehash(dev
,&ifr
.ifr_addr
); 1054 dev
->pa_addr
= (*(struct sockaddr_in
*) 1055 &ifr
.ifr_addr
).sin_addr
.s_addr
; 1056 dev
->family
= ifr
.ifr_addr
.sa_family
; 1059 /* This is naughty. When net-032e comes out It wants moving into the net032 1060 code not the kernel. Till then it can sit here (SIGH) */ 1061 dev
->pa_mask
=ip_get_mask(dev
->pa_addr
); 1063 dev
->pa_brdaddr
= dev
->pa_addr
| ~dev
->pa_mask
; 1068 case SIOCGIFBRDADDR
:/* Get the broadcast address */ 1069 (*(struct sockaddr_in
*) 1070 &ifr
.ifr_broadaddr
).sin_addr
.s_addr
= dev
->pa_brdaddr
; 1071 (*(struct sockaddr_in
*) 1072 &ifr
.ifr_broadaddr
).sin_family
= dev
->family
; 1073 (*(struct sockaddr_in
*) 1074 &ifr
.ifr_broadaddr
).sin_port
=0; 1077 case SIOCSIFBRDADDR
:/* Set the broadcast address */ 1078 dev
->pa_brdaddr
= (*(struct sockaddr_in
*) 1079 &ifr
.ifr_broadaddr
).sin_addr
.s_addr
; 1083 case SIOCGIFDSTADDR
:/* Get the destination address (for point-to-point links) */ 1084 (*(struct sockaddr_in
*) 1085 &ifr
.ifr_dstaddr
).sin_addr
.s_addr
= dev
->pa_dstaddr
; 1086 (*(struct sockaddr_in
*) 1087 &ifr
.ifr_dstaddr
).sin_family
= dev
->family
; 1088 (*(struct sockaddr_in
*) 1089 &ifr
.ifr_dstaddr
).sin_port
=0; 1092 case SIOCSIFDSTADDR
:/* Set the destination address (for point-to-point links) */ 1093 dev
->pa_dstaddr
= (*(struct sockaddr_in
*) 1094 &ifr
.ifr_dstaddr
).sin_addr
.s_addr
; 1098 case SIOCGIFNETMASK
:/* Get the netmask for the interface */ 1099 (*(struct sockaddr_in
*) 1100 &ifr
.ifr_netmask
).sin_addr
.s_addr
= dev
->pa_mask
; 1101 (*(struct sockaddr_in
*) 1102 &ifr
.ifr_netmask
).sin_family
= dev
->family
; 1103 (*(struct sockaddr_in
*) 1104 &ifr
.ifr_netmask
).sin_port
=0; 1107 case SIOCSIFNETMASK
:/* Set the netmask for the interface */ 1109 unsigned long mask
= (*(struct sockaddr_in
*) 1110 &ifr
.ifr_netmask
).sin_addr
.s_addr
; 1113 * The mask we set must be legal. 1115 if(bad_mask(mask
,0)) 1117 dev
->pa_mask
= mask
; 1122 case SIOCGIFMETRIC
:/* Get the metric on the interface (currently unused) */ 1124 ifr
.ifr_metric
= dev
->metric
; 1127 case SIOCSIFMETRIC
:/* Set the metric on the interface (currently unused) */ 1128 dev
->metric
= ifr
.ifr_metric
; 1132 case SIOCGIFMTU
:/* Get the MTU of a device */ 1133 ifr
.ifr_mtu
= dev
->mtu
; 1136 case SIOCSIFMTU
:/* Set the MTU of a device */ 1139 * MTU must be positive. 1146 ret
= (*dev
->change_mtu
)(dev
, ifr
.ifr_mtu
); 1149 dev
->mtu
= ifr
.ifr_mtu
; 1154 case SIOCGIFMEM
:/* Get the per device memory space. We can add this but currently 1155 do not support it */ 1159 case SIOCSIFMEM
:/* Set the per device memory buffer space. Not applicable in our case */ 1164 memcpy(ifr
.ifr_hwaddr
.sa_data
,dev
->dev_addr
, MAX_ADDR_LEN
); 1165 ifr
.ifr_hwaddr
.sa_family
=dev
->type
; 1169 if(dev
->set_mac_address
==NULL
) 1171 if(ifr
.ifr_hwaddr
.sa_family
!=dev
->type
) 1173 ret
=dev
->set_mac_address(dev
,&ifr
.ifr_hwaddr
); 1177 ifr
.ifr_map
.mem_start
=dev
->mem_start
; 1178 ifr
.ifr_map
.mem_end
=dev
->mem_end
; 1179 ifr
.ifr_map
.base_addr
=dev
->base_addr
; 1180 ifr
.ifr_map
.irq
=dev
->irq
; 1181 ifr
.ifr_map
.dma
=dev
->dma
; 1182 ifr
.ifr_map
.port
=dev
->if_port
; 1186 if(dev
->set_config
==NULL
) 1188 return dev
->set_config(dev
,&ifr
.ifr_map
); 1191 if(dev
->set_multicast_list
==NULL
) 1193 if(ifr
.ifr_hwaddr
.sa_family
!=AF_UNSPEC
) 1195 dev_mc_add(dev
,ifr
.ifr_hwaddr
.sa_data
, dev
->addr_len
,1); 1199 if(dev
->set_multicast_list
==NULL
) 1201 if(ifr
.ifr_hwaddr
.sa_family
!=AF_UNSPEC
) 1203 dev_mc_delete(dev
,ifr
.ifr_hwaddr
.sa_data
,dev
->addr_len
,1); 1206 * Unknown or private ioctl 1210 if((getset
>= SIOCDEVPRIVATE
) && 1211 (getset
<= (SIOCDEVPRIVATE
+15))) { 1212 if(dev
->do_ioctl
==NULL
) 1214 ret
=dev
->do_ioctl(dev
, &ifr
, getset
); 1215 memcpy_tofs(arg
,&ifr
,sizeof(struct ifreq
)); 1223 * The load of calls that return an ifreq and ok (saves memory). 1226 memcpy_tofs(arg
, &ifr
,sizeof(struct ifreq
)); 1232 * This function handles all "interface"-type I/O control requests. The actual 1233 * 'doing' part of this is dev_ifsioc above. 1236 intdev_ioctl(unsigned int cmd
,void*arg
) 1241 (void)dev_ifconf((char*) arg
); 1245 * Ioctl calls that can be done by all. 1250 case SIOCGIFDSTADDR
: 1251 case SIOCGIFBRDADDR
: 1252 case SIOCGIFNETMASK
: 1260 returndev_ifsioc(arg
, cmd
); 1263 * Ioctl calls requiring the power of a superuser 1268 case SIOCSIFDSTADDR
: 1269 case SIOCSIFBRDADDR
: 1270 case SIOCSIFNETMASK
: 1280 returndev_ifsioc(arg
, cmd
); 1286 * Unknown or private ioctl. 1290 if((cmd
>= SIOCDEVPRIVATE
) && 1291 (cmd
<= (SIOCDEVPRIVATE
+15))) { 1292 returndev_ifsioc(arg
, cmd
); 1300 * Initialize the DEV module. At boot time this walks the device list and 1301 * unhooks any devices that fail to initialise (normally hardware not 1302 * present) and leaves us with a valid list of present and active devices. 1305 externintlance_init(void); 1306 externintni65_init(void); 1307 externintpi_init(void); 1308 externvoidsdla_setup(void); 1309 externvoiddlci_setup(void); 1311 intnet_dev_init(void) 1313 struct device
*dev
, **dp
; 1316 * Initialise the packet receive queue. 1319 skb_queue_head_init(&backlog
); 1322 * This is VeryUgly(tm). 1324 * Some devices want to be initialized eary.. 1326 #if defined(CONFIG_LANCE) 1329 #if defined(CONFIG_NI65) 1332 #if defined(CONFIG_PI) 1335 #if defined(CONFIG_PT) 1338 #if defined(CONFIG_DLCI) 1341 #if defined(CONFIG_SDLA) 1345 * SLHC if present needs attaching so other people see it 1346 * even if not opened. 1348 #if (defined(CONFIG_SLIP) && defined(CONFIG_SLIP_COMPRESSED)) \ 1349 || defined(CONFIG_PPP) \ 1350 || (defined(CONFIG_ISDN) && defined(CONFIG_ISDN_PPP)) 1356 * If the call to dev->init fails, the dev is removed 1357 * from the chain disconnecting the device until the 1362 while((dev
= *dp
) != NULL
) 1365 for(i
=0; i
< DEV_NUMBUFFS
; i
++) { 1366 skb_queue_head_init(dev
->buffs
+ i
); 1369 if(dev
->init
&& dev
->init(dev
)) 1372 * It failed to come up. Unhook it. 1382 #ifdef CONFIG_PROC_FS 1383 proc_net_register(&(struct proc_dir_entry
) { 1384 PROC_NET_DEV
,3,"dev", 1385 S_IFREG
| S_IRUGO
,1,0,0, 1386 0, &proc_net_inode_operations
, 1392 * Initialise net_alias engine 1394 * - register net_alias device notifier 1395 * - register proc entries: /proc/net/alias_types 1399 #ifdef CONFIG_NET_ALIAS 1403 init_bh(NET_BH
, net_bh
);