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