skbuff.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604
  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. new->vlan_tci = old->vlan_tci;
  413. skb_copy_secmark(new, old);
  414. }
  415. static struct sk_buff *__skb_clone(struct sk_buff *n, struct sk_buff *skb)
  416. {
  417. #define C(x) n->x = skb->x
  418. n->next = n->prev = NULL;
  419. n->sk = NULL;
  420. __copy_skb_header(n, skb);
  421. C(len);
  422. C(data_len);
  423. C(mac_len);
  424. n->hdr_len = skb->nohdr ? skb_headroom(skb) : skb->hdr_len;
  425. n->cloned = 1;
  426. n->nohdr = 0;
  427. n->destructor = NULL;
  428. C(iif);
  429. C(tail);
  430. C(end);
  431. C(head);
  432. C(data);
  433. C(truesize);
  434. #if defined(CONFIG_MAC80211) || defined(CONFIG_MAC80211_MODULE)
  435. C(do_not_encrypt);
  436. #endif
  437. atomic_set(&n->users, 1);
  438. atomic_inc(&(skb_shinfo(skb)->dataref));
  439. skb->cloned = 1;
  440. return n;
  441. #undef C
  442. }
  443. /**
  444. * skb_morph - morph one skb into another
  445. * @dst: the skb to receive the contents
  446. * @src: the skb to supply the contents
  447. *
  448. * This is identical to skb_clone except that the target skb is
  449. * supplied by the user.
  450. *
  451. * The target skb is returned upon exit.
  452. */
  453. struct sk_buff *skb_morph(struct sk_buff *dst, struct sk_buff *src)
  454. {
  455. skb_release_all(dst);
  456. return __skb_clone(dst, src);
  457. }
  458. EXPORT_SYMBOL_GPL(skb_morph);
  459. /**
  460. * skb_clone - duplicate an sk_buff
  461. * @skb: buffer to clone
  462. * @gfp_mask: allocation priority
  463. *
  464. * Duplicate an &sk_buff. The new one is not owned by a socket. Both
  465. * copies share the same packet data but not structure. The new
  466. * buffer has a reference count of 1. If the allocation fails the
  467. * function returns %NULL otherwise the new buffer is returned.
  468. *
  469. * If this function is called from an interrupt gfp_mask() must be
  470. * %GFP_ATOMIC.
  471. */
  472. struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
  473. {
  474. struct sk_buff *n;
  475. n = skb + 1;
  476. if (skb->fclone == SKB_FCLONE_ORIG &&
  477. n->fclone == SKB_FCLONE_UNAVAILABLE) {
  478. atomic_t *fclone_ref = (atomic_t *) (n + 1);
  479. n->fclone = SKB_FCLONE_CLONE;
  480. atomic_inc(fclone_ref);
  481. } else {
  482. n = kmem_cache_alloc(skbuff_head_cache, gfp_mask);
  483. if (!n)
  484. return NULL;
  485. n->fclone = SKB_FCLONE_UNAVAILABLE;
  486. }
  487. return __skb_clone(n, skb);
  488. }
  489. static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
  490. {
  491. #ifndef NET_SKBUFF_DATA_USES_OFFSET
  492. /*
  493. * Shift between the two data areas in bytes
  494. */
  495. unsigned long offset = new->data - old->data;
  496. #endif
  497. __copy_skb_header(new, old);
  498. #ifndef NET_SKBUFF_DATA_USES_OFFSET
  499. /* {transport,network,mac}_header are relative to skb->head */
  500. new->transport_header += offset;
  501. new->network_header += offset;
  502. new->mac_header += offset;
  503. #endif
  504. skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
  505. skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
  506. skb_shinfo(new)->gso_type = skb_shinfo(old)->gso_type;
  507. }
  508. /**
  509. * skb_copy - create private copy of an sk_buff
  510. * @skb: buffer to copy
  511. * @gfp_mask: allocation priority
  512. *
  513. * Make a copy of both an &sk_buff and its data. This is used when the
  514. * caller wishes to modify the data and needs a private copy of the
  515. * data to alter. Returns %NULL on failure or the pointer to the buffer
  516. * on success. The returned buffer has a reference count of 1.
  517. *
  518. * As by-product this function converts non-linear &sk_buff to linear
  519. * one, so that &sk_buff becomes completely private and caller is allowed
  520. * to modify all the data of returned buffer. This means that this
  521. * function is not recommended for use in circumstances when only
  522. * header is going to be modified. Use pskb_copy() instead.
  523. */
  524. struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)
  525. {
  526. int headerlen = skb->data - skb->head;
  527. /*
  528. * Allocate the copy buffer
  529. */
  530. struct sk_buff *n;
  531. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  532. n = alloc_skb(skb->end + skb->data_len, gfp_mask);
  533. #else
  534. n = alloc_skb(skb->end - skb->head + skb->data_len, gfp_mask);
  535. #endif
  536. if (!n)
  537. return NULL;
  538. /* Set the data pointer */
  539. skb_reserve(n, headerlen);
  540. /* Set the tail pointer and length */
  541. skb_put(n, skb->len);
  542. if (skb_copy_bits(skb, -headerlen, n->head, headerlen + skb->len))
  543. BUG();
  544. copy_skb_header(n, skb);
  545. return n;
  546. }
  547. /**
  548. * pskb_copy - create copy of an sk_buff with private head.
  549. * @skb: buffer to copy
  550. * @gfp_mask: allocation priority
  551. *
  552. * Make a copy of both an &sk_buff and part of its data, located
  553. * in header. Fragmented data remain shared. This is used when
  554. * the caller wishes to modify only header of &sk_buff and needs
  555. * private copy of the header to alter. Returns %NULL on failure
  556. * or the pointer to the buffer on success.
  557. * The returned buffer has a reference count of 1.
  558. */
  559. struct sk_buff *pskb_copy(struct sk_buff *skb, gfp_t gfp_mask)
  560. {
  561. /*
  562. * Allocate the copy buffer
  563. */
  564. struct sk_buff *n;
  565. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  566. n = alloc_skb(skb->end, gfp_mask);
  567. #else
  568. n = alloc_skb(skb->end - skb->head, gfp_mask);
  569. #endif
  570. if (!n)
  571. goto out;
  572. /* Set the data pointer */
  573. skb_reserve(n, skb->data - skb->head);
  574. /* Set the tail pointer and length */
  575. skb_put(n, skb_headlen(skb));
  576. /* Copy the bytes */
  577. skb_copy_from_linear_data(skb, n->data, n->len);
  578. n->truesize += skb->data_len;
  579. n->data_len = skb->data_len;
  580. n->len = skb->len;
  581. if (skb_shinfo(skb)->nr_frags) {
  582. int i;
  583. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  584. skb_shinfo(n)->frags[i] = skb_shinfo(skb)->frags[i];
  585. get_page(skb_shinfo(n)->frags[i].page);
  586. }
  587. skb_shinfo(n)->nr_frags = i;
  588. }
  589. if (skb_shinfo(skb)->frag_list) {
  590. skb_shinfo(n)->frag_list = skb_shinfo(skb)->frag_list;
  591. skb_clone_fraglist(n);
  592. }
  593. copy_skb_header(n, skb);
  594. out:
  595. return n;
  596. }
  597. /**
  598. * pskb_expand_head - reallocate header of &sk_buff
  599. * @skb: buffer to reallocate
  600. * @nhead: room to add at head
  601. * @ntail: room to add at tail
  602. * @gfp_mask: allocation priority
  603. *
  604. * Expands (or creates identical copy, if &nhead and &ntail are zero)
  605. * header of skb. &sk_buff itself is not changed. &sk_buff MUST have
  606. * reference count of 1. Returns zero in the case of success or error,
  607. * if expansion failed. In the last case, &sk_buff is not changed.
  608. *
  609. * All the pointers pointing into skb header may change and must be
  610. * reloaded after call to this function.
  611. */
  612. int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
  613. gfp_t gfp_mask)
  614. {
  615. int i;
  616. u8 *data;
  617. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  618. int size = nhead + skb->end + ntail;
  619. #else
  620. int size = nhead + (skb->end - skb->head) + ntail;
  621. #endif
  622. long off;
  623. if (skb_shared(skb))
  624. BUG();
  625. size = SKB_DATA_ALIGN(size);
  626. data = kmalloc(size + sizeof(struct skb_shared_info), gfp_mask);
  627. if (!data)
  628. goto nodata;
  629. /* Copy only real data... and, alas, header. This should be
  630. * optimized for the cases when header is void. */
  631. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  632. memcpy(data + nhead, skb->head, skb->tail);
  633. #else
  634. memcpy(data + nhead, skb->head, skb->tail - skb->head);
  635. #endif
  636. memcpy(data + size, skb_end_pointer(skb),
  637. sizeof(struct skb_shared_info));
  638. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  639. get_page(skb_shinfo(skb)->frags[i].page);
  640. if (skb_shinfo(skb)->frag_list)
  641. skb_clone_fraglist(skb);
  642. skb_release_data(skb);
  643. off = (data + nhead) - skb->head;
  644. skb->head = data;
  645. skb->data += off;
  646. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  647. skb->end = size;
  648. off = nhead;
  649. #else
  650. skb->end = skb->head + size;
  651. #endif
  652. /* {transport,network,mac}_header and tail are relative to skb->head */
  653. skb->tail += off;
  654. skb->transport_header += off;
  655. skb->network_header += off;
  656. skb->mac_header += off;
  657. skb->csum_start += nhead;
  658. skb->cloned = 0;
  659. skb->hdr_len = 0;
  660. skb->nohdr = 0;
  661. atomic_set(&skb_shinfo(skb)->dataref, 1);
  662. return 0;
  663. nodata:
  664. return -ENOMEM;
  665. }
  666. /* Make private copy of skb with writable head and some headroom */
  667. struct sk_buff *skb_realloc_headroom(struct sk_buff *skb, unsigned int headroom)
  668. {
  669. struct sk_buff *skb2;
  670. int delta = headroom - skb_headroom(skb);
  671. if (delta <= 0)
  672. skb2 = pskb_copy(skb, GFP_ATOMIC);
  673. else {
  674. skb2 = skb_clone(skb, GFP_ATOMIC);
  675. if (skb2 && pskb_expand_head(skb2, SKB_DATA_ALIGN(delta), 0,
  676. GFP_ATOMIC)) {
  677. kfree_skb(skb2);
  678. skb2 = NULL;
  679. }
  680. }
  681. return skb2;
  682. }
  683. /**
  684. * skb_copy_expand - copy and expand sk_buff
  685. * @skb: buffer to copy
  686. * @newheadroom: new free bytes at head
  687. * @newtailroom: new free bytes at tail
  688. * @gfp_mask: allocation priority
  689. *
  690. * Make a copy of both an &sk_buff and its data and while doing so
  691. * allocate additional space.
  692. *
  693. * This is used when the caller wishes to modify the data and needs a
  694. * private copy of the data to alter as well as more space for new fields.
  695. * Returns %NULL on failure or the pointer to the buffer
  696. * on success. The returned buffer has a reference count of 1.
  697. *
  698. * You must pass %GFP_ATOMIC as the allocation priority if this function
  699. * is called from an interrupt.
  700. */
  701. struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
  702. int newheadroom, int newtailroom,
  703. gfp_t gfp_mask)
  704. {
  705. /*
  706. * Allocate the copy buffer
  707. */
  708. struct sk_buff *n = alloc_skb(newheadroom + skb->len + newtailroom,
  709. gfp_mask);
  710. int oldheadroom = skb_headroom(skb);
  711. int head_copy_len, head_copy_off;
  712. int off;
  713. if (!n)
  714. return NULL;
  715. skb_reserve(n, newheadroom);
  716. /* Set the tail pointer and length */
  717. skb_put(n, skb->len);
  718. head_copy_len = oldheadroom;
  719. head_copy_off = 0;
  720. if (newheadroom <= head_copy_len)
  721. head_copy_len = newheadroom;
  722. else
  723. head_copy_off = newheadroom - head_copy_len;
  724. /* Copy the linear header and data. */
  725. if (skb_copy_bits(skb, -head_copy_len, n->head + head_copy_off,
  726. skb->len + head_copy_len))
  727. BUG();
  728. copy_skb_header(n, skb);
  729. off = newheadroom - oldheadroom;
  730. n->csum_start += off;
  731. #ifdef NET_SKBUFF_DATA_USES_OFFSET
  732. n->transport_header += off;
  733. n->network_header += off;
  734. n->mac_header += off;
  735. #endif
  736. return n;
  737. }
  738. /**
  739. * skb_pad - zero pad the tail of an skb
  740. * @skb: buffer to pad
  741. * @pad: space to pad
  742. *
  743. * Ensure that a buffer is followed by a padding area that is zero
  744. * filled. Used by network drivers which may DMA or transfer data
  745. * beyond the buffer end onto the wire.
  746. *
  747. * May return error in out of memory cases. The skb is freed on error.
  748. */
  749. int skb_pad(struct sk_buff *skb, int pad)
  750. {
  751. int err;
  752. int ntail;
  753. /* If the skbuff is non linear tailroom is always zero.. */
  754. if (!skb_cloned(skb) && skb_tailroom(skb) >= pad) {
  755. memset(skb->data+skb->len, 0, pad);
  756. return 0;
  757. }
  758. ntail = skb->data_len + pad - (skb->end - skb->tail);
  759. if (likely(skb_cloned(skb) || ntail > 0)) {
  760. err = pskb_expand_head(skb, 0, ntail, GFP_ATOMIC);
  761. if (unlikely(err))
  762. goto free_skb;
  763. }
  764. /* FIXME: The use of this function with non-linear skb's really needs
  765. * to be audited.
  766. */
  767. err = skb_linearize(skb);
  768. if (unlikely(err))
  769. goto free_skb;
  770. memset(skb->data + skb->len, 0, pad);
  771. return 0;
  772. free_skb:
  773. kfree_skb(skb);
  774. return err;
  775. }
  776. /**
  777. * skb_put - add data to a buffer
  778. * @skb: buffer to use
  779. * @len: amount of data to add
  780. *
  781. * This function extends the used data area of the buffer. If this would
  782. * exceed the total buffer size the kernel will panic. A pointer to the
  783. * first byte of the extra data is returned.
  784. */
  785. unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
  786. {
  787. unsigned char *tmp = skb_tail_pointer(skb);
  788. SKB_LINEAR_ASSERT(skb);
  789. skb->tail += len;
  790. skb->len += len;
  791. if (unlikely(skb->tail > skb->end))
  792. skb_over_panic(skb, len, __builtin_return_address(0));
  793. return tmp;
  794. }
  795. EXPORT_SYMBOL(skb_put);
  796. /**
  797. * skb_push - add data to the start of a buffer
  798. * @skb: buffer to use
  799. * @len: amount of data to add
  800. *
  801. * This function extends the used data area of the buffer at the buffer
  802. * start. If this would exceed the total buffer headroom the kernel will
  803. * panic. A pointer to the first byte of the extra data is returned.
  804. */
  805. unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
  806. {
  807. skb->data -= len;
  808. skb->len += len;
  809. if (unlikely(skb->data<skb->head))
  810. skb_under_panic(skb, len, __builtin_return_address(0));
  811. return skb->data;
  812. }
  813. EXPORT_SYMBOL(skb_push);
  814. /**
  815. * skb_pull - remove data from the start of a buffer
  816. * @skb: buffer to use
  817. * @len: amount of data to remove
  818. *
  819. * This function removes data from the start of a buffer, returning
  820. * the memory to the headroom. A pointer to the next data in the buffer
  821. * is returned. Once the data has been pulled future pushes will overwrite
  822. * the old data.
  823. */
  824. unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
  825. {
  826. return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
  827. }
  828. EXPORT_SYMBOL(skb_pull);
  829. /**
  830. * skb_trim - remove end from a buffer
  831. * @skb: buffer to alter
  832. * @len: new length
  833. *
  834. * Cut the length of a buffer down by removing data from the tail. If
  835. * the buffer is already under the length specified it is not modified.
  836. * The skb must be linear.
  837. */
  838. void skb_trim(struct sk_buff *skb, unsigned int len)
  839. {
  840. if (skb->len > len)
  841. __skb_trim(skb, len);
  842. }
  843. EXPORT_SYMBOL(skb_trim);
  844. /* Trims skb to length len. It can change skb pointers.
  845. */
  846. int ___pskb_trim(struct sk_buff *skb, unsigned int len)
  847. {
  848. struct sk_buff **fragp;
  849. struct sk_buff *frag;
  850. int offset = skb_headlen(skb);
  851. int nfrags = skb_shinfo(skb)->nr_frags;
  852. int i;
  853. int err;
  854. if (skb_cloned(skb) &&
  855. unlikely((err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))))
  856. return err;
  857. i = 0;
  858. if (offset >= len)
  859. goto drop_pages;
  860. for (; i < nfrags; i++) {
  861. int end = offset + skb_shinfo(skb)->frags[i].size;
  862. if (end < len) {
  863. offset = end;
  864. continue;
  865. }
  866. skb_shinfo(skb)->frags[i++].size = len - offset;
  867. drop_pages:
  868. skb_shinfo(skb)->nr_frags = i;
  869. for (; i < nfrags; i++)
  870. put_page(skb_shinfo(skb)->frags[i].page);
  871. if (skb_shinfo(skb)->frag_list)
  872. skb_drop_fraglist(skb);
  873. goto done;
  874. }
  875. for (fragp = &skb_shinfo(skb)->frag_list; (frag = *fragp);
  876. fragp = &frag->next) {
  877. int end = offset + frag->len;
  878. if (skb_shared(frag)) {
  879. struct sk_buff *nfrag;
  880. nfrag = skb_clone(frag, GFP_ATOMIC);
  881. if (unlikely(!nfrag))
  882. return -ENOMEM;
  883. nfrag->next = frag->next;
  884. kfree_skb(frag);
  885. frag = nfrag;
  886. *fragp = frag;
  887. }
  888. if (end < len) {
  889. offset = end;
  890. continue;
  891. }
  892. if (end > len &&
  893. unlikely((err = pskb_trim(frag, len - offset))))
  894. return err;
  895. if (frag->next)
  896. skb_drop_list(&frag->next);
  897. break;
  898. }
  899. done:
  900. if (len > skb_headlen(skb)) {
  901. skb->data_len -= skb->len - len;
  902. skb->len = len;
  903. } else {
  904. skb->len = len;
  905. skb->data_len = 0;
  906. skb_set_tail_pointer(skb, len);
  907. }
  908. return 0;
  909. }
  910. /**
  911. * __pskb_pull_tail - advance tail of skb header
  912. * @skb: buffer to reallocate
  913. * @delta: number of bytes to advance tail
  914. *
  915. * The function makes a sense only on a fragmented &sk_buff,
  916. * it expands header moving its tail forward and copying necessary
  917. * data from fragmented part.
  918. *
  919. * &sk_buff MUST have reference count of 1.
  920. *
  921. * Returns %NULL (and &sk_buff does not change) if pull failed
  922. * or value of new tail of skb in the case of success.
  923. *
  924. * All the pointers pointing into skb header may change and must be
  925. * reloaded after call to this function.
  926. */
  927. /* Moves tail of skb head forward, copying data from fragmented part,
  928. * when it is necessary.
  929. * 1. It may fail due to malloc failure.
  930. * 2. It may change skb pointers.
  931. *
  932. * It is pretty complicated. Luckily, it is called only in exceptional cases.
  933. */
  934. unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta)
  935. {
  936. /* If skb has not enough free space at tail, get new one
  937. * plus 128 bytes for future expansions. If we have enough
  938. * room at tail, reallocate without expansion only if skb is cloned.
  939. */
  940. int i, k, eat = (skb->tail + delta) - skb->end;
  941. if (eat > 0 || skb_cloned(skb)) {
  942. if (pskb_expand_head(skb, 0, eat > 0 ? eat + 128 : 0,
  943. GFP_ATOMIC))
  944. return NULL;
  945. }
  946. if (skb_copy_bits(skb, skb_headlen(skb), skb_tail_pointer(skb), delta))
  947. BUG();
  948. /* Optimization: no fragments, no reasons to preestimate
  949. * size of pulled pages. Superb.
  950. */
  951. if (!skb_shinfo(skb)->frag_list)
  952. goto pull_pages;
  953. /* Estimate size of pulled pages. */
  954. eat = delta;
  955. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  956. if (skb_shinfo(skb)->frags[i].size >= eat)
  957. goto pull_pages;
  958. eat -= skb_shinfo(skb)->frags[i].size;
  959. }
  960. /* If we need update frag list, we are in troubles.
  961. * Certainly, it possible to add an offset to skb data,
  962. * but taking into account that pulling is expected to
  963. * be very rare operation, it is worth to fight against
  964. * further bloating skb head and crucify ourselves here instead.
  965. * Pure masohism, indeed. 8)8)
  966. */
  967. if (eat) {
  968. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  969. struct sk_buff *clone = NULL;
  970. struct sk_buff *insp = NULL;
  971. do {
  972. BUG_ON(!list);
  973. if (list->len <= eat) {
  974. /* Eaten as whole. */
  975. eat -= list->len;
  976. list = list->next;
  977. insp = list;
  978. } else {
  979. /* Eaten partially. */
  980. if (skb_shared(list)) {
  981. /* Sucks! We need to fork list. :-( */
  982. clone = skb_clone(list, GFP_ATOMIC);
  983. if (!clone)
  984. return NULL;
  985. insp = list->next;
  986. list = clone;
  987. } else {
  988. /* This may be pulled without
  989. * problems. */
  990. insp = list;
  991. }
  992. if (!pskb_pull(list, eat)) {
  993. if (clone)
  994. kfree_skb(clone);
  995. return NULL;
  996. }
  997. break;
  998. }
  999. } while (eat);
  1000. /* Free pulled out fragments. */
  1001. while ((list = skb_shinfo(skb)->frag_list) != insp) {
  1002. skb_shinfo(skb)->frag_list = list->next;
  1003. kfree_skb(list);
  1004. }
  1005. /* And insert new clone at head. */
  1006. if (clone) {
  1007. clone->next = list;
  1008. skb_shinfo(skb)->frag_list = clone;
  1009. }
  1010. }
  1011. /* Success! Now we may commit changes to skb data. */
  1012. pull_pages:
  1013. eat = delta;
  1014. k = 0;
  1015. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1016. if (skb_shinfo(skb)->frags[i].size <= eat) {
  1017. put_page(skb_shinfo(skb)->frags[i].page);
  1018. eat -= skb_shinfo(skb)->frags[i].size;
  1019. } else {
  1020. skb_shinfo(skb)->frags[k] = skb_shinfo(skb)->frags[i];
  1021. if (eat) {
  1022. skb_shinfo(skb)->frags[k].page_offset += eat;
  1023. skb_shinfo(skb)->frags[k].size -= eat;
  1024. eat = 0;
  1025. }
  1026. k++;
  1027. }
  1028. }
  1029. skb_shinfo(skb)->nr_frags = k;
  1030. skb->tail += delta;
  1031. skb->data_len -= delta;
  1032. return skb_tail_pointer(skb);
  1033. }
  1034. /* Copy some data bits from skb to kernel buffer. */
  1035. int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len)
  1036. {
  1037. int i, copy;
  1038. int start = skb_headlen(skb);
  1039. if (offset > (int)skb->len - len)
  1040. goto fault;
  1041. /* Copy header. */
  1042. if ((copy = start - offset) > 0) {
  1043. if (copy > len)
  1044. copy = len;
  1045. skb_copy_from_linear_data_offset(skb, offset, to, copy);
  1046. if ((len -= copy) == 0)
  1047. return 0;
  1048. offset += copy;
  1049. to += copy;
  1050. }
  1051. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1052. int end;
  1053. WARN_ON(start > offset + len);
  1054. end = start + skb_shinfo(skb)->frags[i].size;
  1055. if ((copy = end - offset) > 0) {
  1056. u8 *vaddr;
  1057. if (copy > len)
  1058. copy = len;
  1059. vaddr = kmap_skb_frag(&skb_shinfo(skb)->frags[i]);
  1060. memcpy(to,
  1061. vaddr + skb_shinfo(skb)->frags[i].page_offset+
  1062. offset - start, copy);
  1063. kunmap_skb_frag(vaddr);
  1064. if ((len -= copy) == 0)
  1065. return 0;
  1066. offset += copy;
  1067. to += copy;
  1068. }
  1069. start = end;
  1070. }
  1071. if (skb_shinfo(skb)->frag_list) {
  1072. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1073. for (; list; list = list->next) {
  1074. int end;
  1075. WARN_ON(start > offset + len);
  1076. end = start + list->len;
  1077. if ((copy = end - offset) > 0) {
  1078. if (copy > len)
  1079. copy = len;
  1080. if (skb_copy_bits(list, offset - start,
  1081. to, copy))
  1082. goto fault;
  1083. if ((len -= copy) == 0)
  1084. return 0;
  1085. offset += copy;
  1086. to += copy;
  1087. }
  1088. start = end;
  1089. }
  1090. }
  1091. if (!len)
  1092. return 0;
  1093. fault:
  1094. return -EFAULT;
  1095. }
  1096. /*
  1097. * Callback from splice_to_pipe(), if we need to release some pages
  1098. * at the end of the spd in case we error'ed out in filling the pipe.
  1099. */
  1100. static void sock_spd_release(struct splice_pipe_desc *spd, unsigned int i)
  1101. {
  1102. struct sk_buff *skb = (struct sk_buff *) spd->partial[i].private;
  1103. kfree_skb(skb);
  1104. }
  1105. /*
  1106. * Fill page/offset/length into spd, if it can hold more pages.
  1107. */
  1108. static inline int spd_fill_page(struct splice_pipe_desc *spd, struct page *page,
  1109. unsigned int len, unsigned int offset,
  1110. struct sk_buff *skb)
  1111. {
  1112. if (unlikely(spd->nr_pages == PIPE_BUFFERS))
  1113. return 1;
  1114. spd->pages[spd->nr_pages] = page;
  1115. spd->partial[spd->nr_pages].len = len;
  1116. spd->partial[spd->nr_pages].offset = offset;
  1117. spd->partial[spd->nr_pages].private = (unsigned long) skb_get(skb);
  1118. spd->nr_pages++;
  1119. return 0;
  1120. }
  1121. static inline void __segment_seek(struct page **page, unsigned int *poff,
  1122. unsigned int *plen, unsigned int off)
  1123. {
  1124. *poff += off;
  1125. *page += *poff / PAGE_SIZE;
  1126. *poff = *poff % PAGE_SIZE;
  1127. *plen -= off;
  1128. }
  1129. static inline int __splice_segment(struct page *page, unsigned int poff,
  1130. unsigned int plen, unsigned int *off,
  1131. unsigned int *len, struct sk_buff *skb,
  1132. struct splice_pipe_desc *spd)
  1133. {
  1134. if (!*len)
  1135. return 1;
  1136. /* skip this segment if already processed */
  1137. if (*off >= plen) {
  1138. *off -= plen;
  1139. return 0;
  1140. }
  1141. /* ignore any bits we already processed */
  1142. if (*off) {
  1143. __segment_seek(&page, &poff, &plen, *off);
  1144. *off = 0;
  1145. }
  1146. do {
  1147. unsigned int flen = min(*len, plen);
  1148. /* the linear region may spread across several pages */
  1149. flen = min_t(unsigned int, flen, PAGE_SIZE - poff);
  1150. if (spd_fill_page(spd, page, flen, poff, skb))
  1151. return 1;
  1152. __segment_seek(&page, &poff, &plen, flen);
  1153. *len -= flen;
  1154. } while (*len && plen);
  1155. return 0;
  1156. }
  1157. /*
  1158. * Map linear and fragment data from the skb to spd. It reports failure if the
  1159. * pipe is full or if we already spliced the requested length.
  1160. */
  1161. static int __skb_splice_bits(struct sk_buff *skb, unsigned int *offset,
  1162. unsigned int *len,
  1163. struct splice_pipe_desc *spd)
  1164. {
  1165. int seg;
  1166. /*
  1167. * map the linear part
  1168. */
  1169. if (__splice_segment(virt_to_page(skb->data),
  1170. (unsigned long) skb->data & (PAGE_SIZE - 1),
  1171. skb_headlen(skb),
  1172. offset, len, skb, spd))
  1173. return 1;
  1174. /*
  1175. * then map the fragments
  1176. */
  1177. for (seg = 0; seg < skb_shinfo(skb)->nr_frags; seg++) {
  1178. const skb_frag_t *f = &skb_shinfo(skb)->frags[seg];
  1179. if (__splice_segment(f->page, f->page_offset, f->size,
  1180. offset, len, skb, spd))
  1181. return 1;
  1182. }
  1183. return 0;
  1184. }
  1185. /*
  1186. * Map data from the skb to a pipe. Should handle both the linear part,
  1187. * the fragments, and the frag list. It does NOT handle frag lists within
  1188. * the frag list, if such a thing exists. We'd probably need to recurse to
  1189. * handle that cleanly.
  1190. */
  1191. int skb_splice_bits(struct sk_buff *__skb, unsigned int offset,
  1192. struct pipe_inode_info *pipe, unsigned int tlen,
  1193. unsigned int flags)
  1194. {
  1195. struct partial_page partial[PIPE_BUFFERS];
  1196. struct page *pages[PIPE_BUFFERS];
  1197. struct splice_pipe_desc spd = {
  1198. .pages = pages,
  1199. .partial = partial,
  1200. .flags = flags,
  1201. .ops = &sock_pipe_buf_ops,
  1202. .spd_release = sock_spd_release,
  1203. };
  1204. struct sk_buff *skb;
  1205. /*
  1206. * I'd love to avoid the clone here, but tcp_read_sock()
  1207. * ignores reference counts and unconditonally kills the sk_buff
  1208. * on return from the actor.
  1209. */
  1210. skb = skb_clone(__skb, GFP_KERNEL);
  1211. if (unlikely(!skb))
  1212. return -ENOMEM;
  1213. /*
  1214. * __skb_splice_bits() only fails if the output has no room left,
  1215. * so no point in going over the frag_list for the error case.
  1216. */
  1217. if (__skb_splice_bits(skb, &offset, &tlen, &spd))
  1218. goto done;
  1219. else if (!tlen)
  1220. goto done;
  1221. /*
  1222. * now see if we have a frag_list to map
  1223. */
  1224. if (skb_shinfo(skb)->frag_list) {
  1225. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1226. for (; list && tlen; list = list->next) {
  1227. if (__skb_splice_bits(list, &offset, &tlen, &spd))
  1228. break;
  1229. }
  1230. }
  1231. done:
  1232. /*
  1233. * drop our reference to the clone, the pipe consumption will
  1234. * drop the rest.
  1235. */
  1236. kfree_skb(skb);
  1237. if (spd.nr_pages) {
  1238. int ret;
  1239. struct sock *sk = __skb->sk;
  1240. /*
  1241. * Drop the socket lock, otherwise we have reverse
  1242. * locking dependencies between sk_lock and i_mutex
  1243. * here as compared to sendfile(). We enter here
  1244. * with the socket lock held, and splice_to_pipe() will
  1245. * grab the pipe inode lock. For sendfile() emulation,
  1246. * we call into ->sendpage() with the i_mutex lock held
  1247. * and networking will grab the socket lock.
  1248. */
  1249. release_sock(sk);
  1250. ret = splice_to_pipe(pipe, &spd);
  1251. lock_sock(sk);
  1252. return ret;
  1253. }
  1254. return 0;
  1255. }
  1256. /**
  1257. * skb_store_bits - store bits from kernel buffer to skb
  1258. * @skb: destination buffer
  1259. * @offset: offset in destination
  1260. * @from: source buffer
  1261. * @len: number of bytes to copy
  1262. *
  1263. * Copy the specified number of bytes from the source buffer to the
  1264. * destination skb. This function handles all the messy bits of
  1265. * traversing fragment lists and such.
  1266. */
  1267. int skb_store_bits(struct sk_buff *skb, int offset, const void *from, int len)
  1268. {
  1269. int i, copy;
  1270. int start = skb_headlen(skb);
  1271. if (offset > (int)skb->len - len)
  1272. goto fault;
  1273. if ((copy = start - offset) > 0) {
  1274. if (copy > len)
  1275. copy = len;
  1276. skb_copy_to_linear_data_offset(skb, offset, from, copy);
  1277. if ((len -= copy) == 0)
  1278. return 0;
  1279. offset += copy;
  1280. from += copy;
  1281. }
  1282. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1283. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1284. int end;
  1285. WARN_ON(start > offset + len);
  1286. end = start + frag->size;
  1287. if ((copy = end - offset) > 0) {
  1288. u8 *vaddr;
  1289. if (copy > len)
  1290. copy = len;
  1291. vaddr = kmap_skb_frag(frag);
  1292. memcpy(vaddr + frag->page_offset + offset - start,
  1293. from, copy);
  1294. kunmap_skb_frag(vaddr);
  1295. if ((len -= copy) == 0)
  1296. return 0;
  1297. offset += copy;
  1298. from += copy;
  1299. }
  1300. start = end;
  1301. }
  1302. if (skb_shinfo(skb)->frag_list) {
  1303. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1304. for (; list; list = list->next) {
  1305. int end;
  1306. WARN_ON(start > offset + len);
  1307. end = start + list->len;
  1308. if ((copy = end - offset) > 0) {
  1309. if (copy > len)
  1310. copy = len;
  1311. if (skb_store_bits(list, offset - start,
  1312. from, copy))
  1313. goto fault;
  1314. if ((len -= copy) == 0)
  1315. return 0;
  1316. offset += copy;
  1317. from += copy;
  1318. }
  1319. start = end;
  1320. }
  1321. }
  1322. if (!len)
  1323. return 0;
  1324. fault:
  1325. return -EFAULT;
  1326. }
  1327. EXPORT_SYMBOL(skb_store_bits);
  1328. /* Checksum skb data. */
  1329. __wsum skb_checksum(const struct sk_buff *skb, int offset,
  1330. int len, __wsum csum)
  1331. {
  1332. int start = skb_headlen(skb);
  1333. int i, copy = start - offset;
  1334. int pos = 0;
  1335. /* Checksum header. */
  1336. if (copy > 0) {
  1337. if (copy > len)
  1338. copy = len;
  1339. csum = csum_partial(skb->data + offset, copy, csum);
  1340. if ((len -= copy) == 0)
  1341. return csum;
  1342. offset += copy;
  1343. pos = copy;
  1344. }
  1345. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1346. int end;
  1347. WARN_ON(start > offset + len);
  1348. end = start + skb_shinfo(skb)->frags[i].size;
  1349. if ((copy = end - offset) > 0) {
  1350. __wsum csum2;
  1351. u8 *vaddr;
  1352. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1353. if (copy > len)
  1354. copy = len;
  1355. vaddr = kmap_skb_frag(frag);
  1356. csum2 = csum_partial(vaddr + frag->page_offset +
  1357. offset - start, copy, 0);
  1358. kunmap_skb_frag(vaddr);
  1359. csum = csum_block_add(csum, csum2, pos);
  1360. if (!(len -= copy))
  1361. return csum;
  1362. offset += copy;
  1363. pos += copy;
  1364. }
  1365. start = end;
  1366. }
  1367. if (skb_shinfo(skb)->frag_list) {
  1368. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1369. for (; list; list = list->next) {
  1370. int end;
  1371. WARN_ON(start > offset + len);
  1372. end = start + list->len;
  1373. if ((copy = end - offset) > 0) {
  1374. __wsum csum2;
  1375. if (copy > len)
  1376. copy = len;
  1377. csum2 = skb_checksum(list, offset - start,
  1378. copy, 0);
  1379. csum = csum_block_add(csum, csum2, pos);
  1380. if ((len -= copy) == 0)
  1381. return csum;
  1382. offset += copy;
  1383. pos += copy;
  1384. }
  1385. start = end;
  1386. }
  1387. }
  1388. BUG_ON(len);
  1389. return csum;
  1390. }
  1391. /* Both of above in one bottle. */
  1392. __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
  1393. u8 *to, int len, __wsum csum)
  1394. {
  1395. int start = skb_headlen(skb);
  1396. int i, copy = start - offset;
  1397. int pos = 0;
  1398. /* Copy header. */
  1399. if (copy > 0) {
  1400. if (copy > len)
  1401. copy = len;
  1402. csum = csum_partial_copy_nocheck(skb->data + offset, to,
  1403. copy, csum);
  1404. if ((len -= copy) == 0)
  1405. return csum;
  1406. offset += copy;
  1407. to += copy;
  1408. pos = copy;
  1409. }
  1410. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1411. int end;
  1412. WARN_ON(start > offset + len);
  1413. end = start + skb_shinfo(skb)->frags[i].size;
  1414. if ((copy = end - offset) > 0) {
  1415. __wsum csum2;
  1416. u8 *vaddr;
  1417. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1418. if (copy > len)
  1419. copy = len;
  1420. vaddr = kmap_skb_frag(frag);
  1421. csum2 = csum_partial_copy_nocheck(vaddr +
  1422. frag->page_offset +
  1423. offset - start, to,
  1424. copy, 0);
  1425. kunmap_skb_frag(vaddr);
  1426. csum = csum_block_add(csum, csum2, pos);
  1427. if (!(len -= copy))
  1428. return csum;
  1429. offset += copy;
  1430. to += copy;
  1431. pos += copy;
  1432. }
  1433. start = end;
  1434. }
  1435. if (skb_shinfo(skb)->frag_list) {
  1436. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1437. for (; list; list = list->next) {
  1438. __wsum csum2;
  1439. int end;
  1440. WARN_ON(start > offset + len);
  1441. end = start + list->len;
  1442. if ((copy = end - offset) > 0) {
  1443. if (copy > len)
  1444. copy = len;
  1445. csum2 = skb_copy_and_csum_bits(list,
  1446. offset - start,
  1447. to, copy, 0);
  1448. csum = csum_block_add(csum, csum2, pos);
  1449. if ((len -= copy) == 0)
  1450. return csum;
  1451. offset += copy;
  1452. to += copy;
  1453. pos += copy;
  1454. }
  1455. start = end;
  1456. }
  1457. }
  1458. BUG_ON(len);
  1459. return csum;
  1460. }
  1461. void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)
  1462. {
  1463. __wsum csum;
  1464. long csstart;
  1465. if (skb->ip_summed == CHECKSUM_PARTIAL)
  1466. csstart = skb->csum_start - skb_headroom(skb);
  1467. else
  1468. csstart = skb_headlen(skb);
  1469. BUG_ON(csstart > skb_headlen(skb));
  1470. skb_copy_from_linear_data(skb, to, csstart);
  1471. csum = 0;
  1472. if (csstart != skb->len)
  1473. csum = skb_copy_and_csum_bits(skb, csstart, to + csstart,
  1474. skb->len - csstart, 0);
  1475. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  1476. long csstuff = csstart + skb->csum_offset;
  1477. *((__sum16 *)(to + csstuff)) = csum_fold(csum);
  1478. }
  1479. }
  1480. /**
  1481. * skb_dequeue - remove from the head of the queue
  1482. * @list: list to dequeue from
  1483. *
  1484. * Remove the head of the list. The list lock is taken so the function
  1485. * may be used safely with other locking list functions. The head item is
  1486. * returned or %NULL if the list is empty.
  1487. */
  1488. struct sk_buff *skb_dequeue(struct sk_buff_head *list)
  1489. {
  1490. unsigned long flags;
  1491. struct sk_buff *result;
  1492. spin_lock_irqsave(&list->lock, flags);
  1493. result = __skb_dequeue(list);
  1494. spin_unlock_irqrestore(&list->lock, flags);
  1495. return result;
  1496. }
  1497. /**
  1498. * skb_dequeue_tail - remove from the tail of the queue
  1499. * @list: list to dequeue from
  1500. *
  1501. * Remove the tail of the list. The list lock is taken so the function
  1502. * may be used safely with other locking list functions. The tail item is
  1503. * returned or %NULL if the list is empty.
  1504. */
  1505. struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list)
  1506. {
  1507. unsigned long flags;
  1508. struct sk_buff *result;
  1509. spin_lock_irqsave(&list->lock, flags);
  1510. result = __skb_dequeue_tail(list);
  1511. spin_unlock_irqrestore(&list->lock, flags);
  1512. return result;
  1513. }
  1514. /**
  1515. * skb_queue_purge - empty a list
  1516. * @list: list to empty
  1517. *
  1518. * Delete all buffers on an &sk_buff list. Each buffer is removed from
  1519. * the list and one reference dropped. This function takes the list
  1520. * lock and is atomic with respect to other list locking functions.
  1521. */
  1522. void skb_queue_purge(struct sk_buff_head *list)
  1523. {
  1524. struct sk_buff *skb;
  1525. while ((skb = skb_dequeue(list)) != NULL)
  1526. kfree_skb(skb);
  1527. }
  1528. /**
  1529. * skb_queue_head - queue a buffer at the list head
  1530. * @list: list to use
  1531. * @newsk: buffer to queue
  1532. *
  1533. * Queue a buffer at the start of the list. This function takes the
  1534. * list lock and can be used safely with other locking &sk_buff functions
  1535. * safely.
  1536. *
  1537. * A buffer cannot be placed on two lists at the same time.
  1538. */
  1539. void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
  1540. {
  1541. unsigned long flags;
  1542. spin_lock_irqsave(&list->lock, flags);
  1543. __skb_queue_head(list, newsk);
  1544. spin_unlock_irqrestore(&list->lock, flags);
  1545. }
  1546. /**
  1547. * skb_queue_tail - queue a buffer at the list tail
  1548. * @list: list to use
  1549. * @newsk: buffer to queue
  1550. *
  1551. * Queue a buffer at the tail of the list. This function takes the
  1552. * list lock and can be used safely with other locking &sk_buff functions
  1553. * safely.
  1554. *
  1555. * A buffer cannot be placed on two lists at the same time.
  1556. */
  1557. void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
  1558. {
  1559. unsigned long flags;
  1560. spin_lock_irqsave(&list->lock, flags);
  1561. __skb_queue_tail(list, newsk);
  1562. spin_unlock_irqrestore(&list->lock, flags);
  1563. }
  1564. /**
  1565. * skb_unlink - remove a buffer from a list
  1566. * @skb: buffer to remove
  1567. * @list: list to use
  1568. *
  1569. * Remove a packet from a list. The list locks are taken and this
  1570. * function is atomic with respect to other list locked calls
  1571. *
  1572. * You must know what list the SKB is on.
  1573. */
  1574. void skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
  1575. {
  1576. unsigned long flags;
  1577. spin_lock_irqsave(&list->lock, flags);
  1578. __skb_unlink(skb, list);
  1579. spin_unlock_irqrestore(&list->lock, flags);
  1580. }
  1581. /**
  1582. * skb_append - append a buffer
  1583. * @old: buffer to insert after
  1584. * @newsk: buffer to insert
  1585. * @list: list to use
  1586. *
  1587. * Place a packet after a given packet in a list. The list locks are taken
  1588. * and this function is atomic with respect to other list locked calls.
  1589. * A buffer cannot be placed on two lists at the same time.
  1590. */
  1591. void skb_append(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list)
  1592. {
  1593. unsigned long flags;
  1594. spin_lock_irqsave(&list->lock, flags);
  1595. __skb_queue_after(list, old, newsk);
  1596. spin_unlock_irqrestore(&list->lock, flags);
  1597. }
  1598. /**
  1599. * skb_insert - insert a buffer
  1600. * @old: buffer to insert before
  1601. * @newsk: buffer to insert
  1602. * @list: list to use
  1603. *
  1604. * Place a packet before a given packet in a list. The list locks are
  1605. * taken and this function is atomic with respect to other list locked
  1606. * calls.
  1607. *
  1608. * A buffer cannot be placed on two lists at the same time.
  1609. */
  1610. void skb_insert(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_insert(newsk, old->prev, old, list);
  1615. spin_unlock_irqrestore(&list->lock, flags);
  1616. }
  1617. static inline void skb_split_inside_header(struct sk_buff *skb,
  1618. struct sk_buff* skb1,
  1619. const u32 len, const int pos)
  1620. {
  1621. int i;
  1622. skb_copy_from_linear_data_offset(skb, len, skb_put(skb1, pos - len),
  1623. pos - len);
  1624. /* And move data appendix as is. */
  1625. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  1626. skb_shinfo(skb1)->frags[i] = skb_shinfo(skb)->frags[i];
  1627. skb_shinfo(skb1)->nr_frags = skb_shinfo(skb)->nr_frags;
  1628. skb_shinfo(skb)->nr_frags = 0;
  1629. skb1->data_len = skb->data_len;
  1630. skb1->len += skb1->data_len;
  1631. skb->data_len = 0;
  1632. skb->len = len;
  1633. skb_set_tail_pointer(skb, len);
  1634. }
  1635. static inline void skb_split_no_header(struct sk_buff *skb,
  1636. struct sk_buff* skb1,
  1637. const u32 len, int pos)
  1638. {
  1639. int i, k = 0;
  1640. const int nfrags = skb_shinfo(skb)->nr_frags;
  1641. skb_shinfo(skb)->nr_frags = 0;
  1642. skb1->len = skb1->data_len = skb->len - len;
  1643. skb->len = len;
  1644. skb->data_len = len - pos;
  1645. for (i = 0; i < nfrags; i++) {
  1646. int size = skb_shinfo(skb)->frags[i].size;
  1647. if (pos + size > len) {
  1648. skb_shinfo(skb1)->frags[k] = skb_shinfo(skb)->frags[i];
  1649. if (pos < len) {
  1650. /* Split frag.
  1651. * We have two variants in this case:
  1652. * 1. Move all the frag to the second
  1653. * part, if it is possible. F.e.
  1654. * this approach is mandatory for TUX,
  1655. * where splitting is expensive.
  1656. * 2. Split is accurately. We make this.
  1657. */
  1658. get_page(skb_shinfo(skb)->frags[i].page);
  1659. skb_shinfo(skb1)->frags[0].page_offset += len - pos;
  1660. skb_shinfo(skb1)->frags[0].size -= len - pos;
  1661. skb_shinfo(skb)->frags[i].size = len - pos;
  1662. skb_shinfo(skb)->nr_frags++;
  1663. }
  1664. k++;
  1665. } else
  1666. skb_shinfo(skb)->nr_frags++;
  1667. pos += size;
  1668. }
  1669. skb_shinfo(skb1)->nr_frags = k;
  1670. }
  1671. /**
  1672. * skb_split - Split fragmented skb to two parts at length len.
  1673. * @skb: the buffer to split
  1674. * @skb1: the buffer to receive the second part
  1675. * @len: new length for skb
  1676. */
  1677. void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len)
  1678. {
  1679. int pos = skb_headlen(skb);
  1680. if (len < pos) /* Split line is inside header. */
  1681. skb_split_inside_header(skb, skb1, len, pos);
  1682. else /* Second chunk has no header, nothing to copy. */
  1683. skb_split_no_header(skb, skb1, len, pos);
  1684. }
  1685. /**
  1686. * skb_prepare_seq_read - Prepare a sequential read of skb data
  1687. * @skb: the buffer to read
  1688. * @from: lower offset of data to be read
  1689. * @to: upper offset of data to be read
  1690. * @st: state variable
  1691. *
  1692. * Initializes the specified state variable. Must be called before
  1693. * invoking skb_seq_read() for the first time.
  1694. */
  1695. void skb_prepare_seq_read(struct sk_buff *skb, unsigned int from,
  1696. unsigned int to, struct skb_seq_state *st)
  1697. {
  1698. st->lower_offset = from;
  1699. st->upper_offset = to;
  1700. st->root_skb = st->cur_skb = skb;
  1701. st->frag_idx = st->stepped_offset = 0;
  1702. st->frag_data = NULL;
  1703. }
  1704. /**
  1705. * skb_seq_read - Sequentially read skb data
  1706. * @consumed: number of bytes consumed by the caller so far
  1707. * @data: destination pointer for data to be returned
  1708. * @st: state variable
  1709. *
  1710. * Reads a block of skb data at &consumed relative to the
  1711. * lower offset specified to skb_prepare_seq_read(). Assigns
  1712. * the head of the data block to &data and returns the length
  1713. * of the block or 0 if the end of the skb data or the upper
  1714. * offset has been reached.
  1715. *
  1716. * The caller is not required to consume all of the data
  1717. * returned, i.e. &consumed is typically set to the number
  1718. * of bytes already consumed and the next call to
  1719. * skb_seq_read() will return the remaining part of the block.
  1720. *
  1721. * Note 1: The size of each block of data returned can be arbitary,
  1722. * this limitation is the cost for zerocopy seqeuental
  1723. * reads of potentially non linear data.
  1724. *
  1725. * Note 2: Fragment lists within fragments are not implemented
  1726. * at the moment, state->root_skb could be replaced with
  1727. * a stack for this purpose.
  1728. */
  1729. unsigned int skb_seq_read(unsigned int consumed, const u8 **data,
  1730. struct skb_seq_state *st)
  1731. {
  1732. unsigned int block_limit, abs_offset = consumed + st->lower_offset;
  1733. skb_frag_t *frag;
  1734. if (unlikely(abs_offset >= st->upper_offset))
  1735. return 0;
  1736. next_skb:
  1737. block_limit = skb_headlen(st->cur_skb);
  1738. if (abs_offset < block_limit) {
  1739. *data = st->cur_skb->data + abs_offset;
  1740. return block_limit - abs_offset;
  1741. }
  1742. if (st->frag_idx == 0 && !st->frag_data)
  1743. st->stepped_offset += skb_headlen(st->cur_skb);
  1744. while (st->frag_idx < skb_shinfo(st->cur_skb)->nr_frags) {
  1745. frag = &skb_shinfo(st->cur_skb)->frags[st->frag_idx];
  1746. block_limit = frag->size + st->stepped_offset;
  1747. if (abs_offset < block_limit) {
  1748. if (!st->frag_data)
  1749. st->frag_data = kmap_skb_frag(frag);
  1750. *data = (u8 *) st->frag_data + frag->page_offset +
  1751. (abs_offset - st->stepped_offset);
  1752. return block_limit - abs_offset;
  1753. }
  1754. if (st->frag_data) {
  1755. kunmap_skb_frag(st->frag_data);
  1756. st->frag_data = NULL;
  1757. }
  1758. st->frag_idx++;
  1759. st->stepped_offset += frag->size;
  1760. }
  1761. if (st->frag_data) {
  1762. kunmap_skb_frag(st->frag_data);
  1763. st->frag_data = NULL;
  1764. }
  1765. if (st->cur_skb->next) {
  1766. st->cur_skb = st->cur_skb->next;
  1767. st->frag_idx = 0;
  1768. goto next_skb;
  1769. } else if (st->root_skb == st->cur_skb &&
  1770. skb_shinfo(st->root_skb)->frag_list) {
  1771. st->cur_skb = skb_shinfo(st->root_skb)->frag_list;
  1772. goto next_skb;
  1773. }
  1774. return 0;
  1775. }
  1776. /**
  1777. * skb_abort_seq_read - Abort a sequential read of skb data
  1778. * @st: state variable
  1779. *
  1780. * Must be called if skb_seq_read() was not called until it
  1781. * returned 0.
  1782. */
  1783. void skb_abort_seq_read(struct skb_seq_state *st)
  1784. {
  1785. if (st->frag_data)
  1786. kunmap_skb_frag(st->frag_data);
  1787. }
  1788. #define TS_SKB_CB(state) ((struct skb_seq_state *) &((state)->cb))
  1789. static unsigned int skb_ts_get_next_block(unsigned int offset, const u8 **text,
  1790. struct ts_config *conf,
  1791. struct ts_state *state)
  1792. {
  1793. return skb_seq_read(offset, text, TS_SKB_CB(state));
  1794. }
  1795. static void skb_ts_finish(struct ts_config *conf, struct ts_state *state)
  1796. {
  1797. skb_abort_seq_read(TS_SKB_CB(state));
  1798. }
  1799. /**
  1800. * skb_find_text - Find a text pattern in skb data
  1801. * @skb: the buffer to look in
  1802. * @from: search offset
  1803. * @to: search limit
  1804. * @config: textsearch configuration
  1805. * @state: uninitialized textsearch state variable
  1806. *
  1807. * Finds a pattern in the skb data according to the specified
  1808. * textsearch configuration. Use textsearch_next() to retrieve
  1809. * subsequent occurrences of the pattern. Returns the offset
  1810. * to the first occurrence or UINT_MAX if no match was found.
  1811. */
  1812. unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
  1813. unsigned int to, struct ts_config *config,
  1814. struct ts_state *state)
  1815. {
  1816. unsigned int ret;
  1817. config->get_next_block = skb_ts_get_next_block;
  1818. config->finish = skb_ts_finish;
  1819. skb_prepare_seq_read(skb, from, to, TS_SKB_CB(state));
  1820. ret = textsearch_find(config, state);
  1821. return (ret <= to - from ? ret : UINT_MAX);
  1822. }
  1823. /**
  1824. * skb_append_datato_frags: - append the user data to a skb
  1825. * @sk: sock structure
  1826. * @skb: skb structure to be appened with user data.
  1827. * @getfrag: call back function to be used for getting the user data
  1828. * @from: pointer to user message iov
  1829. * @length: length of the iov message
  1830. *
  1831. * Description: This procedure append the user data in the fragment part
  1832. * of the skb if any page alloc fails user this procedure returns -ENOMEM
  1833. */
  1834. int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb,
  1835. int (*getfrag)(void *from, char *to, int offset,
  1836. int len, int odd, struct sk_buff *skb),
  1837. void *from, int length)
  1838. {
  1839. int frg_cnt = 0;
  1840. skb_frag_t *frag = NULL;
  1841. struct page *page = NULL;
  1842. int copy, left;
  1843. int offset = 0;
  1844. int ret;
  1845. do {
  1846. /* Return error if we don't have space for new frag */
  1847. frg_cnt = skb_shinfo(skb)->nr_frags;
  1848. if (frg_cnt >= MAX_SKB_FRAGS)
  1849. return -EFAULT;
  1850. /* allocate a new page for next frag */
  1851. page = alloc_pages(sk->sk_allocation, 0);
  1852. /* If alloc_page fails just return failure and caller will
  1853. * free previous allocated pages by doing kfree_skb()
  1854. */
  1855. if (page == NULL)
  1856. return -ENOMEM;
  1857. /* initialize the next frag */
  1858. sk->sk_sndmsg_page = page;
  1859. sk->sk_sndmsg_off = 0;
  1860. skb_fill_page_desc(skb, frg_cnt, page, 0, 0);
  1861. skb->truesize += PAGE_SIZE;
  1862. atomic_add(PAGE_SIZE, &sk->sk_wmem_alloc);
  1863. /* get the new initialized frag */
  1864. frg_cnt = skb_shinfo(skb)->nr_frags;
  1865. frag = &skb_shinfo(skb)->frags[frg_cnt - 1];
  1866. /* copy the user data to page */
  1867. left = PAGE_SIZE - frag->page_offset;
  1868. copy = (length > left)? left : length;
  1869. ret = getfrag(from, (page_address(frag->page) +
  1870. frag->page_offset + frag->size),
  1871. offset, copy, 0, skb);
  1872. if (ret < 0)
  1873. return -EFAULT;
  1874. /* copy was successful so update the size parameters */
  1875. sk->sk_sndmsg_off += copy;
  1876. frag->size += copy;
  1877. skb->len += copy;
  1878. skb->data_len += copy;
  1879. offset += copy;
  1880. length -= copy;
  1881. } while (length > 0);
  1882. return 0;
  1883. }
  1884. /**
  1885. * skb_pull_rcsum - pull skb and update receive checksum
  1886. * @skb: buffer to update
  1887. * @len: length of data pulled
  1888. *
  1889. * This function performs an skb_pull on the packet and updates
  1890. * the CHECKSUM_COMPLETE checksum. It should be used on
  1891. * receive path processing instead of skb_pull unless you know
  1892. * that the checksum difference is zero (e.g., a valid IP header)
  1893. * or you are setting ip_summed to CHECKSUM_NONE.
  1894. */
  1895. unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len)
  1896. {
  1897. BUG_ON(len > skb->len);
  1898. skb->len -= len;
  1899. BUG_ON(skb->len < skb->data_len);
  1900. skb_postpull_rcsum(skb, skb->data, len);
  1901. return skb->data += len;
  1902. }
  1903. EXPORT_SYMBOL_GPL(skb_pull_rcsum);
  1904. /**
  1905. * skb_segment - Perform protocol segmentation on skb.
  1906. * @skb: buffer to segment
  1907. * @features: features for the output path (see dev->features)
  1908. *
  1909. * This function performs segmentation on the given skb. It returns
  1910. * a pointer to the first in a list of new skbs for the segments.
  1911. * In case of error it returns ERR_PTR(err).
  1912. */
  1913. struct sk_buff *skb_segment(struct sk_buff *skb, int features)
  1914. {
  1915. struct sk_buff *segs = NULL;
  1916. struct sk_buff *tail = NULL;
  1917. unsigned int mss = skb_shinfo(skb)->gso_size;
  1918. unsigned int doffset = skb->data - skb_mac_header(skb);
  1919. unsigned int offset = doffset;
  1920. unsigned int headroom;
  1921. unsigned int len;
  1922. int sg = features & NETIF_F_SG;
  1923. int nfrags = skb_shinfo(skb)->nr_frags;
  1924. int err = -ENOMEM;
  1925. int i = 0;
  1926. int pos;
  1927. __skb_push(skb, doffset);
  1928. headroom = skb_headroom(skb);
  1929. pos = skb_headlen(skb);
  1930. do {
  1931. struct sk_buff *nskb;
  1932. skb_frag_t *frag;
  1933. int hsize;
  1934. int k;
  1935. int size;
  1936. len = skb->len - offset;
  1937. if (len > mss)
  1938. len = mss;
  1939. hsize = skb_headlen(skb) - offset;
  1940. if (hsize < 0)
  1941. hsize = 0;
  1942. if (hsize > len || !sg)
  1943. hsize = len;
  1944. nskb = alloc_skb(hsize + doffset + headroom, GFP_ATOMIC);
  1945. if (unlikely(!nskb))
  1946. goto err;
  1947. if (segs)
  1948. tail->next = nskb;
  1949. else
  1950. segs = nskb;
  1951. tail = nskb;
  1952. __copy_skb_header(nskb, skb);
  1953. nskb->mac_len = skb->mac_len;
  1954. skb_reserve(nskb, headroom);
  1955. skb_reset_mac_header(nskb);
  1956. skb_set_network_header(nskb, skb->mac_len);
  1957. nskb->transport_header = (nskb->network_header +
  1958. skb_network_header_len(skb));
  1959. skb_copy_from_linear_data(skb, skb_put(nskb, doffset),
  1960. doffset);
  1961. if (!sg) {
  1962. nskb->ip_summed = CHECKSUM_NONE;
  1963. nskb->csum = skb_copy_and_csum_bits(skb, offset,
  1964. skb_put(nskb, len),
  1965. len, 0);
  1966. continue;
  1967. }
  1968. frag = skb_shinfo(nskb)->frags;
  1969. k = 0;
  1970. skb_copy_from_linear_data_offset(skb, offset,
  1971. skb_put(nskb, hsize), hsize);
  1972. while (pos < offset + len) {
  1973. BUG_ON(i >= nfrags);
  1974. *frag = skb_shinfo(skb)->frags[i];
  1975. get_page(frag->page);
  1976. size = frag->size;
  1977. if (pos < offset) {
  1978. frag->page_offset += offset - pos;
  1979. frag->size -= offset - pos;
  1980. }
  1981. k++;
  1982. if (pos + size <= offset + len) {
  1983. i++;
  1984. pos += size;
  1985. } else {
  1986. frag->size -= pos + size - (offset + len);
  1987. break;
  1988. }
  1989. frag++;
  1990. }
  1991. skb_shinfo(nskb)->nr_frags = k;
  1992. nskb->data_len = len - hsize;
  1993. nskb->len += nskb->data_len;
  1994. nskb->truesize += nskb->data_len;
  1995. } while ((offset += len) < skb->len);
  1996. return segs;
  1997. err:
  1998. while ((skb = segs)) {
  1999. segs = skb->next;
  2000. kfree_skb(skb);
  2001. }
  2002. return ERR_PTR(err);
  2003. }
  2004. EXPORT_SYMBOL_GPL(skb_segment);
  2005. void __init skb_init(void)
  2006. {
  2007. skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
  2008. sizeof(struct sk_buff),
  2009. 0,
  2010. SLAB_HWCACHE_ALIGN|SLAB_PANIC,
  2011. NULL);
  2012. skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
  2013. (2*sizeof(struct sk_buff)) +
  2014. sizeof(atomic_t),
  2015. 0,
  2016. SLAB_HWCACHE_ALIGN|SLAB_PANIC,
  2017. NULL);
  2018. }
  2019. /**
  2020. * skb_to_sgvec - Fill a scatter-gather list from a socket buffer
  2021. * @skb: Socket buffer containing the buffers to be mapped
  2022. * @sg: The scatter-gather list to map into
  2023. * @offset: The offset into the buffer's contents to start mapping
  2024. * @len: Length of buffer space to be mapped
  2025. *
  2026. * Fill the specified scatter-gather list with mappings/pointers into a
  2027. * region of the buffer space attached to a socket buffer.
  2028. */
  2029. static int
  2030. __skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
  2031. {
  2032. int start = skb_headlen(skb);
  2033. int i, copy = start - offset;
  2034. int elt = 0;
  2035. if (copy > 0) {
  2036. if (copy > len)
  2037. copy = len;
  2038. sg_set_buf(sg, skb->data + offset, copy);
  2039. elt++;
  2040. if ((len -= copy) == 0)
  2041. return elt;
  2042. offset += copy;
  2043. }
  2044. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2045. int end;
  2046. WARN_ON(start > offset + len);
  2047. end = start + skb_shinfo(skb)->frags[i].size;
  2048. if ((copy = end - offset) > 0) {
  2049. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2050. if (copy > len)
  2051. copy = len;
  2052. sg_set_page(&sg[elt], frag->page, copy,
  2053. frag->page_offset+offset-start);
  2054. elt++;
  2055. if (!(len -= copy))
  2056. return elt;
  2057. offset += copy;
  2058. }
  2059. start = end;
  2060. }
  2061. if (skb_shinfo(skb)->frag_list) {
  2062. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  2063. for (; list; list = list->next) {
  2064. int end;
  2065. WARN_ON(start > offset + len);
  2066. end = start + list->len;
  2067. if ((copy = end - offset) > 0) {
  2068. if (copy > len)
  2069. copy = len;
  2070. elt += __skb_to_sgvec(list, sg+elt, offset - start,
  2071. copy);
  2072. if ((len -= copy) == 0)
  2073. return elt;
  2074. offset += copy;
  2075. }
  2076. start = end;
  2077. }
  2078. }
  2079. BUG_ON(len);
  2080. return elt;
  2081. }
  2082. int skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
  2083. {
  2084. int nsg = __skb_to_sgvec(skb, sg, offset, len);
  2085. sg_mark_end(&sg[nsg - 1]);
  2086. return nsg;
  2087. }
  2088. /**
  2089. * skb_cow_data - Check that a socket buffer's data buffers are writable
  2090. * @skb: The socket buffer to check.
  2091. * @tailbits: Amount of trailing space to be added
  2092. * @trailer: Returned pointer to the skb where the @tailbits space begins
  2093. *
  2094. * Make sure that the data buffers attached to a socket buffer are
  2095. * writable. If they are not, private copies are made of the data buffers
  2096. * and the socket buffer is set to use these instead.
  2097. *
  2098. * If @tailbits is given, make sure that there is space to write @tailbits
  2099. * bytes of data beyond current end of socket buffer. @trailer will be
  2100. * set to point to the skb in which this space begins.
  2101. *
  2102. * The number of scatterlist elements required to completely map the
  2103. * COW'd and extended socket buffer will be returned.
  2104. */
  2105. int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer)
  2106. {
  2107. int copyflag;
  2108. int elt;
  2109. struct sk_buff *skb1, **skb_p;
  2110. /* If skb is cloned or its head is paged, reallocate
  2111. * head pulling out all the pages (pages are considered not writable
  2112. * at the moment even if they are anonymous).
  2113. */
  2114. if ((skb_cloned(skb) || skb_shinfo(skb)->nr_frags) &&
  2115. __pskb_pull_tail(skb, skb_pagelen(skb)-skb_headlen(skb)) == NULL)
  2116. return -ENOMEM;
  2117. /* Easy case. Most of packets will go this way. */
  2118. if (!skb_shinfo(skb)->frag_list) {
  2119. /* A little of trouble, not enough of space for trailer.
  2120. * This should not happen, when stack is tuned to generate
  2121. * good frames. OK, on miss we reallocate and reserve even more
  2122. * space, 128 bytes is fair. */
  2123. if (skb_tailroom(skb) < tailbits &&
  2124. pskb_expand_head(skb, 0, tailbits-skb_tailroom(skb)+128, GFP_ATOMIC))
  2125. return -ENOMEM;
  2126. /* Voila! */
  2127. *trailer = skb;
  2128. return 1;
  2129. }
  2130. /* Misery. We are in troubles, going to mincer fragments... */
  2131. elt = 1;
  2132. skb_p = &skb_shinfo(skb)->frag_list;
  2133. copyflag = 0;
  2134. while ((skb1 = *skb_p) != NULL) {
  2135. int ntail = 0;
  2136. /* The fragment is partially pulled by someone,
  2137. * this can happen on input. Copy it and everything
  2138. * after it. */
  2139. if (skb_shared(skb1))
  2140. copyflag = 1;
  2141. /* If the skb is the last, worry about trailer. */
  2142. if (skb1->next == NULL && tailbits) {
  2143. if (skb_shinfo(skb1)->nr_frags ||
  2144. skb_shinfo(skb1)->frag_list ||
  2145. skb_tailroom(skb1) < tailbits)
  2146. ntail = tailbits + 128;
  2147. }
  2148. if (copyflag ||
  2149. skb_cloned(skb1) ||
  2150. ntail ||
  2151. skb_shinfo(skb1)->nr_frags ||
  2152. skb_shinfo(skb1)->frag_list) {
  2153. struct sk_buff *skb2;
  2154. /* Fuck, we are miserable poor guys... */
  2155. if (ntail == 0)
  2156. skb2 = skb_copy(skb1, GFP_ATOMIC);
  2157. else
  2158. skb2 = skb_copy_expand(skb1,
  2159. skb_headroom(skb1),
  2160. ntail,
  2161. GFP_ATOMIC);
  2162. if (unlikely(skb2 == NULL))
  2163. return -ENOMEM;
  2164. if (skb1->sk)
  2165. skb_set_owner_w(skb2, skb1->sk);
  2166. /* Looking around. Are we still alive?
  2167. * OK, link new skb, drop old one */
  2168. skb2->next = skb1->next;
  2169. *skb_p = skb2;
  2170. kfree_skb(skb1);
  2171. skb1 = skb2;
  2172. }
  2173. elt++;
  2174. *trailer = skb1;
  2175. skb_p = &skb1->next;
  2176. }
  2177. return elt;
  2178. }
  2179. /**
  2180. * skb_partial_csum_set - set up and verify partial csum values for packet
  2181. * @skb: the skb to set
  2182. * @start: the number of bytes after skb->data to start checksumming.
  2183. * @off: the offset from start to place the checksum.
  2184. *
  2185. * For untrusted partially-checksummed packets, we need to make sure the values
  2186. * for skb->csum_start and skb->csum_offset are valid so we don't oops.
  2187. *
  2188. * This function checks and sets those values and skb->ip_summed: if this
  2189. * returns false you should drop the packet.
  2190. */
  2191. bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off)
  2192. {
  2193. if (unlikely(start > skb->len - 2) ||
  2194. unlikely((int)start + off > skb->len - 2)) {
  2195. if (net_ratelimit())
  2196. printk(KERN_WARNING
  2197. "bad partial csum: csum=%u/%u len=%u\n",
  2198. start, off, skb->len);
  2199. return false;
  2200. }
  2201. skb->ip_summed = CHECKSUM_PARTIAL;
  2202. skb->csum_start = skb_headroom(skb) + start;
  2203. skb->csum_offset = off;
  2204. return true;
  2205. }
  2206. void __skb_warn_lro_forwarding(const struct sk_buff *skb)
  2207. {
  2208. if (net_ratelimit())
  2209. pr_warning("%s: received packets cannot be forwarded"
  2210. " while LRO is enabled\n", skb->dev->name);
  2211. }
  2212. EXPORT_SYMBOL(___pskb_trim);
  2213. EXPORT_SYMBOL(__kfree_skb);
  2214. EXPORT_SYMBOL(kfree_skb);
  2215. EXPORT_SYMBOL(__pskb_pull_tail);
  2216. EXPORT_SYMBOL(__alloc_skb);
  2217. EXPORT_SYMBOL(__netdev_alloc_skb);
  2218. EXPORT_SYMBOL(pskb_copy);
  2219. EXPORT_SYMBOL(pskb_expand_head);
  2220. EXPORT_SYMBOL(skb_checksum);
  2221. EXPORT_SYMBOL(skb_clone);
  2222. EXPORT_SYMBOL(skb_copy);
  2223. EXPORT_SYMBOL(skb_copy_and_csum_bits);
  2224. EXPORT_SYMBOL(skb_copy_and_csum_dev);
  2225. EXPORT_SYMBOL(skb_copy_bits);
  2226. EXPORT_SYMBOL(skb_copy_expand);
  2227. EXPORT_SYMBOL(skb_over_panic);
  2228. EXPORT_SYMBOL(skb_pad);
  2229. EXPORT_SYMBOL(skb_realloc_headroom);
  2230. EXPORT_SYMBOL(skb_under_panic);
  2231. EXPORT_SYMBOL(skb_dequeue);
  2232. EXPORT_SYMBOL(skb_dequeue_tail);
  2233. EXPORT_SYMBOL(skb_insert);
  2234. EXPORT_SYMBOL(skb_queue_purge);
  2235. EXPORT_SYMBOL(skb_queue_head);
  2236. EXPORT_SYMBOL(skb_queue_tail);
  2237. EXPORT_SYMBOL(skb_unlink);
  2238. EXPORT_SYMBOL(skb_append);
  2239. EXPORT_SYMBOL(skb_split);
  2240. EXPORT_SYMBOL(skb_prepare_seq_read);
  2241. EXPORT_SYMBOL(skb_seq_read);
  2242. EXPORT_SYMBOL(skb_abort_seq_read);
  2243. EXPORT_SYMBOL(skb_find_text);
  2244. EXPORT_SYMBOL(skb_append_datato_frags);
  2245. EXPORT_SYMBOL(__skb_warn_lro_forwarding);
  2246. EXPORT_SYMBOL_GPL(skb_to_sgvec);
  2247. EXPORT_SYMBOL_GPL(skb_cow_data);
  2248. EXPORT_SYMBOL_GPL(skb_partial_csum_set);