pktgen.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624
  1. /*
  2. * Authors:
  3. * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se>
  4. * Uppsala University and
  5. * Swedish University of Agricultural Sciences
  6. *
  7. * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
  8. * Ben Greear <greearb@candelatech.com>
  9. * Jens Låås <jens.laas@data.slu.se>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. *
  16. *
  17. * A tool for loading the network with preconfigurated packets.
  18. * The tool is implemented as a linux module. Parameters are output
  19. * device, delay (to hard_xmit), number of packets, and whether
  20. * to use multiple SKBs or just the same one.
  21. * pktgen uses the installed interface's output routine.
  22. *
  23. * Additional hacking by:
  24. *
  25. * Jens.Laas@data.slu.se
  26. * Improved by ANK. 010120.
  27. * Improved by ANK even more. 010212.
  28. * MAC address typo fixed. 010417 --ro
  29. * Integrated. 020301 --DaveM
  30. * Added multiskb option 020301 --DaveM
  31. * Scaling of results. 020417--sigurdur@linpro.no
  32. * Significant re-work of the module:
  33. * * Convert to threaded model to more efficiently be able to transmit
  34. * and receive on multiple interfaces at once.
  35. * * Converted many counters to __u64 to allow longer runs.
  36. * * Allow configuration of ranges, like min/max IP address, MACs,
  37. * and UDP-ports, for both source and destination, and can
  38. * set to use a random distribution or sequentially walk the range.
  39. * * Can now change most values after starting.
  40. * * Place 12-byte packet in UDP payload with magic number,
  41. * sequence number, and timestamp.
  42. * * Add receiver code that detects dropped pkts, re-ordered pkts, and
  43. * latencies (with micro-second) precision.
  44. * * Add IOCTL interface to easily get counters & configuration.
  45. * --Ben Greear <greearb@candelatech.com>
  46. *
  47. * Renamed multiskb to clone_skb and cleaned up sending core for two distinct
  48. * skb modes. A clone_skb=0 mode for Ben "ranges" work and a clone_skb != 0
  49. * as a "fastpath" with a configurable number of clones after alloc's.
  50. * clone_skb=0 means all packets are allocated this also means ranges time
  51. * stamps etc can be used. clone_skb=100 means 1 malloc is followed by 100
  52. * clones.
  53. *
  54. * Also moved to /proc/net/pktgen/
  55. * --ro
  56. *
  57. * Sept 10: Fixed threading/locking. Lots of bone-headed and more clever
  58. * mistakes. Also merged in DaveM's patch in the -pre6 patch.
  59. * --Ben Greear <greearb@candelatech.com>
  60. *
  61. * Integrated to 2.5.x 021029 --Lucio Maciel (luciomaciel@zipmail.com.br)
  62. *
  63. *
  64. * 021124 Finished major redesign and rewrite for new functionality.
  65. * See Documentation/networking/pktgen.txt for how to use this.
  66. *
  67. * The new operation:
  68. * For each CPU one thread/process is created at start. This process checks
  69. * for running devices in the if_list and sends packets until count is 0 it
  70. * also the thread checks the thread->control which is used for inter-process
  71. * communication. controlling process "posts" operations to the threads this
  72. * way. The if_lock should be possible to remove when add/rem_device is merged
  73. * into this too.
  74. *
  75. * By design there should only be *one* "controlling" process. In practice
  76. * multiple write accesses gives unpredictable result. Understood by "write"
  77. * to /proc gives result code thats should be read be the "writer".
  78. * For practical use this should be no problem.
  79. *
  80. * Note when adding devices to a specific CPU there good idea to also assign
  81. * /proc/irq/XX/smp_affinity so TX-interrupts gets bound to the same CPU.
  82. * --ro
  83. *
  84. * Fix refcount off by one if first packet fails, potential null deref,
  85. * memleak 030710- KJP
  86. *
  87. * First "ranges" functionality for ipv6 030726 --ro
  88. *
  89. * Included flow support. 030802 ANK.
  90. *
  91. * Fixed unaligned access on IA-64 Grant Grundler <grundler@parisc-linux.org>
  92. *
  93. * Remove if fix from added Harald Welte <laforge@netfilter.org> 040419
  94. * ia64 compilation fix from Aron Griffis <aron@hp.com> 040604
  95. *
  96. * New xmit() return, do_div and misc clean up by Stephen Hemminger
  97. * <shemminger@osdl.org> 040923
  98. *
  99. * Randy Dunlap fixed u64 printk compiler waring
  100. *
  101. * Remove FCS from BW calculation. Lennert Buytenhek <buytenh@wantstofly.org>
  102. * New time handling. Lennert Buytenhek <buytenh@wantstofly.org> 041213
  103. *
  104. * Corrections from Nikolai Malykh (nmalykh@bilim.com)
  105. * Removed unused flags F_SET_SRCMAC & F_SET_SRCIP 041230
  106. *
  107. * interruptible_sleep_on_timeout() replaced Nishanth Aravamudan <nacc@us.ibm.com>
  108. * 050103
  109. *
  110. * MPLS support by Steven Whitehouse <steve@chygwyn.com>
  111. *
  112. * 802.1Q/Q-in-Q support by Francesco Fondelli (FF) <francesco.fondelli@gmail.com>
  113. *
  114. */
  115. #include <linux/sys.h>
  116. #include <linux/types.h>
  117. #include <linux/module.h>
  118. #include <linux/moduleparam.h>
  119. #include <linux/kernel.h>
  120. #include <linux/smp_lock.h>
  121. #include <linux/mutex.h>
  122. #include <linux/sched.h>
  123. #include <linux/slab.h>
  124. #include <linux/vmalloc.h>
  125. #include <linux/unistd.h>
  126. #include <linux/string.h>
  127. #include <linux/ptrace.h>
  128. #include <linux/errno.h>
  129. #include <linux/ioport.h>
  130. #include <linux/interrupt.h>
  131. #include <linux/capability.h>
  132. #include <linux/freezer.h>
  133. #include <linux/delay.h>
  134. #include <linux/timer.h>
  135. #include <linux/list.h>
  136. #include <linux/init.h>
  137. #include <linux/skbuff.h>
  138. #include <linux/netdevice.h>
  139. #include <linux/inet.h>
  140. #include <linux/inetdevice.h>
  141. #include <linux/rtnetlink.h>
  142. #include <linux/if_arp.h>
  143. #include <linux/if_vlan.h>
  144. #include <linux/in.h>
  145. #include <linux/ip.h>
  146. #include <linux/ipv6.h>
  147. #include <linux/udp.h>
  148. #include <linux/proc_fs.h>
  149. #include <linux/seq_file.h>
  150. #include <linux/wait.h>
  151. #include <linux/etherdevice.h>
  152. #include <linux/kthread.h>
  153. #include <net/checksum.h>
  154. #include <net/ipv6.h>
  155. #include <net/addrconf.h>
  156. #include <asm/byteorder.h>
  157. #include <linux/rcupdate.h>
  158. #include <asm/bitops.h>
  159. #include <asm/io.h>
  160. #include <asm/dma.h>
  161. #include <asm/uaccess.h>
  162. #include <asm/div64.h> /* do_div */
  163. #include <asm/timex.h>
  164. #define VERSION "pktgen v2.68: Packet Generator for packet performance testing.\n"
  165. /* The buckets are exponential in 'width' */
  166. #define LAT_BUCKETS_MAX 32
  167. #define IP_NAME_SZ 32
  168. #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
  169. #define MPLS_STACK_BOTTOM __constant_htonl(0x00000100)
  170. /* Device flag bits */
  171. #define F_IPSRC_RND (1<<0) /* IP-Src Random */
  172. #define F_IPDST_RND (1<<1) /* IP-Dst Random */
  173. #define F_UDPSRC_RND (1<<2) /* UDP-Src Random */
  174. #define F_UDPDST_RND (1<<3) /* UDP-Dst Random */
  175. #define F_MACSRC_RND (1<<4) /* MAC-Src Random */
  176. #define F_MACDST_RND (1<<5) /* MAC-Dst Random */
  177. #define F_TXSIZE_RND (1<<6) /* Transmit size is random */
  178. #define F_IPV6 (1<<7) /* Interface in IPV6 Mode */
  179. #define F_MPLS_RND (1<<8) /* Random MPLS labels */
  180. #define F_VID_RND (1<<9) /* Random VLAN ID */
  181. #define F_SVID_RND (1<<10) /* Random SVLAN ID */
  182. /* Thread control flag bits */
  183. #define T_TERMINATE (1<<0)
  184. #define T_STOP (1<<1) /* Stop run */
  185. #define T_RUN (1<<2) /* Start run */
  186. #define T_REMDEVALL (1<<3) /* Remove all devs */
  187. #define T_REMDEV (1<<4) /* Remove one dev */
  188. /* If lock -- can be removed after some work */
  189. #define if_lock(t) spin_lock(&(t->if_lock));
  190. #define if_unlock(t) spin_unlock(&(t->if_lock));
  191. /* Used to help with determining the pkts on receive */
  192. #define PKTGEN_MAGIC 0xbe9be955
  193. #define PG_PROC_DIR "pktgen"
  194. #define PGCTRL "pgctrl"
  195. static struct proc_dir_entry *pg_proc_dir = NULL;
  196. #define MAX_CFLOWS 65536
  197. #define VLAN_TAG_SIZE(x) ((x)->vlan_id == 0xffff ? 0 : 4)
  198. #define SVLAN_TAG_SIZE(x) ((x)->svlan_id == 0xffff ? 0 : 4)
  199. struct flow_state {
  200. __be32 cur_daddr;
  201. int count;
  202. };
  203. struct pktgen_dev {
  204. /*
  205. * Try to keep frequent/infrequent used vars. separated.
  206. */
  207. char ifname[IFNAMSIZ];
  208. char result[512];
  209. struct pktgen_thread *pg_thread; /* the owner */
  210. struct list_head list; /* Used for chaining in the thread's run-queue */
  211. int running; /* if this changes to false, the test will stop */
  212. /* If min != max, then we will either do a linear iteration, or
  213. * we will do a random selection from within the range.
  214. */
  215. __u32 flags;
  216. int removal_mark; /* non-zero => the device is marked for
  217. * removal by worker thread */
  218. int min_pkt_size; /* = ETH_ZLEN; */
  219. int max_pkt_size; /* = ETH_ZLEN; */
  220. int nfrags;
  221. __u32 delay_us; /* Default delay */
  222. __u32 delay_ns;
  223. __u64 count; /* Default No packets to send */
  224. __u64 sofar; /* How many pkts we've sent so far */
  225. __u64 tx_bytes; /* How many bytes we've transmitted */
  226. __u64 errors; /* Errors when trying to transmit, pkts will be re-sent */
  227. /* runtime counters relating to clone_skb */
  228. __u64 next_tx_us; /* timestamp of when to tx next */
  229. __u32 next_tx_ns;
  230. __u64 allocated_skbs;
  231. __u32 clone_count;
  232. int last_ok; /* Was last skb sent?
  233. * Or a failed transmit of some sort? This will keep
  234. * sequence numbers in order, for example.
  235. */
  236. __u64 started_at; /* micro-seconds */
  237. __u64 stopped_at; /* micro-seconds */
  238. __u64 idle_acc; /* micro-seconds */
  239. __u32 seq_num;
  240. int clone_skb; /* Use multiple SKBs during packet gen. If this number
  241. * is greater than 1, then that many copies of the same
  242. * packet will be sent before a new packet is allocated.
  243. * For instance, if you want to send 1024 identical packets
  244. * before creating a new packet, set clone_skb to 1024.
  245. */
  246. char dst_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
  247. char dst_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
  248. char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
  249. char src_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */
  250. struct in6_addr in6_saddr;
  251. struct in6_addr in6_daddr;
  252. struct in6_addr cur_in6_daddr;
  253. struct in6_addr cur_in6_saddr;
  254. /* For ranges */
  255. struct in6_addr min_in6_daddr;
  256. struct in6_addr max_in6_daddr;
  257. struct in6_addr min_in6_saddr;
  258. struct in6_addr max_in6_saddr;
  259. /* If we're doing ranges, random or incremental, then this
  260. * defines the min/max for those ranges.
  261. */
  262. __be32 saddr_min; /* inclusive, source IP address */
  263. __be32 saddr_max; /* exclusive, source IP address */
  264. __be32 daddr_min; /* inclusive, dest IP address */
  265. __be32 daddr_max; /* exclusive, dest IP address */
  266. __u16 udp_src_min; /* inclusive, source UDP port */
  267. __u16 udp_src_max; /* exclusive, source UDP port */
  268. __u16 udp_dst_min; /* inclusive, dest UDP port */
  269. __u16 udp_dst_max; /* exclusive, dest UDP port */
  270. /* DSCP + ECN */
  271. __u8 tos; /* six most significant bits of (former) IPv4 TOS are for dscp codepoint */
  272. __u8 traffic_class; /* ditto for the (former) Traffic Class in IPv6 (see RFC 3260, sec. 4) */
  273. /* MPLS */
  274. unsigned nr_labels; /* Depth of stack, 0 = no MPLS */
  275. __be32 labels[MAX_MPLS_LABELS];
  276. /* VLAN/SVLAN (802.1Q/Q-in-Q) */
  277. __u8 vlan_p;
  278. __u8 vlan_cfi;
  279. __u16 vlan_id; /* 0xffff means no vlan tag */
  280. __u8 svlan_p;
  281. __u8 svlan_cfi;
  282. __u16 svlan_id; /* 0xffff means no svlan tag */
  283. __u32 src_mac_count; /* How many MACs to iterate through */
  284. __u32 dst_mac_count; /* How many MACs to iterate through */
  285. unsigned char dst_mac[ETH_ALEN];
  286. unsigned char src_mac[ETH_ALEN];
  287. __u32 cur_dst_mac_offset;
  288. __u32 cur_src_mac_offset;
  289. __be32 cur_saddr;
  290. __be32 cur_daddr;
  291. __u16 cur_udp_dst;
  292. __u16 cur_udp_src;
  293. __u32 cur_pkt_size;
  294. __u8 hh[14];
  295. /* = {
  296. 0x00, 0x80, 0xC8, 0x79, 0xB3, 0xCB,
  297. We fill in SRC address later
  298. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  299. 0x08, 0x00
  300. };
  301. */
  302. __u16 pad; /* pad out the hh struct to an even 16 bytes */
  303. struct sk_buff *skb; /* skb we are to transmit next, mainly used for when we
  304. * are transmitting the same one multiple times
  305. */
  306. struct net_device *odev; /* The out-going device. Note that the device should
  307. * have it's pg_info pointer pointing back to this
  308. * device. This will be set when the user specifies
  309. * the out-going device name (not when the inject is
  310. * started as it used to do.)
  311. */
  312. struct flow_state *flows;
  313. unsigned cflows; /* Concurrent flows (config) */
  314. unsigned lflow; /* Flow length (config) */
  315. unsigned nflows; /* accumulated flows (stats) */
  316. };
  317. struct pktgen_hdr {
  318. __be32 pgh_magic;
  319. __be32 seq_num;
  320. __be32 tv_sec;
  321. __be32 tv_usec;
  322. };
  323. struct pktgen_thread {
  324. spinlock_t if_lock;
  325. struct list_head if_list; /* All device here */
  326. struct list_head th_list;
  327. struct task_struct *tsk;
  328. char result[512];
  329. u32 max_before_softirq; /* We'll call do_softirq to prevent starvation. */
  330. /* Field for thread to receive "posted" events terminate, stop ifs etc. */
  331. u32 control;
  332. int pid;
  333. int cpu;
  334. wait_queue_head_t queue;
  335. };
  336. #define REMOVE 1
  337. #define FIND 0
  338. /* This code works around the fact that do_div cannot handle two 64-bit
  339. numbers, and regular 64-bit division doesn't work on x86 kernels.
  340. --Ben
  341. */
  342. #define PG_DIV 0
  343. /* This was emailed to LMKL by: Chris Caputo <ccaputo@alt.net>
  344. * Function copied/adapted/optimized from:
  345. *
  346. * nemesis.sourceforge.net/browse/lib/static/intmath/ix86/intmath.c.html
  347. *
  348. * Copyright 1994, University of Cambridge Computer Laboratory
  349. * All Rights Reserved.
  350. *
  351. */
  352. static inline s64 divremdi3(s64 x, s64 y, int type)
  353. {
  354. u64 a = (x < 0) ? -x : x;
  355. u64 b = (y < 0) ? -y : y;
  356. u64 res = 0, d = 1;
  357. if (b > 0) {
  358. while (b < a) {
  359. b <<= 1;
  360. d <<= 1;
  361. }
  362. }
  363. do {
  364. if (a >= b) {
  365. a -= b;
  366. res += d;
  367. }
  368. b >>= 1;
  369. d >>= 1;
  370. }
  371. while (d);
  372. if (PG_DIV == type) {
  373. return (((x ^ y) & (1ll << 63)) == 0) ? res : -(s64) res;
  374. } else {
  375. return ((x & (1ll << 63)) == 0) ? a : -(s64) a;
  376. }
  377. }
  378. /* End of hacks to deal with 64-bit math on x86 */
  379. /** Convert to milliseconds */
  380. static inline __u64 tv_to_ms(const struct timeval *tv)
  381. {
  382. __u64 ms = tv->tv_usec / 1000;
  383. ms += (__u64) tv->tv_sec * (__u64) 1000;
  384. return ms;
  385. }
  386. /** Convert to micro-seconds */
  387. static inline __u64 tv_to_us(const struct timeval *tv)
  388. {
  389. __u64 us = tv->tv_usec;
  390. us += (__u64) tv->tv_sec * (__u64) 1000000;
  391. return us;
  392. }
  393. static inline __u64 pg_div(__u64 n, __u32 base)
  394. {
  395. __u64 tmp = n;
  396. do_div(tmp, base);
  397. /* printk("pktgen: pg_div, n: %llu base: %d rv: %llu\n",
  398. n, base, tmp); */
  399. return tmp;
  400. }
  401. static inline __u64 pg_div64(__u64 n, __u64 base)
  402. {
  403. __u64 tmp = n;
  404. /*
  405. * How do we know if the architecture we are running on
  406. * supports division with 64 bit base?
  407. *
  408. */
  409. #if defined(__sparc_v9__) || defined(__powerpc64__) || defined(__alpha__) || defined(__x86_64__) || defined(__ia64__)
  410. do_div(tmp, base);
  411. #else
  412. tmp = divremdi3(n, base, PG_DIV);
  413. #endif
  414. return tmp;
  415. }
  416. static inline __u64 getCurMs(void)
  417. {
  418. struct timeval tv;
  419. do_gettimeofday(&tv);
  420. return tv_to_ms(&tv);
  421. }
  422. static inline __u64 getCurUs(void)
  423. {
  424. struct timeval tv;
  425. do_gettimeofday(&tv);
  426. return tv_to_us(&tv);
  427. }
  428. static inline __u64 tv_diff(const struct timeval *a, const struct timeval *b)
  429. {
  430. return tv_to_us(a) - tv_to_us(b);
  431. }
  432. /* old include end */
  433. static char version[] __initdata = VERSION;
  434. static int pktgen_remove_device(struct pktgen_thread *t, struct pktgen_dev *i);
  435. static int pktgen_add_device(struct pktgen_thread *t, const char *ifname);
  436. static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
  437. const char *ifname);
  438. static int pktgen_device_event(struct notifier_block *, unsigned long, void *);
  439. static void pktgen_run_all_threads(void);
  440. static void pktgen_stop_all_threads_ifs(void);
  441. static int pktgen_stop_device(struct pktgen_dev *pkt_dev);
  442. static void pktgen_stop(struct pktgen_thread *t);
  443. static void pktgen_clear_counters(struct pktgen_dev *pkt_dev);
  444. static int pktgen_mark_device(const char *ifname);
  445. static unsigned int scan_ip6(const char *s, char ip[16]);
  446. static unsigned int fmt_ip6(char *s, const char ip[16]);
  447. /* Module parameters, defaults. */
  448. static int pg_count_d = 1000; /* 1000 pkts by default */
  449. static int pg_delay_d;
  450. static int pg_clone_skb_d;
  451. static int debug;
  452. static DEFINE_MUTEX(pktgen_thread_lock);
  453. static LIST_HEAD(pktgen_threads);
  454. static struct notifier_block pktgen_notifier_block = {
  455. .notifier_call = pktgen_device_event,
  456. };
  457. /*
  458. * /proc handling functions
  459. *
  460. */
  461. static int pgctrl_show(struct seq_file *seq, void *v)
  462. {
  463. seq_puts(seq, VERSION);
  464. return 0;
  465. }
  466. static ssize_t pgctrl_write(struct file *file, const char __user * buf,
  467. size_t count, loff_t * ppos)
  468. {
  469. int err = 0;
  470. char data[128];
  471. if (!capable(CAP_NET_ADMIN)) {
  472. err = -EPERM;
  473. goto out;
  474. }
  475. if (count > sizeof(data))
  476. count = sizeof(data);
  477. if (copy_from_user(data, buf, count)) {
  478. err = -EFAULT;
  479. goto out;
  480. }
  481. data[count - 1] = 0; /* Make string */
  482. if (!strcmp(data, "stop"))
  483. pktgen_stop_all_threads_ifs();
  484. else if (!strcmp(data, "start"))
  485. pktgen_run_all_threads();
  486. else
  487. printk("pktgen: Unknown command: %s\n", data);
  488. err = count;
  489. out:
  490. return err;
  491. }
  492. static int pgctrl_open(struct inode *inode, struct file *file)
  493. {
  494. return single_open(file, pgctrl_show, PDE(inode)->data);
  495. }
  496. static const struct file_operations pktgen_fops = {
  497. .owner = THIS_MODULE,
  498. .open = pgctrl_open,
  499. .read = seq_read,
  500. .llseek = seq_lseek,
  501. .write = pgctrl_write,
  502. .release = single_release,
  503. };
  504. static int pktgen_if_show(struct seq_file *seq, void *v)
  505. {
  506. int i;
  507. struct pktgen_dev *pkt_dev = seq->private;
  508. __u64 sa;
  509. __u64 stopped;
  510. __u64 now = getCurUs();
  511. seq_printf(seq,
  512. "Params: count %llu min_pkt_size: %u max_pkt_size: %u\n",
  513. (unsigned long long)pkt_dev->count, pkt_dev->min_pkt_size,
  514. pkt_dev->max_pkt_size);
  515. seq_printf(seq,
  516. " frags: %d delay: %u clone_skb: %d ifname: %s\n",
  517. pkt_dev->nfrags,
  518. 1000 * pkt_dev->delay_us + pkt_dev->delay_ns,
  519. pkt_dev->clone_skb, pkt_dev->ifname);
  520. seq_printf(seq, " flows: %u flowlen: %u\n", pkt_dev->cflows,
  521. pkt_dev->lflow);
  522. if (pkt_dev->flags & F_IPV6) {
  523. char b1[128], b2[128], b3[128];
  524. fmt_ip6(b1, pkt_dev->in6_saddr.s6_addr);
  525. fmt_ip6(b2, pkt_dev->min_in6_saddr.s6_addr);
  526. fmt_ip6(b3, pkt_dev->max_in6_saddr.s6_addr);
  527. seq_printf(seq,
  528. " saddr: %s min_saddr: %s max_saddr: %s\n", b1,
  529. b2, b3);
  530. fmt_ip6(b1, pkt_dev->in6_daddr.s6_addr);
  531. fmt_ip6(b2, pkt_dev->min_in6_daddr.s6_addr);
  532. fmt_ip6(b3, pkt_dev->max_in6_daddr.s6_addr);
  533. seq_printf(seq,
  534. " daddr: %s min_daddr: %s max_daddr: %s\n", b1,
  535. b2, b3);
  536. } else
  537. seq_printf(seq,
  538. " dst_min: %s dst_max: %s\n src_min: %s src_max: %s\n",
  539. pkt_dev->dst_min, pkt_dev->dst_max, pkt_dev->src_min,
  540. pkt_dev->src_max);
  541. seq_puts(seq, " src_mac: ");
  542. if (is_zero_ether_addr(pkt_dev->src_mac))
  543. for (i = 0; i < 6; i++)
  544. seq_printf(seq, "%02X%s", pkt_dev->odev->dev_addr[i],
  545. i == 5 ? " " : ":");
  546. else
  547. for (i = 0; i < 6; i++)
  548. seq_printf(seq, "%02X%s", pkt_dev->src_mac[i],
  549. i == 5 ? " " : ":");
  550. seq_printf(seq, "dst_mac: ");
  551. for (i = 0; i < 6; i++)
  552. seq_printf(seq, "%02X%s", pkt_dev->dst_mac[i],
  553. i == 5 ? "\n" : ":");
  554. seq_printf(seq,
  555. " udp_src_min: %d udp_src_max: %d udp_dst_min: %d udp_dst_max: %d\n",
  556. pkt_dev->udp_src_min, pkt_dev->udp_src_max,
  557. pkt_dev->udp_dst_min, pkt_dev->udp_dst_max);
  558. seq_printf(seq,
  559. " src_mac_count: %d dst_mac_count: %d\n",
  560. pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
  561. if (pkt_dev->nr_labels) {
  562. unsigned i;
  563. seq_printf(seq, " mpls: ");
  564. for(i = 0; i < pkt_dev->nr_labels; i++)
  565. seq_printf(seq, "%08x%s", ntohl(pkt_dev->labels[i]),
  566. i == pkt_dev->nr_labels-1 ? "\n" : ", ");
  567. }
  568. if (pkt_dev->vlan_id != 0xffff) {
  569. seq_printf(seq, " vlan_id: %u vlan_p: %u vlan_cfi: %u\n",
  570. pkt_dev->vlan_id, pkt_dev->vlan_p, pkt_dev->vlan_cfi);
  571. }
  572. if (pkt_dev->svlan_id != 0xffff) {
  573. seq_printf(seq, " svlan_id: %u vlan_p: %u vlan_cfi: %u\n",
  574. pkt_dev->svlan_id, pkt_dev->svlan_p, pkt_dev->svlan_cfi);
  575. }
  576. if (pkt_dev->tos) {
  577. seq_printf(seq, " tos: 0x%02x\n", pkt_dev->tos);
  578. }
  579. if (pkt_dev->traffic_class) {
  580. seq_printf(seq, " traffic_class: 0x%02x\n", pkt_dev->traffic_class);
  581. }
  582. seq_printf(seq, " Flags: ");
  583. if (pkt_dev->flags & F_IPV6)
  584. seq_printf(seq, "IPV6 ");
  585. if (pkt_dev->flags & F_IPSRC_RND)
  586. seq_printf(seq, "IPSRC_RND ");
  587. if (pkt_dev->flags & F_IPDST_RND)
  588. seq_printf(seq, "IPDST_RND ");
  589. if (pkt_dev->flags & F_TXSIZE_RND)
  590. seq_printf(seq, "TXSIZE_RND ");
  591. if (pkt_dev->flags & F_UDPSRC_RND)
  592. seq_printf(seq, "UDPSRC_RND ");
  593. if (pkt_dev->flags & F_UDPDST_RND)
  594. seq_printf(seq, "UDPDST_RND ");
  595. if (pkt_dev->flags & F_MPLS_RND)
  596. seq_printf(seq, "MPLS_RND ");
  597. if (pkt_dev->flags & F_MACSRC_RND)
  598. seq_printf(seq, "MACSRC_RND ");
  599. if (pkt_dev->flags & F_MACDST_RND)
  600. seq_printf(seq, "MACDST_RND ");
  601. if (pkt_dev->flags & F_VID_RND)
  602. seq_printf(seq, "VID_RND ");
  603. if (pkt_dev->flags & F_SVID_RND)
  604. seq_printf(seq, "SVID_RND ");
  605. seq_puts(seq, "\n");
  606. sa = pkt_dev->started_at;
  607. stopped = pkt_dev->stopped_at;
  608. if (pkt_dev->running)
  609. stopped = now; /* not really stopped, more like last-running-at */
  610. seq_printf(seq,
  611. "Current:\n pkts-sofar: %llu errors: %llu\n started: %lluus stopped: %lluus idle: %lluus\n",
  612. (unsigned long long)pkt_dev->sofar,
  613. (unsigned long long)pkt_dev->errors, (unsigned long long)sa,
  614. (unsigned long long)stopped,
  615. (unsigned long long)pkt_dev->idle_acc);
  616. seq_printf(seq,
  617. " seq_num: %d cur_dst_mac_offset: %d cur_src_mac_offset: %d\n",
  618. pkt_dev->seq_num, pkt_dev->cur_dst_mac_offset,
  619. pkt_dev->cur_src_mac_offset);
  620. if (pkt_dev->flags & F_IPV6) {
  621. char b1[128], b2[128];
  622. fmt_ip6(b1, pkt_dev->cur_in6_daddr.s6_addr);
  623. fmt_ip6(b2, pkt_dev->cur_in6_saddr.s6_addr);
  624. seq_printf(seq, " cur_saddr: %s cur_daddr: %s\n", b2, b1);
  625. } else
  626. seq_printf(seq, " cur_saddr: 0x%x cur_daddr: 0x%x\n",
  627. pkt_dev->cur_saddr, pkt_dev->cur_daddr);
  628. seq_printf(seq, " cur_udp_dst: %d cur_udp_src: %d\n",
  629. pkt_dev->cur_udp_dst, pkt_dev->cur_udp_src);
  630. seq_printf(seq, " flows: %u\n", pkt_dev->nflows);
  631. if (pkt_dev->result[0])
  632. seq_printf(seq, "Result: %s\n", pkt_dev->result);
  633. else
  634. seq_printf(seq, "Result: Idle\n");
  635. return 0;
  636. }
  637. static int hex32_arg(const char __user *user_buffer, unsigned long maxlen, __u32 *num)
  638. {
  639. int i = 0;
  640. *num = 0;
  641. for(; i < maxlen; i++) {
  642. char c;
  643. *num <<= 4;
  644. if (get_user(c, &user_buffer[i]))
  645. return -EFAULT;
  646. if ((c >= '0') && (c <= '9'))
  647. *num |= c - '0';
  648. else if ((c >= 'a') && (c <= 'f'))
  649. *num |= c - 'a' + 10;
  650. else if ((c >= 'A') && (c <= 'F'))
  651. *num |= c - 'A' + 10;
  652. else
  653. break;
  654. }
  655. return i;
  656. }
  657. static int count_trail_chars(const char __user * user_buffer,
  658. unsigned int maxlen)
  659. {
  660. int i;
  661. for (i = 0; i < maxlen; i++) {
  662. char c;
  663. if (get_user(c, &user_buffer[i]))
  664. return -EFAULT;
  665. switch (c) {
  666. case '\"':
  667. case '\n':
  668. case '\r':
  669. case '\t':
  670. case ' ':
  671. case '=':
  672. break;
  673. default:
  674. goto done;
  675. };
  676. }
  677. done:
  678. return i;
  679. }
  680. static unsigned long num_arg(const char __user * user_buffer,
  681. unsigned long maxlen, unsigned long *num)
  682. {
  683. int i = 0;
  684. *num = 0;
  685. for (; i < maxlen; i++) {
  686. char c;
  687. if (get_user(c, &user_buffer[i]))
  688. return -EFAULT;
  689. if ((c >= '0') && (c <= '9')) {
  690. *num *= 10;
  691. *num += c - '0';
  692. } else
  693. break;
  694. }
  695. return i;
  696. }
  697. static int strn_len(const char __user * user_buffer, unsigned int maxlen)
  698. {
  699. int i = 0;
  700. for (; i < maxlen; i++) {
  701. char c;
  702. if (get_user(c, &user_buffer[i]))
  703. return -EFAULT;
  704. switch (c) {
  705. case '\"':
  706. case '\n':
  707. case '\r':
  708. case '\t':
  709. case ' ':
  710. goto done_str;
  711. break;
  712. default:
  713. break;
  714. };
  715. }
  716. done_str:
  717. return i;
  718. }
  719. static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev)
  720. {
  721. unsigned n = 0;
  722. char c;
  723. ssize_t i = 0;
  724. int len;
  725. pkt_dev->nr_labels = 0;
  726. do {
  727. __u32 tmp;
  728. len = hex32_arg(&buffer[i], 8, &tmp);
  729. if (len <= 0)
  730. return len;
  731. pkt_dev->labels[n] = htonl(tmp);
  732. if (pkt_dev->labels[n] & MPLS_STACK_BOTTOM)
  733. pkt_dev->flags |= F_MPLS_RND;
  734. i += len;
  735. if (get_user(c, &buffer[i]))
  736. return -EFAULT;
  737. i++;
  738. n++;
  739. if (n >= MAX_MPLS_LABELS)
  740. return -E2BIG;
  741. } while(c == ',');
  742. pkt_dev->nr_labels = n;
  743. return i;
  744. }
  745. static ssize_t pktgen_if_write(struct file *file,
  746. const char __user * user_buffer, size_t count,
  747. loff_t * offset)
  748. {
  749. struct seq_file *seq = (struct seq_file *)file->private_data;
  750. struct pktgen_dev *pkt_dev = seq->private;
  751. int i = 0, max, len;
  752. char name[16], valstr[32];
  753. unsigned long value = 0;
  754. char *pg_result = NULL;
  755. int tmp = 0;
  756. char buf[128];
  757. pg_result = &(pkt_dev->result[0]);
  758. if (count < 1) {
  759. printk("pktgen: wrong command format\n");
  760. return -EINVAL;
  761. }
  762. max = count - i;
  763. tmp = count_trail_chars(&user_buffer[i], max);
  764. if (tmp < 0) {
  765. printk("pktgen: illegal format\n");
  766. return tmp;
  767. }
  768. i += tmp;
  769. /* Read variable name */
  770. len = strn_len(&user_buffer[i], sizeof(name) - 1);
  771. if (len < 0) {
  772. return len;
  773. }
  774. memset(name, 0, sizeof(name));
  775. if (copy_from_user(name, &user_buffer[i], len))
  776. return -EFAULT;
  777. i += len;
  778. max = count - i;
  779. len = count_trail_chars(&user_buffer[i], max);
  780. if (len < 0)
  781. return len;
  782. i += len;
  783. if (debug) {
  784. char tb[count + 1];
  785. if (copy_from_user(tb, user_buffer, count))
  786. return -EFAULT;
  787. tb[count] = 0;
  788. printk("pktgen: %s,%lu buffer -:%s:-\n", name,
  789. (unsigned long)count, tb);
  790. }
  791. if (!strcmp(name, "min_pkt_size")) {
  792. len = num_arg(&user_buffer[i], 10, &value);
  793. if (len < 0) {
  794. return len;
  795. }
  796. i += len;
  797. if (value < 14 + 20 + 8)
  798. value = 14 + 20 + 8;
  799. if (value != pkt_dev->min_pkt_size) {
  800. pkt_dev->min_pkt_size = value;
  801. pkt_dev->cur_pkt_size = value;
  802. }
  803. sprintf(pg_result, "OK: min_pkt_size=%u",
  804. pkt_dev->min_pkt_size);
  805. return count;
  806. }
  807. if (!strcmp(name, "max_pkt_size")) {
  808. len = num_arg(&user_buffer[i], 10, &value);
  809. if (len < 0) {
  810. return len;
  811. }
  812. i += len;
  813. if (value < 14 + 20 + 8)
  814. value = 14 + 20 + 8;
  815. if (value != pkt_dev->max_pkt_size) {
  816. pkt_dev->max_pkt_size = value;
  817. pkt_dev->cur_pkt_size = value;
  818. }
  819. sprintf(pg_result, "OK: max_pkt_size=%u",
  820. pkt_dev->max_pkt_size);
  821. return count;
  822. }
  823. /* Shortcut for min = max */
  824. if (!strcmp(name, "pkt_size")) {
  825. len = num_arg(&user_buffer[i], 10, &value);
  826. if (len < 0) {
  827. return len;
  828. }
  829. i += len;
  830. if (value < 14 + 20 + 8)
  831. value = 14 + 20 + 8;
  832. if (value != pkt_dev->min_pkt_size) {
  833. pkt_dev->min_pkt_size = value;
  834. pkt_dev->max_pkt_size = value;
  835. pkt_dev->cur_pkt_size = value;
  836. }
  837. sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size);
  838. return count;
  839. }
  840. if (!strcmp(name, "debug")) {
  841. len = num_arg(&user_buffer[i], 10, &value);
  842. if (len < 0) {
  843. return len;
  844. }
  845. i += len;
  846. debug = value;
  847. sprintf(pg_result, "OK: debug=%u", debug);
  848. return count;
  849. }
  850. if (!strcmp(name, "frags")) {
  851. len = num_arg(&user_buffer[i], 10, &value);
  852. if (len < 0) {
  853. return len;
  854. }
  855. i += len;
  856. pkt_dev->nfrags = value;
  857. sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags);
  858. return count;
  859. }
  860. if (!strcmp(name, "delay")) {
  861. len = num_arg(&user_buffer[i], 10, &value);
  862. if (len < 0) {
  863. return len;
  864. }
  865. i += len;
  866. if (value == 0x7FFFFFFF) {
  867. pkt_dev->delay_us = 0x7FFFFFFF;
  868. pkt_dev->delay_ns = 0;
  869. } else {
  870. pkt_dev->delay_us = value / 1000;
  871. pkt_dev->delay_ns = value % 1000;
  872. }
  873. sprintf(pg_result, "OK: delay=%u",
  874. 1000 * pkt_dev->delay_us + pkt_dev->delay_ns);
  875. return count;
  876. }
  877. if (!strcmp(name, "udp_src_min")) {
  878. len = num_arg(&user_buffer[i], 10, &value);
  879. if (len < 0) {
  880. return len;
  881. }
  882. i += len;
  883. if (value != pkt_dev->udp_src_min) {
  884. pkt_dev->udp_src_min = value;
  885. pkt_dev->cur_udp_src = value;
  886. }
  887. sprintf(pg_result, "OK: udp_src_min=%u", pkt_dev->udp_src_min);
  888. return count;
  889. }
  890. if (!strcmp(name, "udp_dst_min")) {
  891. len = num_arg(&user_buffer[i], 10, &value);
  892. if (len < 0) {
  893. return len;
  894. }
  895. i += len;
  896. if (value != pkt_dev->udp_dst_min) {
  897. pkt_dev->udp_dst_min = value;
  898. pkt_dev->cur_udp_dst = value;
  899. }
  900. sprintf(pg_result, "OK: udp_dst_min=%u", pkt_dev->udp_dst_min);
  901. return count;
  902. }
  903. if (!strcmp(name, "udp_src_max")) {
  904. len = num_arg(&user_buffer[i], 10, &value);
  905. if (len < 0) {
  906. return len;
  907. }
  908. i += len;
  909. if (value != pkt_dev->udp_src_max) {
  910. pkt_dev->udp_src_max = value;
  911. pkt_dev->cur_udp_src = value;
  912. }
  913. sprintf(pg_result, "OK: udp_src_max=%u", pkt_dev->udp_src_max);
  914. return count;
  915. }
  916. if (!strcmp(name, "udp_dst_max")) {
  917. len = num_arg(&user_buffer[i], 10, &value);
  918. if (len < 0) {
  919. return len;
  920. }
  921. i += len;
  922. if (value != pkt_dev->udp_dst_max) {
  923. pkt_dev->udp_dst_max = value;
  924. pkt_dev->cur_udp_dst = value;
  925. }
  926. sprintf(pg_result, "OK: udp_dst_max=%u", pkt_dev->udp_dst_max);
  927. return count;
  928. }
  929. if (!strcmp(name, "clone_skb")) {
  930. len = num_arg(&user_buffer[i], 10, &value);
  931. if (len < 0) {
  932. return len;
  933. }
  934. i += len;
  935. pkt_dev->clone_skb = value;
  936. sprintf(pg_result, "OK: clone_skb=%d", pkt_dev->clone_skb);
  937. return count;
  938. }
  939. if (!strcmp(name, "count")) {
  940. len = num_arg(&user_buffer[i], 10, &value);
  941. if (len < 0) {
  942. return len;
  943. }
  944. i += len;
  945. pkt_dev->count = value;
  946. sprintf(pg_result, "OK: count=%llu",
  947. (unsigned long long)pkt_dev->count);
  948. return count;
  949. }
  950. if (!strcmp(name, "src_mac_count")) {
  951. len = num_arg(&user_buffer[i], 10, &value);
  952. if (len < 0) {
  953. return len;
  954. }
  955. i += len;
  956. if (pkt_dev->src_mac_count != value) {
  957. pkt_dev->src_mac_count = value;
  958. pkt_dev->cur_src_mac_offset = 0;
  959. }
  960. sprintf(pg_result, "OK: src_mac_count=%d",
  961. pkt_dev->src_mac_count);
  962. return count;
  963. }
  964. if (!strcmp(name, "dst_mac_count")) {
  965. len = num_arg(&user_buffer[i], 10, &value);
  966. if (len < 0) {
  967. return len;
  968. }
  969. i += len;
  970. if (pkt_dev->dst_mac_count != value) {
  971. pkt_dev->dst_mac_count = value;
  972. pkt_dev->cur_dst_mac_offset = 0;
  973. }
  974. sprintf(pg_result, "OK: dst_mac_count=%d",
  975. pkt_dev->dst_mac_count);
  976. return count;
  977. }
  978. if (!strcmp(name, "flag")) {
  979. char f[32];
  980. memset(f, 0, 32);
  981. len = strn_len(&user_buffer[i], sizeof(f) - 1);
  982. if (len < 0) {
  983. return len;
  984. }
  985. if (copy_from_user(f, &user_buffer[i], len))
  986. return -EFAULT;
  987. i += len;
  988. if (strcmp(f, "IPSRC_RND") == 0)
  989. pkt_dev->flags |= F_IPSRC_RND;
  990. else if (strcmp(f, "!IPSRC_RND") == 0)
  991. pkt_dev->flags &= ~F_IPSRC_RND;
  992. else if (strcmp(f, "TXSIZE_RND") == 0)
  993. pkt_dev->flags |= F_TXSIZE_RND;
  994. else if (strcmp(f, "!TXSIZE_RND") == 0)
  995. pkt_dev->flags &= ~F_TXSIZE_RND;
  996. else if (strcmp(f, "IPDST_RND") == 0)
  997. pkt_dev->flags |= F_IPDST_RND;
  998. else if (strcmp(f, "!IPDST_RND") == 0)
  999. pkt_dev->flags &= ~F_IPDST_RND;
  1000. else if (strcmp(f, "UDPSRC_RND") == 0)
  1001. pkt_dev->flags |= F_UDPSRC_RND;
  1002. else if (strcmp(f, "!UDPSRC_RND") == 0)
  1003. pkt_dev->flags &= ~F_UDPSRC_RND;
  1004. else if (strcmp(f, "UDPDST_RND") == 0)
  1005. pkt_dev->flags |= F_UDPDST_RND;
  1006. else if (strcmp(f, "!UDPDST_RND") == 0)
  1007. pkt_dev->flags &= ~F_UDPDST_RND;
  1008. else if (strcmp(f, "MACSRC_RND") == 0)
  1009. pkt_dev->flags |= F_MACSRC_RND;
  1010. else if (strcmp(f, "!MACSRC_RND") == 0)
  1011. pkt_dev->flags &= ~F_MACSRC_RND;
  1012. else if (strcmp(f, "MACDST_RND") == 0)
  1013. pkt_dev->flags |= F_MACDST_RND;
  1014. else if (strcmp(f, "!MACDST_RND") == 0)
  1015. pkt_dev->flags &= ~F_MACDST_RND;
  1016. else if (strcmp(f, "MPLS_RND") == 0)
  1017. pkt_dev->flags |= F_MPLS_RND;
  1018. else if (strcmp(f, "!MPLS_RND") == 0)
  1019. pkt_dev->flags &= ~F_MPLS_RND;
  1020. else if (strcmp(f, "VID_RND") == 0)
  1021. pkt_dev->flags |= F_VID_RND;
  1022. else if (strcmp(f, "!VID_RND") == 0)
  1023. pkt_dev->flags &= ~F_VID_RND;
  1024. else if (strcmp(f, "SVID_RND") == 0)
  1025. pkt_dev->flags |= F_SVID_RND;
  1026. else if (strcmp(f, "!SVID_RND") == 0)
  1027. pkt_dev->flags &= ~F_SVID_RND;
  1028. else if (strcmp(f, "!IPV6") == 0)
  1029. pkt_dev->flags &= ~F_IPV6;
  1030. else {
  1031. sprintf(pg_result,
  1032. "Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
  1033. f,
  1034. "IPSRC_RND, IPDST_RND, UDPSRC_RND, UDPDST_RND, "
  1035. "MACSRC_RND, MACDST_RND, TXSIZE_RND, IPV6, MPLS_RND, VID_RND, SVID_RND\n");
  1036. return count;
  1037. }
  1038. sprintf(pg_result, "OK: flags=0x%x", pkt_dev->flags);
  1039. return count;
  1040. }
  1041. if (!strcmp(name, "dst_min") || !strcmp(name, "dst")) {
  1042. len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_min) - 1);
  1043. if (len < 0) {
  1044. return len;
  1045. }
  1046. if (copy_from_user(buf, &user_buffer[i], len))
  1047. return -EFAULT;
  1048. buf[len] = 0;
  1049. if (strcmp(buf, pkt_dev->dst_min) != 0) {
  1050. memset(pkt_dev->dst_min, 0, sizeof(pkt_dev->dst_min));
  1051. strncpy(pkt_dev->dst_min, buf, len);
  1052. pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
  1053. pkt_dev->cur_daddr = pkt_dev->daddr_min;
  1054. }
  1055. if (debug)
  1056. printk("pktgen: dst_min set to: %s\n",
  1057. pkt_dev->dst_min);
  1058. i += len;
  1059. sprintf(pg_result, "OK: dst_min=%s", pkt_dev->dst_min);
  1060. return count;
  1061. }
  1062. if (!strcmp(name, "dst_max")) {
  1063. len = strn_len(&user_buffer[i], sizeof(pkt_dev->dst_max) - 1);
  1064. if (len < 0) {
  1065. return len;
  1066. }
  1067. if (copy_from_user(buf, &user_buffer[i], len))
  1068. return -EFAULT;
  1069. buf[len] = 0;
  1070. if (strcmp(buf, pkt_dev->dst_max) != 0) {
  1071. memset(pkt_dev->dst_max, 0, sizeof(pkt_dev->dst_max));
  1072. strncpy(pkt_dev->dst_max, buf, len);
  1073. pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
  1074. pkt_dev->cur_daddr = pkt_dev->daddr_max;
  1075. }
  1076. if (debug)
  1077. printk("pktgen: dst_max set to: %s\n",
  1078. pkt_dev->dst_max);
  1079. i += len;
  1080. sprintf(pg_result, "OK: dst_max=%s", pkt_dev->dst_max);
  1081. return count;
  1082. }
  1083. if (!strcmp(name, "dst6")) {
  1084. len = strn_len(&user_buffer[i], sizeof(buf) - 1);
  1085. if (len < 0)
  1086. return len;
  1087. pkt_dev->flags |= F_IPV6;
  1088. if (copy_from_user(buf, &user_buffer[i], len))
  1089. return -EFAULT;
  1090. buf[len] = 0;
  1091. scan_ip6(buf, pkt_dev->in6_daddr.s6_addr);
  1092. fmt_ip6(buf, pkt_dev->in6_daddr.s6_addr);
  1093. ipv6_addr_copy(&pkt_dev->cur_in6_daddr, &pkt_dev->in6_daddr);
  1094. if (debug)
  1095. printk("pktgen: dst6 set to: %s\n", buf);
  1096. i += len;
  1097. sprintf(pg_result, "OK: dst6=%s", buf);
  1098. return count;
  1099. }
  1100. if (!strcmp(name, "dst6_min")) {
  1101. len = strn_len(&user_buffer[i], sizeof(buf) - 1);
  1102. if (len < 0)
  1103. return len;
  1104. pkt_dev->flags |= F_IPV6;
  1105. if (copy_from_user(buf, &user_buffer[i], len))
  1106. return -EFAULT;
  1107. buf[len] = 0;
  1108. scan_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
  1109. fmt_ip6(buf, pkt_dev->min_in6_daddr.s6_addr);
  1110. ipv6_addr_copy(&pkt_dev->cur_in6_daddr,
  1111. &pkt_dev->min_in6_daddr);
  1112. if (debug)
  1113. printk("pktgen: dst6_min set to: %s\n", buf);
  1114. i += len;
  1115. sprintf(pg_result, "OK: dst6_min=%s", buf);
  1116. return count;
  1117. }
  1118. if (!strcmp(name, "dst6_max")) {
  1119. len = strn_len(&user_buffer[i], sizeof(buf) - 1);
  1120. if (len < 0)
  1121. return len;
  1122. pkt_dev->flags |= F_IPV6;
  1123. if (copy_from_user(buf, &user_buffer[i], len))
  1124. return -EFAULT;
  1125. buf[len] = 0;
  1126. scan_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
  1127. fmt_ip6(buf, pkt_dev->max_in6_daddr.s6_addr);
  1128. if (debug)
  1129. printk("pktgen: dst6_max set to: %s\n", buf);
  1130. i += len;
  1131. sprintf(pg_result, "OK: dst6_max=%s", buf);
  1132. return count;
  1133. }
  1134. if (!strcmp(name, "src6")) {
  1135. len = strn_len(&user_buffer[i], sizeof(buf) - 1);
  1136. if (len < 0)
  1137. return len;
  1138. pkt_dev->flags |= F_IPV6;
  1139. if (copy_from_user(buf, &user_buffer[i], len))
  1140. return -EFAULT;
  1141. buf[len] = 0;
  1142. scan_ip6(buf, pkt_dev->in6_saddr.s6_addr);
  1143. fmt_ip6(buf, pkt_dev->in6_saddr.s6_addr);
  1144. ipv6_addr_copy(&pkt_dev->cur_in6_saddr, &pkt_dev->in6_saddr);
  1145. if (debug)
  1146. printk("pktgen: src6 set to: %s\n", buf);
  1147. i += len;
  1148. sprintf(pg_result, "OK: src6=%s", buf);
  1149. return count;
  1150. }
  1151. if (!strcmp(name, "src_min")) {
  1152. len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_min) - 1);
  1153. if (len < 0) {
  1154. return len;
  1155. }
  1156. if (copy_from_user(buf, &user_buffer[i], len))
  1157. return -EFAULT;
  1158. buf[len] = 0;
  1159. if (strcmp(buf, pkt_dev->src_min) != 0) {
  1160. memset(pkt_dev->src_min, 0, sizeof(pkt_dev->src_min));
  1161. strncpy(pkt_dev->src_min, buf, len);
  1162. pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
  1163. pkt_dev->cur_saddr = pkt_dev->saddr_min;
  1164. }
  1165. if (debug)
  1166. printk("pktgen: src_min set to: %s\n",
  1167. pkt_dev->src_min);
  1168. i += len;
  1169. sprintf(pg_result, "OK: src_min=%s", pkt_dev->src_min);
  1170. return count;
  1171. }
  1172. if (!strcmp(name, "src_max")) {
  1173. len = strn_len(&user_buffer[i], sizeof(pkt_dev->src_max) - 1);
  1174. if (len < 0) {
  1175. return len;
  1176. }
  1177. if (copy_from_user(buf, &user_buffer[i], len))
  1178. return -EFAULT;
  1179. buf[len] = 0;
  1180. if (strcmp(buf, pkt_dev->src_max) != 0) {
  1181. memset(pkt_dev->src_max, 0, sizeof(pkt_dev->src_max));
  1182. strncpy(pkt_dev->src_max, buf, len);
  1183. pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
  1184. pkt_dev->cur_saddr = pkt_dev->saddr_max;
  1185. }
  1186. if (debug)
  1187. printk("pktgen: src_max set to: %s\n",
  1188. pkt_dev->src_max);
  1189. i += len;
  1190. sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max);
  1191. return count;
  1192. }
  1193. if (!strcmp(name, "dst_mac")) {
  1194. char *v = valstr;
  1195. unsigned char old_dmac[ETH_ALEN];
  1196. unsigned char *m = pkt_dev->dst_mac;
  1197. memcpy(old_dmac, pkt_dev->dst_mac, ETH_ALEN);
  1198. len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
  1199. if (len < 0) {
  1200. return len;
  1201. }
  1202. memset(valstr, 0, sizeof(valstr));
  1203. if (copy_from_user(valstr, &user_buffer[i], len))
  1204. return -EFAULT;
  1205. i += len;
  1206. for (*m = 0; *v && m < pkt_dev->dst_mac + 6; v++) {
  1207. if (*v >= '0' && *v <= '9') {
  1208. *m *= 16;
  1209. *m += *v - '0';
  1210. }
  1211. if (*v >= 'A' && *v <= 'F') {
  1212. *m *= 16;
  1213. *m += *v - 'A' + 10;
  1214. }
  1215. if (*v >= 'a' && *v <= 'f') {
  1216. *m *= 16;
  1217. *m += *v - 'a' + 10;
  1218. }
  1219. if (*v == ':') {
  1220. m++;
  1221. *m = 0;
  1222. }
  1223. }
  1224. /* Set up Dest MAC */
  1225. if (compare_ether_addr(old_dmac, pkt_dev->dst_mac))
  1226. memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
  1227. sprintf(pg_result, "OK: dstmac");
  1228. return count;
  1229. }
  1230. if (!strcmp(name, "src_mac")) {
  1231. char *v = valstr;
  1232. unsigned char *m = pkt_dev->src_mac;
  1233. len = strn_len(&user_buffer[i], sizeof(valstr) - 1);
  1234. if (len < 0) {
  1235. return len;
  1236. }
  1237. memset(valstr, 0, sizeof(valstr));
  1238. if (copy_from_user(valstr, &user_buffer[i], len))
  1239. return -EFAULT;
  1240. i += len;
  1241. for (*m = 0; *v && m < pkt_dev->src_mac + 6; v++) {
  1242. if (*v >= '0' && *v <= '9') {
  1243. *m *= 16;
  1244. *m += *v - '0';
  1245. }
  1246. if (*v >= 'A' && *v <= 'F') {
  1247. *m *= 16;
  1248. *m += *v - 'A' + 10;
  1249. }
  1250. if (*v >= 'a' && *v <= 'f') {
  1251. *m *= 16;
  1252. *m += *v - 'a' + 10;
  1253. }
  1254. if (*v == ':') {
  1255. m++;
  1256. *m = 0;
  1257. }
  1258. }
  1259. sprintf(pg_result, "OK: srcmac");
  1260. return count;
  1261. }
  1262. if (!strcmp(name, "clear_counters")) {
  1263. pktgen_clear_counters(pkt_dev);
  1264. sprintf(pg_result, "OK: Clearing counters.\n");
  1265. return count;
  1266. }
  1267. if (!strcmp(name, "flows")) {
  1268. len = num_arg(&user_buffer[i], 10, &value);
  1269. if (len < 0) {
  1270. return len;
  1271. }
  1272. i += len;
  1273. if (value > MAX_CFLOWS)
  1274. value = MAX_CFLOWS;
  1275. pkt_dev->cflows = value;
  1276. sprintf(pg_result, "OK: flows=%u", pkt_dev->cflows);
  1277. return count;
  1278. }
  1279. if (!strcmp(name, "flowlen")) {
  1280. len = num_arg(&user_buffer[i], 10, &value);
  1281. if (len < 0) {
  1282. return len;
  1283. }
  1284. i += len;
  1285. pkt_dev->lflow = value;
  1286. sprintf(pg_result, "OK: flowlen=%u", pkt_dev->lflow);
  1287. return count;
  1288. }
  1289. if (!strcmp(name, "mpls")) {
  1290. unsigned n, offset;
  1291. len = get_labels(&user_buffer[i], pkt_dev);
  1292. if (len < 0) { return len; }
  1293. i += len;
  1294. offset = sprintf(pg_result, "OK: mpls=");
  1295. for(n = 0; n < pkt_dev->nr_labels; n++)
  1296. offset += sprintf(pg_result + offset,
  1297. "%08x%s", ntohl(pkt_dev->labels[n]),
  1298. n == pkt_dev->nr_labels-1 ? "" : ",");
  1299. if (pkt_dev->nr_labels && pkt_dev->vlan_id != 0xffff) {
  1300. pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
  1301. pkt_dev->svlan_id = 0xffff;
  1302. if (debug)
  1303. printk("pktgen: VLAN/SVLAN auto turned off\n");
  1304. }
  1305. return count;
  1306. }
  1307. if (!strcmp(name, "vlan_id")) {
  1308. len = num_arg(&user_buffer[i], 4, &value);
  1309. if (len < 0) {
  1310. return len;
  1311. }
  1312. i += len;
  1313. if (value <= 4095) {
  1314. pkt_dev->vlan_id = value; /* turn on VLAN */
  1315. if (debug)
  1316. printk("pktgen: VLAN turned on\n");
  1317. if (debug && pkt_dev->nr_labels)
  1318. printk("pktgen: MPLS auto turned off\n");
  1319. pkt_dev->nr_labels = 0; /* turn off MPLS */
  1320. sprintf(pg_result, "OK: vlan_id=%u", pkt_dev->vlan_id);
  1321. } else {
  1322. pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
  1323. pkt_dev->svlan_id = 0xffff;
  1324. if (debug)
  1325. printk("pktgen: VLAN/SVLAN turned off\n");
  1326. }
  1327. return count;
  1328. }
  1329. if (!strcmp(name, "vlan_p")) {
  1330. len = num_arg(&user_buffer[i], 1, &value);
  1331. if (len < 0) {
  1332. return len;
  1333. }
  1334. i += len;
  1335. if ((value <= 7) && (pkt_dev->vlan_id != 0xffff)) {
  1336. pkt_dev->vlan_p = value;
  1337. sprintf(pg_result, "OK: vlan_p=%u", pkt_dev->vlan_p);
  1338. } else {
  1339. sprintf(pg_result, "ERROR: vlan_p must be 0-7");
  1340. }
  1341. return count;
  1342. }
  1343. if (!strcmp(name, "vlan_cfi")) {
  1344. len = num_arg(&user_buffer[i], 1, &value);
  1345. if (len < 0) {
  1346. return len;
  1347. }
  1348. i += len;
  1349. if ((value <= 1) && (pkt_dev->vlan_id != 0xffff)) {
  1350. pkt_dev->vlan_cfi = value;
  1351. sprintf(pg_result, "OK: vlan_cfi=%u", pkt_dev->vlan_cfi);
  1352. } else {
  1353. sprintf(pg_result, "ERROR: vlan_cfi must be 0-1");
  1354. }
  1355. return count;
  1356. }
  1357. if (!strcmp(name, "svlan_id")) {
  1358. len = num_arg(&user_buffer[i], 4, &value);
  1359. if (len < 0) {
  1360. return len;
  1361. }
  1362. i += len;
  1363. if ((value <= 4095) && ((pkt_dev->vlan_id != 0xffff))) {
  1364. pkt_dev->svlan_id = value; /* turn on SVLAN */
  1365. if (debug)
  1366. printk("pktgen: SVLAN turned on\n");
  1367. if (debug && pkt_dev->nr_labels)
  1368. printk("pktgen: MPLS auto turned off\n");
  1369. pkt_dev->nr_labels = 0; /* turn off MPLS */
  1370. sprintf(pg_result, "OK: svlan_id=%u", pkt_dev->svlan_id);
  1371. } else {
  1372. pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
  1373. pkt_dev->svlan_id = 0xffff;
  1374. if (debug)
  1375. printk("pktgen: VLAN/SVLAN turned off\n");
  1376. }
  1377. return count;
  1378. }
  1379. if (!strcmp(name, "svlan_p")) {
  1380. len = num_arg(&user_buffer[i], 1, &value);
  1381. if (len < 0) {
  1382. return len;
  1383. }
  1384. i += len;
  1385. if ((value <= 7) && (pkt_dev->svlan_id != 0xffff)) {
  1386. pkt_dev->svlan_p = value;
  1387. sprintf(pg_result, "OK: svlan_p=%u", pkt_dev->svlan_p);
  1388. } else {
  1389. sprintf(pg_result, "ERROR: svlan_p must be 0-7");
  1390. }
  1391. return count;
  1392. }
  1393. if (!strcmp(name, "svlan_cfi")) {
  1394. len = num_arg(&user_buffer[i], 1, &value);
  1395. if (len < 0) {
  1396. return len;
  1397. }
  1398. i += len;
  1399. if ((value <= 1) && (pkt_dev->svlan_id != 0xffff)) {
  1400. pkt_dev->svlan_cfi = value;
  1401. sprintf(pg_result, "OK: svlan_cfi=%u", pkt_dev->svlan_cfi);
  1402. } else {
  1403. sprintf(pg_result, "ERROR: svlan_cfi must be 0-1");
  1404. }
  1405. return count;
  1406. }
  1407. if (!strcmp(name, "tos")) {
  1408. __u32 tmp_value = 0;
  1409. len = hex32_arg(&user_buffer[i], 2, &tmp_value);
  1410. if (len < 0) {
  1411. return len;
  1412. }
  1413. i += len;
  1414. if (len == 2) {
  1415. pkt_dev->tos = tmp_value;
  1416. sprintf(pg_result, "OK: tos=0x%02x", pkt_dev->tos);
  1417. } else {
  1418. sprintf(pg_result, "ERROR: tos must be 00-ff");
  1419. }
  1420. return count;
  1421. }
  1422. if (!strcmp(name, "traffic_class")) {
  1423. __u32 tmp_value = 0;
  1424. len = hex32_arg(&user_buffer[i], 2, &tmp_value);
  1425. if (len < 0) {
  1426. return len;
  1427. }
  1428. i += len;
  1429. if (len == 2) {
  1430. pkt_dev->traffic_class = tmp_value;
  1431. sprintf(pg_result, "OK: traffic_class=0x%02x", pkt_dev->traffic_class);
  1432. } else {
  1433. sprintf(pg_result, "ERROR: traffic_class must be 00-ff");
  1434. }
  1435. return count;
  1436. }
  1437. sprintf(pkt_dev->result, "No such parameter \"%s\"", name);
  1438. return -EINVAL;
  1439. }
  1440. static int pktgen_if_open(struct inode *inode, struct file *file)
  1441. {
  1442. return single_open(file, pktgen_if_show, PDE(inode)->data);
  1443. }
  1444. static const struct file_operations pktgen_if_fops = {
  1445. .owner = THIS_MODULE,
  1446. .open = pktgen_if_open,
  1447. .read = seq_read,
  1448. .llseek = seq_lseek,
  1449. .write = pktgen_if_write,
  1450. .release = single_release,
  1451. };
  1452. static int pktgen_thread_show(struct seq_file *seq, void *v)
  1453. {
  1454. struct pktgen_thread *t = seq->private;
  1455. struct pktgen_dev *pkt_dev;
  1456. BUG_ON(!t);
  1457. seq_printf(seq, "Name: %s max_before_softirq: %d\n",
  1458. t->tsk->comm, t->max_before_softirq);
  1459. seq_printf(seq, "Running: ");
  1460. if_lock(t);
  1461. list_for_each_entry(pkt_dev, &t->if_list, list)
  1462. if (pkt_dev->running)
  1463. seq_printf(seq, "%s ", pkt_dev->ifname);
  1464. seq_printf(seq, "\nStopped: ");
  1465. list_for_each_entry(pkt_dev, &t->if_list, list)
  1466. if (!pkt_dev->running)
  1467. seq_printf(seq, "%s ", pkt_dev->ifname);
  1468. if (t->result[0])
  1469. seq_printf(seq, "\nResult: %s\n", t->result);
  1470. else
  1471. seq_printf(seq, "\nResult: NA\n");
  1472. if_unlock(t);
  1473. return 0;
  1474. }
  1475. static ssize_t pktgen_thread_write(struct file *file,
  1476. const char __user * user_buffer,
  1477. size_t count, loff_t * offset)
  1478. {
  1479. struct seq_file *seq = (struct seq_file *)file->private_data;
  1480. struct pktgen_thread *t = seq->private;
  1481. int i = 0, max, len, ret;
  1482. char name[40];
  1483. char *pg_result;
  1484. unsigned long value = 0;
  1485. if (count < 1) {
  1486. // sprintf(pg_result, "Wrong command format");
  1487. return -EINVAL;
  1488. }
  1489. max = count - i;
  1490. len = count_trail_chars(&user_buffer[i], max);
  1491. if (len < 0)
  1492. return len;
  1493. i += len;
  1494. /* Read variable name */
  1495. len = strn_len(&user_buffer[i], sizeof(name) - 1);
  1496. if (len < 0)
  1497. return len;
  1498. memset(name, 0, sizeof(name));
  1499. if (copy_from_user(name, &user_buffer[i], len))
  1500. return -EFAULT;
  1501. i += len;
  1502. max = count - i;
  1503. len = count_trail_chars(&user_buffer[i], max);
  1504. if (len < 0)
  1505. return len;
  1506. i += len;
  1507. if (debug)
  1508. printk("pktgen: t=%s, count=%lu\n", name, (unsigned long)count);
  1509. if (!t) {
  1510. printk("pktgen: ERROR: No thread\n");
  1511. ret = -EINVAL;
  1512. goto out;
  1513. }
  1514. pg_result = &(t->result[0]);
  1515. if (!strcmp(name, "add_device")) {
  1516. char f[32];
  1517. memset(f, 0, 32);
  1518. len = strn_len(&user_buffer[i], sizeof(f) - 1);
  1519. if (len < 0) {
  1520. ret = len;
  1521. goto out;
  1522. }
  1523. if (copy_from_user(f, &user_buffer[i], len))
  1524. return -EFAULT;
  1525. i += len;
  1526. mutex_lock(&pktgen_thread_lock);
  1527. pktgen_add_device(t, f);
  1528. mutex_unlock(&pktgen_thread_lock);
  1529. ret = count;
  1530. sprintf(pg_result, "OK: add_device=%s", f);
  1531. goto out;
  1532. }
  1533. if (!strcmp(name, "rem_device_all")) {
  1534. mutex_lock(&pktgen_thread_lock);
  1535. t->control |= T_REMDEVALL;
  1536. mutex_unlock(&pktgen_thread_lock);
  1537. schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
  1538. ret = count;
  1539. sprintf(pg_result, "OK: rem_device_all");
  1540. goto out;
  1541. }
  1542. if (!strcmp(name, "max_before_softirq")) {
  1543. len = num_arg(&user_buffer[i], 10, &value);
  1544. mutex_lock(&pktgen_thread_lock);
  1545. t->max_before_softirq = value;
  1546. mutex_unlock(&pktgen_thread_lock);
  1547. ret = count;
  1548. sprintf(pg_result, "OK: max_before_softirq=%lu", value);
  1549. goto out;
  1550. }
  1551. ret = -EINVAL;
  1552. out:
  1553. return ret;
  1554. }
  1555. static int pktgen_thread_open(struct inode *inode, struct file *file)
  1556. {
  1557. return single_open(file, pktgen_thread_show, PDE(inode)->data);
  1558. }
  1559. static const struct file_operations pktgen_thread_fops = {
  1560. .owner = THIS_MODULE,
  1561. .open = pktgen_thread_open,
  1562. .read = seq_read,
  1563. .llseek = seq_lseek,
  1564. .write = pktgen_thread_write,
  1565. .release = single_release,
  1566. };
  1567. /* Think find or remove for NN */
  1568. static struct pktgen_dev *__pktgen_NN_threads(const char *ifname, int remove)
  1569. {
  1570. struct pktgen_thread *t;
  1571. struct pktgen_dev *pkt_dev = NULL;
  1572. list_for_each_entry(t, &pktgen_threads, th_list) {
  1573. pkt_dev = pktgen_find_dev(t, ifname);
  1574. if (pkt_dev) {
  1575. if (remove) {
  1576. if_lock(t);
  1577. pkt_dev->removal_mark = 1;
  1578. t->control |= T_REMDEV;
  1579. if_unlock(t);
  1580. }
  1581. break;
  1582. }
  1583. }
  1584. return pkt_dev;
  1585. }
  1586. /*
  1587. * mark a device for removal
  1588. */
  1589. static int pktgen_mark_device(const char *ifname)
  1590. {
  1591. struct pktgen_dev *pkt_dev = NULL;
  1592. const int max_tries = 10, msec_per_try = 125;
  1593. int i = 0;
  1594. int ret = 0;
  1595. mutex_lock(&pktgen_thread_lock);
  1596. pr_debug("pktgen: pktgen_mark_device marking %s for removal\n", ifname);
  1597. while (1) {
  1598. pkt_dev = __pktgen_NN_threads(ifname, REMOVE);
  1599. if (pkt_dev == NULL)
  1600. break; /* success */
  1601. mutex_unlock(&pktgen_thread_lock);
  1602. pr_debug("pktgen: pktgen_mark_device waiting for %s "
  1603. "to disappear....\n", ifname);
  1604. schedule_timeout_interruptible(msecs_to_jiffies(msec_per_try));
  1605. mutex_lock(&pktgen_thread_lock);
  1606. if (++i >= max_tries) {
  1607. printk("pktgen_mark_device: timed out after waiting "
  1608. "%d msec for device %s to be removed\n",
  1609. msec_per_try * i, ifname);
  1610. ret = 1;
  1611. break;
  1612. }
  1613. }
  1614. mutex_unlock(&pktgen_thread_lock);
  1615. return ret;
  1616. }
  1617. static int pktgen_device_event(struct notifier_block *unused,
  1618. unsigned long event, void *ptr)
  1619. {
  1620. struct net_device *dev = (struct net_device *)(ptr);
  1621. /* It is OK that we do not hold the group lock right now,
  1622. * as we run under the RTNL lock.
  1623. */
  1624. switch (event) {
  1625. case NETDEV_CHANGEADDR:
  1626. case NETDEV_GOING_DOWN:
  1627. case NETDEV_DOWN:
  1628. case NETDEV_UP:
  1629. /* Ignore for now */
  1630. break;
  1631. case NETDEV_UNREGISTER:
  1632. pktgen_mark_device(dev->name);
  1633. break;
  1634. };
  1635. return NOTIFY_DONE;
  1636. }
  1637. /* Associate pktgen_dev with a device. */
  1638. static struct net_device *pktgen_setup_dev(struct pktgen_dev *pkt_dev)
  1639. {
  1640. struct net_device *odev;
  1641. /* Clean old setups */
  1642. if (pkt_dev->odev) {
  1643. dev_put(pkt_dev->odev);
  1644. pkt_dev->odev = NULL;
  1645. }
  1646. odev = dev_get_by_name(pkt_dev->ifname);
  1647. if (!odev) {
  1648. printk("pktgen: no such netdevice: \"%s\"\n", pkt_dev->ifname);
  1649. goto out;
  1650. }
  1651. if (odev->type != ARPHRD_ETHER) {
  1652. printk("pktgen: not an ethernet device: \"%s\"\n",
  1653. pkt_dev->ifname);
  1654. goto out_put;
  1655. }
  1656. if (!netif_running(odev)) {
  1657. printk("pktgen: device is down: \"%s\"\n", pkt_dev->ifname);
  1658. goto out_put;
  1659. }
  1660. pkt_dev->odev = odev;
  1661. return pkt_dev->odev;
  1662. out_put:
  1663. dev_put(odev);
  1664. out:
  1665. return NULL;
  1666. }
  1667. /* Read pkt_dev from the interface and set up internal pktgen_dev
  1668. * structure to have the right information to create/send packets
  1669. */
  1670. static void pktgen_setup_inject(struct pktgen_dev *pkt_dev)
  1671. {
  1672. /* Try once more, just in case it works now. */
  1673. if (!pkt_dev->odev)
  1674. pktgen_setup_dev(pkt_dev);
  1675. if (!pkt_dev->odev) {
  1676. printk("pktgen: ERROR: pkt_dev->odev == NULL in setup_inject.\n");
  1677. sprintf(pkt_dev->result,
  1678. "ERROR: pkt_dev->odev == NULL in setup_inject.\n");
  1679. return;
  1680. }
  1681. /* Default to the interface's mac if not explicitly set. */
  1682. if (is_zero_ether_addr(pkt_dev->src_mac))
  1683. memcpy(&(pkt_dev->hh[6]), pkt_dev->odev->dev_addr, ETH_ALEN);
  1684. /* Set up Dest MAC */
  1685. memcpy(&(pkt_dev->hh[0]), pkt_dev->dst_mac, ETH_ALEN);
  1686. /* Set up pkt size */
  1687. pkt_dev->cur_pkt_size = pkt_dev->min_pkt_size;
  1688. if (pkt_dev->flags & F_IPV6) {
  1689. /*
  1690. * Skip this automatic address setting until locks or functions
  1691. * gets exported
  1692. */
  1693. #ifdef NOTNOW
  1694. int i, set = 0, err = 1;
  1695. struct inet6_dev *idev;
  1696. for (i = 0; i < IN6_ADDR_HSIZE; i++)
  1697. if (pkt_dev->cur_in6_saddr.s6_addr[i]) {
  1698. set = 1;
  1699. break;
  1700. }
  1701. if (!set) {
  1702. /*
  1703. * Use linklevel address if unconfigured.
  1704. *
  1705. * use ipv6_get_lladdr if/when it's get exported
  1706. */
  1707. rcu_read_lock();
  1708. if ((idev = __in6_dev_get(pkt_dev->odev)) != NULL) {
  1709. struct inet6_ifaddr *ifp;
  1710. read_lock_bh(&idev->lock);
  1711. for (ifp = idev->addr_list; ifp;
  1712. ifp = ifp->if_next) {
  1713. if (ifp->scope == IFA_LINK
  1714. && !(ifp->
  1715. flags & IFA_F_TENTATIVE)) {
  1716. ipv6_addr_copy(&pkt_dev->
  1717. cur_in6_saddr,
  1718. &ifp->addr);
  1719. err = 0;
  1720. break;
  1721. }
  1722. }
  1723. read_unlock_bh(&idev->lock);
  1724. }
  1725. rcu_read_unlock();
  1726. if (err)
  1727. printk("pktgen: ERROR: IPv6 link address not availble.\n");
  1728. }
  1729. #endif
  1730. } else {
  1731. pkt_dev->saddr_min = 0;
  1732. pkt_dev->saddr_max = 0;
  1733. if (strlen(pkt_dev->src_min) == 0) {
  1734. struct in_device *in_dev;
  1735. rcu_read_lock();
  1736. in_dev = __in_dev_get_rcu(pkt_dev->odev);
  1737. if (in_dev) {
  1738. if (in_dev->ifa_list) {
  1739. pkt_dev->saddr_min =
  1740. in_dev->ifa_list->ifa_address;
  1741. pkt_dev->saddr_max = pkt_dev->saddr_min;
  1742. }
  1743. }
  1744. rcu_read_unlock();
  1745. } else {
  1746. pkt_dev->saddr_min = in_aton(pkt_dev->src_min);
  1747. pkt_dev->saddr_max = in_aton(pkt_dev->src_max);
  1748. }
  1749. pkt_dev->daddr_min = in_aton(pkt_dev->dst_min);
  1750. pkt_dev->daddr_max = in_aton(pkt_dev->dst_max);
  1751. }
  1752. /* Initialize current values. */
  1753. pkt_dev->cur_dst_mac_offset = 0;
  1754. pkt_dev->cur_src_mac_offset = 0;
  1755. pkt_dev->cur_saddr = pkt_dev->saddr_min;
  1756. pkt_dev->cur_daddr = pkt_dev->daddr_min;
  1757. pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
  1758. pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
  1759. pkt_dev->nflows = 0;
  1760. }
  1761. static void spin(struct pktgen_dev *pkt_dev, __u64 spin_until_us)
  1762. {
  1763. __u64 start;
  1764. __u64 now;
  1765. start = now = getCurUs();
  1766. printk(KERN_INFO "sleeping for %d\n", (int)(spin_until_us - now));
  1767. while (now < spin_until_us) {
  1768. /* TODO: optimize sleeping behavior */
  1769. if (spin_until_us - now > jiffies_to_usecs(1) + 1)
  1770. schedule_timeout_interruptible(1);
  1771. else if (spin_until_us - now > 100) {
  1772. do_softirq();
  1773. if (!pkt_dev->running)
  1774. return;
  1775. if (need_resched())
  1776. schedule();
  1777. }
  1778. now = getCurUs();
  1779. }
  1780. pkt_dev->idle_acc += now - start;
  1781. }
  1782. /* Increment/randomize headers according to flags and current values
  1783. * for IP src/dest, UDP src/dst port, MAC-Addr src/dst
  1784. */
  1785. static void mod_cur_headers(struct pktgen_dev *pkt_dev)
  1786. {
  1787. __u32 imn;
  1788. __u32 imx;
  1789. int flow = 0;
  1790. if (pkt_dev->cflows) {
  1791. flow = random32() % pkt_dev->cflows;
  1792. if (pkt_dev->flows[flow].count > pkt_dev->lflow)
  1793. pkt_dev->flows[flow].count = 0;
  1794. }
  1795. /* Deal with source MAC */
  1796. if (pkt_dev->src_mac_count > 1) {
  1797. __u32 mc;
  1798. __u32 tmp;
  1799. if (pkt_dev->flags & F_MACSRC_RND)
  1800. mc = random32() % pkt_dev->src_mac_count;
  1801. else {
  1802. mc = pkt_dev->cur_src_mac_offset++;
  1803. if (pkt_dev->cur_src_mac_offset >
  1804. pkt_dev->src_mac_count)
  1805. pkt_dev->cur_src_mac_offset = 0;
  1806. }
  1807. tmp = pkt_dev->src_mac[5] + (mc & 0xFF);
  1808. pkt_dev->hh[11] = tmp;
  1809. tmp = (pkt_dev->src_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
  1810. pkt_dev->hh[10] = tmp;
  1811. tmp = (pkt_dev->src_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
  1812. pkt_dev->hh[9] = tmp;
  1813. tmp = (pkt_dev->src_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
  1814. pkt_dev->hh[8] = tmp;
  1815. tmp = (pkt_dev->src_mac[1] + (tmp >> 8));
  1816. pkt_dev->hh[7] = tmp;
  1817. }
  1818. /* Deal with Destination MAC */
  1819. if (pkt_dev->dst_mac_count > 1) {
  1820. __u32 mc;
  1821. __u32 tmp;
  1822. if (pkt_dev->flags & F_MACDST_RND)
  1823. mc = random32() % pkt_dev->dst_mac_count;
  1824. else {
  1825. mc = pkt_dev->cur_dst_mac_offset++;
  1826. if (pkt_dev->cur_dst_mac_offset >
  1827. pkt_dev->dst_mac_count) {
  1828. pkt_dev->cur_dst_mac_offset = 0;
  1829. }
  1830. }
  1831. tmp = pkt_dev->dst_mac[5] + (mc & 0xFF);
  1832. pkt_dev->hh[5] = tmp;
  1833. tmp = (pkt_dev->dst_mac[4] + ((mc >> 8) & 0xFF) + (tmp >> 8));
  1834. pkt_dev->hh[4] = tmp;
  1835. tmp = (pkt_dev->dst_mac[3] + ((mc >> 16) & 0xFF) + (tmp >> 8));
  1836. pkt_dev->hh[3] = tmp;
  1837. tmp = (pkt_dev->dst_mac[2] + ((mc >> 24) & 0xFF) + (tmp >> 8));
  1838. pkt_dev->hh[2] = tmp;
  1839. tmp = (pkt_dev->dst_mac[1] + (tmp >> 8));
  1840. pkt_dev->hh[1] = tmp;
  1841. }
  1842. if (pkt_dev->flags & F_MPLS_RND) {
  1843. unsigned i;
  1844. for(i = 0; i < pkt_dev->nr_labels; i++)
  1845. if (pkt_dev->labels[i] & MPLS_STACK_BOTTOM)
  1846. pkt_dev->labels[i] = MPLS_STACK_BOTTOM |
  1847. ((__force __be32)random32() &
  1848. htonl(0x000fffff));
  1849. }
  1850. if ((pkt_dev->flags & F_VID_RND) && (pkt_dev->vlan_id != 0xffff)) {
  1851. pkt_dev->vlan_id = random32() & (4096-1);
  1852. }
  1853. if ((pkt_dev->flags & F_SVID_RND) && (pkt_dev->svlan_id != 0xffff)) {
  1854. pkt_dev->svlan_id = random32() & (4096 - 1);
  1855. }
  1856. if (pkt_dev->udp_src_min < pkt_dev->udp_src_max) {
  1857. if (pkt_dev->flags & F_UDPSRC_RND)
  1858. pkt_dev->cur_udp_src = random32() %
  1859. (pkt_dev->udp_src_max - pkt_dev->udp_src_min)
  1860. + pkt_dev->udp_src_min;
  1861. else {
  1862. pkt_dev->cur_udp_src++;
  1863. if (pkt_dev->cur_udp_src >= pkt_dev->udp_src_max)
  1864. pkt_dev->cur_udp_src = pkt_dev->udp_src_min;
  1865. }
  1866. }
  1867. if (pkt_dev->udp_dst_min < pkt_dev->udp_dst_max) {
  1868. if (pkt_dev->flags & F_UDPDST_RND) {
  1869. pkt_dev->cur_udp_dst = random32() %
  1870. (pkt_dev->udp_dst_max - pkt_dev->udp_dst_min)
  1871. + pkt_dev->udp_dst_min;
  1872. } else {
  1873. pkt_dev->cur_udp_dst++;
  1874. if (pkt_dev->cur_udp_dst >= pkt_dev->udp_dst_max)
  1875. pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min;
  1876. }
  1877. }
  1878. if (!(pkt_dev->flags & F_IPV6)) {
  1879. if ((imn = ntohl(pkt_dev->saddr_min)) < (imx =
  1880. ntohl(pkt_dev->
  1881. saddr_max))) {
  1882. __u32 t;
  1883. if (pkt_dev->flags & F_IPSRC_RND)
  1884. t = random32() % (imx - imn) + imn;
  1885. else {
  1886. t = ntohl(pkt_dev->cur_saddr);
  1887. t++;
  1888. if (t > imx) {
  1889. t = imn;
  1890. }
  1891. }
  1892. pkt_dev->cur_saddr = htonl(t);
  1893. }
  1894. if (pkt_dev->cflows && pkt_dev->flows[flow].count != 0) {
  1895. pkt_dev->cur_daddr = pkt_dev->flows[flow].cur_daddr;
  1896. } else {
  1897. imn = ntohl(pkt_dev->daddr_min);
  1898. imx = ntohl(pkt_dev->daddr_max);
  1899. if (imn < imx) {
  1900. __u32 t;
  1901. __be32 s;
  1902. if (pkt_dev->flags & F_IPDST_RND) {
  1903. t = random32() % (imx - imn) + imn;
  1904. s = htonl(t);
  1905. while (LOOPBACK(s) || MULTICAST(s)
  1906. || BADCLASS(s) || ZERONET(s)
  1907. || LOCAL_MCAST(s)) {
  1908. t = random32() % (imx - imn) + imn;
  1909. s = htonl(t);
  1910. }
  1911. pkt_dev->cur_daddr = s;
  1912. } else {
  1913. t = ntohl(pkt_dev->cur_daddr);
  1914. t++;
  1915. if (t > imx) {
  1916. t = imn;
  1917. }
  1918. pkt_dev->cur_daddr = htonl(t);
  1919. }
  1920. }
  1921. if (pkt_dev->cflows) {
  1922. pkt_dev->flows[flow].cur_daddr =
  1923. pkt_dev->cur_daddr;
  1924. pkt_dev->nflows++;
  1925. }
  1926. }
  1927. } else { /* IPV6 * */
  1928. if (pkt_dev->min_in6_daddr.s6_addr32[0] == 0 &&
  1929. pkt_dev->min_in6_daddr.s6_addr32[1] == 0 &&
  1930. pkt_dev->min_in6_daddr.s6_addr32[2] == 0 &&
  1931. pkt_dev->min_in6_daddr.s6_addr32[3] == 0) ;
  1932. else {
  1933. int i;
  1934. /* Only random destinations yet */
  1935. for (i = 0; i < 4; i++) {
  1936. pkt_dev->cur_in6_daddr.s6_addr32[i] =
  1937. (((__force __be32)random32() |
  1938. pkt_dev->min_in6_daddr.s6_addr32[i]) &
  1939. pkt_dev->max_in6_daddr.s6_addr32[i]);
  1940. }
  1941. }
  1942. }
  1943. if (pkt_dev->min_pkt_size < pkt_dev->max_pkt_size) {
  1944. __u32 t;
  1945. if (pkt_dev->flags & F_TXSIZE_RND) {
  1946. t = random32() %
  1947. (pkt_dev->max_pkt_size - pkt_dev->min_pkt_size)
  1948. + pkt_dev->min_pkt_size;
  1949. } else {
  1950. t = pkt_dev->cur_pkt_size + 1;
  1951. if (t > pkt_dev->max_pkt_size)
  1952. t = pkt_dev->min_pkt_size;
  1953. }
  1954. pkt_dev->cur_pkt_size = t;
  1955. }
  1956. pkt_dev->flows[flow].count++;
  1957. }
  1958. static void mpls_push(__be32 *mpls, struct pktgen_dev *pkt_dev)
  1959. {
  1960. unsigned i;
  1961. for(i = 0; i < pkt_dev->nr_labels; i++) {
  1962. *mpls++ = pkt_dev->labels[i] & ~MPLS_STACK_BOTTOM;
  1963. }
  1964. mpls--;
  1965. *mpls |= MPLS_STACK_BOTTOM;
  1966. }
  1967. static inline __be16 build_tci(unsigned int id, unsigned int cfi,
  1968. unsigned int prio)
  1969. {
  1970. return htons(id | (cfi << 12) | (prio << 13));
  1971. }
  1972. static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
  1973. struct pktgen_dev *pkt_dev)
  1974. {
  1975. struct sk_buff *skb = NULL;
  1976. __u8 *eth;
  1977. struct udphdr *udph;
  1978. int datalen, iplen;
  1979. struct iphdr *iph;
  1980. struct pktgen_hdr *pgh = NULL;
  1981. __be16 protocol = __constant_htons(ETH_P_IP);
  1982. __be32 *mpls;
  1983. __be16 *vlan_tci = NULL; /* Encapsulates priority and VLAN ID */
  1984. __be16 *vlan_encapsulated_proto = NULL; /* packet type ID field (or len) for VLAN tag */
  1985. __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */
  1986. __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
  1987. if (pkt_dev->nr_labels)
  1988. protocol = __constant_htons(ETH_P_MPLS_UC);
  1989. if (pkt_dev->vlan_id != 0xffff)
  1990. protocol = __constant_htons(ETH_P_8021Q);
  1991. /* Update any of the values, used when we're incrementing various
  1992. * fields.
  1993. */
  1994. mod_cur_headers(pkt_dev);
  1995. datalen = (odev->hard_header_len + 16) & ~0xf;
  1996. skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + datalen +
  1997. pkt_dev->nr_labels*sizeof(u32) +
  1998. VLAN_TAG_SIZE(pkt_dev) + SVLAN_TAG_SIZE(pkt_dev),
  1999. GFP_ATOMIC);
  2000. if (!skb) {
  2001. sprintf(pkt_dev->result, "No memory");
  2002. return NULL;
  2003. }
  2004. skb_reserve(skb, datalen);
  2005. /* Reserve for ethernet and IP header */
  2006. eth = (__u8 *) skb_push(skb, 14);
  2007. mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32));
  2008. if (pkt_dev->nr_labels)
  2009. mpls_push(mpls, pkt_dev);
  2010. if (pkt_dev->vlan_id != 0xffff) {
  2011. if(pkt_dev->svlan_id != 0xffff) {
  2012. svlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
  2013. *svlan_tci = build_tci(pkt_dev->svlan_id,
  2014. pkt_dev->svlan_cfi,
  2015. pkt_dev->svlan_p);
  2016. svlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
  2017. *svlan_encapsulated_proto = __constant_htons(ETH_P_8021Q);
  2018. }
  2019. vlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
  2020. *vlan_tci = build_tci(pkt_dev->vlan_id,
  2021. pkt_dev->vlan_cfi,
  2022. pkt_dev->vlan_p);
  2023. vlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
  2024. *vlan_encapsulated_proto = __constant_htons(ETH_P_IP);
  2025. }
  2026. iph = (struct iphdr *)skb_put(skb, sizeof(struct iphdr));
  2027. udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
  2028. memcpy(eth, pkt_dev->hh, 12);
  2029. *(__be16 *) & eth[12] = protocol;
  2030. /* Eth + IPh + UDPh + mpls */
  2031. datalen = pkt_dev->cur_pkt_size - 14 - 20 - 8 -
  2032. pkt_dev->nr_labels*sizeof(u32) - VLAN_TAG_SIZE(pkt_dev) - SVLAN_TAG_SIZE(pkt_dev);
  2033. if (datalen < sizeof(struct pktgen_hdr))
  2034. datalen = sizeof(struct pktgen_hdr);
  2035. udph->source = htons(pkt_dev->cur_udp_src);
  2036. udph->dest = htons(pkt_dev->cur_udp_dst);
  2037. udph->len = htons(datalen + 8); /* DATA + udphdr */
  2038. udph->check = 0; /* No checksum */
  2039. iph->ihl = 5;
  2040. iph->version = 4;
  2041. iph->ttl = 32;
  2042. iph->tos = pkt_dev->tos;
  2043. iph->protocol = IPPROTO_UDP; /* UDP */
  2044. iph->saddr = pkt_dev->cur_saddr;
  2045. iph->daddr = pkt_dev->cur_daddr;
  2046. iph->frag_off = 0;
  2047. iplen = 20 + 8 + datalen;
  2048. iph->tot_len = htons(iplen);
  2049. iph->check = 0;
  2050. iph->check = ip_fast_csum((void *)iph, iph->ihl);
  2051. skb->protocol = protocol;
  2052. skb->mac.raw = ((u8 *) iph) - 14 - pkt_dev->nr_labels*sizeof(u32) -
  2053. VLAN_TAG_SIZE(pkt_dev) - SVLAN_TAG_SIZE(pkt_dev);
  2054. skb->dev = odev;
  2055. skb->pkt_type = PACKET_HOST;
  2056. skb->nh.iph = iph;
  2057. skb->h.uh = udph;
  2058. if (pkt_dev->nfrags <= 0)
  2059. pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
  2060. else {
  2061. int frags = pkt_dev->nfrags;
  2062. int i;
  2063. pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
  2064. if (frags > MAX_SKB_FRAGS)
  2065. frags = MAX_SKB_FRAGS;
  2066. if (datalen > frags * PAGE_SIZE) {
  2067. skb_put(skb, datalen - frags * PAGE_SIZE);
  2068. datalen = frags * PAGE_SIZE;
  2069. }
  2070. i = 0;
  2071. while (datalen > 0) {
  2072. struct page *page = alloc_pages(GFP_KERNEL, 0);
  2073. skb_shinfo(skb)->frags[i].page = page;
  2074. skb_shinfo(skb)->frags[i].page_offset = 0;
  2075. skb_shinfo(skb)->frags[i].size =
  2076. (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
  2077. datalen -= skb_shinfo(skb)->frags[i].size;
  2078. skb->len += skb_shinfo(skb)->frags[i].size;
  2079. skb->data_len += skb_shinfo(skb)->frags[i].size;
  2080. i++;
  2081. skb_shinfo(skb)->nr_frags = i;
  2082. }
  2083. while (i < frags) {
  2084. int rem;
  2085. if (i == 0)
  2086. break;
  2087. rem = skb_shinfo(skb)->frags[i - 1].size / 2;
  2088. if (rem == 0)
  2089. break;
  2090. skb_shinfo(skb)->frags[i - 1].size -= rem;
  2091. skb_shinfo(skb)->frags[i] =
  2092. skb_shinfo(skb)->frags[i - 1];
  2093. get_page(skb_shinfo(skb)->frags[i].page);
  2094. skb_shinfo(skb)->frags[i].page =
  2095. skb_shinfo(skb)->frags[i - 1].page;
  2096. skb_shinfo(skb)->frags[i].page_offset +=
  2097. skb_shinfo(skb)->frags[i - 1].size;
  2098. skb_shinfo(skb)->frags[i].size = rem;
  2099. i++;
  2100. skb_shinfo(skb)->nr_frags = i;
  2101. }
  2102. }
  2103. /* Stamp the time, and sequence number, convert them to network byte order */
  2104. if (pgh) {
  2105. struct timeval timestamp;
  2106. pgh->pgh_magic = htonl(PKTGEN_MAGIC);
  2107. pgh->seq_num = htonl(pkt_dev->seq_num);
  2108. do_gettimeofday(&timestamp);
  2109. pgh->tv_sec = htonl(timestamp.tv_sec);
  2110. pgh->tv_usec = htonl(timestamp.tv_usec);
  2111. }
  2112. return skb;
  2113. }
  2114. /*
  2115. * scan_ip6, fmt_ip taken from dietlibc-0.21
  2116. * Author Felix von Leitner <felix-dietlibc@fefe.de>
  2117. *
  2118. * Slightly modified for kernel.
  2119. * Should be candidate for net/ipv4/utils.c
  2120. * --ro
  2121. */
  2122. static unsigned int scan_ip6(const char *s, char ip[16])
  2123. {
  2124. unsigned int i;
  2125. unsigned int len = 0;
  2126. unsigned long u;
  2127. char suffix[16];
  2128. unsigned int prefixlen = 0;
  2129. unsigned int suffixlen = 0;
  2130. __be32 tmp;
  2131. for (i = 0; i < 16; i++)
  2132. ip[i] = 0;
  2133. for (;;) {
  2134. if (*s == ':') {
  2135. len++;
  2136. if (s[1] == ':') { /* Found "::", skip to part 2 */
  2137. s += 2;
  2138. len++;
  2139. break;
  2140. }
  2141. s++;
  2142. }
  2143. {
  2144. char *tmp;
  2145. u = simple_strtoul(s, &tmp, 16);
  2146. i = tmp - s;
  2147. }
  2148. if (!i)
  2149. return 0;
  2150. if (prefixlen == 12 && s[i] == '.') {
  2151. /* the last 4 bytes may be written as IPv4 address */
  2152. tmp = in_aton(s);
  2153. memcpy((struct in_addr *)(ip + 12), &tmp, sizeof(tmp));
  2154. return i + len;
  2155. }
  2156. ip[prefixlen++] = (u >> 8);
  2157. ip[prefixlen++] = (u & 255);
  2158. s += i;
  2159. len += i;
  2160. if (prefixlen == 16)
  2161. return len;
  2162. }
  2163. /* part 2, after "::" */
  2164. for (;;) {
  2165. if (*s == ':') {
  2166. if (suffixlen == 0)
  2167. break;
  2168. s++;
  2169. len++;
  2170. } else if (suffixlen != 0)
  2171. break;
  2172. {
  2173. char *tmp;
  2174. u = simple_strtol(s, &tmp, 16);
  2175. i = tmp - s;
  2176. }
  2177. if (!i) {
  2178. if (*s)
  2179. len--;
  2180. break;
  2181. }
  2182. if (suffixlen + prefixlen <= 12 && s[i] == '.') {
  2183. tmp = in_aton(s);
  2184. memcpy((struct in_addr *)(suffix + suffixlen), &tmp,
  2185. sizeof(tmp));
  2186. suffixlen += 4;
  2187. len += strlen(s);
  2188. break;
  2189. }
  2190. suffix[suffixlen++] = (u >> 8);
  2191. suffix[suffixlen++] = (u & 255);
  2192. s += i;
  2193. len += i;
  2194. if (prefixlen + suffixlen == 16)
  2195. break;
  2196. }
  2197. for (i = 0; i < suffixlen; i++)
  2198. ip[16 - suffixlen + i] = suffix[i];
  2199. return len;
  2200. }
  2201. static char tohex(char hexdigit)
  2202. {
  2203. return hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
  2204. }
  2205. static int fmt_xlong(char *s, unsigned int i)
  2206. {
  2207. char *bak = s;
  2208. *s = tohex((i >> 12) & 0xf);
  2209. if (s != bak || *s != '0')
  2210. ++s;
  2211. *s = tohex((i >> 8) & 0xf);
  2212. if (s != bak || *s != '0')
  2213. ++s;
  2214. *s = tohex((i >> 4) & 0xf);
  2215. if (s != bak || *s != '0')
  2216. ++s;
  2217. *s = tohex(i & 0xf);
  2218. return s - bak + 1;
  2219. }
  2220. static unsigned int fmt_ip6(char *s, const char ip[16])
  2221. {
  2222. unsigned int len;
  2223. unsigned int i;
  2224. unsigned int temp;
  2225. unsigned int compressing;
  2226. int j;
  2227. len = 0;
  2228. compressing = 0;
  2229. for (j = 0; j < 16; j += 2) {
  2230. #ifdef V4MAPPEDPREFIX
  2231. if (j == 12 && !memcmp(ip, V4mappedprefix, 12)) {
  2232. inet_ntoa_r(*(struct in_addr *)(ip + 12), s);
  2233. temp = strlen(s);
  2234. return len + temp;
  2235. }
  2236. #endif
  2237. temp = ((unsigned long)(unsigned char)ip[j] << 8) +
  2238. (unsigned long)(unsigned char)ip[j + 1];
  2239. if (temp == 0) {
  2240. if (!compressing) {
  2241. compressing = 1;
  2242. if (j == 0) {
  2243. *s++ = ':';
  2244. ++len;
  2245. }
  2246. }
  2247. } else {
  2248. if (compressing) {
  2249. compressing = 0;
  2250. *s++ = ':';
  2251. ++len;
  2252. }
  2253. i = fmt_xlong(s, temp);
  2254. len += i;
  2255. s += i;
  2256. if (j < 14) {
  2257. *s++ = ':';
  2258. ++len;
  2259. }
  2260. }
  2261. }
  2262. if (compressing) {
  2263. *s++ = ':';
  2264. ++len;
  2265. }
  2266. *s = 0;
  2267. return len;
  2268. }
  2269. static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
  2270. struct pktgen_dev *pkt_dev)
  2271. {
  2272. struct sk_buff *skb = NULL;
  2273. __u8 *eth;
  2274. struct udphdr *udph;
  2275. int datalen;
  2276. struct ipv6hdr *iph;
  2277. struct pktgen_hdr *pgh = NULL;
  2278. __be16 protocol = __constant_htons(ETH_P_IPV6);
  2279. __be32 *mpls;
  2280. __be16 *vlan_tci = NULL; /* Encapsulates priority and VLAN ID */
  2281. __be16 *vlan_encapsulated_proto = NULL; /* packet type ID field (or len) for VLAN tag */
  2282. __be16 *svlan_tci = NULL; /* Encapsulates priority and SVLAN ID */
  2283. __be16 *svlan_encapsulated_proto = NULL; /* packet type ID field (or len) for SVLAN tag */
  2284. if (pkt_dev->nr_labels)
  2285. protocol = __constant_htons(ETH_P_MPLS_UC);
  2286. if (pkt_dev->vlan_id != 0xffff)
  2287. protocol = __constant_htons(ETH_P_8021Q);
  2288. /* Update any of the values, used when we're incrementing various
  2289. * fields.
  2290. */
  2291. mod_cur_headers(pkt_dev);
  2292. skb = alloc_skb(pkt_dev->cur_pkt_size + 64 + 16 +
  2293. pkt_dev->nr_labels*sizeof(u32) +
  2294. VLAN_TAG_SIZE(pkt_dev) + SVLAN_TAG_SIZE(pkt_dev),
  2295. GFP_ATOMIC);
  2296. if (!skb) {
  2297. sprintf(pkt_dev->result, "No memory");
  2298. return NULL;
  2299. }
  2300. skb_reserve(skb, 16);
  2301. /* Reserve for ethernet and IP header */
  2302. eth = (__u8 *) skb_push(skb, 14);
  2303. mpls = (__be32 *)skb_put(skb, pkt_dev->nr_labels*sizeof(__u32));
  2304. if (pkt_dev->nr_labels)
  2305. mpls_push(mpls, pkt_dev);
  2306. if (pkt_dev->vlan_id != 0xffff) {
  2307. if(pkt_dev->svlan_id != 0xffff) {
  2308. svlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
  2309. *svlan_tci = build_tci(pkt_dev->svlan_id,
  2310. pkt_dev->svlan_cfi,
  2311. pkt_dev->svlan_p);
  2312. svlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
  2313. *svlan_encapsulated_proto = __constant_htons(ETH_P_8021Q);
  2314. }
  2315. vlan_tci = (__be16 *)skb_put(skb, sizeof(__be16));
  2316. *vlan_tci = build_tci(pkt_dev->vlan_id,
  2317. pkt_dev->vlan_cfi,
  2318. pkt_dev->vlan_p);
  2319. vlan_encapsulated_proto = (__be16 *)skb_put(skb, sizeof(__be16));
  2320. *vlan_encapsulated_proto = __constant_htons(ETH_P_IPV6);
  2321. }
  2322. iph = (struct ipv6hdr *)skb_put(skb, sizeof(struct ipv6hdr));
  2323. udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
  2324. memcpy(eth, pkt_dev->hh, 12);
  2325. *(__be16 *) & eth[12] = protocol;
  2326. /* Eth + IPh + UDPh + mpls */
  2327. datalen = pkt_dev->cur_pkt_size - 14 -
  2328. sizeof(struct ipv6hdr) - sizeof(struct udphdr) -
  2329. pkt_dev->nr_labels*sizeof(u32) - VLAN_TAG_SIZE(pkt_dev) - SVLAN_TAG_SIZE(pkt_dev);
  2330. if (datalen < sizeof(struct pktgen_hdr)) {
  2331. datalen = sizeof(struct pktgen_hdr);
  2332. if (net_ratelimit())
  2333. printk(KERN_INFO "pktgen: increased datalen to %d\n",
  2334. datalen);
  2335. }
  2336. udph->source = htons(pkt_dev->cur_udp_src);
  2337. udph->dest = htons(pkt_dev->cur_udp_dst);
  2338. udph->len = htons(datalen + sizeof(struct udphdr));
  2339. udph->check = 0; /* No checksum */
  2340. *(__be32 *) iph = __constant_htonl(0x60000000); /* Version + flow */
  2341. if (pkt_dev->traffic_class) {
  2342. /* Version + traffic class + flow (0) */
  2343. *(__be32 *)iph |= htonl(0x60000000 | (pkt_dev->traffic_class << 20));
  2344. }
  2345. iph->hop_limit = 32;
  2346. iph->payload_len = htons(sizeof(struct udphdr) + datalen);
  2347. iph->nexthdr = IPPROTO_UDP;
  2348. ipv6_addr_copy(&iph->daddr, &pkt_dev->cur_in6_daddr);
  2349. ipv6_addr_copy(&iph->saddr, &pkt_dev->cur_in6_saddr);
  2350. skb->mac.raw = ((u8 *) iph) - 14 - pkt_dev->nr_labels*sizeof(u32) -
  2351. VLAN_TAG_SIZE(pkt_dev) - SVLAN_TAG_SIZE(pkt_dev);
  2352. skb->protocol = protocol;
  2353. skb->dev = odev;
  2354. skb->pkt_type = PACKET_HOST;
  2355. skb->nh.ipv6h = iph;
  2356. skb->h.uh = udph;
  2357. if (pkt_dev->nfrags <= 0)
  2358. pgh = (struct pktgen_hdr *)skb_put(skb, datalen);
  2359. else {
  2360. int frags = pkt_dev->nfrags;
  2361. int i;
  2362. pgh = (struct pktgen_hdr *)(((char *)(udph)) + 8);
  2363. if (frags > MAX_SKB_FRAGS)
  2364. frags = MAX_SKB_FRAGS;
  2365. if (datalen > frags * PAGE_SIZE) {
  2366. skb_put(skb, datalen - frags * PAGE_SIZE);
  2367. datalen = frags * PAGE_SIZE;
  2368. }
  2369. i = 0;
  2370. while (datalen > 0) {
  2371. struct page *page = alloc_pages(GFP_KERNEL, 0);
  2372. skb_shinfo(skb)->frags[i].page = page;
  2373. skb_shinfo(skb)->frags[i].page_offset = 0;
  2374. skb_shinfo(skb)->frags[i].size =
  2375. (datalen < PAGE_SIZE ? datalen : PAGE_SIZE);
  2376. datalen -= skb_shinfo(skb)->frags[i].size;
  2377. skb->len += skb_shinfo(skb)->frags[i].size;
  2378. skb->data_len += skb_shinfo(skb)->frags[i].size;
  2379. i++;
  2380. skb_shinfo(skb)->nr_frags = i;
  2381. }
  2382. while (i < frags) {
  2383. int rem;
  2384. if (i == 0)
  2385. break;
  2386. rem = skb_shinfo(skb)->frags[i - 1].size / 2;
  2387. if (rem == 0)
  2388. break;
  2389. skb_shinfo(skb)->frags[i - 1].size -= rem;
  2390. skb_shinfo(skb)->frags[i] =
  2391. skb_shinfo(skb)->frags[i - 1];
  2392. get_page(skb_shinfo(skb)->frags[i].page);
  2393. skb_shinfo(skb)->frags[i].page =
  2394. skb_shinfo(skb)->frags[i - 1].page;
  2395. skb_shinfo(skb)->frags[i].page_offset +=
  2396. skb_shinfo(skb)->frags[i - 1].size;
  2397. skb_shinfo(skb)->frags[i].size = rem;
  2398. i++;
  2399. skb_shinfo(skb)->nr_frags = i;
  2400. }
  2401. }
  2402. /* Stamp the time, and sequence number, convert them to network byte order */
  2403. /* should we update cloned packets too ? */
  2404. if (pgh) {
  2405. struct timeval timestamp;
  2406. pgh->pgh_magic = htonl(PKTGEN_MAGIC);
  2407. pgh->seq_num = htonl(pkt_dev->seq_num);
  2408. do_gettimeofday(&timestamp);
  2409. pgh->tv_sec = htonl(timestamp.tv_sec);
  2410. pgh->tv_usec = htonl(timestamp.tv_usec);
  2411. }
  2412. /* pkt_dev->seq_num++; FF: you really mean this? */
  2413. return skb;
  2414. }
  2415. static inline struct sk_buff *fill_packet(struct net_device *odev,
  2416. struct pktgen_dev *pkt_dev)
  2417. {
  2418. if (pkt_dev->flags & F_IPV6)
  2419. return fill_packet_ipv6(odev, pkt_dev);
  2420. else
  2421. return fill_packet_ipv4(odev, pkt_dev);
  2422. }
  2423. static void pktgen_clear_counters(struct pktgen_dev *pkt_dev)
  2424. {
  2425. pkt_dev->seq_num = 1;
  2426. pkt_dev->idle_acc = 0;
  2427. pkt_dev->sofar = 0;
  2428. pkt_dev->tx_bytes = 0;
  2429. pkt_dev->errors = 0;
  2430. }
  2431. /* Set up structure for sending pkts, clear counters */
  2432. static void pktgen_run(struct pktgen_thread *t)
  2433. {
  2434. struct pktgen_dev *pkt_dev;
  2435. int started = 0;
  2436. pr_debug("pktgen: entering pktgen_run. %p\n", t);
  2437. if_lock(t);
  2438. list_for_each_entry(pkt_dev, &t->if_list, list) {
  2439. /*
  2440. * setup odev and create initial packet.
  2441. */
  2442. pktgen_setup_inject(pkt_dev);
  2443. if (pkt_dev->odev) {
  2444. pktgen_clear_counters(pkt_dev);
  2445. pkt_dev->running = 1; /* Cranke yeself! */
  2446. pkt_dev->skb = NULL;
  2447. pkt_dev->started_at = getCurUs();
  2448. pkt_dev->next_tx_us = getCurUs(); /* Transmit immediately */
  2449. pkt_dev->next_tx_ns = 0;
  2450. strcpy(pkt_dev->result, "Starting");
  2451. started++;
  2452. } else
  2453. strcpy(pkt_dev->result, "Error starting");
  2454. }
  2455. if_unlock(t);
  2456. if (started)
  2457. t->control &= ~(T_STOP);
  2458. }
  2459. static void pktgen_stop_all_threads_ifs(void)
  2460. {
  2461. struct pktgen_thread *t;
  2462. pr_debug("pktgen: entering pktgen_stop_all_threads_ifs.\n");
  2463. mutex_lock(&pktgen_thread_lock);
  2464. list_for_each_entry(t, &pktgen_threads, th_list)
  2465. t->control |= T_STOP;
  2466. mutex_unlock(&pktgen_thread_lock);
  2467. }
  2468. static int thread_is_running(struct pktgen_thread *t)
  2469. {
  2470. struct pktgen_dev *pkt_dev;
  2471. int res = 0;
  2472. list_for_each_entry(pkt_dev, &t->if_list, list)
  2473. if (pkt_dev->running) {
  2474. res = 1;
  2475. break;
  2476. }
  2477. return res;
  2478. }
  2479. static int pktgen_wait_thread_run(struct pktgen_thread *t)
  2480. {
  2481. if_lock(t);
  2482. while (thread_is_running(t)) {
  2483. if_unlock(t);
  2484. msleep_interruptible(100);
  2485. if (signal_pending(current))
  2486. goto signal;
  2487. if_lock(t);
  2488. }
  2489. if_unlock(t);
  2490. return 1;
  2491. signal:
  2492. return 0;
  2493. }
  2494. static int pktgen_wait_all_threads_run(void)
  2495. {
  2496. struct pktgen_thread *t;
  2497. int sig = 1;
  2498. mutex_lock(&pktgen_thread_lock);
  2499. list_for_each_entry(t, &pktgen_threads, th_list) {
  2500. sig = pktgen_wait_thread_run(t);
  2501. if (sig == 0)
  2502. break;
  2503. }
  2504. if (sig == 0)
  2505. list_for_each_entry(t, &pktgen_threads, th_list)
  2506. t->control |= (T_STOP);
  2507. mutex_unlock(&pktgen_thread_lock);
  2508. return sig;
  2509. }
  2510. static void pktgen_run_all_threads(void)
  2511. {
  2512. struct pktgen_thread *t;
  2513. pr_debug("pktgen: entering pktgen_run_all_threads.\n");
  2514. mutex_lock(&pktgen_thread_lock);
  2515. list_for_each_entry(t, &pktgen_threads, th_list)
  2516. t->control |= (T_RUN);
  2517. mutex_unlock(&pktgen_thread_lock);
  2518. schedule_timeout_interruptible(msecs_to_jiffies(125)); /* Propagate thread->control */
  2519. pktgen_wait_all_threads_run();
  2520. }
  2521. static void show_results(struct pktgen_dev *pkt_dev, int nr_frags)
  2522. {
  2523. __u64 total_us, bps, mbps, pps, idle;
  2524. char *p = pkt_dev->result;
  2525. total_us = pkt_dev->stopped_at - pkt_dev->started_at;
  2526. idle = pkt_dev->idle_acc;
  2527. p += sprintf(p, "OK: %llu(c%llu+d%llu) usec, %llu (%dbyte,%dfrags)\n",
  2528. (unsigned long long)total_us,
  2529. (unsigned long long)(total_us - idle),
  2530. (unsigned long long)idle,
  2531. (unsigned long long)pkt_dev->sofar,
  2532. pkt_dev->cur_pkt_size, nr_frags);
  2533. pps = pkt_dev->sofar * USEC_PER_SEC;
  2534. while ((total_us >> 32) != 0) {
  2535. pps >>= 1;
  2536. total_us >>= 1;
  2537. }
  2538. do_div(pps, total_us);
  2539. bps = pps * 8 * pkt_dev->cur_pkt_size;
  2540. mbps = bps;
  2541. do_div(mbps, 1000000);
  2542. p += sprintf(p, " %llupps %lluMb/sec (%llubps) errors: %llu",
  2543. (unsigned long long)pps,
  2544. (unsigned long long)mbps,
  2545. (unsigned long long)bps,
  2546. (unsigned long long)pkt_dev->errors);
  2547. }
  2548. /* Set stopped-at timer, remove from running list, do counters & statistics */
  2549. static int pktgen_stop_device(struct pktgen_dev *pkt_dev)
  2550. {
  2551. int nr_frags = pkt_dev->skb ? skb_shinfo(pkt_dev->skb)->nr_frags : -1;
  2552. if (!pkt_dev->running) {
  2553. printk("pktgen: interface: %s is already stopped\n",
  2554. pkt_dev->ifname);
  2555. return -EINVAL;
  2556. }
  2557. pkt_dev->stopped_at = getCurUs();
  2558. pkt_dev->running = 0;
  2559. show_results(pkt_dev, nr_frags);
  2560. return 0;
  2561. }
  2562. static struct pktgen_dev *next_to_run(struct pktgen_thread *t)
  2563. {
  2564. struct pktgen_dev *pkt_dev, *best = NULL;
  2565. if_lock(t);
  2566. list_for_each_entry(pkt_dev, &t->if_list, list) {
  2567. if (!pkt_dev->running)
  2568. continue;
  2569. if (best == NULL)
  2570. best = pkt_dev;
  2571. else if (pkt_dev->next_tx_us < best->next_tx_us)
  2572. best = pkt_dev;
  2573. }
  2574. if_unlock(t);
  2575. return best;
  2576. }
  2577. static void pktgen_stop(struct pktgen_thread *t)
  2578. {
  2579. struct pktgen_dev *pkt_dev;
  2580. pr_debug("pktgen: entering pktgen_stop\n");
  2581. if_lock(t);
  2582. list_for_each_entry(pkt_dev, &t->if_list, list) {
  2583. pktgen_stop_device(pkt_dev);
  2584. if (pkt_dev->skb)
  2585. kfree_skb(pkt_dev->skb);
  2586. pkt_dev->skb = NULL;
  2587. }
  2588. if_unlock(t);
  2589. }
  2590. /*
  2591. * one of our devices needs to be removed - find it
  2592. * and remove it
  2593. */
  2594. static void pktgen_rem_one_if(struct pktgen_thread *t)
  2595. {
  2596. struct list_head *q, *n;
  2597. struct pktgen_dev *cur;
  2598. pr_debug("pktgen: entering pktgen_rem_one_if\n");
  2599. if_lock(t);
  2600. list_for_each_safe(q, n, &t->if_list) {
  2601. cur = list_entry(q, struct pktgen_dev, list);
  2602. if (!cur->removal_mark)
  2603. continue;
  2604. if (cur->skb)
  2605. kfree_skb(cur->skb);
  2606. cur->skb = NULL;
  2607. pktgen_remove_device(t, cur);
  2608. break;
  2609. }
  2610. if_unlock(t);
  2611. }
  2612. static void pktgen_rem_all_ifs(struct pktgen_thread *t)
  2613. {
  2614. struct list_head *q, *n;
  2615. struct pktgen_dev *cur;
  2616. /* Remove all devices, free mem */
  2617. pr_debug("pktgen: entering pktgen_rem_all_ifs\n");
  2618. if_lock(t);
  2619. list_for_each_safe(q, n, &t->if_list) {
  2620. cur = list_entry(q, struct pktgen_dev, list);
  2621. if (cur->skb)
  2622. kfree_skb(cur->skb);
  2623. cur->skb = NULL;
  2624. pktgen_remove_device(t, cur);
  2625. }
  2626. if_unlock(t);
  2627. }
  2628. static void pktgen_rem_thread(struct pktgen_thread *t)
  2629. {
  2630. /* Remove from the thread list */
  2631. remove_proc_entry(t->tsk->comm, pg_proc_dir);
  2632. mutex_lock(&pktgen_thread_lock);
  2633. list_del(&t->th_list);
  2634. mutex_unlock(&pktgen_thread_lock);
  2635. }
  2636. static __inline__ void pktgen_xmit(struct pktgen_dev *pkt_dev)
  2637. {
  2638. struct net_device *odev = NULL;
  2639. __u64 idle_start = 0;
  2640. int ret;
  2641. odev = pkt_dev->odev;
  2642. if (pkt_dev->delay_us || pkt_dev->delay_ns) {
  2643. u64 now;
  2644. now = getCurUs();
  2645. if (now < pkt_dev->next_tx_us)
  2646. spin(pkt_dev, pkt_dev->next_tx_us);
  2647. /* This is max DELAY, this has special meaning of
  2648. * "never transmit"
  2649. */
  2650. if (pkt_dev->delay_us == 0x7FFFFFFF) {
  2651. pkt_dev->next_tx_us = getCurUs() + pkt_dev->delay_us;
  2652. pkt_dev->next_tx_ns = pkt_dev->delay_ns;
  2653. goto out;
  2654. }
  2655. }
  2656. if (netif_queue_stopped(odev) || need_resched()) {
  2657. idle_start = getCurUs();
  2658. if (!netif_running(odev)) {
  2659. pktgen_stop_device(pkt_dev);
  2660. if (pkt_dev->skb)
  2661. kfree_skb(pkt_dev->skb);
  2662. pkt_dev->skb = NULL;
  2663. goto out;
  2664. }
  2665. if (need_resched())
  2666. schedule();
  2667. pkt_dev->idle_acc += getCurUs() - idle_start;
  2668. if (netif_queue_stopped(odev)) {
  2669. pkt_dev->next_tx_us = getCurUs(); /* TODO */
  2670. pkt_dev->next_tx_ns = 0;
  2671. goto out; /* Try the next interface */
  2672. }
  2673. }
  2674. if (pkt_dev->last_ok || !pkt_dev->skb) {
  2675. if ((++pkt_dev->clone_count >= pkt_dev->clone_skb)
  2676. || (!pkt_dev->skb)) {
  2677. /* build a new pkt */
  2678. if (pkt_dev->skb)
  2679. kfree_skb(pkt_dev->skb);
  2680. pkt_dev->skb = fill_packet(odev, pkt_dev);
  2681. if (pkt_dev->skb == NULL) {
  2682. printk("pktgen: ERROR: couldn't allocate skb in fill_packet.\n");
  2683. schedule();
  2684. pkt_dev->clone_count--; /* back out increment, OOM */
  2685. goto out;
  2686. }
  2687. pkt_dev->allocated_skbs++;
  2688. pkt_dev->clone_count = 0; /* reset counter */
  2689. }
  2690. }
  2691. netif_tx_lock_bh(odev);
  2692. if (!netif_queue_stopped(odev)) {
  2693. atomic_inc(&(pkt_dev->skb->users));
  2694. retry_now:
  2695. ret = odev->hard_start_xmit(pkt_dev->skb, odev);
  2696. if (likely(ret == NETDEV_TX_OK)) {
  2697. pkt_dev->last_ok = 1;
  2698. pkt_dev->sofar++;
  2699. pkt_dev->seq_num++;
  2700. pkt_dev->tx_bytes += pkt_dev->cur_pkt_size;
  2701. } else if (ret == NETDEV_TX_LOCKED
  2702. && (odev->features & NETIF_F_LLTX)) {
  2703. cpu_relax();
  2704. goto retry_now;
  2705. } else { /* Retry it next time */
  2706. atomic_dec(&(pkt_dev->skb->users));
  2707. if (debug && net_ratelimit())
  2708. printk(KERN_INFO "pktgen: Hard xmit error\n");
  2709. pkt_dev->errors++;
  2710. pkt_dev->last_ok = 0;
  2711. }
  2712. pkt_dev->next_tx_us = getCurUs();
  2713. pkt_dev->next_tx_ns = 0;
  2714. pkt_dev->next_tx_us += pkt_dev->delay_us;
  2715. pkt_dev->next_tx_ns += pkt_dev->delay_ns;
  2716. if (pkt_dev->next_tx_ns > 1000) {
  2717. pkt_dev->next_tx_us++;
  2718. pkt_dev->next_tx_ns -= 1000;
  2719. }
  2720. }
  2721. else { /* Retry it next time */
  2722. pkt_dev->last_ok = 0;
  2723. pkt_dev->next_tx_us = getCurUs(); /* TODO */
  2724. pkt_dev->next_tx_ns = 0;
  2725. }
  2726. netif_tx_unlock_bh(odev);
  2727. /* If pkt_dev->count is zero, then run forever */
  2728. if ((pkt_dev->count != 0) && (pkt_dev->sofar >= pkt_dev->count)) {
  2729. if (atomic_read(&(pkt_dev->skb->users)) != 1) {
  2730. idle_start = getCurUs();
  2731. while (atomic_read(&(pkt_dev->skb->users)) != 1) {
  2732. if (signal_pending(current)) {
  2733. break;
  2734. }
  2735. schedule();
  2736. }
  2737. pkt_dev->idle_acc += getCurUs() - idle_start;
  2738. }
  2739. /* Done with this */
  2740. pktgen_stop_device(pkt_dev);
  2741. if (pkt_dev->skb)
  2742. kfree_skb(pkt_dev->skb);
  2743. pkt_dev->skb = NULL;
  2744. }
  2745. out:;
  2746. }
  2747. /*
  2748. * Main loop of the thread goes here
  2749. */
  2750. static int pktgen_thread_worker(void *arg)
  2751. {
  2752. DEFINE_WAIT(wait);
  2753. struct pktgen_thread *t = arg;
  2754. struct pktgen_dev *pkt_dev = NULL;
  2755. int cpu = t->cpu;
  2756. u32 max_before_softirq;
  2757. u32 tx_since_softirq = 0;
  2758. BUG_ON(smp_processor_id() != cpu);
  2759. init_waitqueue_head(&t->queue);
  2760. t->pid = current->pid;
  2761. pr_debug("pktgen: starting pktgen/%d: pid=%d\n", cpu, current->pid);
  2762. max_before_softirq = t->max_before_softirq;
  2763. set_current_state(TASK_INTERRUPTIBLE);
  2764. while (!kthread_should_stop()) {
  2765. pkt_dev = next_to_run(t);
  2766. if (!pkt_dev &&
  2767. (t->control & (T_STOP | T_RUN | T_REMDEVALL | T_REMDEV))
  2768. == 0) {
  2769. prepare_to_wait(&(t->queue), &wait,
  2770. TASK_INTERRUPTIBLE);
  2771. schedule_timeout(HZ / 10);
  2772. finish_wait(&(t->queue), &wait);
  2773. }
  2774. __set_current_state(TASK_RUNNING);
  2775. if (pkt_dev) {
  2776. pktgen_xmit(pkt_dev);
  2777. /*
  2778. * We like to stay RUNNING but must also give
  2779. * others fair share.
  2780. */
  2781. tx_since_softirq += pkt_dev->last_ok;
  2782. if (tx_since_softirq > max_before_softirq) {
  2783. if (local_softirq_pending())
  2784. do_softirq();
  2785. tx_since_softirq = 0;
  2786. }
  2787. }
  2788. if (t->control & T_STOP) {
  2789. pktgen_stop(t);
  2790. t->control &= ~(T_STOP);
  2791. }
  2792. if (t->control & T_RUN) {
  2793. pktgen_run(t);
  2794. t->control &= ~(T_RUN);
  2795. }
  2796. if (t->control & T_REMDEVALL) {
  2797. pktgen_rem_all_ifs(t);
  2798. t->control &= ~(T_REMDEVALL);
  2799. }
  2800. if (t->control & T_REMDEV) {
  2801. pktgen_rem_one_if(t);
  2802. t->control &= ~(T_REMDEV);
  2803. }
  2804. try_to_freeze();
  2805. set_current_state(TASK_INTERRUPTIBLE);
  2806. }
  2807. pr_debug("pktgen: %s stopping all device\n", t->tsk->comm);
  2808. pktgen_stop(t);
  2809. pr_debug("pktgen: %s removing all device\n", t->tsk->comm);
  2810. pktgen_rem_all_ifs(t);
  2811. pr_debug("pktgen: %s removing thread.\n", t->tsk->comm);
  2812. pktgen_rem_thread(t);
  2813. return 0;
  2814. }
  2815. static struct pktgen_dev *pktgen_find_dev(struct pktgen_thread *t,
  2816. const char *ifname)
  2817. {
  2818. struct pktgen_dev *p, *pkt_dev = NULL;
  2819. if_lock(t);
  2820. list_for_each_entry(p, &t->if_list, list)
  2821. if (strncmp(p->ifname, ifname, IFNAMSIZ) == 0) {
  2822. pkt_dev = p;
  2823. break;
  2824. }
  2825. if_unlock(t);
  2826. pr_debug("pktgen: find_dev(%s) returning %p\n", ifname, pkt_dev);
  2827. return pkt_dev;
  2828. }
  2829. /*
  2830. * Adds a dev at front of if_list.
  2831. */
  2832. static int add_dev_to_thread(struct pktgen_thread *t,
  2833. struct pktgen_dev *pkt_dev)
  2834. {
  2835. int rv = 0;
  2836. if_lock(t);
  2837. if (pkt_dev->pg_thread) {
  2838. printk("pktgen: ERROR: already assigned to a thread.\n");
  2839. rv = -EBUSY;
  2840. goto out;
  2841. }
  2842. list_add(&pkt_dev->list, &t->if_list);
  2843. pkt_dev->pg_thread = t;
  2844. pkt_dev->running = 0;
  2845. out:
  2846. if_unlock(t);
  2847. return rv;
  2848. }
  2849. /* Called under thread lock */
  2850. static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
  2851. {
  2852. struct pktgen_dev *pkt_dev;
  2853. struct proc_dir_entry *pe;
  2854. /* We don't allow a device to be on several threads */
  2855. pkt_dev = __pktgen_NN_threads(ifname, FIND);
  2856. if (pkt_dev) {
  2857. printk("pktgen: ERROR: interface already used.\n");
  2858. return -EBUSY;
  2859. }
  2860. pkt_dev = kzalloc(sizeof(struct pktgen_dev), GFP_KERNEL);
  2861. if (!pkt_dev)
  2862. return -ENOMEM;
  2863. pkt_dev->flows = vmalloc(MAX_CFLOWS * sizeof(struct flow_state));
  2864. if (pkt_dev->flows == NULL) {
  2865. kfree(pkt_dev);
  2866. return -ENOMEM;
  2867. }
  2868. memset(pkt_dev->flows, 0, MAX_CFLOWS * sizeof(struct flow_state));
  2869. pkt_dev->removal_mark = 0;
  2870. pkt_dev->min_pkt_size = ETH_ZLEN;
  2871. pkt_dev->max_pkt_size = ETH_ZLEN;
  2872. pkt_dev->nfrags = 0;
  2873. pkt_dev->clone_skb = pg_clone_skb_d;
  2874. pkt_dev->delay_us = pg_delay_d / 1000;
  2875. pkt_dev->delay_ns = pg_delay_d % 1000;
  2876. pkt_dev->count = pg_count_d;
  2877. pkt_dev->sofar = 0;
  2878. pkt_dev->udp_src_min = 9; /* sink port */
  2879. pkt_dev->udp_src_max = 9;
  2880. pkt_dev->udp_dst_min = 9;
  2881. pkt_dev->udp_dst_max = 9;
  2882. pkt_dev->vlan_p = 0;
  2883. pkt_dev->vlan_cfi = 0;
  2884. pkt_dev->vlan_id = 0xffff;
  2885. pkt_dev->svlan_p = 0;
  2886. pkt_dev->svlan_cfi = 0;
  2887. pkt_dev->svlan_id = 0xffff;
  2888. strncpy(pkt_dev->ifname, ifname, IFNAMSIZ);
  2889. if (!pktgen_setup_dev(pkt_dev)) {
  2890. printk("pktgen: ERROR: pktgen_setup_dev failed.\n");
  2891. if (pkt_dev->flows)
  2892. vfree(pkt_dev->flows);
  2893. kfree(pkt_dev);
  2894. return -ENODEV;
  2895. }
  2896. pe = create_proc_entry(ifname, 0600, pg_proc_dir);
  2897. if (!pe) {
  2898. printk("pktgen: cannot create %s/%s procfs entry.\n",
  2899. PG_PROC_DIR, ifname);
  2900. if (pkt_dev->flows)
  2901. vfree(pkt_dev->flows);
  2902. kfree(pkt_dev);
  2903. return -EINVAL;
  2904. }
  2905. pe->proc_fops = &pktgen_if_fops;
  2906. pe->data = pkt_dev;
  2907. return add_dev_to_thread(t, pkt_dev);
  2908. }
  2909. static int __init pktgen_create_thread(int cpu)
  2910. {
  2911. struct pktgen_thread *t;
  2912. struct proc_dir_entry *pe;
  2913. struct task_struct *p;
  2914. t = kzalloc(sizeof(struct pktgen_thread), GFP_KERNEL);
  2915. if (!t) {
  2916. printk("pktgen: ERROR: out of memory, can't create new thread.\n");
  2917. return -ENOMEM;
  2918. }
  2919. spin_lock_init(&t->if_lock);
  2920. t->cpu = cpu;
  2921. INIT_LIST_HEAD(&t->if_list);
  2922. list_add_tail(&t->th_list, &pktgen_threads);
  2923. p = kthread_create(pktgen_thread_worker, t, "kpktgend_%d", cpu);
  2924. if (IS_ERR(p)) {
  2925. printk("pktgen: kernel_thread() failed for cpu %d\n", t->cpu);
  2926. list_del(&t->th_list);
  2927. kfree(t);
  2928. return PTR_ERR(p);
  2929. }
  2930. kthread_bind(p, cpu);
  2931. t->tsk = p;
  2932. pe = create_proc_entry(t->tsk->comm, 0600, pg_proc_dir);
  2933. if (!pe) {
  2934. printk("pktgen: cannot create %s/%s procfs entry.\n",
  2935. PG_PROC_DIR, t->tsk->comm);
  2936. kthread_stop(p);
  2937. list_del(&t->th_list);
  2938. kfree(t);
  2939. return -EINVAL;
  2940. }
  2941. pe->proc_fops = &pktgen_thread_fops;
  2942. pe->data = t;
  2943. wake_up_process(p);
  2944. return 0;
  2945. }
  2946. /*
  2947. * Removes a device from the thread if_list.
  2948. */
  2949. static void _rem_dev_from_if_list(struct pktgen_thread *t,
  2950. struct pktgen_dev *pkt_dev)
  2951. {
  2952. struct list_head *q, *n;
  2953. struct pktgen_dev *p;
  2954. list_for_each_safe(q, n, &t->if_list) {
  2955. p = list_entry(q, struct pktgen_dev, list);
  2956. if (p == pkt_dev)
  2957. list_del(&p->list);
  2958. }
  2959. }
  2960. static int pktgen_remove_device(struct pktgen_thread *t,
  2961. struct pktgen_dev *pkt_dev)
  2962. {
  2963. pr_debug("pktgen: remove_device pkt_dev=%p\n", pkt_dev);
  2964. if (pkt_dev->running) {
  2965. printk("pktgen:WARNING: trying to remove a running interface, stopping it now.\n");
  2966. pktgen_stop_device(pkt_dev);
  2967. }
  2968. /* Dis-associate from the interface */
  2969. if (pkt_dev->odev) {
  2970. dev_put(pkt_dev->odev);
  2971. pkt_dev->odev = NULL;
  2972. }
  2973. /* And update the thread if_list */
  2974. _rem_dev_from_if_list(t, pkt_dev);
  2975. /* Clean up proc file system */
  2976. remove_proc_entry(pkt_dev->ifname, pg_proc_dir);
  2977. if (pkt_dev->flows)
  2978. vfree(pkt_dev->flows);
  2979. kfree(pkt_dev);
  2980. return 0;
  2981. }
  2982. static int __init pg_init(void)
  2983. {
  2984. int cpu;
  2985. struct proc_dir_entry *pe;
  2986. printk(version);
  2987. pg_proc_dir = proc_mkdir(PG_PROC_DIR, proc_net);
  2988. if (!pg_proc_dir)
  2989. return -ENODEV;
  2990. pg_proc_dir->owner = THIS_MODULE;
  2991. pe = create_proc_entry(PGCTRL, 0600, pg_proc_dir);
  2992. if (pe == NULL) {
  2993. printk("pktgen: ERROR: cannot create %s procfs entry.\n",
  2994. PGCTRL);
  2995. proc_net_remove(PG_PROC_DIR);
  2996. return -EINVAL;
  2997. }
  2998. pe->proc_fops = &pktgen_fops;
  2999. pe->data = NULL;
  3000. /* Register us to receive netdevice events */
  3001. register_netdevice_notifier(&pktgen_notifier_block);
  3002. for_each_online_cpu(cpu) {
  3003. int err;
  3004. err = pktgen_create_thread(cpu);
  3005. if (err)
  3006. printk("pktgen: WARNING: Cannot create thread for cpu %d (%d)\n",
  3007. cpu, err);
  3008. }
  3009. if (list_empty(&pktgen_threads)) {
  3010. printk("pktgen: ERROR: Initialization failed for all threads\n");
  3011. unregister_netdevice_notifier(&pktgen_notifier_block);
  3012. remove_proc_entry(PGCTRL, pg_proc_dir);
  3013. proc_net_remove(PG_PROC_DIR);
  3014. return -ENODEV;
  3015. }
  3016. return 0;
  3017. }
  3018. static void __exit pg_cleanup(void)
  3019. {
  3020. struct pktgen_thread *t;
  3021. struct list_head *q, *n;
  3022. wait_queue_head_t queue;
  3023. init_waitqueue_head(&queue);
  3024. /* Stop all interfaces & threads */
  3025. list_for_each_safe(q, n, &pktgen_threads) {
  3026. t = list_entry(q, struct pktgen_thread, th_list);
  3027. kthread_stop(t->tsk);
  3028. kfree(t);
  3029. }
  3030. /* Un-register us from receiving netdevice events */
  3031. unregister_netdevice_notifier(&pktgen_notifier_block);
  3032. /* Clean up proc file system */
  3033. remove_proc_entry(PGCTRL, pg_proc_dir);
  3034. proc_net_remove(PG_PROC_DIR);
  3035. }
  3036. module_init(pg_init);
  3037. module_exit(pg_cleanup);
  3038. MODULE_AUTHOR("Robert Olsson <robert.olsson@its.uu.se");
  3039. MODULE_DESCRIPTION("Packet Generator tool");
  3040. MODULE_LICENSE("GPL");
  3041. module_param(pg_count_d, int, 0);
  3042. module_param(pg_delay_d, int, 0);
  3043. module_param(pg_clone_skb_d, int, 0);
  3044. module_param(debug, int, 0);