skbuff.c 65 KB

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