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