Main Page | Class List | File List | Class Members | File Members

dev.c

Go to the documentation of this file.
00001 /* 00002 * NET3 Protocol independent device support routines. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 00007 * 2 of the License, or (at your option) any later version. 00008 * 00009 * Derived from the non IP parts of dev.c 1.0.19 00010 * Authors: Ross Biro, <bir7@leland.Stanford.Edu> 00011 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 00012 * Mark Evans, <evansmp@uhura.aston.ac.uk> 00013 * 00014 * Additional Authors: 00015 * Florian la Roche <rzsfl@rz.uni-sb.de> 00016 * Alan Cox <gw4pts@gw4pts.ampr.org> 00017 * David Hinds <dahinds@users.sourceforge.net> 00018 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> 00019 * Adam Sulmicki <adam@cfar.umd.edu> 00020 * Pekka Riikonen <priikone@poesidon.pspt.fi> 00021 * 00022 * Changes: 00023 * D.J. Barrow : Fixed bug where dev->refcnt gets set to 2 00024 * if register_netdev gets called before 00025 * net_dev_init & also removed a few lines 00026 * of code in the process. 00027 * Alan Cox : device private ioctl copies fields back. 00028 * Alan Cox : Transmit queue code does relevant stunts to 00029 * keep the queue safe. 00030 * Alan Cox : Fixed double lock. 00031 * Alan Cox : Fixed promisc NULL pointer trap 00032 * ???????? : Support the full private ioctl range 00033 * Alan Cox : Moved ioctl permission check into drivers 00034 * Tim Kordas : SIOCADDMULTI/SIOCDELMULTI 00035 * Alan Cox : 100 backlog just doesn't cut it when 00036 * you start doing multicast video 8) 00037 * Alan Cox : Rewrote net_bh and list manager. 00038 * Alan Cox : Fix ETH_P_ALL echoback lengths. 00039 * Alan Cox : Took out transmit every packet pass 00040 * Saved a few bytes in the ioctl handler 00041 * Alan Cox : Network driver sets packet type before calling netif_rx. Saves 00042 * a function call a packet. 00043 * Alan Cox : Hashed net_bh() 00044 * Richard Kooijman: Timestamp fixes. 00045 * Alan Cox : Wrong field in SIOCGIFDSTADDR 00046 * Alan Cox : Device lock protection. 00047 * Alan Cox : Fixed nasty side effect of device close changes. 00048 * Rudi Cilibrasi : Pass the right thing to set_mac_address() 00049 * Dave Miller : 32bit quantity for the device lock to make it work out 00050 * on a Sparc. 00051 * Bjorn Ekwall : Added KERNELD hack. 00052 * Alan Cox : Cleaned up the backlog initialise. 00053 * Craig Metz : SIOCGIFCONF fix if space for under 00054 * 1 device. 00055 * Thomas Bogendoerfer : Return ENODEV for dev_open, if there 00056 * is no device open function. 00057 * Andi Kleen : Fix error reporting for SIOCGIFCONF 00058 * Michael Chastain : Fix signed/unsigned for SIOCGIFCONF 00059 * Cyrus Durgin : Cleaned for KMOD 00060 * Adam Sulmicki : Bug Fix : Network Device Unload 00061 * A network device unload needs to purge 00062 * the backlog queue. 00063 * Paul Rusty Russell : SIOCSIFNAME 00064 * Pekka Riikonen : Netdev boot-time settings code 00065 * Andrew Morton : Make unregister_netdevice wait indefinitely on dev->refcnt 00066 * J Hadi Salim : - Backlog queue sampling 00067 * - netif_rx() feedback 00068 */ 00069 00070 #include <asm/uaccess.h> 00071 #include <asm/system.h> 00072 #include <asm/bitops.h> 00073 #include <linux/config.h> 00074 #include <linux/types.h> 00075 #include <linux/kernel.h> 00076 #include <linux/sched.h> 00077 #include <linux/string.h> 00078 #include <linux/mm.h> 00079 #include <linux/socket.h> 00080 #include <linux/sockios.h> 00081 #include <linux/errno.h> 00082 #include <linux/interrupt.h> 00083 #include <linux/if_ether.h> 00084 #include <linux/netdevice.h> 00085 #include <linux/etherdevice.h> 00086 #include <linux/notifier.h> 00087 #include <linux/skbuff.h> 00088 #include <linux/brlock.h> 00089 #include <net/sock.h> 00090 #include <linux/rtnetlink.h> 00091 #include <linux/proc_fs.h> 00092 #include <linux/stat.h> 00093 #include <linux/if_bridge.h> 00094 #include <linux/divert.h> 00095 #include <net/dst.h> 00096 #include <net/pkt_sched.h> 00097 #include <net/profile.h> 00098 #include <net/checksum.h> 00099 #include <linux/highmem.h> 00100 #include <linux/init.h> 00101 #include <linux/kmod.h> 00102 #include <linux/module.h> 00103 #if defined(CONFIG_NET_RADIO) || defined(CONFIG_NET_PCMCIA_RADIO) 00104 #include <linux/wireless.h> /* Note : will define WIRELESS_EXT */ 00105 #include <net/iw_handler.h> 00106 #endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */ 00107 #ifdef CONFIG_PLIP 00108 extern int plip_init(void); 00109 #endif 00110 00111 00112 /* This define, if set, will randomly drop a packet when congestion 00113 * is more than moderate. It helps fairness in the multi-interface 00114 * case when one of them is a hog, but it kills performance for the 00115 * single interface case so it is off now by default. 00116 */ 00117 #undef RAND_LIE 00118 00119 /* Setting this will sample the queue lengths and thus congestion 00120 * via a timer instead of as each packet is received. 00121 */ 00122 #undef OFFLINE_SAMPLE 00123 00124 NET_PROFILE_DEFINE(dev_queue_xmit) 00125 NET_PROFILE_DEFINE(softnet_process) 00126 00127 const char *if_port_text[] = { 00128 "unknown", 00129 "BNC", 00130 "10baseT", 00131 "AUI", 00132 "100baseT", 00133 "100baseTX", 00134 "100baseFX" 00135 }; 00136 00137 /* 00138 * The list of packet types we will receive (as opposed to discard) 00139 * and the routines to invoke. 00140 * 00141 * Why 16. Because with 16 the only overlap we get on a hash of the 00142 * low nibble of the protocol value is RARP/SNAP/X.25. 00143 * 00144 * NOTE: That is no longer true with the addition of VLAN tags. Not 00145 * sure which should go first, but I bet it won't make much 00146 * difference if we are running VLANs. The good news is that 00147 * this protocol won't be in the list unless compiled in, so 00148 * the average user (w/out VLANs) will not be adversly affected. 00149 * --BLG 00150 * 00151 * 0800 IP 00152 * 8100 802.1Q VLAN 00153 * 0001 802.3 00154 * 0002 AX.25 00155 * 0004 802.2 00156 * 8035 RARP 00157 * 0005 SNAP 00158 * 0805 X.25 00159 * 0806 ARP 00160 * 8137 IPX 00161 * 0009 Localtalk 00162 * 86DD IPv6 00163 */ 00164 00165 static struct packet_type *ptype_base[16]; /* 16 way hashed list */ 00166 static struct packet_type *ptype_all = NULL; /* Taps */ 00167 00168 #ifdef OFFLINE_SAMPLE 00169 static void sample_queue(unsigned long dummy); 00170 static struct timer_list samp_timer = { function: sample_queue }; 00171 #endif 00172 00173 #ifdef CONFIG_HOTPLUG 00174 static int net_run_sbin_hotplug(struct net_device *dev, char *action); 00175 #else 00176 #define net_run_sbin_hotplug(dev, action) ({ 0; }) 00177 #endif 00178 00179 /* 00180 * Our notifier list 00181 */ 00182 00183 static struct notifier_block *netdev_chain=NULL; 00184 00185 /* 00186 * Device drivers call our routines to queue packets here. We empty the 00187 * queue in the local softnet handler. 00188 */ 00189 struct softnet_data softnet_data[NR_CPUS] __cacheline_aligned; 00190 00191 #ifdef CONFIG_NET_FASTROUTE 00192 int netdev_fastroute; 00193 int netdev_fastroute_obstacles; 00194 #endif 00195 00196 00197 /****************************************************************************************** 00198 00199 Protocol management and registration routines 00200 00201 *******************************************************************************************/ 00202 00203 /* 00204 * For efficiency 00205 */ 00206 00207 int netdev_nit=0; 00208 00209 /* 00210 * Add a protocol ID to the list. Now that the input handler is 00211 * smarter we can dispense with all the messy stuff that used to be 00212 * here. 00213 * 00214 * BEWARE!!! Protocol handlers, mangling input packets, 00215 * MUST BE last in hash buckets and checking protocol handlers 00216 * MUST start from promiscous ptype_all chain in net_bh. 00217 * It is true now, do not change it. 00218 * Explantion follows: if protocol handler, mangling packet, will 00219 * be the first on list, it is not able to sense, that packet 00220 * is cloned and should be copied-on-write, so that it will 00221 * change it and subsequent readers will get broken packet. 00222 * --ANK (980803) 00223 */ 00224 00225 /* 00226 * dev_add_pack - add packet handler 00227 * @pt: packet type declaration 00228 * 00229 * Add a protocol handler to the networking stack. The passed &packet_type 00230 * is linked into kernel lists and may not be freed until it has been 00231 * removed from the kernel lists. 00232 */ 00233 00234 void dev_add_pack(struct packet_type *pt) 00235 { 00236 int hash; 00237 00238 br_write_lock_bh(BR_NETPROTO_LOCK); 00239 00240 #ifdef CONFIG_NET_FASTROUTE 00241 /* Hack to detect packet socket */ 00242 if ((pt->data) && ((int)(pt->data)!=1)) { 00243 netdev_fastroute_obstacles++; 00244 dev_clear_fastroute(pt->dev); 00245 } 00246 #endif 00247 if (pt->type == htons(ETH_P_ALL)) { 00248 netdev_nit++; 00249 pt->next=ptype_all; 00250 ptype_all=pt; 00251 } else { 00252 hash=ntohs(pt->type)&15; 00253 pt->next = ptype_base[hash]; 00254 ptype_base[hash] = pt; 00255 } 00256 br_write_unlock_bh(BR_NETPROTO_LOCK); 00257 } 00258 00259 00260 /* 00261 * dev_remove_pack - remove packet handler 00262 * @pt: packet type declaration 00263 * 00264 * Remove a protocol handler that was previously added to the kernel 00265 * protocol handlers by dev_add_pack(). The passed &packet_type is removed 00266 * from the kernel lists and can be freed or reused once this function 00267 * returns. 00268 */ 00269 00270 void dev_remove_pack(struct packet_type *pt) 00271 { 00272 struct packet_type **pt1; 00273 00274 br_write_lock_bh(BR_NETPROTO_LOCK); 00275 00276 if (pt->type == htons(ETH_P_ALL)) { 00277 netdev_nit--; 00278 pt1=&ptype_all; 00279 } else { 00280 pt1=&ptype_base[ntohs(pt->type)&15]; 00281 } 00282 00283 for (; (*pt1) != NULL; pt1 = &((*pt1)->next)) { 00284 if (pt == (*pt1)) { 00285 *pt1 = pt->next; 00286 #ifdef CONFIG_NET_FASTROUTE 00287 if (pt->data) 00288 netdev_fastroute_obstacles--; 00289 #endif 00290 br_write_unlock_bh(BR_NETPROTO_LOCK); 00291 return; 00292 } 00293 } 00294 br_write_unlock_bh(BR_NETPROTO_LOCK); 00295 printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt); 00296 } 00297 00298 /****************************************************************************** 00299 00300 Device Boot-time Settings Routines 00301 00302 *******************************************************************************/ 00303 00304 /* Boot time configuration table */ 00305 static struct netdev_boot_setup dev_boot_setup[NETDEV_BOOT_SETUP_MAX]; 00306 00307 /* 00308 * netdev_boot_setup_add - add new setup entry 00309 * @name: name of the device 00310 * @map: configured settings for the device 00311 * 00312 * Adds new setup entry to the dev_boot_setup list. The function 00313 * returns 0 on error and 1 on success. This is a generic routine to 00314 * all netdevices. 00315 */ 00316 int netdev_boot_setup_add(char *name, struct ifmap *map) 00317 { 00318 struct netdev_boot_setup *s; 00319 int i; 00320 00321 s = dev_boot_setup; 00322 for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { 00323 if (s[i].name[0] == '\0' || s[i].name[0] == ' ') { 00324 memset(s[i].name, 0, sizeof(s[i].name)); 00325 strcpy(s[i].name, name); 00326 memcpy(&s[i].map, map, sizeof(s[i].map)); 00327 break; 00328 } 00329 } 00330 00331 if (i >= NETDEV_BOOT_SETUP_MAX) 00332 return 0; 00333 00334 return 1; 00335 } 00336 00337 /* 00338 * netdev_boot_setup_check - check boot time settings 00339 * @dev: the netdevice 00340 * 00341 * Check boot time settings for the device. 00342 * The found settings are set for the device to be used 00343 * later in the device probing. 00344 * Returns 0 if no settings found, 1 if they are. 00345 */ 00346 int netdev_boot_setup_check(struct net_device *dev) 00347 { 00348 struct netdev_boot_setup *s; 00349 int i; 00350 00351 s = dev_boot_setup; 00352 for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { 00353 if (s[i].name[0] != '\0' && s[i].name[0] != ' ' && 00354 !strncmp(dev->name, s[i].name, strlen(s[i].name))) { 00355 dev->irq = s[i].map.irq; 00356 dev->base_addr = s[i].map.base_addr; 00357 dev->mem_start = s[i].map.mem_start; 00358 dev->mem_end = s[i].map.mem_end; 00359 return 1; 00360 } 00361 } 00362 return 0; 00363 } 00364 00365 /* 00366 * Saves at boot time configured settings for any netdevice. 00367 */ 00368 int __init netdev_boot_setup(char *str) 00369 { 00370 int ints[5]; 00371 struct ifmap map; 00372 00373 str = get_options(str, ARRAY_SIZE(ints), ints); 00374 if (!str || !*str) 00375 return 0; 00376 00377 /* Save settings */ 00378 memset(&map, 0, sizeof(map)); 00379 if (ints[0] > 0) 00380 map.irq = ints[1]; 00381 if (ints[0] > 1) 00382 map.base_addr = ints[2]; 00383 if (ints[0] > 2) 00384 map.mem_start = ints[3]; 00385 if (ints[0] > 3) 00386 map.mem_end = ints[4]; 00387 00388 /* Add new entry to the list */ 00389 return netdev_boot_setup_add(str, &map); 00390 } 00391 00392 __setup("netdev=", netdev_boot_setup); 00393 00394 /***************************************************************************************** 00395 00396 Device Interface Subroutines 00397 00398 ******************************************************************************************/ 00399 00400 /* 00401 * __dev_get_by_name - find a device by its name 00402 * @name: name to find 00403 * 00404 * Find an interface by name. Must be called under RTNL semaphore 00405 * or @dev_base_lock. If the name is found a pointer to the device 00406 * is returned. If the name is not found then %NULL is returned. The 00407 * reference counters are not incremented so the caller must be 00408 * careful with locks. 00409 */ 00410 00411 00412 struct net_device *__dev_get_by_name(const char *name) 00413 { 00414 struct net_device *dev; 00415 00416 for (dev = dev_base; dev != NULL; dev = dev->next) { 00417 if (strncmp(dev->name, name, IFNAMSIZ) == 0) 00418 return dev; 00419 } 00420 return NULL; 00421 } 00422 00423 /* 00424 * dev_get_by_name - find a device by its name 00425 * @name: name to find 00426 * 00427 * Find an interface by name. This can be called from any 00428 * context and does its own locking. The returned handle has 00429 * the usage count incremented and the caller must use dev_put() to 00430 * release it when it is no longer needed. %NULL is returned if no 00431 * matching device is found. 00432 */ 00433 00434 struct net_device *dev_get_by_name(const char *name) 00435 { 00436 struct net_device *dev; 00437 00438 read_lock(&dev_base_lock); 00439 dev = __dev_get_by_name(name); 00440 if (dev) 00441 dev_hold(dev); 00442 read_unlock(&dev_base_lock); 00443 return dev; 00444 } 00445 00446 /* 00447 Return value is changed to int to prevent illegal usage in future. 00448 It is still legal to use to check for device existence. 00449 00450 User should understand, that the result returned by this function 00451 is meaningless, if it was not issued under rtnl semaphore. 00452 */ 00453 00454 /* 00455 * dev_get - test if a device exists 00456 * @name: name to test for 00457 * 00458 * Test if a name exists. Returns true if the name is found. In order 00459 * to be sure the name is not allocated or removed during the test the 00460 * caller must hold the rtnl semaphore. 00461 * 00462 * This function primarily exists for back compatibility with older 00463 * drivers. 00464 */ 00465 00466 int dev_get(const char *name) 00467 { 00468 struct net_device *dev; 00469 00470 read_lock(&dev_base_lock); 00471 dev = __dev_get_by_name(name); 00472 read_unlock(&dev_base_lock); 00473 return dev != NULL; 00474 } 00475 00476 /* 00477 * __dev_get_by_index - find a device by its ifindex 00478 * @ifindex: index of device 00479 * 00480 * Search for an interface by index. Returns %NULL if the device 00481 * is not found or a pointer to the device. The device has not 00482 * had its reference counter increased so the caller must be careful 00483 * about locking. The caller must hold either the RTNL semaphore 00484 * or @dev_base_lock. 00485 */ 00486 00487 struct net_device * __dev_get_by_index(int ifindex) 00488 { 00489 struct net_device *dev; 00490 00491 for (dev = dev_base; dev != NULL; dev = dev->next) { 00492 if (dev->ifindex == ifindex) 00493 return dev; 00494 } 00495 return NULL; 00496 } 00497 00498 00499 /* 00500 * dev_get_by_index - find a device by its ifindex 00501 * @ifindex: index of device 00502 * 00503 * Search for an interface by index. Returns NULL if the device 00504 * is not found or a pointer to the device. The device returned has 00505 * had a reference added and the pointer is safe until the user calls 00506 * dev_put to indicate they have finished with it. 00507 */ 00508 00509 struct net_device * dev_get_by_index(int ifindex) 00510 { 00511 struct net_device *dev; 00512 00513 read_lock(&dev_base_lock); 00514 dev = __dev_get_by_index(ifindex); 00515 if (dev) 00516 dev_hold(dev); 00517 read_unlock(&dev_base_lock); 00518 return dev; 00519 } 00520 00521 /* 00522 * dev_getbyhwaddr - find a device by its hardware address 00523 * @type: media type of device 00524 * @ha: hardware address 00525 * 00526 * Search for an interface by MAC address. Returns NULL if the device 00527 * is not found or a pointer to the device. The caller must hold the 00528 * rtnl semaphore. The returned device has not had its ref count increased 00529 * and the caller must therefore be careful about locking 00530 * 00531 * BUGS: 00532 * If the API was consistent this would be __dev_get_by_hwaddr 00533 */ 00534 00535 struct net_device *dev_getbyhwaddr(unsigned short type, char *ha) 00536 { 00537 struct net_device *dev; 00538 00539 ASSERT_RTNL(); 00540 00541 for (dev = dev_base; dev != NULL; dev = dev->next) { 00542 if (dev->type == type && 00543 memcmp(dev->dev_addr, ha, dev->addr_len) == 0) 00544 return dev; 00545 } 00546 return NULL; 00547 } 00548 00549 /* 00550 * dev_get_by_flags - find any device with given flags 00551 * @if_flags: IFF_* values 00552 * @mask: bitmask of bits in if_flags to check 00553 * 00554 * Search for any interface with the given flags. Returns NULL if a device 00555 * is not found or a pointer to the device. The device returned has 00556 * had a reference added and the pointer is safe until the user calls 00557 * dev_put to indicate they have finished with it. 00558 */ 00559 00560 struct net_device * dev_get_by_flags(unsigned short if_flags, unsigned short mask) 00561 { 00562 struct net_device *dev; 00563 00564 read_lock(&dev_base_lock); 00565 dev = __dev_get_by_flags(if_flags, mask); 00566 if (dev) 00567 dev_hold(dev); 00568 read_unlock(&dev_base_lock); 00569 return dev; 00570 } 00571 00572 /* 00573 * __dev_get_by_flags - find any device with given flags 00574 * @if_flags: IFF_* values 00575 * @mask: bitmask of bits in if_flags to check 00576 * 00577 * Search for any interface with the given flags. Returns NULL if a device 00578 * is not found or a pointer to the device. The caller must hold either 00579 * the RTNL semaphore or @dev_base_lock. 00580 */ 00581 00582 struct net_device *__dev_get_by_flags(unsigned short if_flags, unsigned short mask) 00583 { 00584 struct net_device *dev; 00585 00586 for (dev = dev_base; dev != NULL; dev = dev->next) { 00587 if (((dev->flags ^ if_flags) & mask) == 0) 00588 return dev; 00589 } 00590 return NULL; 00591 } 00592 00593 /* 00594 * dev_alloc_name - allocate a name for a device 00595 * @dev: device 00596 * @name: name format string 00597 * 00598 * Passed a format string - eg "lt%d" it will try and find a suitable 00599 * id. Not efficient for many devices, not called a lot. The caller 00600 * must hold the dev_base or rtnl lock while allocating the name and 00601 * adding the device in order to avoid duplicates. Returns the number 00602 * of the unit assigned or a negative errno code. 00603 */ 00604 00605 int dev_alloc_name(struct net_device *dev, const char *name) 00606 { 00607 int i; 00608 char buf[32]; 00609 char *p; 00610 00611 /* 00612 * Verify the string as this thing may have come from 00613 * the user. There must be either one "%d" and no other "%" 00614 * characters, or no "%" characters at all. 00615 */ 00616 p = strchr(name, '%'); 00617 if (p && (p[1] != 'd' || strchr(p+2, '%'))) 00618 return -EINVAL; 00619 00620 /* 00621 * If you need over 100 please also fix the algorithm... 00622 */ 00623 for (i = 0; i < 100; i++) { 00624 snprintf(buf,sizeof(buf),name,i); 00625 if (__dev_get_by_name(buf) == NULL) { 00626 strcpy(dev->name, buf); 00627 return i; 00628 } 00629 } 00630 return -ENFILE; /* Over 100 of the things .. bail out! */ 00631 } 00632 00633 /* 00634 * dev_alloc - allocate a network device and name 00635 * @name: name format string 00636 * @err: error return pointer 00637 * 00638 * Passed a format string, eg. "lt%d", it will allocate a network device 00639 * and space for the name. %NULL is returned if no memory is available. 00640 * If the allocation succeeds then the name is assigned and the 00641 * device pointer returned. %NULL is returned if the name allocation 00642 * failed. The cause of an error is returned as a negative errno code 00643 * in the variable @err points to. 00644 * 00645 * The caller must hold the @dev_base or RTNL locks when doing this in 00646 * order to avoid duplicate name allocations. 00647 */ 00648 00649 struct net_device *dev_alloc(const char *name, int *err) 00650 { 00651 struct net_device *dev=kmalloc(sizeof(struct net_device), GFP_KERNEL); 00652 if (dev == NULL) { 00653 *err = -ENOBUFS; 00654 return NULL; 00655 } 00656 memset(dev, 0, sizeof(struct net_device)); 00657 *err = dev_alloc_name(dev, name); 00658 if (*err < 0) { 00659 kfree(dev); 00660 return NULL; 00661 } 00662 return dev; 00663 } 00664 00665 /* 00666 * netdev_state_change - device changes state 00667 * @dev: device to cause notification 00668 * 00669 * Called to indicate a device has changed state. This function calls 00670 * the notifier chains for netdev_chain and sends a NEWLINK message 00671 * to the routing socket. 00672 */ 00673 00674 void netdev_state_change(struct net_device *dev) 00675 { 00676 if (dev->flags&IFF_UP) { 00677 notifier_call_chain(&netdev_chain, NETDEV_CHANGE, dev); 00678 rtmsg_ifinfo(RTM_NEWLINK, dev, 0); 00679 } 00680 } 00681 00682 00683 #ifdef CONFIG_KMOD 00684 00685 /* 00686 * dev_load - load a network module 00687 * @name: name of interface 00688 * 00689 * If a network interface is not present and the process has suitable 00690 * privileges this function loads the module. If module loading is not 00691 * available in this kernel then it becomes a nop. 00692 */ 00693 00694 void dev_load(const char *name) 00695 { 00696 if (!dev_get(name) && capable(CAP_SYS_MODULE)) 00697 request_module(name); 00698 } 00699 00700 #else 00701 00702 extern inline void dev_load(const char *unused){;} 00703 00704 #endif 00705 00706 static int default_rebuild_header(struct sk_buff *skb) 00707 { 00708 printk(KERN_DEBUG "%s: default_rebuild_header called -- BUG!\n", skb->dev ? skb->dev->name : "NULL!!!"); 00709 kfree_skb(skb); 00710 return 1; 00711 } 00712 00713 /* 00714 * dev_open - prepare an interface for use. 00715 * @dev: device to open 00716 * 00717 * Takes a device from down to up state. The device's private open 00718 * function is invoked and then the multicast lists are loaded. Finally 00719 * the device is moved into the up state and a %NETDEV_UP message is 00720 * sent to the netdev notifier chain. 00721 * 00722 * Calling this function on an active interface is a nop. On a failure 00723 * a negative errno code is returned. 00724 */ 00725 00726 int dev_open(struct net_device *dev) 00727 { 00728 int ret = 0; 00729 00730 /* 00731 * Is it already up? 00732 */ 00733 00734 if (dev->flags&IFF_UP) 00735 return 0; 00736 00737 /* 00738 * Is it even present? 00739 */ 00740 if (!netif_device_present(dev)) 00741 return -ENODEV; 00742 00743 /* 00744 * Call device private open method 00745 */ 00746 if (try_inc_mod_count(dev->owner)) { 00747 set_bit(__LINK_STATE_START, &dev->state); 00748 if (dev->open) { 00749 ret = dev->open(dev); 00750 if (ret != 0) { 00751 clear_bit(__LINK_STATE_START, &dev->state); 00752 if (dev->owner) 00753 __MOD_DEC_USE_COUNT(dev->owner); 00754 } 00755 } 00756 } else { 00757 ret = -ENODEV; 00758 } 00759 00760 /* 00761 * If it went open OK then: 00762 */ 00763 00764 if (ret == 0) 00765 { 00766 /* 00767 * Set the flags. 00768 */ 00769 dev->flags |= IFF_UP; 00770 00771 /* 00772 * Initialize multicasting status 00773 */ 00774 dev_mc_upload(dev); 00775 00776 /* 00777 * Wakeup transmit queue engine 00778 */ 00779 dev_activate(dev); 00780 00781 /* 00782 * ... and announce new interface. 00783 */ 00784 notifier_call_chain(&netdev_chain, NETDEV_UP, dev); 00785 } 00786 return(ret); 00787 } 00788 00789 #ifdef CONFIG_NET_FASTROUTE 00790 00791 static void dev_do_clear_fastroute(struct net_device *dev) 00792 { 00793 if (dev->accept_fastpath) { 00794 int i; 00795 00796 for (i=0; i<=NETDEV_FASTROUTE_HMASK; i++) { 00797 struct dst_entry *dst; 00798 00799 write_lock_irq(&dev->fastpath_lock); 00800 dst = dev->fastpath[i]; 00801 dev->fastpath[i] = NULL; 00802 write_unlock_irq(&dev->fastpath_lock); 00803 00804 dst_release(dst); 00805 } 00806 } 00807 } 00808 00809 void dev_clear_fastroute(struct net_device *dev) 00810 { 00811 if (dev) { 00812 dev_do_clear_fastroute(dev); 00813 } else { 00814 read_lock(&dev_base_lock); 00815 for (dev = dev_base; dev; dev = dev->next) 00816 dev_do_clear_fastroute(dev); 00817 read_unlock(&dev_base_lock); 00818 } 00819 } 00820 #endif 00821 00822 /* 00823 * dev_close - shutdown an interface. 00824 * @dev: device to shutdown 00825 * 00826 * This function moves an active device into down state. A 00827 * %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device 00828 * is then deactivated and finally a %NETDEV_DOWN is sent to the notifier 00829 * chain. 00830 */ 00831 00832 int dev_close(struct net_device *dev) 00833 { 00834 if (!(dev->flags&IFF_UP)) 00835 return 0; 00836 00837 /* 00838 * Tell people we are going down, so that they can 00839 * prepare to death, when device is still operating. 00840 */ 00841 notifier_call_chain(&netdev_chain, NETDEV_GOING_DOWN, dev); 00842 00843 dev_deactivate(dev); 00844 00845 clear_bit(__LINK_STATE_START, &dev->state); 00846 00847 /* Synchronize to scheduled poll. We cannot touch poll list, 00848 * it can be even on different cpu. So just clear netif_running(), 00849 * and wait when poll really will happen. Actually, the best place 00850 * for this is inside dev->stop() after device stopped its irq 00851 * engine, but this requires more changes in devices. */ 00852 00853 smp_mb__after_clear_bit(); /* Commit netif_running(). */ 00854 while (test_bit(__LINK_STATE_RX_SCHED, &dev->state)) { 00855 /* No hurry. */ 00856 current->state = TASK_INTERRUPTIBLE; 00857 schedule_timeout(1); 00858 } 00859 00860 /* 00861 * Call the device specific close. This cannot fail. 00862 * Only if device is UP 00863 * 00864 * We allow it to be called even after a DETACH hot-plug 00865 * event. 00866 */ 00867 00868 if (dev->stop) 00869 dev->stop(dev); 00870 00871 /* 00872 * Device is now down. 00873 */ 00874 00875 dev->flags &= ~IFF_UP; 00876 #ifdef CONFIG_NET_FASTROUTE 00877 dev_clear_fastroute(dev); 00878 #endif 00879 00880 /* 00881 * Tell people we are down 00882 */ 00883 notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev); 00884 00885 /* 00886 * Drop the module refcount 00887 */ 00888 if (dev->owner) 00889 __MOD_DEC_USE_COUNT(dev->owner); 00890 00891 return(0); 00892 } 00893 00894 00895 /* 00896 * Device change register/unregister. These are not inline or static 00897 * as we export them to the world. 00898 */ 00899 00900 /* 00901 * register_netdevice_notifier - register a network notifier block 00902 * @nb: notifier 00903 * 00904 * Register a notifier to be called when network device events occur. 00905 * The notifier passed is linked into the kernel structures and must 00906 * not be reused until it has been unregistered. A negative errno code 00907 * is returned on a failure. 00908 */ 00909 00910 int register_netdevice_notifier(struct notifier_block *nb) 00911 { 00912 return notifier_chain_register(&netdev_chain, nb); 00913 } 00914 00915 /* 00916 * unregister_netdevice_notifier - unregister a network notifier block 00917 * @nb: notifier 00918 * 00919 * Unregister a notifier previously registered by 00920 * register_netdevice_notifier(). The notifier is unlinked into the 00921 * kernel structures and may then be reused. A negative errno code 00922 * is returned on a failure. 00923 */ 00924 00925 int unregister_netdevice_notifier(struct notifier_block *nb) 00926 { 00927 return notifier_chain_unregister(&netdev_chain,nb); 00928 } 00929 00930 /* 00931 * Support routine. Sends outgoing frames to any network 00932 * taps currently in use. 00933 */ 00934 00935 void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) 00936 { 00937 struct packet_type *ptype; 00938 do_gettimeofday(&skb->stamp); 00939 00940 br_read_lock(BR_NETPROTO_LOCK); 00941 for (ptype = ptype_all; ptype!=NULL; ptype = ptype->next) 00942 { 00943 /* Never send packets back to the socket 00944 * they originated from - MvS (miquels@drinkel.ow.org) 00945 */ 00946 if ((ptype->dev == dev || !ptype->dev) && 00947 ((struct sock *)ptype->data != skb->sk)) 00948 { 00949 struct sk_buff *skb2; 00950 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL) 00951 break; 00952 00953 /* skb->nh should be correctly 00954 set by sender, so that the second statement is 00955 just protection against buggy protocols. 00956 */ 00957 skb2->mac.raw = skb2->data; 00958 00959 if (skb2->nh.raw < skb2->data || skb2->nh.raw > skb2->tail) { 00960 if (net_ratelimit()) 00961 printk(KERN_CRIT "protocol %04x is buggy, dev %s\n", skb2->protocol, dev->name); 00962 skb2->nh.raw = skb2->data; 00963 } 00964 00965 skb2->h.raw = skb2->nh.raw; 00966 skb2->pkt_type = PACKET_OUTGOING; 00967 ptype->func(skb2, skb->dev, ptype); 00968 } 00969 } 00970 br_read_unlock(BR_NETPROTO_LOCK); 00971 } 00972 00973 /* Calculate csum in the case, when packet is misrouted. 00974 * If it failed by some reason, ignore and send skb with wrong 00975 * checksum. 00976 */ 00977 struct sk_buff * skb_checksum_help(struct sk_buff *skb) 00978 { 00979 int offset; 00980 unsigned int csum; 00981 00982 offset = skb->h.raw - skb->data; 00983 if (offset > (int)skb->len) 00984 BUG(); 00985 csum = skb_checksum(skb, offset, skb->len-offset, 0); 00986 00987 offset = skb->tail - skb->h.raw; 00988 if (offset <= 0) 00989 BUG(); 00990 if (skb->csum+2 > offset) 00991 BUG(); 00992 00993 *(u16*)(skb->h.raw + skb->csum) = csum_fold(csum); 00994 skb->ip_summed = CHECKSUM_NONE; 00995 return skb; 00996 } 00997 00998 #ifdef CONFIG_HIGHMEM 00999 /* Actually, we should eliminate this check as soon as we know, that: 01000 * 1. IOMMU is present and allows to map all the memory. 01001 * 2. No high memory really exists on this machine. 01002 */ 01003 01004 static inline int 01005 illegal_highdma(struct net_device *dev, struct sk_buff *skb) 01006 { 01007 int i; 01008 01009 if (dev->features&NETIF_F_HIGHDMA) 01010 return 0; 01011 01012 for (i=0; i<skb_shinfo(skb)->nr_frags; i++) 01013 if (skb_shinfo(skb)->frags[i].page >= highmem_start_page) 01014 return 1; 01015 01016 return 0; 01017 } 01018 #else 01019 #define illegal_highdma(dev, skb) (0) 01020 #endif 01021 01022 /* 01023 * dev_queue_xmit - transmit a buffer 01024 * @skb: buffer to transmit 01025 * 01026 * Queue a buffer for transmission to a network device. The caller must 01027 * have set the device and priority and built the buffer before calling this 01028 * function. The function can be called from an interrupt. 01029 * 01030 * A negative errno code is returned on a failure. A success does not 01031 * guarantee the frame will be transmitted as it may be dropped due 01032 * to congestion or traffic shaping. 01033 */ 01034 01035 int dev_queue_xmit(struct sk_buff *skb) 01036 { 01037 struct net_device *dev = skb->dev; 01038 struct Qdisc *q; 01039 01040 if (skb_shinfo(skb)->frag_list && 01041 !(dev->features&NETIF_F_FRAGLIST) && 01042 skb_linearize(skb, GFP_ATOMIC) != 0) { 01043 kfree_skb(skb); 01044 return -ENOMEM; 01045 } 01046 01047 /* Fragmented skb is linearized if device does not support SG, 01048 * or if at least one of fragments is in highmem and device 01049 * does not support DMA from it. 01050 */ 01051 if (skb_shinfo(skb)->nr_frags && 01052 (!(dev->features&NETIF_F_SG) || illegal_highdma(dev, skb)) && 01053 skb_linearize(skb, GFP_ATOMIC) != 0) { 01054 kfree_skb(skb); 01055 return -ENOMEM; 01056 } 01057 01058 /* If packet is not checksummed and device does not support 01059 * checksumming for this protocol, complete checksumming here. 01060 */ 01061 if (skb->ip_summed == CHECKSUM_HW && 01062 (!(dev->features&(NETIF_F_HW_CSUM|NETIF_F_NO_CSUM)) && 01063 (!(dev->features&NETIF_F_IP_CSUM) || 01064 skb->protocol != htons(ETH_P_IP)))) { 01065 if ((skb = skb_checksum_help(skb)) == NULL) 01066 return -ENOMEM; 01067 } 01068 01069 /* Grab device queue */ 01070 spin_lock_bh(&dev->queue_lock); 01071 q = dev->qdisc; 01072 if (q->enqueue) { 01073 int ret = q->enqueue(skb, q); 01074 01075 qdisc_run(dev); 01076 01077 spin_unlock_bh(&dev->queue_lock); 01078 return ret == NET_XMIT_BYPASS ? NET_XMIT_SUCCESS : ret; 01079 } 01080 01081 /* The device has no queue. Common case for software devices: 01082 loopback, all the sorts of tunnels... 01083 01084 Really, it is unlikely that xmit_lock protection is necessary here. 01085 (f.e. loopback and IP tunnels are clean ignoring statistics counters.) 01086 However, it is possible, that they rely on protection 01087 made by us here. 01088 01089 Check this and shot the lock. It is not prone from deadlocks. 01090 Either shot noqueue qdisc, it is even simpler 8) 01091 */ 01092 if (dev->flags&IFF_UP) { 01093 int cpu = smp_processor_id(); 01094 01095 if (dev->xmit_lock_owner != cpu) { 01096 spin_unlock(&dev->queue_lock); 01097 spin_lock(&dev->xmit_lock); 01098 dev->xmit_lock_owner = cpu; 01099 01100 if (!netif_queue_stopped(dev)) { 01101 if (netdev_nit) 01102 dev_queue_xmit_nit(skb,dev); 01103 01104 if (dev->hard_start_xmit(skb, dev) == 0) { 01105 dev->xmit_lock_owner = -1; 01106 spin_unlock_bh(&dev->xmit_lock); 01107 return 0; 01108 } 01109 } 01110 dev->xmit_lock_owner = -1; 01111 spin_unlock_bh(&dev->xmit_lock); 01112 if (net_ratelimit()) 01113 printk(KERN_CRIT "Virtual device %s asks to queue packet!\n", dev->name); 01114 kfree_skb(skb); 01115 return -ENETDOWN; 01116 } else { 01117 /* Recursion is detected! It is possible, unfortunately */ 01118 if (net_ratelimit()) 01119 printk(KERN_CRIT "Dead loop on virtual device %s, fix it urgently!\n", dev->name); 01120 } 01121 } 01122 spin_unlock_bh(&dev->queue_lock); 01123 01124 kfree_skb(skb); 01125 return -ENETDOWN; 01126 } 01127 01128 01129 /*======================================================================= 01130 Receiver routines 01131 =======================================================================*/ 01132 01133 int netdev_max_backlog = 300; 01134 int weight_p = 64; /* old backlog weight */ 01135 /* These numbers are selected based on intuition and some 01136 * experimentatiom, if you have more scientific way of doing this 01137 * please go ahead and fix things. 01138 */ 01139 int no_cong_thresh = 10; 01140 int no_cong = 20; 01141 int lo_cong = 100; 01142 int mod_cong = 290; 01143 01144 struct netif_rx_stats netdev_rx_stat[NR_CPUS]; 01145 01146 01147 #ifdef CONFIG_NET_HW_FLOWCONTROL 01148 atomic_t netdev_dropping = ATOMIC_INIT(0); 01149 static unsigned long netdev_fc_mask = 1; 01150 unsigned long netdev_fc_xoff = 0; 01151 spinlock_t netdev_fc_lock = SPIN_LOCK_UNLOCKED; 01152 01153 static struct 01154 { 01155 void (*stimul)(struct net_device *); 01156 struct net_device *dev; 01157 } netdev_fc_slots[BITS_PER_LONG]; 01158 01159 int netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev)) 01160 { 01161 int bit = 0; 01162 unsigned long flags; 01163 01164 spin_lock_irqsave(&netdev_fc_lock, flags); 01165 if (netdev_fc_mask != ~0UL) { 01166 bit = ffz(netdev_fc_mask); 01167 netdev_fc_slots[bit].stimul = stimul; 01168 netdev_fc_slots[bit].dev = dev; 01169 set_bit(bit, &netdev_fc_mask); 01170 clear_bit(bit, &netdev_fc_xoff); 01171 } 01172 spin_unlock_irqrestore(&netdev_fc_lock, flags); 01173 return bit; 01174 } 01175 01176 void netdev_unregister_fc(int bit) 01177 { 01178 unsigned long flags; 01179 01180 spin_lock_irqsave(&netdev_fc_lock, flags); 01181 if (bit > 0) { 01182 netdev_fc_slots[bit].stimul = NULL; 01183 netdev_fc_slots[bit].dev = NULL; 01184 clear_bit(bit, &netdev_fc_mask); 01185 clear_bit(bit, &netdev_fc_xoff); 01186 } 01187 spin_unlock_irqrestore(&netdev_fc_lock, flags); 01188 } 01189 01190 static void netdev_wakeup(void) 01191 { 01192 unsigned long xoff; 01193 01194 spin_lock(&netdev_fc_lock); 01195 xoff = netdev_fc_xoff; 01196 netdev_fc_xoff = 0; 01197 while (xoff) { 01198 int i = ffz(~xoff); 01199 xoff &= ~(1<<i); 01200 netdev_fc_slots[i].stimul(netdev_fc_slots[i].dev); 01201 } 01202 spin_unlock(&netdev_fc_lock); 01203 } 01204 #endif 01205 01206 static void get_sample_stats(int cpu) 01207 { 01208 #ifdef RAND_LIE 01209 unsigned long rd; 01210 int rq; 01211 #endif 01212 int blog = softnet_data[cpu].input_pkt_queue.qlen; 01213 int avg_blog = softnet_data[cpu].avg_blog; 01214 01215 avg_blog = (avg_blog >> 1)+ (blog >> 1); 01216 01217 if (avg_blog > mod_cong) { 01218 /* Above moderate congestion levels. */ 01219 softnet_data[cpu].cng_level = NET_RX_CN_HIGH; 01220 #ifdef RAND_LIE 01221 rd = net_random(); 01222 rq = rd % netdev_max_backlog; 01223 if (rq < avg_blog) /* unlucky bastard */ 01224 softnet_data[cpu].cng_level = NET_RX_DROP; 01225 #endif 01226 } else if (avg_blog > lo_cong) { 01227 softnet_data[cpu].cng_level = NET_RX_CN_MOD; 01228 #ifdef RAND_LIE 01229 rd = net_random(); 01230 rq = rd % netdev_max_backlog; 01231 if (rq < avg_blog) /* unlucky bastard */ 01232 softnet_data[cpu].cng_level = NET_RX_CN_HIGH; 01233 #endif 01234 } else if (avg_blog > no_cong) 01235 softnet_data[cpu].cng_level = NET_RX_CN_LOW; 01236 else /* no congestion */ 01237 softnet_data[cpu].cng_level = NET_RX_SUCCESS; 01238 01239 softnet_data[cpu].avg_blog = avg_blog; 01240 } 01241 01242 #ifdef OFFLINE_SAMPLE 01243 static void sample_queue(unsigned long dummy) 01244 { 01245 /* 10 ms 0r 1ms -- i dont care -- JHS */ 01246 int next_tick = 1; 01247 int cpu = smp_processor_id(); 01248 01249 get_sample_stats(cpu); 01250 next_tick += jiffies; 01251 mod_timer(&samp_timer, next_tick); 01252 } 01253 #endif 01254 01255 01256 /* 01257 * netif_rx - post buffer to the network code 01258 * @skb: buffer to post 01259 * 01260 * This function receives a packet from a device driver and queues it for 01261 * the upper (protocol) levels to process. It always succeeds. The buffer 01262 * may be dropped during processing for congestion control or by the 01263 * protocol layers. 01264 * 01265 * return values: 01266 * NET_RX_SUCCESS (no congestion) 01267 * NET_RX_CN_LOW (low congestion) 01268 * NET_RX_CN_MOD (moderate congestion) 01269 * NET_RX_CN_HIGH (high congestion) 01270 * NET_RX_DROP (packet was dropped) 01271 * 01272 * 01273 */ 01274 01275 int netif_rx(struct sk_buff *skb) 01276 { 01277 int this_cpu = smp_processor_id(); 01278 struct softnet_data *queue; 01279 unsigned long flags; 01280 01281 if (skb->stamp.tv_sec == 0) 01282 do_gettimeofday(&skb->stamp); 01283 01284 /* The code is rearranged so that the path is the most 01285 short when CPU is congested, but is still operating. 01286 */ 01287 queue = &softnet_data[this_cpu]; 01288 01289 local_irq_save(flags); 01290 01291 netdev_rx_stat[this_cpu].total++; 01292 if (queue->input_pkt_queue.qlen <= netdev_max_backlog) { 01293 if (queue->input_pkt_queue.qlen) { 01294 if (queue->throttle) 01295 goto drop; 01296 01297 enqueue: 01298 dev_hold(skb->dev); 01299 __skb_queue_tail(&queue->input_pkt_queue,skb); 01300 local_irq_restore(flags); 01301 #ifndef OFFLINE_SAMPLE 01302 get_sample_stats(this_cpu); 01303 #endif 01304 return queue->cng_level; 01305 } 01306 01307 if (queue->throttle) { 01308 queue->throttle = 0; 01309 #ifdef CONFIG_NET_HW_FLOWCONTROL 01310 if (atomic_dec_and_test(&netdev_dropping)) 01311 netdev_wakeup(); 01312 #endif 01313 } 01314 01315 netif_rx_schedule(&queue->blog_dev); 01316 goto enqueue; 01317 } 01318 01319 if (queue->throttle == 0) { 01320 queue->throttle = 1; 01321 netdev_rx_stat[this_cpu].throttled++; 01322 #ifdef CONFIG_NET_HW_FLOWCONTROL 01323 atomic_inc(&netdev_dropping); 01324 #endif 01325 } 01326 01327 drop: 01328 netdev_rx_stat[this_cpu].dropped++; 01329 local_irq_restore(flags); 01330 01331 kfree_skb(skb); 01332 return NET_RX_DROP; 01333 } 01334 01335 /* Deliver skb to an old protocol, which is not threaded well 01336 or which do not understand shared skbs. 01337 */ 01338 static int deliver_to_old_ones(struct packet_type *pt, struct sk_buff *skb, int last) 01339 { 01340 static spinlock_t net_bh_lock = SPIN_LOCK_UNLOCKED; 01341 int ret = NET_RX_DROP; 01342 01343 01344 if (!last) { 01345 skb = skb_clone(skb, GFP_ATOMIC); 01346 if (skb == NULL) 01347 return ret; 01348 } 01349 if (skb_is_nonlinear(skb) && skb_linearize(skb, GFP_ATOMIC) != 0) { 01350 kfree_skb(skb); 01351 return ret; 01352 } 01353 01354 /* The assumption (correct one) is that old protocols 01355 did not depened on BHs different of NET_BH and TIMER_BH. 01356 */ 01357 01358 /* Emulate NET_BH with special spinlock */ 01359 spin_lock(&net_bh_lock); 01360 01361 /* Disable timers and wait for all timers completion */ 01362 tasklet_disable(bh_task_vec+TIMER_BH); 01363 01364 ret = pt->func(skb, skb->dev, pt); 01365 01366 tasklet_hi_enable(bh_task_vec+TIMER_BH); 01367 spin_unlock(&net_bh_lock); 01368 return ret; 01369 } 01370 01371 static __inline__ void skb_bond(struct sk_buff *skb) 01372 { 01373 struct net_device *dev = skb->dev; 01374 01375 if (dev->master) { 01376 skb->real_dev = skb->dev; 01377 skb->dev = dev->master; 01378 } 01379 } 01380 01381 static void net_tx_action(struct softirq_action *h) 01382 { 01383 int cpu = smp_processor_id(); 01384 01385 if (softnet_data[cpu].completion_queue) { 01386 struct sk_buff *clist; 01387 01388 local_irq_disable(); 01389 clist = softnet_data[cpu].completion_queue; 01390 softnet_data[cpu].completion_queue = NULL; 01391 local_irq_enable(); 01392 01393 while (clist != NULL) { 01394 struct sk_buff *skb = clist; 01395 clist = clist->next; 01396 01397 BUG_TRAP(atomic_read(&skb->users) == 0); 01398 __kfree_skb(skb); 01399 } 01400 } 01401 01402 if (softnet_data[cpu].output_queue) { 01403 struct net_device *head; 01404 01405 local_irq_disable(); 01406 head = softnet_data[cpu].output_queue; 01407 softnet_data[cpu].output_queue = NULL; 01408 local_irq_enable(); 01409 01410 while (head != NULL) { 01411 struct net_device *dev = head; 01412 head = head->next_sched; 01413 01414 smp_mb__before_clear_bit(); 01415 clear_bit(__LINK_STATE_SCHED, &dev->state); 01416 01417 if (spin_trylock(&dev->queue_lock)) { 01418 qdisc_run(dev); 01419 spin_unlock(&dev->queue_lock); 01420 } else { 01421 netif_schedule(dev); 01422 } 01423 } 01424 } 01425 } 01426 01427 01428 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) 01429 void (*br_handle_frame_hook)(struct sk_buff *skb) = NULL; 01430 #endif 01431 01432 static __inline__ int handle_bridge(struct sk_buff *skb, 01433 struct packet_type *pt_prev) 01434 { 01435 int ret = NET_RX_DROP; 01436 01437 if (pt_prev) { 01438 if (!pt_prev->data) 01439 ret = deliver_to_old_ones(pt_prev, skb, 0); 01440 else { 01441 atomic_inc(&skb->users); 01442 ret = pt_prev->func(skb, skb->dev, pt_prev); 01443 } 01444 } 01445 01446 br_handle_frame_hook(skb); 01447 return ret; 01448 } 01449 01450 01451 #ifdef CONFIG_NET_DIVERT 01452 static inline int handle_diverter(struct sk_buff *skb) 01453 { 01454 /* if diversion is supported on device, then divert */ 01455 if (skb->dev->divert && skb->dev->divert->divert) 01456 divert_frame(skb); 01457 return 0; 01458 } 01459 #endif /* CONFIG_NET_DIVERT */ 01460 01461 int netif_receive_skb(struct sk_buff *skb) 01462 { 01463 struct packet_type *ptype, *pt_prev; 01464 int ret = NET_RX_DROP; 01465 unsigned short type = skb->protocol; 01466 01467 if (skb->stamp.tv_sec == 0) 01468 do_gettimeofday(&skb->stamp); 01469 01470 skb_bond(skb); 01471 01472 netdev_rx_stat[smp_processor_id()].total++; 01473 01474 #ifdef CONFIG_NET_FASTROUTE 01475 if (skb->pkt_type == PACKET_FASTROUTE) { 01476 netdev_rx_stat[smp_processor_id()].fastroute_deferred_out++; 01477 return dev_queue_xmit(skb); 01478 } 01479 #endif 01480 01481 skb->h.raw = skb->nh.raw = skb->data; 01482 01483 pt_prev = NULL; 01484 for (ptype = ptype_all; ptype; ptype = ptype->next) { 01485 if (!ptype->dev || ptype->dev == skb->dev) { 01486 if (pt_prev) { 01487 if (!pt_prev->data) { 01488 ret = deliver_to_old_ones(pt_prev, skb, 0); 01489 } else { 01490 atomic_inc(&skb->users); 01491 ret = pt_prev->func(skb, skb->dev, pt_prev); 01492 } 01493 } 01494 pt_prev = ptype; 01495 } 01496 } 01497 01498 #ifdef CONFIG_NET_DIVERT 01499 if (skb->dev->divert && skb->dev->divert->divert) 01500 ret = handle_diverter(skb); 01501 #endif /* CONFIG_NET_DIVERT */ 01502 01503 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) 01504 if (skb->dev->br_port != NULL && 01505 br_handle_frame_hook != NULL) { 01506 return handle_bridge(skb, pt_prev); 01507 } 01508 #endif 01509 01510 for (ptype=ptype_base[ntohs(type)&15];ptype;ptype=ptype->next) { 01511 if (ptype->type == type && 01512 (!ptype->dev || ptype->dev == skb->dev)) { 01513 if (pt_prev) { 01514 if (!pt_prev->data) { 01515 ret = deliver_to_old_ones(pt_prev, skb, 0); 01516 } else { 01517 atomic_inc(&skb->users); 01518 ret = pt_prev->func(skb, skb->dev, pt_prev); 01519 } 01520 } 01521 pt_prev = ptype; 01522 } 01523 } 01524 01525 if (pt_prev) { 01526 if (!pt_prev->data) { 01527 ret = deliver_to_old_ones(pt_prev, skb, 1); 01528 } else { 01529 ret = pt_prev->func(skb, skb->dev, pt_prev); 01530 } 01531 } else { 01532 kfree_skb(skb); 01533 /* Jamal, now you will not able to escape explaining 01534 * me how you were going to use this. :-) 01535 */ 01536 ret = NET_RX_DROP; 01537 } 01538 01539 return ret; 01540 } 01541 01542 static int process_backlog(struct net_device *backlog_dev, int *budget) 01543 { 01544 int work = 0; 01545 int quota = min(backlog_dev->quota, *budget); 01546 int this_cpu = smp_processor_id(); 01547 struct softnet_data *queue = &softnet_data[this_cpu]; 01548 unsigned long start_time = jiffies; 01549 01550 for (;;) { 01551 struct sk_buff *skb; 01552 struct net_device *dev; 01553 01554 local_irq_disable(); 01555 skb = __skb_dequeue(&queue->input_pkt_queue); 01556 if (skb == NULL) 01557 goto job_done; 01558 local_irq_enable(); 01559 01560 dev = skb->dev; 01561 01562 netif_receive_skb(skb); 01563 01564 dev_put(dev); 01565 01566 work++; 01567 01568 if (work >= quota || jiffies - start_time > 1) 01569 break; 01570 01571 #ifdef CONFIG_NET_HW_FLOWCONTROL 01572 if (queue->throttle && queue->input_pkt_queue.qlen < no_cong_thresh ) { 01573 queue->throttle = 0; 01574 if (atomic_dec_and_test(&netdev_dropping)) { 01575 netdev_wakeup(); 01576 break; 01577 } 01578 } 01579 #endif 01580 } 01581 01582 backlog_dev->quota -= work; 01583 *budget -= work; 01584 return -1; 01585 01586 job_done: 01587 backlog_dev->quota -= work; 01588 *budget -= work; 01589 01590 list_del(&backlog_dev->poll_list); 01591 smp_mb__before_clear_bit(); 01592 netif_poll_enable(backlog_dev); 01593 01594 if (queue->throttle) { 01595 queue->throttle = 0; 01596 #ifdef CONFIG_NET_HW_FLOWCONTROL 01597 if (atomic_dec_and_test(&netdev_dropping)) 01598 netdev_wakeup(); 01599 #endif 01600 } 01601 local_irq_enable(); 01602 return 0; 01603 } 01604 01605 static void net_rx_action(struct softirq_action *h) 01606 { 01607 int this_cpu = smp_processor_id(); 01608 struct softnet_data *queue = &softnet_data[this_cpu]; 01609 unsigned long start_time = jiffies; 01610 int budget = netdev_max_backlog; 01611 01612 br_read_lock(BR_NETPROTO_LOCK); 01613 local_irq_disable(); 01614 01615 while (!list_empty(&queue->poll_list)) { 01616 struct net_device *dev; 01617 01618 if (budget <= 0 || jiffies - start_time > 1) 01619 goto softnet_break; 01620 01621 local_irq_enable(); 01622 01623 dev = list_entry(queue->poll_list.next, struct net_device, poll_list); 01624 01625 if (dev->quota <= 0 || dev->poll(dev, &budget)) { 01626 local_irq_disable(); 01627 list_del(&dev->poll_list); 01628 list_add_tail(&dev->poll_list, &queue->poll_list); 01629 if (dev->quota < 0) 01630 dev->quota += dev->weight; 01631 else 01632 dev->quota = dev->weight; 01633 } else { 01634 dev_put(dev); 01635 local_irq_disable(); 01636 } 01637 } 01638 01639 local_irq_enable(); 01640 br_read_unlock(BR_NETPROTO_LOCK); 01641 return; 01642 01643 softnet_break: 01644 netdev_rx_stat[this_cpu].time_squeeze++; 01645 __cpu_raise_softirq(this_cpu, NET_RX_SOFTIRQ); 01646 01647 local_irq_enable(); 01648 br_read_unlock(BR_NETPROTO_LOCK); 01649 } 01650 01651 static gifconf_func_t * gifconf_list [NPROTO]; 01652 01653 /* 01654 * register_gifconf - register a SIOCGIF handler 01655 * @family: Address family 01656 * @gifconf: Function handler 01657 * 01658 * Register protocol dependent address dumping routines. The handler 01659 * that is passed must not be freed or reused until it has been replaced 01660 * by another handler. 01661 */ 01662 01663 int register_gifconf(unsigned int family, gifconf_func_t * gifconf) 01664 { 01665 if (family>=NPROTO) 01666 return -EINVAL; 01667 gifconf_list[family] = gifconf; 01668 return 0; 01669 } 01670 01671 01672 /* 01673 * Map an interface index to its name (SIOCGIFNAME) 01674 */ 01675 01676 /* 01677 * We need this ioctl for efficient implementation of the 01678 * if_indextoname() function required by the IPv6 API. Without 01679 * it, we would have to search all the interfaces to find a 01680 * match. --pb 01681 */ 01682 01683 static int dev_ifname(struct ifreq *arg) 01684 { 01685 struct net_device *dev; 01686 struct ifreq ifr; 01687 01688 /* 01689 * Fetch the caller's info block. 01690 */ 01691 01692 if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) 01693 return -EFAULT; 01694 01695 read_lock(&dev_base_lock); 01696 dev = __dev_get_by_index(ifr.ifr_ifindex); 01697 if (!dev) { 01698 read_unlock(&dev_base_lock); 01699 return -ENODEV; 01700 } 01701 01702 strcpy(ifr.ifr_name, dev->name); 01703 read_unlock(&dev_base_lock); 01704 01705 if (copy_to_user(arg, &ifr, sizeof(struct ifreq))) 01706 return -EFAULT; 01707 return 0; 01708 } 01709 01710 /* 01711 * Perform a SIOCGIFCONF call. This structure will change 01712 * size eventually, and there is nothing I can do about it. 01713 * Thus we will need a 'compatibility mode'. 01714 */ 01715 01716 static int dev_ifconf(char *arg) 01717 { 01718 struct ifconf ifc; 01719 struct net_device *dev; 01720 char *pos; 01721 int len; 01722 int total; 01723 int i; 01724 01725 /* 01726 * Fetch the caller's info block. 01727 */ 01728 01729 if (copy_from_user(&ifc, arg, sizeof(struct ifconf))) 01730 return -EFAULT; 01731 01732 pos = ifc.ifc_buf; 01733 len = ifc.ifc_len; 01734 01735 /* 01736 * Loop over the interfaces, and write an info block for each. 01737 */ 01738 01739 total = 0; 01740 for (dev = dev_base; dev != NULL; dev = dev->next) { 01741 for (i=0; i<NPROTO; i++) { 01742 if (gifconf_list[i]) { 01743 int done; 01744 if (pos==NULL) { 01745 done = gifconf_list[i](dev, NULL, 0); 01746 } else { 01747 done = gifconf_list[i](dev, pos+total, len-total); 01748 } 01749 if (done<0) { 01750 return -EFAULT; 01751 } 01752 total += done; 01753 } 01754 } 01755 } 01756 01757 /* 01758 * All done. Write the updated control block back to the caller. 01759 */ 01760 ifc.ifc_len = total; 01761 01762 if (copy_to_user(arg, &ifc, sizeof(struct ifconf))) 01763 return -EFAULT; 01764 01765 /* 01766 * Both BSD and Solaris return 0 here, so we do too. 01767 */ 01768 return 0; 01769 } 01770 01771 /* 01772 * This is invoked by the /proc filesystem handler to display a device 01773 * in detail. 01774 */ 01775 01776 #ifdef CONFIG_PROC_FS 01777 01778 static int sprintf_stats(char *buffer, struct net_device *dev) 01779 { 01780 struct net_device_stats *stats = (dev->get_stats ? dev->get_stats(dev): NULL); 01781 int size; 01782 01783 if (stats) 01784 size = sprintf(buffer, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu %8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n", 01785 dev->name, 01786 stats->rx_bytes, 01787 stats->rx_packets, stats->rx_errors, 01788 stats->rx_dropped + stats->rx_missed_errors, 01789 stats->rx_fifo_errors, 01790 stats->rx_length_errors + stats->rx_over_errors 01791 + stats->rx_crc_errors + stats->rx_frame_errors, 01792 stats->rx_compressed, stats->multicast, 01793 stats->tx_bytes, 01794 stats->tx_packets, stats->tx_errors, stats->tx_dropped, 01795 stats->tx_fifo_errors, stats->collisions, 01796 stats->tx_carrier_errors + stats->tx_aborted_errors 01797 + stats->tx_window_errors + stats->tx_heartbeat_errors, 01798 stats->tx_compressed); 01799 else 01800 size = sprintf(buffer, "%6s: No statistics available.\n", dev->name); 01801 01802 return size; 01803 } 01804 01805 /* 01806 * Called from the PROCfs module. This now uses the new arbitrary sized /proc/net interface 01807 * to create /proc/net/dev 01808 */ 01809 01810 static int dev_get_info(char *buffer, char **start, off_t offset, int length) 01811 { 01812 int len = 0; 01813 off_t begin = 0; 01814 off_t pos = 0; 01815 int size; 01816 struct net_device *dev; 01817 01818 01819 size = sprintf(buffer, 01820 "Inter-| Receive | Transmit\n" 01821 " face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n"); 01822 01823 pos += size; 01824 len += size; 01825 01826 01827 read_lock(&dev_base_lock); 01828 for (dev = dev_base; dev != NULL; dev = dev->next) { 01829 size = sprintf_stats(buffer+len, dev); 01830 len += size; 01831 pos = begin + len; 01832 01833 if (pos < offset) { 01834 len = 0; 01835 begin = pos; 01836 } 01837 if (pos > offset + length) 01838 break; 01839 } 01840 read_unlock(&dev_base_lock); 01841 01842 *start = buffer + (offset - begin); /* Start of wanted data */ 01843 len -= (offset - begin); /* Start slop */ 01844 if (len > length) 01845 len = length; /* Ending slop */ 01846 if (len < 0) 01847 len = 0; 01848 return len; 01849 } 01850 01851 static int dev_proc_stats(char *buffer, char **start, off_t offset, 01852 int length, int *eof, void *data) 01853 { 01854 int i, lcpu; 01855 int len=0; 01856 01857 for (lcpu=0; lcpu<smp_num_cpus; lcpu++) { 01858 i = cpu_logical_map(lcpu); 01859 len += sprintf(buffer+len, "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n", 01860 netdev_rx_stat[i].total, 01861 netdev_rx_stat[i].dropped, 01862 netdev_rx_stat[i].time_squeeze, 01863 netdev_rx_stat[i].throttled, 01864 netdev_rx_stat[i].fastroute_hit, 01865 netdev_rx_stat[i].fastroute_success, 01866 netdev_rx_stat[i].fastroute_defer, 01867 netdev_rx_stat[i].fastroute_deferred_out, 01868 #if 0 01869 netdev_rx_stat[i].fastroute_latency_reduction 01870 #else 01871 netdev_rx_stat[i].cpu_collision 01872 #endif 01873 ); 01874 } 01875 01876 len -= offset; 01877 01878 if (len > length) 01879 len = length; 01880 if (len < 0) 01881 len = 0; 01882 01883 *start = buffer + offset; 01884 *eof = 1; 01885 01886 return len; 01887 } 01888 01889 #endif /* CONFIG_PROC_FS */ 01890 01891 01892 /* 01893 * netdev_set_master - set up master/slave pair 01894 * @slave: slave device 01895 * @master: new master device 01896 * 01897 * Changes the master device of the slave. Pass %NULL to break the 01898 * bonding. The caller must hold the RTNL semaphore. On a failure 01899 * a negative errno code is returned. On success the reference counts 01900 * are adjusted, %RTM_NEWLINK is sent to the routing socket and the 01901 * function returns zero. 01902 */ 01903 01904 int netdev_set_master(struct net_device *slave, struct net_device *master) 01905 { 01906 struct net_device *old = slave->master; 01907 01908 ASSERT_RTNL(); 01909 01910 if (master) { 01911 if (old) 01912 return -EBUSY; 01913 dev_hold(master); 01914 } 01915 01916 br_write_lock_bh(BR_NETPROTO_LOCK); 01917 slave->master = master; 01918 br_write_unlock_bh(BR_NETPROTO_LOCK); 01919 01920 if (old) 01921 dev_put(old); 01922 01923 if (master) 01924 slave->flags |= IFF_SLAVE; 01925 else 01926 slave->flags &= ~IFF_SLAVE; 01927 01928 rtmsg_ifinfo(RTM_NEWLINK, slave, IFF_SLAVE); 01929 return 0; 01930 } 01931 01932 /* 01933 * dev_set_promiscuity - update promiscuity count on a device 01934 * @dev: device 01935 * @inc: modifier 01936 * 01937 * Add or remove promsicuity from a device. While the count in the device 01938 * remains above zero the interface remains promiscuous. Once it hits zero 01939 * the device reverts back to normal filtering operation. A negative inc 01940 * value is used to drop promiscuity on the device. 01941 */ 01942 01943 void dev_set_promiscuity(struct net_device *dev, int inc) 01944 { 01945 unsigned short old_flags = dev->flags; 01946 01947 dev->flags |= IFF_PROMISC; 01948 if ((dev->promiscuity += inc) == 0) 01949 dev->flags &= ~IFF_PROMISC; 01950 if (dev->flags^old_flags) { 01951 #ifdef CONFIG_NET_FASTROUTE 01952 if (dev->flags&IFF_PROMISC) { 01953 netdev_fastroute_obstacles++; 01954 dev_clear_fastroute(dev); 01955 } else 01956 netdev_fastroute_obstacles--; 01957 #endif 01958 dev_mc_upload(dev); 01959 printk(KERN_INFO "device %s %s promiscuous mode\n", 01960 dev->name, (dev->flags&IFF_PROMISC) ? "entered" : "left"); 01961 } 01962 } 01963 01964 /* 01965 * dev_set_allmulti - update allmulti count on a device 01966 * @dev: device 01967 * @inc: modifier 01968 * 01969 * Add or remove reception of all multicast frames to a device. While the 01970 * count in the device remains above zero the interface remains listening 01971 * to all interfaces. Once it hits zero the device reverts back to normal 01972 * filtering operation. A negative @inc value is used to drop the counter 01973 * when releasing a resource needing all multicasts. 01974 */ 01975 01976 void dev_set_allmulti(struct net_device *dev, int inc) 01977 { 01978 unsigned short old_flags = dev->flags; 01979 01980 dev->flags |= IFF_ALLMULTI; 01981 if ((dev->allmulti += inc) == 0) 01982 dev->flags &= ~IFF_ALLMULTI; 01983 if (dev->flags^old_flags) 01984 dev_mc_upload(dev); 01985 } 01986 01987 int dev_change_flags(struct net_device *dev, unsigned flags) 01988 { 01989 int ret; 01990 int old_flags = dev->flags; 01991 01992 /* 01993 * Set the flags on our device. 01994 */ 01995 01996 dev->flags = (flags & (IFF_DEBUG|IFF_NOTRAILERS|IFF_NOARP|IFF_DYNAMIC| 01997 IFF_MULTICAST|IFF_PORTSEL|IFF_AUTOMEDIA)) | 01998 (dev->flags & (IFF_UP|IFF_VOLATILE|IFF_PROMISC|IFF_ALLMULTI)); 01999 02000 /* 02001 * Load in the correct multicast list now the flags have changed. 02002 */ 02003 02004 dev_mc_upload(dev); 02005 02006 /* 02007 * Have we downed the interface. We handle IFF_UP ourselves 02008 * according to user attempts to set it, rather than blindly 02009 * setting it. 02010 */ 02011 02012 ret = 0; 02013 if ((old_flags^flags)&IFF_UP) /* Bit is different ? */ 02014 { 02015 ret = ((old_flags & IFF_UP) ? dev_close : dev_open)(dev); 02016 02017 if (ret == 0) 02018 dev_mc_upload(dev); 02019 } 02020 02021 if (dev->flags&IFF_UP && 02022 ((old_flags^dev->flags)&~(IFF_UP|IFF_PROMISC|IFF_ALLMULTI|IFF_VOLATILE))) 02023 notifier_call_chain(&netdev_chain, NETDEV_CHANGE, dev); 02024 02025 if ((flags^dev->gflags)&IFF_PROMISC) { 02026 int inc = (flags&IFF_PROMISC) ? +1 : -1; 02027 dev->gflags ^= IFF_PROMISC; 02028 dev_set_promiscuity(dev, inc); 02029 } 02030 02031 /* NOTE: order of synchronization of IFF_PROMISC and IFF_ALLMULTI 02032 is important. Some (broken) drivers set IFF_PROMISC, when 02033 IFF_ALLMULTI is requested not asking us and not reporting. 02034 */ 02035 if ((flags^dev->gflags)&IFF_ALLMULTI) { 02036 int inc = (flags&IFF_ALLMULTI) ? +1 : -1; 02037 dev->gflags ^= IFF_ALLMULTI; 02038 dev_set_allmulti(dev, inc); 02039 } 02040 02041 if (old_flags^dev->flags) 02042 rtmsg_ifinfo(RTM_NEWLINK, dev, old_flags^dev->flags); 02043 02044 return ret; 02045 } 02046 02047 /* 02048 * Perform the SIOCxIFxxx calls. 02049 */ 02050 02051 static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd) 02052 { 02053 struct net_device *dev; 02054 int err; 02055 02056 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL) 02057 return -ENODEV; 02058 02059 switch(cmd) 02060 { 02061 case SIOCGIFFLAGS: /* Get interface flags */ 02062 ifr->ifr_flags = (dev->flags&~(IFF_PROMISC|IFF_ALLMULTI|IFF_RUNNING)) 02063 |(dev->gflags&(IFF_PROMISC|IFF_ALLMULTI)); 02064 if (netif_running(dev) && netif_carrier_ok(dev)) 02065 ifr->ifr_flags |= IFF_RUNNING; 02066 return 0; 02067 02068 case SIOCSIFFLAGS: /* Set interface flags */ 02069 return dev_change_flags(dev, ifr->ifr_flags); 02070 02071 case SIOCGIFMETRIC: /* Get the metric on the interface (currently unused) */ 02072 ifr->ifr_metric = 0; 02073 return 0; 02074 02075 case SIOCSIFMETRIC: /* Set the metric on the interface (currently unused) */ 02076 return -EOPNOTSUPP; 02077 02078 case SIOCGIFMTU: /* Get the MTU of a device */ 02079 ifr->ifr_mtu = dev->mtu; 02080 return 0; 02081 02082 case SIOCSIFMTU: /* Set the MTU of a device */ 02083 if (ifr->ifr_mtu == dev->mtu) 02084 return 0; 02085 02086 /* 02087 * MTU must be positive. 02088 */ 02089 02090 if (ifr->ifr_mtu<0) 02091 return -EINVAL; 02092 02093 if (!netif_device_present(dev)) 02094 return -ENODEV; 02095 02096 if (dev->change_mtu) 02097 err = dev->change_mtu(dev, ifr->ifr_mtu); 02098 else { 02099 dev->mtu = ifr->ifr_mtu; 02100 err = 0; 02101 } 02102 if (!err && dev->flags&IFF_UP) 02103 notifier_call_chain(&netdev_chain, NETDEV_CHANGEMTU, dev); 02104 return err; 02105 02106 case SIOCGIFHWADDR: 02107 memcpy(ifr->ifr_hwaddr.sa_data,dev->dev_addr, MAX_ADDR_LEN); 02108 ifr->ifr_hwaddr.sa_family=dev->type; 02109 return 0; 02110 02111 case SIOCSIFHWADDR: 02112 if (dev->set_mac_address == NULL) 02113 return -EOPNOTSUPP; 02114 if (ifr->ifr_hwaddr.sa_family!=dev->type) 02115 return -EINVAL; 02116 if (!netif_device_present(dev)) 02117 return -ENODEV; 02118 err = dev->set_mac_address(dev, &ifr->ifr_hwaddr); 02119 if (!err) 02120 notifier_call_chain(&netdev_chain, NETDEV_CHANGEADDR, dev); 02121 return err; 02122 02123 case SIOCSIFHWBROADCAST: 02124 if (ifr->ifr_hwaddr.sa_family!=dev->type) 02125 return -EINVAL; 02126 memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data, MAX_ADDR_LEN); 02127 notifier_call_chain(&netdev_chain, NETDEV_CHANGEADDR, dev); 02128 return 0; 02129 02130 case SIOCGIFMAP: 02131 ifr->ifr_map.mem_start=dev->mem_start; 02132 ifr->ifr_map.mem_end=dev->mem_end; 02133 ifr->ifr_map.base_addr=dev->base_addr; 02134 ifr->ifr_map.irq=dev->irq; 02135 ifr->ifr_map.dma=dev->dma; 02136 ifr->ifr_map.port=dev->if_port; 02137 return 0; 02138 02139 case SIOCSIFMAP: 02140 if (dev->set_config) { 02141 if (!netif_device_present(dev)) 02142 return -ENODEV; 02143 return dev->set_config(dev,&ifr->ifr_map); 02144 } 02145 return -EOPNOTSUPP; 02146 02147 case SIOCADDMULTI: 02148 if (dev->set_multicast_list == NULL || 02149 ifr->ifr_hwaddr.sa_family != AF_UNSPEC) 02150 return -EINVAL; 02151 if (!netif_device_present(dev)) 02152 return -ENODEV; 02153 dev_mc_add(dev,ifr->ifr_hwaddr.sa_data, dev->addr_len, 1); 02154 return 0; 02155 02156 case SIOCDELMULTI: 02157 if (dev->set_multicast_list == NULL || 02158 ifr->ifr_hwaddr.sa_family!=AF_UNSPEC) 02159 return -EINVAL; 02160 if (!netif_device_present(dev)) 02161 return -ENODEV; 02162 dev_mc_delete(dev,ifr->ifr_hwaddr.sa_data,dev->addr_len, 1); 02163 return 0; 02164 02165 case SIOCGIFINDEX: 02166 ifr->ifr_ifindex = dev->ifindex; 02167 return 0; 02168 02169 case SIOCGIFTXQLEN: 02170 ifr->ifr_qlen = dev->tx_queue_len; 02171 return 0; 02172 02173 case SIOCSIFTXQLEN: 02174 if (ifr->ifr_qlen<0) 02175 return -EINVAL; 02176 dev->tx_queue_len = ifr->ifr_qlen; 02177 return 0; 02178 02179 case SIOCSIFNAME: 02180 if (dev->flags&IFF_UP) 02181 return -EBUSY; 02182 if (__dev_get_by_name(ifr->ifr_newname)) 02183 return -EEXIST; 02184 memcpy(dev->name, ifr->ifr_newname, IFNAMSIZ); 02185 dev->name[IFNAMSIZ-1] = 0; 02186 notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev); 02187 return 0; 02188 02189 /* 02190 * Unknown or private ioctl 02191 */ 02192 02193 default: 02194 if ((cmd >= SIOCDEVPRIVATE && 02195 cmd <= SIOCDEVPRIVATE + 15) || 02196 cmd == SIOCBONDENSLAVE || 02197 cmd == SIOCBONDRELEASE || 02198 cmd == SIOCBONDSETHWADDR || 02199 cmd == SIOCBONDSLAVEINFOQUERY || 02200 cmd == SIOCBONDINFOQUERY || 02201 cmd == SIOCBONDCHANGEACTIVE || 02202 cmd == SIOCGMIIPHY || 02203 cmd == SIOCGMIIREG || 02204 cmd == SIOCSMIIREG || 02205 cmd == SIOCWANDEV) { 02206 if (dev->do_ioctl) { 02207 if (!netif_device_present(dev)) 02208 return -ENODEV; 02209 return dev->do_ioctl(dev, ifr, cmd); 02210 } 02211 return -EOPNOTSUPP; 02212 } 02213 02214 } 02215 return -EINVAL; 02216 } 02217 02218 /* 02219 * This function handles all "interface"-type I/O control requests. The actual 02220 * 'doing' part of this is dev_ifsioc above. 02221 */ 02222 02223 /* 02224 * dev_ioctl - network device ioctl 02225 * @cmd: command to issue 02226 * @arg: pointer to a struct ifreq in user space 02227 * 02228 * Issue ioctl functions to devices. This is normally called by the 02229 * user space syscall interfaces but can sometimes be useful for 02230 * other purposes. The return value is the return from the syscall if 02231 * positive or a negative errno code on error. 02232 */ 02233 02234 int dev_ioctl(unsigned int cmd, void *arg) 02235 { 02236 struct ifreq ifr; 02237 int ret; 02238 char *colon; 02239 02240 /* One special case: SIOCGIFCONF takes ifconf argument 02241 and requires shared lock, because it sleeps writing 02242 to user space. 02243 */ 02244 02245 if (cmd == SIOCGIFCONF) { 02246 rtnl_shlock(); 02247 ret = dev_ifconf((char *) arg); 02248 rtnl_shunlock(); 02249 return ret; 02250 } 02251 if (cmd == SIOCGIFNAME) { 02252 return dev_ifname((struct ifreq *)arg); 02253 } 02254 02255 if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) 02256 return -EFAULT; 02257 02258 ifr.ifr_name[IFNAMSIZ-1] = 0; 02259 02260 colon = strchr(ifr.ifr_name, ':'); 02261 if (colon) 02262 *colon = 0; 02263 02264 /* 02265 * See which interface the caller is talking about. 02266 */ 02267 02268 switch(cmd) 02269 { 02270 /* 02271 * These ioctl calls: 02272 * - can be done by all. 02273 * - atomic and do not require locking. 02274 * - return a value 02275 */ 02276 02277 case SIOCGIFFLAGS: 02278 case SIOCGIFMETRIC: 02279 case SIOCGIFMTU: 02280 case SIOCGIFHWADDR: 02281 case SIOCGIFSLAVE: 02282 case SIOCGIFMAP: 02283 case SIOCGIFINDEX: 02284 case SIOCGIFTXQLEN: 02285 dev_load(ifr.ifr_name); 02286 read_lock(&dev_base_lock); 02287 ret = dev_ifsioc(&ifr, cmd); 02288 read_unlock(&dev_base_lock); 02289 if (!ret) { 02290 if (colon) 02291 *colon = ':'; 02292 if (copy_to_user(arg, &ifr, sizeof(struct ifreq))) 02293 return -EFAULT; 02294 } 02295 return ret; 02296 02297 case SIOCETHTOOL: 02298 dev_load(ifr.ifr_name); 02299 rtnl_lock(); 02300 ret = dev_ethtool(&ifr); 02301 rtnl_unlock(); 02302 if (!ret) { 02303 if (colon) 02304 *colon = ':'; 02305 if (copy_to_user(arg, &ifr, 02306 sizeof(struct ifreq))) 02307 ret = -EFAULT; 02308 } 02309 return ret; 02310 02311 /* 02312 * These ioctl calls: 02313 * - require superuser power. 02314 * - require strict serialization. 02315 * - return a value 02316 */ 02317 02318 case SIOCGMIIPHY: 02319 case SIOCGMIIREG: 02320 if (!capable(CAP_NET_ADMIN)) 02321 return -EPERM; 02322 dev_load(ifr.ifr_name); 02323 dev_probe_lock(); 02324 rtnl_lock(); 02325 ret = dev_ifsioc(&ifr, cmd); 02326 rtnl_unlock(); 02327 dev_probe_unlock(); 02328 if (!ret) { 02329 if (colon) 02330 *colon = ':'; 02331 if (copy_to_user(arg, &ifr, sizeof(struct ifreq))) 02332 return -EFAULT; 02333 } 02334 return ret; 02335 02336 /* 02337 * These ioctl calls: 02338 * - require superuser power. 02339 * - require strict serialization. 02340 * - do not return a value 02341 */ 02342 02343 case SIOCSIFFLAGS: 02344 case SIOCSIFMETRIC: 02345 case SIOCSIFMTU: 02346 case SIOCSIFMAP: 02347 case SIOCSIFHWADDR: 02348 case SIOCSIFSLAVE: 02349 case SIOCADDMULTI: 02350 case SIOCDELMULTI: 02351 case SIOCSIFHWBROADCAST: 02352 case SIOCSIFTXQLEN: 02353 case SIOCSIFNAME: 02354 case SIOCSMIIREG: 02355 case SIOCBONDENSLAVE: 02356 case SIOCBONDRELEASE: 02357 case SIOCBONDSETHWADDR: 02358 case SIOCBONDSLAVEINFOQUERY: 02359 case SIOCBONDINFOQUERY: 02360 case SIOCBONDCHANGEACTIVE: 02361 if (!capable(CAP_NET_ADMIN)) 02362 return -EPERM; 02363 dev_load(ifr.ifr_name); 02364 dev_probe_lock(); 02365 rtnl_lock(); 02366 ret = dev_ifsioc(&ifr, cmd); 02367 rtnl_unlock(); 02368 dev_probe_unlock(); 02369 return ret; 02370 02371 case SIOCGIFMEM: 02372 /* Get the per device memory space. We can add this but currently 02373 do not support it */ 02374 case SIOCSIFMEM: 02375 /* Set the per device memory buffer space. Not applicable in our case */ 02376 case SIOCSIFLINK: 02377 return -EINVAL; 02378 02379 /* 02380 * Unknown or private ioctl. 02381 */ 02382 02383 default: 02384 if (cmd == SIOCWANDEV || 02385 (cmd >= SIOCDEVPRIVATE && 02386 cmd <= SIOCDEVPRIVATE + 15)) { 02387 dev_load(ifr.ifr_name); 02388 dev_probe_lock(); 02389 rtnl_lock(); 02390 ret = dev_ifsioc(&ifr, cmd); 02391 rtnl_unlock(); 02392 dev_probe_unlock(); 02393 if (!ret && copy_to_user(arg, &ifr, sizeof(struct ifreq))) 02394 return -EFAULT; 02395 return ret; 02396 } 02397 #ifdef WIRELESS_EXT 02398 /* Take care of Wireless Extensions */ 02399 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) { 02400 /* If command is `set a parameter', or 02401 * `get the encoding parameters', check if 02402 * the user has the right to do it */ 02403 if (IW_IS_SET(cmd) || (cmd == SIOCGIWENCODE)) { 02404 if(!capable(CAP_NET_ADMIN)) 02405 return -EPERM; 02406 } 02407 dev_load(ifr.ifr_name); 02408 rtnl_lock(); 02409 /* Follow me in net/core/wireless.c */ 02410 ret = wireless_process_ioctl(&ifr, cmd); 02411 rtnl_unlock(); 02412 if (!ret && IW_IS_GET(cmd) && 02413 copy_to_user(arg, &ifr, sizeof(struct ifreq))) 02414 return -EFAULT; 02415 return ret; 02416 } 02417 #endif /* WIRELESS_EXT */ 02418 return -EINVAL; 02419 } 02420 } 02421 02422 02423 /* 02424 * dev_new_index - allocate an ifindex 02425 * 02426 * Returns a suitable unique value for a new device interface 02427 * number. The caller must hold the rtnl semaphore or the 02428 * dev_base_lock to be sure it remains unique. 02429 */ 02430 02431 int dev_new_index(void) 02432 { 02433 static int ifindex; 02434 for (;;) { 02435 if (++ifindex <= 0) 02436 ifindex=1; 02437 if (__dev_get_by_index(ifindex) == NULL) 02438 return ifindex; 02439 } 02440 } 02441 02442 static int dev_boot_phase = 1; 02443 02444 /* 02445 * register_netdevice - register a network device 02446 * @dev: device to register 02447 * 02448 * Take a completed network device structure and add it to the kernel 02449 * interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier 02450 * chain. 0 is returned on success. A negative errno code is returned 02451 * on a failure to set up the device, or if the name is a duplicate. 02452 * 02453 * Callers must hold the rtnl semaphore. See the comment at the 02454 * end of Space.c for details about the locking. You may want 02455 * register_netdev() instead of this. 02456 * 02457 * BUGS: 02458 * The locking appears insufficient to guarantee two parallel registers 02459 * will not get the same name. 02460 */ 02461 02462 int net_dev_init(void); 02463 02464 int register_netdevice(struct net_device *dev) 02465 { 02466 struct net_device *d, **dp; 02467 #ifdef CONFIG_NET_DIVERT 02468 int ret; 02469 #endif 02470 02471 spin_lock_init(&dev->queue_lock); 02472 spin_lock_init(&dev->xmit_lock); 02473 dev->xmit_lock_owner = -1; 02474 #ifdef CONFIG_NET_FASTROUTE 02475 dev->fastpath_lock=RW_LOCK_UNLOCKED; 02476 #endif 02477 02478 if (dev_boot_phase) 02479 net_dev_init(); 02480 02481 #ifdef CONFIG_NET_DIVERT 02482 ret = alloc_divert_blk(dev); 02483 if (ret) 02484 return ret; 02485 #endif /* CONFIG_NET_DIVERT */ 02486 02487 dev->iflink = -1; 02488 02489 /* Init, if this function is available */ 02490 if (dev->init && dev->init(dev) != 0) { 02491 #ifdef CONFIG_NET_DIVERT 02492 free_divert_blk(dev); 02493 #endif 02494 return -EIO; 02495 } 02496 02497 dev->ifindex = dev_new_index(); 02498 if (dev->iflink == -1) 02499 dev->iflink = dev->ifindex; 02500 02501 /* Check for existence, and append to tail of chain */ 02502 for (dp=&dev_base; (d=*dp) != NULL; dp=&d->next) { 02503 if (d == dev || strcmp(d->name, dev->name) == 0) { 02504 #ifdef CONFIG_NET_DIVERT 02505 free_divert_blk(dev); 02506 #endif 02507 return -EEXIST; 02508 } 02509 } 02510 02511 /* Fix illegal SG+CSUM combinations. */ 02512 if ((dev->features & NETIF_F_SG) && 02513 !(dev->features & (NETIF_F_IP_CSUM | 02514 NETIF_F_NO_CSUM | 02515 NETIF_F_HW_CSUM))) { 02516 printk("%s: Dropping NETIF_F_SG since no checksum feature.\n", 02517 dev->name); 02518 dev->features &= ~NETIF_F_SG; 02519 } 02520 02521 /* 02522 * nil rebuild_header routine, 02523 * that should be never called and used as just bug trap. 02524 */ 02525 02526 if (dev->rebuild_header == NULL) 02527 dev->rebuild_header = default_rebuild_header; 02528 02529 /* 02530 * Default initial state at registry is that the 02531 * device is present. 02532 */ 02533 02534 set_bit(__LINK_STATE_PRESENT, &dev->state); 02535 02536 dev->next = NULL; 02537 dev_init_scheduler(dev); 02538 write_lock_bh(&dev_base_lock); 02539 *dp = dev; 02540 dev_hold(dev); 02541 dev->deadbeaf = 0; 02542 write_unlock_bh(&dev_base_lock); 02543 02544 /* Notify protocols, that a new device appeared. */ 02545 notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev); 02546 02547 net_run_sbin_hotplug(dev, "register"); 02548 02549 return 0; 02550 } 02551 02552 /* 02553 * netdev_finish_unregister - complete unregistration 02554 * @dev: device 02555 * 02556 * Destroy and free a dead device. A value of zero is returned on 02557 * success. 02558 */ 02559 02560 int netdev_finish_unregister(struct net_device *dev) 02561 { 02562 BUG_TRAP(dev->ip_ptr==NULL); 02563 BUG_TRAP(dev->ip6_ptr==NULL); 02564 BUG_TRAP(dev->dn_ptr==NULL); 02565 02566 if (!dev->deadbeaf) { 02567 printk(KERN_ERR "Freeing alive device %p, %s\n", dev, dev->name); 02568 return 0; 02569 } 02570 #ifdef NET_REFCNT_DEBUG 02571 printk(KERN_DEBUG "netdev_finish_unregister: %s%s.\n", dev->name, 02572 (dev->features & NETIF_F_DYNALLOC)?"":", old style"); 02573 #endif 02574 if (dev->destructor) 02575 dev->destructor(dev); 02576 if (dev->features & NETIF_F_DYNALLOC) 02577 kfree(dev); 02578 return 0; 02579 } 02580 02581 /* 02582 * unregister_netdevice - remove device from the kernel 02583 * @dev: device 02584 * 02585 * This function shuts down a device interface and removes it 02586 * from the kernel tables. On success 0 is returned, on a failure 02587 * a negative errno code is returned. 02588 * 02589 * Callers must hold the rtnl semaphore. See the comment at the 02590 * end of Space.c for details about the locking. You may want 02591 * unregister_netdev() instead of this. 02592 */ 02593 02594 int unregister_netdevice(struct net_device *dev) 02595 { 02596 unsigned long now, warning_time; 02597 struct net_device *d, **dp; 02598 02599 /* If device is running, close it first. */ 02600 if (dev->flags & IFF_UP) 02601 dev_close(dev); 02602 02603 BUG_TRAP(dev->deadbeaf==0); 02604 dev->deadbeaf = 1; 02605 02606 /* And unlink it from device chain. */ 02607 for (dp = &dev_base; (d=*dp) != NULL; dp=&d->next) { 02608 if (d == dev) { 02609 write_lock_bh(&dev_base_lock); 02610 *dp = d->next; 02611 write_unlock_bh(&dev_base_lock); 02612 break; 02613 } 02614 } 02615 if (d == NULL) { 02616 printk(KERN_DEBUG "unregister_netdevice: device %s/%p never was registered\n", dev->name, dev); 02617 return -ENODEV; 02618 } 02619 02620 /* Synchronize to net_rx_action. */ 02621 br_write_lock_bh(BR_NETPROTO_LOCK); 02622 br_write_unlock_bh(BR_NETPROTO_LOCK); 02623 02624 if (dev_boot_phase == 0) { 02625 #ifdef CONFIG_NET_FASTROUTE 02626 dev_clear_fastroute(dev); 02627 #endif 02628 02629 /* Shutdown queueing discipline. */ 02630 dev_shutdown(dev); 02631 02632 net_run_sbin_hotplug(dev, "unregister"); 02633 02634 /* Notify protocols, that we are about to destroy 02635 this device. They should clean all the things. 02636 */ 02637 notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev); 02638 02639 /* 02640 * Flush the multicast chain 02641 */ 02642 dev_mc_discard(dev); 02643 } 02644 02645 if (dev->uninit) 02646 dev->uninit(dev); 02647 02648 /* Notifier chain MUST detach us from master device. */ 02649 BUG_TRAP(dev->master==NULL); 02650 02651 #ifdef CONFIG_NET_DIVERT 02652 free_divert_blk(dev); 02653 #endif 02654 02655 if (dev->features & NETIF_F_DYNALLOC) { 02656 #ifdef NET_REFCNT_DEBUG 02657 if (atomic_read(&dev->refcnt) != 1) 02658 printk(KERN_DEBUG "unregister_netdevice: holding %s refcnt=%d\n", dev->name, atomic_read(&dev->refcnt)-1); 02659 #endif 02660 dev_put(dev); 02661 return 0; 02662 } 02663 02664 /* Last reference is our one */ 02665 if (atomic_read(&dev->refcnt) == 1) { 02666 dev_put(dev); 02667 return 0; 02668 } 02669 02670 #ifdef NET_REFCNT_DEBUG 02671 printk("unregister_netdevice: waiting %s refcnt=%d\n", dev->name, atomic_read(&dev->refcnt)); 02672 #endif 02673 02674 /* EXPLANATION. If dev->refcnt is not now 1 (our own reference) 02675 it means that someone in the kernel still has a reference 02676 to this device and we cannot release it. 02677 02678 "New style" devices have destructors, hence we can return from this 02679 function and destructor will do all the work later. As of kernel 2.4.0 02680 there are very few "New Style" devices. 02681 02682 "Old style" devices expect that the device is free of any references 02683 upon exit from this function. 02684 We cannot return from this function until all such references have 02685 fallen away. This is because the caller of this function will probably 02686 immediately kfree(*dev) and then be unloaded via sys_delete_module. 02687 02688 So, we linger until all references fall away. The duration of the 02689 linger is basically unbounded! It is driven by, for example, the 02690 current setting of sysctl_ipfrag_time. 02691 02692 After 1 second, we start to rebroadcast unregister notifications 02693 in hope that careless clients will release the device. 02694 02695 */ 02696 02697 now = warning_time = jiffies; 02698 while (atomic_read(&dev->refcnt) != 1) { 02699 if ((jiffies - now) > 1*HZ) { 02700 /* Rebroadcast unregister notification */ 02701 notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev); 02702 } 02703 current->state = TASK_INTERRUPTIBLE; 02704 schedule_timeout(HZ/4); 02705 current->state = TASK_RUNNING; 02706 if ((jiffies - warning_time) > 10*HZ) { 02707 printk(KERN_EMERG "unregister_netdevice: waiting for %s to " 02708 "become free. Usage count = %d\n", 02709 dev->name, atomic_read(&dev->refcnt)); 02710 warning_time = jiffies; 02711 } 02712 } 02713 dev_put(dev); 02714 return 0; 02715 } 02716 02717 02718 /* 02719 * Initialize the DEV module. At boot time this walks the device list and 02720 * unhooks any devices that fail to initialise (normally hardware not 02721 * present) and leaves us with a valid list of present and active devices. 02722 * 02723 */ 02724 02725 extern void net_device_init(void); 02726 extern void ip_auto_config(void); 02727 struct proc_dir_entry *proc_net_drivers; 02728 #ifdef CONFIG_NET_DIVERT 02729 extern void dv_init(void); 02730 #endif /* CONFIG_NET_DIVERT */ 02731 02732 02733 /* 02734 * Callers must hold the rtnl semaphore. See the comment at the 02735 * end of Space.c for details about the locking. 02736 */ 02737 int __init net_dev_init(void) 02738 { 02739 struct net_device *dev, **dp; 02740 int i; 02741 02742 if (!dev_boot_phase) 02743 return 0; 02744 02745 02746 #ifdef CONFIG_NET_DIVERT 02747 dv_init(); 02748 #endif /* CONFIG_NET_DIVERT */ 02749 02750 /* 02751 * Initialise the packet receive queues. 02752 */ 02753 02754 for (i = 0; i < NR_CPUS; i++) { 02755 struct softnet_data *queue; 02756 02757 queue = &softnet_data[i]; 02758 skb_queue_head_init(&queue->input_pkt_queue); 02759 queue->throttle = 0; 02760 queue->cng_level = 0; 02761 queue->avg_blog = 10; /* arbitrary non-zero */ 02762 queue->completion_queue = NULL; 02763 INIT_LIST_HEAD(&queue->poll_list); 02764 set_bit(__LINK_STATE_START, &queue->blog_dev.state); 02765 queue->blog_dev.weight = weight_p; 02766 queue->blog_dev.poll = process_backlog; 02767 atomic_set(&queue->blog_dev.refcnt, 1); 02768 } 02769 02770 #ifdef CONFIG_NET_PROFILE 02771 net_profile_init(); 02772 NET_PROFILE_REGISTER(dev_queue_xmit); 02773 NET_PROFILE_REGISTER(softnet_process); 02774 #endif 02775 02776 #ifdef OFFLINE_SAMPLE 02777 samp_timer.expires = jiffies + (10 * HZ); 02778 add_timer(&samp_timer); 02779 #endif 02780 02781 /* 02782 * Add the devices. 02783 * If the call to dev->init fails, the dev is removed 02784 * from the chain disconnecting the device until the 02785 * next reboot. 02786 * 02787 * NB At boot phase networking is dead. No locking is required. 02788 * But we still preserve dev_base_lock for sanity. 02789 */ 02790 02791 dp = &dev_base; 02792 while ((dev = *dp) != NULL) { 02793 spin_lock_init(&dev->queue_lock); 02794 spin_lock_init(&dev->xmit_lock); 02795 #ifdef CONFIG_NET_FASTROUTE 02796 dev->fastpath_lock = RW_LOCK_UNLOCKED; 02797 #endif 02798 dev->xmit_lock_owner = -1; 02799 dev->iflink = -1; 02800 dev_hold(dev); 02801 02802 /* 02803 * Allocate name. If the init() fails 02804 * the name will be reissued correctly. 02805 */ 02806 if (strchr(dev->name, '%')) 02807 dev_alloc_name(dev, dev->name); 02808 02809 /* 02810 * Check boot time settings for the device. 02811 */ 02812 netdev_boot_setup_check(dev); 02813 02814 if (dev->init && dev->init(dev)) { 02815 /* 02816 * It failed to come up. It will be unhooked later. 02817 * dev_alloc_name can now advance to next suitable 02818 * name that is checked next. 02819 */ 02820 dev->deadbeaf = 1; 02821 dp = &dev->next; 02822 } else { 02823 dp = &dev->next; 02824 dev->ifindex = dev_new_index(); 02825 if (dev->iflink == -1) 02826 dev->iflink = dev->ifindex; 02827 if (dev->rebuild_header == NULL) 02828 dev->rebuild_header = default_rebuild_header; 02829 dev_init_scheduler(dev); 02830 set_bit(__LINK_STATE_PRESENT, &dev->state); 02831 } 02832 } 02833 02834 /* 02835 * Unhook devices that failed to come up 02836 */ 02837 dp = &dev_base; 02838 while ((dev = *dp) != NULL) { 02839 if (dev->deadbeaf) { 02840 write_lock_bh(&dev_base_lock); 02841 *dp = dev->next; 02842 write_unlock_bh(&dev_base_lock); 02843 dev_put(dev); 02844 } else { 02845 dp = &dev->next; 02846 } 02847 } 02848 02849 #ifdef CONFIG_PROC_FS 02850 proc_net_create("dev", 0, dev_get_info); 02851 create_proc_read_entry("net/softnet_stat", 0, 0, dev_proc_stats, NULL); 02852 proc_net_drivers = proc_mkdir("net/drivers", 0); 02853 #ifdef WIRELESS_EXT 02854 /* Available in net/core/wireless.c */ 02855 proc_net_create("wireless", 0, dev_get_wireless_info); 02856 #endif /* WIRELESS_EXT */ 02857 #endif /* CONFIG_PROC_FS */ 02858 02859 dev_boot_phase = 0; 02860 02861 open_softirq(NET_TX_SOFTIRQ, net_tx_action, NULL); 02862 open_softirq(NET_RX_SOFTIRQ, net_rx_action, NULL); 02863 02864 dst_init(); 02865 dev_mcast_init(); 02866 02867 #ifdef CONFIG_NET_SCHED 02868 pktsched_init(); 02869 #endif 02870 /* 02871 * Initialise network devices 02872 */ 02873 02874 net_device_init(); 02875 02876 return 0; 02877 } 02878 02879 #ifdef CONFIG_HOTPLUG 02880 02881 /* Notify userspace when a netdevice event occurs, 02882 * by running '/sbin/hotplug net' with certain 02883 * environment variables set. 02884 */ 02885 02886 static int net_run_sbin_hotplug(struct net_device *dev, char *action) 02887 { 02888 char *argv[3], *envp[5], ifname[12 + IFNAMSIZ], action_str[32]; 02889 int i; 02890 02891 sprintf(ifname, "INTERFACE=%s", dev->name); 02892 sprintf(action_str, "ACTION=%s", action); 02893 02894 i = 0; 02895 argv[i++] = hotplug_path; 02896 argv[i++] = "net"; 02897 argv[i] = 0; 02898 02899 i = 0; 02900 /* minimal command environment */ 02901 envp [i++] = "HOME=/"; 02902 envp [i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; 02903 envp [i++] = ifname; 02904 envp [i++] = action_str; 02905 envp [i] = 0; 02906 02907 return call_usermodehelper(argv [0], argv, envp); 02908 } 02909 #endif

Generated on Wed Dec 1 21:25:29 2004 for Linux 2.4.23 Networking by doxygen 1.3.8