This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / net / core / dev.c~
1 /*
2  *      NET3    Protocol independent device support routines.
3  *
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.
8  *
9  *      Derived from the non IP parts of dev.c 1.0.19
10  *              Authors:        Ross Biro
11  *                              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12  *                              Mark Evans, <evansmp@uhura.aston.ac.uk>
13  *
14  *      Additional Authors:
15  *              Florian la Roche <rzsfl@rz.uni-sb.de>
16  *              Alan Cox <gw4pts@gw4pts.ampr.org>
17  *              David Hinds <dahinds@users.sourceforge.net>
18  *              Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
19  *              Adam Sulmicki <adam@cfar.umd.edu>
20  *              Pekka Riikonen <priikone@poesidon.pspt.fi>
21  *
22  *      Changes:
23  *              D.J. Barrow     :       Fixed bug where dev->refcnt gets set
24  *                                      to 2 if register_netdev gets called
25  *                                      before net_dev_init & also removed a
26  *                                      few lines of code in the process.
27  *              Alan Cox        :       device private ioctl copies fields back.
28  *              Alan Cox        :       Transmit queue code does relevant
29  *                                      stunts to keep the queue safe.
30  *              Alan Cox        :       Fixed double lock.
31  *              Alan Cox        :       Fixed promisc NULL pointer trap
32  *              ????????        :       Support the full private ioctl range
33  *              Alan Cox        :       Moved ioctl permission check into
34  *                                      drivers
35  *              Tim Kordas      :       SIOCADDMULTI/SIOCDELMULTI
36  *              Alan Cox        :       100 backlog just doesn't cut it when
37  *                                      you start doing multicast video 8)
38  *              Alan Cox        :       Rewrote net_bh and list manager.
39  *              Alan Cox        :       Fix ETH_P_ALL echoback lengths.
40  *              Alan Cox        :       Took out transmit every packet pass
41  *                                      Saved a few bytes in the ioctl handler
42  *              Alan Cox        :       Network driver sets packet type before
43  *                                      calling netif_rx. Saves a function
44  *                                      call a packet.
45  *              Alan Cox        :       Hashed net_bh()
46  *              Richard Kooijman:       Timestamp fixes.
47  *              Alan Cox        :       Wrong field in SIOCGIFDSTADDR
48  *              Alan Cox        :       Device lock protection.
49  *              Alan Cox        :       Fixed nasty side effect of device close
50  *                                      changes.
51  *              Rudi Cilibrasi  :       Pass the right thing to
52  *                                      set_mac_address()
53  *              Dave Miller     :       32bit quantity for the device lock to
54  *                                      make it work out on a Sparc.
55  *              Bjorn Ekwall    :       Added KERNELD hack.
56  *              Alan Cox        :       Cleaned up the backlog initialise.
57  *              Craig Metz      :       SIOCGIFCONF fix if space for under
58  *                                      1 device.
59  *          Thomas Bogendoerfer :       Return ENODEV for dev_open, if there
60  *                                      is no device open function.
61  *              Andi Kleen      :       Fix error reporting for SIOCGIFCONF
62  *          Michael Chastain    :       Fix signed/unsigned for SIOCGIFCONF
63  *              Cyrus Durgin    :       Cleaned for KMOD
64  *              Adam Sulmicki   :       Bug Fix : Network Device Unload
65  *                                      A network device unload needs to purge
66  *                                      the backlog queue.
67  *      Paul Rusty Russell      :       SIOCSIFNAME
68  *              Pekka Riikonen  :       Netdev boot-time settings code
69  *              Andrew Morton   :       Make unregister_netdevice wait
70  *                                      indefinitely on dev->refcnt
71  *              J Hadi Salim    :       - Backlog queue sampling
72  *                                      - netif_rx() feedback
73  */
74
75 #include <asm/uaccess.h>
76 #include <asm/system.h>
77 #include <linux/bitops.h>
78 #include <linux/capability.h>
79 #include <linux/config.h>
80 #include <linux/cpu.h>
81 #include <linux/types.h>
82 #include <linux/kernel.h>
83 #include <linux/sched.h>
84 #include <linux/mutex.h>
85 #include <linux/string.h>
86 #include <linux/mm.h>
87 #include <linux/socket.h>
88 #include <linux/sockios.h>
89 #include <linux/errno.h>
90 #include <linux/interrupt.h>
91 #include <linux/if_ether.h>
92 #include <linux/netdevice.h>
93 #include <linux/etherdevice.h>
94 #include <linux/notifier.h>
95 #include <linux/skbuff.h>
96 #include <net/sock.h>
97 #include <linux/rtnetlink.h>
98 #include <linux/proc_fs.h>
99 #include <linux/seq_file.h>
100 #include <linux/stat.h>
101 #include <linux/if_bridge.h>
102 #include <linux/divert.h>
103 #include <net/dst.h>
104 #include <net/pkt_sched.h>
105 #include <net/checksum.h>
106 #include <linux/highmem.h>
107 #include <linux/init.h>
108 #include <linux/kmod.h>
109 #include <linux/module.h>
110 #include <linux/kallsyms.h>
111 #include <linux/netpoll.h>
112 #include <linux/rcupdate.h>
113 #include <linux/delay.h>
114 #include <linux/wireless.h>
115 #include <net/iw_handler.h>
116 #include <asm/current.h>
117 #include <linux/audit.h>
118 #include <linux/err.h>
119
120 #ifdef CONFIG_XEN
121 #include <net/ip.h>
122 #include <linux/tcp.h>
123 #include <linux/udp.h>
124 #endif
125
126 /*
127  *      The list of packet types we will receive (as opposed to discard)
128  *      and the routines to invoke.
129  *
130  *      Why 16. Because with 16 the only overlap we get on a hash of the
131  *      low nibble of the protocol value is RARP/SNAP/X.25.
132  *
133  *      NOTE:  That is no longer true with the addition of VLAN tags.  Not
134  *             sure which should go first, but I bet it won't make much
135  *             difference if we are running VLANs.  The good news is that
136  *             this protocol won't be in the list unless compiled in, so
137  *             the average user (w/out VLANs) will not be adversely affected.
138  *             --BLG
139  *
140  *              0800    IP
141  *              8100    802.1Q VLAN
142  *              0001    802.3
143  *              0002    AX.25
144  *              0004    802.2
145  *              8035    RARP
146  *              0005    SNAP
147  *              0805    X.25
148  *              0806    ARP
149  *              8137    IPX
150  *              0009    Localtalk
151  *              86DD    IPv6
152  */
153
154 static DEFINE_SPINLOCK(ptype_lock);
155 static struct list_head ptype_base[16]; /* 16 way hashed list */
156 static struct list_head ptype_all;              /* Taps */
157
158 /*
159  * The @dev_base list is protected by @dev_base_lock and the rtnl
160  * semaphore.
161  *
162  * Pure readers hold dev_base_lock for reading.
163  *
164  * Writers must hold the rtnl semaphore while they loop through the
165  * dev_base list, and hold dev_base_lock for writing when they do the
166  * actual updates.  This allows pure readers to access the list even
167  * while a writer is preparing to update it.
168  *
169  * To put it another way, dev_base_lock is held for writing only to
170  * protect against pure readers; the rtnl semaphore provides the
171  * protection against other writers.
172  *
173  * See, for example usages, register_netdevice() and
174  * unregister_netdevice(), which must be called with the rtnl
175  * semaphore held.
176  */
177 struct net_device *dev_base;
178 static struct net_device **dev_tail = &dev_base;
179 DEFINE_RWLOCK(dev_base_lock);
180
181 EXPORT_SYMBOL(dev_base);
182 EXPORT_SYMBOL(dev_base_lock);
183
184 #define NETDEV_HASHBITS 8
185 static struct hlist_head dev_name_head[1<<NETDEV_HASHBITS];
186 static struct hlist_head dev_index_head[1<<NETDEV_HASHBITS];
187
188 static inline struct hlist_head *dev_name_hash(const char *name)
189 {
190         unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ));
191         return &dev_name_head[hash & ((1<<NETDEV_HASHBITS)-1)];
192 }
193
194 static inline struct hlist_head *dev_index_hash(int ifindex)
195 {
196         return &dev_index_head[ifindex & ((1<<NETDEV_HASHBITS)-1)];
197 }
198
199 /*
200  *      Our notifier list
201  */
202
203 static RAW_NOTIFIER_HEAD(netdev_chain);
204
205 /*
206  *      Device drivers call our routines to queue packets here. We empty the
207  *      queue in the local softnet handler.
208  */
209 DEFINE_PER_CPU(struct softnet_data, softnet_data) = { NULL };
210
211 #ifdef CONFIG_SYSFS
212 extern int netdev_sysfs_init(void);
213 extern int netdev_register_sysfs(struct net_device *);
214 extern void netdev_unregister_sysfs(struct net_device *);
215 #else
216 #define netdev_sysfs_init()             (0)
217 #define netdev_register_sysfs(dev)      (0)
218 #define netdev_unregister_sysfs(dev)    do { } while(0)
219 #endif
220
221
222 /*******************************************************************************
223
224                 Protocol management and registration routines
225
226 *******************************************************************************/
227
228 /*
229  *      For efficiency
230  */
231
232 int netdev_nit;
233
234 /*
235  *      Add a protocol ID to the list. Now that the input handler is
236  *      smarter we can dispense with all the messy stuff that used to be
237  *      here.
238  *
239  *      BEWARE!!! Protocol handlers, mangling input packets,
240  *      MUST BE last in hash buckets and checking protocol handlers
241  *      MUST start from promiscuous ptype_all chain in net_bh.
242  *      It is true now, do not change it.
243  *      Explanation follows: if protocol handler, mangling packet, will
244  *      be the first on list, it is not able to sense, that packet
245  *      is cloned and should be copied-on-write, so that it will
246  *      change it and subsequent readers will get broken packet.
247  *                                                      --ANK (980803)
248  */
249
250 /**
251  *      dev_add_pack - add packet handler
252  *      @pt: packet type declaration
253  *
254  *      Add a protocol handler to the networking stack. The passed &packet_type
255  *      is linked into kernel lists and may not be freed until it has been
256  *      removed from the kernel lists.
257  *
258  *      This call does not sleep therefore it can not 
259  *      guarantee all CPU's that are in middle of receiving packets
260  *      will see the new packet type (until the next received packet).
261  */
262
263 void dev_add_pack(struct packet_type *pt)
264 {
265         int hash;
266
267         spin_lock_bh(&ptype_lock);
268         if (pt->type == htons(ETH_P_ALL)) {
269                 netdev_nit++;
270                 list_add_rcu(&pt->list, &ptype_all);
271         } else {
272                 hash = ntohs(pt->type) & 15;
273                 list_add_rcu(&pt->list, &ptype_base[hash]);
274         }
275         spin_unlock_bh(&ptype_lock);
276 }
277
278 /**
279  *      __dev_remove_pack        - remove packet handler
280  *      @pt: packet type declaration
281  *
282  *      Remove a protocol handler that was previously added to the kernel
283  *      protocol handlers by dev_add_pack(). The passed &packet_type is removed
284  *      from the kernel lists and can be freed or reused once this function
285  *      returns. 
286  *
287  *      The packet type might still be in use by receivers
288  *      and must not be freed until after all the CPU's have gone
289  *      through a quiescent state.
290  */
291 void __dev_remove_pack(struct packet_type *pt)
292 {
293         struct list_head *head;
294         struct packet_type *pt1;
295
296         spin_lock_bh(&ptype_lock);
297
298         if (pt->type == htons(ETH_P_ALL)) {
299                 netdev_nit--;
300                 head = &ptype_all;
301         } else
302                 head = &ptype_base[ntohs(pt->type) & 15];
303
304         list_for_each_entry(pt1, head, list) {
305                 if (pt == pt1) {
306                         list_del_rcu(&pt->list);
307                         goto out;
308                 }
309         }
310
311         printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt);
312 out:
313         spin_unlock_bh(&ptype_lock);
314 }
315 /**
316  *      dev_remove_pack  - remove packet handler
317  *      @pt: packet type declaration
318  *
319  *      Remove a protocol handler that was previously added to the kernel
320  *      protocol handlers by dev_add_pack(). The passed &packet_type is removed
321  *      from the kernel lists and can be freed or reused once this function
322  *      returns.
323  *
324  *      This call sleeps to guarantee that no CPU is looking at the packet
325  *      type after return.
326  */
327 void dev_remove_pack(struct packet_type *pt)
328 {
329         __dev_remove_pack(pt);
330         
331         synchronize_net();
332 }
333
334 /******************************************************************************
335
336                       Device Boot-time Settings Routines
337
338 *******************************************************************************/
339
340 /* Boot time configuration table */
341 static struct netdev_boot_setup dev_boot_setup[NETDEV_BOOT_SETUP_MAX];
342
343 /**
344  *      netdev_boot_setup_add   - add new setup entry
345  *      @name: name of the device
346  *      @map: configured settings for the device
347  *
348  *      Adds new setup entry to the dev_boot_setup list.  The function
349  *      returns 0 on error and 1 on success.  This is a generic routine to
350  *      all netdevices.
351  */
352 static int netdev_boot_setup_add(char *name, struct ifmap *map)
353 {
354         struct netdev_boot_setup *s;
355         int i;
356
357         s = dev_boot_setup;
358         for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
359                 if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
360                         memset(s[i].name, 0, sizeof(s[i].name));
361                         strcpy(s[i].name, name);
362                         memcpy(&s[i].map, map, sizeof(s[i].map));
363                         break;
364                 }
365         }
366
367         return i >= NETDEV_BOOT_SETUP_MAX ? 0 : 1;
368 }
369
370 /**
371  *      netdev_boot_setup_check - check boot time settings
372  *      @dev: the netdevice
373  *
374  *      Check boot time settings for the device.
375  *      The found settings are set for the device to be used
376  *      later in the device probing.
377  *      Returns 0 if no settings found, 1 if they are.
378  */
379 int netdev_boot_setup_check(struct net_device *dev)
380 {
381         struct netdev_boot_setup *s = dev_boot_setup;
382         int i;
383
384         for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
385                 if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
386                     !strncmp(dev->name, s[i].name, strlen(s[i].name))) {
387                         dev->irq        = s[i].map.irq;
388                         dev->base_addr  = s[i].map.base_addr;
389                         dev->mem_start  = s[i].map.mem_start;
390                         dev->mem_end    = s[i].map.mem_end;
391                         return 1;
392                 }
393         }
394         return 0;
395 }
396
397
398 /**
399  *      netdev_boot_base        - get address from boot time settings
400  *      @prefix: prefix for network device
401  *      @unit: id for network device
402  *
403  *      Check boot time settings for the base address of device.
404  *      The found settings are set for the device to be used
405  *      later in the device probing.
406  *      Returns 0 if no settings found.
407  */
408 unsigned long netdev_boot_base(const char *prefix, int unit)
409 {
410         const struct netdev_boot_setup *s = dev_boot_setup;
411         char name[IFNAMSIZ];
412         int i;
413
414         sprintf(name, "%s%d", prefix, unit);
415
416         /*
417          * If device already registered then return base of 1
418          * to indicate not to probe for this interface
419          */
420         if (__dev_get_by_name(name))
421                 return 1;
422
423         for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++)
424                 if (!strcmp(name, s[i].name))
425                         return s[i].map.base_addr;
426         return 0;
427 }
428
429 /*
430  * Saves at boot time configured settings for any netdevice.
431  */
432 int __init netdev_boot_setup(char *str)
433 {
434         int ints[5];
435         struct ifmap map;
436
437         str = get_options(str, ARRAY_SIZE(ints), ints);
438         if (!str || !*str)
439                 return 0;
440
441         /* Save settings */
442         memset(&map, 0, sizeof(map));
443         if (ints[0] > 0)
444                 map.irq = ints[1];
445         if (ints[0] > 1)
446                 map.base_addr = ints[2];
447         if (ints[0] > 2)
448                 map.mem_start = ints[3];
449         if (ints[0] > 3)
450                 map.mem_end = ints[4];
451
452         /* Add new entry to the list */
453         return netdev_boot_setup_add(str, &map);
454 }
455
456 __setup("netdev=", netdev_boot_setup);
457
458 /*******************************************************************************
459
460                             Device Interface Subroutines
461
462 *******************************************************************************/
463
464 /**
465  *      __dev_get_by_name       - find a device by its name
466  *      @name: name to find
467  *
468  *      Find an interface by name. Must be called under RTNL semaphore
469  *      or @dev_base_lock. If the name is found a pointer to the device
470  *      is returned. If the name is not found then %NULL is returned. The
471  *      reference counters are not incremented so the caller must be
472  *      careful with locks.
473  */
474
475 struct net_device *__dev_get_by_name(const char *name)
476 {
477         struct hlist_node *p;
478
479         hlist_for_each(p, dev_name_hash(name)) {
480                 struct net_device *dev
481                         = hlist_entry(p, struct net_device, name_hlist);
482                 if (!strncmp(dev->name, name, IFNAMSIZ))
483                         return dev;
484         }
485         return NULL;
486 }
487
488 /**
489  *      dev_get_by_name         - find a device by its name
490  *      @name: name to find
491  *
492  *      Find an interface by name. This can be called from any
493  *      context and does its own locking. The returned handle has
494  *      the usage count incremented and the caller must use dev_put() to
495  *      release it when it is no longer needed. %NULL is returned if no
496  *      matching device is found.
497  */
498
499 struct net_device *dev_get_by_name(const char *name)
500 {
501         struct net_device *dev;
502
503         read_lock(&dev_base_lock);
504         dev = __dev_get_by_name(name);
505         if (dev)
506                 dev_hold(dev);
507         read_unlock(&dev_base_lock);
508         return dev;
509 }
510
511 /**
512  *      __dev_get_by_index - find a device by its ifindex
513  *      @ifindex: index of device
514  *
515  *      Search for an interface by index. Returns %NULL if the device
516  *      is not found or a pointer to the device. The device has not
517  *      had its reference counter increased so the caller must be careful
518  *      about locking. The caller must hold either the RTNL semaphore
519  *      or @dev_base_lock.
520  */
521
522 struct net_device *__dev_get_by_index(int ifindex)
523 {
524         struct hlist_node *p;
525
526         hlist_for_each(p, dev_index_hash(ifindex)) {
527                 struct net_device *dev
528                         = hlist_entry(p, struct net_device, index_hlist);
529                 if (dev->ifindex == ifindex)
530                         return dev;
531         }
532         return NULL;
533 }
534
535
536 /**
537  *      dev_get_by_index - find a device by its ifindex
538  *      @ifindex: index of device
539  *
540  *      Search for an interface by index. Returns NULL if the device
541  *      is not found or a pointer to the device. The device returned has
542  *      had a reference added and the pointer is safe until the user calls
543  *      dev_put to indicate they have finished with it.
544  */
545
546 struct net_device *dev_get_by_index(int ifindex)
547 {
548         struct net_device *dev;
549
550         read_lock(&dev_base_lock);
551         dev = __dev_get_by_index(ifindex);
552         if (dev)
553                 dev_hold(dev);
554         read_unlock(&dev_base_lock);
555         return dev;
556 }
557
558 /**
559  *      dev_getbyhwaddr - find a device by its hardware address
560  *      @type: media type of device
561  *      @ha: hardware address
562  *
563  *      Search for an interface by MAC address. Returns NULL if the device
564  *      is not found or a pointer to the device. The caller must hold the
565  *      rtnl semaphore. The returned device has not had its ref count increased
566  *      and the caller must therefore be careful about locking
567  *
568  *      BUGS:
569  *      If the API was consistent this would be __dev_get_by_hwaddr
570  */
571
572 struct net_device *dev_getbyhwaddr(unsigned short type, char *ha)
573 {
574         struct net_device *dev;
575
576         ASSERT_RTNL();
577
578         for (dev = dev_base; dev; dev = dev->next)
579                 if (dev->type == type &&
580                     !memcmp(dev->dev_addr, ha, dev->addr_len))
581                         break;
582         return dev;
583 }
584
585 EXPORT_SYMBOL(dev_getbyhwaddr);
586
587 struct net_device *dev_getfirstbyhwtype(unsigned short type)
588 {
589         struct net_device *dev;
590
591         rtnl_lock();
592         for (dev = dev_base; dev; dev = dev->next) {
593                 if (dev->type == type) {
594                         dev_hold(dev);
595                         break;
596                 }
597         }
598         rtnl_unlock();
599         return dev;
600 }
601
602 EXPORT_SYMBOL(dev_getfirstbyhwtype);
603
604 /**
605  *      dev_get_by_flags - find any device with given flags
606  *      @if_flags: IFF_* values
607  *      @mask: bitmask of bits in if_flags to check
608  *
609  *      Search for any interface with the given flags. Returns NULL if a device
610  *      is not found or a pointer to the device. The device returned has 
611  *      had a reference added and the pointer is safe until the user calls
612  *      dev_put to indicate they have finished with it.
613  */
614
615 struct net_device * dev_get_by_flags(unsigned short if_flags, unsigned short mask)
616 {
617         struct net_device *dev;
618
619         read_lock(&dev_base_lock);
620         for (dev = dev_base; dev != NULL; dev = dev->next) {
621                 if (((dev->flags ^ if_flags) & mask) == 0) {
622                         dev_hold(dev);
623                         break;
624                 }
625         }
626         read_unlock(&dev_base_lock);
627         return dev;
628 }
629
630 /**
631  *      dev_valid_name - check if name is okay for network device
632  *      @name: name string
633  *
634  *      Network device names need to be valid file names to
635  *      to allow sysfs to work
636  */
637 int dev_valid_name(const char *name)
638 {
639         return !(*name == '\0' 
640                  || !strcmp(name, ".")
641                  || !strcmp(name, "..")
642                  || strchr(name, '/'));
643 }
644
645 /**
646  *      dev_alloc_name - allocate a name for a device
647  *      @dev: device
648  *      @name: name format string
649  *
650  *      Passed a format string - eg "lt%d" it will try and find a suitable
651  *      id. It scans list of devices to build up a free map, then chooses
652  *      the first empty slot. The caller must hold the dev_base or rtnl lock
653  *      while allocating the name and adding the device in order to avoid
654  *      duplicates.
655  *      Limited to bits_per_byte * page size devices (ie 32K on most platforms).
656  *      Returns the number of the unit assigned or a negative errno code.
657  */
658
659 int dev_alloc_name(struct net_device *dev, const char *name)
660 {
661         int i = 0;
662         char buf[IFNAMSIZ];
663         const char *p;
664         const int max_netdevices = 8*PAGE_SIZE;
665         long *inuse;
666         struct net_device *d;
667
668         p = strnchr(name, IFNAMSIZ-1, '%');
669         if (p) {
670                 /*
671                  * Verify the string as this thing may have come from
672                  * the user.  There must be either one "%d" and no other "%"
673                  * characters.
674                  */
675                 if (p[1] != 'd' || strchr(p + 2, '%'))
676                         return -EINVAL;
677
678                 /* Use one page as a bit array of possible slots */
679                 inuse = (long *) get_zeroed_page(GFP_ATOMIC);
680                 if (!inuse)
681                         return -ENOMEM;
682
683                 for (d = dev_base; d; d = d->next) {
684                         if (!sscanf(d->name, name, &i))
685                                 continue;
686                         if (i < 0 || i >= max_netdevices)
687                                 continue;
688
689                         /*  avoid cases where sscanf is not exact inverse of printf */
690                         snprintf(buf, sizeof(buf), name, i);
691                         if (!strncmp(buf, d->name, IFNAMSIZ))
692                                 set_bit(i, inuse);
693                 }
694
695                 i = find_first_zero_bit(inuse, max_netdevices);
696                 free_page((unsigned long) inuse);
697         }
698
699         snprintf(buf, sizeof(buf), name, i);
700         if (!__dev_get_by_name(buf)) {
701                 strlcpy(dev->name, buf, IFNAMSIZ);
702                 return i;
703         }
704
705         /* It is possible to run out of possible slots
706          * when the name is long and there isn't enough space left
707          * for the digits, or if all bits are used.
708          */
709         return -ENFILE;
710 }
711
712
713 /**
714  *      dev_change_name - change name of a device
715  *      @dev: device
716  *      @newname: name (or format string) must be at least IFNAMSIZ
717  *
718  *      Change name of a device, can pass format strings "eth%d".
719  *      for wildcarding.
720  */
721 int dev_change_name(struct net_device *dev, char *newname)
722 {
723         int err = 0;
724
725         ASSERT_RTNL();
726
727         if (dev->flags & IFF_UP)
728                 return -EBUSY;
729
730         if (!dev_valid_name(newname))
731                 return -EINVAL;
732
733         if (strchr(newname, '%')) {
734                 err = dev_alloc_name(dev, newname);
735                 if (err < 0)
736                         return err;
737                 strcpy(newname, dev->name);
738         }
739         else if (__dev_get_by_name(newname))
740                 return -EEXIST;
741         else
742                 strlcpy(dev->name, newname, IFNAMSIZ);
743
744         err = class_device_rename(&dev->class_dev, dev->name);
745         if (!err) {
746                 hlist_del(&dev->name_hlist);
747                 hlist_add_head(&dev->name_hlist, dev_name_hash(dev->name));
748                 raw_notifier_call_chain(&netdev_chain,
749                                 NETDEV_CHANGENAME, dev);
750         }
751
752         return err;
753 }
754
755 /**
756  *      netdev_features_change - device changes features
757  *      @dev: device to cause notification
758  *
759  *      Called to indicate a device has changed features.
760  */
761 void netdev_features_change(struct net_device *dev)
762 {
763         raw_notifier_call_chain(&netdev_chain, NETDEV_FEAT_CHANGE, dev);
764 }
765 EXPORT_SYMBOL(netdev_features_change);
766
767 /**
768  *      netdev_state_change - device changes state
769  *      @dev: device to cause notification
770  *
771  *      Called to indicate a device has changed state. This function calls
772  *      the notifier chains for netdev_chain and sends a NEWLINK message
773  *      to the routing socket.
774  */
775 void netdev_state_change(struct net_device *dev)
776 {
777         if (dev->flags & IFF_UP) {
778                 raw_notifier_call_chain(&netdev_chain,
779                                 NETDEV_CHANGE, dev);
780                 rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
781         }
782 }
783
784 /**
785  *      dev_load        - load a network module
786  *      @name: name of interface
787  *
788  *      If a network interface is not present and the process has suitable
789  *      privileges this function loads the module. If module loading is not
790  *      available in this kernel then it becomes a nop.
791  */
792
793 void dev_load(const char *name)
794 {
795         struct net_device *dev;  
796
797         read_lock(&dev_base_lock);
798         dev = __dev_get_by_name(name);
799         read_unlock(&dev_base_lock);
800
801         if (!dev && capable(CAP_SYS_MODULE))
802                 request_module("%s", name);
803 }
804
805 static int default_rebuild_header(struct sk_buff *skb)
806 {
807         printk(KERN_DEBUG "%s: default_rebuild_header called -- BUG!\n",
808                skb->dev ? skb->dev->name : "NULL!!!");
809         kfree_skb(skb);
810         return 1;
811 }
812
813
814 /**
815  *      dev_open        - prepare an interface for use.
816  *      @dev:   device to open
817  *
818  *      Takes a device from down to up state. The device's private open
819  *      function is invoked and then the multicast lists are loaded. Finally
820  *      the device is moved into the up state and a %NETDEV_UP message is
821  *      sent to the netdev notifier chain.
822  *
823  *      Calling this function on an active interface is a nop. On a failure
824  *      a negative errno code is returned.
825  */
826 int dev_open(struct net_device *dev)
827 {
828         int ret = 0;
829
830         /*
831          *      Is it already up?
832          */
833
834         if (dev->flags & IFF_UP)
835                 return 0;
836
837         /*
838          *      Is it even present?
839          */
840         if (!netif_device_present(dev))
841                 return -ENODEV;
842
843         /*
844          *      Call device private open method
845          */
846         set_bit(__LINK_STATE_START, &dev->state);
847         if (dev->open) {
848                 ret = dev->open(dev);
849                 if (ret)
850                         clear_bit(__LINK_STATE_START, &dev->state);
851         }
852
853         /*
854          *      If it went open OK then:
855          */
856
857         if (!ret) {
858                 /*
859                  *      Set the flags.
860                  */
861                 dev->flags |= IFF_UP;
862
863                 /*
864                  *      Initialize multicasting status
865                  */
866                 dev_mc_upload(dev);
867
868                 /*
869                  *      Wakeup transmit queue engine
870                  */
871                 dev_activate(dev);
872
873                 /*
874                  *      ... and announce new interface.
875                  */
876                 raw_notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
877         }
878         return ret;
879 }
880
881 /**
882  *      dev_close - shutdown an interface.
883  *      @dev: device to shutdown
884  *
885  *      This function moves an active device into down state. A
886  *      %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device
887  *      is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
888  *      chain.
889  */
890 int dev_close(struct net_device *dev)
891 {
892         if (!(dev->flags & IFF_UP))
893                 return 0;
894
895         /*
896          *      Tell people we are going down, so that they can
897          *      prepare to death, when device is still operating.
898          */
899         raw_notifier_call_chain(&netdev_chain, NETDEV_GOING_DOWN, dev);
900
901         dev_deactivate(dev);
902
903         clear_bit(__LINK_STATE_START, &dev->state);
904
905         /* Synchronize to scheduled poll. We cannot touch poll list,
906          * it can be even on different cpu. So just clear netif_running(),
907          * and wait when poll really will happen. Actually, the best place
908          * for this is inside dev->stop() after device stopped its irq
909          * engine, but this requires more changes in devices. */
910
911         smp_mb__after_clear_bit(); /* Commit netif_running(). */
912         while (test_bit(__LINK_STATE_RX_SCHED, &dev->state)) {
913                 /* No hurry. */
914                 msleep(1);
915         }
916
917         /*
918          *      Call the device specific close. This cannot fail.
919          *      Only if device is UP
920          *
921          *      We allow it to be called even after a DETACH hot-plug
922          *      event.
923          */
924         if (dev->stop)
925                 dev->stop(dev);
926
927         /*
928          *      Device is now down.
929          */
930
931         dev->flags &= ~IFF_UP;
932
933         /*
934          * Tell people we are down
935          */
936         raw_notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
937
938         return 0;
939 }
940
941
942 /*
943  *      Device change register/unregister. These are not inline or static
944  *      as we export them to the world.
945  */
946
947 /**
948  *      register_netdevice_notifier - register a network notifier block
949  *      @nb: notifier
950  *
951  *      Register a notifier to be called when network device events occur.
952  *      The notifier passed is linked into the kernel structures and must
953  *      not be reused until it has been unregistered. A negative errno code
954  *      is returned on a failure.
955  *
956  *      When registered all registration and up events are replayed
957  *      to the new notifier to allow device to have a race free 
958  *      view of the network device list.
959  */
960
961 int register_netdevice_notifier(struct notifier_block *nb)
962 {
963         struct net_device *dev;
964         int err;
965
966         rtnl_lock();
967         err = raw_notifier_chain_register(&netdev_chain, nb);
968         if (!err) {
969                 for (dev = dev_base; dev; dev = dev->next) {
970                         nb->notifier_call(nb, NETDEV_REGISTER, dev);
971
972                         if (dev->flags & IFF_UP) 
973                                 nb->notifier_call(nb, NETDEV_UP, dev);
974                 }
975         }
976         rtnl_unlock();
977         return err;
978 }
979
980 /**
981  *      unregister_netdevice_notifier - unregister a network notifier block
982  *      @nb: notifier
983  *
984  *      Unregister a notifier previously registered by
985  *      register_netdevice_notifier(). The notifier is unlinked into the
986  *      kernel structures and may then be reused. A negative errno code
987  *      is returned on a failure.
988  */
989
990 int unregister_netdevice_notifier(struct notifier_block *nb)
991 {
992         int err;
993
994         rtnl_lock();
995         err = raw_notifier_chain_unregister(&netdev_chain, nb);
996         rtnl_unlock();
997         return err;
998 }
999
1000 /**
1001  *      call_netdevice_notifiers - call all network notifier blocks
1002  *      @val: value passed unmodified to notifier function
1003  *      @v:   pointer passed unmodified to notifier function
1004  *
1005  *      Call all network notifier blocks.  Parameters and return value
1006  *      are as for raw_notifier_call_chain().
1007  */
1008
1009 int call_netdevice_notifiers(unsigned long val, void *v)
1010 {
1011         return raw_notifier_call_chain(&netdev_chain, val, v);
1012 }
1013
1014 /* When > 0 there are consumers of rx skb time stamps */
1015 static atomic_t netstamp_needed = ATOMIC_INIT(0);
1016
1017 void net_enable_timestamp(void)
1018 {
1019         atomic_inc(&netstamp_needed);
1020 }
1021
1022 void net_disable_timestamp(void)
1023 {
1024         atomic_dec(&netstamp_needed);
1025 }
1026
1027 void __net_timestamp(struct sk_buff *skb)
1028 {
1029         struct timeval tv;
1030
1031         do_gettimeofday(&tv);
1032         skb_set_timestamp(skb, &tv);
1033 }
1034 EXPORT_SYMBOL(__net_timestamp);
1035
1036 static inline void net_timestamp(struct sk_buff *skb)
1037 {
1038         if (atomic_read(&netstamp_needed))
1039                 __net_timestamp(skb);
1040         else {
1041                 skb->tstamp.off_sec = 0;
1042                 skb->tstamp.off_usec = 0;
1043         }
1044 }
1045
1046 /*
1047  *      Support routine. Sends outgoing frames to any network
1048  *      taps currently in use.
1049  */
1050
1051 static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
1052 {
1053         struct packet_type *ptype;
1054
1055         net_timestamp(skb);
1056
1057         rcu_read_lock();
1058         list_for_each_entry_rcu(ptype, &ptype_all, list) {
1059                 /* Never send packets back to the socket
1060                  * they originated from - MvS (miquels@drinkel.ow.org)
1061                  */
1062                 if ((ptype->dev == dev || !ptype->dev) &&
1063                     (ptype->af_packet_priv == NULL ||
1064                      (struct sock *)ptype->af_packet_priv != skb->sk)) {
1065                         struct sk_buff *skb2= skb_clone(skb, GFP_ATOMIC);
1066                         if (!skb2)
1067                                 break;
1068
1069                         /* skb->nh should be correctly
1070                            set by sender, so that the second statement is
1071                            just protection against buggy protocols.
1072                          */
1073                         skb2->mac.raw = skb2->data;
1074
1075                         if (skb2->nh.raw < skb2->data ||
1076                             skb2->nh.raw > skb2->tail) {
1077                                 if (net_ratelimit())
1078                                         printk(KERN_CRIT "protocol %04x is "
1079                                                "buggy, dev %s\n",
1080                                                skb2->protocol, dev->name);
1081                                 skb2->nh.raw = skb2->data;
1082                         }
1083
1084                         skb2->h.raw = skb2->nh.raw;
1085                         skb2->pkt_type = PACKET_OUTGOING;
1086                         ptype->func(skb2, skb->dev, ptype, skb->dev);
1087                 }
1088         }
1089         rcu_read_unlock();
1090 }
1091
1092
1093 void __netif_schedule(struct net_device *dev)
1094 {
1095         if (!test_and_set_bit(__LINK_STATE_SCHED, &dev->state)) {
1096                 unsigned long flags;
1097                 struct softnet_data *sd;
1098
1099                 local_irq_save(flags);
1100                 sd = &__get_cpu_var(softnet_data);
1101                 dev->next_sched = sd->output_queue;
1102                 sd->output_queue = dev;
1103                 raise_softirq_irqoff(NET_TX_SOFTIRQ);
1104                 local_irq_restore(flags);
1105         }
1106 }
1107 EXPORT_SYMBOL(__netif_schedule);
1108
1109 void __netif_rx_schedule(struct net_device *dev)
1110 {
1111         unsigned long flags;
1112
1113         local_irq_save(flags);
1114         dev_hold(dev);
1115         list_add_tail(&dev->poll_list, &__get_cpu_var(softnet_data).poll_list);
1116         if (dev->quota < 0)
1117                 dev->quota += dev->weight;
1118         else
1119                 dev->quota = dev->weight;
1120         __raise_softirq_irqoff(NET_RX_SOFTIRQ);
1121         local_irq_restore(flags);
1122 }
1123 EXPORT_SYMBOL(__netif_rx_schedule);
1124
1125 void dev_kfree_skb_any(struct sk_buff *skb)
1126 {
1127         if (in_irq() || irqs_disabled())
1128                 dev_kfree_skb_irq(skb);
1129         else
1130                 dev_kfree_skb(skb);
1131 }
1132 EXPORT_SYMBOL(dev_kfree_skb_any);
1133
1134
1135 /* Hot-plugging. */
1136 void netif_device_detach(struct net_device *dev)
1137 {
1138         if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) &&
1139             netif_running(dev)) {
1140                 netif_stop_queue(dev);
1141         }
1142 }
1143 EXPORT_SYMBOL(netif_device_detach);
1144
1145 void netif_device_attach(struct net_device *dev)
1146 {
1147         if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) &&
1148             netif_running(dev)) {
1149                 netif_wake_queue(dev);
1150                 __netdev_watchdog_up(dev);
1151         }
1152 }
1153 EXPORT_SYMBOL(netif_device_attach);
1154
1155
1156 /*
1157  * Invalidate hardware checksum when packet is to be mangled, and
1158  * complete checksum manually on outgoing path.
1159  */
1160 int skb_checksum_help(struct sk_buff *skb, int inward)
1161 {
1162         unsigned int csum;
1163         int ret = 0, offset = skb->h.raw - skb->data;
1164
1165         if (inward) {
1166                 skb->ip_summed = CHECKSUM_NONE;
1167                 goto out;
1168         }
1169
1170         if (skb_cloned(skb)) {
1171                 ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1172                 if (ret)
1173                         goto out;
1174         }
1175
1176         BUG_ON(offset > (int)skb->len);
1177         csum = skb_checksum(skb, offset, skb->len-offset, 0);
1178
1179         offset = skb->tail - skb->h.raw;
1180         BUG_ON(offset <= 0);
1181         BUG_ON(skb->csum + 2 > offset);
1182
1183         *(u16*)(skb->h.raw + skb->csum) = csum_fold(csum);
1184         skb->ip_summed = CHECKSUM_NONE;
1185 out:    
1186         return ret;
1187 }
1188
1189 /**
1190  *      skb_gso_segment - Perform segmentation on skb.
1191  *      @skb: buffer to segment
1192  *      @features: features for the output path (see dev->features)
1193  *
1194  *      This function segments the given skb and returns a list of segments.
1195  *
1196  *      It may return NULL if the skb requires no segmentation.  This is
1197  *      only possible when GSO is used for verifying header integrity.
1198  */
1199 struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features)
1200 {
1201         struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT);
1202         struct packet_type *ptype;
1203         int type = skb->protocol;
1204
1205         BUG_ON(skb_shinfo(skb)->frag_list);
1206         BUG_ON(skb->ip_summed != CHECKSUM_HW);
1207
1208         skb->mac.raw = skb->data;
1209         skb->mac_len = skb->nh.raw - skb->data;
1210         __skb_pull(skb, skb->mac_len);
1211
1212         rcu_read_lock();
1213         list_for_each_entry_rcu(ptype, &ptype_base[ntohs(type) & 15], list) {
1214                 if (ptype->type == type && !ptype->dev && ptype->gso_segment) {
1215                         segs = ptype->gso_segment(skb, features);
1216                         break;
1217                 }
1218         }
1219         rcu_read_unlock();
1220
1221         __skb_push(skb, skb->data - skb->mac.raw);
1222
1223         return segs;
1224 }
1225
1226 EXPORT_SYMBOL(skb_gso_segment);
1227
1228 /* Take action when hardware reception checksum errors are detected. */
1229 #ifdef CONFIG_BUG
1230 void netdev_rx_csum_fault(struct net_device *dev)
1231 {
1232         if (net_ratelimit()) {
1233                 printk(KERN_ERR "%s: hw csum failure.\n", 
1234                         dev ? dev->name : "<unknown>");
1235                 dump_stack();
1236         }
1237 }
1238 EXPORT_SYMBOL(netdev_rx_csum_fault);
1239 #endif
1240
1241 #ifdef CONFIG_HIGHMEM
1242 /* Actually, we should eliminate this check as soon as we know, that:
1243  * 1. IOMMU is present and allows to map all the memory.
1244  * 2. No high memory really exists on this machine.
1245  */
1246
1247 static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
1248 {
1249         int i;
1250
1251         if (dev->features & NETIF_F_HIGHDMA)
1252                 return 0;
1253
1254         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
1255                 if (PageHighMem(skb_shinfo(skb)->frags[i].page))
1256                         return 1;
1257
1258         return 0;
1259 }
1260 #else
1261 #define illegal_highdma(dev, skb)       (0)
1262 #endif
1263
1264 struct dev_gso_cb {
1265         void (*destructor)(struct sk_buff *skb);
1266 };
1267
1268 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
1269
1270 static void dev_gso_skb_destructor(struct sk_buff *skb)
1271 {
1272         struct dev_gso_cb *cb;
1273
1274         do {
1275                 struct sk_buff *nskb = skb->next;
1276
1277                 skb->next = nskb->next;
1278                 nskb->next = NULL;
1279                 kfree_skb(nskb);
1280         } while (skb->next);
1281
1282         cb = DEV_GSO_CB(skb);
1283         if (cb->destructor)
1284                 cb->destructor(skb);
1285 }
1286
1287 /**
1288  *      dev_gso_segment - Perform emulated hardware segmentation on skb.
1289  *      @skb: buffer to segment
1290  *
1291  *      This function segments the given skb and stores the list of segments
1292  *      in skb->next.
1293  */
1294 static int dev_gso_segment(struct sk_buff *skb)
1295 {
1296         struct net_device *dev = skb->dev;
1297         struct sk_buff *segs;
1298         int features = dev->features & ~(illegal_highdma(dev, skb) ?
1299                                          NETIF_F_SG : 0);
1300
1301         segs = skb_gso_segment(skb, features);
1302
1303         /* Verifying header integrity only. */
1304         if (!segs)
1305                 return 0;
1306
1307         if (unlikely(IS_ERR(segs)))
1308                 return PTR_ERR(segs);
1309
1310         skb->next = segs;
1311         DEV_GSO_CB(skb)->destructor = skb->destructor;
1312         skb->destructor = dev_gso_skb_destructor;
1313
1314         return 0;
1315 }
1316
1317 int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1318 {
1319         if (likely(!skb->next)) {
1320                 if (netdev_nit)
1321                         dev_queue_xmit_nit(skb, dev);
1322
1323                 if (netif_needs_gso(dev, skb)) {
1324                         if (unlikely(dev_gso_segment(skb)))
1325                                 goto out_kfree_skb;
1326                         if (skb->next)
1327                                 goto gso;
1328                 }
1329
1330                 return dev->hard_start_xmit(skb, dev);
1331         }
1332
1333 gso:
1334         do {
1335                 struct sk_buff *nskb = skb->next;
1336                 int rc;
1337
1338                 skb->next = nskb->next;
1339                 nskb->next = NULL;
1340                 rc = dev->hard_start_xmit(nskb, dev);
1341                 if (unlikely(rc)) {
1342                         nskb->next = skb->next;
1343                         skb->next = nskb;
1344                         return rc;
1345                 }
1346                 if (unlikely(netif_queue_stopped(dev) && skb->next))
1347                         return NETDEV_TX_BUSY;
1348         } while (skb->next);
1349         
1350         skb->destructor = DEV_GSO_CB(skb)->destructor;
1351
1352 out_kfree_skb:
1353         kfree_skb(skb);
1354         return 0;
1355 }
1356
1357 #define HARD_TX_LOCK(dev, cpu) {                        \
1358         if ((dev->features & NETIF_F_LLTX) == 0) {      \
1359                 netif_tx_lock(dev);                     \
1360         }                                               \
1361 }
1362
1363 #define HARD_TX_UNLOCK(dev) {                           \
1364         if ((dev->features & NETIF_F_LLTX) == 0) {      \
1365                 netif_tx_unlock(dev);                   \
1366         }                                               \
1367 }
1368
1369 #ifdef CONFIG_XEN
1370 inline int skb_checksum_setup(struct sk_buff *skb)
1371 {
1372         if (skb->proto_csum_blank) {
1373                 if (skb->protocol != htons(ETH_P_IP))
1374                         goto out;
1375                 skb->h.raw = (unsigned char *)skb->nh.iph + 4*skb->nh.iph->ihl;
1376                 if (skb->h.raw >= skb->tail)
1377                         goto out;
1378                 switch (skb->nh.iph->protocol) {
1379                 case IPPROTO_TCP:
1380                         skb->csum = offsetof(struct tcphdr, check);
1381                         break;
1382                 case IPPROTO_UDP:
1383                         skb->csum = offsetof(struct udphdr, check);
1384                         break;
1385                 default:
1386                         if (net_ratelimit())
1387                                 printk(KERN_ERR "Attempting to checksum a non-"
1388                                        "TCP/UDP packet, dropping a protocol"
1389                                        " %d packet", skb->nh.iph->protocol);
1390                         goto out;
1391                 }
1392                 if ((skb->h.raw + skb->csum + 2) > skb->tail)
1393                         goto out;
1394                 skb->ip_summed = CHECKSUM_HW;
1395                 skb->proto_csum_blank = 0;
1396         }
1397         return 0;
1398 out:
1399         return -EPROTO;
1400 }
1401 #else
1402 inline int skb_checksum_setup(struct sk_buff *skb) { return 0; }
1403 #endif
1404
1405
1406 /**
1407  *      dev_queue_xmit - transmit a buffer
1408  *      @skb: buffer to transmit
1409  *
1410  *      Queue a buffer for transmission to a network device. The caller must
1411  *      have set the device and priority and built the buffer before calling
1412  *      this function. The function can be called from an interrupt.
1413  *
1414  *      A negative errno code is returned on a failure. A success does not
1415  *      guarantee the frame will be transmitted as it may be dropped due
1416  *      to congestion or traffic shaping.
1417  *
1418  * -----------------------------------------------------------------------------------
1419  *      I notice this method can also return errors from the queue disciplines,
1420  *      including NET_XMIT_DROP, which is a positive value.  So, errors can also
1421  *      be positive.
1422  *
1423  *      Regardless of the return value, the skb is consumed, so it is currently
1424  *      difficult to retry a send to this method.  (You can bump the ref count
1425  *      before sending to hold a reference for retry if you are careful.)
1426  *
1427  *      When calling this method, interrupts MUST be enabled.  This is because
1428  *      the BH enable code must have IRQs enabled so that it will not deadlock.
1429  *          --BLG
1430  */
1431
1432 int dev_queue_xmit(struct sk_buff *skb)
1433 {
1434         struct net_device *dev = skb->dev;
1435         struct Qdisc *q;
1436         int rc = -ENOMEM;
1437
1438         /* If a checksum-deferred packet is forwarded to a device that needs a
1439          * checksum, correct the pointers and force checksumming.
1440          */
1441         if (skb_checksum_setup(skb))
1442                 goto out_kfree_skb;
1443
1444         /* GSO will handle the following emulations directly. */
1445         if (netif_needs_gso(dev, skb))
1446                 goto gso;
1447
1448         if (skb_shinfo(skb)->frag_list &&
1449             !(dev->features & NETIF_F_FRAGLIST) &&
1450             __skb_linearize(skb))
1451                 goto out_kfree_skb;
1452
1453         /* Fragmented skb is linearized if device does not support SG,
1454          * or if at least one of fragments is in highmem and device
1455          * does not support DMA from it.
1456          */
1457         if (skb_shinfo(skb)->nr_frags &&
1458             (!(dev->features & NETIF_F_SG) || illegal_highdma(dev, skb)) &&
1459             __skb_linearize(skb))
1460                 goto out_kfree_skb;
1461
1462         /* If packet is not checksummed and device does not support
1463          * checksumming for this protocol, complete checksumming here.
1464          */
1465         if (skb->ip_summed == CHECKSUM_HW &&
1466             (!(dev->features & NETIF_F_GEN_CSUM) &&
1467              (!(dev->features & NETIF_F_IP_CSUM) ||
1468               skb->protocol != htons(ETH_P_IP))))
1469                 if (skb_checksum_help(skb, 0))
1470                         goto out_kfree_skb;
1471
1472 gso:
1473         spin_lock_prefetch(&dev->queue_lock);
1474
1475         /* Disable soft irqs for various locks below. Also 
1476          * stops preemption for RCU. 
1477          */
1478         rcu_read_lock_bh(); 
1479
1480         /* Updates of qdisc are serialized by queue_lock. 
1481          * The struct Qdisc which is pointed to by qdisc is now a 
1482          * rcu structure - it may be accessed without acquiring 
1483          * a lock (but the structure may be stale.) The freeing of the
1484          * qdisc will be deferred until it's known that there are no 
1485          * more references to it.
1486          * 
1487          * If the qdisc has an enqueue function, we still need to 
1488          * hold the queue_lock before calling it, since queue_lock
1489          * also serializes access to the device queue.
1490          */
1491
1492         q = rcu_dereference(dev->qdisc);
1493 #ifdef CONFIG_NET_CLS_ACT
1494         skb->tc_verd = SET_TC_AT(skb->tc_verd,AT_EGRESS);
1495 #endif
1496         if (q->enqueue) {
1497                 /* Grab device queue */
1498                 spin_lock(&dev->queue_lock);
1499
1500                 rc = q->enqueue(skb, q);
1501
1502                 qdisc_run(dev);
1503
1504                 spin_unlock(&dev->queue_lock);
1505                 rc = rc == NET_XMIT_BYPASS ? NET_XMIT_SUCCESS : rc;
1506                 goto out;
1507         }
1508
1509         /* The device has no queue. Common case for software devices:
1510            loopback, all the sorts of tunnels...
1511
1512            Really, it is unlikely that netif_tx_lock protection is necessary
1513            here.  (f.e. loopback and IP tunnels are clean ignoring statistics
1514            counters.)
1515            However, it is possible, that they rely on protection
1516            made by us here.
1517
1518            Check this and shot the lock. It is not prone from deadlocks.
1519            Either shot noqueue qdisc, it is even simpler 8)
1520          */
1521         if (dev->flags & IFF_UP) {
1522                 int cpu = smp_processor_id(); /* ok because BHs are off */
1523
1524                 if (dev->xmit_lock_owner != cpu) {
1525
1526                         HARD_TX_LOCK(dev, cpu);
1527
1528                         if (!netif_queue_stopped(dev)) {
1529                                 rc = 0;
1530                                 if (!dev_hard_start_xmit(skb, dev)) {
1531                                         HARD_TX_UNLOCK(dev);
1532                                         goto out;
1533                                 }
1534                         }
1535                         HARD_TX_UNLOCK(dev);
1536                         if (net_ratelimit())
1537                                 printk(KERN_CRIT "Virtual device %s asks to "
1538                                        "queue packet!\n", dev->name);
1539                 } else {
1540                         /* Recursion is detected! It is possible,
1541                          * unfortunately */
1542                         if (net_ratelimit())
1543                                 printk(KERN_CRIT "Dead loop on virtual device "
1544                                        "%s, fix it urgently!\n", dev->name);
1545                 }
1546         }
1547
1548         rc = -ENETDOWN;
1549         rcu_read_unlock_bh();
1550
1551 out_kfree_skb:
1552         kfree_skb(skb);
1553         return rc;
1554 out:
1555         rcu_read_unlock_bh();
1556         return rc;
1557 }
1558
1559
1560 /*=======================================================================
1561                         Receiver routines
1562   =======================================================================*/
1563
1564 int netdev_max_backlog = 1000;
1565 int netdev_budget = 300;
1566 int weight_p = 64;            /* old backlog weight */
1567
1568 DEFINE_PER_CPU(struct netif_rx_stats, netdev_rx_stat) = { 0, };
1569
1570
1571 /**
1572  *      netif_rx        -       post buffer to the network code
1573  *      @skb: buffer to post
1574  *
1575  *      This function receives a packet from a device driver and queues it for
1576  *      the upper (protocol) levels to process.  It always succeeds. The buffer
1577  *      may be dropped during processing for congestion control or by the
1578  *      protocol layers.
1579  *
1580  *      return values:
1581  *      NET_RX_SUCCESS  (no congestion)
1582  *      NET_RX_CN_LOW   (low congestion)
1583  *      NET_RX_CN_MOD   (moderate congestion)
1584  *      NET_RX_CN_HIGH  (high congestion)
1585  *      NET_RX_DROP     (packet was dropped)
1586  *
1587  */
1588
1589 int netif_rx(struct sk_buff *skb)
1590 {
1591         struct softnet_data *queue;
1592         unsigned long flags;
1593
1594         /* if netpoll wants it, pretend we never saw it */
1595         if (netpoll_rx(skb))
1596                 return NET_RX_DROP;
1597
1598         if (!skb->tstamp.off_sec)
1599                 net_timestamp(skb);
1600
1601         /*
1602          * The code is rearranged so that the path is the most
1603          * short when CPU is congested, but is still operating.
1604          */
1605         local_irq_save(flags);
1606         queue = &__get_cpu_var(softnet_data);
1607
1608         __get_cpu_var(netdev_rx_stat).total++;
1609         if (queue->input_pkt_queue.qlen <= netdev_max_backlog) {
1610                 if (queue->input_pkt_queue.qlen) {
1611 enqueue:
1612                         dev_hold(skb->dev);
1613                         __skb_queue_tail(&queue->input_pkt_queue, skb);
1614                         local_irq_restore(flags);
1615                         return NET_RX_SUCCESS;
1616                 }
1617
1618                 netif_rx_schedule(&queue->backlog_dev);
1619                 goto enqueue;
1620         }
1621
1622         __get_cpu_var(netdev_rx_stat).dropped++;
1623         local_irq_restore(flags);
1624
1625         kfree_skb(skb);
1626         return NET_RX_DROP;
1627 }
1628
1629 int netif_rx_ni(struct sk_buff *skb)
1630 {
1631         int err;
1632
1633         preempt_disable();
1634         err = netif_rx(skb);
1635         if (local_softirq_pending())
1636                 do_softirq();
1637         preempt_enable();
1638
1639         return err;
1640 }
1641
1642 EXPORT_SYMBOL(netif_rx_ni);
1643
1644 static inline struct net_device *skb_bond(struct sk_buff *skb)
1645 {
1646         struct net_device *dev = skb->dev;
1647
1648         if (dev->master) {
1649                 /*
1650                  * On bonding slaves other than the currently active
1651                  * slave, suppress duplicates except for 802.3ad
1652                  * ETH_P_SLOW and alb non-mcast/bcast.
1653                  */
1654                 if (dev->priv_flags & IFF_SLAVE_INACTIVE) {
1655                         if (dev->master->priv_flags & IFF_MASTER_ALB) {
1656                                 if (skb->pkt_type != PACKET_BROADCAST &&
1657                                     skb->pkt_type != PACKET_MULTICAST)
1658                                         goto keep;
1659                         }
1660
1661                         if (dev->master->priv_flags & IFF_MASTER_8023AD &&
1662                             skb->protocol == __constant_htons(ETH_P_SLOW))
1663                                 goto keep;
1664                 
1665                         kfree_skb(skb);
1666                         return NULL;
1667                 }
1668 keep:
1669                 skb->dev = dev->master;
1670         }
1671
1672         return dev;
1673 }
1674
1675 static void net_tx_action(struct softirq_action *h)
1676 {
1677         struct softnet_data *sd = &__get_cpu_var(softnet_data);
1678
1679         if (sd->completion_queue) {
1680                 struct sk_buff *clist;
1681
1682                 local_irq_disable();
1683                 clist = sd->completion_queue;
1684                 sd->completion_queue = NULL;
1685                 local_irq_enable();
1686
1687                 while (clist) {
1688                         struct sk_buff *skb = clist;
1689                         clist = clist->next;
1690
1691                         BUG_TRAP(!atomic_read(&skb->users));
1692                         __kfree_skb(skb);
1693                 }
1694         }
1695
1696         if (sd->output_queue) {
1697                 struct net_device *head;
1698
1699                 local_irq_disable();
1700                 head = sd->output_queue;
1701                 sd->output_queue = NULL;
1702                 local_irq_enable();
1703
1704                 while (head) {
1705                         struct net_device *dev = head;
1706                         head = head->next_sched;
1707
1708                         smp_mb__before_clear_bit();
1709                         clear_bit(__LINK_STATE_SCHED, &dev->state);
1710
1711                         if (spin_trylock(&dev->queue_lock)) {
1712                                 qdisc_run(dev);
1713                                 spin_unlock(&dev->queue_lock);
1714                         } else {
1715                                 netif_schedule(dev);
1716                         }
1717                 }
1718         }
1719 }
1720
1721 static __inline__ int deliver_skb(struct sk_buff *skb,
1722                                   struct packet_type *pt_prev,
1723                                   struct net_device *orig_dev)
1724 {
1725         atomic_inc(&skb->users);
1726         return pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
1727 }
1728
1729 #if defined(CONFIG_BRIDGE) || defined (CONFIG_BRIDGE_MODULE)
1730 int (*br_handle_frame_hook)(struct net_bridge_port *p, struct sk_buff **pskb);
1731 struct net_bridge;
1732 struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
1733                                                 unsigned char *addr);
1734 void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent);
1735
1736 static __inline__ int handle_bridge(struct sk_buff **pskb,
1737                                     struct packet_type **pt_prev, int *ret,
1738                                     struct net_device *orig_dev)
1739 {
1740         struct net_bridge_port *port;
1741
1742         if ((*pskb)->pkt_type == PACKET_LOOPBACK ||
1743             (port = rcu_dereference((*pskb)->dev->br_port)) == NULL)
1744                 return 0;
1745
1746         if (*pt_prev) {
1747                 *ret = deliver_skb(*pskb, *pt_prev, orig_dev);
1748                 *pt_prev = NULL;
1749         } 
1750         
1751         return br_handle_frame_hook(port, pskb);
1752 }
1753 #else
1754 #define handle_bridge(skb, pt_prev, ret, orig_dev)      (0)
1755 #endif
1756
1757 #ifdef CONFIG_NET_CLS_ACT
1758 /* TODO: Maybe we should just force sch_ingress to be compiled in
1759  * when CONFIG_NET_CLS_ACT is? otherwise some useless instructions
1760  * a compare and 2 stores extra right now if we dont have it on
1761  * but have CONFIG_NET_CLS_ACT
1762  * NOTE: This doesnt stop any functionality; if you dont have 
1763  * the ingress scheduler, you just cant add policies on ingress.
1764  *
1765  */
1766 static int ing_filter(struct sk_buff *skb) 
1767 {
1768         struct Qdisc *q;
1769         struct net_device *dev = skb->dev;
1770         int result = TC_ACT_OK;
1771         
1772         if (dev->qdisc_ingress) {
1773                 __u32 ttl = (__u32) G_TC_RTTL(skb->tc_verd);
1774                 if (MAX_RED_LOOP < ttl++) {
1775                         printk("Redir loop detected Dropping packet (%s->%s)\n",
1776                                 skb->input_dev->name, skb->dev->name);
1777                         return TC_ACT_SHOT;
1778                 }
1779
1780                 skb->tc_verd = SET_TC_RTTL(skb->tc_verd,ttl);
1781
1782                 skb->tc_verd = SET_TC_AT(skb->tc_verd,AT_INGRESS);
1783
1784                 spin_lock(&dev->ingress_lock);
1785                 if ((q = dev->qdisc_ingress) != NULL)
1786                         result = q->enqueue(skb, q);
1787                 spin_unlock(&dev->ingress_lock);
1788
1789         }
1790
1791         return result;
1792 }
1793 #endif
1794
1795 int netif_receive_skb(struct sk_buff *skb)
1796 {
1797         struct packet_type *ptype, *pt_prev;
1798         struct net_device *orig_dev;
1799         int ret = NET_RX_DROP;
1800         unsigned short type;
1801
1802         /* if we've gotten here through NAPI, check netpoll */
1803         if (skb->dev->poll && netpoll_rx(skb))
1804                 return NET_RX_DROP;
1805
1806         if (!skb->tstamp.off_sec)
1807                 net_timestamp(skb);
1808
1809         if (!skb->input_dev)
1810                 skb->input_dev = skb->dev;
1811
1812         orig_dev = skb_bond(skb);
1813
1814         if (!orig_dev)
1815                 return NET_RX_DROP;
1816
1817         __get_cpu_var(netdev_rx_stat).total++;
1818
1819         skb->h.raw = skb->nh.raw = skb->data;
1820         skb->mac_len = skb->nh.raw - skb->mac.raw;
1821
1822         pt_prev = NULL;
1823
1824         rcu_read_lock();
1825
1826 #ifdef CONFIG_NET_CLS_ACT
1827         if (skb->tc_verd & TC_NCLS) {
1828                 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
1829                 goto ncls;
1830         }
1831 #endif
1832
1833 #ifdef CONFIG_XEN
1834         switch (skb->ip_summed) {
1835         case CHECKSUM_UNNECESSARY:
1836                 skb->proto_data_valid = 1;
1837                 break;
1838         case CHECKSUM_HW:
1839                 /* XXX Implement me. */
1840         default:
1841                 skb->proto_data_valid = 0;
1842                 break;
1843         }
1844 #endif
1845
1846         list_for_each_entry_rcu(ptype, &ptype_all, list) {
1847                 if (!ptype->dev || ptype->dev == skb->dev) {
1848                         if (pt_prev) 
1849                                 ret = deliver_skb(skb, pt_prev, orig_dev);
1850                         pt_prev = ptype;
1851                 }
1852         }
1853
1854 #ifdef CONFIG_NET_CLS_ACT
1855         if (pt_prev) {
1856                 ret = deliver_skb(skb, pt_prev, orig_dev);
1857                 pt_prev = NULL; /* noone else should process this after*/
1858         } else {
1859                 skb->tc_verd = SET_TC_OK2MUNGE(skb->tc_verd);
1860         }
1861
1862         ret = ing_filter(skb);
1863
1864         if (ret == TC_ACT_SHOT || (ret == TC_ACT_STOLEN)) {
1865                 kfree_skb(skb);
1866                 goto out;
1867         }
1868
1869         skb->tc_verd = 0;
1870 ncls:
1871 #endif
1872
1873         handle_diverter(skb);
1874
1875         if (handle_bridge(&skb, &pt_prev, &ret, orig_dev))
1876                 goto out;
1877
1878         type = skb->protocol;
1879         list_for_each_entry_rcu(ptype, &ptype_base[ntohs(type)&15], list) {
1880                 if (ptype->type == type &&
1881                     (!ptype->dev || ptype->dev == skb->dev)) {
1882                         if (pt_prev) 
1883                                 ret = deliver_skb(skb, pt_prev, orig_dev);
1884                         pt_prev = ptype;
1885                 }
1886         }
1887
1888         if (pt_prev) {
1889                 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
1890         } else {
1891                 kfree_skb(skb);
1892                 /* Jamal, now you will not able to escape explaining
1893                  * me how you were going to use this. :-)
1894                  */
1895                 ret = NET_RX_DROP;
1896         }
1897
1898 out:
1899         rcu_read_unlock();
1900         return ret;
1901 }
1902
1903 static int process_backlog(struct net_device *backlog_dev, int *budget)
1904 {
1905         int work = 0;
1906         int quota = min(backlog_dev->quota, *budget);
1907         struct softnet_data *queue = &__get_cpu_var(softnet_data);
1908         unsigned long start_time = jiffies;
1909
1910         backlog_dev->weight = weight_p;
1911         for (;;) {
1912                 struct sk_buff *skb;
1913                 struct net_device *dev;
1914
1915                 local_irq_disable();
1916                 skb = __skb_dequeue(&queue->input_pkt_queue);
1917                 if (!skb)
1918                         goto job_done;
1919                 local_irq_enable();
1920
1921                 dev = skb->dev;
1922
1923                 netif_receive_skb(skb);
1924
1925                 dev_put(dev);
1926
1927                 work++;
1928
1929                 if (work >= quota || jiffies - start_time > 1)
1930                         break;
1931
1932         }
1933
1934         backlog_dev->quota -= work;
1935         *budget -= work;
1936         return -1;
1937
1938 job_done:
1939         backlog_dev->quota -= work;
1940         *budget -= work;
1941
1942         list_del(&backlog_dev->poll_list);
1943         smp_mb__before_clear_bit();
1944         netif_poll_enable(backlog_dev);
1945
1946         local_irq_enable();
1947         return 0;
1948 }
1949
1950 static void net_rx_action(struct softirq_action *h)
1951 {
1952         struct softnet_data *queue = &__get_cpu_var(softnet_data);
1953         unsigned long start_time = jiffies;
1954         int budget = netdev_budget;
1955         void *have;
1956
1957         local_irq_disable();
1958
1959         while (!list_empty(&queue->poll_list)) {
1960                 struct net_device *dev;
1961
1962                 if (budget <= 0 || jiffies - start_time > 1)
1963                         goto softnet_break;
1964
1965                 local_irq_enable();
1966
1967                 dev = list_entry(queue->poll_list.next,
1968                                  struct net_device, poll_list);
1969                 have = netpoll_poll_lock(dev);
1970
1971                 if (dev->quota <= 0 || dev->poll(dev, &budget)) {
1972                         netpoll_poll_unlock(have);
1973                         local_irq_disable();
1974                         list_move_tail(&dev->poll_list, &queue->poll_list);
1975                         if (dev->quota < 0)
1976                                 dev->quota += dev->weight;
1977                         else
1978                                 dev->quota = dev->weight;
1979                 } else {
1980                         netpoll_poll_unlock(have);
1981                         dev_put(dev);
1982                         local_irq_disable();
1983                 }
1984         }
1985 out:
1986         local_irq_enable();
1987         return;
1988
1989 softnet_break:
1990         __get_cpu_var(netdev_rx_stat).time_squeeze++;
1991         __raise_softirq_irqoff(NET_RX_SOFTIRQ);
1992         goto out;
1993 }
1994
1995 static gifconf_func_t * gifconf_list [NPROTO];
1996
1997 /**
1998  *      register_gifconf        -       register a SIOCGIF handler
1999  *      @family: Address family
2000  *      @gifconf: Function handler
2001  *
2002  *      Register protocol dependent address dumping routines. The handler
2003  *      that is passed must not be freed or reused until it has been replaced
2004  *      by another handler.
2005  */
2006 int register_gifconf(unsigned int family, gifconf_func_t * gifconf)
2007 {
2008         if (family >= NPROTO)
2009                 return -EINVAL;
2010         gifconf_list[family] = gifconf;
2011         return 0;
2012 }
2013
2014
2015 /*
2016  *      Map an interface index to its name (SIOCGIFNAME)
2017  */
2018
2019 /*
2020  *      We need this ioctl for efficient implementation of the
2021  *      if_indextoname() function required by the IPv6 API.  Without
2022  *      it, we would have to search all the interfaces to find a
2023  *      match.  --pb
2024  */
2025
2026 static int dev_ifname(struct ifreq __user *arg)
2027 {
2028         struct net_device *dev;
2029         struct ifreq ifr;
2030
2031         /*
2032          *      Fetch the caller's info block.
2033          */
2034
2035         if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
2036                 return -EFAULT;
2037
2038         read_lock(&dev_base_lock);
2039         dev = __dev_get_by_index(ifr.ifr_ifindex);
2040         if (!dev) {
2041                 read_unlock(&dev_base_lock);
2042                 return -ENODEV;
2043         }
2044
2045         strcpy(ifr.ifr_name, dev->name);
2046         read_unlock(&dev_base_lock);
2047
2048         if (copy_to_user(arg, &ifr, sizeof(struct ifreq)))
2049                 return -EFAULT;
2050         return 0;
2051 }
2052
2053 /*
2054  *      Perform a SIOCGIFCONF call. This structure will change
2055  *      size eventually, and there is nothing I can do about it.
2056  *      Thus we will need a 'compatibility mode'.
2057  */
2058
2059 static int dev_ifconf(char __user *arg)
2060 {
2061         struct ifconf ifc;
2062         struct net_device *dev;
2063         char __user *pos;
2064         int len;
2065         int total;
2066         int i;
2067
2068         /*
2069          *      Fetch the caller's info block.
2070          */
2071
2072         if (copy_from_user(&ifc, arg, sizeof(struct ifconf)))
2073                 return -EFAULT;
2074
2075         pos = ifc.ifc_buf;
2076         len = ifc.ifc_len;
2077
2078         /*
2079          *      Loop over the interfaces, and write an info block for each.
2080          */
2081
2082         total = 0;
2083         for (dev = dev_base; dev; dev = dev->next) {
2084                 if (vx_flags(VXF_HIDE_NETIF, 0) &&
2085                         !dev_in_nx_info(dev, current->nx_info))
2086                         continue;
2087                 for (i = 0; i < NPROTO; i++) {
2088                         if (gifconf_list[i]) {
2089                                 int done;
2090                                 if (!pos)
2091                                         done = gifconf_list[i](dev, NULL, 0);
2092                                 else
2093                                         done = gifconf_list[i](dev, pos + total,
2094                                                                len - total);
2095                                 if (done < 0)
2096                                         return -EFAULT;
2097                                 total += done;
2098                         }
2099                 }
2100         }
2101
2102         /*
2103          *      All done.  Write the updated control block back to the caller.
2104          */
2105         ifc.ifc_len = total;
2106
2107         /*
2108          *      Both BSD and Solaris return 0 here, so we do too.
2109          */
2110         return copy_to_user(arg, &ifc, sizeof(struct ifconf)) ? -EFAULT : 0;
2111 }
2112
2113 #ifdef CONFIG_PROC_FS
2114 /*
2115  *      This is invoked by the /proc filesystem handler to display a device
2116  *      in detail.
2117  */
2118 static __inline__ struct net_device *dev_get_idx(loff_t pos)
2119 {
2120         struct net_device *dev;
2121         loff_t i;
2122
2123         for (i = 0, dev = dev_base; dev && i < pos; ++i, dev = dev->next);
2124
2125         return i == pos ? dev : NULL;
2126 }
2127
2128 void *dev_seq_start(struct seq_file *seq, loff_t *pos)
2129 {
2130         read_lock(&dev_base_lock);
2131         return *pos ? dev_get_idx(*pos - 1) : SEQ_START_TOKEN;
2132 }
2133
2134 void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2135 {
2136         ++*pos;
2137         return v == SEQ_START_TOKEN ? dev_base : ((struct net_device *)v)->next;
2138 }
2139
2140 void dev_seq_stop(struct seq_file *seq, void *v)
2141 {
2142         read_unlock(&dev_base_lock);
2143 }
2144
2145 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
2146 {
2147         struct nx_info *nxi = current->nx_info;
2148
2149         if (vx_flags(VXF_HIDE_NETIF, 0) && !dev_in_nx_info(dev, nxi))
2150                 return;
2151         if (dev->get_stats) {
2152                 struct net_device_stats *stats = dev->get_stats(dev);
2153
2154                 seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
2155                                 "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
2156                            dev->name, stats->rx_bytes, stats->rx_packets,
2157                            stats->rx_errors,
2158                            stats->rx_dropped + stats->rx_missed_errors,
2159                            stats->rx_fifo_errors,
2160                            stats->rx_length_errors + stats->rx_over_errors +
2161                              stats->rx_crc_errors + stats->rx_frame_errors,
2162                            stats->rx_compressed, stats->multicast,
2163                            stats->tx_bytes, stats->tx_packets,
2164                            stats->tx_errors, stats->tx_dropped,
2165                            stats->tx_fifo_errors, stats->collisions,
2166                            stats->tx_carrier_errors +
2167                              stats->tx_aborted_errors +
2168                              stats->tx_window_errors +
2169                              stats->tx_heartbeat_errors,
2170                            stats->tx_compressed);
2171         } else
2172                 seq_printf(seq, "%6s: No statistics available.\n", dev->name);
2173 }
2174
2175 /*
2176  *      Called from the PROCfs module. This now uses the new arbitrary sized
2177  *      /proc/net interface to create /proc/net/dev
2178  */
2179 static int dev_seq_show(struct seq_file *seq, void *v)
2180 {
2181         if (v == SEQ_START_TOKEN)
2182                 seq_puts(seq, "Inter-|   Receive                            "
2183                               "                    |  Transmit\n"
2184                               " face |bytes    packets errs drop fifo frame "
2185                               "compressed multicast|bytes    packets errs "
2186                               "drop fifo colls carrier compressed\n");
2187         else
2188                 dev_seq_printf_stats(seq, v);
2189         return 0;
2190 }
2191
2192 static struct netif_rx_stats *softnet_get_online(loff_t *pos)
2193 {
2194         struct netif_rx_stats *rc = NULL;
2195
2196         while (*pos < NR_CPUS)
2197                 if (cpu_online(*pos)) {
2198                         rc = &per_cpu(netdev_rx_stat, *pos);
2199                         break;
2200                 } else
2201                         ++*pos;
2202         return rc;
2203 }
2204
2205 static void *softnet_seq_start(struct seq_file *seq, loff_t *pos)
2206 {
2207         return softnet_get_online(pos);
2208 }
2209
2210 static void *softnet_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2211 {
2212         ++*pos;
2213         return softnet_get_online(pos);
2214 }
2215
2216 static void softnet_seq_stop(struct seq_file *seq, void *v)
2217 {
2218 }
2219
2220 static int softnet_seq_show(struct seq_file *seq, void *v)
2221 {
2222         struct netif_rx_stats *s = v;
2223
2224         seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
2225                    s->total, s->dropped, s->time_squeeze, 0,
2226                    0, 0, 0, 0, /* was fastroute */
2227                    s->cpu_collision );
2228         return 0;
2229 }
2230
2231 static struct seq_operations dev_seq_ops = {
2232         .start = dev_seq_start,
2233         .next  = dev_seq_next,
2234         .stop  = dev_seq_stop,
2235         .show  = dev_seq_show,
2236 };
2237
2238 static int dev_seq_open(struct inode *inode, struct file *file)
2239 {
2240         return seq_open(file, &dev_seq_ops);
2241 }
2242
2243 static struct file_operations dev_seq_fops = {
2244         .owner   = THIS_MODULE,
2245         .open    = dev_seq_open,
2246         .read    = seq_read,
2247         .llseek  = seq_lseek,
2248         .release = seq_release,
2249 };
2250
2251 static struct seq_operations softnet_seq_ops = {
2252         .start = softnet_seq_start,
2253         .next  = softnet_seq_next,
2254         .stop  = softnet_seq_stop,
2255         .show  = softnet_seq_show,
2256 };
2257
2258 static int softnet_seq_open(struct inode *inode, struct file *file)
2259 {
2260         return seq_open(file, &softnet_seq_ops);
2261 }
2262
2263 static struct file_operations softnet_seq_fops = {
2264         .owner   = THIS_MODULE,
2265         .open    = softnet_seq_open,
2266         .read    = seq_read,
2267         .llseek  = seq_lseek,
2268         .release = seq_release,
2269 };
2270
2271 #ifdef CONFIG_WIRELESS_EXT
2272 extern int wireless_proc_init(void);
2273 #else
2274 #define wireless_proc_init() 0
2275 #endif
2276
2277 static int __init dev_proc_init(void)
2278 {
2279         int rc = -ENOMEM;
2280
2281         if (!proc_net_fops_create("dev", S_IRUGO, &dev_seq_fops))
2282                 goto out;
2283         if (!proc_net_fops_create("softnet_stat", S_IRUGO, &softnet_seq_fops))
2284                 goto out_dev;
2285         if (wireless_proc_init())
2286                 goto out_softnet;
2287         rc = 0;
2288 out:
2289         return rc;
2290 out_softnet:
2291         proc_net_remove("softnet_stat");
2292 out_dev:
2293         proc_net_remove("dev");
2294         goto out;
2295 }
2296 #else
2297 #define dev_proc_init() 0
2298 #endif  /* CONFIG_PROC_FS */
2299
2300
2301 /**
2302  *      netdev_set_master       -       set up master/slave pair
2303  *      @slave: slave device
2304  *      @master: new master device
2305  *
2306  *      Changes the master device of the slave. Pass %NULL to break the
2307  *      bonding. The caller must hold the RTNL semaphore. On a failure
2308  *      a negative errno code is returned. On success the reference counts
2309  *      are adjusted, %RTM_NEWLINK is sent to the routing socket and the
2310  *      function returns zero.
2311  */
2312 int netdev_set_master(struct net_device *slave, struct net_device *master)
2313 {
2314         struct net_device *old = slave->master;
2315
2316         ASSERT_RTNL();
2317
2318         if (master) {
2319                 if (old)
2320                         return -EBUSY;
2321                 dev_hold(master);
2322         }
2323
2324         slave->master = master;
2325         
2326         synchronize_net();
2327
2328         if (old)
2329                 dev_put(old);
2330
2331         if (master)
2332                 slave->flags |= IFF_SLAVE;
2333         else
2334                 slave->flags &= ~IFF_SLAVE;
2335
2336         rtmsg_ifinfo(RTM_NEWLINK, slave, IFF_SLAVE);
2337         return 0;
2338 }
2339
2340 /**
2341  *      dev_set_promiscuity     - update promiscuity count on a device
2342  *      @dev: device
2343  *      @inc: modifier
2344  *
2345  *      Add or remove promiscuity from a device. While the count in the device
2346  *      remains above zero the interface remains promiscuous. Once it hits zero
2347  *      the device reverts back to normal filtering operation. A negative inc
2348  *      value is used to drop promiscuity on the device.
2349  */
2350 void dev_set_promiscuity(struct net_device *dev, int inc)
2351 {
2352         unsigned short old_flags = dev->flags;
2353
2354         if ((dev->promiscuity += inc) == 0)
2355                 dev->flags &= ~IFF_PROMISC;
2356         else
2357                 dev->flags |= IFF_PROMISC;
2358         if (dev->flags != old_flags) {
2359                 dev_mc_upload(dev);
2360                 printk(KERN_INFO "device %s %s promiscuous mode\n",
2361                        dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
2362                                                                "left");
2363                 audit_log(current->audit_context, GFP_ATOMIC,
2364                         AUDIT_ANOM_PROMISCUOUS,
2365                         "dev=%s prom=%d old_prom=%d auid=%u",
2366                         dev->name, (dev->flags & IFF_PROMISC),
2367                         (old_flags & IFF_PROMISC),
2368                         audit_get_loginuid(current->audit_context)); 
2369         }
2370 }
2371
2372 /**
2373  *      dev_set_allmulti        - update allmulti count on a device
2374  *      @dev: device
2375  *      @inc: modifier
2376  *
2377  *      Add or remove reception of all multicast frames to a device. While the
2378  *      count in the device remains above zero the interface remains listening
2379  *      to all interfaces. Once it hits zero the device reverts back to normal
2380  *      filtering operation. A negative @inc value is used to drop the counter
2381  *      when releasing a resource needing all multicasts.
2382  */
2383
2384 void dev_set_allmulti(struct net_device *dev, int inc)
2385 {
2386         unsigned short old_flags = dev->flags;
2387
2388         dev->flags |= IFF_ALLMULTI;
2389         if ((dev->allmulti += inc) == 0)
2390                 dev->flags &= ~IFF_ALLMULTI;
2391         if (dev->flags ^ old_flags)
2392                 dev_mc_upload(dev);
2393 }
2394
2395 unsigned dev_get_flags(const struct net_device *dev)
2396 {
2397         unsigned flags;
2398
2399         flags = (dev->flags & ~(IFF_PROMISC |
2400                                 IFF_ALLMULTI |
2401                                 IFF_RUNNING |
2402                                 IFF_LOWER_UP |
2403                                 IFF_DORMANT)) |
2404                 (dev->gflags & (IFF_PROMISC |
2405                                 IFF_ALLMULTI));
2406
2407         if (netif_running(dev)) {
2408                 if (netif_oper_up(dev))
2409                         flags |= IFF_RUNNING;
2410                 if (netif_carrier_ok(dev))
2411                         flags |= IFF_LOWER_UP;
2412                 if (netif_dormant(dev))
2413                         flags |= IFF_DORMANT;
2414         }
2415
2416         return flags;
2417 }
2418
2419 int dev_change_flags(struct net_device *dev, unsigned flags)
2420 {
2421         int ret;
2422         int old_flags = dev->flags;
2423
2424         /*
2425          *      Set the flags on our device.
2426          */
2427
2428         dev->flags = (flags & (IFF_DEBUG | IFF_NOTRAILERS | IFF_NOARP |
2429                                IFF_DYNAMIC | IFF_MULTICAST | IFF_PORTSEL |
2430                                IFF_AUTOMEDIA)) |
2431                      (dev->flags & (IFF_UP | IFF_VOLATILE | IFF_PROMISC |
2432                                     IFF_ALLMULTI));
2433
2434         /*
2435          *      Load in the correct multicast list now the flags have changed.
2436          */
2437
2438         dev_mc_upload(dev);
2439
2440         /*
2441          *      Have we downed the interface. We handle IFF_UP ourselves
2442          *      according to user attempts to set it, rather than blindly
2443          *      setting it.
2444          */
2445
2446         ret = 0;
2447         if ((old_flags ^ flags) & IFF_UP) {     /* Bit is different  ? */
2448                 ret = ((old_flags & IFF_UP) ? dev_close : dev_open)(dev);
2449
2450                 if (!ret)
2451                         dev_mc_upload(dev);
2452         }
2453
2454         if (dev->flags & IFF_UP &&
2455             ((old_flags ^ dev->flags) &~ (IFF_UP | IFF_PROMISC | IFF_ALLMULTI |
2456                                           IFF_VOLATILE)))
2457                 raw_notifier_call_chain(&netdev_chain,
2458                                 NETDEV_CHANGE, dev);
2459
2460         if ((flags ^ dev->gflags) & IFF_PROMISC) {
2461                 int inc = (flags & IFF_PROMISC) ? +1 : -1;
2462                 dev->gflags ^= IFF_PROMISC;
2463                 dev_set_promiscuity(dev, inc);
2464         }
2465
2466         /* NOTE: order of synchronization of IFF_PROMISC and IFF_ALLMULTI
2467            is important. Some (broken) drivers set IFF_PROMISC, when
2468            IFF_ALLMULTI is requested not asking us and not reporting.
2469          */
2470         if ((flags ^ dev->gflags) & IFF_ALLMULTI) {
2471                 int inc = (flags & IFF_ALLMULTI) ? +1 : -1;
2472                 dev->gflags ^= IFF_ALLMULTI;
2473                 dev_set_allmulti(dev, inc);
2474         }
2475
2476         if (old_flags ^ dev->flags)
2477                 rtmsg_ifinfo(RTM_NEWLINK, dev, old_flags ^ dev->flags);
2478
2479         return ret;
2480 }
2481
2482 int dev_set_mtu(struct net_device *dev, int new_mtu)
2483 {
2484         int err;
2485
2486         if (new_mtu == dev->mtu)
2487                 return 0;
2488
2489         /*      MTU must be positive.    */
2490         if (new_mtu < 0)
2491                 return -EINVAL;
2492
2493         if (!netif_device_present(dev))
2494                 return -ENODEV;
2495
2496         err = 0;
2497         if (dev->change_mtu)
2498                 err = dev->change_mtu(dev, new_mtu);
2499         else
2500                 dev->mtu = new_mtu;
2501         if (!err && dev->flags & IFF_UP)
2502                 raw_notifier_call_chain(&netdev_chain,
2503                                 NETDEV_CHANGEMTU, dev);
2504         return err;
2505 }
2506
2507 int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
2508 {
2509         int err;
2510
2511         if (!dev->set_mac_address)
2512                 return -EOPNOTSUPP;
2513         if (sa->sa_family != dev->type)
2514                 return -EINVAL;
2515         if (!netif_device_present(dev))
2516                 return -ENODEV;
2517         err = dev->set_mac_address(dev, sa);
2518         if (!err)
2519                 raw_notifier_call_chain(&netdev_chain,
2520                                 NETDEV_CHANGEADDR, dev);
2521         return err;
2522 }
2523
2524 /*
2525  *      Perform the SIOCxIFxxx calls.
2526  */
2527 static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
2528 {
2529         int err;
2530         struct net_device *dev = __dev_get_by_name(ifr->ifr_name);
2531
2532         if (!dev)
2533                 return -ENODEV;
2534
2535         switch (cmd) {
2536                 case SIOCGIFFLAGS:      /* Get interface flags */
2537                         ifr->ifr_flags = dev_get_flags(dev);
2538                         return 0;
2539
2540                 case SIOCSIFFLAGS:      /* Set interface flags */
2541                         return dev_change_flags(dev, ifr->ifr_flags);
2542
2543                 case SIOCGIFMETRIC:     /* Get the metric on the interface
2544                                            (currently unused) */
2545                         ifr->ifr_metric = 0;
2546                         return 0;
2547
2548                 case SIOCSIFMETRIC:     /* Set the metric on the interface
2549                                            (currently unused) */
2550                         return -EOPNOTSUPP;
2551
2552                 case SIOCGIFMTU:        /* Get the MTU of a device */
2553                         ifr->ifr_mtu = dev->mtu;
2554                         return 0;
2555
2556                 case SIOCSIFMTU:        /* Set the MTU of a device */
2557                         return dev_set_mtu(dev, ifr->ifr_mtu);
2558
2559                 case SIOCGIFHWADDR:
2560                         if (!dev->addr_len)
2561                                 memset(ifr->ifr_hwaddr.sa_data, 0, sizeof ifr->ifr_hwaddr.sa_data);
2562                         else
2563                                 memcpy(ifr->ifr_hwaddr.sa_data, dev->dev_addr,
2564                                        min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
2565                         ifr->ifr_hwaddr.sa_family = dev->type;
2566                         return 0;
2567
2568                 case SIOCSIFHWADDR:
2569                         return dev_set_mac_address(dev, &ifr->ifr_hwaddr);
2570
2571                 case SIOCSIFHWBROADCAST:
2572                         if (ifr->ifr_hwaddr.sa_family != dev->type)
2573                                 return -EINVAL;
2574                         memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data,
2575                                min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
2576                         raw_notifier_call_chain(&netdev_chain,
2577                                             NETDEV_CHANGEADDR, dev);
2578                         return 0;
2579
2580                 case SIOCGIFMAP:
2581                         ifr->ifr_map.mem_start = dev->mem_start;
2582                         ifr->ifr_map.mem_end   = dev->mem_end;
2583                         ifr->ifr_map.base_addr = dev->base_addr;
2584                         ifr->ifr_map.irq       = dev->irq;
2585                         ifr->ifr_map.dma       = dev->dma;
2586                         ifr->ifr_map.port      = dev->if_port;
2587                         return 0;
2588
2589                 case SIOCSIFMAP:
2590                         if (dev->set_config) {
2591                                 if (!netif_device_present(dev))
2592                                         return -ENODEV;
2593                                 return dev->set_config(dev, &ifr->ifr_map);
2594                         }
2595                         return -EOPNOTSUPP;
2596
2597                 case SIOCADDMULTI:
2598                         if (!dev->set_multicast_list ||
2599                             ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
2600                                 return -EINVAL;
2601                         if (!netif_device_present(dev))
2602                                 return -ENODEV;
2603                         return dev_mc_add(dev, ifr->ifr_hwaddr.sa_data,
2604                                           dev->addr_len, 1);
2605
2606                 case SIOCDELMULTI:
2607                         if (!dev->set_multicast_list ||
2608                             ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
2609                                 return -EINVAL;
2610                         if (!netif_device_present(dev))
2611                                 return -ENODEV;
2612                         return dev_mc_delete(dev, ifr->ifr_hwaddr.sa_data,
2613                                              dev->addr_len, 1);
2614
2615                 case SIOCGIFINDEX:
2616                         ifr->ifr_ifindex = dev->ifindex;
2617                         return 0;
2618
2619                 case SIOCGIFTXQLEN:
2620                         ifr->ifr_qlen = dev->tx_queue_len;
2621                         return 0;
2622
2623                 case SIOCSIFTXQLEN:
2624                         if (ifr->ifr_qlen < 0)
2625                                 return -EINVAL;
2626                         dev->tx_queue_len = ifr->ifr_qlen;
2627                         return 0;
2628
2629                 case SIOCSIFNAME:
2630                         ifr->ifr_newname[IFNAMSIZ-1] = '\0';
2631                         return dev_change_name(dev, ifr->ifr_newname);
2632
2633                 /*
2634                  *      Unknown or private ioctl
2635                  */
2636
2637                 default:
2638                         if ((cmd >= SIOCDEVPRIVATE &&
2639                             cmd <= SIOCDEVPRIVATE + 15) ||
2640                             cmd == SIOCBONDENSLAVE ||
2641                             cmd == SIOCBONDRELEASE ||
2642                             cmd == SIOCBONDSETHWADDR ||
2643                             cmd == SIOCBONDSLAVEINFOQUERY ||
2644                             cmd == SIOCBONDINFOQUERY ||
2645                             cmd == SIOCBONDCHANGEACTIVE ||
2646                             cmd == SIOCGMIIPHY ||
2647                             cmd == SIOCGMIIREG ||
2648                             cmd == SIOCSMIIREG ||
2649                             cmd == SIOCBRADDIF ||
2650                             cmd == SIOCBRDELIF ||
2651                             cmd == SIOCWANDEV) {
2652                                 err = -EOPNOTSUPP;
2653                                 if (dev->do_ioctl) {
2654                                         if (netif_device_present(dev))
2655                                                 err = dev->do_ioctl(dev, ifr,
2656                                                                     cmd);
2657                                         else
2658                                                 err = -ENODEV;
2659                                 }
2660                         } else
2661                                 err = -EINVAL;
2662
2663         }
2664         return err;
2665 }
2666
2667 /*
2668  *      This function handles all "interface"-type I/O control requests. The actual
2669  *      'doing' part of this is dev_ifsioc above.
2670  */
2671
2672 /**
2673  *      dev_ioctl       -       network device ioctl
2674  *      @cmd: command to issue
2675  *      @arg: pointer to a struct ifreq in user space
2676  *
2677  *      Issue ioctl functions to devices. This is normally called by the
2678  *      user space syscall interfaces but can sometimes be useful for
2679  *      other purposes. The return value is the return from the syscall if
2680  *      positive or a negative errno code on error.
2681  */
2682
2683 int dev_ioctl(unsigned int cmd, void __user *arg)
2684 {
2685         struct ifreq ifr;
2686         int ret;
2687         char *colon;
2688
2689         /* One special case: SIOCGIFCONF takes ifconf argument
2690            and requires shared lock, because it sleeps writing
2691            to user space.
2692          */
2693
2694         if (cmd == SIOCGIFCONF) {
2695                 rtnl_lock();
2696                 ret = dev_ifconf((char __user *) arg);
2697                 rtnl_unlock();
2698                 return ret;
2699         }
2700         if (cmd == SIOCGIFNAME)
2701                 return dev_ifname((struct ifreq __user *)arg);
2702
2703         if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
2704                 return -EFAULT;
2705
2706         ifr.ifr_name[IFNAMSIZ-1] = 0;
2707
2708         colon = strchr(ifr.ifr_name, ':');
2709         if (colon)
2710                 *colon = 0;
2711
2712         /*
2713          *      See which interface the caller is talking about.
2714          */
2715
2716         switch (cmd) {
2717                 /*
2718                  *      These ioctl calls:
2719                  *      - can be done by all.
2720                  *      - atomic and do not require locking.
2721                  *      - return a value
2722                  */
2723                 case SIOCGIFFLAGS:
2724                 case SIOCGIFMETRIC:
2725                 case SIOCGIFMTU:
2726                 case SIOCGIFHWADDR:
2727                 case SIOCGIFSLAVE:
2728                 case SIOCGIFMAP:
2729                 case SIOCGIFINDEX:
2730                 case SIOCGIFTXQLEN:
2731                         dev_load(ifr.ifr_name);
2732                         read_lock(&dev_base_lock);
2733                         ret = dev_ifsioc(&ifr, cmd);
2734                         read_unlock(&dev_base_lock);
2735                         if (!ret) {
2736                                 if (colon)
2737                                         *colon = ':';
2738                                 if (copy_to_user(arg, &ifr,
2739                                                  sizeof(struct ifreq)))
2740                                         ret = -EFAULT;
2741                         }
2742                         return ret;
2743
2744                 case SIOCETHTOOL:
2745                         dev_load(ifr.ifr_name);
2746                         rtnl_lock();
2747                         ret = dev_ethtool(&ifr);
2748                         rtnl_unlock();
2749                         if (!ret) {
2750                                 if (colon)
2751                                         *colon = ':';
2752                                 if (copy_to_user(arg, &ifr,
2753                                                  sizeof(struct ifreq)))
2754                                         ret = -EFAULT;
2755                         }
2756                         return ret;
2757
2758                 /*
2759                  *      These ioctl calls:
2760                  *      - require superuser power.
2761                  *      - require strict serialization.
2762                  *      - return a value
2763                  */
2764                 case SIOCGMIIPHY:
2765                 case SIOCGMIIREG:
2766                 case SIOCSIFNAME:
2767                         if (!capable(CAP_NET_ADMIN))
2768                                 return -EPERM;
2769                         dev_load(ifr.ifr_name);
2770                         rtnl_lock();
2771                         ret = dev_ifsioc(&ifr, cmd);
2772                         rtnl_unlock();
2773                         if (!ret) {
2774                                 if (colon)
2775                                         *colon = ':';
2776                                 if (copy_to_user(arg, &ifr,
2777                                                  sizeof(struct ifreq)))
2778                                         ret = -EFAULT;
2779                         }
2780                         return ret;
2781
2782                 /*
2783                  *      These ioctl calls:
2784                  *      - require superuser power.
2785                  *      - require strict serialization.
2786                  *      - do not return a value
2787                  */
2788                 case SIOCSIFFLAGS:
2789                 case SIOCSIFMETRIC:
2790                 case SIOCSIFMTU:
2791                 case SIOCSIFMAP:
2792                 case SIOCSIFHWADDR:
2793                 case SIOCSIFSLAVE:
2794                 case SIOCADDMULTI:
2795                 case SIOCDELMULTI:
2796                 case SIOCSIFHWBROADCAST:
2797                 case SIOCSIFTXQLEN:
2798                 case SIOCSMIIREG:
2799                 case SIOCBONDENSLAVE:
2800                 case SIOCBONDRELEASE:
2801                 case SIOCBONDSETHWADDR:
2802                 case SIOCBONDCHANGEACTIVE:
2803                 case SIOCBRADDIF:
2804                 case SIOCBRDELIF:
2805                         if (!capable(CAP_NET_ADMIN))
2806                                 return -EPERM;
2807                         /* fall through */
2808                 case SIOCBONDSLAVEINFOQUERY:
2809                 case SIOCBONDINFOQUERY:
2810                         dev_load(ifr.ifr_name);
2811                         rtnl_lock();
2812                         ret = dev_ifsioc(&ifr, cmd);
2813                         rtnl_unlock();
2814                         return ret;
2815
2816                 case SIOCGIFMEM:
2817                         /* Get the per device memory space. We can add this but
2818                          * currently do not support it */
2819                 case SIOCSIFMEM:
2820                         /* Set the per device memory buffer space.
2821                          * Not applicable in our case */
2822                 case SIOCSIFLINK:
2823                         return -EINVAL;
2824
2825                 /*
2826                  *      Unknown or private ioctl.
2827                  */
2828                 default:
2829                         if (cmd == SIOCWANDEV ||
2830                             (cmd >= SIOCDEVPRIVATE &&
2831                              cmd <= SIOCDEVPRIVATE + 15)) {
2832                                 dev_load(ifr.ifr_name);
2833                                 rtnl_lock();
2834                                 ret = dev_ifsioc(&ifr, cmd);
2835                                 rtnl_unlock();
2836                                 if (!ret && copy_to_user(arg, &ifr,
2837                                                          sizeof(struct ifreq)))
2838                                         ret = -EFAULT;
2839                                 return ret;
2840                         }
2841 #ifdef CONFIG_WIRELESS_EXT
2842                         /* Take care of Wireless Extensions */
2843                         if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
2844                                 /* If command is `set a parameter', or
2845                                  * `get the encoding parameters', check if
2846                                  * the user has the right to do it */
2847                                 if (IW_IS_SET(cmd) || cmd == SIOCGIWENCODE
2848                                     || cmd == SIOCGIWENCODEEXT) {
2849                                         if (!capable(CAP_NET_ADMIN))
2850                                                 return -EPERM;
2851                                 }
2852                                 dev_load(ifr.ifr_name);
2853                                 rtnl_lock();
2854                                 /* Follow me in net/core/wireless.c */
2855                                 ret = wireless_process_ioctl(&ifr, cmd);
2856                                 rtnl_unlock();
2857                                 if (IW_IS_GET(cmd) &&
2858                                     copy_to_user(arg, &ifr,
2859                                                  sizeof(struct ifreq)))
2860                                         ret = -EFAULT;
2861                                 return ret;
2862                         }
2863 #endif  /* CONFIG_WIRELESS_EXT */
2864                         return -EINVAL;
2865         }
2866 }
2867
2868
2869 /**
2870  *      dev_new_index   -       allocate an ifindex
2871  *
2872  *      Returns a suitable unique value for a new device interface
2873  *      number.  The caller must hold the rtnl semaphore or the
2874  *      dev_base_lock to be sure it remains unique.
2875  */
2876 static int dev_new_index(void)
2877 {
2878         static int ifindex;
2879         for (;;) {
2880                 if (++ifindex <= 0)
2881                         ifindex = 1;
2882                 if (!__dev_get_by_index(ifindex))
2883                         return ifindex;
2884         }
2885 }
2886
2887 static int dev_boot_phase = 1;
2888
2889 /* Delayed registration/unregisteration */
2890 static DEFINE_SPINLOCK(net_todo_list_lock);
2891 static struct list_head net_todo_list = LIST_HEAD_INIT(net_todo_list);
2892
2893 static inline void net_set_todo(struct net_device *dev)
2894 {
2895         spin_lock(&net_todo_list_lock);
2896         list_add_tail(&dev->todo_list, &net_todo_list);
2897         spin_unlock(&net_todo_list_lock);
2898 }
2899
2900 /**
2901  *      register_netdevice      - register a network device
2902  *      @dev: device to register
2903  *
2904  *      Take a completed network device structure and add it to the kernel
2905  *      interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier
2906  *      chain. 0 is returned on success. A negative errno code is returned
2907  *      on a failure to set up the device, or if the name is a duplicate.
2908  *
2909  *      Callers must hold the rtnl semaphore. You may want
2910  *      register_netdev() instead of this.
2911  *
2912  *      BUGS:
2913  *      The locking appears insufficient to guarantee two parallel registers
2914  *      will not get the same name.
2915  */
2916
2917 int register_netdevice(struct net_device *dev)
2918 {
2919         struct hlist_head *head;
2920         struct hlist_node *p;
2921         int ret;
2922
2923         BUG_ON(dev_boot_phase);
2924         ASSERT_RTNL();
2925
2926         might_sleep();
2927
2928         /* When net_device's are persistent, this will be fatal. */
2929         BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
2930
2931         spin_lock_init(&dev->queue_lock);
2932         spin_lock_init(&dev->_xmit_lock);
2933         dev->xmit_lock_owner = -1;
2934 #ifdef CONFIG_NET_CLS_ACT
2935         spin_lock_init(&dev->ingress_lock);
2936 #endif
2937
2938         ret = alloc_divert_blk(dev);
2939         if (ret)
2940                 goto out;
2941
2942         dev->iflink = -1;
2943
2944         /* Init, if this function is available */
2945         if (dev->init) {
2946                 ret = dev->init(dev);
2947                 if (ret) {
2948                         if (ret > 0)
2949                                 ret = -EIO;
2950                         goto out_err;
2951                 }
2952         }
2953  
2954         if (!dev_valid_name(dev->name)) {
2955                 ret = -EINVAL;
2956                 goto out_err;
2957         }
2958
2959         dev->ifindex = dev_new_index();
2960         if (dev->iflink == -1)
2961                 dev->iflink = dev->ifindex;
2962
2963         /* Check for existence of name */
2964         head = dev_name_hash(dev->name);
2965         hlist_for_each(p, head) {
2966                 struct net_device *d
2967                         = hlist_entry(p, struct net_device, name_hlist);
2968                 if (!strncmp(d->name, dev->name, IFNAMSIZ)) {
2969                         ret = -EEXIST;
2970                         goto out_err;
2971                 }
2972         }
2973
2974         /* Fix illegal SG+CSUM combinations. */
2975         if ((dev->features & NETIF_F_SG) &&
2976             !(dev->features & NETIF_F_ALL_CSUM)) {
2977                 printk("%s: Dropping NETIF_F_SG since no checksum feature.\n",
2978                        dev->name);
2979                 dev->features &= ~NETIF_F_SG;
2980         }
2981
2982         /* TSO requires that SG is present as well. */
2983         if ((dev->features & NETIF_F_TSO) &&
2984             !(dev->features & NETIF_F_SG)) {
2985                 printk("%s: Dropping NETIF_F_TSO since no SG feature.\n",
2986                        dev->name);
2987                 dev->features &= ~NETIF_F_TSO;
2988         }
2989         if (dev->features & NETIF_F_UFO) {
2990                 if (!(dev->features & NETIF_F_HW_CSUM)) {
2991                         printk(KERN_ERR "%s: Dropping NETIF_F_UFO since no "
2992                                         "NETIF_F_HW_CSUM feature.\n",
2993                                                         dev->name);
2994                         dev->features &= ~NETIF_F_UFO;
2995                 }
2996                 if (!(dev->features & NETIF_F_SG)) {
2997                         printk(KERN_ERR "%s: Dropping NETIF_F_UFO since no "
2998                                         "NETIF_F_SG feature.\n",
2999                                         dev->name);
3000                         dev->features &= ~NETIF_F_UFO;
3001                 }
3002         }
3003
3004         /*
3005          *      nil rebuild_header routine,
3006          *      that should be never called and used as just bug trap.
3007          */
3008
3009         if (!dev->rebuild_header)
3010                 dev->rebuild_header = default_rebuild_header;
3011
3012         ret = netdev_register_sysfs(dev);
3013         if (ret)
3014                 goto out_err;
3015         dev->reg_state = NETREG_REGISTERED;
3016
3017         /*
3018          *      Default initial state at registry is that the
3019          *      device is present.
3020          */
3021
3022         set_bit(__LINK_STATE_PRESENT, &dev->state);
3023
3024         dev->next = NULL;
3025         dev_init_scheduler(dev);
3026         write_lock_bh(&dev_base_lock);
3027         *dev_tail = dev;
3028         dev_tail = &dev->next;
3029         hlist_add_head(&dev->name_hlist, head);
3030         hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex));
3031         dev_hold(dev);
3032         write_unlock_bh(&dev_base_lock);
3033
3034         /* Notify protocols, that a new device appeared. */
3035         raw_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
3036
3037         ret = 0;
3038
3039 out:
3040         return ret;
3041 out_err:
3042         free_divert_blk(dev);
3043         goto out;
3044 }
3045
3046 /**
3047  *      register_netdev - register a network device
3048  *      @dev: device to register
3049  *
3050  *      Take a completed network device structure and add it to the kernel
3051  *      interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier
3052  *      chain. 0 is returned on success. A negative errno code is returned
3053  *      on a failure to set up the device, or if the name is a duplicate.
3054  *
3055  *      This is a wrapper around register_netdev that takes the rtnl semaphore
3056  *      and expands the device name if you passed a format string to
3057  *      alloc_netdev.
3058  */
3059 int register_netdev(struct net_device *dev)
3060 {
3061         int err;
3062
3063         rtnl_lock();
3064
3065         /*
3066          * If the name is a format string the caller wants us to do a
3067          * name allocation.
3068          */
3069         if (strchr(dev->name, '%')) {
3070                 err = dev_alloc_name(dev, dev->name);
3071                 if (err < 0)
3072                         goto out;
3073         }
3074         
3075         /*
3076          * Back compatibility hook. Kill this one in 2.5
3077          */
3078         if (dev->name[0] == 0 || dev->name[0] == ' ') {
3079                 err = dev_alloc_name(dev, "eth%d");
3080                 if (err < 0)
3081                         goto out;
3082         }
3083
3084         err = register_netdevice(dev);
3085 out:
3086         rtnl_unlock();
3087         return err;
3088 }
3089 EXPORT_SYMBOL(register_netdev);
3090
3091 /*
3092  * netdev_wait_allrefs - wait until all references are gone.
3093  *
3094  * This is called when unregistering network devices.
3095  *
3096  * Any protocol or device that holds a reference should register
3097  * for netdevice notification, and cleanup and put back the
3098  * reference if they receive an UNREGISTER event.
3099  * We can get stuck here if buggy protocols don't correctly
3100  * call dev_put. 
3101  */
3102 static void netdev_wait_allrefs(struct net_device *dev)
3103 {
3104         unsigned long rebroadcast_time, warning_time;
3105
3106         rebroadcast_time = warning_time = jiffies;
3107         while (atomic_read(&dev->refcnt) != 0) {
3108                 if (time_after(jiffies, rebroadcast_time + 1 * HZ)) {
3109                         rtnl_lock();
3110
3111                         /* Rebroadcast unregister notification */
3112                         raw_notifier_call_chain(&netdev_chain,
3113                                             NETDEV_UNREGISTER, dev);
3114
3115                         if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
3116                                      &dev->state)) {
3117                                 /* We must not have linkwatch events
3118                                  * pending on unregister. If this
3119                                  * happens, we simply run the queue
3120                                  * unscheduled, resulting in a noop
3121                                  * for this device.
3122                                  */
3123                                 linkwatch_run_queue();
3124                         }
3125
3126                         __rtnl_unlock();
3127
3128                         rebroadcast_time = jiffies;
3129                 }
3130
3131                 msleep(250);
3132
3133                 if (time_after(jiffies, warning_time + 10 * HZ)) {
3134                         printk(KERN_EMERG "unregister_netdevice: "
3135                                "waiting for %s to become free. Usage "
3136                                "count = %d\n",
3137                                dev->name, atomic_read(&dev->refcnt));
3138                         warning_time = jiffies;
3139                 }
3140         }
3141 }
3142
3143 /* The sequence is:
3144  *
3145  *      rtnl_lock();
3146  *      ...
3147  *      register_netdevice(x1);
3148  *      register_netdevice(x2);
3149  *      ...
3150  *      unregister_netdevice(y1);
3151  *      unregister_netdevice(y2);
3152  *      ...
3153  *      rtnl_unlock();
3154  *      free_netdev(y1);
3155  *      free_netdev(y2);
3156  *
3157  * We are invoked by rtnl_unlock() after it drops the semaphore.
3158  * This allows us to deal with problems:
3159  * 1) We can delete sysfs objects which invoke hotplug
3160  *    without deadlocking with linkwatch via keventd.
3161  * 2) Since we run with the RTNL semaphore not held, we can sleep
3162  *    safely in order to wait for the netdev refcnt to drop to zero.
3163  */
3164 static DEFINE_MUTEX(net_todo_run_mutex);
3165 void netdev_run_todo(void)
3166 {
3167         struct list_head list = LIST_HEAD_INIT(list);
3168
3169         /* Need to guard against multiple cpu's getting out of order. */
3170         mutex_lock(&net_todo_run_mutex);
3171
3172         /* Not safe to do outside the semaphore.  We must not return
3173          * until all unregister events invoked by the local processor
3174          * have been completed (either by this todo run, or one on
3175          * another cpu).
3176          */
3177         if (list_empty(&net_todo_list))
3178                 goto out;
3179
3180         /* Snapshot list, allow later requests */
3181         spin_lock(&net_todo_list_lock);
3182         list_splice_init(&net_todo_list, &list);
3183         spin_unlock(&net_todo_list_lock);
3184                 
3185         while (!list_empty(&list)) {
3186                 struct net_device *dev
3187                         = list_entry(list.next, struct net_device, todo_list);
3188                 list_del(&dev->todo_list);
3189
3190                 if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
3191                         printk(KERN_ERR "network todo '%s' but state %d\n",
3192                                dev->name, dev->reg_state);
3193                         dump_stack();
3194                         continue;
3195                 }
3196
3197                 netdev_unregister_sysfs(dev);
3198                 dev->reg_state = NETREG_UNREGISTERED;
3199
3200                 netdev_wait_allrefs(dev);
3201
3202                 /* paranoia */
3203                 BUG_ON(atomic_read(&dev->refcnt));
3204                 BUG_TRAP(!dev->ip_ptr);
3205                 BUG_TRAP(!dev->ip6_ptr);
3206                 BUG_TRAP(!dev->dn_ptr);
3207
3208                 /* It must be the very last action,
3209                  * after this 'dev' may point to freed up memory.
3210                  */
3211                 if (dev->destructor)
3212                         dev->destructor(dev);
3213         }
3214
3215 out:
3216         mutex_unlock(&net_todo_run_mutex);
3217 }
3218
3219 /**
3220  *      alloc_netdev - allocate network device
3221  *      @sizeof_priv:   size of private data to allocate space for
3222  *      @name:          device name format string
3223  *      @setup:         callback to initialize device
3224  *
3225  *      Allocates a struct net_device with private data area for driver use
3226  *      and performs basic initialization.
3227  */
3228 struct net_device *alloc_netdev(int sizeof_priv, const char *name,
3229                 void (*setup)(struct net_device *))
3230 {
3231         void *p;
3232         struct net_device *dev;
3233         int alloc_size;
3234
3235         /* ensure 32-byte alignment of both the device and private area */
3236         alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
3237         alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
3238
3239         p = kzalloc(alloc_size, GFP_KERNEL);
3240         if (!p) {
3241                 printk(KERN_ERR "alloc_dev: Unable to allocate device.\n");
3242                 return NULL;
3243         }
3244
3245         dev = (struct net_device *)
3246                 (((long)p + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
3247         dev->padded = (char *)dev - (char *)p;
3248
3249         if (sizeof_priv)
3250                 dev->priv = netdev_priv(dev);
3251
3252         setup(dev);
3253         strcpy(dev->name, name);
3254         return dev;
3255 }
3256 EXPORT_SYMBOL(alloc_netdev);
3257
3258 /**
3259  *      free_netdev - free network device
3260  *      @dev: device
3261  *
3262  *      This function does the last stage of destroying an allocated device 
3263  *      interface. The reference to the device object is released.  
3264  *      If this is the last reference then it will be freed.
3265  */
3266 void free_netdev(struct net_device *dev)
3267 {
3268 #ifdef CONFIG_SYSFS
3269         /*  Compatibility with error handling in drivers */
3270         if (dev->reg_state == NETREG_UNINITIALIZED) {
3271                 kfree((char *)dev - dev->padded);
3272                 return;
3273         }
3274
3275         BUG_ON(dev->reg_state != NETREG_UNREGISTERED);
3276         dev->reg_state = NETREG_RELEASED;
3277
3278         /* will free via class release */
3279         class_device_put(&dev->class_dev);
3280 #else
3281         kfree((char *)dev - dev->padded);
3282 #endif
3283 }
3284  
3285 /* Synchronize with packet receive processing. */
3286 void synchronize_net(void) 
3287 {
3288         might_sleep();
3289         synchronize_rcu();
3290 }
3291
3292 /**
3293  *      unregister_netdevice - remove device from the kernel
3294  *      @dev: device
3295  *
3296  *      This function shuts down a device interface and removes it
3297  *      from the kernel tables. On success 0 is returned, on a failure
3298  *      a negative errno code is returned.
3299  *
3300  *      Callers must hold the rtnl semaphore.  You may want
3301  *      unregister_netdev() instead of this.
3302  */
3303
3304 int unregister_netdevice(struct net_device *dev)
3305 {
3306         struct net_device *d, **dp;
3307
3308         BUG_ON(dev_boot_phase);
3309         ASSERT_RTNL();
3310
3311         /* Some devices call without registering for initialization unwind. */
3312         if (dev->reg_state == NETREG_UNINITIALIZED) {
3313                 printk(KERN_DEBUG "unregister_netdevice: device %s/%p never "
3314                                   "was registered\n", dev->name, dev);
3315                 return -ENODEV;
3316         }
3317
3318         BUG_ON(dev->reg_state != NETREG_REGISTERED);
3319
3320         /* If device is running, close it first. */
3321         if (dev->flags & IFF_UP)
3322                 dev_close(dev);
3323
3324         /* And unlink it from device chain. */
3325         for (dp = &dev_base; (d = *dp) != NULL; dp = &d->next) {
3326                 if (d == dev) {
3327                         write_lock_bh(&dev_base_lock);
3328                         hlist_del(&dev->name_hlist);
3329                         hlist_del(&dev->index_hlist);
3330                         if (dev_tail == &dev->next)
3331                                 dev_tail = dp;
3332                         *dp = d->next;
3333                         write_unlock_bh(&dev_base_lock);
3334                         break;
3335                 }
3336         }
3337         if (!d) {
3338                 printk(KERN_ERR "unregister net_device: '%s' not found\n",
3339                        dev->name);
3340                 return -ENODEV;
3341         }
3342
3343         dev->reg_state = NETREG_UNREGISTERING;
3344
3345         synchronize_net();
3346
3347         /* Shutdown queueing discipline. */
3348         dev_shutdown(dev);
3349
3350         
3351         /* Notify protocols, that we are about to destroy
3352            this device. They should clean all the things.
3353         */
3354         raw_notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
3355         
3356         /*
3357          *      Flush the multicast chain
3358          */
3359         dev_mc_discard(dev);
3360
3361         if (dev->uninit)
3362                 dev->uninit(dev);
3363
3364         /* Notifier chain MUST detach us from master device. */
3365         BUG_TRAP(!dev->master);
3366
3367         free_divert_blk(dev);
3368
3369         /* Finish processing unregister after unlock */
3370         net_set_todo(dev);
3371
3372         synchronize_net();
3373
3374         dev_put(dev);
3375         return 0;
3376 }
3377
3378 /**
3379  *      unregister_netdev - remove device from the kernel
3380  *      @dev: device
3381  *
3382  *      This function shuts down a device interface and removes it
3383  *      from the kernel tables. On success 0 is returned, on a failure
3384  *      a negative errno code is returned.
3385  *
3386  *      This is just a wrapper for unregister_netdevice that takes
3387  *      the rtnl semaphore.  In general you want to use this and not
3388  *      unregister_netdevice.
3389  */
3390 void unregister_netdev(struct net_device *dev)
3391 {
3392         rtnl_lock();
3393         unregister_netdevice(dev);
3394         rtnl_unlock();
3395 }
3396
3397 EXPORT_SYMBOL(unregister_netdev);
3398
3399 #ifdef CONFIG_HOTPLUG_CPU
3400 static int dev_cpu_callback(struct notifier_block *nfb,
3401                             unsigned long action,
3402                             void *ocpu)
3403 {
3404         struct sk_buff **list_skb;
3405         struct net_device **list_net;
3406         struct sk_buff *skb;
3407         unsigned int cpu, oldcpu = (unsigned long)ocpu;
3408         struct softnet_data *sd, *oldsd;
3409
3410         if (action != CPU_DEAD)
3411                 return NOTIFY_OK;
3412
3413         local_irq_disable();
3414         cpu = smp_processor_id();
3415         sd = &per_cpu(softnet_data, cpu);
3416         oldsd = &per_cpu(softnet_data, oldcpu);
3417
3418         /* Find end of our completion_queue. */
3419         list_skb = &sd->completion_queue;
3420         while (*list_skb)
3421                 list_skb = &(*list_skb)->next;
3422         /* Append completion queue from offline CPU. */
3423         *list_skb = oldsd->completion_queue;
3424         oldsd->completion_queue = NULL;
3425
3426         /* Find end of our output_queue. */
3427         list_net = &sd->output_queue;
3428         while (*list_net)
3429                 list_net = &(*list_net)->next_sched;
3430         /* Append output queue from offline CPU. */
3431         *list_net = oldsd->output_queue;
3432         oldsd->output_queue = NULL;
3433
3434         raise_softirq_irqoff(NET_TX_SOFTIRQ);
3435         local_irq_enable();
3436
3437         /* Process offline CPU's input_pkt_queue */
3438         while ((skb = __skb_dequeue(&oldsd->input_pkt_queue)))
3439                 netif_rx(skb);
3440
3441         return NOTIFY_OK;
3442 }
3443 #endif /* CONFIG_HOTPLUG_CPU */
3444
3445
3446 /*
3447  *      Initialize the DEV module. At boot time this walks the device list and
3448  *      unhooks any devices that fail to initialise (normally hardware not
3449  *      present) and leaves us with a valid list of present and active devices.
3450  *
3451  */
3452
3453 /*
3454  *       This is called single threaded during boot, so no need
3455  *       to take the rtnl semaphore.
3456  */
3457 static int __init net_dev_init(void)
3458 {
3459         int i, rc = -ENOMEM;
3460
3461         BUG_ON(!dev_boot_phase);
3462
3463         net_random_init();
3464
3465         if (dev_proc_init())
3466                 goto out;
3467
3468         if (netdev_sysfs_init())
3469                 goto out;
3470
3471         INIT_LIST_HEAD(&ptype_all);
3472         for (i = 0; i < 16; i++) 
3473                 INIT_LIST_HEAD(&ptype_base[i]);
3474
3475         for (i = 0; i < ARRAY_SIZE(dev_name_head); i++)
3476                 INIT_HLIST_HEAD(&dev_name_head[i]);
3477
3478         for (i = 0; i < ARRAY_SIZE(dev_index_head); i++)
3479                 INIT_HLIST_HEAD(&dev_index_head[i]);
3480
3481         /*
3482          *      Initialise the packet receive queues.
3483          */
3484
3485         for_each_possible_cpu(i) {
3486                 struct softnet_data *queue;
3487
3488                 queue = &per_cpu(softnet_data, i);
3489                 skb_queue_head_init(&queue->input_pkt_queue);
3490                 queue->completion_queue = NULL;
3491                 INIT_LIST_HEAD(&queue->poll_list);
3492                 set_bit(__LINK_STATE_START, &queue->backlog_dev.state);
3493                 queue->backlog_dev.weight = weight_p;
3494                 queue->backlog_dev.poll = process_backlog;
3495                 atomic_set(&queue->backlog_dev.refcnt, 1);
3496         }
3497
3498         dev_boot_phase = 0;
3499
3500         open_softirq(NET_TX_SOFTIRQ, net_tx_action, NULL);
3501         open_softirq(NET_RX_SOFTIRQ, net_rx_action, NULL);
3502
3503         hotcpu_notifier(dev_cpu_callback, 0);
3504         dst_init();
3505         dev_mcast_init();
3506         rc = 0;
3507 out:
3508         return rc;
3509 }
3510
3511 subsys_initcall(net_dev_init);
3512
3513 EXPORT_SYMBOL(__dev_get_by_index);
3514 EXPORT_SYMBOL(__dev_get_by_name);
3515 EXPORT_SYMBOL(__dev_remove_pack);
3516 EXPORT_SYMBOL(dev_valid_name);
3517 EXPORT_SYMBOL(dev_add_pack);
3518 EXPORT_SYMBOL(dev_alloc_name);
3519 EXPORT_SYMBOL(dev_close);
3520 EXPORT_SYMBOL(dev_get_by_flags);
3521 EXPORT_SYMBOL(dev_get_by_index);
3522 EXPORT_SYMBOL(dev_get_by_name);
3523 EXPORT_SYMBOL(dev_open);
3524 EXPORT_SYMBOL(dev_queue_xmit);
3525 EXPORT_SYMBOL(dev_remove_pack);
3526 EXPORT_SYMBOL(dev_set_allmulti);
3527 EXPORT_SYMBOL(dev_set_promiscuity);
3528 EXPORT_SYMBOL(dev_change_flags);
3529 EXPORT_SYMBOL(dev_set_mtu);
3530 EXPORT_SYMBOL(dev_set_mac_address);
3531 EXPORT_SYMBOL(free_netdev);
3532 EXPORT_SYMBOL(netdev_boot_setup_check);
3533 EXPORT_SYMBOL(netdev_set_master);
3534 EXPORT_SYMBOL(netdev_state_change);
3535 EXPORT_SYMBOL(netif_receive_skb);
3536 EXPORT_SYMBOL(netif_rx);
3537 EXPORT_SYMBOL(register_gifconf);
3538 EXPORT_SYMBOL(register_netdevice);
3539 EXPORT_SYMBOL(register_netdevice_notifier);
3540 EXPORT_SYMBOL(skb_checksum_help);
3541 EXPORT_SYMBOL(synchronize_net);
3542 EXPORT_SYMBOL(unregister_netdevice);
3543 EXPORT_SYMBOL(unregister_netdevice_notifier);
3544 EXPORT_SYMBOL(net_enable_timestamp);
3545 EXPORT_SYMBOL(net_disable_timestamp);
3546 EXPORT_SYMBOL(dev_get_flags);
3547 EXPORT_SYMBOL(skb_checksum_setup);
3548
3549 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
3550 EXPORT_SYMBOL(br_handle_frame_hook);
3551 EXPORT_SYMBOL(br_fdb_get_hook);
3552 EXPORT_SYMBOL(br_fdb_put_hook);
3553 #endif
3554
3555 #ifdef CONFIG_KMOD
3556 EXPORT_SYMBOL(dev_load);
3557 #endif
3558
3559 EXPORT_PER_CPU_SYMBOL(softnet_data);