skbuff.c 64 KB

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