dev.c 79 KB

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