dev.c 81 KB

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