skbuff.c 64 KB

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