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