skbuff.c 64 KB

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