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