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
48 * Thomas Bogendoerfer : Return ENODEV for dev_open, if there
49 * is no device open function.
53 #include <asm/uaccess.h>
54 #include <asm/system.h>
55 #include <asm/bitops.h>
56 #include <linux/config.h>
57 #include <linux/types.h>
58 #include <linux/kernel.h>
59 #include <linux/sched.h>
60 #include <linux/string.h>
62 #include <linux/socket.h>
63 #include <linux/sockios.h>
65 #include <linux/errno.h>
66 #include <linux/interrupt.h>
67 #include <linux/if_ether.h>
68 #include <linux/inet.h>
69 #include <linux/netdevice.h>
70 #include <linux/etherdevice.h>
71 #include <linux/notifier.h>
73 #include <net/route.h>
74 #include <linux/skbuff.h>
78 #include <linux/proc_fs.h>
79 #include <linux/stat.h>
81 #include <linux/net_alias.h>
82 #include <linux/init.h>
84 #include <linux/kerneld.h>
86 #ifdef CONFIG_NET_RADIO
87 #include <linux/wireless.h>
88 #endif /* CONFIG_NET_RADIO */
90 extern int plip_init(void);
94 * The list of devices, that are able to output.
97 static struct device
*dev_up_base
;
100 * The list of packet types we will receive (as opposed to discard)
101 * and the routines to invoke.
103 * Why 16. Because with 16 the only overlap we get on a hash of the
104 * low nibble of the protocol value is RARP/SNAP/X.25.
119 struct packet_type
*ptype_base
[16]; /* 16 way hashed list */
120 struct packet_type
*ptype_all
= NULL
; /* Taps */
126 atomic_t dev_lockct
= ATOMIC_INIT(0);
132 struct notifier_block
*netdev_chain
=NULL
;
135 * Device drivers call our routines to queue packets here. We empty the
136 * queue in the bottom half handler.
139 static struct sk_buff_head backlog
;
142 * We don't overdo the queue or we will thrash memory badly.
145 static int backlog_size
= 0;
149 /******************************************************************************************
151 Protocol management and registration routines
153 *******************************************************************************************/
159 static int dev_nit
=0;
162 * Add a protocol ID to the list. Now that the input handler is
163 * smarter we can dispense with all the messy stuff that used to be
167 void dev_add_pack(struct packet_type
*pt
)
170 if(pt
->type
==htons(ETH_P_ALL
))
178 hash
=ntohs(pt
->type
)&15;
179 pt
->next
= ptype_base
[hash
];
180 ptype_base
[hash
] = pt
;
186 * Remove a protocol ID from the list.
189 void dev_remove_pack(struct packet_type
*pt
)
191 struct packet_type
**pt1
;
192 if(pt
->type
==htons(ETH_P_ALL
))
198 pt1
=&ptype_base
[ntohs(pt
->type
)&15];
199 for(; (*pt1
)!=NULL
; pt1
=&((*pt1
)->next
))
207 printk(KERN_WARNING
"dev_remove_pack: %p not found.\n", pt
);
210 /*****************************************************************************************
212 Device Interface Subroutines
214 ******************************************************************************************/
217 * Find an interface by name.
220 struct device
*dev_get(const char *name
)
224 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
)
226 if (strcmp(dev
->name
, name
) == 0)
232 struct device
* dev_get_by_index(int ifindex
)
236 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
)
238 if (dev
->ifindex
== ifindex
)
244 struct device
*dev_getbyhwaddr(unsigned short type
, char *ha
)
248 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
)
250 if (dev
->type
== type
&&
251 !(dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
)) &&
252 memcmp(dev
->dev_addr
, ha
, dev
->addr_len
) == 0)
259 * Passed a format string - eg "lt%d" it will try and find a suitable
260 * id. Not efficient for many devices, not called a lot..
263 int dev_alloc_name(struct device
*dev
, const char *name
)
267 * If you need over 100 please also fix the algorithm...
271 sprintf(dev
->name
,name
,i
);
272 if(dev_get(dev
->name
)==NULL
)
275 return -ENFILE
; /* Over 100 of the things .. bail out! */
278 struct device
*dev_alloc(const char *name
, int *err
)
280 struct device
*dev
=kmalloc(sizeof(struct device
)+16, GFP_KERNEL
);
286 dev
->name
=(char *)(dev
+1); /* Name string space */
287 *err
=dev_alloc_name(dev
,name
);
298 * Find and possibly load an interface.
301 #ifdef CONFIG_KERNELD
303 void dev_load(const char *name
)
306 #ifdef CONFIG_NET_ALIAS
309 for (sptr
=name
; *sptr
; sptr
++) if(*sptr
==':') break;
310 if (!(*sptr
&& *(sptr
+1)))
312 request_module(name
);
319 * Prepare an interface for use.
322 int dev_open(struct device
*dev
)
327 * Call device private open method
331 ret
= dev
->open(dev
);
334 * If it went open OK then set the flags
339 dev
->flags
|= (IFF_UP
| IFF_RUNNING
);
341 * Initialise multicasting status
344 notifier_call_chain(&netdev_chain
, NETDEV_UP
, dev
);
347 * Passive non transmitting devices (including
348 * aliases) need not be on this chain.
350 if (!net_alias_is(dev
) && dev
->tx_queue_len
)
353 dev
->next_up
= dev_up_base
;
363 * Completely shutdown an interface.
366 int dev_close(struct device
*dev
)
369 struct device
**devp
;
372 * Call the device specific close. This cannot fail.
373 * Only if device is UP
376 if ((dev
->flags
& IFF_UP
) && dev
->stop
)
380 * Device is now down.
383 dev
->flags
&=~(IFF_UP
|IFF_RUNNING
);
386 * Tell people we are going down
389 notifier_call_chain(&netdev_chain
, NETDEV_DOWN
, dev
);
391 * Flush the multicast chain
396 * Purge any queued packets when we down the link
398 while(ct
<DEV_NUMBUFFS
)
401 while((skb
=skb_dequeue(&dev
->buffs
[ct
]))!=NULL
)
402 kfree_skb(skb
,FREE_WRITE
);
407 * The device is no longer up. Drop it from the list.
415 *devp
= dev
->next_up
;
418 devp
= &(*devp
)->next_up
;
425 * Device change register/unregister. These are not inline or static
426 * as we export them to the world.
429 int register_netdevice_notifier(struct notifier_block
*nb
)
431 return notifier_chain_register(&netdev_chain
, nb
);
434 int unregister_netdevice_notifier(struct notifier_block
*nb
)
436 return notifier_chain_unregister(&netdev_chain
,nb
);
440 * Support routine. Sends outgoing frames to any network
441 * taps currently in use.
444 static void queue_xmit_nit(struct sk_buff
*skb
, struct device
*dev
)
446 struct packet_type
*ptype
;
447 get_fast_time(&skb
->stamp
);
449 for (ptype
= ptype_all
; ptype
!=NULL
; ptype
= ptype
->next
)
451 /* Never send packets back to the socket
452 * they originated from - MvS (miquels@drinkel.ow.org)
454 if ((ptype
->dev
== dev
|| !ptype
->dev
) &&
455 ((struct sock
*)ptype
->data
!= skb
->sk
))
457 struct sk_buff
*skb2
;
458 if ((skb2
= skb_clone(skb
, GFP_ATOMIC
)) == NULL
)
460 skb2
->mac
.raw
= skb2
->data
;
461 skb2
->nh
.raw
= skb2
->h
.raw
= skb2
->data
+ dev
->hard_header_len
;
462 ptype
->func(skb2
, skb
->dev
, ptype
);
468 * Send (or queue for sending) a packet.
470 * IMPORTANT: When this is called to resend frames. The caller MUST
471 * already have locked the sk_buff. Apart from that we do the
475 static void do_dev_queue_xmit(struct sk_buff
*skb
, struct device
*dev
, int pri
)
478 struct sk_buff_head
*list
;
479 int retransmission
= 0; /* used to say if the packet should go */
480 /* at the front or the back of the */
481 /* queue - front is a retransmit try */
484 * Negative priority is used to flag a frame that is being pulled from the
485 * queue front as a retransmit attempt. It therefore goes back on the queue
486 * start on a failure.
495 #ifdef CONFIG_NET_DEBUG
496 if (pri
>= DEV_NUMBUFFS
)
498 printk(KERN_WARNING
"bad priority in do_dev_queue_xmit.\n");
504 * If we are bridging and this is directly generated output
505 * pass the frame via the bridge.
509 if(skb
->pkt_bridged
!=IS_BRIDGED
&& br_stats
.flags
& BR_UP
)
516 list
= dev
->buffs
+ pri
;
521 * If this isn't a retransmission, use the first packet instead.
522 * Note: We don't do strict priority ordering here. We will in
523 * fact kick the queue that is our priority. The dev_tint reload
524 * does strict priority queueing. In effect what we are doing here
525 * is to add some random jitter to the queues and to do so by
526 * saving clocks. Doing a perfect priority queue isn't a good idea
527 * as you get some fascinating timing interactions.
532 /* avoid overrunning the device queue.. */
533 if (skb_queue_len(list
) > dev
->tx_queue_len
)
535 dev_kfree_skb(skb
, FREE_WRITE
);
539 /* copy outgoing packets to any sniffer packet handlers */
541 queue_xmit_nit(skb
,dev
);
543 if (skb_queue_len(list
)) {
545 __skb_queue_tail(list
, skb
);
546 skb
= __skb_dequeue(list
);
547 restore_flags(flags
);
550 if (dev
->hard_start_xmit(skb
, dev
) == 0) {
552 * Packet is now solely the responsibility of the driver
558 * Transmission failed, put skb back into a list. Once on the list it's safe and
559 * no longer device locked (it can be freed safely from the device queue)
562 __skb_queue_head(list
,skb
);
563 restore_flags(flags
);
567 * Entry point for transmitting frames.
570 int dev_queue_xmit(struct sk_buff
*skb
)
572 struct device
*dev
= skb
->dev
;
577 * If the address has not been resolved. Call the device header rebuilder.
578 * This can cover all protocols and technically not just ARP either.
584 * FIXME: we should make the printk for no rebuild
585 * header a default rebuild_header routine and drop
586 * this call. Similarly we should make hard_header
587 * have a default NULL operation not check conditions.
589 if (dev
->rebuild_header
)
591 if (dev
->rebuild_header(skb
))
598 printk(KERN_DEBUG
"%s: !skb->arp & !rebuild_header!\n", dev
->name
);
603 * If dev is an alias, switch to its main device.
604 * "arp" resolution has been made with alias device, so
605 * arp entries refer to alias, not main.
609 if (net_alias_is(dev
))
610 skb
->dev
= dev
= net_alias_main_dev(dev
);
612 do_dev_queue_xmit(skb
, dev
, skb
->priority
);
618 * Fast path for loopback frames.
621 void dev_loopback_xmit(struct sk_buff
*skb
)
623 struct sk_buff
*newskb
=skb_clone(skb
, GFP_ATOMIC
);
627 skb_pull(newskb
, newskb
->nh
.raw
- newskb
->data
);
628 newskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
629 if (newskb
->dst
==NULL
)
630 printk(KERN_DEBUG
"BUG: packet without dst looped back 1\n");
636 * Receive a packet from a device driver and queue it for the upper
637 * (protocol) levels. It always succeeds.
640 void netif_rx(struct sk_buff
*skb
)
642 static int dropping
= 0;
645 * Any received buffers are un-owned and should be discarded
646 * when freed. These will be updated later as the frames get
651 if(skb
->stamp
.tv_sec
==0)
652 get_fast_time(&skb
->stamp
);
655 * Check that we aren't overdoing things.
660 else if (backlog_size
> 300)
665 kfree_skb(skb
, FREE_READ
);
670 * Add it to the "backlog" queue.
673 skb_queue_tail(&backlog
,skb
);
677 * If any packet arrived, mark it for processing after the
678 * hardware interrupt returns.
686 * This routine causes all interfaces to try to send some data.
689 static void dev_transmit(void)
693 for (dev
= dev_up_base
; dev
!= NULL
; dev
= dev
->next_up
)
695 if (dev
->flags
!= 0 && !dev
->tbusy
)
706 /**********************************************************************************
708 Receive Queue Processor
710 ***********************************************************************************/
713 * When we are called the queue is ready to grab, the interrupts are
714 * on and hardware can interrupt and queue to the receive queue as we
715 * run with no problems.
716 * This is run as a bottom half after an interrupt handler that does
722 struct packet_type
*ptype
;
723 struct packet_type
*pt_prev
;
728 * Can we send anything now? We want to clear the
729 * decks for any more sends that get done as we
730 * process the input. This also minimises the
731 * latency on a transmit interrupt bh.
737 * Any data left to process. This may occur because a
738 * mark_bh() is done after we empty the queue including
739 * that from the device which does a mark_bh() just after
743 * While the queue is not empty..
745 * Note that the queue never shrinks due to
746 * an interrupt, so we can do this test without
747 * disabling interrupts.
750 while (!skb_queue_empty(&backlog
))
752 struct sk_buff
* skb
= backlog
.next
;
755 * We have a packet. Therefore the queue has shrunk
758 __skb_unlink(skb
, &backlog
);
763 * We do not want to spin in net_bh infinitely. --ANK
768 printk(KERN_WARNING
"net_bh: too many loops, dropping...\n");
769 kfree_skb(skb
, FREE_WRITE
);
776 * If we are bridging then pass the frame up to the
777 * bridging code (if this protocol is to be bridged).
778 * If it is bridged then move on
781 if (br_stats
.flags
& BR_UP
&& br_protocol_ok(ntohs(skb
->protocol
)))
784 * We pass the bridge a complete frame. This means
785 * recovering the MAC header first.
788 int offset
=skb
->data
-skb
->mac
.raw
;
790 skb_push(skb
,offset
); /* Put header back on for bridge */
791 if(br_receive_frame(skb
))
797 * Pull the MAC header off for the copy going to
800 skb_pull(skb
,offset
);
806 * Bump the pointer to the next structure.
808 * On entry to the protocol layer. skb->data and
809 * skb->nh.raw point to the MAC and encapsulated data
812 /* XXX until we figure out every place to modify.. */
813 skb
->h
.raw
= skb
->nh
.raw
= skb
->data
;
816 * Fetch the packet protocol ID.
819 type
= skb
->protocol
;
822 * We got a packet ID. Now loop over the "known protocols"
823 * list. There are two lists. The ptype_all list of taps (normally empty)
824 * and the main protocol list which is hashed perfectly for normal protocols.
828 for (ptype
= ptype_all
; ptype
!=NULL
; ptype
=ptype
->next
)
832 struct sk_buff
*skb2
=skb_clone(skb
, GFP_ATOMIC
);
834 pt_prev
->func(skb2
,skb
->dev
, pt_prev
);
839 for (ptype
= ptype_base
[ntohs(type
)&15]; ptype
!= NULL
; ptype
= ptype
->next
)
841 if (ptype
->type
== type
&& (!ptype
->dev
|| ptype
->dev
==skb
->dev
))
844 * We already have a match queued. Deliver
845 * to it and then remember the new match
849 struct sk_buff
*skb2
;
851 skb2
=skb_clone(skb
, GFP_ATOMIC
);
854 * Kick the protocol handler. This should be fast
855 * and efficient code.
859 pt_prev
->func(skb2
, skb
->dev
, pt_prev
);
861 /* Remember the current last to do */
864 } /* End of protocol list loop */
867 * Is there a last item to send to ?
871 pt_prev
->func(skb
, skb
->dev
, pt_prev
);
873 * Has an unknown packet has been received ?
877 kfree_skb(skb
, FREE_WRITE
);
879 * Again, see if we can transmit anything now.
880 * [Ought to take this out judging by tests it slows
881 * us down not speeds us up]
886 } /* End of queue loop */
889 * We have emptied the queue
893 * One last output flush.
901 * This routine is called when an device driver (i.e. an
902 * interface) is ready to transmit a packet.
905 void dev_tint(struct device
*dev
)
909 struct sk_buff_head
* head
;
912 * aliases do not transmit (for now :) )
915 if (net_alias_is(dev
)) {
916 printk(KERN_DEBUG
"net alias %s transmits\n", dev
->name
);
925 * Work the queues in priority order
927 for(i
= 0;i
< DEV_NUMBUFFS
; i
++,head
++)
930 while (!skb_queue_empty(head
)) {
934 __skb_unlink(skb
, head
);
936 * Stop anyone freeing the buffer while we retransmit it
938 restore_flags(flags
);
940 * Feed them to the output stage and if it fails
941 * indicate they re-queue at the front.
943 do_dev_queue_xmit(skb
,dev
,-i
- 1);
945 * If we can take no more then stop here.
952 restore_flags(flags
);
957 * Perform a SIOCGIFCONF call. This structure will change
958 * size eventually, and there is nothing I can do about it.
959 * Thus we will need a 'compatibility mode'.
962 static int dev_ifconf(char *arg
)
972 * Fetch the caller's info block.
975 err
= copy_from_user(&ifc
, arg
, sizeof(struct ifconf
));
982 * We now walk the device list filling each active device
987 * Loop over the interfaces, and write an info block for each.
990 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
)
993 * Have we run out of space here ?
996 if (len
< sizeof(struct ifreq
))
999 memset(&ifr
, 0, sizeof(struct ifreq
));
1000 strcpy(ifr
.ifr_name
, dev
->name
);
1001 (*(struct sockaddr_in
*) &ifr
.ifr_addr
).sin_family
= dev
->family
;
1002 (*(struct sockaddr_in
*) &ifr
.ifr_addr
).sin_addr
.s_addr
= dev
->pa_addr
;
1006 * Write this block to the caller's space.
1009 err
= copy_to_user(pos
, &ifr
, sizeof(struct ifreq
));
1012 pos
+= sizeof(struct ifreq
);
1013 len
-= sizeof(struct ifreq
);
1017 * All done. Write the updated control block back to the caller.
1020 ifc
.ifc_len
= (pos
- ifc
.ifc_buf
);
1021 ifc
.ifc_req
= (struct ifreq
*) ifc
.ifc_buf
;
1022 err
= copy_to_user(arg
, &ifc
, sizeof(struct ifconf
));
1027 * Report how much was filled in
1035 * This is invoked by the /proc filesystem handler to display a device
1039 #ifdef CONFIG_PROC_FS
1040 static int sprintf_stats(char *buffer
, struct device
*dev
)
1042 struct net_device_stats
*stats
= (dev
->get_stats
? dev
->get_stats(dev
): NULL
);
1046 size
= sprintf(buffer
, "%6s:%8lu %7lu %4lu %4lu %4lu %4lu %8lu %8lu %4lu %4lu %4lu %5lu %4lu\n",
1049 stats
->rx_packets
, stats
->rx_errors
,
1050 stats
->rx_dropped
+ stats
->rx_missed_errors
,
1051 stats
->rx_fifo_errors
,
1052 stats
->rx_length_errors
+ stats
->rx_over_errors
1053 + stats
->rx_crc_errors
+ stats
->rx_frame_errors
,
1055 stats
->tx_packets
, stats
->tx_errors
, stats
->tx_dropped
,
1056 stats
->tx_fifo_errors
, stats
->collisions
,
1057 stats
->tx_carrier_errors
+ stats
->tx_aborted_errors
1058 + stats
->tx_window_errors
+ stats
->tx_heartbeat_errors
);
1060 size
= sprintf(buffer
, "%6s: No statistics available.\n", dev
->name
);
1066 * Called from the PROCfs module. This now uses the new arbitrary sized /proc/net interface
1067 * to create /proc/net/dev
1070 int dev_get_info(char *buffer
, char **start
, off_t offset
, int length
, int dummy
)
1080 size
= sprintf(buffer
, "Inter-| Receive | Transmit\n"
1081 " face |bytes packets errs drop fifo frame|bytes packets errs drop fifo colls carrier\n");
1087 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
)
1089 size
= sprintf_stats(buffer
+len
, dev
);
1098 if(pos
>offset
+length
)
1102 *start
=buffer
+(offset
-begin
); /* Start of wanted data */
1103 len
-=(offset
-begin
); /* Start slop */
1105 len
=length
; /* Ending slop */
1108 #endif /* CONFIG_PROC_FS */
1111 #ifdef CONFIG_NET_RADIO
1112 #ifdef CONFIG_PROC_FS
1115 * Print one entry of /proc/net/wireless
1116 * This is a clone of /proc/net/dev (just above)
1118 static int sprintf_wireless_stats(char *buffer
, struct device
*dev
)
1120 /* Get stats from the driver */
1121 struct iw_statistics
*stats
= (dev
->get_wireless_stats
?
1122 dev
->get_wireless_stats(dev
) :
1123 (struct iw_statistics
*) NULL
);
1126 if(stats
!= (struct iw_statistics
*) NULL
)
1127 size
= sprintf(buffer
,
1128 "%6s: %02x %3d%c %3d%c %3d%c %5d %5d %5d\n",
1132 stats
->qual
.updated
& 1 ? '.' : ' ',
1134 stats
->qual
.updated
& 2 ? '.' : ' ',
1136 stats
->qual
.updated
& 3 ? '.' : ' ',
1137 stats
->discard
.nwid
,
1138 stats
->discard
.code
,
1139 stats
->discard
.misc
);
1147 * Print info for /proc/net/wireless (print all entries)
1148 * This is a clone of /proc/net/dev (just above)
1150 int dev_get_wireless_info(char * buffer
, char **start
, off_t offset
,
1151 int length
, int dummy
)
1158 struct device
* dev
;
1160 size
= sprintf(buffer
,
1161 "Inter-|sta| Quality | Discarded packets\n"
1162 " face |tus|link level noise| nwid crypt misc\n");
1167 for(dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
)
1169 size
= sprintf_wireless_stats(buffer
+len
, dev
);
1178 if(pos
> offset
+ length
)
1182 *start
= buffer
+ (offset
- begin
); /* Start of wanted data */
1183 len
-= (offset
- begin
); /* Start slop */
1185 len
= length
; /* Ending slop */
1189 #endif /* CONFIG_PROC_FS */
1190 #endif /* CONFIG_NET_RADIO */
1194 * Perform the SIOCxIFxxx calls.
1196 * The socket layer has seen an ioctl the address family thinks is
1197 * for the device. At this point we get invoked to make a decision
1200 static int dev_ifsioc(void *arg
, unsigned int getset
)
1207 * Fetch the caller's info block into kernel space
1210 err
= copy_from_user(&ifr
, arg
, sizeof(struct ifreq
));
1215 * See which interface the caller is talking about.
1220 * net_alias_dev_get(): dev_get() with added alias naming magic.
1221 * only allow alias creation/deletion if (getset==SIOCSIFADDR)
1225 #ifdef CONFIG_KERNELD
1226 dev_load(ifr
.ifr_name
);
1229 #ifdef CONFIG_NET_ALIAS
1230 if ((dev
= net_alias_dev_get(ifr
.ifr_name
, getset
== SIOCSIFADDR
, &err
, NULL
, NULL
)) == NULL
)
1233 if ((dev
= dev_get(ifr
.ifr_name
)) == NULL
)
1238 case SIOCGIFFLAGS
: /* Get interface flags */
1239 ifr
.ifr_flags
= dev
->flags
;
1242 case SIOCSIFFLAGS
: /* Set interface flags */
1244 int old_flags
= dev
->flags
;
1247 * We are not allowed to potentially close/unload
1248 * a device until we get this lock.
1255 * Set the flags on our device.
1258 dev
->flags
= (ifr
.ifr_flags
& (
1259 IFF_BROADCAST
| IFF_DEBUG
| IFF_LOOPBACK
|
1260 IFF_POINTOPOINT
| IFF_NOTRAILERS
| IFF_RUNNING
|
1261 IFF_NOARP
| IFF_PROMISC
| IFF_ALLMULTI
| IFF_SLAVE
| IFF_MASTER
1262 | IFF_MULTICAST
)) | (dev
->flags
& IFF_UP
);
1264 * Load in the correct multicast list now the flags have changed.
1270 * Have we downed the interface. We handle IFF_UP ourselves
1271 * according to user attempts to set it, rather than blindly
1275 if ((old_flags
^ifr
.ifr_flags
)&IFF_UP
) /* Bit is different ? */
1277 if(old_flags
&IFF_UP
) /* Gone down */
1283 dev
->flags
&=~IFF_UP
; /* Open failed */
1289 * Load in the correct multicast list now the flags have changed.
1293 if ((dev
->flags
&IFF_UP
) && ((old_flags
^dev
->flags
)&~(IFF_UP
|IFF_RUNNING
|IFF_PROMISC
)))
1295 printk(KERN_DEBUG
"SIFFL %s(%s)\n", dev
->name
, current
->comm
);
1296 notifier_call_chain(&netdev_chain
, NETDEV_CHANGE
, dev
);
1298 if ((dev
->flags
^old_flags
)&IFF_PROMISC
) {
1299 if (dev
->flags
&IFF_PROMISC
)
1300 printk(KERN_INFO
"%s enters promiscuous mode.\n", dev
->name
);
1302 printk(KERN_INFO
"%s leave promiscuous mode.\n", dev
->name
);
1308 case SIOCGIFMETRIC
: /* Get the metric on the interface (currently unused) */
1310 ifr
.ifr_metric
= dev
->metric
;
1313 case SIOCSIFMETRIC
: /* Set the metric on the interface (currently unused) */
1314 dev
->metric
= ifr
.ifr_metric
;
1318 case SIOCGIFMTU
: /* Get the MTU of a device */
1319 ifr
.ifr_mtu
= dev
->mtu
;
1322 case SIOCSIFMTU
: /* Set the MTU of a device */
1324 if (ifr
.ifr_mtu
== dev
->mtu
) {
1330 * MTU must be positive.
1336 if (dev
->change_mtu
)
1337 ret
= dev
->change_mtu(dev
, ifr
.ifr_mtu
);
1340 dev
->mtu
= ifr
.ifr_mtu
;
1343 if (!ret
&& dev
->flags
&IFF_UP
) {
1344 printk(KERN_DEBUG
"SIFMTU %s(%s)\n", dev
->name
, current
->comm
);
1345 notifier_call_chain(&netdev_chain
, NETDEV_CHANGEMTU
, dev
);
1349 case SIOCGIFMEM
: /* Get the per device memory space. We can add this but currently
1350 do not support it */
1354 case SIOCSIFMEM
: /* Set the per device memory buffer space. Not applicable in our case */
1359 memcpy(ifr
.ifr_hwaddr
.sa_data
,dev
->dev_addr
, MAX_ADDR_LEN
);
1360 ifr
.ifr_hwaddr
.sa_family
=dev
->type
;
1364 if(dev
->set_mac_address
==NULL
)
1366 if(ifr
.ifr_hwaddr
.sa_family
!=dev
->type
)
1368 ret
=dev
->set_mac_address(dev
,&ifr
.ifr_hwaddr
);
1370 notifier_call_chain(&netdev_chain
, NETDEV_CHANGEADDR
, dev
);
1374 ifr
.ifr_map
.mem_start
=dev
->mem_start
;
1375 ifr
.ifr_map
.mem_end
=dev
->mem_end
;
1376 ifr
.ifr_map
.base_addr
=dev
->base_addr
;
1377 ifr
.ifr_map
.irq
=dev
->irq
;
1378 ifr
.ifr_map
.dma
=dev
->dma
;
1379 ifr
.ifr_map
.port
=dev
->if_port
;
1383 if(dev
->set_config
==NULL
)
1385 return dev
->set_config(dev
,&ifr
.ifr_map
);
1388 if(dev
->set_multicast_list
==NULL
)
1390 if(ifr
.ifr_hwaddr
.sa_family
!=AF_UNSPEC
)
1392 dev_mc_add(dev
,ifr
.ifr_hwaddr
.sa_data
, dev
->addr_len
, 1);
1396 if(dev
->set_multicast_list
==NULL
)
1398 if(ifr
.ifr_hwaddr
.sa_family
!=AF_UNSPEC
)
1400 dev_mc_delete(dev
,ifr
.ifr_hwaddr
.sa_data
,dev
->addr_len
, 1);
1404 ifr
.ifr_ifindex
= dev
->ifindex
;
1409 * Unknown or private ioctl
1413 if((getset
>= SIOCDEVPRIVATE
) &&
1414 (getset
<= (SIOCDEVPRIVATE
+ 15))) {
1415 if(dev
->do_ioctl
==NULL
)
1417 ret
= dev
->do_ioctl(dev
, &ifr
, getset
);
1420 err
= copy_to_user(arg
,&ifr
,sizeof(struct ifreq
));
1427 #ifdef CONFIG_NET_RADIO
1428 if((getset
>= SIOCIWFIRST
) && (getset
<= SIOCIWLAST
))
1430 if(dev
->do_ioctl
==NULL
)
1432 /* Perform the ioctl */
1433 ret
=dev
->do_ioctl(dev
, &ifr
, getset
);
1434 /* If return args... */
1435 if(IW_IS_GET(getset
))
1437 if (copy_to_user(arg
, &ifr
,
1438 sizeof(struct ifreq
)))
1445 #endif /* CONFIG_NET_RADIO */
1451 * The load of calls that return an ifreq and ok (saves memory).
1454 err
= copy_to_user(arg
, &ifr
, sizeof(struct ifreq
));
1462 * This function handles all "interface"-type I/O control requests. The actual
1463 * 'doing' part of this is dev_ifsioc above.
1466 int dev_ioctl(unsigned int cmd
, void *arg
)
1471 (void) dev_ifconf((char *) arg
);
1475 * Ioctl calls that can be done by all.
1487 return dev_ifsioc(arg
, cmd
);
1490 * Ioctl calls requiring the power of a superuser
1503 return dev_ifsioc(arg
, cmd
);
1509 * Unknown or private ioctl.
1513 if((cmd
>= SIOCDEVPRIVATE
) &&
1514 (cmd
<= (SIOCDEVPRIVATE
+ 15))) {
1515 return dev_ifsioc(arg
, cmd
);
1517 #ifdef CONFIG_NET_RADIO
1518 if((cmd
>= SIOCIWFIRST
) && (cmd
<= SIOCIWLAST
))
1520 if((IW_IS_SET(cmd
)) && (!suser()))
1522 return dev_ifsioc(arg
, cmd
);
1524 #endif /* CONFIG_NET_RADIO */
1536 * Initialize the DEV module. At boot time this walks the device list and
1537 * unhooks any devices that fail to initialise (normally hardware not
1538 * present) and leaves us with a valid list of present and active devices.
1541 extern int lance_init(void);
1542 extern int pi_init(void);
1543 extern int bpq_init(void);
1544 extern int scc_init(void);
1545 extern void sdla_setup(void);
1546 extern void dlci_setup(void);
1547 extern int pt_init(void);
1548 extern int sm_init(void);
1549 extern int baycom_init(void);
1550 extern int lapbeth_init(void);
1552 #ifdef CONFIG_PROC_FS
1553 static struct proc_dir_entry proc_net_dev
= {
1554 PROC_NET_DEV
, 3, "dev",
1555 S_IFREG
| S_IRUGO
, 1, 0, 0,
1556 0, &proc_net_inode_operations
,
1561 #ifdef CONFIG_NET_RADIO
1562 #ifdef CONFIG_PROC_FS
1563 static struct proc_dir_entry proc_net_wireless
= {
1564 PROC_NET_WIRELESS
, 8, "wireless",
1565 S_IFREG
| S_IRUGO
, 1, 0, 0,
1566 0, &proc_net_inode_operations
,
1567 dev_get_wireless_info
1569 #endif /* CONFIG_PROC_FS */
1570 #endif /* CONFIG_NET_RADIO */
1572 __initfunc(int net_dev_init(void))
1574 struct device
*dev
, **dp
;
1577 * Initialise the packet receive queue.
1580 skb_queue_head_init(&backlog
);
1583 * The bridge has to be up before the devices
1586 #ifdef CONFIG_BRIDGE
1591 * This is Very Ugly(tm).
1593 * Some devices want to be initialized early..
1595 #if defined(CONFIG_LANCE)
1598 #if defined(CONFIG_PI)
1601 #if defined(CONFIG_SCC)
1604 #if defined(CONFIG_PT)
1607 #if defined(CONFIG_BPQETHER)
1610 #if defined(CONFIG_DLCI)
1613 #if defined(CONFIG_SDLA)
1616 #if defined(CONFIG_BAYCOM)
1619 #if defined(CONFIG_SOUNDMODEM)
1622 #if defined(CONFIG_LAPBETHER)
1625 #if defined(CONFIG_PLIP)
1629 * SLHC if present needs attaching so other people see it
1630 * even if not opened.
1632 #if (defined(CONFIG_SLIP) && defined(CONFIG_SLIP_COMPRESSED)) \
1633 || defined(CONFIG_PPP) \
1634 || (defined(CONFIG_ISDN) && defined(CONFIG_ISDN_PPP))
1640 * If the call to dev->init fails, the dev is removed
1641 * from the chain disconnecting the device until the
1646 while ((dev
= *dp
) != NULL
)
1649 for (i
= 0; i
< DEV_NUMBUFFS
; i
++) {
1650 skb_queue_head_init(dev
->buffs
+ i
);
1653 if (dev
->init
&& dev
->init(dev
))
1656 * It failed to come up. Unhook it.
1663 dev
->ifindex
= dev_new_index();
1667 #ifdef CONFIG_PROC_FS
1668 proc_net_register(&proc_net_dev
);
1671 #ifdef CONFIG_NET_RADIO
1672 #ifdef CONFIG_PROC_FS
1673 proc_net_register(&proc_net_wireless
);
1674 #endif /* CONFIG_PROC_FS */
1675 #endif /* CONFIG_NET_RADIO */
1678 * Initialise net_alias engine
1680 * - register net_alias device notifier
1681 * - register proc entries: /proc/net/alias_types
1685 #ifdef CONFIG_NET_ALIAS
1689 init_bh(NET_BH
, net_bh
);