skbuff.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622
  1. /*
  2. * Routines having to do with the 'struct sk_buff' memory handlers.
  3. *
  4. * Authors: Alan Cox <iiitac@pyr.swan.ac.uk>
  5. * Florian La Roche <rzsfl@rz.uni-sb.de>
  6. *
  7. * Fixes:
  8. * Alan Cox : Fixed the worst of the load
  9. * balancer bugs.
  10. * Dave Platt : Interrupt stacking fix.
  11. * Richard Kooijman : Timestamp fixes.
  12. * Alan Cox : Changed buffer format.
  13. * Alan Cox : destructor hook for AF_UNIX etc.
  14. * Linus Torvalds : Better skb_clone.
  15. * Alan Cox : Added skb_copy.
  16. * Alan Cox : Added all the changed routines Linus
  17. * only put in the headers
  18. * Ray VanTassle : Fixed --skb->lock in free
  19. * Alan Cox : skb_copy copy arp field
  20. * Andi Kleen : slabified it.
  21. * Robert Olsson : Removed skb_head_pool
  22. *
  23. * NOTE:
  24. * The __skb_ routines should be called with interrupts
  25. * disabled, or you better be *real* sure that the operation is atomic
  26. * with respect to whatever list is being frobbed (e.g. via lock_sock()
  27. * or via disabling bottom half handlers, etc).
  28. *
  29. * This program is free software; you can redistribute it and/or
  30. * modify it under the terms of the GNU General Public License
  31. * as published by the Free Software Foundation; either version
  32. * 2 of the License, or (at your option) any later version.
  33. */
  34. /*
  35. * The functions in this file will not compile correctly with gcc 2.4.x
  36. */
  37. #include <linux/module.h>
  38. #include <linux/types.h>
  39. #include <linux/kernel.h>
  40. #include <linux/mm.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/in.h>
  43. #include <linux/inet.h>
  44. #include <linux/slab.h>
  45. #include <linux/netdevice.h>
  46. #ifdef CONFIG_NET_CLS_ACT
  47. #include <net/pkt_sched.h>
  48. #endif
  49. #include <linux/string.h>
  50. #include <linux/skbuff.h>
  51. #include <linux/splice.h>
  52. #include <linux/cache.h>
  53. #include <linux/rtnetlink.h>
  54. #include <linux/init.h>
  55. #include <linux/scatterlist.h>
  56. #include <net/protocol.h>
  57. #include <net/dst.h>
  58. #include <net/sock.h>
  59. #include <net/checksum.h>
  60. #include <net/xfrm.h>
  61. #include <asm/uaccess.h>
  62. #include <asm/system.h>
  63. #include "kmap_skb.h"
  64. static struct kmem_cache *skbuff_head_cache __read_mostly;
  65. static struct kmem_cache *skbuff_fclone_cache __read_mostly;
  66. static void sock_pipe_buf_release(struct pipe_inode_info *pipe,
  67. struct pipe_buffer *buf)
  68. {
  69. struct sk_buff *skb = (struct sk_buff *) buf->private;
  70. kfree_skb(skb);
  71. }
  72. static void sock_pipe_buf_get(struct pipe_inode_info *pipe,
  73. struct pipe_buffer *buf)
  74. {
  75. struct sk_buff *skb = (struct sk_buff *) buf->private;
  76. skb_get(skb);
  77. }
  78. static int sock_pipe_buf_steal(struct pipe_inode_info *pipe,
  79. struct pipe_buffer *buf)
  80. {
  81. return 1;
  82. }
  83. /* Pipe buffer operations for a socket. */
  84. static struct pipe_buf_operations sock_pipe_buf_ops = {
  85. .can_merge = 0,
  86. .map = generic_pipe_buf_map,
  87. .unmap = generic_pipe_buf_unmap,
  88. .confirm = generic_pipe_buf_confirm,
  89. .release = sock_pipe_buf_release,
  90. .steal = sock_pipe_buf_steal,
  91. .get = sock_pipe_buf_get,
  92. };
  93. /*
  94. * Keep out-of-line to prevent kernel bloat.
  95. * __builtin_return_address is not used because it is not always
  96. * reliable.
  97. */
  98. /**
  99. * skb_over_panic - private function
  100. * @skb: buffer
  101. * @sz: size
  102. * @here: address
  103. *
  104. * Out of line support code for skb_put(). Not user callable.
  105. */
  106. void skb_over_panic(struct sk_buff *skb, int sz, void *here)
  107. {
  108. printk(KERN_EMERG "skb_over_panic: text:%p len:%d put:%d head:%p "
  109. "data:%p tail:%#lx end:%#lx dev:%s\n",
  110. here, skb->len, sz, skb->head, skb->data,
  111. (unsigned long)skb->tail, (unsigned long)skb->end,
  112. skb->dev ? skb->dev->name : "<NULL>");
  113. BUG();
  114. }
  115. /**
  116. * skb_under_panic - private function
  117. * @skb: buffer
  118. * @sz: size
  119. * @here: address
  120. *
  121. * Out of line support code for skb_push(). Not user callable.
  122. */
  123. void skb_under_panic(struct sk_buff *skb, int sz, void *here)
  124. {
  125. printk(KERN_EMERG "skb_under_panic: text:%p len:%d put:%d head:%p "
  126. "data:%p tail:%#lx end:%#lx dev:%s\n",
  127. here, skb->len, sz, skb->head, skb->data,
  128. (unsigned long)skb->tail, (unsigned long)skb->end,
  129. skb->dev ? skb->dev->name : "<NULL>");
  130. BUG();
  131. }
  132. void skb_truesize_bug(struct sk_buff *skb)
  133. {
  134. printk(KERN_ERR "SKB BUG: Invalid truesize (%u) "
  135. "len=%u, sizeof(sk_buff)=%Zd\n",
  136. skb->truesize, skb->len, sizeof(struct sk_buff));
  137. }
  138. EXPORT_SYMBOL(skb_truesize_bug);
  139. /* Allocate a new skbuff. We do this ourselves so we can fill in a few
  140. * 'private' fields and also do memory statistics to find all the
  141. * [BEEP] leaks.
  142. *
  143. */
  144. /**
  145. * __alloc_skb - allocate a network buffer
  146. * @size: size to allocate
  147. * @gfp_mask: allocation mask
  148. * @fclone: allocate from fclone cache instead of head cache
  149. * and allocate a cloned (child) skb
  150. * @node: numa node to allocate memory on
  151. *
  152. * Allocate a new &sk_buff. The returned buffer has no headroom and a
  153. * tail room of size bytes. The object has a reference count of one.
  154. * The return is the buffer. On a failure the return is %NULL.
  155. *
  156. * Buffers may only be allocated from interrupts using a @gfp_mask of
  157. * %GFP_ATOMIC.
  158. */
  159. struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
  160. int fclone, int node)
  161. {
  162. struct kmem_cache *cache;
  163. struct skb_shared_info *shinfo;
  164. struct sk_buff *skb;
  165. u8 *data;
  166. cache = fclone ? skbuff_fclone_cache : skbuff_head_cache;
  167. /* Get the HEAD */
  168. skb = kmem_cache_alloc_node(cache, gfp_mask & ~__GFP_DMA, node);
  169. if (!skb)
  170. goto out;
  171. size = SKB_DATA_ALIGN(size);
  172. data = kmalloc_node_track_caller(size + sizeof(struct skb_shared_info),
  173. gfp_mask, node);
  174. if (!data)
  175. goto nodata;
  176. /*
  177. * Only clear those fields we need to clear, not those that we will
  178. * actually initialise below. Hence, don't put any more fields after
  179. * the tail pointer in struct sk_buff!
  180. */
  181. memset(skb, 0, offsetof(struct sk_buff, tail));
  182. skb->truesize = size + sizeof(struct sk_buff);
  183. atomic_set(&skb->users, 1);
  184. skb->head = data;
  185. skb->data = data;
  186. skb_reset_tail_pointer(skb);
  187. skb->end = skb->tail + size;
  188. /* make sure we initialize shinfo sequentially */
  189. shinfo = skb_shinfo(skb);
  190. atomic_set(&shinfo->dataref, 1);
  191. shinfo->nr_frags = 0;
  192. shinfo->gso_size = 0;
  193. shinfo->gso_segs = 0;
  194. shinfo->gso_type = 0;
  195. shinfo->ip6_frag_id = 0;
  196. shinfo->frag_list = NULL;
  197. if (fclone) {
  198. struct sk_buff *child = skb + 1;
  199. atomic_t *fclone_ref = (atomic_t *) (child + 1);
  200. skb->fclone = SKB_FCLONE_ORIG;
  201. atomic_set(fclone_ref, 1);
  202. child->fclone = SKB_FCLONE_UNAVAILABLE;
  203. }
  204. out:
  205. return skb;
  206. nodata:
  207. kmem_cache_free(cache, skb);
  208. skb = NULL;
  209. goto out;
  210. }
  211. /**
  212. * __netdev_alloc_skb - allocate an skbuff for rx on a specific device
  213. * @dev: network device to receive on
  214. * @length: length to allocate
  215. * @gfp_mask: get_free_pages mask, passed to alloc_skb
  216. *
  217. * Allocate a new &sk_buff and assign it a usage count of one. The
  218. * buffer has unspecified headroom built in. Users should allocate
  219. * the headroom they think they need without accounting for the
  220. * built in space. The built in space is used for optimisations.
  221. *
  222. * %NULL is returned if there is no free memory.
  223. */
  224. struct sk_buff *__netdev_alloc_skb(struct net_device *dev,
  225. unsigned int length, gfp_t gfp_mask)
  226. {
  227. int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1;
  228. struct sk_buff *skb;
  229. skb = __alloc_skb(length + NET_SKB_PAD, gfp_mask, 0, node);
  230. if (likely(skb)) {
  231. skb_reserve(skb, NET_SKB_PAD);
  232. skb->dev = dev;
  233. }
  234. return skb;
  235. }
  236. /**
  237. * dev_alloc_skb - allocate an skbuff for receiving
  238. * @length: length to allocate
  239. *
  240. * Allocate a new &sk_buff and assign it a usage count of one. The
  241. * buffer has unspecified headroom built in. Users should allocate
  242. * the headroom they think they need without accounting for the
  243. * built in space. The built in space is used for optimisations.
  244. *
  245. * %NULL is returned if there is no free memory. Although this function
  246. * allocates memory it can be called from an interrupt.
  247. */
  248. struct sk_buff *dev_alloc_skb(unsigned int length)
  249. {
  250. /*
  251. * There is more code here than it seems:
  252. * __dev_alloc_skb is an inline
  253. */
  254. return __dev_alloc_skb(length, GFP_ATOMIC);
  255. }
  256. EXPORT_SYMBOL(dev_alloc_skb);
  257. static void skb_drop_list(struct sk_buff **listp)
  258. {
  259. struct sk_buff *list = *listp;
  260. *listp = NULL;
  261. do {
  262. struct sk_buff *this = list;
  263. list = list->next;
  264. kfree_skb(this);
  265. } while (list);
  266. }
  267. static inline void skb_drop_fraglist(struct sk_buff *skb)
  268. {
  269. skb_drop_list(&skb_shinfo(skb)->frag_list);
  270. }
  271. static void skb_clone_fraglist(struct sk_buff *skb)
  272. {
  273. struct sk_buff *list;
  274. for (list = skb_shinfo(skb)->frag_list; list; list = list->next)
  275. skb_get(list);
  276. }
  277. static void skb_release_data(struct sk_buff *skb)
  278. {
  279. if (!skb->cloned ||
  280. !atomic_sub_return(skb->nohdr ? (1 << SKB_DATAREF_SHIFT) + 1 : 1,
  281. &skb_shinfo(skb)->dataref)) {
  282. if (skb_shinfo(skb)->nr_frags) {
  283. int i;
  284. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  285. put_page(skb_shinfo(skb)->frags[i].page);
  286. }
  287. if (skb_shinfo(skb)->frag_list)
  288. skb_drop_fraglist(skb);
  289. kfree(skb->head);
  290. }
  291. }
  292. /*
  293. * Free an skbuff by memory without cleaning the state.
  294. */
  295. static void kfree_skbmem(struct sk_buff *skb)
  296. {
  297. struct sk_buff *other;
  298. atomic_t *fclone_ref;
  299. switch (skb->fclone) {
  300. case SKB_FCLONE_UNAVAILABLE:
  301. kmem_cache_free(skbuff_head_cache, skb);
  302. break;
  303. case SKB_FCLONE_ORIG:
  304. fclone_ref = (atomic_t *) (skb + 2);
  305. if (atomic_dec_and_test(fclone_ref))
  306. kmem_cache_free(skbuff_fclone_cache, skb);
  307. break;
  308. case SKB_FCLONE_CLONE:
  309. fclone_ref = (atomic_t *) (skb + 1);
  310. other = skb - 1;
  311. /* The clone portion is available for
  312. * fast-cloning again.
  313. */
  314. skb->fclone = SKB_FCLONE_UNAVAILABLE;
  315. if (atomic_dec_and_test(fclone_ref))
  316. kmem_cache_free(skbuff_fclone_cache, other);
  317. break;
  318. }
  319. }
  320. /* Free everything but the sk_buff shell. */
  321. static void skb_release_all(struct sk_buff *skb)
  322. {
  323. dst_release(skb->dst);
  324. #ifdef CONFIG_XFRM
  325. secpath_put(skb->sp);
  326. #endif
  327. if (skb->destructor) {
  328. WARN_ON(in_irq());
  329. skb->destructor(skb);
  330. }
  331. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  332. nf_conntrack_put(skb->nfct);
  333. nf_conntrack_put_reasm(skb->nfct_reasm);
  334. #endif
  335. #ifdef CONFIG_BRIDGE_NETFILTER
  336. nf_bridge_put(skb->nf_bridge);
  337. #endif
  338. /* XXX: IS this still necessary? - JHS */
  339. #ifdef CONFIG_NET_SCHED
  340. skb->tc_index = 0;
  341. #ifdef CONFIG_NET_CLS_ACT
  342. skb->tc_verd = 0;
  343. #endif
  344. #endif
  345. skb_release_data(skb);
  346. }
  347. /**
  348. * __kfree_skb - private function
  349. * @skb: buffer
  350. *
  351. * Free an sk_buff. Release anything attached to the buffer.
  352. * Clean the state. This is an internal helper function. Users should
  353. * always call kfree_skb
  354. */
  355. void __kfree_skb(struct sk_buff *skb)
  356. {
  357. skb_release_all(skb);
  358. kfree_skbmem(skb);
  359. }
  360. /**
  361. * kfree_skb - free an sk_buff
  362. * @skb: buffer to free
  363. *
  364. * Drop a reference to the buffer and free it if the usage count has
  365. * hit zero.
  366. */
  367. void kfree_skb(struct sk_buff *skb)
  368. {
  369. if (unlikely(!skb))
  370. return;
  371. if (likely(atomic_read(&skb->users) == 1))
  372. smp_rmb();
  373. else if (likely(!atomic_dec_and_test(&skb->users)))
  374. return;
  375. __kfree_skb(skb);
  376. }
  377. static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
  378. {
  379. new->tstamp = old->tstamp;
  380. new->dev = old->dev;
  381. new->transport_header = old->transport_header;
  382. new->network_header = old->network_header;
  383. new->mac_header = old->mac_header;
  384. new->dst = dst_clone(old->dst);
  385. #ifdef CONFIG_INET
  386. new->sp = secpath_get(old->sp);
  387. #endif
  388. memcpy(new->cb, old->cb, sizeof(old->cb));
  389. new->csum_start = old->csum_start;
  390. new->csum_offset = old->csum_offset;
  391. new->local_df = old->local_df;
  392. new->pkt_type = old->pkt_type;
  393. new->ip_summed = old->ip_summed;
  394. skb_copy_queue_mapping(new, old);
  395. new->priority = old->priority;
  396. #if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
  397. new->ipvs_property = old->ipvs_property;
  398. #endif
  399. new->protocol = old->protocol;
  400. new->mark = old->mark;
  401. __nf_copy(new, old);
  402. #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \
  403. defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
  404. new->nf_trace = old->nf_trace;
  405. #endif
  406. #ifdef CONFIG_NET_SCHED
  407. new->tc_index = old->tc_index;
  408. #ifdef CONFIG_NET_CLS_ACT
  409. new->tc_verd = old->tc_verd;
  410. #endif
  411. #endif
  412. skb_copy_secmark(new, old);
  413. }
  414. static struct sk_buff *__skb_clone(struct sk_buff *n, struct sk_buff *skb)
  415. {
  416. #define C(x) n->x = skb->x
  417. n->next = n->prev = NULL;
  418. n->sk = NULL;
  419. __copy_skb_header(n, skb);
  420. C(len);
  421. C(data_len);
  422. C(mac_len);
  423. n->hdr_len = skb->nohdr ? skb_headroom(skb) : skb->hdr_len;
  424. n->cloned = 1;
  425. n->nohdr = 0;
  426. n->destructor = NULL;
  427. C(iif);
  428. C(tail);
  429. C(end);
  430. C(head);
  431. C(data);
  432. C(truesize);
  433. atomic_set(&n->users, 1);
  434. atomic_inc(&(skb_shinfo(skb)->dataref));
  435. skb->cloned = 1;
  436. return n;
  437. #undef C
  438. }
  439. /**
  440. * skb_morph - morph one skb into another
  441. * @dst: the skb to receive the contents
  442. * @src: the skb to supply the contents
  443. *
  444. * This is identical to skb_clone except that the target skb is
  445. * supplied by the user.
  446. *
  447. * The target skb is returned upon exit.
  448. */
  449. struct sk_buff *skb_morph(struct sk_buff *dst, struct sk_buff *src)
  450. {
  451. skb_release_all(dst);
  452. return __skb_clone(dst, src);
  453. }
  454. EXPORT_SYMBOL_GPL(skb_morph);
  455. /**
  456. * skb_clone - duplicate an sk_buff
  457. * @skb: buffer to clone
  458. * @gfp_mask: allocation priority
  459. *
  460. * Duplicate an &sk_buff. The new one is not owned by a socket. Both
  461. * copies share the same packet data but not structure. The new
  462. * buffer has a reference count of 1. If the allocation fails the
  463. * function returns %NULL otherwise the new buffer is returned.
  464. *
  465. * If this function is called from an interrupt gfp_mask() must be
  466. * %GFP_ATOMIC.
  467. */
  468. struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
  469. {
  470. struct sk_buff *n;
  471. n = skb + 1;
  472. if (skb->fclone == SKB_FCLONE_ORIG &&
  473. n->fclone == SKB_FCLONE_UNAVAILABLE) {
  474. atomic_t *fclone_ref = (atomic_t *) (n + 1);
  475. n->fclone = SKB_FCLONE_CLONE;
  476. atomic_inc(fclone_ref);
  477. } else {
  478. n = kmem_cache_alloc(skbuff_head_cache, gfp_mask);
  479. if (!n)
  480. return NULL;
  481. n->fclone = SKB_FCLONE_UNAVAILABLE;
  482. }
  483. return __skb_clone(n, skb);
  484. }
  485. static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
  486. {
  487. #ifndef NET_SKBUFF_DATA_USES_OFFSET
  488. /*
  489. * Shift between the two data areas in bytes
  490. */
  491. unsigned long offset = new->data - old->data;
  492. #endif
  493. __copy_skb_header(new, old);
  494. #ifndef NET_SKBUFF_DATA_USES_OFFSET
  495. /* {transport,network,mac}_header are relative to skb->head */
  496. new->transport_header += offset;
  497. new->network_header += offset;
  498. new->mac_header += offset;
  499. #endif
  500. skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
  501. skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
  502. skb_shinfo(new)->gso_type = skb_shinfo(old)->gso_type;
  503. }
  504. /**
  505. * skb_copy - create private copy of an sk_buff
  506. * @skb: buffer to copy
  507. * @gfp_mask: allocation priority
  508. *
  509. * Make a copy of both an &sk_buff and its data. This is used when the
  510. * caller wishes to modify the data and needs a private copy of the
  511. * data to alter. Returns %NULL on failure or the pointer to the buffer
  512. * on success. The returned buffer has a reference count of 1.
  513. *
  514. * As by-product this function converts non-linear &sk_buff to linear
  515. * one, so that &sk_buff becomes completely private and caller is allowed
  516. * to modify all the data of returned buffer. This means that this
  517. * function is not recommended for use in circumstances when only
  518. * header is going to be modified. Use pskb_copy() instead.
  519. */
  520. struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)
  521. {
  522. int headerlen = skb->data - skb->head;
  523. /*
  524. * Allocate the copy buffer
  525. */
  526. struct sk_buff *n;
  527. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  528. n = alloc_skb(skb->end + skb->data_len, gfp_mask);
  529. #else
  530. n = alloc_skb(skb->end - skb->head + skb->data_len, gfp_mask);
  531. #endif
  532. if (!n)
  533. return NULL;
  534. /* Set the data pointer */
  535. skb_reserve(n, headerlen);
  536. /* Set the tail pointer and length */
  537. skb_put(n, skb->len);
  538. if (skb_copy_bits(skb, -headerlen, n->head, headerlen + skb->len))
  539. BUG();
  540. copy_skb_header(n, skb);
  541. return n;
  542. }
  543. /**
  544. * pskb_copy - create copy of an sk_buff with private head.
  545. * @skb: buffer to copy
  546. * @gfp_mask: allocation priority
  547. *
  548. * Make a copy of both an &sk_buff and part of its data, located
  549. * in header. Fragmented data remain shared. This is used when
  550. * the caller wishes to modify only header of &sk_buff and needs
  551. * private copy of the header to alter. Returns %NULL on failure
  552. * or the pointer to the buffer on success.
  553. * The returned buffer has a reference count of 1.
  554. */
  555. struct sk_buff *pskb_copy(struct sk_buff *skb, gfp_t gfp_mask)
  556. {
  557. /*
  558. * Allocate the copy buffer
  559. */
  560. struct sk_buff *n;
  561. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  562. n = alloc_skb(skb->end, gfp_mask);
  563. #else
  564. n = alloc_skb(skb->end - skb->head, gfp_mask);
  565. #endif
  566. if (!n)
  567. goto out;
  568. /* Set the data pointer */
  569. skb_reserve(n, skb->data - skb->head);
  570. /* Set the tail pointer and length */
  571. skb_put(n, skb_headlen(skb));
  572. /* Copy the bytes */
  573. skb_copy_from_linear_data(skb, n->data, n->len);
  574. n->truesize += skb->data_len;
  575. n->data_len = skb->data_len;
  576. n->len = skb->len;
  577. if (skb_shinfo(skb)->nr_frags) {
  578. int i;
  579. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  580. skb_shinfo(n)->frags[i] = skb_shinfo(skb)->frags[i];
  581. get_page(skb_shinfo(n)->frags[i].page);
  582. }
  583. skb_shinfo(n)->nr_frags = i;
  584. }
  585. if (skb_shinfo(skb)->frag_list) {
  586. skb_shinfo(n)->frag_list = skb_shinfo(skb)->frag_list;
  587. skb_clone_fraglist(n);
  588. }
  589. copy_skb_header(n, skb);
  590. out:
  591. return n;
  592. }
  593. /**
  594. * pskb_expand_head - reallocate header of &sk_buff
  595. * @skb: buffer to reallocate
  596. * @nhead: room to add at head
  597. * @ntail: room to add at tail
  598. * @gfp_mask: allocation priority
  599. *
  600. * Expands (or creates identical copy, if &nhead and &ntail are zero)
  601. * header of skb. &sk_buff itself is not changed. &sk_buff MUST have
  602. * reference count of 1. Returns zero in the case of success or error,
  603. * if expansion failed. In the last case, &sk_buff is not changed.
  604. *
  605. * All the pointers pointing into skb header may change and must be
  606. * reloaded after call to this function.
  607. */
  608. int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
  609. gfp_t gfp_mask)
  610. {
  611. int i;
  612. u8 *data;
  613. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  614. int size = nhead + skb->end + ntail;
  615. #else
  616. int size = nhead + (skb->end - skb->head) + ntail;
  617. #endif
  618. long off;
  619. if (skb_shared(skb))
  620. BUG();
  621. size = SKB_DATA_ALIGN(size);
  622. data = kmalloc(size + sizeof(struct skb_shared_info), gfp_mask);
  623. if (!data)
  624. goto nodata;
  625. /* Copy only real data... and, alas, header. This should be
  626. * optimized for the cases when header is void. */
  627. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  628. memcpy(data + nhead, skb->head, skb->tail);
  629. #else
  630. memcpy(data + nhead, skb->head, skb->tail - skb->head);
  631. #endif
  632. memcpy(data + size, skb_end_pointer(skb),
  633. sizeof(struct skb_shared_info));
  634. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  635. get_page(skb_shinfo(skb)->frags[i].page);
  636. if (skb_shinfo(skb)->frag_list)
  637. skb_clone_fraglist(skb);
  638. skb_release_data(skb);
  639. off = (data + nhead) - skb->head;
  640. skb->head = data;
  641. skb->data += off;
  642. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  643. skb->end = size;
  644. off = nhead;
  645. #else
  646. skb->end = skb->head + size;
  647. #endif
  648. /* {transport,network,mac}_header and tail are relative to skb->head */
  649. skb->tail += off;
  650. skb->transport_header += off;
  651. skb->network_header += off;
  652. skb->mac_header += off;
  653. skb->csum_start += nhead;
  654. skb->cloned = 0;
  655. skb->hdr_len = 0;
  656. skb->nohdr = 0;
  657. atomic_set(&skb_shinfo(skb)->dataref, 1);
  658. return 0;
  659. nodata:
  660. return -ENOMEM;
  661. }
  662. /* Make private copy of skb with writable head and some headroom */
  663. struct sk_buff *skb_realloc_headroom(struct sk_buff *skb, unsigned int headroom)
  664. {
  665. struct sk_buff *skb2;
  666. int delta = headroom - skb_headroom(skb);
  667. if (delta <= 0)
  668. skb2 = pskb_copy(skb, GFP_ATOMIC);
  669. else {
  670. skb2 = skb_clone(skb, GFP_ATOMIC);
  671. if (skb2 && pskb_expand_head(skb2, SKB_DATA_ALIGN(delta), 0,
  672. GFP_ATOMIC)) {
  673. kfree_skb(skb2);
  674. skb2 = NULL;
  675. }
  676. }
  677. return skb2;
  678. }
  679. /**
  680. * skb_copy_expand - copy and expand sk_buff
  681. * @skb: buffer to copy
  682. * @newheadroom: new free bytes at head
  683. * @newtailroom: new free bytes at tail
  684. * @gfp_mask: allocation priority
  685. *
  686. * Make a copy of both an &sk_buff and its data and while doing so
  687. * allocate additional space.
  688. *
  689. * This is used when the caller wishes to modify the data and needs a
  690. * private copy of the data to alter as well as more space for new fields.
  691. * Returns %NULL on failure or the pointer to the buffer
  692. * on success. The returned buffer has a reference count of 1.
  693. *
  694. * You must pass %GFP_ATOMIC as the allocation priority if this function
  695. * is called from an interrupt.
  696. */
  697. struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
  698. int newheadroom, int newtailroom,
  699. gfp_t gfp_mask)
  700. {
  701. /*
  702. * Allocate the copy buffer
  703. */
  704. struct sk_buff *n = alloc_skb(newheadroom + skb->len + newtailroom,
  705. gfp_mask);
  706. int oldheadroom = skb_headroom(skb);
  707. int head_copy_len, head_copy_off;
  708. int off;
  709. if (!n)
  710. return NULL;
  711. skb_reserve(n, newheadroom);
  712. /* Set the tail pointer and length */
  713. skb_put(n, skb->len);
  714. head_copy_len = oldheadroom;
  715. head_copy_off = 0;
  716. if (newheadroom <= head_copy_len)
  717. head_copy_len = newheadroom;
  718. else
  719. head_copy_off = newheadroom - head_copy_len;
  720. /* Copy the linear header and data. */
  721. if (skb_copy_bits(skb, -head_copy_len, n->head + head_copy_off,
  722. skb->len + head_copy_len))
  723. BUG();
  724. copy_skb_header(n, skb);
  725. off = newheadroom - oldheadroom;
  726. n->csum_start += off;
  727. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  728. n->transport_header += off;
  729. n->network_header += off;
  730. n->mac_header += off;
  731. #endif
  732. return n;
  733. }
  734. /**
  735. * skb_pad - zero pad the tail of an skb
  736. * @skb: buffer to pad
  737. * @pad: space to pad
  738. *
  739. * Ensure that a buffer is followed by a padding area that is zero
  740. * filled. Used by network drivers which may DMA or transfer data
  741. * beyond the buffer end onto the wire.
  742. *
  743. * May return error in out of memory cases. The skb is freed on error.
  744. */
  745. int skb_pad(struct sk_buff *skb, int pad)
  746. {
  747. int err;
  748. int ntail;
  749. /* If the skbuff is non linear tailroom is always zero.. */
  750. if (!skb_cloned(skb) && skb_tailroom(skb) >= pad) {
  751. memset(skb->data+skb->len, 0, pad);
  752. return 0;
  753. }
  754. ntail = skb->data_len + pad - (skb->end - skb->tail);
  755. if (likely(skb_cloned(skb) || ntail > 0)) {
  756. err = pskb_expand_head(skb, 0, ntail, GFP_ATOMIC);
  757. if (unlikely(err))
  758. goto free_skb;
  759. }
  760. /* FIXME: The use of this function with non-linear skb's really needs
  761. * to be audited.
  762. */
  763. err = skb_linearize(skb);
  764. if (unlikely(err))
  765. goto free_skb;
  766. memset(skb->data + skb->len, 0, pad);
  767. return 0;
  768. free_skb:
  769. kfree_skb(skb);
  770. return err;
  771. }
  772. /**
  773. * skb_put - add data to a buffer
  774. * @skb: buffer to use
  775. * @len: amount of data to add
  776. *
  777. * This function extends the used data area of the buffer. If this would
  778. * exceed the total buffer size the kernel will panic. A pointer to the
  779. * first byte of the extra data is returned.
  780. */
  781. unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
  782. {
  783. unsigned char *tmp = skb_tail_pointer(skb);
  784. SKB_LINEAR_ASSERT(skb);
  785. skb->tail += len;
  786. skb->len += len;
  787. if (unlikely(skb->tail > skb->end))
  788. skb_over_panic(skb, len, __builtin_return_address(0));
  789. return tmp;
  790. }
  791. EXPORT_SYMBOL(skb_put);
  792. /**
  793. * skb_push - add data to the start of a buffer
  794. * @skb: buffer to use
  795. * @len: amount of data to add
  796. *
  797. * This function extends the used data area of the buffer at the buffer
  798. * start. If this would exceed the total buffer headroom the kernel will
  799. * panic. A pointer to the first byte of the extra data is returned.
  800. */
  801. unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
  802. {
  803. skb->data -= len;
  804. skb->len += len;
  805. if (unlikely(skb->data<skb->head))
  806. skb_under_panic(skb, len, __builtin_return_address(0));
  807. return skb->data;
  808. }
  809. EXPORT_SYMBOL(skb_push);
  810. /**
  811. * skb_pull - remove data from the start of a buffer
  812. * @skb: buffer to use
  813. * @len: amount of data to remove
  814. *
  815. * This function removes data from the start of a buffer, returning
  816. * the memory to the headroom. A pointer to the next data in the buffer
  817. * is returned. Once the data has been pulled future pushes will overwrite
  818. * the old data.
  819. */
  820. unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
  821. {
  822. return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
  823. }
  824. EXPORT_SYMBOL(skb_pull);
  825. /**
  826. * skb_trim - remove end from a buffer
  827. * @skb: buffer to alter
  828. * @len: new length
  829. *
  830. * Cut the length of a buffer down by removing data from the tail. If
  831. * the buffer is already under the length specified it is not modified.
  832. * The skb must be linear.
  833. */
  834. void skb_trim(struct sk_buff *skb, unsigned int len)
  835. {
  836. if (skb->len > len)
  837. __skb_trim(skb, len);
  838. }
  839. EXPORT_SYMBOL(skb_trim);
  840. /* Trims skb to length len. It can change skb pointers.
  841. */
  842. int ___pskb_trim(struct sk_buff *skb, unsigned int len)
  843. {
  844. struct sk_buff **fragp;
  845. struct sk_buff *frag;
  846. int offset = skb_headlen(skb);
  847. int nfrags = skb_shinfo(skb)->nr_frags;
  848. int i;
  849. int err;
  850. if (skb_cloned(skb) &&
  851. unlikely((err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))))
  852. return err;
  853. i = 0;
  854. if (offset >= len)
  855. goto drop_pages;
  856. for (; i < nfrags; i++) {
  857. int end = offset + skb_shinfo(skb)->frags[i].size;
  858. if (end < len) {
  859. offset = end;
  860. continue;
  861. }
  862. skb_shinfo(skb)->frags[i++].size = len - offset;
  863. drop_pages:
  864. skb_shinfo(skb)->nr_frags = i;
  865. for (; i < nfrags; i++)
  866. put_page(skb_shinfo(skb)->frags[i].page);
  867. if (skb_shinfo(skb)->frag_list)
  868. skb_drop_fraglist(skb);
  869. goto done;
  870. }
  871. for (fragp = &skb_shinfo(skb)->frag_list; (frag = *fragp);
  872. fragp = &frag->next) {
  873. int end = offset + frag->len;
  874. if (skb_shared(frag)) {
  875. struct sk_buff *nfrag;
  876. nfrag = skb_clone(frag, GFP_ATOMIC);
  877. if (unlikely(!nfrag))
  878. return -ENOMEM;
  879. nfrag->next = frag->next;
  880. kfree_skb(frag);
  881. frag = nfrag;
  882. *fragp = frag;
  883. }
  884. if (end < len) {
  885. offset = end;
  886. continue;
  887. }
  888. if (end > len &&
  889. unlikely((err = pskb_trim(frag, len - offset))))
  890. return err;
  891. if (frag->next)
  892. skb_drop_list(&frag->next);
  893. break;
  894. }
  895. done:
  896. if (len > skb_headlen(skb)) {
  897. skb->data_len -= skb->len - len;
  898. skb->len = len;
  899. } else {
  900. skb->len = len;
  901. skb->data_len = 0;
  902. skb_set_tail_pointer(skb, len);
  903. }
  904. return 0;
  905. }
  906. /**
  907. * __pskb_pull_tail - advance tail of skb header
  908. * @skb: buffer to reallocate
  909. * @delta: number of bytes to advance tail
  910. *
  911. * The function makes a sense only on a fragmented &sk_buff,
  912. * it expands header moving its tail forward and copying necessary
  913. * data from fragmented part.
  914. *
  915. * &sk_buff MUST have reference count of 1.
  916. *
  917. * Returns %NULL (and &sk_buff does not change) if pull failed
  918. * or value of new tail of skb in the case of success.
  919. *
  920. * All the pointers pointing into skb header may change and must be
  921. * reloaded after call to this function.
  922. */
  923. /* Moves tail of skb head forward, copying data from fragmented part,
  924. * when it is necessary.
  925. * 1. It may fail due to malloc failure.
  926. * 2. It may change skb pointers.
  927. *
  928. * It is pretty complicated. Luckily, it is called only in exceptional cases.
  929. */
  930. unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta)
  931. {
  932. /* If skb has not enough free space at tail, get new one
  933. * plus 128 bytes for future expansions. If we have enough
  934. * room at tail, reallocate without expansion only if skb is cloned.
  935. */
  936. int i, k, eat = (skb->tail + delta) - skb->end;
  937. if (eat > 0 || skb_cloned(skb)) {
  938. if (pskb_expand_head(skb, 0, eat > 0 ? eat + 128 : 0,
  939. GFP_ATOMIC))
  940. return NULL;
  941. }
  942. if (skb_copy_bits(skb, skb_headlen(skb), skb_tail_pointer(skb), delta))
  943. BUG();
  944. /* Optimization: no fragments, no reasons to preestimate
  945. * size of pulled pages. Superb.
  946. */
  947. if (!skb_shinfo(skb)->frag_list)
  948. goto pull_pages;
  949. /* Estimate size of pulled pages. */
  950. eat = delta;
  951. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  952. if (skb_shinfo(skb)->frags[i].size >= eat)
  953. goto pull_pages;
  954. eat -= skb_shinfo(skb)->frags[i].size;
  955. }
  956. /* If we need update frag list, we are in troubles.
  957. * Certainly, it possible to add an offset to skb data,
  958. * but taking into account that pulling is expected to
  959. * be very rare operation, it is worth to fight against
  960. * further bloating skb head and crucify ourselves here instead.
  961. * Pure masohism, indeed. 8)8)
  962. */
  963. if (eat) {
  964. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  965. struct sk_buff *clone = NULL;
  966. struct sk_buff *insp = NULL;
  967. do {
  968. BUG_ON(!list);
  969. if (list->len <= eat) {
  970. /* Eaten as whole. */
  971. eat -= list->len;
  972. list = list->next;
  973. insp = list;
  974. } else {
  975. /* Eaten partially. */
  976. if (skb_shared(list)) {
  977. /* Sucks! We need to fork list. :-( */
  978. clone = skb_clone(list, GFP_ATOMIC);
  979. if (!clone)
  980. return NULL;
  981. insp = list->next;
  982. list = clone;
  983. } else {
  984. /* This may be pulled without
  985. * problems. */
  986. insp = list;
  987. }
  988. if (!pskb_pull(list, eat)) {
  989. if (clone)
  990. kfree_skb(clone);
  991. return NULL;
  992. }
  993. break;
  994. }
  995. } while (eat);
  996. /* Free pulled out fragments. */
  997. while ((list = skb_shinfo(skb)->frag_list) != insp) {
  998. skb_shinfo(skb)->frag_list = list->next;
  999. kfree_skb(list);
  1000. }
  1001. /* And insert new clone at head. */
  1002. if (clone) {
  1003. clone->next = list;
  1004. skb_shinfo(skb)->frag_list = clone;
  1005. }
  1006. }
  1007. /* Success! Now we may commit changes to skb data. */
  1008. pull_pages:
  1009. eat = delta;
  1010. k = 0;
  1011. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1012. if (skb_shinfo(skb)->frags[i].size <= eat) {
  1013. put_page(skb_shinfo(skb)->frags[i].page);
  1014. eat -= skb_shinfo(skb)->frags[i].size;
  1015. } else {
  1016. skb_shinfo(skb)->frags[k] = skb_shinfo(skb)->frags[i];
  1017. if (eat) {
  1018. skb_shinfo(skb)->frags[k].page_offset += eat;
  1019. skb_shinfo(skb)->frags[k].size -= eat;
  1020. eat = 0;
  1021. }
  1022. k++;
  1023. }
  1024. }
  1025. skb_shinfo(skb)->nr_frags = k;
  1026. skb->tail += delta;
  1027. skb->data_len -= delta;
  1028. return skb_tail_pointer(skb);
  1029. }
  1030. /* Copy some data bits from skb to kernel buffer. */
  1031. int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len)
  1032. {
  1033. int i, copy;
  1034. int start = skb_headlen(skb);
  1035. if (offset > (int)skb->len - len)
  1036. goto fault;
  1037. /* Copy header. */
  1038. if ((copy = start - offset) > 0) {
  1039. if (copy > len)
  1040. copy = len;
  1041. skb_copy_from_linear_data_offset(skb, offset, to, copy);
  1042. if ((len -= copy) == 0)
  1043. return 0;
  1044. offset += copy;
  1045. to += copy;
  1046. }
  1047. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1048. int end;
  1049. BUG_TRAP(start <= offset + len);
  1050. end = start + skb_shinfo(skb)->frags[i].size;
  1051. if ((copy = end - offset) > 0) {
  1052. u8 *vaddr;
  1053. if (copy > len)
  1054. copy = len;
  1055. vaddr = kmap_skb_frag(&skb_shinfo(skb)->frags[i]);
  1056. memcpy(to,
  1057. vaddr + skb_shinfo(skb)->frags[i].page_offset+
  1058. offset - start, copy);
  1059. kunmap_skb_frag(vaddr);
  1060. if ((len -= copy) == 0)
  1061. return 0;
  1062. offset += copy;
  1063. to += copy;
  1064. }
  1065. start = end;
  1066. }
  1067. if (skb_shinfo(skb)->frag_list) {
  1068. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1069. for (; list; list = list->next) {
  1070. int end;
  1071. BUG_TRAP(start <= offset + len);
  1072. end = start + list->len;
  1073. if ((copy = end - offset) > 0) {
  1074. if (copy > len)
  1075. copy = len;
  1076. if (skb_copy_bits(list, offset - start,
  1077. to, copy))
  1078. goto fault;
  1079. if ((len -= copy) == 0)
  1080. return 0;
  1081. offset += copy;
  1082. to += copy;
  1083. }
  1084. start = end;
  1085. }
  1086. }
  1087. if (!len)
  1088. return 0;
  1089. fault:
  1090. return -EFAULT;
  1091. }
  1092. /*
  1093. * Callback from splice_to_pipe(), if we need to release some pages
  1094. * at the end of the spd in case we error'ed out in filling the pipe.
  1095. */
  1096. static void sock_spd_release(struct splice_pipe_desc *spd, unsigned int i)
  1097. {
  1098. struct sk_buff *skb = (struct sk_buff *) spd->partial[i].private;
  1099. kfree_skb(skb);
  1100. }
  1101. /*
  1102. * Fill page/offset/length into spd, if it can hold more pages.
  1103. */
  1104. static inline int spd_fill_page(struct splice_pipe_desc *spd, struct page *page,
  1105. unsigned int len, unsigned int offset,
  1106. struct sk_buff *skb)
  1107. {
  1108. if (unlikely(spd->nr_pages == PIPE_BUFFERS))
  1109. return 1;
  1110. spd->pages[spd->nr_pages] = page;
  1111. spd->partial[spd->nr_pages].len = len;
  1112. spd->partial[spd->nr_pages].offset = offset;
  1113. spd->partial[spd->nr_pages].private = (unsigned long) skb_get(skb);
  1114. spd->nr_pages++;
  1115. return 0;
  1116. }
  1117. /*
  1118. * Map linear and fragment data from the skb to spd. Returns number of
  1119. * pages mapped.
  1120. */
  1121. static int __skb_splice_bits(struct sk_buff *skb, unsigned int *offset,
  1122. unsigned int *total_len,
  1123. struct splice_pipe_desc *spd)
  1124. {
  1125. unsigned int nr_pages = spd->nr_pages;
  1126. unsigned int poff, plen, len, toff, tlen;
  1127. int headlen, seg;
  1128. toff = *offset;
  1129. tlen = *total_len;
  1130. if (!tlen)
  1131. goto err;
  1132. /*
  1133. * if the offset is greater than the linear part, go directly to
  1134. * the fragments.
  1135. */
  1136. headlen = skb_headlen(skb);
  1137. if (toff >= headlen) {
  1138. toff -= headlen;
  1139. goto map_frag;
  1140. }
  1141. /*
  1142. * first map the linear region into the pages/partial map, skipping
  1143. * any potential initial offset.
  1144. */
  1145. len = 0;
  1146. while (len < headlen) {
  1147. void *p = skb->data + len;
  1148. poff = (unsigned long) p & (PAGE_SIZE - 1);
  1149. plen = min_t(unsigned int, headlen - len, PAGE_SIZE - poff);
  1150. len += plen;
  1151. if (toff) {
  1152. if (plen <= toff) {
  1153. toff -= plen;
  1154. continue;
  1155. }
  1156. plen -= toff;
  1157. poff += toff;
  1158. toff = 0;
  1159. }
  1160. plen = min(plen, tlen);
  1161. if (!plen)
  1162. break;
  1163. /*
  1164. * just jump directly to update and return, no point
  1165. * in going over fragments when the output is full.
  1166. */
  1167. if (spd_fill_page(spd, virt_to_page(p), plen, poff, skb))
  1168. goto done;
  1169. tlen -= plen;
  1170. }
  1171. /*
  1172. * then map the fragments
  1173. */
  1174. map_frag:
  1175. for (seg = 0; seg < skb_shinfo(skb)->nr_frags; seg++) {
  1176. const skb_frag_t *f = &skb_shinfo(skb)->frags[seg];
  1177. plen = f->size;
  1178. poff = f->page_offset;
  1179. if (toff) {
  1180. if (plen <= toff) {
  1181. toff -= plen;
  1182. continue;
  1183. }
  1184. plen -= toff;
  1185. poff += toff;
  1186. toff = 0;
  1187. }
  1188. plen = min(plen, tlen);
  1189. if (!plen)
  1190. break;
  1191. if (spd_fill_page(spd, f->page, plen, poff, skb))
  1192. break;
  1193. tlen -= plen;
  1194. }
  1195. done:
  1196. if (spd->nr_pages - nr_pages) {
  1197. *offset = 0;
  1198. *total_len = tlen;
  1199. return 0;
  1200. }
  1201. err:
  1202. return 1;
  1203. }
  1204. /*
  1205. * Map data from the skb to a pipe. Should handle both the linear part,
  1206. * the fragments, and the frag list. It does NOT handle frag lists within
  1207. * the frag list, if such a thing exists. We'd probably need to recurse to
  1208. * handle that cleanly.
  1209. */
  1210. int skb_splice_bits(struct sk_buff *__skb, unsigned int offset,
  1211. struct pipe_inode_info *pipe, unsigned int tlen,
  1212. unsigned int flags)
  1213. {
  1214. struct partial_page partial[PIPE_BUFFERS];
  1215. struct page *pages[PIPE_BUFFERS];
  1216. struct splice_pipe_desc spd = {
  1217. .pages = pages,
  1218. .partial = partial,
  1219. .flags = flags,
  1220. .ops = &sock_pipe_buf_ops,
  1221. .spd_release = sock_spd_release,
  1222. };
  1223. struct sk_buff *skb;
  1224. /*
  1225. * I'd love to avoid the clone here, but tcp_read_sock()
  1226. * ignores reference counts and unconditonally kills the sk_buff
  1227. * on return from the actor.
  1228. */
  1229. skb = skb_clone(__skb, GFP_KERNEL);
  1230. if (unlikely(!skb))
  1231. return -ENOMEM;
  1232. /*
  1233. * __skb_splice_bits() only fails if the output has no room left,
  1234. * so no point in going over the frag_list for the error case.
  1235. */
  1236. if (__skb_splice_bits(skb, &offset, &tlen, &spd))
  1237. goto done;
  1238. else if (!tlen)
  1239. goto done;
  1240. /*
  1241. * now see if we have a frag_list to map
  1242. */
  1243. if (skb_shinfo(skb)->frag_list) {
  1244. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1245. for (; list && tlen; list = list->next) {
  1246. if (__skb_splice_bits(list, &offset, &tlen, &spd))
  1247. break;
  1248. }
  1249. }
  1250. done:
  1251. /*
  1252. * drop our reference to the clone, the pipe consumption will
  1253. * drop the rest.
  1254. */
  1255. kfree_skb(skb);
  1256. if (spd.nr_pages) {
  1257. int ret;
  1258. struct sock *sk = __skb->sk;
  1259. /*
  1260. * Drop the socket lock, otherwise we have reverse
  1261. * locking dependencies between sk_lock and i_mutex
  1262. * here as compared to sendfile(). We enter here
  1263. * with the socket lock held, and splice_to_pipe() will
  1264. * grab the pipe inode lock. For sendfile() emulation,
  1265. * we call into ->sendpage() with the i_mutex lock held
  1266. * and networking will grab the socket lock.
  1267. */
  1268. release_sock(sk);
  1269. ret = splice_to_pipe(pipe, &spd);
  1270. lock_sock(sk);
  1271. return ret;
  1272. }
  1273. return 0;
  1274. }
  1275. /**
  1276. * skb_store_bits - store bits from kernel buffer to skb
  1277. * @skb: destination buffer
  1278. * @offset: offset in destination
  1279. * @from: source buffer
  1280. * @len: number of bytes to copy
  1281. *
  1282. * Copy the specified number of bytes from the source buffer to the
  1283. * destination skb. This function handles all the messy bits of
  1284. * traversing fragment lists and such.
  1285. */
  1286. int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len)
  1287. {
  1288. int i, copy;
  1289. int start = skb_headlen(skb);
  1290. if (offset > (int)skb->len - len)
  1291. goto fault;
  1292. if ((copy = start - offset) > 0) {
  1293. if (copy > len)
  1294. copy = len;
  1295. skb_copy_to_linear_data_offset(skb, offset, from, copy);
  1296. if ((len -= copy) == 0)
  1297. return 0;
  1298. offset += copy;
  1299. from += copy;
  1300. }
  1301. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1302. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1303. int end;
  1304. BUG_TRAP(start <= offset + len);
  1305. end = start + frag->size;
  1306. if ((copy = end - offset) > 0) {
  1307. u8 *vaddr;
  1308. if (copy > len)
  1309. copy = len;
  1310. vaddr = kmap_skb_frag(frag);
  1311. memcpy(vaddr + frag->page_offset + offset - start,
  1312. from, copy);
  1313. kunmap_skb_frag(vaddr);
  1314. if ((len -= copy) == 0)
  1315. return 0;
  1316. offset += copy;
  1317. from += copy;
  1318. }
  1319. start = end;
  1320. }
  1321. if (skb_shinfo(skb)->frag_list) {
  1322. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1323. for (; list; list = list->next) {
  1324. int end;
  1325. BUG_TRAP(start <= offset + len);
  1326. end = start + list->len;
  1327. if ((copy = end - offset) > 0) {
  1328. if (copy > len)
  1329. copy = len;
  1330. if (skb_store_bits(list, offset - start,
  1331. from, copy))
  1332. goto fault;
  1333. if ((len -= copy) == 0)
  1334. return 0;
  1335. offset += copy;
  1336. from += copy;
  1337. }
  1338. start = end;
  1339. }
  1340. }
  1341. if (!len)
  1342. return 0;
  1343. fault:
  1344. return -EFAULT;
  1345. }
  1346. EXPORT_SYMBOL(skb_store_bits);
  1347. /* Checksum skb data. */
  1348. __wsum skb_checksum(const struct sk_buff *skb, int offset,
  1349. int len, __wsum csum)
  1350. {
  1351. int start = skb_headlen(skb);
  1352. int i, copy = start - offset;
  1353. int pos = 0;
  1354. /* Checksum header. */
  1355. if (copy > 0) {
  1356. if (copy > len)
  1357. copy = len;
  1358. csum = csum_partial(skb->data + offset, copy, csum);
  1359. if ((len -= copy) == 0)
  1360. return csum;
  1361. offset += copy;
  1362. pos = copy;
  1363. }
  1364. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1365. int end;
  1366. BUG_TRAP(start <= offset + len);
  1367. end = start + skb_shinfo(skb)->frags[i].size;
  1368. if ((copy = end - offset) > 0) {
  1369. __wsum csum2;
  1370. u8 *vaddr;
  1371. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1372. if (copy > len)
  1373. copy = len;
  1374. vaddr = kmap_skb_frag(frag);
  1375. csum2 = csum_partial(vaddr + frag->page_offset +
  1376. offset - start, copy, 0);
  1377. kunmap_skb_frag(vaddr);
  1378. csum = csum_block_add(csum, csum2, pos);
  1379. if (!(len -= copy))
  1380. return csum;
  1381. offset += copy;
  1382. pos += copy;
  1383. }
  1384. start = end;
  1385. }
  1386. if (skb_shinfo(skb)->frag_list) {
  1387. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1388. for (; list; list = list->next) {
  1389. int end;
  1390. BUG_TRAP(start <= offset + len);
  1391. end = start + list->len;
  1392. if ((copy = end - offset) > 0) {
  1393. __wsum csum2;
  1394. if (copy > len)
  1395. copy = len;
  1396. csum2 = skb_checksum(list, offset - start,
  1397. copy, 0);
  1398. csum = csum_block_add(csum, csum2, pos);
  1399. if ((len -= copy) == 0)
  1400. return csum;
  1401. offset += copy;
  1402. pos += copy;
  1403. }
  1404. start = end;
  1405. }
  1406. }
  1407. BUG_ON(len);
  1408. return csum;
  1409. }
  1410. /* Both of above in one bottle. */
  1411. __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
  1412. u8 *to, int len, __wsum csum)
  1413. {
  1414. int start = skb_headlen(skb);
  1415. int i, copy = start - offset;
  1416. int pos = 0;
  1417. /* Copy header. */
  1418. if (copy > 0) {
  1419. if (copy > len)
  1420. copy = len;
  1421. csum = csum_partial_copy_nocheck(skb->data + offset, to,
  1422. copy, csum);
  1423. if ((len -= copy) == 0)
  1424. return csum;
  1425. offset += copy;
  1426. to += copy;
  1427. pos = copy;
  1428. }
  1429. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1430. int end;
  1431. BUG_TRAP(start <= offset + len);
  1432. end = start + skb_shinfo(skb)->frags[i].size;
  1433. if ((copy = end - offset) > 0) {
  1434. __wsum csum2;
  1435. u8 *vaddr;
  1436. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1437. if (copy > len)
  1438. copy = len;
  1439. vaddr = kmap_skb_frag(frag);
  1440. csum2 = csum_partial_copy_nocheck(vaddr +
  1441. frag->page_offset +
  1442. offset - start, to,
  1443. copy, 0);
  1444. kunmap_skb_frag(vaddr);
  1445. csum = csum_block_add(csum, csum2, pos);
  1446. if (!(len -= copy))
  1447. return csum;
  1448. offset += copy;
  1449. to += copy;
  1450. pos += copy;
  1451. }
  1452. start = end;
  1453. }
  1454. if (skb_shinfo(skb)->frag_list) {
  1455. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1456. for (; list; list = list->next) {
  1457. __wsum csum2;
  1458. int end;
  1459. BUG_TRAP(start <= offset + len);
  1460. end = start + list->len;
  1461. if ((copy = end - offset) > 0) {
  1462. if (copy > len)
  1463. copy = len;
  1464. csum2 = skb_copy_and_csum_bits(list,
  1465. offset - start,
  1466. to, copy, 0);
  1467. csum = csum_block_add(csum, csum2, pos);
  1468. if ((len -= copy) == 0)
  1469. return csum;
  1470. offset += copy;
  1471. to += copy;
  1472. pos += copy;
  1473. }
  1474. start = end;
  1475. }
  1476. }
  1477. BUG_ON(len);
  1478. return csum;
  1479. }
  1480. void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)
  1481. {
  1482. __wsum csum;
  1483. long csstart;
  1484. if (skb->ip_summed == CHECKSUM_PARTIAL)
  1485. csstart = skb->csum_start - skb_headroom(skb);
  1486. else
  1487. csstart = skb_headlen(skb);
  1488. BUG_ON(csstart > skb_headlen(skb));
  1489. skb_copy_from_linear_data(skb, to, csstart);
  1490. csum = 0;
  1491. if (csstart != skb->len)
  1492. csum = skb_copy_and_csum_bits(skb, csstart, to + csstart,
  1493. skb->len - csstart, 0);
  1494. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  1495. long csstuff = csstart + skb->csum_offset;
  1496. *((__sum16 *)(to + csstuff)) = csum_fold(csum);
  1497. }
  1498. }
  1499. /**
  1500. * skb_dequeue - remove from the head of the queue
  1501. * @list: list to dequeue from
  1502. *
  1503. * Remove the head of the list. The list lock is taken so the function
  1504. * may be used safely with other locking list functions. The head item is
  1505. * returned or %NULL if the list is empty.
  1506. */
  1507. struct sk_buff *skb_dequeue(struct sk_buff_head *list)
  1508. {
  1509. unsigned long flags;
  1510. struct sk_buff *result;
  1511. spin_lock_irqsave(&list->lock, flags);
  1512. result = __skb_dequeue(list);
  1513. spin_unlock_irqrestore(&list->lock, flags);
  1514. return result;
  1515. }
  1516. /**
  1517. * skb_dequeue_tail - remove from the tail of the queue
  1518. * @list: list to dequeue from
  1519. *
  1520. * Remove the tail of the list. The list lock is taken so the function
  1521. * may be used safely with other locking list functions. The tail item is
  1522. * returned or %NULL if the list is empty.
  1523. */
  1524. struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list)
  1525. {
  1526. unsigned long flags;
  1527. struct sk_buff *result;
  1528. spin_lock_irqsave(&list->lock, flags);
  1529. result = __skb_dequeue_tail(list);
  1530. spin_unlock_irqrestore(&list->lock, flags);
  1531. return result;
  1532. }
  1533. /**
  1534. * skb_queue_purge - empty a list
  1535. * @list: list to empty
  1536. *
  1537. * Delete all buffers on an &sk_buff list. Each buffer is removed from
  1538. * the list and one reference dropped. This function takes the list
  1539. * lock and is atomic with respect to other list locking functions.
  1540. */
  1541. void skb_queue_purge(struct sk_buff_head *list)
  1542. {
  1543. struct sk_buff *skb;
  1544. while ((skb = skb_dequeue(list)) != NULL)
  1545. kfree_skb(skb);
  1546. }
  1547. /**
  1548. * skb_queue_head - queue a buffer at the list head
  1549. * @list: list to use
  1550. * @newsk: buffer to queue
  1551. *
  1552. * Queue a buffer at the start of the list. This function takes the
  1553. * list lock and can be used safely with other locking &sk_buff functions
  1554. * safely.
  1555. *
  1556. * A buffer cannot be placed on two lists at the same time.
  1557. */
  1558. void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
  1559. {
  1560. unsigned long flags;
  1561. spin_lock_irqsave(&list->lock, flags);
  1562. __skb_queue_head(list, newsk);
  1563. spin_unlock_irqrestore(&list->lock, flags);
  1564. }
  1565. /**
  1566. * skb_queue_tail - queue a buffer at the list tail
  1567. * @list: list to use
  1568. * @newsk: buffer to queue
  1569. *
  1570. * Queue a buffer at the tail of the list. This function takes the
  1571. * list lock and can be used safely with other locking &sk_buff functions
  1572. * safely.
  1573. *
  1574. * A buffer cannot be placed on two lists at the same time.
  1575. */
  1576. void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
  1577. {
  1578. unsigned long flags;
  1579. spin_lock_irqsave(&list->lock, flags);
  1580. __skb_queue_tail(list, newsk);
  1581. spin_unlock_irqrestore(&list->lock, flags);
  1582. }
  1583. /**
  1584. * skb_unlink - remove a buffer from a list
  1585. * @skb: buffer to remove
  1586. * @list: list to use
  1587. *
  1588. * Remove a packet from a list. The list locks are taken and this
  1589. * function is atomic with respect to other list locked calls
  1590. *
  1591. * You must know what list the SKB is on.
  1592. */
  1593. void skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
  1594. {
  1595. unsigned long flags;
  1596. spin_lock_irqsave(&list->lock, flags);
  1597. __skb_unlink(skb, list);
  1598. spin_unlock_irqrestore(&list->lock, flags);
  1599. }
  1600. /**
  1601. * skb_append - append a buffer
  1602. * @old: buffer to insert after
  1603. * @newsk: buffer to insert
  1604. * @list: list to use
  1605. *
  1606. * Place a packet after a given packet in a list. The list locks are taken
  1607. * and this function is atomic with respect to other list locked calls.
  1608. * A buffer cannot be placed on two lists at the same time.
  1609. */
  1610. void skb_append(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list)
  1611. {
  1612. unsigned long flags;
  1613. spin_lock_irqsave(&list->lock, flags);
  1614. __skb_queue_after(list, old, newsk);
  1615. spin_unlock_irqrestore(&list->lock, flags);
  1616. }
  1617. /**
  1618. * skb_insert - insert a buffer
  1619. * @old: buffer to insert before
  1620. * @newsk: buffer to insert
  1621. * @list: list to use
  1622. *
  1623. * Place a packet before a given packet in a list. The list locks are
  1624. * taken and this function is atomic with respect to other list locked
  1625. * calls.
  1626. *
  1627. * A buffer cannot be placed on two lists at the same time.
  1628. */
  1629. void skb_insert(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list)
  1630. {
  1631. unsigned long flags;
  1632. spin_lock_irqsave(&list->lock, flags);
  1633. __skb_insert(newsk, old->prev, old, list);
  1634. spin_unlock_irqrestore(&list->lock, flags);
  1635. }
  1636. static inline void skb_split_inside_header(struct sk_buff *skb,
  1637. struct sk_buff* skb1,
  1638. const u32 len, const int pos)
  1639. {
  1640. int i;
  1641. skb_copy_from_linear_data_offset(skb, len, skb_put(skb1, pos - len),
  1642. pos - len);
  1643. /* And move data appendix as is. */
  1644. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  1645. skb_shinfo(skb1)->frags[i] = skb_shinfo(skb)->frags[i];
  1646. skb_shinfo(skb1)->nr_frags = skb_shinfo(skb)->nr_frags;
  1647. skb_shinfo(skb)->nr_frags = 0;
  1648. skb1->data_len = skb->data_len;
  1649. skb1->len += skb1->data_len;
  1650. skb->data_len = 0;
  1651. skb->len = len;
  1652. skb_set_tail_pointer(skb, len);
  1653. }
  1654. static inline void skb_split_no_header(struct sk_buff *skb,
  1655. struct sk_buff* skb1,
  1656. const u32 len, int pos)
  1657. {
  1658. int i, k = 0;
  1659. const int nfrags = skb_shinfo(skb)->nr_frags;
  1660. skb_shinfo(skb)->nr_frags = 0;
  1661. skb1->len = skb1->data_len = skb->len - len;
  1662. skb->len = len;
  1663. skb->data_len = len - pos;
  1664. for (i = 0; i < nfrags; i++) {
  1665. int size = skb_shinfo(skb)->frags[i].size;
  1666. if (pos + size > len) {
  1667. skb_shinfo(skb1)->frags[k] = skb_shinfo(skb)->frags[i];
  1668. if (pos < len) {
  1669. /* Split frag.
  1670. * We have two variants in this case:
  1671. * 1. Move all the frag to the second
  1672. * part, if it is possible. F.e.
  1673. * this approach is mandatory for TUX,
  1674. * where splitting is expensive.
  1675. * 2. Split is accurately. We make this.
  1676. */
  1677. get_page(skb_shinfo(skb)->frags[i].page);
  1678. skb_shinfo(skb1)->frags[0].page_offset += len - pos;
  1679. skb_shinfo(skb1)->frags[0].size -= len - pos;
  1680. skb_shinfo(skb)->frags[i].size = len - pos;
  1681. skb_shinfo(skb)->nr_frags++;
  1682. }
  1683. k++;
  1684. } else
  1685. skb_shinfo(skb)->nr_frags++;
  1686. pos += size;
  1687. }
  1688. skb_shinfo(skb1)->nr_frags = k;
  1689. }
  1690. /**
  1691. * skb_split - Split fragmented skb to two parts at length len.
  1692. * @skb: the buffer to split
  1693. * @skb1: the buffer to receive the second part
  1694. * @len: new length for skb
  1695. */
  1696. void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len)
  1697. {
  1698. int pos = skb_headlen(skb);
  1699. if (len < pos) /* Split line is inside header. */
  1700. skb_split_inside_header(skb, skb1, len, pos);
  1701. else /* Second chunk has no header, nothing to copy. */
  1702. skb_split_no_header(skb, skb1, len, pos);
  1703. }
  1704. /**
  1705. * skb_prepare_seq_read - Prepare a sequential read of skb data
  1706. * @skb: the buffer to read
  1707. * @from: lower offset of data to be read
  1708. * @to: upper offset of data to be read
  1709. * @st: state variable
  1710. *
  1711. * Initializes the specified state variable. Must be called before
  1712. * invoking skb_seq_read() for the first time.
  1713. */
  1714. void skb_prepare_seq_read(struct sk_buff *skb, unsigned int from,
  1715. unsigned int to, struct skb_seq_state *st)
  1716. {
  1717. st->lower_offset = from;
  1718. st->upper_offset = to;
  1719. st->root_skb = st->cur_skb = skb;
  1720. st->frag_idx = st->stepped_offset = 0;
  1721. st->frag_data = NULL;
  1722. }
  1723. /**
  1724. * skb_seq_read - Sequentially read skb data
  1725. * @consumed: number of bytes consumed by the caller so far
  1726. * @data: destination pointer for data to be returned
  1727. * @st: state variable
  1728. *
  1729. * Reads a block of skb data at &consumed relative to the
  1730. * lower offset specified to skb_prepare_seq_read(). Assigns
  1731. * the head of the data block to &data and returns the length
  1732. * of the block or 0 if the end of the skb data or the upper
  1733. * offset has been reached.
  1734. *
  1735. * The caller is not required to consume all of the data
  1736. * returned, i.e. &consumed is typically set to the number
  1737. * of bytes already consumed and the next call to
  1738. * skb_seq_read() will return the remaining part of the block.
  1739. *
  1740. * Note 1: The size of each block of data returned can be arbitary,
  1741. * this limitation is the cost for zerocopy seqeuental
  1742. * reads of potentially non linear data.
  1743. *
  1744. * Note 2: Fragment lists within fragments are not implemented
  1745. * at the moment, state->root_skb could be replaced with
  1746. * a stack for this purpose.
  1747. */
  1748. unsigned int skb_seq_read(unsigned int consumed, const u8 **data,
  1749. struct skb_seq_state *st)
  1750. {
  1751. unsigned int block_limit, abs_offset = consumed + st->lower_offset;
  1752. skb_frag_t *frag;
  1753. if (unlikely(abs_offset >= st->upper_offset))
  1754. return 0;
  1755. next_skb:
  1756. block_limit = skb_headlen(st->cur_skb);
  1757. if (abs_offset < block_limit) {
  1758. *data = st->cur_skb->data + abs_offset;
  1759. return block_limit - abs_offset;
  1760. }
  1761. if (st->frag_idx == 0 && !st->frag_data)
  1762. st->stepped_offset += skb_headlen(st->cur_skb);
  1763. while (st->frag_idx < skb_shinfo(st->cur_skb)->nr_frags) {
  1764. frag = &skb_shinfo(st->cur_skb)->frags[st->frag_idx];
  1765. block_limit = frag->size + st->stepped_offset;
  1766. if (abs_offset < block_limit) {
  1767. if (!st->frag_data)
  1768. st->frag_data = kmap_skb_frag(frag);
  1769. *data = (u8 *) st->frag_data + frag->page_offset +
  1770. (abs_offset - st->stepped_offset);
  1771. return block_limit - abs_offset;
  1772. }
  1773. if (st->frag_data) {
  1774. kunmap_skb_frag(st->frag_data);
  1775. st->frag_data = NULL;
  1776. }
  1777. st->frag_idx++;
  1778. st->stepped_offset += frag->size;
  1779. }
  1780. if (st->frag_data) {
  1781. kunmap_skb_frag(st->frag_data);
  1782. st->frag_data = NULL;
  1783. }
  1784. if (st->cur_skb->next) {
  1785. st->cur_skb = st->cur_skb->next;
  1786. st->frag_idx = 0;
  1787. goto next_skb;
  1788. } else if (st->root_skb == st->cur_skb &&
  1789. skb_shinfo(st->root_skb)->frag_list) {
  1790. st->cur_skb = skb_shinfo(st->root_skb)->frag_list;
  1791. goto next_skb;
  1792. }
  1793. return 0;
  1794. }
  1795. /**
  1796. * skb_abort_seq_read - Abort a sequential read of skb data
  1797. * @st: state variable
  1798. *
  1799. * Must be called if skb_seq_read() was not called until it
  1800. * returned 0.
  1801. */
  1802. void skb_abort_seq_read(struct skb_seq_state *st)
  1803. {
  1804. if (st->frag_data)
  1805. kunmap_skb_frag(st->frag_data);
  1806. }
  1807. #define TS_SKB_CB(state) ((struct skb_seq_state *) &((state)->cb))
  1808. static unsigned int skb_ts_get_next_block(unsigned int offset, const u8 **text,
  1809. struct ts_config *conf,
  1810. struct ts_state *state)
  1811. {
  1812. return skb_seq_read(offset, text, TS_SKB_CB(state));
  1813. }
  1814. static void skb_ts_finish(struct ts_config *conf, struct ts_state *state)
  1815. {
  1816. skb_abort_seq_read(TS_SKB_CB(state));
  1817. }
  1818. /**
  1819. * skb_find_text - Find a text pattern in skb data
  1820. * @skb: the buffer to look in
  1821. * @from: search offset
  1822. * @to: search limit
  1823. * @config: textsearch configuration
  1824. * @state: uninitialized textsearch state variable
  1825. *
  1826. * Finds a pattern in the skb data according to the specified
  1827. * textsearch configuration. Use textsearch_next() to retrieve
  1828. * subsequent occurrences of the pattern. Returns the offset
  1829. * to the first occurrence or UINT_MAX if no match was found.
  1830. */
  1831. unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
  1832. unsigned int to, struct ts_config *config,
  1833. struct ts_state *state)
  1834. {
  1835. unsigned int ret;
  1836. config->get_next_block = skb_ts_get_next_block;
  1837. config->finish = skb_ts_finish;
  1838. skb_prepare_seq_read(skb, from, to, TS_SKB_CB(state));
  1839. ret = textsearch_find(config, state);
  1840. return (ret <= to - from ? ret : UINT_MAX);
  1841. }
  1842. /**
  1843. * skb_append_datato_frags: - append the user data to a skb
  1844. * @sk: sock structure
  1845. * @skb: skb structure to be appened with user data.
  1846. * @getfrag: call back function to be used for getting the user data
  1847. * @from: pointer to user message iov
  1848. * @length: length of the iov message
  1849. *
  1850. * Description: This procedure append the user data in the fragment part
  1851. * of the skb if any page alloc fails user this procedure returns -ENOMEM
  1852. */
  1853. int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb,
  1854. int (*getfrag)(void *from, char *to, int offset,
  1855. int len, int odd, struct sk_buff *skb),
  1856. void *from, int length)
  1857. {
  1858. int frg_cnt = 0;
  1859. skb_frag_t *frag = NULL;
  1860. struct page *page = NULL;
  1861. int copy, left;
  1862. int offset = 0;
  1863. int ret;
  1864. do {
  1865. /* Return error if we don't have space for new frag */
  1866. frg_cnt = skb_shinfo(skb)->nr_frags;
  1867. if (frg_cnt >= MAX_SKB_FRAGS)
  1868. return -EFAULT;
  1869. /* allocate a new page for next frag */
  1870. page = alloc_pages(sk->sk_allocation, 0);
  1871. /* If alloc_page fails just return failure and caller will
  1872. * free previous allocated pages by doing kfree_skb()
  1873. */
  1874. if (page == NULL)
  1875. return -ENOMEM;
  1876. /* initialize the next frag */
  1877. sk->sk_sndmsg_page = page;
  1878. sk->sk_sndmsg_off = 0;
  1879. skb_fill_page_desc(skb, frg_cnt, page, 0, 0);
  1880. skb->truesize += PAGE_SIZE;
  1881. atomic_add(PAGE_SIZE, &sk->sk_wmem_alloc);
  1882. /* get the new initialized frag */
  1883. frg_cnt = skb_shinfo(skb)->nr_frags;
  1884. frag = &skb_shinfo(skb)->frags[frg_cnt - 1];
  1885. /* copy the user data to page */
  1886. left = PAGE_SIZE - frag->page_offset;
  1887. copy = (length > left)? left : length;
  1888. ret = getfrag(from, (page_address(frag->page) +
  1889. frag->page_offset + frag->size),
  1890. offset, copy, 0, skb);
  1891. if (ret < 0)
  1892. return -EFAULT;
  1893. /* copy was successful so update the size parameters */
  1894. sk->sk_sndmsg_off += copy;
  1895. frag->size += copy;
  1896. skb->len += copy;
  1897. skb->data_len += copy;
  1898. offset += copy;
  1899. length -= copy;
  1900. } while (length > 0);
  1901. return 0;
  1902. }
  1903. /**
  1904. * skb_pull_rcsum - pull skb and update receive checksum
  1905. * @skb: buffer to update
  1906. * @len: length of data pulled
  1907. *
  1908. * This function performs an skb_pull on the packet and updates
  1909. * the CHECKSUM_COMPLETE checksum. It should be used on
  1910. * receive path processing instead of skb_pull unless you know
  1911. * that the checksum difference is zero (e.g., a valid IP header)
  1912. * or you are setting ip_summed to CHECKSUM_NONE.
  1913. */
  1914. unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len)
  1915. {
  1916. BUG_ON(len > skb->len);
  1917. skb->len -= len;
  1918. BUG_ON(skb->len < skb->data_len);
  1919. skb_postpull_rcsum(skb, skb->data, len);
  1920. return skb->data += len;
  1921. }
  1922. EXPORT_SYMBOL_GPL(skb_pull_rcsum);
  1923. /**
  1924. * skb_segment - Perform protocol segmentation on skb.
  1925. * @skb: buffer to segment
  1926. * @features: features for the output path (see dev->features)
  1927. *
  1928. * This function performs segmentation on the given skb. It returns
  1929. * a pointer to the first in a list of new skbs for the segments.
  1930. * In case of error it returns ERR_PTR(err).
  1931. */
  1932. struct sk_buff *skb_segment(struct sk_buff *skb, int features)
  1933. {
  1934. struct sk_buff *segs = NULL;
  1935. struct sk_buff *tail = NULL;
  1936. unsigned int mss = skb_shinfo(skb)->gso_size;
  1937. unsigned int doffset = skb->data - skb_mac_header(skb);
  1938. unsigned int offset = doffset;
  1939. unsigned int headroom;
  1940. unsigned int len;
  1941. int sg = features & NETIF_F_SG;
  1942. int nfrags = skb_shinfo(skb)->nr_frags;
  1943. int err = -ENOMEM;
  1944. int i = 0;
  1945. int pos;
  1946. __skb_push(skb, doffset);
  1947. headroom = skb_headroom(skb);
  1948. pos = skb_headlen(skb);
  1949. do {
  1950. struct sk_buff *nskb;
  1951. skb_frag_t *frag;
  1952. int hsize;
  1953. int k;
  1954. int size;
  1955. len = skb->len - offset;
  1956. if (len > mss)
  1957. len = mss;
  1958. hsize = skb_headlen(skb) - offset;
  1959. if (hsize < 0)
  1960. hsize = 0;
  1961. if (hsize > len || !sg)
  1962. hsize = len;
  1963. nskb = alloc_skb(hsize + doffset + headroom, GFP_ATOMIC);
  1964. if (unlikely(!nskb))
  1965. goto err;
  1966. if (segs)
  1967. tail->next = nskb;
  1968. else
  1969. segs = nskb;
  1970. tail = nskb;
  1971. nskb->dev = skb->dev;
  1972. skb_copy_queue_mapping(nskb, skb);
  1973. nskb->priority = skb->priority;
  1974. nskb->protocol = skb->protocol;
  1975. nskb->dst = dst_clone(skb->dst);
  1976. memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
  1977. nskb->pkt_type = skb->pkt_type;
  1978. nskb->mac_len = skb->mac_len;
  1979. skb_reserve(nskb, headroom);
  1980. skb_reset_mac_header(nskb);
  1981. skb_set_network_header(nskb, skb->mac_len);
  1982. nskb->transport_header = (nskb->network_header +
  1983. skb_network_header_len(skb));
  1984. skb_copy_from_linear_data(skb, skb_put(nskb, doffset),
  1985. doffset);
  1986. if (!sg) {
  1987. nskb->csum = skb_copy_and_csum_bits(skb, offset,
  1988. skb_put(nskb, len),
  1989. len, 0);
  1990. continue;
  1991. }
  1992. frag = skb_shinfo(nskb)->frags;
  1993. k = 0;
  1994. nskb->ip_summed = CHECKSUM_PARTIAL;
  1995. nskb->csum = skb->csum;
  1996. skb_copy_from_linear_data_offset(skb, offset,
  1997. skb_put(nskb, hsize), hsize);
  1998. while (pos < offset + len) {
  1999. BUG_ON(i >= nfrags);
  2000. *frag = skb_shinfo(skb)->frags[i];
  2001. get_page(frag->page);
  2002. size = frag->size;
  2003. if (pos < offset) {
  2004. frag->page_offset += offset - pos;
  2005. frag->size -= offset - pos;
  2006. }
  2007. k++;
  2008. if (pos + size <= offset + len) {
  2009. i++;
  2010. pos += size;
  2011. } else {
  2012. frag->size -= pos + size - (offset + len);
  2013. break;
  2014. }
  2015. frag++;
  2016. }
  2017. skb_shinfo(nskb)->nr_frags = k;
  2018. nskb->data_len = len - hsize;
  2019. nskb->len += nskb->data_len;
  2020. nskb->truesize += nskb->data_len;
  2021. } while ((offset += len) < skb->len);
  2022. return segs;
  2023. err:
  2024. while ((skb = segs)) {
  2025. segs = skb->next;
  2026. kfree_skb(skb);
  2027. }
  2028. return ERR_PTR(err);
  2029. }
  2030. EXPORT_SYMBOL_GPL(skb_segment);
  2031. void __init skb_init(void)
  2032. {
  2033. skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
  2034. sizeof(struct sk_buff),
  2035. 0,
  2036. SLAB_HWCACHE_ALIGN|SLAB_PANIC,
  2037. NULL);
  2038. skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
  2039. (2*sizeof(struct sk_buff)) +
  2040. sizeof(atomic_t),
  2041. 0,
  2042. SLAB_HWCACHE_ALIGN|SLAB_PANIC,
  2043. NULL);
  2044. }
  2045. /**
  2046. * skb_to_sgvec - Fill a scatter-gather list from a socket buffer
  2047. * @skb: Socket buffer containing the buffers to be mapped
  2048. * @sg: The scatter-gather list to map into
  2049. * @offset: The offset into the buffer's contents to start mapping
  2050. * @len: Length of buffer space to be mapped
  2051. *
  2052. * Fill the specified scatter-gather list with mappings/pointers into a
  2053. * region of the buffer space attached to a socket buffer.
  2054. */
  2055. static int
  2056. __skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
  2057. {
  2058. int start = skb_headlen(skb);
  2059. int i, copy = start - offset;
  2060. int elt = 0;
  2061. if (copy > 0) {
  2062. if (copy > len)
  2063. copy = len;
  2064. sg_set_buf(sg, skb->data + offset, copy);
  2065. elt++;
  2066. if ((len -= copy) == 0)
  2067. return elt;
  2068. offset += copy;
  2069. }
  2070. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2071. int end;
  2072. BUG_TRAP(start <= offset + len);
  2073. end = start + skb_shinfo(skb)->frags[i].size;
  2074. if ((copy = end - offset) > 0) {
  2075. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2076. if (copy > len)
  2077. copy = len;
  2078. sg_set_page(&sg[elt], frag->page, copy,
  2079. frag->page_offset+offset-start);
  2080. elt++;
  2081. if (!(len -= copy))
  2082. return elt;
  2083. offset += copy;
  2084. }
  2085. start = end;
  2086. }
  2087. if (skb_shinfo(skb)->frag_list) {
  2088. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  2089. for (; list; list = list->next) {
  2090. int end;
  2091. BUG_TRAP(start <= offset + len);
  2092. end = start + list->len;
  2093. if ((copy = end - offset) > 0) {
  2094. if (copy > len)
  2095. copy = len;
  2096. elt += __skb_to_sgvec(list, sg+elt, offset - start,
  2097. copy);
  2098. if ((len -= copy) == 0)
  2099. return elt;
  2100. offset += copy;
  2101. }
  2102. start = end;
  2103. }
  2104. }
  2105. BUG_ON(len);
  2106. return elt;
  2107. }
  2108. int skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
  2109. {
  2110. int nsg = __skb_to_sgvec(skb, sg, offset, len);
  2111. sg_mark_end(&sg[nsg - 1]);
  2112. return nsg;
  2113. }
  2114. /**
  2115. * skb_cow_data - Check that a socket buffer's data buffers are writable
  2116. * @skb: The socket buffer to check.
  2117. * @tailbits: Amount of trailing space to be added
  2118. * @trailer: Returned pointer to the skb where the @tailbits space begins
  2119. *
  2120. * Make sure that the data buffers attached to a socket buffer are
  2121. * writable. If they are not, private copies are made of the data buffers
  2122. * and the socket buffer is set to use these instead.
  2123. *
  2124. * If @tailbits is given, make sure that there is space to write @tailbits
  2125. * bytes of data beyond current end of socket buffer. @trailer will be
  2126. * set to point to the skb in which this space begins.
  2127. *
  2128. * The number of scatterlist elements required to completely map the
  2129. * COW'd and extended socket buffer will be returned.
  2130. */
  2131. int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer)
  2132. {
  2133. int copyflag;
  2134. int elt;
  2135. struct sk_buff *skb1, **skb_p;
  2136. /* If skb is cloned or its head is paged, reallocate
  2137. * head pulling out all the pages (pages are considered not writable
  2138. * at the moment even if they are anonymous).
  2139. */
  2140. if ((skb_cloned(skb) || skb_shinfo(skb)->nr_frags) &&
  2141. __pskb_pull_tail(skb, skb_pagelen(skb)-skb_headlen(skb)) == NULL)
  2142. return -ENOMEM;
  2143. /* Easy case. Most of packets will go this way. */
  2144. if (!skb_shinfo(skb)->frag_list) {
  2145. /* A little of trouble, not enough of space for trailer.
  2146. * This should not happen, when stack is tuned to generate
  2147. * good frames. OK, on miss we reallocate and reserve even more
  2148. * space, 128 bytes is fair. */
  2149. if (skb_tailroom(skb) < tailbits &&
  2150. pskb_expand_head(skb, 0, tailbits-skb_tailroom(skb)+128, GFP_ATOMIC))
  2151. return -ENOMEM;
  2152. /* Voila! */
  2153. *trailer = skb;
  2154. return 1;
  2155. }
  2156. /* Misery. We are in troubles, going to mincer fragments... */
  2157. elt = 1;
  2158. skb_p = &skb_shinfo(skb)->frag_list;
  2159. copyflag = 0;
  2160. while ((skb1 = *skb_p) != NULL) {
  2161. int ntail = 0;
  2162. /* The fragment is partially pulled by someone,
  2163. * this can happen on input. Copy it and everything
  2164. * after it. */
  2165. if (skb_shared(skb1))
  2166. copyflag = 1;
  2167. /* If the skb is the last, worry about trailer. */
  2168. if (skb1->next == NULL && tailbits) {
  2169. if (skb_shinfo(skb1)->nr_frags ||
  2170. skb_shinfo(skb1)->frag_list ||
  2171. skb_tailroom(skb1) < tailbits)
  2172. ntail = tailbits + 128;
  2173. }
  2174. if (copyflag ||
  2175. skb_cloned(skb1) ||
  2176. ntail ||
  2177. skb_shinfo(skb1)->nr_frags ||
  2178. skb_shinfo(skb1)->frag_list) {
  2179. struct sk_buff *skb2;
  2180. /* Fuck, we are miserable poor guys... */
  2181. if (ntail == 0)
  2182. skb2 = skb_copy(skb1, GFP_ATOMIC);
  2183. else
  2184. skb2 = skb_copy_expand(skb1,
  2185. skb_headroom(skb1),
  2186. ntail,
  2187. GFP_ATOMIC);
  2188. if (unlikely(skb2 == NULL))
  2189. return -ENOMEM;
  2190. if (skb1->sk)
  2191. skb_set_owner_w(skb2, skb1->sk);
  2192. /* Looking around. Are we still alive?
  2193. * OK, link new skb, drop old one */
  2194. skb2->next = skb1->next;
  2195. *skb_p = skb2;
  2196. kfree_skb(skb1);
  2197. skb1 = skb2;
  2198. }
  2199. elt++;
  2200. *trailer = skb1;
  2201. skb_p = &skb1->next;
  2202. }
  2203. return elt;
  2204. }
  2205. /**
  2206. * skb_partial_csum_set - set up and verify partial csum values for packet
  2207. * @skb: the skb to set
  2208. * @start: the number of bytes after skb->data to start checksumming.
  2209. * @off: the offset from start to place the checksum.
  2210. *
  2211. * For untrusted partially-checksummed packets, we need to make sure the values
  2212. * for skb->csum_start and skb->csum_offset are valid so we don't oops.
  2213. *
  2214. * This function checks and sets those values and skb->ip_summed: if this
  2215. * returns false you should drop the packet.
  2216. */
  2217. bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off)
  2218. {
  2219. if (unlikely(start > skb->len - 2) ||
  2220. unlikely((int)start + off > skb->len - 2)) {
  2221. if (net_ratelimit())
  2222. printk(KERN_WARNING
  2223. "bad partial csum: csum=%u/%u len=%u\n",
  2224. start, off, skb->len);
  2225. return false;
  2226. }
  2227. skb->ip_summed = CHECKSUM_PARTIAL;
  2228. skb->csum_start = skb_headroom(skb) + start;
  2229. skb->csum_offset = off;
  2230. return true;
  2231. }
  2232. EXPORT_SYMBOL(___pskb_trim);
  2233. EXPORT_SYMBOL(__kfree_skb);
  2234. EXPORT_SYMBOL(kfree_skb);
  2235. EXPORT_SYMBOL(__pskb_pull_tail);
  2236. EXPORT_SYMBOL(__alloc_skb);
  2237. EXPORT_SYMBOL(__netdev_alloc_skb);
  2238. EXPORT_SYMBOL(pskb_copy);
  2239. EXPORT_SYMBOL(pskb_expand_head);
  2240. EXPORT_SYMBOL(skb_checksum);
  2241. EXPORT_SYMBOL(skb_clone);
  2242. EXPORT_SYMBOL(skb_copy);
  2243. EXPORT_SYMBOL(skb_copy_and_csum_bits);
  2244. EXPORT_SYMBOL(skb_copy_and_csum_dev);
  2245. EXPORT_SYMBOL(skb_copy_bits);
  2246. EXPORT_SYMBOL(skb_copy_expand);
  2247. EXPORT_SYMBOL(skb_over_panic);
  2248. EXPORT_SYMBOL(skb_pad);
  2249. EXPORT_SYMBOL(skb_realloc_headroom);
  2250. EXPORT_SYMBOL(skb_under_panic);
  2251. EXPORT_SYMBOL(skb_dequeue);
  2252. EXPORT_SYMBOL(skb_dequeue_tail);
  2253. EXPORT_SYMBOL(skb_insert);
  2254. EXPORT_SYMBOL(skb_queue_purge);
  2255. EXPORT_SYMBOL(skb_queue_head);
  2256. EXPORT_SYMBOL(skb_queue_tail);
  2257. EXPORT_SYMBOL(skb_unlink);
  2258. EXPORT_SYMBOL(skb_append);
  2259. EXPORT_SYMBOL(skb_split);
  2260. EXPORT_SYMBOL(skb_prepare_seq_read);
  2261. EXPORT_SYMBOL(skb_seq_read);
  2262. EXPORT_SYMBOL(skb_abort_seq_read);
  2263. EXPORT_SYMBOL(skb_find_text);
  2264. EXPORT_SYMBOL(skb_append_datato_frags);
  2265. EXPORT_SYMBOL_GPL(skb_to_sgvec);
  2266. EXPORT_SYMBOL_GPL(skb_cow_data);
  2267. EXPORT_SYMBOL_GPL(skb_partial_csum_set);