b0141c2441197abc22a8bd944d427a87b5013d06
[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/config.h>
42 #include <linux/module.h>
43 #include <linux/types.h>
44 #include <linux/kernel.h>
45 #include <linux/sched.h>
46 #include <linux/mm.h>
47 #include <linux/interrupt.h>
48 #include <linux/in.h>
49 #include <linux/inet.h>
50 #include <linux/slab.h>
51 #include <linux/netdevice.h>
52 #ifdef CONFIG_NET_CLS_ACT
53 #include <net/pkt_sched.h>
54 #endif
55 #include <linux/string.h>
56 #include <linux/skbuff.h>
57 #include <linux/cache.h>
58 #include <linux/rtnetlink.h>
59 #include <linux/init.h>
60 #include <linux/highmem.h>
61
62 #include <net/protocol.h>
63 #include <net/dst.h>
64 #include <net/sock.h>
65 #include <net/checksum.h>
66 #include <net/xfrm.h>
67
68 #include <asm/uaccess.h>
69 #include <asm/system.h>
70
71 static kmem_cache_t *skbuff_head_cache;
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_INFO "skput:over: %p:%d put:%d dev:%s",
90                 here, skb->len, sz, skb->dev ? skb->dev->name : "<NULL>");
91         BUG();
92 }
93
94 /**
95  *      skb_under_panic -       private function
96  *      @skb: buffer
97  *      @sz: size
98  *      @here: address
99  *
100  *      Out of line support code for skb_push(). Not user callable.
101  */
102
103 void skb_under_panic(struct sk_buff *skb, int sz, void *here)
104 {
105         printk(KERN_INFO "skput:under: %p:%d put:%d dev:%s",
106                here, skb->len, sz, skb->dev ? skb->dev->name : "<NULL>");
107         BUG();
108 }
109
110 /*      Allocate a new skbuff. We do this ourselves so we can fill in a few
111  *      'private' fields and also do memory statistics to find all the
112  *      [BEEP] leaks.
113  *
114  */
115
116 /**
117  *      alloc_skb       -       allocate a network buffer
118  *      @size: size to allocate
119  *      @gfp_mask: allocation mask
120  *
121  *      Allocate a new &sk_buff. The returned buffer has no headroom and a
122  *      tail room of size bytes. The object has a reference count of one.
123  *      The return is the buffer. On a failure the return is %NULL.
124  *
125  *      Buffers may only be allocated from interrupts using a @gfp_mask of
126  *      %GFP_ATOMIC.
127  */
128 struct sk_buff *alloc_skb(unsigned int size, int gfp_mask)
129 {
130         struct sk_buff *skb;
131         u8 *data;
132
133         /* Get the HEAD */
134         skb = kmem_cache_alloc(skbuff_head_cache,
135                                gfp_mask & ~__GFP_DMA);
136         if (!skb)
137                 goto out;
138
139         /* Get the DATA. Size must match skb_add_mtu(). */
140         size = SKB_DATA_ALIGN(size);
141         data = kmalloc(size + sizeof(struct skb_shared_info), gfp_mask);
142         if (!data)
143                 goto nodata;
144
145         memset(skb, 0, offsetof(struct sk_buff, truesize));
146         skb->truesize = size + sizeof(struct sk_buff);
147         atomic_set(&skb->users, 1);
148         skb->head = data;
149         skb->data = data;
150         skb->tail = data;
151         skb->end  = data + size;
152
153         atomic_set(&(skb_shinfo(skb)->dataref), 1);
154         skb_shinfo(skb)->nr_frags  = 0;
155         skb_shinfo(skb)->tso_size = 0;
156         skb_shinfo(skb)->tso_segs = 0;
157         skb_shinfo(skb)->frag_list = NULL;
158 out:
159         return skb;
160 nodata:
161         kmem_cache_free(skbuff_head_cache, skb);
162         skb = NULL;
163         goto out;
164 }
165
166
167 static void skb_drop_fraglist(struct sk_buff *skb)
168 {
169         struct sk_buff *list = skb_shinfo(skb)->frag_list;
170
171         skb_shinfo(skb)->frag_list = NULL;
172
173         do {
174                 struct sk_buff *this = list;
175                 list = list->next;
176                 kfree_skb(this);
177         } while (list);
178 }
179
180 static void skb_clone_fraglist(struct sk_buff *skb)
181 {
182         struct sk_buff *list;
183
184         for (list = skb_shinfo(skb)->frag_list; list; list = list->next)
185                 skb_get(list);
186 }
187
188 void skb_release_data(struct sk_buff *skb)
189 {
190         if (!skb->cloned ||
191             atomic_dec_and_test(&(skb_shinfo(skb)->dataref))) {
192                 if (skb_shinfo(skb)->nr_frags) {
193                         int i;
194                         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
195                                 put_page(skb_shinfo(skb)->frags[i].page);
196                 }
197
198                 if (skb_shinfo(skb)->frag_list)
199                         skb_drop_fraglist(skb);
200
201                 kfree(skb->head);
202         }
203 }
204
205 /*
206  *      Free an skbuff by memory without cleaning the state.
207  */
208 void kfree_skbmem(struct sk_buff *skb)
209 {
210         skb_release_data(skb);
211         kmem_cache_free(skbuff_head_cache, skb);
212 }
213
214 /**
215  *      __kfree_skb - private function
216  *      @skb: buffer
217  *
218  *      Free an sk_buff. Release anything attached to the buffer.
219  *      Clean the state. This is an internal helper function. Users should
220  *      always call kfree_skb
221  */
222
223 void __kfree_skb(struct sk_buff *skb)
224 {
225         if (skb->list) {
226                 printk(KERN_WARNING "Warning: kfree_skb passed an skb still "
227                        "on a list (from %p).\n", NET_CALLER(skb));
228                 BUG();
229         }
230
231         dst_release(skb->dst);
232 #ifdef CONFIG_XFRM
233         secpath_put(skb->sp);
234 #endif
235         if(skb->destructor) {
236                 if (in_irq())
237                         printk(KERN_WARNING "Warning: kfree_skb on "
238                                             "hard IRQ %p\n", NET_CALLER(skb));
239                 skb->destructor(skb);
240         }
241 #ifdef CONFIG_NETFILTER
242         nf_conntrack_put(skb->nfct);
243 #ifdef CONFIG_BRIDGE_NETFILTER
244         nf_bridge_put(skb->nf_bridge);
245 #endif
246 #endif
247 /* XXX: IS this still necessary? - JHS */
248 #ifdef CONFIG_NET_SCHED
249         skb->tc_index = 0;
250 #ifdef CONFIG_NET_CLS_ACT
251         skb->tc_verd = 0;
252         skb->tc_classid = 0;
253 #endif
254 #endif
255
256         kfree_skbmem(skb);
257 }
258
259 /**
260  *      skb_clone       -       duplicate an sk_buff
261  *      @skb: buffer to clone
262  *      @gfp_mask: allocation priority
263  *
264  *      Duplicate an &sk_buff. The new one is not owned by a socket. Both
265  *      copies share the same packet data but not structure. The new
266  *      buffer has a reference count of 1. If the allocation fails the
267  *      function returns %NULL otherwise the new buffer is returned.
268  *
269  *      If this function is called from an interrupt gfp_mask() must be
270  *      %GFP_ATOMIC.
271  */
272
273 struct sk_buff *skb_clone(struct sk_buff *skb, int gfp_mask)
274 {
275         struct sk_buff *n = kmem_cache_alloc(skbuff_head_cache, gfp_mask);
276
277         if (!n) 
278                 return NULL;
279
280 #define C(x) n->x = skb->x
281
282         n->next = n->prev = NULL;
283         n->list = NULL;
284         n->sk = NULL;
285         C(stamp);
286         C(dev);
287         C(real_dev);
288         C(h);
289         C(nh);
290         C(mac);
291         C(dst);
292         dst_clone(skb->dst);
293         C(sp);
294 #ifdef CONFIG_INET
295         secpath_get(skb->sp);
296 #endif
297         memcpy(n->cb, skb->cb, sizeof(skb->cb));
298         C(len);
299         C(data_len);
300         C(csum);
301         C(local_df);
302         n->cloned = 1;
303         C(pkt_type);
304         C(ip_summed);
305         C(priority);
306         C(protocol);
307         C(security);
308         n->destructor = NULL;
309 #ifdef CONFIG_NETFILTER
310         C(nfmark);
311         C(nfcache);
312         C(nfct);
313         nf_conntrack_get(skb->nfct);
314         C(nfctinfo);
315 #ifdef CONFIG_NETFILTER_DEBUG
316         C(nf_debug);
317 #endif
318 #ifdef CONFIG_BRIDGE_NETFILTER
319         C(nf_bridge);
320         nf_bridge_get(skb->nf_bridge);
321 #endif
322 #endif /*CONFIG_NETFILTER*/
323 #if defined(CONFIG_HIPPI)
324         C(private);
325 #endif
326 #ifdef CONFIG_NET_SCHED
327         C(tc_index);
328 #ifdef CONFIG_NET_CLS_ACT
329         n->tc_verd = SET_TC_VERD(skb->tc_verd,0);
330         n->tc_verd = CLR_TC_OK2MUNGE(skb->tc_verd);
331         n->tc_verd = CLR_TC_MUNGED(skb->tc_verd);
332         C(input_dev);
333         C(tc_classid);
334 #endif
335
336 #endif
337 #if defined(CONFIG_VNET) || defined(CONFIG_VNET_MODULE)
338         C(xid);
339 #endif
340         C(truesize);
341         atomic_set(&n->users, 1);
342         C(head);
343         C(data);
344         C(tail);
345         C(end);
346
347         atomic_inc(&(skb_shinfo(skb)->dataref));
348         skb->cloned = 1;
349
350         return n;
351 }
352
353 static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
354 {
355         /*
356          *      Shift between the two data areas in bytes
357          */
358         unsigned long offset = new->data - old->data;
359
360         new->list       = NULL;
361         new->sk         = NULL;
362         new->dev        = old->dev;
363         new->real_dev   = old->real_dev;
364         new->priority   = old->priority;
365         new->protocol   = old->protocol;
366         new->dst        = dst_clone(old->dst);
367 #ifdef CONFIG_INET
368         new->sp         = secpath_get(old->sp);
369 #endif
370         new->h.raw      = old->h.raw + offset;
371         new->nh.raw     = old->nh.raw + offset;
372         new->mac.raw    = old->mac.raw + offset;
373         memcpy(new->cb, old->cb, sizeof(old->cb));
374         new->local_df   = old->local_df;
375         new->pkt_type   = old->pkt_type;
376         new->stamp      = old->stamp;
377         new->destructor = NULL;
378         new->security   = old->security;
379 #ifdef CONFIG_NETFILTER
380         new->nfmark     = old->nfmark;
381         new->nfcache    = old->nfcache;
382         new->nfct       = old->nfct;
383         nf_conntrack_get(old->nfct);
384         new->nfctinfo   = old->nfctinfo;
385 #ifdef CONFIG_NETFILTER_DEBUG
386         new->nf_debug   = old->nf_debug;
387 #endif
388 #ifdef CONFIG_BRIDGE_NETFILTER
389         new->nf_bridge  = old->nf_bridge;
390         nf_bridge_get(old->nf_bridge);
391 #endif
392 #endif
393 #ifdef CONFIG_NET_SCHED
394 #ifdef CONFIG_NET_CLS_ACT
395         new->tc_verd = old->tc_verd;
396 #endif
397         new->tc_index   = old->tc_index;
398 #endif
399 #if defined(CONFIG_VNET) || defined(CONFIG_VNET_MODULE)
400         new->xid        = old->xid;
401 #endif
402         atomic_set(&new->users, 1);
403         skb_shinfo(new)->tso_size = skb_shinfo(old)->tso_size;
404         skb_shinfo(new)->tso_segs = skb_shinfo(old)->tso_segs;
405 }
406
407 /**
408  *      skb_copy        -       create private copy of an sk_buff
409  *      @skb: buffer to copy
410  *      @gfp_mask: allocation priority
411  *
412  *      Make a copy of both an &sk_buff and its data. This is used when the
413  *      caller wishes to modify the data and needs a private copy of the
414  *      data to alter. Returns %NULL on failure or the pointer to the buffer
415  *      on success. The returned buffer has a reference count of 1.
416  *
417  *      As by-product this function converts non-linear &sk_buff to linear
418  *      one, so that &sk_buff becomes completely private and caller is allowed
419  *      to modify all the data of returned buffer. This means that this
420  *      function is not recommended for use in circumstances when only
421  *      header is going to be modified. Use pskb_copy() instead.
422  */
423
424 struct sk_buff *skb_copy(const struct sk_buff *skb, int gfp_mask)
425 {
426         int headerlen = skb->data - skb->head;
427         /*
428          *      Allocate the copy buffer
429          */
430         struct sk_buff *n = alloc_skb(skb->end - skb->head + skb->data_len,
431                                       gfp_mask);
432         if (!n)
433                 return NULL;
434
435         /* Set the data pointer */
436         skb_reserve(n, headerlen);
437         /* Set the tail pointer and length */
438         skb_put(n, skb->len);
439         n->csum      = skb->csum;
440         n->ip_summed = skb->ip_summed;
441
442         if (skb_copy_bits(skb, -headerlen, n->head, headerlen + skb->len))
443                 BUG();
444
445         copy_skb_header(n, skb);
446         return n;
447 }
448
449
450 /**
451  *      pskb_copy       -       create copy of an sk_buff with private head.
452  *      @skb: buffer to copy
453  *      @gfp_mask: allocation priority
454  *
455  *      Make a copy of both an &sk_buff and part of its data, located
456  *      in header. Fragmented data remain shared. This is used when
457  *      the caller wishes to modify only header of &sk_buff and needs
458  *      private copy of the header to alter. Returns %NULL on failure
459  *      or the pointer to the buffer on success.
460  *      The returned buffer has a reference count of 1.
461  */
462
463 struct sk_buff *pskb_copy(struct sk_buff *skb, int gfp_mask)
464 {
465         /*
466          *      Allocate the copy buffer
467          */
468         struct sk_buff *n = alloc_skb(skb->end - skb->head, gfp_mask);
469
470         if (!n)
471                 goto out;
472
473         /* Set the data pointer */
474         skb_reserve(n, skb->data - skb->head);
475         /* Set the tail pointer and length */
476         skb_put(n, skb_headlen(skb));
477         /* Copy the bytes */
478         memcpy(n->data, skb->data, n->len);
479         n->csum      = skb->csum;
480         n->ip_summed = skb->ip_summed;
481
482         n->data_len  = skb->data_len;
483         n->len       = skb->len;
484
485         if (skb_shinfo(skb)->nr_frags) {
486                 int i;
487
488                 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
489                         skb_shinfo(n)->frags[i] = skb_shinfo(skb)->frags[i];
490                         get_page(skb_shinfo(n)->frags[i].page);
491                 }
492                 skb_shinfo(n)->nr_frags = i;
493         }
494
495         if (skb_shinfo(skb)->frag_list) {
496                 skb_shinfo(n)->frag_list = skb_shinfo(skb)->frag_list;
497                 skb_clone_fraglist(n);
498         }
499
500         copy_skb_header(n, skb);
501 out:
502         return n;
503 }
504
505 /**
506  *      pskb_expand_head - reallocate header of &sk_buff
507  *      @skb: buffer to reallocate
508  *      @nhead: room to add at head
509  *      @ntail: room to add at tail
510  *      @gfp_mask: allocation priority
511  *
512  *      Expands (or creates identical copy, if &nhead and &ntail are zero)
513  *      header of skb. &sk_buff itself is not changed. &sk_buff MUST have
514  *      reference count of 1. Returns zero in the case of success or error,
515  *      if expansion failed. In the last case, &sk_buff is not changed.
516  *
517  *      All the pointers pointing into skb header may change and must be
518  *      reloaded after call to this function.
519  */
520
521 int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, int gfp_mask)
522 {
523         int i;
524         u8 *data;
525         int size = nhead + (skb->end - skb->head) + ntail;
526         long off;
527
528         if (skb_shared(skb))
529                 BUG();
530
531         size = SKB_DATA_ALIGN(size);
532
533         data = kmalloc(size + sizeof(struct skb_shared_info), gfp_mask);
534         if (!data)
535                 goto nodata;
536
537         /* Copy only real data... and, alas, header. This should be
538          * optimized for the cases when header is void. */
539         memcpy(data + nhead, skb->head, skb->tail - skb->head);
540         memcpy(data + size, skb->end, sizeof(struct skb_shared_info));
541
542         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
543                 get_page(skb_shinfo(skb)->frags[i].page);
544
545         if (skb_shinfo(skb)->frag_list)
546                 skb_clone_fraglist(skb);
547
548         skb_release_data(skb);
549
550         off = (data + nhead) - skb->head;
551
552         skb->head     = data;
553         skb->end      = data + size;
554         skb->data    += off;
555         skb->tail    += off;
556         skb->mac.raw += off;
557         skb->h.raw   += off;
558         skb->nh.raw  += off;
559         skb->cloned   = 0;
560         atomic_set(&skb_shinfo(skb)->dataref, 1);
561         return 0;
562
563 nodata:
564         return -ENOMEM;
565 }
566
567 /* Make private copy of skb with writable head and some headroom */
568
569 struct sk_buff *skb_realloc_headroom(struct sk_buff *skb, unsigned int headroom)
570 {
571         struct sk_buff *skb2;
572         int delta = headroom - skb_headroom(skb);
573
574         if (delta <= 0)
575                 skb2 = pskb_copy(skb, GFP_ATOMIC);
576         else {
577                 skb2 = skb_clone(skb, GFP_ATOMIC);
578                 if (skb2 && pskb_expand_head(skb2, SKB_DATA_ALIGN(delta), 0,
579                                              GFP_ATOMIC)) {
580                         kfree_skb(skb2);
581                         skb2 = NULL;
582                 }
583         }
584         return skb2;
585 }
586
587
588 /**
589  *      skb_copy_expand -       copy and expand sk_buff
590  *      @skb: buffer to copy
591  *      @newheadroom: new free bytes at head
592  *      @newtailroom: new free bytes at tail
593  *      @gfp_mask: allocation priority
594  *
595  *      Make a copy of both an &sk_buff and its data and while doing so
596  *      allocate additional space.
597  *
598  *      This is used when the caller wishes to modify the data and needs a
599  *      private copy of the data to alter as well as more space for new fields.
600  *      Returns %NULL on failure or the pointer to the buffer
601  *      on success. The returned buffer has a reference count of 1.
602  *
603  *      You must pass %GFP_ATOMIC as the allocation priority if this function
604  *      is called from an interrupt.
605  *
606  *      BUG ALERT: ip_summed is not copied. Why does this work? Is it used
607  *      only by netfilter in the cases when checksum is recalculated? --ANK
608  */
609 struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
610                                 int newheadroom, int newtailroom, int gfp_mask)
611 {
612         /*
613          *      Allocate the copy buffer
614          */
615         struct sk_buff *n = alloc_skb(newheadroom + skb->len + newtailroom,
616                                       gfp_mask);
617         int head_copy_len, head_copy_off;
618
619         if (!n)
620                 return NULL;
621
622         skb_reserve(n, newheadroom);
623
624         /* Set the tail pointer and length */
625         skb_put(n, skb->len);
626
627         head_copy_len = skb_headroom(skb);
628         head_copy_off = 0;
629         if (newheadroom <= head_copy_len)
630                 head_copy_len = newheadroom;
631         else
632                 head_copy_off = newheadroom - head_copy_len;
633
634         /* Copy the linear header and data. */
635         if (skb_copy_bits(skb, -head_copy_len, n->head + head_copy_off,
636                           skb->len + head_copy_len))
637                 BUG();
638
639         copy_skb_header(n, skb);
640
641         return n;
642 }
643
644 /**
645  *      skb_pad                 -       zero pad the tail of an skb
646  *      @skb: buffer to pad
647  *      @pad: space to pad
648  *
649  *      Ensure that a buffer is followed by a padding area that is zero
650  *      filled. Used by network drivers which may DMA or transfer data
651  *      beyond the buffer end onto the wire.
652  *
653  *      May return NULL in out of memory cases.
654  */
655  
656 struct sk_buff *skb_pad(struct sk_buff *skb, int pad)
657 {
658         struct sk_buff *nskb;
659         
660         /* If the skbuff is non linear tailroom is always zero.. */
661         if (skb_tailroom(skb) >= pad) {
662                 memset(skb->data+skb->len, 0, pad);
663                 return skb;
664         }
665         
666         nskb = skb_copy_expand(skb, skb_headroom(skb), skb_tailroom(skb) + pad, GFP_ATOMIC);
667         kfree_skb(skb);
668         if (nskb)
669                 memset(nskb->data+nskb->len, 0, pad);
670         return nskb;
671 }       
672  
673 /* Trims skb to length len. It can change skb pointers, if "realloc" is 1.
674  * If realloc==0 and trimming is impossible without change of data,
675  * it is BUG().
676  */
677
678 int ___pskb_trim(struct sk_buff *skb, unsigned int len, int realloc)
679 {
680         int offset = skb_headlen(skb);
681         int nfrags = skb_shinfo(skb)->nr_frags;
682         int i;
683
684         for (i = 0; i < nfrags; i++) {
685                 int end = offset + skb_shinfo(skb)->frags[i].size;
686                 if (end > len) {
687                         if (skb_cloned(skb)) {
688                                 if (!realloc)
689                                         BUG();
690                                 if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
691                                         return -ENOMEM;
692                         }
693                         if (len <= offset) {
694                                 put_page(skb_shinfo(skb)->frags[i].page);
695                                 skb_shinfo(skb)->nr_frags--;
696                         } else {
697                                 skb_shinfo(skb)->frags[i].size = len - offset;
698                         }
699                 }
700                 offset = end;
701         }
702
703         if (offset < len) {
704                 skb->data_len -= skb->len - len;
705                 skb->len       = len;
706         } else {
707                 if (len <= skb_headlen(skb)) {
708                         skb->len      = len;
709                         skb->data_len = 0;
710                         skb->tail     = skb->data + len;
711                         if (skb_shinfo(skb)->frag_list && !skb_cloned(skb))
712                                 skb_drop_fraglist(skb);
713                 } else {
714                         skb->data_len -= skb->len - len;
715                         skb->len       = len;
716                 }
717         }
718
719         return 0;
720 }
721
722 /**
723  *      __pskb_pull_tail - advance tail of skb header
724  *      @skb: buffer to reallocate
725  *      @delta: number of bytes to advance tail
726  *
727  *      The function makes a sense only on a fragmented &sk_buff,
728  *      it expands header moving its tail forward and copying necessary
729  *      data from fragmented part.
730  *
731  *      &sk_buff MUST have reference count of 1.
732  *
733  *      Returns %NULL (and &sk_buff does not change) if pull failed
734  *      or value of new tail of skb in the case of success.
735  *
736  *      All the pointers pointing into skb header may change and must be
737  *      reloaded after call to this function.
738  */
739
740 /* Moves tail of skb head forward, copying data from fragmented part,
741  * when it is necessary.
742  * 1. It may fail due to malloc failure.
743  * 2. It may change skb pointers.
744  *
745  * It is pretty complicated. Luckily, it is called only in exceptional cases.
746  */
747 unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta)
748 {
749         /* If skb has not enough free space at tail, get new one
750          * plus 128 bytes for future expansions. If we have enough
751          * room at tail, reallocate without expansion only if skb is cloned.
752          */
753         int i, k, eat = (skb->tail + delta) - skb->end;
754
755         if (eat > 0 || skb_cloned(skb)) {
756                 if (pskb_expand_head(skb, 0, eat > 0 ? eat + 128 : 0,
757                                      GFP_ATOMIC))
758                         return NULL;
759         }
760
761         if (skb_copy_bits(skb, skb_headlen(skb), skb->tail, delta))
762                 BUG();
763
764         /* Optimization: no fragments, no reasons to preestimate
765          * size of pulled pages. Superb.
766          */
767         if (!skb_shinfo(skb)->frag_list)
768                 goto pull_pages;
769
770         /* Estimate size of pulled pages. */
771         eat = delta;
772         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
773                 if (skb_shinfo(skb)->frags[i].size >= eat)
774                         goto pull_pages;
775                 eat -= skb_shinfo(skb)->frags[i].size;
776         }
777
778         /* If we need update frag list, we are in troubles.
779          * Certainly, it possible to add an offset to skb data,
780          * but taking into account that pulling is expected to
781          * be very rare operation, it is worth to fight against
782          * further bloating skb head and crucify ourselves here instead.
783          * Pure masohism, indeed. 8)8)
784          */
785         if (eat) {
786                 struct sk_buff *list = skb_shinfo(skb)->frag_list;
787                 struct sk_buff *clone = NULL;
788                 struct sk_buff *insp = NULL;
789
790                 do {
791                         if (!list)
792                                 BUG();
793
794                         if (list->len <= eat) {
795                                 /* Eaten as whole. */
796                                 eat -= list->len;
797                                 list = list->next;
798                                 insp = list;
799                         } else {
800                                 /* Eaten partially. */
801
802                                 if (skb_shared(list)) {
803                                         /* Sucks! We need to fork list. :-( */
804                                         clone = skb_clone(list, GFP_ATOMIC);
805                                         if (!clone)
806                                                 return NULL;
807                                         insp = list->next;
808                                         list = clone;
809                                 } else {
810                                         /* This may be pulled without
811                                          * problems. */
812                                         insp = list;
813                                 }
814                                 if (!pskb_pull(list, eat)) {
815                                         if (clone)
816                                                 kfree_skb(clone);
817                                         return NULL;
818                                 }
819                                 break;
820                         }
821                 } while (eat);
822
823                 /* Free pulled out fragments. */
824                 while ((list = skb_shinfo(skb)->frag_list) != insp) {
825                         skb_shinfo(skb)->frag_list = list->next;
826                         kfree_skb(list);
827                 }
828                 /* And insert new clone at head. */
829                 if (clone) {
830                         clone->next = list;
831                         skb_shinfo(skb)->frag_list = clone;
832                 }
833         }
834         /* Success! Now we may commit changes to skb data. */
835
836 pull_pages:
837         eat = delta;
838         k = 0;
839         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
840                 if (skb_shinfo(skb)->frags[i].size <= eat) {
841                         put_page(skb_shinfo(skb)->frags[i].page);
842                         eat -= skb_shinfo(skb)->frags[i].size;
843                 } else {
844                         skb_shinfo(skb)->frags[k] = skb_shinfo(skb)->frags[i];
845                         if (eat) {
846                                 skb_shinfo(skb)->frags[k].page_offset += eat;
847                                 skb_shinfo(skb)->frags[k].size -= eat;
848                                 eat = 0;
849                         }
850                         k++;
851                 }
852         }
853         skb_shinfo(skb)->nr_frags = k;
854
855         skb->tail     += delta;
856         skb->data_len -= delta;
857
858         return skb->tail;
859 }
860
861 /* Copy some data bits from skb to kernel buffer. */
862
863 int skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len)
864 {
865         int i, copy;
866         int start = skb_headlen(skb);
867
868         if (offset > (int)skb->len - len)
869                 goto fault;
870
871         /* Copy header. */
872         if ((copy = start - offset) > 0) {
873                 if (copy > len)
874                         copy = len;
875                 memcpy(to, skb->data + offset, copy);
876                 if ((len -= copy) == 0)
877                         return 0;
878                 offset += copy;
879                 to     += copy;
880         }
881
882         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
883                 int end;
884
885                 BUG_TRAP(start <= offset + len);
886
887                 end = start + skb_shinfo(skb)->frags[i].size;
888                 if ((copy = end - offset) > 0) {
889                         u8 *vaddr;
890
891                         if (copy > len)
892                                 copy = len;
893
894                         vaddr = kmap_skb_frag(&skb_shinfo(skb)->frags[i]);
895                         memcpy(to,
896                                vaddr + skb_shinfo(skb)->frags[i].page_offset+
897                                offset - start, copy);
898                         kunmap_skb_frag(vaddr);
899
900                         if ((len -= copy) == 0)
901                                 return 0;
902                         offset += copy;
903                         to     += copy;
904                 }
905                 start = end;
906         }
907
908         if (skb_shinfo(skb)->frag_list) {
909                 struct sk_buff *list = skb_shinfo(skb)->frag_list;
910
911                 for (; list; list = list->next) {
912                         int end;
913
914                         BUG_TRAP(start <= offset + len);
915
916                         end = start + list->len;
917                         if ((copy = end - offset) > 0) {
918                                 if (copy > len)
919                                         copy = len;
920                                 if (skb_copy_bits(list, offset - start,
921                                                   to, copy))
922                                         goto fault;
923                                 if ((len -= copy) == 0)
924                                         return 0;
925                                 offset += copy;
926                                 to     += copy;
927                         }
928                         start = end;
929                 }
930         }
931         if (!len)
932                 return 0;
933
934 fault:
935         return -EFAULT;
936 }
937
938 /* Keep iterating until skb_iter_next returns false. */
939 void skb_iter_first(const struct sk_buff *skb, struct skb_iter *i)
940 {
941         i->len = skb_headlen(skb);
942         i->data = (unsigned char *)skb->data;
943         i->nextfrag = 0;
944         i->fraglist = NULL;
945 }
946
947 int skb_iter_next(const struct sk_buff *skb, struct skb_iter *i)
948 {
949         /* Unmap previous, if not head fragment. */
950         if (i->nextfrag)
951                 kunmap_skb_frag(i->data);
952
953         if (i->fraglist) {
954         fraglist:
955                 /* We're iterating through fraglist. */
956                 if (i->nextfrag < skb_shinfo(i->fraglist)->nr_frags) {
957                         i->data = kmap_skb_frag(&skb_shinfo(i->fraglist)
958                                                 ->frags[i->nextfrag]);
959                         i->len = skb_shinfo(i->fraglist)->frags[i->nextfrag]
960                                 .size;
961                         i->nextfrag++;
962                         return 1;
963                 }
964                 /* Fragments with fragments?  Too hard! */
965                 BUG_ON(skb_shinfo(i->fraglist)->frag_list);
966                 i->fraglist = i->fraglist->next;
967                 if (!i->fraglist)
968                         goto end;
969
970                 i->len = skb_headlen(i->fraglist);
971                 i->data = i->fraglist->data;
972                 i->nextfrag = 0;
973                 return 1;
974         }
975
976         if (i->nextfrag < skb_shinfo(skb)->nr_frags) {
977                 i->data = kmap_skb_frag(&skb_shinfo(skb)->frags[i->nextfrag]);
978                 i->len = skb_shinfo(skb)->frags[i->nextfrag].size;
979                 i->nextfrag++;
980                 return 1;
981         }
982
983         i->fraglist = skb_shinfo(skb)->frag_list;
984         if (i->fraglist)
985                 goto fraglist;
986
987 end:
988         /* Bug trap for callers */
989         i->data = NULL;
990         return 0;
991 }
992
993 void skb_iter_abort(const struct sk_buff *skb, struct skb_iter *i)
994 {
995         /* Unmap previous, if not head fragment. */
996         if (i->data && i->nextfrag)
997                 kunmap_skb_frag(i->data);
998         /* Bug trap for callers */
999         i->data = NULL;
1000 }
1001
1002 /* Checksum skb data. */
1003
1004 unsigned int skb_checksum(const struct sk_buff *skb, int offset,
1005                           int len, unsigned int csum)
1006 {
1007         int start = skb_headlen(skb);
1008         int i, copy = start - offset;
1009         int pos = 0;
1010
1011         /* Checksum header. */
1012         if (copy > 0) {
1013                 if (copy > len)
1014                         copy = len;
1015                 csum = csum_partial(skb->data + offset, copy, csum);
1016                 if ((len -= copy) == 0)
1017                         return csum;
1018                 offset += copy;
1019                 pos     = copy;
1020         }
1021
1022         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1023                 int end;
1024
1025                 BUG_TRAP(start <= offset + len);
1026
1027                 end = start + skb_shinfo(skb)->frags[i].size;
1028                 if ((copy = end - offset) > 0) {
1029                         unsigned int csum2;
1030                         u8 *vaddr;
1031                         skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1032
1033                         if (copy > len)
1034                                 copy = len;
1035                         vaddr = kmap_skb_frag(frag);
1036                         csum2 = csum_partial(vaddr + frag->page_offset +
1037                                              offset - start, copy, 0);
1038                         kunmap_skb_frag(vaddr);
1039                         csum = csum_block_add(csum, csum2, pos);
1040                         if (!(len -= copy))
1041                                 return csum;
1042                         offset += copy;
1043                         pos    += copy;
1044                 }
1045                 start = end;
1046         }
1047
1048         if (skb_shinfo(skb)->frag_list) {
1049                 struct sk_buff *list = skb_shinfo(skb)->frag_list;
1050
1051                 for (; list; list = list->next) {
1052                         int end;
1053
1054                         BUG_TRAP(start <= offset + len);
1055
1056                         end = start + list->len;
1057                         if ((copy = end - offset) > 0) {
1058                                 unsigned int csum2;
1059                                 if (copy > len)
1060                                         copy = len;
1061                                 csum2 = skb_checksum(list, offset - start,
1062                                                      copy, 0);
1063                                 csum = csum_block_add(csum, csum2, pos);
1064                                 if ((len -= copy) == 0)
1065                                         return csum;
1066                                 offset += copy;
1067                                 pos    += copy;
1068                         }
1069                         start = end;
1070                 }
1071         }
1072         if (len)
1073                 BUG();
1074
1075         return csum;
1076 }
1077
1078 /* Both of above in one bottle. */
1079
1080 unsigned int skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
1081                                     u8 *to, int len, unsigned int csum)
1082 {
1083         int start = skb_headlen(skb);
1084         int i, copy = start - offset;
1085         int pos = 0;
1086
1087         /* Copy header. */
1088         if (copy > 0) {
1089                 if (copy > len)
1090                         copy = len;
1091                 csum = csum_partial_copy_nocheck(skb->data + offset, to,
1092                                                  copy, csum);
1093                 if ((len -= copy) == 0)
1094                         return csum;
1095                 offset += copy;
1096                 to     += copy;
1097                 pos     = copy;
1098         }
1099
1100         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1101                 int end;
1102
1103                 BUG_TRAP(start <= offset + len);
1104
1105                 end = start + skb_shinfo(skb)->frags[i].size;
1106                 if ((copy = end - offset) > 0) {
1107                         unsigned int csum2;
1108                         u8 *vaddr;
1109                         skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1110
1111                         if (copy > len)
1112                                 copy = len;
1113                         vaddr = kmap_skb_frag(frag);
1114                         csum2 = csum_partial_copy_nocheck(vaddr +
1115                                                           frag->page_offset +
1116                                                           offset - start, to,
1117                                                           copy, 0);
1118                         kunmap_skb_frag(vaddr);
1119                         csum = csum_block_add(csum, csum2, pos);
1120                         if (!(len -= copy))
1121                                 return csum;
1122                         offset += copy;
1123                         to     += copy;
1124                         pos    += copy;
1125                 }
1126                 start = end;
1127         }
1128
1129         if (skb_shinfo(skb)->frag_list) {
1130                 struct sk_buff *list = skb_shinfo(skb)->frag_list;
1131
1132                 for (; list; list = list->next) {
1133                         unsigned int csum2;
1134                         int end;
1135
1136                         BUG_TRAP(start <= offset + len);
1137
1138                         end = start + list->len;
1139                         if ((copy = end - offset) > 0) {
1140                                 if (copy > len)
1141                                         copy = len;
1142                                 csum2 = skb_copy_and_csum_bits(list,
1143                                                                offset - start,
1144                                                                to, copy, 0);
1145                                 csum = csum_block_add(csum, csum2, pos);
1146                                 if ((len -= copy) == 0)
1147                                         return csum;
1148                                 offset += copy;
1149                                 to     += copy;
1150                                 pos    += copy;
1151                         }
1152                         start = end;
1153                 }
1154         }
1155         if (len)
1156                 BUG();
1157         return csum;
1158 }
1159
1160 void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to)
1161 {
1162         unsigned int csum;
1163         long csstart;
1164
1165         if (skb->ip_summed == CHECKSUM_HW)
1166                 csstart = skb->h.raw - skb->data;
1167         else
1168                 csstart = skb_headlen(skb);
1169
1170         if (csstart > skb_headlen(skb))
1171                 BUG();
1172
1173         memcpy(to, skb->data, csstart);
1174
1175         csum = 0;
1176         if (csstart != skb->len)
1177                 csum = skb_copy_and_csum_bits(skb, csstart, to + csstart,
1178                                               skb->len - csstart, 0);
1179
1180         if (skb->ip_summed == CHECKSUM_HW) {
1181                 long csstuff = csstart + skb->csum;
1182
1183                 *((unsigned short *)(to + csstuff)) = csum_fold(csum);
1184         }
1185 }
1186
1187 /**
1188  *      skb_dequeue - remove from the head of the queue
1189  *      @list: list to dequeue from
1190  *
1191  *      Remove the head of the list. The list lock is taken so the function
1192  *      may be used safely with other locking list functions. The head item is
1193  *      returned or %NULL if the list is empty.
1194  */
1195
1196 struct sk_buff *skb_dequeue(struct sk_buff_head *list)
1197 {
1198         unsigned long flags;
1199         struct sk_buff *result;
1200
1201         spin_lock_irqsave(&list->lock, flags);
1202         result = __skb_dequeue(list);
1203         spin_unlock_irqrestore(&list->lock, flags);
1204         return result;
1205 }
1206
1207 /**
1208  *      skb_dequeue_tail - remove from the tail of the queue
1209  *      @list: list to dequeue from
1210  *
1211  *      Remove the tail of the list. The list lock is taken so the function
1212  *      may be used safely with other locking list functions. The tail item is
1213  *      returned or %NULL if the list is empty.
1214  */
1215 struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list)
1216 {
1217         unsigned long flags;
1218         struct sk_buff *result;
1219
1220         spin_lock_irqsave(&list->lock, flags);
1221         result = __skb_dequeue_tail(list);
1222         spin_unlock_irqrestore(&list->lock, flags);
1223         return result;
1224 }
1225
1226 /**
1227  *      skb_queue_purge - empty a list
1228  *      @list: list to empty
1229  *
1230  *      Delete all buffers on an &sk_buff list. Each buffer is removed from
1231  *      the list and one reference dropped. This function takes the list
1232  *      lock and is atomic with respect to other list locking functions.
1233  */
1234 void skb_queue_purge(struct sk_buff_head *list)
1235 {
1236         struct sk_buff *skb;
1237         while ((skb = skb_dequeue(list)) != NULL)
1238                 kfree_skb(skb);
1239 }
1240
1241 /**
1242  *      skb_queue_head - queue a buffer at the list head
1243  *      @list: list to use
1244  *      @newsk: buffer to queue
1245  *
1246  *      Queue a buffer at the start of the list. This function takes the
1247  *      list lock and can be used safely with other locking &sk_buff functions
1248  *      safely.
1249  *
1250  *      A buffer cannot be placed on two lists at the same time.
1251  */
1252 void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
1253 {
1254         unsigned long flags;
1255
1256         spin_lock_irqsave(&list->lock, flags);
1257         __skb_queue_head(list, newsk);
1258         spin_unlock_irqrestore(&list->lock, flags);
1259 }
1260
1261 /**
1262  *      skb_queue_tail - queue a buffer at the list tail
1263  *      @list: list to use
1264  *      @newsk: buffer to queue
1265  *
1266  *      Queue a buffer at the tail of the list. This function takes the
1267  *      list lock and can be used safely with other locking &sk_buff functions
1268  *      safely.
1269  *
1270  *      A buffer cannot be placed on two lists at the same time.
1271  */
1272 void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
1273 {
1274         unsigned long flags;
1275
1276         spin_lock_irqsave(&list->lock, flags);
1277         __skb_queue_tail(list, newsk);
1278         spin_unlock_irqrestore(&list->lock, flags);
1279 }
1280 /**
1281  *      skb_unlink      -       remove a buffer from a list
1282  *      @skb: buffer to remove
1283  *
1284  *      Place a packet after a given packet in a list. The list locks are taken
1285  *      and this function is atomic with respect to other list locked calls
1286  *
1287  *      Works even without knowing the list it is sitting on, which can be
1288  *      handy at times. It also means that THE LIST MUST EXIST when you
1289  *      unlink. Thus a list must have its contents unlinked before it is
1290  *      destroyed.
1291  */
1292 void skb_unlink(struct sk_buff *skb)
1293 {
1294         struct sk_buff_head *list = skb->list;
1295
1296         if (list) {
1297                 unsigned long flags;
1298
1299                 spin_lock_irqsave(&list->lock, flags);
1300                 if (skb->list == list)
1301                         __skb_unlink(skb, skb->list);
1302                 spin_unlock_irqrestore(&list->lock, flags);
1303         }
1304 }
1305
1306
1307 /**
1308  *      skb_append      -       append a buffer
1309  *      @old: buffer to insert after
1310  *      @newsk: buffer to insert
1311  *
1312  *      Place a packet after a given packet in a list. The list locks are taken
1313  *      and this function is atomic with respect to other list locked calls.
1314  *      A buffer cannot be placed on two lists at the same time.
1315  */
1316
1317 void skb_append(struct sk_buff *old, struct sk_buff *newsk)
1318 {
1319         unsigned long flags;
1320
1321         spin_lock_irqsave(&old->list->lock, flags);
1322         __skb_append(old, newsk);
1323         spin_unlock_irqrestore(&old->list->lock, flags);
1324 }
1325
1326
1327 /**
1328  *      skb_insert      -       insert a buffer
1329  *      @old: buffer to insert before
1330  *      @newsk: buffer to insert
1331  *
1332  *      Place a packet before a given packet in a list. The list locks are taken
1333  *      and this function is atomic with respect to other list locked calls
1334  *      A buffer cannot be placed on two lists at the same time.
1335  */
1336
1337 void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
1338 {
1339         unsigned long flags;
1340
1341         spin_lock_irqsave(&old->list->lock, flags);
1342         __skb_insert(newsk, old->prev, old, old->list);
1343         spin_unlock_irqrestore(&old->list->lock, flags);
1344 }
1345
1346 #if 0
1347 /*
1348  *      Tune the memory allocator for a new MTU size.
1349  */
1350 void skb_add_mtu(int mtu)
1351 {
1352         /* Must match allocation in alloc_skb */
1353         mtu = SKB_DATA_ALIGN(mtu) + sizeof(struct skb_shared_info);
1354
1355         kmem_add_cache_size(mtu);
1356 }
1357 #endif
1358
1359 static inline void skb_split_inside_header(struct sk_buff *skb,
1360                                            struct sk_buff* skb1,
1361                                            const u32 len, const int pos)
1362 {
1363         int i;
1364
1365         memcpy(skb_put(skb1, pos - len), skb->data + len, pos - len);
1366
1367         /* And move data appendix as is. */
1368         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
1369                 skb_shinfo(skb1)->frags[i] = skb_shinfo(skb)->frags[i];
1370
1371         skb_shinfo(skb1)->nr_frags = skb_shinfo(skb)->nr_frags;
1372         skb_shinfo(skb)->nr_frags  = 0;
1373         skb1->data_len             = skb->data_len;
1374         skb1->len                  += skb1->data_len;
1375         skb->data_len              = 0;
1376         skb->len                   = len;
1377         skb->tail                  = skb->data + len;
1378 }
1379
1380 static inline void skb_split_no_header(struct sk_buff *skb,
1381                                        struct sk_buff* skb1,
1382                                        const u32 len, int pos)
1383 {
1384         int i, k = 0;
1385         const int nfrags = skb_shinfo(skb)->nr_frags;
1386
1387         skb_shinfo(skb)->nr_frags = 0;
1388         skb1->len                 = skb1->data_len = skb->len - len;
1389         skb->len                  = len;
1390         skb->data_len             = len - pos;
1391
1392         for (i = 0; i < nfrags; i++) {
1393                 int size = skb_shinfo(skb)->frags[i].size;
1394
1395                 if (pos + size > len) {
1396                         skb_shinfo(skb1)->frags[k] = skb_shinfo(skb)->frags[i];
1397
1398                         if (pos < len) {
1399                                 /* Split frag.
1400                                  * We have to variants in this case:
1401                                  * 1. Move all the frag to the second
1402                                  *    part, if it is possible. F.e.
1403                                  *    this approach is mandatory for TUX,
1404                                  *    where splitting is expensive.
1405                                  * 2. Split is accurately. We make this.
1406                                  */
1407                                 get_page(skb_shinfo(skb)->frags[i].page);
1408                                 skb_shinfo(skb1)->frags[0].page_offset += len - pos;
1409                                 skb_shinfo(skb1)->frags[0].size -= len - pos;
1410                                 skb_shinfo(skb)->frags[i].size  = len - pos;
1411                                 skb_shinfo(skb)->nr_frags++;
1412                         }
1413                         k++;
1414                 } else
1415                         skb_shinfo(skb)->nr_frags++;
1416                 pos += size;
1417         }
1418         skb_shinfo(skb1)->nr_frags = k;
1419 }
1420
1421 /**
1422  * skb_split - Split fragmented skb to two parts at length len.
1423  */
1424 void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len)
1425 {
1426         int pos = skb_headlen(skb);
1427
1428         if (len < pos)  /* Split line is inside header. */
1429                 skb_split_inside_header(skb, skb1, len, pos);
1430         else            /* Second chunk has no header, nothing to copy. */
1431                 skb_split_no_header(skb, skb1, len, pos);
1432 }
1433
1434 void __init skb_init(void)
1435 {
1436         skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
1437                                               sizeof(struct sk_buff),
1438                                               0,
1439                                               SLAB_HWCACHE_ALIGN,
1440                                               NULL, NULL);
1441         if (!skbuff_head_cache)
1442                 panic("cannot create skbuff cache");
1443 }
1444
1445 EXPORT_SYMBOL(___pskb_trim);
1446 EXPORT_SYMBOL(__kfree_skb);
1447 EXPORT_SYMBOL(__pskb_pull_tail);
1448 EXPORT_SYMBOL(alloc_skb);
1449 EXPORT_SYMBOL(pskb_copy);
1450 EXPORT_SYMBOL(pskb_expand_head);
1451 EXPORT_SYMBOL(skb_checksum);
1452 EXPORT_SYMBOL(skb_clone);
1453 EXPORT_SYMBOL(skb_clone_fraglist);
1454 EXPORT_SYMBOL(skb_copy);
1455 EXPORT_SYMBOL(skb_copy_and_csum_bits);
1456 EXPORT_SYMBOL(skb_copy_and_csum_dev);
1457 EXPORT_SYMBOL(skb_copy_bits);
1458 EXPORT_SYMBOL(skb_copy_expand);
1459 EXPORT_SYMBOL(skb_over_panic);
1460 EXPORT_SYMBOL(skb_pad);
1461 EXPORT_SYMBOL(skb_realloc_headroom);
1462 EXPORT_SYMBOL(skb_under_panic);
1463 EXPORT_SYMBOL(skb_dequeue);
1464 EXPORT_SYMBOL(skb_dequeue_tail);
1465 EXPORT_SYMBOL(skb_insert);
1466 EXPORT_SYMBOL(skb_queue_purge);
1467 EXPORT_SYMBOL(skb_queue_head);
1468 EXPORT_SYMBOL(skb_queue_tail);
1469 EXPORT_SYMBOL(skb_unlink);
1470 EXPORT_SYMBOL(skb_append);
1471 EXPORT_SYMBOL(skb_split);
1472 EXPORT_SYMBOL(skb_iter_first);
1473 EXPORT_SYMBOL(skb_iter_next);
1474 EXPORT_SYMBOL(skb_iter_abort);