2 * Definitions for the 'struct sk_buff' memory handlers.
5 * Alan Cox, <gw4pts@gw4pts.ampr.org>
6 * Florian La Roche, <rzsfl@rz.uni-sb.de>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #ifndef _LINUX_SKBUFF_H
15 #define _LINUX_SKBUFF_H
17 #include <linux/config.h>
18 #include <linux/kernel.h>
19 #include <linux/compiler.h>
20 #include <linux/time.h>
21 #include <linux/cache.h>
23 #include <asm/atomic.h>
24 #include <asm/types.h>
25 #include <linux/spinlock.h>
27 #include <linux/highmem.h>
28 #include <linux/poll.h>
29 #include <linux/net.h>
31 #define HAVE_ALLOC_SKB /* For the drivers to know */
32 #define HAVE_ALIGNABLE_SKB /* Ditto 8) */
33 #define SLAB_SKB /* Slabified skbuffs */
35 #define CHECKSUM_NONE 0
37 #define CHECKSUM_UNNECESSARY 2
39 #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \
40 ~(SMP_CACHE_BYTES - 1))
41 #define SKB_MAX_ORDER(X, ORDER) (((PAGE_SIZE << (ORDER)) - (X) - \
42 sizeof(struct skb_shared_info)) & \
43 ~(SMP_CACHE_BYTES - 1))
44 #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0))
45 #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2))
47 /* A. Checksumming of received packets by device.
49 * NONE: device failed to checksum this packet.
50 * skb->csum is undefined.
52 * UNNECESSARY: device parsed packet and wouldbe verified checksum.
53 * skb->csum is undefined.
54 * It is bad option, but, unfortunately, many of vendors do this.
55 * Apparently with secret goal to sell you new device, when you
56 * will add new protocol to your host. F.e. IPv6. 8)
58 * HW: the most generic way. Device supplied checksum of _all_
59 * the packet as seen by netif_rx in skb->csum.
60 * NOTE: Even if device supports only some protocols, but
61 * is able to produce some skb->csum, it MUST use HW,
64 * B. Checksumming on output.
66 * NONE: skb is checksummed by protocol or csum is not required.
68 * HW: device is required to csum packet as seen by hard_start_xmit
69 * from skb->h.raw to the end and to record the checksum
70 * at skb->h.raw+skb->csum.
72 * Device must show its capabilities in dev->features, set
73 * at device setup time.
74 * NETIF_F_HW_CSUM - it is clever device, it is able to checksum
76 * NETIF_F_NO_CSUM - loopback or reliable single hop media.
77 * NETIF_F_IP_CSUM - device is dumb. It is able to csum only
78 * TCP/UDP over IPv4. Sigh. Vendors like this
79 * way by an unknown reason. Though, see comment above
80 * about CHECKSUM_UNNECESSARY. 8)
82 * Any questions? No questions, good. --ANK
86 #define NET_CALLER(arg) (*(((void **)&arg) - 1))
88 #define NET_CALLER(arg) __builtin_return_address(0)
91 #ifdef CONFIG_NETFILTER
94 void (*destroy)(struct nf_conntrack *);
98 struct nf_conntrack *master;
101 #ifdef CONFIG_BRIDGE_NETFILTER
102 struct nf_bridge_info {
104 struct net_device *physindev;
105 struct net_device *physoutdev;
106 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
107 struct net_device *netoutdev;
110 unsigned long data[32 / sizeof(unsigned long)];
116 struct sk_buff_head {
117 /* These two members must be first. */
118 struct sk_buff *next;
119 struct sk_buff *prev;
127 /* To allow 64K frame to be packed as single skb without frag_list */
128 #define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2)
130 typedef struct skb_frag_struct skb_frag_t;
132 struct skb_frag_struct {
138 /* This data is invariant across clones and lives at
139 * the end of the header data, ie. at skb->end.
141 struct skb_shared_info {
143 unsigned int nr_frags;
144 unsigned short tso_size;
145 unsigned short tso_segs;
146 struct sk_buff *frag_list;
147 skb_frag_t frags[MAX_SKB_FRAGS];
151 * struct sk_buff - socket buffer
152 * @next: Next buffer in list
153 * @prev: Previous buffer in list
154 * @list: List we are on
155 * @sk: Socket we are owned by
156 * @stamp: Time we arrived
157 * @dev: Device we arrived on/are leaving by
158 * @real_dev: The real device we are using
159 * @h: Transport layer header
160 * @nh: Network layer header
161 * @mac: Link layer header
162 * @dst: FIXME: Describe this field
163 * @cb: Control buffer. Free for use by every layer. Put private vars here
164 * @len: Length of actual data
165 * @data_len: Data length
166 * @mac_len: Length of link layer header
168 * @__unused: Dead field, may be reused
169 * @cloned: Head may be cloned (check refcnt to be sure)
170 * @pkt_type: Packet class
171 * @ip_summed: Driver fed us an IP checksum
172 * @priority: Packet queueing priority
173 * @users: User count - see {datagram,tcp}.c
174 * @protocol: Packet protocol from driver
175 * @security: Security level of packet
176 * @truesize: Buffer size
177 * @head: Head of buffer
178 * @data: Data head pointer
179 * @tail: Tail pointer
181 * @destructor: Destruct function
182 * @nfmark: Can be used for communication between hooks
183 * @nfcache: Cache info
184 * @nfct: Associated connection, if any
185 * @nf_debug: Netfilter debugging
186 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
187 * @private: Data which is private to the HIPPI implementation
188 * @tc_index: Traffic control index
192 /* These two members must be first. */
193 struct sk_buff *next;
194 struct sk_buff *prev;
196 struct sk_buff_head *list;
198 struct timeval stamp;
199 struct net_device *dev;
200 struct net_device *real_dev;
205 struct icmphdr *icmph;
206 struct igmphdr *igmph;
208 struct ipv6hdr *ipv6h;
214 struct ipv6hdr *ipv6h;
220 struct ethhdr *ethernet;
224 struct dst_entry *dst;
228 * This is the control buffer. It is free to use for every
229 * layer. Please put your private variables there. If you
230 * want to keep them across layers you have to do a skb_clone()
231 * first. This is owned by whoever has the skb queued ATM.
239 unsigned char local_df,
244 unsigned short protocol,
247 void (*destructor)(struct sk_buff *skb);
248 #ifdef CONFIG_NETFILTER
249 unsigned long nfmark;
251 struct nf_ct_info *nfct;
252 #ifdef CONFIG_NETFILTER_DEBUG
253 unsigned int nf_debug;
255 #ifdef CONFIG_BRIDGE_NETFILTER
256 struct nf_bridge_info *nf_bridge;
258 #endif /* CONFIG_NETFILTER */
259 #if defined(CONFIG_HIPPI)
264 #ifdef CONFIG_NET_SCHED
265 __u32 tc_index; /* traffic control index */
268 /* These elements must be at the end, see alloc_skb() for details. */
269 unsigned int truesize;
279 * Handling routines are only of interest to the kernel
281 #include <linux/slab.h>
283 #include <asm/system.h>
285 extern void __kfree_skb(struct sk_buff *skb);
286 extern struct sk_buff *alloc_skb(unsigned int size, int priority);
287 extern void kfree_skbmem(struct sk_buff *skb);
288 extern struct sk_buff *skb_clone(struct sk_buff *skb, int priority);
289 extern struct sk_buff *skb_copy(const struct sk_buff *skb, int priority);
290 extern struct sk_buff *pskb_copy(struct sk_buff *skb, int gfp_mask);
291 extern int pskb_expand_head(struct sk_buff *skb,
292 int nhead, int ntail, int gfp_mask);
293 extern struct sk_buff *skb_realloc_headroom(struct sk_buff *skb,
294 unsigned int headroom);
295 extern struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
296 int newheadroom, int newtailroom,
298 extern struct sk_buff * skb_pad(struct sk_buff *skb, int pad);
299 #define dev_kfree_skb(a) kfree_skb(a)
300 extern void skb_over_panic(struct sk_buff *skb, int len,
302 extern void skb_under_panic(struct sk_buff *skb, int len,
306 #define skb_shinfo(SKB) ((struct skb_shared_info *)((SKB)->end))
309 * skb_queue_empty - check if a queue is empty
312 * Returns true if the queue is empty, false otherwise.
314 static inline int skb_queue_empty(const struct sk_buff_head *list)
316 return list->next == (struct sk_buff *)list;
320 * skb_get - reference buffer
321 * @skb: buffer to reference
323 * Makes another reference to a socket buffer and returns a pointer
326 static inline struct sk_buff *skb_get(struct sk_buff *skb)
328 atomic_inc(&skb->users);
333 * If users == 1, we are the only owner and are can avoid redundant
338 * kfree_skb - free an sk_buff
339 * @skb: buffer to free
341 * Drop a reference to the buffer and free it if the usage count has
344 static inline void kfree_skb(struct sk_buff *skb)
346 if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
350 /* Use this if you didn't touch the skb state [for fast switching] */
351 static inline void kfree_skb_fast(struct sk_buff *skb)
353 if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
358 * skb_cloned - is the buffer a clone
359 * @skb: buffer to check
361 * Returns true if the buffer was generated with skb_clone() and is
362 * one of multiple shared copies of the buffer. Cloned buffers are
363 * shared data so must not be written to under normal circumstances.
365 static inline int skb_cloned(const struct sk_buff *skb)
367 return skb->cloned && atomic_read(&skb_shinfo(skb)->dataref) != 1;
371 * skb_shared - is the buffer shared
372 * @skb: buffer to check
374 * Returns true if more than one person has a reference to this
377 static inline int skb_shared(const struct sk_buff *skb)
379 return atomic_read(&skb->users) != 1;
383 * skb_share_check - check if buffer is shared and if so clone it
384 * @skb: buffer to check
385 * @pri: priority for memory allocation
387 * If the buffer is shared the buffer is cloned and the old copy
388 * drops a reference. A new clone with a single reference is returned.
389 * If the buffer is not shared the original buffer is returned. When
390 * being called from interrupt status or with spinlocks held pri must
393 * NULL is returned on a memory allocation failure.
395 static inline struct sk_buff *skb_share_check(struct sk_buff *skb, int pri)
397 might_sleep_if(pri & __GFP_WAIT);
398 if (skb_shared(skb)) {
399 struct sk_buff *nskb = skb_clone(skb, pri);
407 * Copy shared buffers into a new sk_buff. We effectively do COW on
408 * packets to handle cases where we have a local reader and forward
409 * and a couple of other messy ones. The normal one is tcpdumping
410 * a packet thats being forwarded.
414 * skb_unshare - make a copy of a shared buffer
415 * @skb: buffer to check
416 * @pri: priority for memory allocation
418 * If the socket buffer is a clone then this function creates a new
419 * copy of the data, drops a reference count on the old copy and returns
420 * the new copy with the reference count at 1. If the buffer is not a clone
421 * the original buffer is returned. When called with a spinlock held or
422 * from interrupt state @pri must be %GFP_ATOMIC
424 * %NULL is returned on a memory allocation failure.
426 static inline struct sk_buff *skb_unshare(struct sk_buff *skb, int pri)
428 might_sleep_if(pri & __GFP_WAIT);
429 if (skb_cloned(skb)) {
430 struct sk_buff *nskb = skb_copy(skb, pri);
431 kfree_skb(skb); /* Free our shared copy */
439 * @list_: list to peek at
441 * Peek an &sk_buff. Unlike most other operations you _MUST_
442 * be careful with this one. A peek leaves the buffer on the
443 * list and someone else may run off with it. You must hold
444 * the appropriate locks or have a private queue to do this.
446 * Returns %NULL for an empty list or a pointer to the head element.
447 * The reference count is not incremented and the reference is therefore
448 * volatile. Use with caution.
450 static inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
452 struct sk_buff *list = ((struct sk_buff *)list_)->next;
453 if (list == (struct sk_buff *)list_)
460 * @list_: list to peek at
462 * Peek an &sk_buff. Unlike most other operations you _MUST_
463 * be careful with this one. A peek leaves the buffer on the
464 * list and someone else may run off with it. You must hold
465 * the appropriate locks or have a private queue to do this.
467 * Returns %NULL for an empty list or a pointer to the tail element.
468 * The reference count is not incremented and the reference is therefore
469 * volatile. Use with caution.
471 static inline struct sk_buff *skb_peek_tail(struct sk_buff_head *list_)
473 struct sk_buff *list = ((struct sk_buff *)list_)->prev;
474 if (list == (struct sk_buff *)list_)
480 * skb_queue_len - get queue length
481 * @list_: list to measure
483 * Return the length of an &sk_buff queue.
485 static inline __u32 skb_queue_len(const struct sk_buff_head *list_)
490 static inline void skb_queue_head_init(struct sk_buff_head *list)
492 spin_lock_init(&list->lock);
493 list->prev = list->next = (struct sk_buff *)list;
498 * Insert an sk_buff at the start of a list.
500 * The "__skb_xxxx()" functions are the non-atomic ones that
501 * can only be called with interrupts disabled.
505 * __skb_queue_head - queue a buffer at the list head
507 * @newsk: buffer to queue
509 * Queue a buffer at the start of a list. This function takes no locks
510 * and you must therefore hold required locks before calling it.
512 * A buffer cannot be placed on two lists at the same time.
514 extern void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk);
515 static inline void __skb_queue_head(struct sk_buff_head *list,
516 struct sk_buff *newsk)
518 struct sk_buff *prev, *next;
522 prev = (struct sk_buff *)list;
526 next->prev = prev->next = newsk;
530 * __skb_queue_tail - queue a buffer at the list tail
532 * @newsk: buffer to queue
534 * Queue a buffer at the end of a list. This function takes no locks
535 * and you must therefore hold required locks before calling it.
537 * A buffer cannot be placed on two lists at the same time.
539 extern void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk);
540 static inline void __skb_queue_tail(struct sk_buff_head *list,
541 struct sk_buff *newsk)
543 struct sk_buff *prev, *next;
547 next = (struct sk_buff *)list;
551 next->prev = prev->next = newsk;
556 * __skb_dequeue - remove from the head of the queue
557 * @list: list to dequeue from
559 * Remove the head of the list. This function does not take any locks
560 * so must be used with appropriate locks held only. The head item is
561 * returned or %NULL if the list is empty.
563 extern struct sk_buff *skb_dequeue(struct sk_buff_head *list);
564 static inline struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
566 struct sk_buff *next, *prev, *result;
568 prev = (struct sk_buff *) list;
577 result->next = result->prev = NULL;
585 * Insert a packet on a list.
587 extern void skb_insert(struct sk_buff *old, struct sk_buff *newsk);
588 static inline void __skb_insert(struct sk_buff *newsk,
589 struct sk_buff *prev, struct sk_buff *next,
590 struct sk_buff_head *list)
594 next->prev = prev->next = newsk;
600 * Place a packet after a given packet in a list.
602 extern void skb_append(struct sk_buff *old, struct sk_buff *newsk);
603 static inline void __skb_append(struct sk_buff *old, struct sk_buff *newsk)
605 __skb_insert(newsk, old, old->next, old->list);
609 * remove sk_buff from list. _Must_ be called atomically, and with
612 extern void skb_unlink(struct sk_buff *skb);
613 static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
615 struct sk_buff *next, *prev;
620 skb->next = skb->prev = NULL;
627 /* XXX: more streamlined implementation */
630 * __skb_dequeue_tail - remove from the tail of the queue
631 * @list: list to dequeue from
633 * Remove the tail of the list. This function does not take any locks
634 * so must be used with appropriate locks held only. The tail item is
635 * returned or %NULL if the list is empty.
637 extern struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list);
638 static inline struct sk_buff *__skb_dequeue_tail(struct sk_buff_head *list)
640 struct sk_buff *skb = skb_peek_tail(list);
642 __skb_unlink(skb, list);
647 static inline int skb_is_nonlinear(const struct sk_buff *skb)
649 return skb->data_len;
652 static inline unsigned int skb_headlen(const struct sk_buff *skb)
654 return skb->len - skb->data_len;
657 static inline int skb_pagelen(const struct sk_buff *skb)
661 for (i = (int)skb_shinfo(skb)->nr_frags - 1; i >= 0; i--)
662 len += skb_shinfo(skb)->frags[i].size;
663 return len + skb_headlen(skb);
666 static inline void skb_fill_page_desc(struct sk_buff *skb, int i, struct page *page, int off, int size)
668 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
670 frag->page_offset = off;
672 skb_shinfo(skb)->nr_frags = i+1;
675 #define SKB_PAGE_ASSERT(skb) BUG_ON(skb_shinfo(skb)->nr_frags)
676 #define SKB_FRAG_ASSERT(skb) BUG_ON(skb_shinfo(skb)->frag_list)
677 #define SKB_LINEAR_ASSERT(skb) BUG_ON(skb_is_nonlinear(skb))
680 * Add data to an sk_buff
682 static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len)
684 unsigned char *tmp = skb->tail;
685 SKB_LINEAR_ASSERT(skb);
692 * skb_put - add data to a buffer
693 * @skb: buffer to use
694 * @len: amount of data to add
696 * This function extends the used data area of the buffer. If this would
697 * exceed the total buffer size the kernel will panic. A pointer to the
698 * first byte of the extra data is returned.
700 static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
702 unsigned char *tmp = skb->tail;
703 SKB_LINEAR_ASSERT(skb);
706 if (unlikely(skb->tail>skb->end))
707 skb_over_panic(skb, len, current_text_addr());
711 static inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len)
719 * skb_push - add data to the start of a buffer
720 * @skb: buffer to use
721 * @len: amount of data to add
723 * This function extends the used data area of the buffer at the buffer
724 * start. If this would exceed the total buffer headroom the kernel will
725 * panic. A pointer to the first byte of the extra data is returned.
727 static inline unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
731 if (unlikely(skb->data<skb->head))
732 skb_under_panic(skb, len, current_text_addr());
736 static inline unsigned char *__skb_pull(struct sk_buff *skb, unsigned int len)
739 BUG_ON(skb->len < skb->data_len);
740 return skb->data += len;
744 * skb_pull - remove data from the start of a buffer
745 * @skb: buffer to use
746 * @len: amount of data to remove
748 * This function removes data from the start of a buffer, returning
749 * the memory to the headroom. A pointer to the next data in the buffer
750 * is returned. Once the data has been pulled future pushes will overwrite
753 static inline unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
755 return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
758 extern unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta);
760 static inline unsigned char *__pskb_pull(struct sk_buff *skb, unsigned int len)
762 if (len > skb_headlen(skb) &&
763 !__pskb_pull_tail(skb, len-skb_headlen(skb)))
766 return skb->data += len;
769 static inline unsigned char *pskb_pull(struct sk_buff *skb, unsigned int len)
771 return unlikely(len > skb->len) ? NULL : __pskb_pull(skb, len);
774 static inline int pskb_may_pull(struct sk_buff *skb, unsigned int len)
776 if (likely(len <= skb_headlen(skb)))
778 if (unlikely(len > skb->len))
780 return __pskb_pull_tail(skb, len-skb_headlen(skb)) != NULL;
784 * skb_headroom - bytes at buffer head
785 * @skb: buffer to check
787 * Return the number of bytes of free space at the head of an &sk_buff.
789 static inline int skb_headroom(const struct sk_buff *skb)
791 return skb->data - skb->head;
795 * skb_tailroom - bytes at buffer end
796 * @skb: buffer to check
798 * Return the number of bytes of free space at the tail of an sk_buff
800 static inline int skb_tailroom(const struct sk_buff *skb)
802 return skb_is_nonlinear(skb) ? 0 : skb->end - skb->tail;
806 * skb_reserve - adjust headroom
807 * @skb: buffer to alter
808 * @len: bytes to move
810 * Increase the headroom of an empty &sk_buff by reducing the tail
811 * room. This is only allowed for an empty buffer.
813 static inline void skb_reserve(struct sk_buff *skb, unsigned int len)
819 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len, int realloc);
821 static inline void __skb_trim(struct sk_buff *skb, unsigned int len)
823 if (!skb->data_len) {
825 skb->tail = skb->data + len;
827 ___pskb_trim(skb, len, 0);
831 * skb_trim - remove end from a buffer
832 * @skb: buffer to alter
835 * Cut the length of a buffer down by removing data from the tail. If
836 * the buffer is already under the length specified it is not modified.
838 static inline void skb_trim(struct sk_buff *skb, unsigned int len)
841 __skb_trim(skb, len);
845 static inline int __pskb_trim(struct sk_buff *skb, unsigned int len)
847 if (!skb->data_len) {
849 skb->tail = skb->data+len;
852 return ___pskb_trim(skb, len, 1);
855 static inline int pskb_trim(struct sk_buff *skb, unsigned int len)
857 return (len < skb->len) ? __pskb_trim(skb, len) : 0;
861 * skb_orphan - orphan a buffer
862 * @skb: buffer to orphan
864 * If a buffer currently has an owner then we call the owner's
865 * destructor function and make the @skb unowned. The buffer continues
866 * to exist but is no longer charged to its former owner.
868 static inline void skb_orphan(struct sk_buff *skb)
871 skb->destructor(skb);
872 skb->destructor = NULL;
877 * __skb_queue_purge - empty a list
878 * @list: list to empty
880 * Delete all buffers on an &sk_buff list. Each buffer is removed from
881 * the list and one reference dropped. This function does not take the
882 * list lock and the caller must hold the relevant locks to use it.
884 extern void skb_queue_purge(struct sk_buff_head *list);
885 static inline void __skb_queue_purge(struct sk_buff_head *list)
888 while ((skb = __skb_dequeue(list)) != NULL)
893 * __dev_alloc_skb - allocate an skbuff for sending
894 * @length: length to allocate
895 * @gfp_mask: get_free_pages mask, passed to alloc_skb
897 * Allocate a new &sk_buff and assign it a usage count of one. The
898 * buffer has unspecified headroom built in. Users should allocate
899 * the headroom they think they need without accounting for the
900 * built in space. The built in space is used for optimisations.
902 * %NULL is returned in there is no free memory.
904 static inline struct sk_buff *__dev_alloc_skb(unsigned int length,
907 struct sk_buff *skb = alloc_skb(length + 16, gfp_mask);
909 skb_reserve(skb, 16);
914 * dev_alloc_skb - allocate an skbuff for sending
915 * @length: length to allocate
917 * Allocate a new &sk_buff and assign it a usage count of one. The
918 * buffer has unspecified headroom built in. Users should allocate
919 * the headroom they think they need without accounting for the
920 * built in space. The built in space is used for optimisations.
922 * %NULL is returned in there is no free memory. Although this function
923 * allocates memory it can be called from an interrupt.
925 static inline struct sk_buff *dev_alloc_skb(unsigned int length)
927 return __dev_alloc_skb(length, GFP_ATOMIC);
931 * skb_cow - copy header of skb when it is required
932 * @skb: buffer to cow
933 * @headroom: needed headroom
935 * If the skb passed lacks sufficient headroom or its data part
936 * is shared, data is reallocated. If reallocation fails, an error
937 * is returned and original skb is not changed.
939 * The result is skb with writable area skb->head...skb->tail
940 * and at least @headroom of space at head.
942 static inline int skb_cow(struct sk_buff *skb, unsigned int headroom)
944 int delta = (headroom > 16 ? headroom : 16) - skb_headroom(skb);
949 if (delta || skb_cloned(skb))
950 return pskb_expand_head(skb, (delta + 15) & ~15, 0, GFP_ATOMIC);
955 * skb_padto - pad an skbuff up to a minimal size
956 * @skb: buffer to pad
957 * @len: minimal length
959 * Pads up a buffer to ensure the trailing bytes exist and are
960 * blanked. If the buffer already contains sufficient data it
961 * is untouched. Returns the buffer, which may be a replacement
962 * for the original, or NULL for out of memory - in which case
963 * the original buffer is still freed.
966 static inline struct sk_buff *skb_padto(struct sk_buff *skb, unsigned int len)
968 unsigned int size = skb->len;
969 if (likely(size >= len))
971 return skb_pad(skb, len-size);
975 * skb_linearize - convert paged skb to linear one
976 * @skb: buffer to linarize
977 * @gfp: allocation mode
979 * If there is no free memory -ENOMEM is returned, otherwise zero
980 * is returned and the old skb data released.
982 extern int __skb_linearize(struct sk_buff *skb, int gfp);
983 static inline int skb_linearize(struct sk_buff *skb, int gfp)
985 return __skb_linearize(skb, gfp);
988 static inline void *kmap_skb_frag(const skb_frag_t *frag)
990 #ifdef CONFIG_HIGHMEM
995 return kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ);
998 static inline void kunmap_skb_frag(void *vaddr)
1000 kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
1001 #ifdef CONFIG_HIGHMEM
1006 #define skb_queue_walk(queue, skb) \
1007 for (skb = (queue)->next, prefetch(skb->next); \
1008 (skb != (struct sk_buff *)(queue)); \
1009 skb = skb->next, prefetch(skb->next))
1012 extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
1013 int noblock, int *err);
1014 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
1015 struct poll_table_struct *wait);
1016 extern int skb_copy_datagram(const struct sk_buff *from,
1017 int offset, char __user *to, int size);
1018 extern int skb_copy_datagram_iovec(const struct sk_buff *from,
1019 int offset, struct iovec *to,
1021 extern int skb_copy_and_csum_datagram(const struct sk_buff *skb,
1022 int offset, u8 __user *to,
1023 int len, unsigned int *csump);
1024 extern int skb_copy_and_csum_datagram_iovec(const
1025 struct sk_buff *skb,
1028 extern void skb_free_datagram(struct sock *sk, struct sk_buff *skb);
1029 extern unsigned int skb_checksum(const struct sk_buff *skb, int offset,
1030 int len, unsigned int csum);
1031 extern int skb_copy_bits(const struct sk_buff *skb, int offset,
1033 extern unsigned int skb_copy_and_csum_bits(const struct sk_buff *skb,
1034 int offset, u8 *to, int len,
1036 extern void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to);
1038 extern void skb_init(void);
1039 extern void skb_add_mtu(int mtu);
1041 struct tux_req_struct;
1043 #ifdef CONFIG_NETFILTER
1044 static inline void nf_conntrack_put(struct nf_ct_info *nfct)
1046 if (nfct && atomic_dec_and_test(&nfct->master->use))
1047 nfct->master->destroy(nfct->master);
1049 static inline void nf_conntrack_get(struct nf_ct_info *nfct)
1052 atomic_inc(&nfct->master->use);
1055 #ifdef CONFIG_BRIDGE_NETFILTER
1056 static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1058 if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
1061 static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1064 atomic_inc(&nf_bridge->use);
1070 #endif /* __KERNEL__ */
1071 #endif /* _LINUX_SKBUFF_H */