skbuff.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028
  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/cache.h>
  54. #include <linux/rtnetlink.h>
  55. #include <linux/init.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. /*
  67. * Keep out-of-line to prevent kernel bloat.
  68. * __builtin_return_address is not used because it is not always
  69. * reliable.
  70. */
  71. /**
  72. * skb_over_panic - private function
  73. * @skb: buffer
  74. * @sz: size
  75. * @here: address
  76. *
  77. * Out of line support code for skb_put(). Not user callable.
  78. */
  79. void skb_over_panic(struct sk_buff *skb, int sz, void *here)
  80. {
  81. printk(KERN_EMERG "skb_over_panic: text:%p len:%d put:%d head:%p "
  82. "data:%p tail:%p end:%p dev:%s\n",
  83. here, skb->len, sz, skb->head, skb->data, skb->tail, skb->end,
  84. skb->dev ? skb->dev->name : "<NULL>");
  85. BUG();
  86. }
  87. /**
  88. * skb_under_panic - private function
  89. * @skb: buffer
  90. * @sz: size
  91. * @here: address
  92. *
  93. * Out of line support code for skb_push(). Not user callable.
  94. */
  95. void skb_under_panic(struct sk_buff *skb, int sz, void *here)
  96. {
  97. printk(KERN_EMERG "skb_under_panic: text:%p len:%d put:%d head:%p "
  98. "data:%p tail:%p end:%p dev:%s\n",
  99. here, skb->len, sz, skb->head, skb->data, skb->tail, skb->end,
  100. skb->dev ? skb->dev->name : "<NULL>");
  101. BUG();
  102. }
  103. void skb_truesize_bug(struct sk_buff *skb)
  104. {
  105. printk(KERN_ERR "SKB BUG: Invalid truesize (%u) "
  106. "len=%u, sizeof(sk_buff)=%Zd\n",
  107. skb->truesize, skb->len, sizeof(struct sk_buff));
  108. }
  109. EXPORT_SYMBOL(skb_truesize_bug);
  110. /* Allocate a new skbuff. We do this ourselves so we can fill in a few
  111. * 'private' fields and also do memory statistics to find all the
  112. * [BEEP] leaks.
  113. *
  114. */
  115. /**
  116. * __alloc_skb - allocate a network buffer
  117. * @size: size to allocate
  118. * @gfp_mask: allocation mask
  119. * @fclone: allocate from fclone cache instead of head cache
  120. * and allocate a cloned (child) skb
  121. * @node: numa node to allocate memory on
  122. *
  123. * Allocate a new &sk_buff. The returned buffer has no headroom and a
  124. * tail room of size bytes. The object has a reference count of one.
  125. * The return is the buffer. On a failure the return is %NULL.
  126. *
  127. * Buffers may only be allocated from interrupts using a @gfp_mask of
  128. * %GFP_ATOMIC.
  129. */
  130. struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
  131. int fclone, int node)
  132. {
  133. struct kmem_cache *cache;
  134. struct skb_shared_info *shinfo;
  135. struct sk_buff *skb;
  136. u8 *data;
  137. cache = fclone ? skbuff_fclone_cache : skbuff_head_cache;
  138. /* Get the HEAD */
  139. skb = kmem_cache_alloc_node(cache, gfp_mask & ~__GFP_DMA, node);
  140. if (!skb)
  141. goto out;
  142. /* Get the DATA. Size must match skb_add_mtu(). */
  143. size = SKB_DATA_ALIGN(size);
  144. data = kmalloc_node_track_caller(size + sizeof(struct skb_shared_info),
  145. gfp_mask, node);
  146. if (!data)
  147. goto nodata;
  148. memset(skb, 0, offsetof(struct sk_buff, truesize));
  149. skb->truesize = size + sizeof(struct sk_buff);
  150. atomic_set(&skb->users, 1);
  151. skb->head = data;
  152. skb->data = data;
  153. skb->tail = data;
  154. skb->end = data + size;
  155. /* make sure we initialize shinfo sequentially */
  156. shinfo = skb_shinfo(skb);
  157. atomic_set(&shinfo->dataref, 1);
  158. shinfo->nr_frags = 0;
  159. shinfo->gso_size = 0;
  160. shinfo->gso_segs = 0;
  161. shinfo->gso_type = 0;
  162. shinfo->ip6_frag_id = 0;
  163. shinfo->frag_list = NULL;
  164. if (fclone) {
  165. struct sk_buff *child = skb + 1;
  166. atomic_t *fclone_ref = (atomic_t *) (child + 1);
  167. skb->fclone = SKB_FCLONE_ORIG;
  168. atomic_set(fclone_ref, 1);
  169. child->fclone = SKB_FCLONE_UNAVAILABLE;
  170. }
  171. out:
  172. return skb;
  173. nodata:
  174. kmem_cache_free(cache, skb);
  175. skb = NULL;
  176. goto out;
  177. }
  178. /**
  179. * __netdev_alloc_skb - allocate an skbuff for rx on a specific device
  180. * @dev: network device to receive on
  181. * @length: length to allocate
  182. * @gfp_mask: get_free_pages mask, passed to alloc_skb
  183. *
  184. * Allocate a new &sk_buff and assign it a usage count of one. The
  185. * buffer has unspecified headroom built in. Users should allocate
  186. * the headroom they think they need without accounting for the
  187. * built in space. The built in space is used for optimisations.
  188. *
  189. * %NULL is returned if there is no free memory.
  190. */
  191. struct sk_buff *__netdev_alloc_skb(struct net_device *dev,
  192. unsigned int length, gfp_t gfp_mask)
  193. {
  194. int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1;
  195. struct sk_buff *skb;
  196. skb = __alloc_skb(length + NET_SKB_PAD, gfp_mask, 0, node);
  197. if (likely(skb)) {
  198. skb_reserve(skb, NET_SKB_PAD);
  199. skb->dev = dev;
  200. }
  201. return skb;
  202. }
  203. static void skb_drop_list(struct sk_buff **listp)
  204. {
  205. struct sk_buff *list = *listp;
  206. *listp = NULL;
  207. do {
  208. struct sk_buff *this = list;
  209. list = list->next;
  210. kfree_skb(this);
  211. } while (list);
  212. }
  213. static inline void skb_drop_fraglist(struct sk_buff *skb)
  214. {
  215. skb_drop_list(&skb_shinfo(skb)->frag_list);
  216. }
  217. static void skb_clone_fraglist(struct sk_buff *skb)
  218. {
  219. struct sk_buff *list;
  220. for (list = skb_shinfo(skb)->frag_list; list; list = list->next)
  221. skb_get(list);
  222. }
  223. static void skb_release_data(struct sk_buff *skb)
  224. {
  225. if (!skb->cloned ||
  226. !atomic_sub_return(skb->nohdr ? (1 << SKB_DATAREF_SHIFT) + 1 : 1,
  227. &skb_shinfo(skb)->dataref)) {
  228. if (skb_shinfo(skb)->nr_frags) {
  229. int i;
  230. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  231. put_page(skb_shinfo(skb)->frags[i].page);
  232. }
  233. if (skb_shinfo(skb)->frag_list)
  234. skb_drop_fraglist(skb);
  235. kfree(skb->head);
  236. }
  237. }
  238. /*
  239. * Free an skbuff by memory without cleaning the state.
  240. */
  241. void kfree_skbmem(struct sk_buff *skb)
  242. {
  243. struct sk_buff *other;
  244. atomic_t *fclone_ref;
  245. skb_release_data(skb);
  246. switch (skb->fclone) {
  247. case SKB_FCLONE_UNAVAILABLE:
  248. kmem_cache_free(skbuff_head_cache, skb);
  249. break;
  250. case SKB_FCLONE_ORIG:
  251. fclone_ref = (atomic_t *) (skb + 2);
  252. if (atomic_dec_and_test(fclone_ref))
  253. kmem_cache_free(skbuff_fclone_cache, skb);
  254. break;
  255. case SKB_FCLONE_CLONE:
  256. fclone_ref = (atomic_t *) (skb + 1);
  257. other = skb - 1;
  258. /* The clone portion is available for
  259. * fast-cloning again.
  260. */
  261. skb->fclone = SKB_FCLONE_UNAVAILABLE;
  262. if (atomic_dec_and_test(fclone_ref))
  263. kmem_cache_free(skbuff_fclone_cache, other);
  264. break;
  265. };
  266. }
  267. /**
  268. * __kfree_skb - private function
  269. * @skb: buffer
  270. *
  271. * Free an sk_buff. Release anything attached to the buffer.
  272. * Clean the state. This is an internal helper function. Users should
  273. * always call kfree_skb
  274. */
  275. void __kfree_skb(struct sk_buff *skb)
  276. {
  277. dst_release(skb->dst);
  278. #ifdef CONFIG_XFRM
  279. secpath_put(skb->sp);
  280. #endif
  281. if (skb->destructor) {
  282. WARN_ON(in_irq());
  283. skb->destructor(skb);
  284. }
  285. #ifdef CONFIG_NETFILTER
  286. nf_conntrack_put(skb->nfct);
  287. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  288. nf_conntrack_put_reasm(skb->nfct_reasm);
  289. #endif
  290. #ifdef CONFIG_BRIDGE_NETFILTER
  291. nf_bridge_put(skb->nf_bridge);
  292. #endif
  293. #endif
  294. /* XXX: IS this still necessary? - JHS */
  295. #ifdef CONFIG_NET_SCHED
  296. skb->tc_index = 0;
  297. #ifdef CONFIG_NET_CLS_ACT
  298. skb->tc_verd = 0;
  299. #endif
  300. #endif
  301. kfree_skbmem(skb);
  302. }
  303. /**
  304. * kfree_skb - free an sk_buff
  305. * @skb: buffer to free
  306. *
  307. * Drop a reference to the buffer and free it if the usage count has
  308. * hit zero.
  309. */
  310. void kfree_skb(struct sk_buff *skb)
  311. {
  312. if (unlikely(!skb))
  313. return;
  314. if (likely(atomic_read(&skb->users) == 1))
  315. smp_rmb();
  316. else if (likely(!atomic_dec_and_test(&skb->users)))
  317. return;
  318. __kfree_skb(skb);
  319. }
  320. /**
  321. * skb_clone - duplicate an sk_buff
  322. * @skb: buffer to clone
  323. * @gfp_mask: allocation priority
  324. *
  325. * Duplicate an &sk_buff. The new one is not owned by a socket. Both
  326. * copies share the same packet data but not structure. The new
  327. * buffer has a reference count of 1. If the allocation fails the
  328. * function returns %NULL otherwise the new buffer is returned.
  329. *
  330. * If this function is called from an interrupt gfp_mask() must be
  331. * %GFP_ATOMIC.
  332. */
  333. struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
  334. {
  335. struct sk_buff *n;
  336. n = skb + 1;
  337. if (skb->fclone == SKB_FCLONE_ORIG &&
  338. n->fclone == SKB_FCLONE_UNAVAILABLE) {
  339. atomic_t *fclone_ref = (atomic_t *) (n + 1);
  340. n->fclone = SKB_FCLONE_CLONE;
  341. atomic_inc(fclone_ref);
  342. } else {
  343. n = kmem_cache_alloc(skbuff_head_cache, gfp_mask);
  344. if (!n)
  345. return NULL;
  346. n->fclone = SKB_FCLONE_UNAVAILABLE;
  347. }
  348. #define C(x) n->x = skb->x
  349. n->next = n->prev = NULL;
  350. n->sk = NULL;
  351. C(tstamp);
  352. C(dev);
  353. C(transport_header);
  354. C(network_header);
  355. C(mac_header);
  356. C(dst);
  357. dst_clone(skb->dst);
  358. C(sp);
  359. #ifdef CONFIG_INET
  360. secpath_get(skb->sp);
  361. #endif
  362. memcpy(n->cb, skb->cb, sizeof(skb->cb));
  363. C(len);
  364. C(data_len);
  365. C(mac_len);
  366. C(csum);
  367. C(local_df);
  368. n->cloned = 1;
  369. n->nohdr = 0;
  370. C(pkt_type);
  371. C(ip_summed);
  372. C(priority);
  373. #if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
  374. C(ipvs_property);
  375. #endif
  376. C(protocol);
  377. n->destructor = NULL;
  378. C(mark);
  379. __nf_copy(n, skb);
  380. #ifdef CONFIG_NET_SCHED
  381. C(tc_index);
  382. #ifdef CONFIG_NET_CLS_ACT
  383. n->tc_verd = SET_TC_VERD(skb->tc_verd,0);
  384. n->tc_verd = CLR_TC_OK2MUNGE(n->tc_verd);
  385. n->tc_verd = CLR_TC_MUNGED(n->tc_verd);
  386. C(iif);
  387. #endif
  388. skb_copy_secmark(n, skb);
  389. #endif
  390. C(truesize);
  391. atomic_set(&n->users, 1);
  392. C(head);
  393. C(data);
  394. C(tail);
  395. C(end);
  396. atomic_inc(&(skb_shinfo(skb)->dataref));
  397. skb->cloned = 1;
  398. return n;
  399. }
  400. static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
  401. {
  402. #ifndef NET_SKBUFF_DATA_USES_OFFSET
  403. /*
  404. * Shift between the two data areas in bytes
  405. */
  406. unsigned long offset = new->data - old->data;
  407. #endif
  408. new->sk = NULL;
  409. new->dev = old->dev;
  410. new->priority = old->priority;
  411. new->protocol = old->protocol;
  412. new->dst = dst_clone(old->dst);
  413. #ifdef CONFIG_INET
  414. new->sp = secpath_get(old->sp);
  415. #endif
  416. new->transport_header = old->transport_header;
  417. new->network_header = old->network_header;
  418. new->mac_header = old->mac_header;
  419. #ifndef NET_SKBUFF_DATA_USES_OFFSET
  420. /* {transport,network,mac}_header are relative to skb->head */
  421. new->transport_header += offset;
  422. new->network_header += offset;
  423. new->mac_header += offset;
  424. #endif
  425. memcpy(new->cb, old->cb, sizeof(old->cb));
  426. new->local_df = old->local_df;
  427. new->fclone = SKB_FCLONE_UNAVAILABLE;
  428. new->pkt_type = old->pkt_type;
  429. new->tstamp = old->tstamp;
  430. new->destructor = NULL;
  431. new->mark = old->mark;
  432. __nf_copy(new, old);
  433. #if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
  434. new->ipvs_property = old->ipvs_property;
  435. #endif
  436. #ifdef CONFIG_NET_SCHED
  437. #ifdef CONFIG_NET_CLS_ACT
  438. new->tc_verd = old->tc_verd;
  439. #endif
  440. new->tc_index = old->tc_index;
  441. #endif
  442. skb_copy_secmark(new, old);
  443. atomic_set(&new->users, 1);
  444. skb_shinfo(new)->gso_size = skb_shinfo(old)->gso_size;
  445. skb_shinfo(new)->gso_segs = skb_shinfo(old)->gso_segs;
  446. skb_shinfo(new)->gso_type = skb_shinfo(old)->gso_type;
  447. }
  448. /**
  449. * skb_copy - create private copy of an sk_buff
  450. * @skb: buffer to copy
  451. * @gfp_mask: allocation priority
  452. *
  453. * Make a copy of both an &sk_buff and its data. This is used when the
  454. * caller wishes to modify the data and needs a private copy of the
  455. * data to alter. Returns %NULL on failure or the pointer to the buffer
  456. * on success. The returned buffer has a reference count of 1.
  457. *
  458. * As by-product this function converts non-linear &sk_buff to linear
  459. * one, so that &sk_buff becomes completely private and caller is allowed
  460. * to modify all the data of returned buffer. This means that this
  461. * function is not recommended for use in circumstances when only
  462. * header is going to be modified. Use pskb_copy() instead.
  463. */
  464. struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)
  465. {
  466. int headerlen = skb->data - skb->head;
  467. /*
  468. * Allocate the copy buffer
  469. */
  470. struct sk_buff *n = alloc_skb(skb->end - skb->head + skb->data_len,
  471. gfp_mask);
  472. if (!n)
  473. return NULL;
  474. /* Set the data pointer */
  475. skb_reserve(n, headerlen);
  476. /* Set the tail pointer and length */
  477. skb_put(n, skb->len);
  478. n->csum = skb->csum;
  479. n->ip_summed = skb->ip_summed;
  480. if (skb_copy_bits(skb, -headerlen, n->head, headerlen + skb->len))
  481. BUG();
  482. copy_skb_header(n, skb);
  483. return n;
  484. }
  485. /**
  486. * pskb_copy - create copy of an sk_buff with private head.
  487. * @skb: buffer to copy
  488. * @gfp_mask: allocation priority
  489. *
  490. * Make a copy of both an &sk_buff and part of its data, located
  491. * in header. Fragmented data remain shared. This is used when
  492. * the caller wishes to modify only header of &sk_buff and needs
  493. * private copy of the header to alter. Returns %NULL on failure
  494. * or the pointer to the buffer on success.
  495. * The returned buffer has a reference count of 1.
  496. */
  497. struct sk_buff *pskb_copy(struct sk_buff *skb, gfp_t gfp_mask)
  498. {
  499. /*
  500. * Allocate the copy buffer
  501. */
  502. struct sk_buff *n = alloc_skb(skb->end - skb->head, gfp_mask);
  503. if (!n)
  504. goto out;
  505. /* Set the data pointer */
  506. skb_reserve(n, skb->data - skb->head);
  507. /* Set the tail pointer and length */
  508. skb_put(n, skb_headlen(skb));
  509. /* Copy the bytes */
  510. memcpy(n->data, skb->data, n->len);
  511. n->csum = skb->csum;
  512. n->ip_summed = skb->ip_summed;
  513. n->truesize += skb->data_len;
  514. n->data_len = skb->data_len;
  515. n->len = skb->len;
  516. if (skb_shinfo(skb)->nr_frags) {
  517. int i;
  518. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  519. skb_shinfo(n)->frags[i] = skb_shinfo(skb)->frags[i];
  520. get_page(skb_shinfo(n)->frags[i].page);
  521. }
  522. skb_shinfo(n)->nr_frags = i;
  523. }
  524. if (skb_shinfo(skb)->frag_list) {
  525. skb_shinfo(n)->frag_list = skb_shinfo(skb)->frag_list;
  526. skb_clone_fraglist(n);
  527. }
  528. copy_skb_header(n, skb);
  529. out:
  530. return n;
  531. }
  532. /**
  533. * pskb_expand_head - reallocate header of &sk_buff
  534. * @skb: buffer to reallocate
  535. * @nhead: room to add at head
  536. * @ntail: room to add at tail
  537. * @gfp_mask: allocation priority
  538. *
  539. * Expands (or creates identical copy, if &nhead and &ntail are zero)
  540. * header of skb. &sk_buff itself is not changed. &sk_buff MUST have
  541. * reference count of 1. Returns zero in the case of success or error,
  542. * if expansion failed. In the last case, &sk_buff is not changed.
  543. *
  544. * All the pointers pointing into skb header may change and must be
  545. * reloaded after call to this function.
  546. */
  547. int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
  548. gfp_t gfp_mask)
  549. {
  550. int i;
  551. u8 *data;
  552. int size = nhead + (skb->end - skb->head) + ntail;
  553. long off;
  554. if (skb_shared(skb))
  555. BUG();
  556. size = SKB_DATA_ALIGN(size);
  557. data = kmalloc(size + sizeof(struct skb_shared_info), gfp_mask);
  558. if (!data)
  559. goto nodata;
  560. /* Copy only real data... and, alas, header. This should be
  561. * optimized for the cases when header is void. */
  562. memcpy(data + nhead, skb->head, skb->tail - skb->head);
  563. memcpy(data + size, skb->end, sizeof(struct skb_shared_info));
  564. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  565. get_page(skb_shinfo(skb)->frags[i].page);
  566. if (skb_shinfo(skb)->frag_list)
  567. skb_clone_fraglist(skb);
  568. skb_release_data(skb);
  569. off = (data + nhead) - skb->head;
  570. skb->head = data;
  571. skb->end = data + size;
  572. skb->data += off;
  573. skb->tail += off;
  574. #ifndef NET_SKBUFF_DATA_USES_OFFSET
  575. /* {transport,network,mac}_header are relative to skb->head */
  576. skb->transport_header += off;
  577. skb->network_header += off;
  578. skb->mac_header += off;
  579. #endif
  580. skb->cloned = 0;
  581. skb->nohdr = 0;
  582. atomic_set(&skb_shinfo(skb)->dataref, 1);
  583. return 0;
  584. nodata:
  585. return -ENOMEM;
  586. }
  587. /* Make private copy of skb with writable head and some headroom */
  588. struct sk_buff *skb_realloc_headroom(struct sk_buff *skb, unsigned int headroom)
  589. {
  590. struct sk_buff *skb2;
  591. int delta = headroom - skb_headroom(skb);
  592. if (delta <= 0)
  593. skb2 = pskb_copy(skb, GFP_ATOMIC);
  594. else {
  595. skb2 = skb_clone(skb, GFP_ATOMIC);
  596. if (skb2 && pskb_expand_head(skb2, SKB_DATA_ALIGN(delta), 0,
  597. GFP_ATOMIC)) {
  598. kfree_skb(skb2);
  599. skb2 = NULL;
  600. }
  601. }
  602. return skb2;
  603. }
  604. /**
  605. * skb_copy_expand - copy and expand sk_buff
  606. * @skb: buffer to copy
  607. * @newheadroom: new free bytes at head
  608. * @newtailroom: new free bytes at tail
  609. * @gfp_mask: allocation priority
  610. *
  611. * Make a copy of both an &sk_buff and its data and while doing so
  612. * allocate additional space.
  613. *
  614. * This is used when the caller wishes to modify the data and needs a
  615. * private copy of the data to alter as well as more space for new fields.
  616. * Returns %NULL on failure or the pointer to the buffer
  617. * on success. The returned buffer has a reference count of 1.
  618. *
  619. * You must pass %GFP_ATOMIC as the allocation priority if this function
  620. * is called from an interrupt.
  621. *
  622. * BUG ALERT: ip_summed is not copied. Why does this work? Is it used
  623. * only by netfilter in the cases when checksum is recalculated? --ANK
  624. */
  625. struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
  626. int newheadroom, int newtailroom,
  627. gfp_t gfp_mask)
  628. {
  629. /*
  630. * Allocate the copy buffer
  631. */
  632. struct sk_buff *n = alloc_skb(newheadroom + skb->len + newtailroom,
  633. gfp_mask);
  634. int head_copy_len, head_copy_off;
  635. if (!n)
  636. return NULL;
  637. skb_reserve(n, newheadroom);
  638. /* Set the tail pointer and length */
  639. skb_put(n, skb->len);
  640. head_copy_len = skb_headroom(skb);
  641. head_copy_off = 0;
  642. if (newheadroom <= head_copy_len)
  643. head_copy_len = newheadroom;
  644. else
  645. head_copy_off = newheadroom - head_copy_len;
  646. /* Copy the linear header and data. */
  647. if (skb_copy_bits(skb, -head_copy_len, n->head + head_copy_off,
  648. skb->len + head_copy_len))
  649. BUG();
  650. copy_skb_header(n, skb);
  651. return n;
  652. }
  653. /**
  654. * skb_pad - zero pad the tail of an skb
  655. * @skb: buffer to pad
  656. * @pad: space to pad
  657. *
  658. * Ensure that a buffer is followed by a padding area that is zero
  659. * filled. Used by network drivers which may DMA or transfer data
  660. * beyond the buffer end onto the wire.
  661. *
  662. * May return error in out of memory cases. The skb is freed on error.
  663. */
  664. int skb_pad(struct sk_buff *skb, int pad)
  665. {
  666. int err;
  667. int ntail;
  668. /* If the skbuff is non linear tailroom is always zero.. */
  669. if (!skb_cloned(skb) && skb_tailroom(skb) >= pad) {
  670. memset(skb->data+skb->len, 0, pad);
  671. return 0;
  672. }
  673. ntail = skb->data_len + pad - (skb->end - skb->tail);
  674. if (likely(skb_cloned(skb) || ntail > 0)) {
  675. err = pskb_expand_head(skb, 0, ntail, GFP_ATOMIC);
  676. if (unlikely(err))
  677. goto free_skb;
  678. }
  679. /* FIXME: The use of this function with non-linear skb's really needs
  680. * to be audited.
  681. */
  682. err = skb_linearize(skb);
  683. if (unlikely(err))
  684. goto free_skb;
  685. memset(skb->data + skb->len, 0, pad);
  686. return 0;
  687. free_skb:
  688. kfree_skb(skb);
  689. return err;
  690. }
  691. /* Trims skb to length len. It can change skb pointers.
  692. */
  693. int ___pskb_trim(struct sk_buff *skb, unsigned int len)
  694. {
  695. struct sk_buff **fragp;
  696. struct sk_buff *frag;
  697. int offset = skb_headlen(skb);
  698. int nfrags = skb_shinfo(skb)->nr_frags;
  699. int i;
  700. int err;
  701. if (skb_cloned(skb) &&
  702. unlikely((err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))))
  703. return err;
  704. i = 0;
  705. if (offset >= len)
  706. goto drop_pages;
  707. for (; i < nfrags; i++) {
  708. int end = offset + skb_shinfo(skb)->frags[i].size;
  709. if (end < len) {
  710. offset = end;
  711. continue;
  712. }
  713. skb_shinfo(skb)->frags[i++].size = len - offset;
  714. drop_pages:
  715. skb_shinfo(skb)->nr_frags = i;
  716. for (; i < nfrags; i++)
  717. put_page(skb_shinfo(skb)->frags[i].page);
  718. if (skb_shinfo(skb)->frag_list)
  719. skb_drop_fraglist(skb);
  720. goto done;
  721. }
  722. for (fragp = &skb_shinfo(skb)->frag_list; (frag = *fragp);
  723. fragp = &frag->next) {
  724. int end = offset + frag->len;
  725. if (skb_shared(frag)) {
  726. struct sk_buff *nfrag;
  727. nfrag = skb_clone(frag, GFP_ATOMIC);
  728. if (unlikely(!nfrag))
  729. return -ENOMEM;
  730. nfrag->next = frag->next;
  731. kfree_skb(frag);
  732. frag = nfrag;
  733. *fragp = frag;
  734. }
  735. if (end < len) {
  736. offset = end;
  737. continue;
  738. }
  739. if (end > len &&
  740. unlikely((err = pskb_trim(frag, len - offset))))
  741. return err;
  742. if (frag->next)
  743. skb_drop_list(&frag->next);
  744. break;
  745. }
  746. done:
  747. if (len > skb_headlen(skb)) {
  748. skb->data_len -= skb->len - len;
  749. skb->len = len;
  750. } else {
  751. skb->len = len;
  752. skb->data_len = 0;
  753. skb->tail = skb->data + len;
  754. }
  755. return 0;
  756. }
  757. /**
  758. * __pskb_pull_tail - advance tail of skb header
  759. * @skb: buffer to reallocate
  760. * @delta: number of bytes to advance tail
  761. *
  762. * The function makes a sense only on a fragmented &sk_buff,
  763. * it expands header moving its tail forward and copying necessary
  764. * data from fragmented part.
  765. *
  766. * &sk_buff MUST have reference count of 1.
  767. *
  768. * Returns %NULL (and &sk_buff does not change) if pull failed
  769. * or value of new tail of skb in the case of success.
  770. *
  771. * All the pointers pointing into skb header may change and must be
  772. * reloaded after call to this function.
  773. */
  774. /* Moves tail of skb head forward, copying data from fragmented part,
  775. * when it is necessary.
  776. * 1. It may fail due to malloc failure.
  777. * 2. It may change skb pointers.
  778. *
  779. * It is pretty complicated. Luckily, it is called only in exceptional cases.
  780. */
  781. unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta)
  782. {
  783. /* If skb has not enough free space at tail, get new one
  784. * plus 128 bytes for future expansions. If we have enough
  785. * room at tail, reallocate without expansion only if skb is cloned.
  786. */
  787. int i, k, eat = (skb->tail + delta) - skb->end;
  788. if (eat > 0 || skb_cloned(skb)) {
  789. if (pskb_expand_head(skb, 0, eat > 0 ? eat + 128 : 0,
  790. GFP_ATOMIC))
  791. return NULL;
  792. }
  793. if (skb_copy_bits(skb, skb_headlen(skb), skb->tail, delta))
  794. BUG();
  795. /* Optimization: no fragments, no reasons to preestimate
  796. * size of pulled pages. Superb.
  797. */
  798. if (!skb_shinfo(skb)->frag_list)
  799. goto pull_pages;
  800. /* Estimate size of pulled pages. */
  801. eat = delta;
  802. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  803. if (skb_shinfo(skb)->frags[i].size >= eat)
  804. goto pull_pages;
  805. eat -= skb_shinfo(skb)->frags[i].size;
  806. }
  807. /* If we need update frag list, we are in troubles.
  808. * Certainly, it possible to add an offset to skb data,
  809. * but taking into account that pulling is expected to
  810. * be very rare operation, it is worth to fight against
  811. * further bloating skb head and crucify ourselves here instead.
  812. * Pure masohism, indeed. 8)8)
  813. */
  814. if (eat) {
  815. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  816. struct sk_buff *clone = NULL;
  817. struct sk_buff *insp = NULL;
  818. do {
  819. BUG_ON(!list);
  820. if (list->len <= eat) {
  821. /* Eaten as whole. */
  822. eat -= list->len;
  823. list = list->next;
  824. insp = list;
  825. } else {
  826. /* Eaten partially. */
  827. if (skb_shared(list)) {
  828. /* Sucks! We need to fork list. :-( */
  829. clone = skb_clone(list, GFP_ATOMIC);
  830. if (!clone)
  831. return NULL;
  832. insp = list->next;
  833. list = clone;
  834. } else {
  835. /* This may be pulled without
  836. * problems. */
  837. insp = list;
  838. }
  839. if (!pskb_pull(list, eat)) {
  840. if (clone)
  841. kfree_skb(clone);
  842. return NULL;
  843. }
  844. break;
  845. }
  846. } while (eat);
  847. /* Free pulled out fragments. */
  848. while ((list = skb_shinfo(skb)->frag_list) != insp) {
  849. skb_shinfo(skb)->frag_list = list->next;
  850. kfree_skb(list);
  851. }
  852. /* And insert new clone at head. */
  853. if (clone) {
  854. clone->next = list;
  855. skb_shinfo(skb)->frag_list = clone;
  856. }
  857. }
  858. /* Success! Now we may commit changes to skb data. */
  859. pull_pages:
  860. eat = delta;
  861. k = 0;
  862. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  863. if (skb_shinfo(skb)->frags[i].size <= eat) {
  864. put_page(skb_shinfo(skb)->frags[i].page);
  865. eat -= skb_shinfo(skb)->frags[i].size;
  866. } else {
  867. skb_shinfo(skb)->frags[k] = skb_shinfo(skb)->frags[i];
  868. if (eat) {
  869. skb_shinfo(skb)->frags[k].page_offset += eat;
  870. skb_shinfo(skb)->frags[k].size -= eat;
  871. eat = 0;
  872. }
  873. k++;
  874. }
  875. }
  876. skb_shinfo(skb)->nr_frags = k;
  877. skb->tail += delta;
  878. skb->data_len -= delta;
  879. return skb->tail;
  880. }
  881. /* Copy some data bits from skb to kernel buffer. */
  882. int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len)
  883. {
  884. int i, copy;
  885. int start = skb_headlen(skb);
  886. if (offset > (int)skb->len - len)
  887. goto fault;
  888. /* Copy header. */
  889. if ((copy = start - offset) > 0) {
  890. if (copy > len)
  891. copy = len;
  892. memcpy(to, skb->data + offset, copy);
  893. if ((len -= copy) == 0)
  894. return 0;
  895. offset += copy;
  896. to += copy;
  897. }
  898. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  899. int end;
  900. BUG_TRAP(start <= offset + len);
  901. end = start + skb_shinfo(skb)->frags[i].size;
  902. if ((copy = end - offset) > 0) {
  903. u8 *vaddr;
  904. if (copy > len)
  905. copy = len;
  906. vaddr = kmap_skb_frag(&skb_shinfo(skb)->frags[i]);
  907. memcpy(to,
  908. vaddr + skb_shinfo(skb)->frags[i].page_offset+
  909. offset - start, copy);
  910. kunmap_skb_frag(vaddr);
  911. if ((len -= copy) == 0)
  912. return 0;
  913. offset += copy;
  914. to += copy;
  915. }
  916. start = end;
  917. }
  918. if (skb_shinfo(skb)->frag_list) {
  919. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  920. for (; list; list = list->next) {
  921. int end;
  922. BUG_TRAP(start <= offset + len);
  923. end = start + list->len;
  924. if ((copy = end - offset) > 0) {
  925. if (copy > len)
  926. copy = len;
  927. if (skb_copy_bits(list, offset - start,
  928. to, copy))
  929. goto fault;
  930. if ((len -= copy) == 0)
  931. return 0;
  932. offset += copy;
  933. to += copy;
  934. }
  935. start = end;
  936. }
  937. }
  938. if (!len)
  939. return 0;
  940. fault:
  941. return -EFAULT;
  942. }
  943. /**
  944. * skb_store_bits - store bits from kernel buffer to skb
  945. * @skb: destination buffer
  946. * @offset: offset in destination
  947. * @from: source buffer
  948. * @len: number of bytes to copy
  949. *
  950. * Copy the specified number of bytes from the source buffer to the
  951. * destination skb. This function handles all the messy bits of
  952. * traversing fragment lists and such.
  953. */
  954. int skb_store_bits(const struct sk_buff *skb, int offset, void *from, int len)
  955. {
  956. int i, copy;
  957. int start = skb_headlen(skb);
  958. if (offset > (int)skb->len - len)
  959. goto fault;
  960. if ((copy = start - offset) > 0) {
  961. if (copy > len)
  962. copy = len;
  963. memcpy(skb->data + offset, from, copy);
  964. if ((len -= copy) == 0)
  965. return 0;
  966. offset += copy;
  967. from += copy;
  968. }
  969. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  970. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  971. int end;
  972. BUG_TRAP(start <= offset + len);
  973. end = start + frag->size;
  974. if ((copy = end - offset) > 0) {
  975. u8 *vaddr;
  976. if (copy > len)
  977. copy = len;
  978. vaddr = kmap_skb_frag(frag);
  979. memcpy(vaddr + frag->page_offset + offset - start,
  980. from, copy);
  981. kunmap_skb_frag(vaddr);
  982. if ((len -= copy) == 0)
  983. return 0;
  984. offset += copy;
  985. from += copy;
  986. }
  987. start = end;
  988. }
  989. if (skb_shinfo(skb)->frag_list) {
  990. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  991. for (; list; list = list->next) {
  992. int end;
  993. BUG_TRAP(start <= offset + len);
  994. end = start + list->len;
  995. if ((copy = end - offset) > 0) {
  996. if (copy > len)
  997. copy = len;
  998. if (skb_store_bits(list, offset - start,
  999. from, copy))
  1000. goto fault;
  1001. if ((len -= copy) == 0)
  1002. return 0;
  1003. offset += copy;
  1004. from += copy;
  1005. }
  1006. start = end;
  1007. }
  1008. }
  1009. if (!len)
  1010. return 0;
  1011. fault:
  1012. return -EFAULT;
  1013. }
  1014. EXPORT_SYMBOL(skb_store_bits);
  1015. /* Checksum skb data. */
  1016. __wsum skb_checksum(const struct sk_buff *skb, int offset,
  1017. int len, __wsum csum)
  1018. {
  1019. int start = skb_headlen(skb);
  1020. int i, copy = start - offset;
  1021. int pos = 0;
  1022. /* Checksum header. */
  1023. if (copy > 0) {
  1024. if (copy > len)
  1025. copy = len;
  1026. csum = csum_partial(skb->data + offset, copy, csum);
  1027. if ((len -= copy) == 0)
  1028. return csum;
  1029. offset += copy;
  1030. pos = copy;
  1031. }
  1032. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1033. int end;
  1034. BUG_TRAP(start <= offset + len);
  1035. end = start + skb_shinfo(skb)->frags[i].size;
  1036. if ((copy = end - offset) > 0) {
  1037. __wsum csum2;
  1038. u8 *vaddr;
  1039. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1040. if (copy > len)
  1041. copy = len;
  1042. vaddr = kmap_skb_frag(frag);
  1043. csum2 = csum_partial(vaddr + frag->page_offset +
  1044. offset - start, copy, 0);
  1045. kunmap_skb_frag(vaddr);
  1046. csum = csum_block_add(csum, csum2, pos);
  1047. if (!(len -= copy))
  1048. return csum;
  1049. offset += copy;
  1050. pos += copy;
  1051. }
  1052. start = end;
  1053. }
  1054. if (skb_shinfo(skb)->frag_list) {
  1055. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1056. for (; list; list = list->next) {
  1057. int end;
  1058. BUG_TRAP(start <= offset + len);
  1059. end = start + list->len;
  1060. if ((copy = end - offset) > 0) {
  1061. __wsum csum2;
  1062. if (copy > len)
  1063. copy = len;
  1064. csum2 = skb_checksum(list, offset - start,
  1065. copy, 0);
  1066. csum = csum_block_add(csum, csum2, pos);
  1067. if ((len -= copy) == 0)
  1068. return csum;
  1069. offset += copy;
  1070. pos += copy;
  1071. }
  1072. start = end;
  1073. }
  1074. }
  1075. BUG_ON(len);
  1076. return csum;
  1077. }
  1078. /* Both of above in one bottle. */
  1079. __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
  1080. u8 *to, int len, __wsum csum)
  1081. {
  1082. int start = skb_headlen(skb);
  1083. int i, copy = start - offset;
  1084. int pos = 0;
  1085. /* Copy header. */
  1086. if (copy > 0) {
  1087. if (copy > len)
  1088. copy = len;
  1089. csum = csum_partial_copy_nocheck(skb->data + offset, to,
  1090. copy, csum);
  1091. if ((len -= copy) == 0)
  1092. return csum;
  1093. offset += copy;
  1094. to += copy;
  1095. pos = copy;
  1096. }
  1097. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1098. int end;
  1099. BUG_TRAP(start <= offset + len);
  1100. end = start + skb_shinfo(skb)->frags[i].size;
  1101. if ((copy = end - offset) > 0) {
  1102. __wsum csum2;
  1103. u8 *vaddr;
  1104. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1105. if (copy > len)
  1106. copy = len;
  1107. vaddr = kmap_skb_frag(frag);
  1108. csum2 = csum_partial_copy_nocheck(vaddr +
  1109. frag->page_offset +
  1110. offset - start, to,
  1111. copy, 0);
  1112. kunmap_skb_frag(vaddr);
  1113. csum = csum_block_add(csum, csum2, pos);
  1114. if (!(len -= copy))
  1115. return csum;
  1116. offset += copy;
  1117. to += copy;
  1118. pos += copy;
  1119. }
  1120. start = end;
  1121. }
  1122. if (skb_shinfo(skb)->frag_list) {
  1123. struct sk_buff *list = skb_shinfo(skb)->frag_list;
  1124. for (; list; list = list->next) {
  1125. __wsum csum2;
  1126. int end;
  1127. BUG_TRAP(start <= offset + len);
  1128. end = start + list->len;
  1129. if ((copy = end - offset) > 0) {
  1130. if (copy > len)
  1131. copy = len;
  1132. csum2 = skb_copy_and_csum_bits(list,
  1133. offset - start,
  1134. to, copy, 0);
  1135. csum = csum_block_add(csum, csum2, pos);
  1136. if ((len -= copy) == 0)
  1137. return csum;
  1138. offset += copy;
  1139. to += copy;
  1140. pos += copy;
  1141. }
  1142. start = end;
  1143. }
  1144. }
  1145. BUG_ON(len);
  1146. return csum;
  1147. }
  1148. void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)
  1149. {
  1150. __wsum csum;
  1151. long csstart;
  1152. if (skb->ip_summed == CHECKSUM_PARTIAL)
  1153. csstart = skb_transport_offset(skb);
  1154. else
  1155. csstart = skb_headlen(skb);
  1156. BUG_ON(csstart > skb_headlen(skb));
  1157. memcpy(to, skb->data, csstart);
  1158. csum = 0;
  1159. if (csstart != skb->len)
  1160. csum = skb_copy_and_csum_bits(skb, csstart, to + csstart,
  1161. skb->len - csstart, 0);
  1162. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  1163. long csstuff = csstart + skb->csum_offset;
  1164. *((__sum16 *)(to + csstuff)) = csum_fold(csum);
  1165. }
  1166. }
  1167. /**
  1168. * skb_dequeue - remove from the head of the queue
  1169. * @list: list to dequeue from
  1170. *
  1171. * Remove the head of the list. The list lock is taken so the function
  1172. * may be used safely with other locking list functions. The head item is
  1173. * returned or %NULL if the list is empty.
  1174. */
  1175. struct sk_buff *skb_dequeue(struct sk_buff_head *list)
  1176. {
  1177. unsigned long flags;
  1178. struct sk_buff *result;
  1179. spin_lock_irqsave(&list->lock, flags);
  1180. result = __skb_dequeue(list);
  1181. spin_unlock_irqrestore(&list->lock, flags);
  1182. return result;
  1183. }
  1184. /**
  1185. * skb_dequeue_tail - remove from the tail of the queue
  1186. * @list: list to dequeue from
  1187. *
  1188. * Remove the tail of the list. The list lock is taken so the function
  1189. * may be used safely with other locking list functions. The tail item is
  1190. * returned or %NULL if the list is empty.
  1191. */
  1192. struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list)
  1193. {
  1194. unsigned long flags;
  1195. struct sk_buff *result;
  1196. spin_lock_irqsave(&list->lock, flags);
  1197. result = __skb_dequeue_tail(list);
  1198. spin_unlock_irqrestore(&list->lock, flags);
  1199. return result;
  1200. }
  1201. /**
  1202. * skb_queue_purge - empty a list
  1203. * @list: list to empty
  1204. *
  1205. * Delete all buffers on an &sk_buff list. Each buffer is removed from
  1206. * the list and one reference dropped. This function takes the list
  1207. * lock and is atomic with respect to other list locking functions.
  1208. */
  1209. void skb_queue_purge(struct sk_buff_head *list)
  1210. {
  1211. struct sk_buff *skb;
  1212. while ((skb = skb_dequeue(list)) != NULL)
  1213. kfree_skb(skb);
  1214. }
  1215. /**
  1216. * skb_queue_head - queue a buffer at the list head
  1217. * @list: list to use
  1218. * @newsk: buffer to queue
  1219. *
  1220. * Queue a buffer at the start of the list. This function takes the
  1221. * list lock and can be used safely with other locking &sk_buff functions
  1222. * safely.
  1223. *
  1224. * A buffer cannot be placed on two lists at the same time.
  1225. */
  1226. void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
  1227. {
  1228. unsigned long flags;
  1229. spin_lock_irqsave(&list->lock, flags);
  1230. __skb_queue_head(list, newsk);
  1231. spin_unlock_irqrestore(&list->lock, flags);
  1232. }
  1233. /**
  1234. * skb_queue_tail - queue a buffer at the list tail
  1235. * @list: list to use
  1236. * @newsk: buffer to queue
  1237. *
  1238. * Queue a buffer at the tail of the list. This function takes the
  1239. * list lock and can be used safely with other locking &sk_buff functions
  1240. * safely.
  1241. *
  1242. * A buffer cannot be placed on two lists at the same time.
  1243. */
  1244. void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
  1245. {
  1246. unsigned long flags;
  1247. spin_lock_irqsave(&list->lock, flags);
  1248. __skb_queue_tail(list, newsk);
  1249. spin_unlock_irqrestore(&list->lock, flags);
  1250. }
  1251. /**
  1252. * skb_unlink - remove a buffer from a list
  1253. * @skb: buffer to remove
  1254. * @list: list to use
  1255. *
  1256. * Remove a packet from a list. The list locks are taken and this
  1257. * function is atomic with respect to other list locked calls
  1258. *
  1259. * You must know what list the SKB is on.
  1260. */
  1261. void skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
  1262. {
  1263. unsigned long flags;
  1264. spin_lock_irqsave(&list->lock, flags);
  1265. __skb_unlink(skb, list);
  1266. spin_unlock_irqrestore(&list->lock, flags);
  1267. }
  1268. /**
  1269. * skb_append - append a buffer
  1270. * @old: buffer to insert after
  1271. * @newsk: buffer to insert
  1272. * @list: list to use
  1273. *
  1274. * Place a packet after a given packet in a list. The list locks are taken
  1275. * and this function is atomic with respect to other list locked calls.
  1276. * A buffer cannot be placed on two lists at the same time.
  1277. */
  1278. void skb_append(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list)
  1279. {
  1280. unsigned long flags;
  1281. spin_lock_irqsave(&list->lock, flags);
  1282. __skb_append(old, newsk, list);
  1283. spin_unlock_irqrestore(&list->lock, flags);
  1284. }
  1285. /**
  1286. * skb_insert - insert a buffer
  1287. * @old: buffer to insert before
  1288. * @newsk: buffer to insert
  1289. * @list: list to use
  1290. *
  1291. * Place a packet before a given packet in a list. The list locks are
  1292. * taken and this function is atomic with respect to other list locked
  1293. * calls.
  1294. *
  1295. * A buffer cannot be placed on two lists at the same time.
  1296. */
  1297. void skb_insert(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list)
  1298. {
  1299. unsigned long flags;
  1300. spin_lock_irqsave(&list->lock, flags);
  1301. __skb_insert(newsk, old->prev, old, list);
  1302. spin_unlock_irqrestore(&list->lock, flags);
  1303. }
  1304. #if 0
  1305. /*
  1306. * Tune the memory allocator for a new MTU size.
  1307. */
  1308. void skb_add_mtu(int mtu)
  1309. {
  1310. /* Must match allocation in alloc_skb */
  1311. mtu = SKB_DATA_ALIGN(mtu) + sizeof(struct skb_shared_info);
  1312. kmem_add_cache_size(mtu);
  1313. }
  1314. #endif
  1315. static inline void skb_split_inside_header(struct sk_buff *skb,
  1316. struct sk_buff* skb1,
  1317. const u32 len, const int pos)
  1318. {
  1319. int i;
  1320. memcpy(skb_put(skb1, pos - len), skb->data + len, pos - len);
  1321. /* And move data appendix as is. */
  1322. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  1323. skb_shinfo(skb1)->frags[i] = skb_shinfo(skb)->frags[i];
  1324. skb_shinfo(skb1)->nr_frags = skb_shinfo(skb)->nr_frags;
  1325. skb_shinfo(skb)->nr_frags = 0;
  1326. skb1->data_len = skb->data_len;
  1327. skb1->len += skb1->data_len;
  1328. skb->data_len = 0;
  1329. skb->len = len;
  1330. skb->tail = skb->data + len;
  1331. }
  1332. static inline void skb_split_no_header(struct sk_buff *skb,
  1333. struct sk_buff* skb1,
  1334. const u32 len, int pos)
  1335. {
  1336. int i, k = 0;
  1337. const int nfrags = skb_shinfo(skb)->nr_frags;
  1338. skb_shinfo(skb)->nr_frags = 0;
  1339. skb1->len = skb1->data_len = skb->len - len;
  1340. skb->len = len;
  1341. skb->data_len = len - pos;
  1342. for (i = 0; i < nfrags; i++) {
  1343. int size = skb_shinfo(skb)->frags[i].size;
  1344. if (pos + size > len) {
  1345. skb_shinfo(skb1)->frags[k] = skb_shinfo(skb)->frags[i];
  1346. if (pos < len) {
  1347. /* Split frag.
  1348. * We have two variants in this case:
  1349. * 1. Move all the frag to the second
  1350. * part, if it is possible. F.e.
  1351. * this approach is mandatory for TUX,
  1352. * where splitting is expensive.
  1353. * 2. Split is accurately. We make this.
  1354. */
  1355. get_page(skb_shinfo(skb)->frags[i].page);
  1356. skb_shinfo(skb1)->frags[0].page_offset += len - pos;
  1357. skb_shinfo(skb1)->frags[0].size -= len - pos;
  1358. skb_shinfo(skb)->frags[i].size = len - pos;
  1359. skb_shinfo(skb)->nr_frags++;
  1360. }
  1361. k++;
  1362. } else
  1363. skb_shinfo(skb)->nr_frags++;
  1364. pos += size;
  1365. }
  1366. skb_shinfo(skb1)->nr_frags = k;
  1367. }
  1368. /**
  1369. * skb_split - Split fragmented skb to two parts at length len.
  1370. * @skb: the buffer to split
  1371. * @skb1: the buffer to receive the second part
  1372. * @len: new length for skb
  1373. */
  1374. void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len)
  1375. {
  1376. int pos = skb_headlen(skb);
  1377. if (len < pos) /* Split line is inside header. */
  1378. skb_split_inside_header(skb, skb1, len, pos);
  1379. else /* Second chunk has no header, nothing to copy. */
  1380. skb_split_no_header(skb, skb1, len, pos);
  1381. }
  1382. /**
  1383. * skb_prepare_seq_read - Prepare a sequential read of skb data
  1384. * @skb: the buffer to read
  1385. * @from: lower offset of data to be read
  1386. * @to: upper offset of data to be read
  1387. * @st: state variable
  1388. *
  1389. * Initializes the specified state variable. Must be called before
  1390. * invoking skb_seq_read() for the first time.
  1391. */
  1392. void skb_prepare_seq_read(struct sk_buff *skb, unsigned int from,
  1393. unsigned int to, struct skb_seq_state *st)
  1394. {
  1395. st->lower_offset = from;
  1396. st->upper_offset = to;
  1397. st->root_skb = st->cur_skb = skb;
  1398. st->frag_idx = st->stepped_offset = 0;
  1399. st->frag_data = NULL;
  1400. }
  1401. /**
  1402. * skb_seq_read - Sequentially read skb data
  1403. * @consumed: number of bytes consumed by the caller so far
  1404. * @data: destination pointer for data to be returned
  1405. * @st: state variable
  1406. *
  1407. * Reads a block of skb data at &consumed relative to the
  1408. * lower offset specified to skb_prepare_seq_read(). Assigns
  1409. * the head of the data block to &data and returns the length
  1410. * of the block or 0 if the end of the skb data or the upper
  1411. * offset has been reached.
  1412. *
  1413. * The caller is not required to consume all of the data
  1414. * returned, i.e. &consumed is typically set to the number
  1415. * of bytes already consumed and the next call to
  1416. * skb_seq_read() will return the remaining part of the block.
  1417. *
  1418. * Note: The size of each block of data returned can be arbitary,
  1419. * this limitation is the cost for zerocopy seqeuental
  1420. * reads of potentially non linear data.
  1421. *
  1422. * Note: Fragment lists within fragments are not implemented
  1423. * at the moment, state->root_skb could be replaced with
  1424. * a stack for this purpose.
  1425. */
  1426. unsigned int skb_seq_read(unsigned int consumed, const u8 **data,
  1427. struct skb_seq_state *st)
  1428. {
  1429. unsigned int block_limit, abs_offset = consumed + st->lower_offset;
  1430. skb_frag_t *frag;
  1431. if (unlikely(abs_offset >= st->upper_offset))
  1432. return 0;
  1433. next_skb:
  1434. block_limit = skb_headlen(st->cur_skb);
  1435. if (abs_offset < block_limit) {
  1436. *data = st->cur_skb->data + abs_offset;
  1437. return block_limit - abs_offset;
  1438. }
  1439. if (st->frag_idx == 0 && !st->frag_data)
  1440. st->stepped_offset += skb_headlen(st->cur_skb);
  1441. while (st->frag_idx < skb_shinfo(st->cur_skb)->nr_frags) {
  1442. frag = &skb_shinfo(st->cur_skb)->frags[st->frag_idx];
  1443. block_limit = frag->size + st->stepped_offset;
  1444. if (abs_offset < block_limit) {
  1445. if (!st->frag_data)
  1446. st->frag_data = kmap_skb_frag(frag);
  1447. *data = (u8 *) st->frag_data + frag->page_offset +
  1448. (abs_offset - st->stepped_offset);
  1449. return block_limit - abs_offset;
  1450. }
  1451. if (st->frag_data) {
  1452. kunmap_skb_frag(st->frag_data);
  1453. st->frag_data = NULL;
  1454. }
  1455. st->frag_idx++;
  1456. st->stepped_offset += frag->size;
  1457. }
  1458. if (st->cur_skb->next) {
  1459. st->cur_skb = st->cur_skb->next;
  1460. st->frag_idx = 0;
  1461. goto next_skb;
  1462. } else if (st->root_skb == st->cur_skb &&
  1463. skb_shinfo(st->root_skb)->frag_list) {
  1464. st->cur_skb = skb_shinfo(st->root_skb)->frag_list;
  1465. goto next_skb;
  1466. }
  1467. return 0;
  1468. }
  1469. /**
  1470. * skb_abort_seq_read - Abort a sequential read of skb data
  1471. * @st: state variable
  1472. *
  1473. * Must be called if skb_seq_read() was not called until it
  1474. * returned 0.
  1475. */
  1476. void skb_abort_seq_read(struct skb_seq_state *st)
  1477. {
  1478. if (st->frag_data)
  1479. kunmap_skb_frag(st->frag_data);
  1480. }
  1481. #define TS_SKB_CB(state) ((struct skb_seq_state *) &((state)->cb))
  1482. static unsigned int skb_ts_get_next_block(unsigned int offset, const u8 **text,
  1483. struct ts_config *conf,
  1484. struct ts_state *state)
  1485. {
  1486. return skb_seq_read(offset, text, TS_SKB_CB(state));
  1487. }
  1488. static void skb_ts_finish(struct ts_config *conf, struct ts_state *state)
  1489. {
  1490. skb_abort_seq_read(TS_SKB_CB(state));
  1491. }
  1492. /**
  1493. * skb_find_text - Find a text pattern in skb data
  1494. * @skb: the buffer to look in
  1495. * @from: search offset
  1496. * @to: search limit
  1497. * @config: textsearch configuration
  1498. * @state: uninitialized textsearch state variable
  1499. *
  1500. * Finds a pattern in the skb data according to the specified
  1501. * textsearch configuration. Use textsearch_next() to retrieve
  1502. * subsequent occurrences of the pattern. Returns the offset
  1503. * to the first occurrence or UINT_MAX if no match was found.
  1504. */
  1505. unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
  1506. unsigned int to, struct ts_config *config,
  1507. struct ts_state *state)
  1508. {
  1509. unsigned int ret;
  1510. config->get_next_block = skb_ts_get_next_block;
  1511. config->finish = skb_ts_finish;
  1512. skb_prepare_seq_read(skb, from, to, TS_SKB_CB(state));
  1513. ret = textsearch_find(config, state);
  1514. return (ret <= to - from ? ret : UINT_MAX);
  1515. }
  1516. /**
  1517. * skb_append_datato_frags: - append the user data to a skb
  1518. * @sk: sock structure
  1519. * @skb: skb structure to be appened with user data.
  1520. * @getfrag: call back function to be used for getting the user data
  1521. * @from: pointer to user message iov
  1522. * @length: length of the iov message
  1523. *
  1524. * Description: This procedure append the user data in the fragment part
  1525. * of the skb if any page alloc fails user this procedure returns -ENOMEM
  1526. */
  1527. int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb,
  1528. int (*getfrag)(void *from, char *to, int offset,
  1529. int len, int odd, struct sk_buff *skb),
  1530. void *from, int length)
  1531. {
  1532. int frg_cnt = 0;
  1533. skb_frag_t *frag = NULL;
  1534. struct page *page = NULL;
  1535. int copy, left;
  1536. int offset = 0;
  1537. int ret;
  1538. do {
  1539. /* Return error if we don't have space for new frag */
  1540. frg_cnt = skb_shinfo(skb)->nr_frags;
  1541. if (frg_cnt >= MAX_SKB_FRAGS)
  1542. return -EFAULT;
  1543. /* allocate a new page for next frag */
  1544. page = alloc_pages(sk->sk_allocation, 0);
  1545. /* If alloc_page fails just return failure and caller will
  1546. * free previous allocated pages by doing kfree_skb()
  1547. */
  1548. if (page == NULL)
  1549. return -ENOMEM;
  1550. /* initialize the next frag */
  1551. sk->sk_sndmsg_page = page;
  1552. sk->sk_sndmsg_off = 0;
  1553. skb_fill_page_desc(skb, frg_cnt, page, 0, 0);
  1554. skb->truesize += PAGE_SIZE;
  1555. atomic_add(PAGE_SIZE, &sk->sk_wmem_alloc);
  1556. /* get the new initialized frag */
  1557. frg_cnt = skb_shinfo(skb)->nr_frags;
  1558. frag = &skb_shinfo(skb)->frags[frg_cnt - 1];
  1559. /* copy the user data to page */
  1560. left = PAGE_SIZE - frag->page_offset;
  1561. copy = (length > left)? left : length;
  1562. ret = getfrag(from, (page_address(frag->page) +
  1563. frag->page_offset + frag->size),
  1564. offset, copy, 0, skb);
  1565. if (ret < 0)
  1566. return -EFAULT;
  1567. /* copy was successful so update the size parameters */
  1568. sk->sk_sndmsg_off += copy;
  1569. frag->size += copy;
  1570. skb->len += copy;
  1571. skb->data_len += copy;
  1572. offset += copy;
  1573. length -= copy;
  1574. } while (length > 0);
  1575. return 0;
  1576. }
  1577. /**
  1578. * skb_pull_rcsum - pull skb and update receive checksum
  1579. * @skb: buffer to update
  1580. * @start: start of data before pull
  1581. * @len: length of data pulled
  1582. *
  1583. * This function performs an skb_pull on the packet and updates
  1584. * update the CHECKSUM_COMPLETE checksum. It should be used on
  1585. * receive path processing instead of skb_pull unless you know
  1586. * that the checksum difference is zero (e.g., a valid IP header)
  1587. * or you are setting ip_summed to CHECKSUM_NONE.
  1588. */
  1589. unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len)
  1590. {
  1591. BUG_ON(len > skb->len);
  1592. skb->len -= len;
  1593. BUG_ON(skb->len < skb->data_len);
  1594. skb_postpull_rcsum(skb, skb->data, len);
  1595. return skb->data += len;
  1596. }
  1597. EXPORT_SYMBOL_GPL(skb_pull_rcsum);
  1598. /**
  1599. * skb_segment - Perform protocol segmentation on skb.
  1600. * @skb: buffer to segment
  1601. * @features: features for the output path (see dev->features)
  1602. *
  1603. * This function performs segmentation on the given skb. It returns
  1604. * the segment at the given position. It returns NULL if there are
  1605. * no more segments to generate, or when an error is encountered.
  1606. */
  1607. struct sk_buff *skb_segment(struct sk_buff *skb, int features)
  1608. {
  1609. struct sk_buff *segs = NULL;
  1610. struct sk_buff *tail = NULL;
  1611. unsigned int mss = skb_shinfo(skb)->gso_size;
  1612. unsigned int doffset = skb->data - skb_mac_header(skb);
  1613. unsigned int offset = doffset;
  1614. unsigned int headroom;
  1615. unsigned int len;
  1616. int sg = features & NETIF_F_SG;
  1617. int nfrags = skb_shinfo(skb)->nr_frags;
  1618. int err = -ENOMEM;
  1619. int i = 0;
  1620. int pos;
  1621. __skb_push(skb, doffset);
  1622. headroom = skb_headroom(skb);
  1623. pos = skb_headlen(skb);
  1624. do {
  1625. struct sk_buff *nskb;
  1626. skb_frag_t *frag;
  1627. int hsize;
  1628. int k;
  1629. int size;
  1630. len = skb->len - offset;
  1631. if (len > mss)
  1632. len = mss;
  1633. hsize = skb_headlen(skb) - offset;
  1634. if (hsize < 0)
  1635. hsize = 0;
  1636. if (hsize > len || !sg)
  1637. hsize = len;
  1638. nskb = alloc_skb(hsize + doffset + headroom, GFP_ATOMIC);
  1639. if (unlikely(!nskb))
  1640. goto err;
  1641. if (segs)
  1642. tail->next = nskb;
  1643. else
  1644. segs = nskb;
  1645. tail = nskb;
  1646. nskb->dev = skb->dev;
  1647. nskb->priority = skb->priority;
  1648. nskb->protocol = skb->protocol;
  1649. nskb->dst = dst_clone(skb->dst);
  1650. memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
  1651. nskb->pkt_type = skb->pkt_type;
  1652. nskb->mac_len = skb->mac_len;
  1653. skb_reserve(nskb, headroom);
  1654. skb_reset_mac_header(nskb);
  1655. skb_set_network_header(nskb, skb->mac_len);
  1656. nskb->transport_header = (nskb->network_header +
  1657. skb_network_header_len(skb));
  1658. memcpy(skb_put(nskb, doffset), skb->data, doffset);
  1659. if (!sg) {
  1660. nskb->csum = skb_copy_and_csum_bits(skb, offset,
  1661. skb_put(nskb, len),
  1662. len, 0);
  1663. continue;
  1664. }
  1665. frag = skb_shinfo(nskb)->frags;
  1666. k = 0;
  1667. nskb->ip_summed = CHECKSUM_PARTIAL;
  1668. nskb->csum = skb->csum;
  1669. memcpy(skb_put(nskb, hsize), skb->data + offset, hsize);
  1670. while (pos < offset + len) {
  1671. BUG_ON(i >= nfrags);
  1672. *frag = skb_shinfo(skb)->frags[i];
  1673. get_page(frag->page);
  1674. size = frag->size;
  1675. if (pos < offset) {
  1676. frag->page_offset += offset - pos;
  1677. frag->size -= offset - pos;
  1678. }
  1679. k++;
  1680. if (pos + size <= offset + len) {
  1681. i++;
  1682. pos += size;
  1683. } else {
  1684. frag->size -= pos + size - (offset + len);
  1685. break;
  1686. }
  1687. frag++;
  1688. }
  1689. skb_shinfo(nskb)->nr_frags = k;
  1690. nskb->data_len = len - hsize;
  1691. nskb->len += nskb->data_len;
  1692. nskb->truesize += nskb->data_len;
  1693. } while ((offset += len) < skb->len);
  1694. return segs;
  1695. err:
  1696. while ((skb = segs)) {
  1697. segs = skb->next;
  1698. kfree_skb(skb);
  1699. }
  1700. return ERR_PTR(err);
  1701. }
  1702. EXPORT_SYMBOL_GPL(skb_segment);
  1703. void __init skb_init(void)
  1704. {
  1705. skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
  1706. sizeof(struct sk_buff),
  1707. 0,
  1708. SLAB_HWCACHE_ALIGN|SLAB_PANIC,
  1709. NULL, NULL);
  1710. skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
  1711. (2*sizeof(struct sk_buff)) +
  1712. sizeof(atomic_t),
  1713. 0,
  1714. SLAB_HWCACHE_ALIGN|SLAB_PANIC,
  1715. NULL, NULL);
  1716. }
  1717. EXPORT_SYMBOL(___pskb_trim);
  1718. EXPORT_SYMBOL(__kfree_skb);
  1719. EXPORT_SYMBOL(kfree_skb);
  1720. EXPORT_SYMBOL(__pskb_pull_tail);
  1721. EXPORT_SYMBOL(__alloc_skb);
  1722. EXPORT_SYMBOL(__netdev_alloc_skb);
  1723. EXPORT_SYMBOL(pskb_copy);
  1724. EXPORT_SYMBOL(pskb_expand_head);
  1725. EXPORT_SYMBOL(skb_checksum);
  1726. EXPORT_SYMBOL(skb_clone);
  1727. EXPORT_SYMBOL(skb_clone_fraglist);
  1728. EXPORT_SYMBOL(skb_copy);
  1729. EXPORT_SYMBOL(skb_copy_and_csum_bits);
  1730. EXPORT_SYMBOL(skb_copy_and_csum_dev);
  1731. EXPORT_SYMBOL(skb_copy_bits);
  1732. EXPORT_SYMBOL(skb_copy_expand);
  1733. EXPORT_SYMBOL(skb_over_panic);
  1734. EXPORT_SYMBOL(skb_pad);
  1735. EXPORT_SYMBOL(skb_realloc_headroom);
  1736. EXPORT_SYMBOL(skb_under_panic);
  1737. EXPORT_SYMBOL(skb_dequeue);
  1738. EXPORT_SYMBOL(skb_dequeue_tail);
  1739. EXPORT_SYMBOL(skb_insert);
  1740. EXPORT_SYMBOL(skb_queue_purge);
  1741. EXPORT_SYMBOL(skb_queue_head);
  1742. EXPORT_SYMBOL(skb_queue_tail);
  1743. EXPORT_SYMBOL(skb_unlink);
  1744. EXPORT_SYMBOL(skb_append);
  1745. EXPORT_SYMBOL(skb_split);
  1746. EXPORT_SYMBOL(skb_prepare_seq_read);
  1747. EXPORT_SYMBOL(skb_seq_read);
  1748. EXPORT_SYMBOL(skb_abort_seq_read);
  1749. EXPORT_SYMBOL(skb_find_text);
  1750. EXPORT_SYMBOL(skb_append_datato_frags);