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