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/kernel.h>
18 #include <linux/compiler.h>
19 #include <linux/time.h>
20 #include <linux/cache.h>
22 #include <asm/atomic.h>
23 #include <asm/types.h>
24 #include <linux/spinlock.h>
25 #include <linux/net.h>
26 #include <linux/textsearch.h>
27 #include <net/checksum.h>
28 #include <linux/rcupdate.h>
29 #include <linux/dmaengine.h>
30 #include <linux/hrtimer.h>
32 #define HAVE_ALLOC_SKB /* For the drivers to know */
33 #define HAVE_ALIGNABLE_SKB /* Ditto 8) */
35 /* Don't change this without changing skb_csum_unnecessary! */
36 #define CHECKSUM_NONE 0
37 #define CHECKSUM_UNNECESSARY 1
38 #define CHECKSUM_COMPLETE 2
39 #define CHECKSUM_PARTIAL 3
41 #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \
42 ~(SMP_CACHE_BYTES - 1))
43 #define SKB_WITH_OVERHEAD(X) \
44 ((X) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
45 #define SKB_MAX_ORDER(X, ORDER) \
46 SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X))
47 #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0))
48 #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2))
50 /* A. Checksumming of received packets by device.
52 * NONE: device failed to checksum this packet.
53 * skb->csum is undefined.
55 * UNNECESSARY: device parsed packet and wouldbe verified checksum.
56 * skb->csum is undefined.
57 * It is bad option, but, unfortunately, many of vendors do this.
58 * Apparently with secret goal to sell you new device, when you
59 * will add new protocol to your host. F.e. IPv6. 8)
61 * COMPLETE: the most generic way. Device supplied checksum of _all_
62 * the packet as seen by netif_rx in skb->csum.
63 * NOTE: Even if device supports only some protocols, but
64 * is able to produce some skb->csum, it MUST use COMPLETE,
67 * B. Checksumming on output.
69 * NONE: skb is checksummed by protocol or csum is not required.
71 * PARTIAL: device is required to csum packet as seen by hard_start_xmit
72 * from skb->transport_header to the end and to record the checksum
73 * at skb->transport_header + skb->csum.
75 * Device must show its capabilities in dev->features, set
76 * at device setup time.
77 * NETIF_F_HW_CSUM - it is clever device, it is able to checksum
79 * NETIF_F_NO_CSUM - loopback or reliable single hop media.
80 * NETIF_F_IP_CSUM - device is dumb. It is able to csum only
81 * TCP/UDP over IPv4. Sigh. Vendors like this
82 * way by an unknown reason. Though, see comment above
83 * about CHECKSUM_UNNECESSARY. 8)
85 * Any questions? No questions, good. --ANK
90 struct pipe_inode_info
;
92 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
98 #ifdef CONFIG_BRIDGE_NETFILTER
99 struct nf_bridge_info
{
101 struct net_device
*physindev
;
102 struct net_device
*physoutdev
;
103 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
104 struct net_device
*netoutdev
;
107 unsigned long data
[32 / sizeof(unsigned long)];
111 struct sk_buff_head
{
112 /* These two members must be first. */
113 struct sk_buff
*next
;
114 struct sk_buff
*prev
;
122 /* To allow 64K frame to be packed as single skb without frag_list */
123 #define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2)
125 typedef struct skb_frag_struct skb_frag_t
;
127 struct skb_frag_struct
{
133 /* This data is invariant across clones and lives at
134 * the end of the header data, ie. at skb->end.
136 struct skb_shared_info
{
138 unsigned short nr_frags
;
139 unsigned short gso_size
;
140 /* Warning: this field is not always filled in (UFO)! */
141 unsigned short gso_segs
;
142 unsigned short gso_type
;
144 struct sk_buff
*frag_list
;
146 /* Intermediate layers must ensure that destructor_arg
147 * remains valid until skb destructor */
148 void * destructor_arg
;
150 /* must be last field, see pskb_expand_head() */
151 skb_frag_t frags
[MAX_SKB_FRAGS
];
154 /* We divide dataref into two halves. The higher 16 bits hold references
155 * to the payload part of skb->data. The lower 16 bits hold references to
156 * the entire skb->data. A clone of a headerless skb holds the length of
157 * the header in skb->hdr_len.
159 * All users must obey the rule that the skb->data reference count must be
160 * greater than or equal to the payload reference count.
162 * Holding a reference to the payload part means that the user does not
163 * care about modifications to the header part of skb->data.
165 #define SKB_DATAREF_SHIFT 16
166 #define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1)
170 SKB_FCLONE_UNAVAILABLE
,
176 SKB_GSO_TCPV4
= 1 << 0,
177 SKB_GSO_UDP
= 1 << 1,
179 /* This indicates the skb is from an untrusted source. */
180 SKB_GSO_DODGY
= 1 << 2,
182 /* This indicates the tcp segment has CWR set. */
183 SKB_GSO_TCP_ECN
= 1 << 3,
185 SKB_GSO_TCPV6
= 1 << 4,
188 #if BITS_PER_LONG > 32
189 #define NET_SKBUFF_DATA_USES_OFFSET 1
192 #ifdef NET_SKBUFF_DATA_USES_OFFSET
193 typedef unsigned int sk_buff_data_t
;
195 typedef unsigned char *sk_buff_data_t
;
199 * struct sk_buff - socket buffer
200 * @next: Next buffer in list
201 * @prev: Previous buffer in list
202 * @sk: Socket we are owned by
203 * @tstamp: Time we arrived
204 * @dev: Device we arrived on/are leaving by
205 * @iif: ifindex of device we arrived on
206 * @transport_header: Transport layer header
207 * @network_header: Network layer header
208 * @mac_header: Link layer header
209 * @dst: destination entry
210 * @sp: the security path, used for xfrm
211 * @cb: Control buffer. Free for use by every layer. Put private vars here
212 * @len: Length of actual data
213 * @data_len: Data length
214 * @mac_len: Length of link layer header
215 * @hdr_len: writable header length of cloned skb
216 * @csum: Checksum (must include start/offset pair)
217 * @csum_start: Offset from skb->head where checksumming should start
218 * @csum_offset: Offset from csum_start where checksum should be stored
219 * @local_df: allow local fragmentation
220 * @cloned: Head may be cloned (check refcnt to be sure)
221 * @nohdr: Payload reference only, must not modify header
222 * @pkt_type: Packet class
223 * @fclone: skbuff clone status
224 * @ip_summed: Driver fed us an IP checksum
225 * @priority: Packet queueing priority
226 * @users: User count - see {datagram,tcp}.c
227 * @protocol: Packet protocol from driver
228 * @truesize: Buffer size
229 * @head: Head of buffer
230 * @data: Data head pointer
231 * @tail: Tail pointer
233 * @destructor: Destruct function
234 * @mark: Generic packet mark
235 * @nfct: Associated connection, if any
236 * @ipvs_property: skbuff is owned by ipvs
237 * @nfctinfo: Relationship of this skb to the connection
238 * @nfct_reasm: netfilter conntrack re-assembly pointer
239 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
240 * @tc_index: Traffic control index
241 * @tc_verd: traffic control verdict
242 * @dma_cookie: a cookie to one of several possible DMA operations
243 * done by skb DMA functions
244 * @secmark: security marking
245 * @vlan_tci: vlan tag control information
249 /* These two members must be first. */
250 struct sk_buff
*next
;
251 struct sk_buff
*prev
;
255 struct net_device
*dev
;
257 /* 4 byte hole on 64 bit*/
259 struct dst_entry
*dst
;
263 * This is the control buffer. It is free to use for every
264 * layer. Please put your private variables there. If you
265 * want to keep them across layers you have to do a skb_clone()
266 * first. This is owned by whoever has the skb queued ATM.
273 __u16 ctf_mac_len
, /* This field is used by Broadcom CTF driver! */
296 void (*destructor
)(struct sk_buff
*skb
);
300 sk_buff_data_t transport_header
;
301 sk_buff_data_t network_header
;
302 sk_buff_data_t mac_header
;
303 /* These elements must be at the end, see alloc_skb() for details. */
308 unsigned int truesize
;
310 unsigned char wl_idx
;
311 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
312 struct nf_conntrack
*nfct
;
313 struct sk_buff
*nfct_reasm
;
320 #ifdef CONFIG_BRIDGE_NETFILTER
321 struct nf_bridge_info
*nf_bridge
;
323 #ifdef CONFIG_NET_SCHED
324 __u16 tc_index
; /* traffic control index */
325 //#ifdef CONFIG_NET_CLS_ACT
326 __u16 tc_verd
; /* traffic control verdict */
329 #ifdef CONFIG_NET_DMA
330 dma_cookie_t dma_cookie
;
332 #ifdef CONFIG_NETWORK_SECMARK
336 #if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
338 struct nf_info
*nf_info
;
344 * Handling routines are only of interest to the kernel
346 #include <linux/slab.h>
348 #include <asm/system.h>
350 extern void kfree_skb(struct sk_buff
*skb
);
351 extern void __kfree_skb(struct sk_buff
*skb
);
352 extern struct sk_buff
*__alloc_skb(unsigned int size
,
353 gfp_t priority
, int fclone
, int node
);
354 static inline struct sk_buff
*alloc_skb(unsigned int size
,
357 return __alloc_skb(size
, priority
, 0, -1);
360 static inline struct sk_buff
*alloc_skb_fclone(unsigned int size
,
363 return __alloc_skb(size
, priority
, 1, -1);
366 extern struct sk_buff
*skb_morph(struct sk_buff
*dst
, struct sk_buff
*src
);
367 extern struct sk_buff
*skb_clone(struct sk_buff
*skb
,
369 extern struct sk_buff
*skb_copy(const struct sk_buff
*skb
,
371 extern struct sk_buff
*pskb_copy(struct sk_buff
*skb
,
373 extern int pskb_expand_head(struct sk_buff
*skb
,
374 int nhead
, int ntail
,
376 extern struct sk_buff
*skb_realloc_headroom(struct sk_buff
*skb
,
377 unsigned int headroom
);
378 extern struct sk_buff
*skb_copy_expand(const struct sk_buff
*skb
,
379 int newheadroom
, int newtailroom
,
381 extern int skb_to_sgvec(struct sk_buff
*skb
,
382 struct scatterlist
*sg
, int offset
,
384 extern int skb_cow_data(struct sk_buff
*skb
, int tailbits
,
385 struct sk_buff
**trailer
);
386 extern int skb_pad(struct sk_buff
*skb
, int pad
);
387 #define dev_kfree_skb(a) kfree_skb(a)
388 extern void skb_over_panic(struct sk_buff
*skb
, int len
,
390 extern void skb_under_panic(struct sk_buff
*skb
, int len
,
393 extern int skb_append_datato_frags(struct sock
*sk
, struct sk_buff
*skb
,
394 int getfrag(void *from
, char *to
, int offset
,
395 int len
,int odd
, struct sk_buff
*skb
),
396 void *from
, int length
);
403 __u32 stepped_offset
;
404 struct sk_buff
*root_skb
;
405 struct sk_buff
*cur_skb
;
409 extern void skb_prepare_seq_read(struct sk_buff
*skb
,
410 unsigned int from
, unsigned int to
,
411 struct skb_seq_state
*st
);
412 extern unsigned int skb_seq_read(unsigned int consumed
, const u8
**data
,
413 struct skb_seq_state
*st
);
414 extern void skb_abort_seq_read(struct skb_seq_state
*st
);
416 extern unsigned int skb_find_text(struct sk_buff
*skb
, unsigned int from
,
417 unsigned int to
, struct ts_config
*config
,
418 struct ts_state
*state
);
420 #ifdef NET_SKBUFF_DATA_USES_OFFSET
421 static inline unsigned char *skb_end_pointer(const struct sk_buff
*skb
)
423 return skb
->head
+ skb
->end
;
426 static inline unsigned char *skb_end_pointer(const struct sk_buff
*skb
)
433 #define skb_shinfo(SKB) ((struct skb_shared_info *)(skb_end_pointer(SKB)))
436 * skb_queue_empty - check if a queue is empty
439 * Returns true if the queue is empty, false otherwise.
441 static inline int skb_queue_empty(const struct sk_buff_head
*list
)
443 return list
->next
== (struct sk_buff
*)list
;
447 * skb_get - reference buffer
448 * @skb: buffer to reference
450 * Makes another reference to a socket buffer and returns a pointer
453 static inline struct sk_buff
*skb_get(struct sk_buff
*skb
)
455 atomic_inc(&skb
->users
);
460 * If users == 1, we are the only owner and are can avoid redundant
465 * skb_cloned - is the buffer a clone
466 * @skb: buffer to check
468 * Returns true if the buffer was generated with skb_clone() and is
469 * one of multiple shared copies of the buffer. Cloned buffers are
470 * shared data so must not be written to under normal circumstances.
472 static inline int skb_cloned(const struct sk_buff
*skb
)
474 return skb
->cloned
&&
475 (atomic_read(&skb_shinfo(skb
)->dataref
) & SKB_DATAREF_MASK
) != 1;
479 * skb_header_cloned - is the header a clone
480 * @skb: buffer to check
482 * Returns true if modifying the header part of the buffer requires
483 * the data to be copied.
485 static inline int skb_header_cloned(const struct sk_buff
*skb
)
492 dataref
= atomic_read(&skb_shinfo(skb
)->dataref
);
493 dataref
= (dataref
& SKB_DATAREF_MASK
) - (dataref
>> SKB_DATAREF_SHIFT
);
498 * skb_header_release - release reference to header
499 * @skb: buffer to operate on
501 * Drop a reference to the header part of the buffer. This is done
502 * by acquiring a payload reference. You must not read from the header
503 * part of skb->data after this.
505 static inline void skb_header_release(struct sk_buff
*skb
)
509 atomic_add(1 << SKB_DATAREF_SHIFT
, &skb_shinfo(skb
)->dataref
);
513 * skb_shared - is the buffer shared
514 * @skb: buffer to check
516 * Returns true if more than one person has a reference to this
519 static inline int skb_shared(const struct sk_buff
*skb
)
521 return atomic_read(&skb
->users
) != 1;
525 * skb_share_check - check if buffer is shared and if so clone it
526 * @skb: buffer to check
527 * @pri: priority for memory allocation
529 * If the buffer is shared the buffer is cloned and the old copy
530 * drops a reference. A new clone with a single reference is returned.
531 * If the buffer is not shared the original buffer is returned. When
532 * being called from interrupt status or with spinlocks held pri must
535 * NULL is returned on a memory allocation failure.
537 static inline struct sk_buff
*skb_share_check(struct sk_buff
*skb
,
540 might_sleep_if(pri
& __GFP_WAIT
);
541 if (skb_shared(skb
)) {
542 struct sk_buff
*nskb
= skb_clone(skb
, pri
);
550 * Copy shared buffers into a new sk_buff. We effectively do COW on
551 * packets to handle cases where we have a local reader and forward
552 * and a couple of other messy ones. The normal one is tcpdumping
553 * a packet thats being forwarded.
557 * skb_unshare - make a copy of a shared buffer
558 * @skb: buffer to check
559 * @pri: priority for memory allocation
561 * If the socket buffer is a clone then this function creates a new
562 * copy of the data, drops a reference count on the old copy and returns
563 * the new copy with the reference count at 1. If the buffer is not a clone
564 * the original buffer is returned. When called with a spinlock held or
565 * from interrupt state @pri must be %GFP_ATOMIC
567 * %NULL is returned on a memory allocation failure.
569 static inline struct sk_buff
*skb_unshare(struct sk_buff
*skb
,
572 might_sleep_if(pri
& __GFP_WAIT
);
573 if (skb_cloned(skb
)) {
574 struct sk_buff
*nskb
= skb_copy(skb
, pri
);
575 kfree_skb(skb
); /* Free our shared copy */
583 * @list_: list to peek at
585 * Peek an &sk_buff. Unlike most other operations you _MUST_
586 * be careful with this one. A peek leaves the buffer on the
587 * list and someone else may run off with it. You must hold
588 * the appropriate locks or have a private queue to do this.
590 * Returns %NULL for an empty list or a pointer to the head element.
591 * The reference count is not incremented and the reference is therefore
592 * volatile. Use with caution.
594 static inline struct sk_buff
*skb_peek(struct sk_buff_head
*list_
)
596 struct sk_buff
*list
= ((struct sk_buff
*)list_
)->next
;
597 if (list
== (struct sk_buff
*)list_
)
604 * @list_: list to peek at
606 * Peek an &sk_buff. Unlike most other operations you _MUST_
607 * be careful with this one. A peek leaves the buffer on the
608 * list and someone else may run off with it. You must hold
609 * the appropriate locks or have a private queue to do this.
611 * Returns %NULL for an empty list or a pointer to the tail element.
612 * The reference count is not incremented and the reference is therefore
613 * volatile. Use with caution.
615 static inline struct sk_buff
*skb_peek_tail(struct sk_buff_head
*list_
)
617 struct sk_buff
*list
= ((struct sk_buff
*)list_
)->prev
;
618 if (list
== (struct sk_buff
*)list_
)
624 * skb_queue_len - get queue length
625 * @list_: list to measure
627 * Return the length of an &sk_buff queue.
629 static inline __u32
skb_queue_len(const struct sk_buff_head
*list_
)
635 * __skb_queue_head_init - initialize non-spinlock portions of sk_buff_head
636 * @list: queue to initialize
638 * This initializes only the list and queue length aspects of
639 * an sk_buff_head object. This allows to initialize the list
640 * aspects of an sk_buff_head without reinitializing things like
641 * the spinlock. It can also be used for on-stack sk_buff_head
642 * objects where the spinlock is known to not be used.
644 static inline void __skb_queue_head_init(struct sk_buff_head
*list
)
646 list
->prev
= list
->next
= (struct sk_buff
*)list
;
651 * This function creates a split out lock class for each invocation;
652 * this is needed for now since a whole lot of users of the skb-queue
653 * infrastructure in drivers have different locking usage (in hardirq)
654 * than the networking core (in softirq only). In the long run either the
655 * network layer or drivers should need annotation to consolidate the
656 * main types of usage into 3 classes.
658 static inline void skb_queue_head_init(struct sk_buff_head
*list
)
660 spin_lock_init(&list
->lock
);
661 __skb_queue_head_init(list
);
664 static inline void skb_queue_head_init_class(struct sk_buff_head
*list
,
665 struct lock_class_key
*class)
667 skb_queue_head_init(list
);
668 lockdep_set_class(&list
->lock
, class);
672 * Insert a packet on a list.
674 extern void skb_insert(struct sk_buff
*old
, struct sk_buff
*newsk
, struct sk_buff_head
*list
);
675 static inline void __skb_insert(struct sk_buff
*newsk
,
676 struct sk_buff
*prev
, struct sk_buff
*next
,
677 struct sk_buff_head
*list
)
681 next
->prev
= prev
->next
= newsk
;
685 static inline void __skb_queue_splice(const struct sk_buff_head
*list
,
686 struct sk_buff
*prev
,
687 struct sk_buff
*next
)
689 struct sk_buff
*first
= list
->next
;
690 struct sk_buff
*last
= list
->prev
;
700 * skb_queue_splice - join two skb lists, this is designed for stacks
701 * @list: the new list to add
702 * @head: the place to add it in the first list
704 static inline void skb_queue_splice(const struct sk_buff_head
*list
,
705 struct sk_buff_head
*head
)
707 if (!skb_queue_empty(list
)) {
708 __skb_queue_splice(list
, (struct sk_buff
*) head
, head
->next
);
709 head
->qlen
+= list
->qlen
;
714 * skb_queue_splice - join two skb lists and reinitialise the emptied list
715 * @list: the new list to add
716 * @head: the place to add it in the first list
718 * The list at @list is reinitialised
720 static inline void skb_queue_splice_init(struct sk_buff_head
*list
,
721 struct sk_buff_head
*head
)
723 if (!skb_queue_empty(list
)) {
724 __skb_queue_splice(list
, (struct sk_buff
*) head
, head
->next
);
725 head
->qlen
+= list
->qlen
;
726 __skb_queue_head_init(list
);
731 * skb_queue_splice_tail - join two skb lists, each list being a queue
732 * @list: the new list to add
733 * @head: the place to add it in the first list
735 static inline void skb_queue_splice_tail(const struct sk_buff_head
*list
,
736 struct sk_buff_head
*head
)
738 if (!skb_queue_empty(list
)) {
739 __skb_queue_splice(list
, head
->prev
, (struct sk_buff
*) head
);
740 head
->qlen
+= list
->qlen
;
745 * skb_queue_splice_tail - join two skb lists and reinitialise the emptied list
746 * @list: the new list to add
747 * @head: the place to add it in the first list
749 * Each of the lists is a queue.
750 * The list at @list is reinitialised
752 static inline void skb_queue_splice_tail_init(struct sk_buff_head
*list
,
753 struct sk_buff_head
*head
)
755 if (!skb_queue_empty(list
)) {
756 __skb_queue_splice(list
, head
->prev
, (struct sk_buff
*) head
);
757 head
->qlen
+= list
->qlen
;
758 __skb_queue_head_init(list
);
763 * Insert an sk_buff at the start of a list.
765 * The "__skb_xxxx()" functions are the non-atomic ones that
766 * can only be called with interrupts disabled.
770 * __skb_queue_after - queue a buffer at the list head
772 * @prev: place after this buffer
773 * @newsk: buffer to queue
775 * Queue a buffer int the middle of a list. This function takes no locks
776 * and you must therefore hold required locks before calling it.
778 * A buffer cannot be placed on two lists at the same time.
780 static inline void __skb_queue_after(struct sk_buff_head
*list
,
781 struct sk_buff
*prev
,
782 struct sk_buff
*newsk
)
784 __skb_insert(newsk
, prev
, prev
->next
, list
);
788 * __skb_queue_head - queue a buffer at the list head
790 * @newsk: buffer to queue
792 * Queue a buffer at the start of a list. This function takes no locks
793 * and you must therefore hold required locks before calling it.
795 * A buffer cannot be placed on two lists at the same time.
797 extern void skb_queue_head(struct sk_buff_head
*list
, struct sk_buff
*newsk
);
798 static inline void __skb_queue_head(struct sk_buff_head
*list
,
799 struct sk_buff
*newsk
)
801 __skb_queue_after(list
, (struct sk_buff
*)list
, newsk
);
804 static inline void __skb_queue_before(struct sk_buff_head
*list
,
805 struct sk_buff
*next
,
806 struct sk_buff
*newsk
)
808 __skb_insert(newsk
, next
->prev
, next
, list
);
812 * __skb_queue_tail - queue a buffer at the list tail
814 * @newsk: buffer to queue
816 * Queue a buffer at the end of a list. This function takes no locks
817 * and you must therefore hold required locks before calling it.
819 * A buffer cannot be placed on two lists at the same time.
821 extern void skb_queue_tail(struct sk_buff_head
*list
, struct sk_buff
*newsk
);
822 static inline void __skb_queue_tail(struct sk_buff_head
*list
,
823 struct sk_buff
*newsk
)
825 __skb_queue_before(list
, (struct sk_buff
*)list
, newsk
);
830 * remove sk_buff from list. _Must_ be called atomically, and with
833 extern void skb_unlink(struct sk_buff
*skb
, struct sk_buff_head
*list
);
834 static inline void __skb_unlink(struct sk_buff
*skb
, struct sk_buff_head
*list
)
836 struct sk_buff
*next
, *prev
;
841 skb
->next
= skb
->prev
= NULL
;
847 * __skb_dequeue - remove from the head of the queue
848 * @list: list to dequeue from
850 * Remove the head of the list. This function does not take any locks
851 * so must be used with appropriate locks held only. The head item is
852 * returned or %NULL if the list is empty.
854 extern struct sk_buff
*skb_dequeue(struct sk_buff_head
*list
);
855 static inline struct sk_buff
*__skb_dequeue(struct sk_buff_head
*list
)
857 struct sk_buff
*skb
= skb_peek(list
);
859 __skb_unlink(skb
, list
);
865 * Place a packet after a given packet in a list.
867 extern void skb_append(struct sk_buff
*old
, struct sk_buff
*newsk
, struct sk_buff_head
*list
);
868 static inline void __skb_append(struct sk_buff
*old
, struct sk_buff
*newsk
, struct sk_buff_head
*list
)
870 __skb_insert(newsk
, old
, old
->next
, list
);
874 /* XXX: more streamlined implementation */
877 * __skb_dequeue_tail - remove from the tail of the queue
878 * @list: list to dequeue from
880 * Remove the tail of the list. This function does not take any locks
881 * so must be used with appropriate locks held only. The tail item is
882 * returned or %NULL if the list is empty.
884 extern struct sk_buff
*skb_dequeue_tail(struct sk_buff_head
*list
);
885 static inline struct sk_buff
*__skb_dequeue_tail(struct sk_buff_head
*list
)
887 struct sk_buff
*skb
= skb_peek_tail(list
);
889 __skb_unlink(skb
, list
);
894 static inline int skb_is_nonlinear(const struct sk_buff
*skb
)
896 return skb
->data_len
;
899 static inline unsigned int skb_headlen(const struct sk_buff
*skb
)
901 return skb
->len
- skb
->data_len
;
904 static inline int skb_pagelen(const struct sk_buff
*skb
)
908 for (i
= (int)skb_shinfo(skb
)->nr_frags
- 1; i
>= 0; i
--)
909 len
+= skb_shinfo(skb
)->frags
[i
].size
;
910 return len
+ skb_headlen(skb
);
913 static inline void skb_fill_page_desc(struct sk_buff
*skb
, int i
,
914 struct page
*page
, int off
, int size
)
916 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
919 frag
->page_offset
= off
;
921 skb_shinfo(skb
)->nr_frags
= i
+ 1;
924 #define SKB_PAGE_ASSERT(skb) BUG_ON(skb_shinfo(skb)->nr_frags)
925 #define SKB_FRAG_ASSERT(skb) BUG_ON(skb_shinfo(skb)->frag_list)
926 #define SKB_LINEAR_ASSERT(skb) BUG_ON(skb_is_nonlinear(skb))
928 #ifdef NET_SKBUFF_DATA_USES_OFFSET
929 static inline unsigned char *skb_tail_pointer(const struct sk_buff
*skb
)
931 return skb
->head
+ skb
->tail
;
934 static inline void skb_reset_tail_pointer(struct sk_buff
*skb
)
936 skb
->tail
= skb
->data
- skb
->head
;
939 static inline void skb_set_tail_pointer(struct sk_buff
*skb
, const int offset
)
941 skb_reset_tail_pointer(skb
);
944 #else /* NET_SKBUFF_DATA_USES_OFFSET */
945 static inline unsigned char *skb_tail_pointer(const struct sk_buff
*skb
)
950 static inline void skb_reset_tail_pointer(struct sk_buff
*skb
)
952 skb
->tail
= skb
->data
;
955 static inline void skb_set_tail_pointer(struct sk_buff
*skb
, const int offset
)
957 skb
->tail
= skb
->data
+ offset
;
960 #endif /* NET_SKBUFF_DATA_USES_OFFSET */
963 * Add data to an sk_buff
965 static inline unsigned char *__skb_put(struct sk_buff
*skb
, unsigned int len
)
967 unsigned char *tmp
= skb_tail_pointer(skb
);
968 SKB_LINEAR_ASSERT(skb
);
975 * skb_put - add data to a buffer
976 * @skb: buffer to use
977 * @len: amount of data to add
979 * This function extends the used data area of the buffer. If this would
980 * exceed the total buffer size the kernel will panic. A pointer to the
981 * first byte of the extra data is returned.
983 static inline unsigned char *skb_put(struct sk_buff
*skb
, unsigned int len
)
985 unsigned char *tmp
= skb_tail_pointer(skb
);
986 SKB_LINEAR_ASSERT(skb
);
989 if (unlikely(skb
->tail
> skb
->end
))
990 skb_over_panic(skb
, len
, current_text_addr());
994 static inline unsigned char *__skb_push(struct sk_buff
*skb
, unsigned int len
)
1002 * skb_push - add data to the start of a buffer
1003 * @skb: buffer to use
1004 * @len: amount of data to add
1006 * This function extends the used data area of the buffer at the buffer
1007 * start. If this would exceed the total buffer headroom the kernel will
1008 * panic. A pointer to the first byte of the extra data is returned.
1010 static inline unsigned char *skb_push(struct sk_buff
*skb
, unsigned int len
)
1014 if (unlikely(skb
->data
<skb
->head
))
1015 skb_under_panic(skb
, len
, current_text_addr());
1019 static inline unsigned char *__skb_pull(struct sk_buff
*skb
, unsigned int len
)
1022 BUG_ON(skb
->len
< skb
->data_len
);
1023 return skb
->data
+= len
;
1027 * skb_pull - remove data from the start of a buffer
1028 * @skb: buffer to use
1029 * @len: amount of data to remove
1031 * This function removes data from the start of a buffer, returning
1032 * the memory to the headroom. A pointer to the next data in the buffer
1033 * is returned. Once the data has been pulled future pushes will overwrite
1036 static inline unsigned char *skb_pull(struct sk_buff
*skb
, unsigned int len
)
1038 return unlikely(len
> skb
->len
) ? NULL
: __skb_pull(skb
, len
);
1041 extern unsigned char *__pskb_pull_tail(struct sk_buff
*skb
, int delta
);
1043 static inline unsigned char *__pskb_pull(struct sk_buff
*skb
, unsigned int len
)
1045 if (len
> skb_headlen(skb
) &&
1046 !__pskb_pull_tail(skb
, len
-skb_headlen(skb
)))
1049 return skb
->data
+= len
;
1052 static inline unsigned char *pskb_pull(struct sk_buff
*skb
, unsigned int len
)
1054 return unlikely(len
> skb
->len
) ? NULL
: __pskb_pull(skb
, len
);
1057 static inline int pskb_may_pull(struct sk_buff
*skb
, unsigned int len
)
1059 if (likely(len
<= skb_headlen(skb
)))
1061 if (unlikely(len
> skb
->len
))
1063 return __pskb_pull_tail(skb
, len
-skb_headlen(skb
)) != NULL
;
1067 * skb_headroom - bytes at buffer head
1068 * @skb: buffer to check
1070 * Return the number of bytes of free space at the head of an &sk_buff.
1072 static inline int skb_headroom(const struct sk_buff
*skb
)
1074 return skb
->data
- skb
->head
;
1078 * skb_tailroom - bytes at buffer end
1079 * @skb: buffer to check
1081 * Return the number of bytes of free space at the tail of an sk_buff
1083 static inline int skb_tailroom(const struct sk_buff
*skb
)
1085 return skb_is_nonlinear(skb
) ? 0 : skb
->end
- skb
->tail
;
1089 * skb_reserve - adjust headroom
1090 * @skb: buffer to alter
1091 * @len: bytes to move
1093 * Increase the headroom of an empty &sk_buff by reducing the tail
1094 * room. This is only allowed for an empty buffer.
1096 static inline void skb_reserve(struct sk_buff
*skb
, int len
)
1102 #ifdef NET_SKBUFF_DATA_USES_OFFSET
1103 static inline unsigned char *skb_transport_header(const struct sk_buff
*skb
)
1105 return skb
->head
+ skb
->transport_header
;
1108 static inline void skb_reset_transport_header(struct sk_buff
*skb
)
1110 skb
->transport_header
= skb
->data
- skb
->head
;
1113 static inline void skb_set_transport_header(struct sk_buff
*skb
,
1116 skb_reset_transport_header(skb
);
1117 skb
->transport_header
+= offset
;
1120 static inline unsigned char *skb_network_header(const struct sk_buff
*skb
)
1122 return skb
->head
+ skb
->network_header
;
1125 static inline void skb_reset_network_header(struct sk_buff
*skb
)
1127 skb
->network_header
= skb
->data
- skb
->head
;
1130 static inline void skb_set_network_header(struct sk_buff
*skb
, const int offset
)
1132 skb_reset_network_header(skb
);
1133 skb
->network_header
+= offset
;
1136 static inline unsigned char *skb_mac_header(const struct sk_buff
*skb
)
1138 return skb
->head
+ skb
->mac_header
;
1141 static inline int skb_mac_header_was_set(const struct sk_buff
*skb
)
1143 return skb
->mac_header
!= ~0U;
1146 static inline void skb_reset_mac_header(struct sk_buff
*skb
)
1148 skb
->mac_header
= skb
->data
- skb
->head
;
1151 static inline void skb_set_mac_header(struct sk_buff
*skb
, const int offset
)
1153 skb_reset_mac_header(skb
);
1154 skb
->mac_header
+= offset
;
1157 #else /* NET_SKBUFF_DATA_USES_OFFSET */
1159 static inline unsigned char *skb_transport_header(const struct sk_buff
*skb
)
1161 return skb
->transport_header
;
1164 static inline void skb_reset_transport_header(struct sk_buff
*skb
)
1166 skb
->transport_header
= skb
->data
;
1169 static inline void skb_set_transport_header(struct sk_buff
*skb
,
1172 skb
->transport_header
= skb
->data
+ offset
;
1175 static inline unsigned char *skb_network_header(const struct sk_buff
*skb
)
1177 return skb
->network_header
;
1180 static inline void skb_reset_network_header(struct sk_buff
*skb
)
1182 skb
->network_header
= skb
->data
;
1185 static inline void skb_set_network_header(struct sk_buff
*skb
, const int offset
)
1187 skb
->network_header
= skb
->data
+ offset
;
1190 static inline unsigned char *skb_mac_header(const struct sk_buff
*skb
)
1192 return skb
->mac_header
;
1195 static inline int skb_mac_header_was_set(const struct sk_buff
*skb
)
1197 return skb
->mac_header
!= NULL
;
1200 static inline void skb_reset_mac_header(struct sk_buff
*skb
)
1202 skb
->mac_header
= skb
->data
;
1205 static inline void skb_set_mac_header(struct sk_buff
*skb
, const int offset
)
1207 skb
->mac_header
= skb
->data
+ offset
;
1209 #endif /* NET_SKBUFF_DATA_USES_OFFSET */
1211 static inline int skb_transport_offset(const struct sk_buff
*skb
)
1213 return skb_transport_header(skb
) - skb
->data
;
1216 static inline u32
skb_network_header_len(const struct sk_buff
*skb
)
1218 return skb
->transport_header
- skb
->network_header
;
1221 static inline int skb_network_offset(const struct sk_buff
*skb
)
1223 return skb_network_header(skb
) - skb
->data
;
1227 * CPUs often take a performance hit when accessing unaligned memory
1228 * locations. The actual performance hit varies, it can be small if the
1229 * hardware handles it or large if we have to take an exception and fix it
1232 * Since an ethernet header is 14 bytes network drivers often end up with
1233 * the IP header at an unaligned offset. The IP header can be aligned by
1234 * shifting the start of the packet by 2 bytes. Drivers should do this
1237 * skb_reserve(NET_IP_ALIGN);
1239 * The downside to this alignment of the IP header is that the DMA is now
1240 * unaligned. On some architectures the cost of an unaligned DMA is high
1241 * and this cost outweighs the gains made by aligning the IP header.
1243 * Since this trade off varies between architectures, we allow NET_IP_ALIGN
1246 #ifndef NET_IP_ALIGN
1247 #define NET_IP_ALIGN 2
1251 * The networking layer reserves some headroom in skb data (via
1252 * dev_alloc_skb). This is used to avoid having to reallocate skb data when
1253 * the header has to grow. In the default case, if the header has to grow
1254 * 32 bytes or less we avoid the reallocation.
1256 * Unfortunately this headroom changes the DMA alignment of the resulting
1257 * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive
1258 * on some architectures. An architecture can override this value,
1259 * perhaps setting it to a cacheline in size (since that will maintain
1260 * cacheline alignment of the DMA). It must be a power of 2.
1262 * Various parts of the networking layer expect at least 32 bytes of
1263 * headroom, you should not reduce this.
1265 * This has been changed to 64 to acommodate for routing between ethernet
1266 * and wireless, but only for new allocations
1269 #define NET_SKB_PAD 32
1272 #ifndef NET_SKB_PAD_ALLOC
1273 #define NET_SKB_PAD_ALLOC 64
1276 extern int ___pskb_trim(struct sk_buff
*skb
, unsigned int len
);
1278 static inline void __skb_trim(struct sk_buff
*skb
, unsigned int len
)
1280 if (unlikely(skb
->data_len
)) {
1285 skb_set_tail_pointer(skb
, len
);
1289 * skb_trim - remove end from a buffer
1290 * @skb: buffer to alter
1293 * Cut the length of a buffer down by removing data from the tail. If
1294 * the buffer is already under the length specified it is not modified.
1295 * The skb must be linear.
1297 static inline void skb_trim(struct sk_buff
*skb
, unsigned int len
)
1300 __skb_trim(skb
, len
);
1304 static inline int __pskb_trim(struct sk_buff
*skb
, unsigned int len
)
1307 return ___pskb_trim(skb
, len
);
1308 __skb_trim(skb
, len
);
1312 static inline int pskb_trim(struct sk_buff
*skb
, unsigned int len
)
1314 return (len
< skb
->len
) ? __pskb_trim(skb
, len
) : 0;
1318 * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
1319 * @skb: buffer to alter
1322 * This is identical to pskb_trim except that the caller knows that
1323 * the skb is not cloned so we should never get an error due to out-
1326 static inline void pskb_trim_unique(struct sk_buff
*skb
, unsigned int len
)
1328 int err
= pskb_trim(skb
, len
);
1333 * skb_orphan - orphan a buffer
1334 * @skb: buffer to orphan
1336 * If a buffer currently has an owner then we call the owner's
1337 * destructor function and make the @skb unowned. The buffer continues
1338 * to exist but is no longer charged to its former owner.
1340 static inline void skb_orphan(struct sk_buff
*skb
)
1342 if (skb
->destructor
)
1343 skb
->destructor(skb
);
1344 skb
->destructor
= NULL
;
1349 * __skb_queue_purge - empty a list
1350 * @list: list to empty
1352 * Delete all buffers on an &sk_buff list. Each buffer is removed from
1353 * the list and one reference dropped. This function does not take the
1354 * list lock and the caller must hold the relevant locks to use it.
1356 extern void skb_queue_purge(struct sk_buff_head
*list
);
1357 static inline void __skb_queue_purge(struct sk_buff_head
*list
)
1359 struct sk_buff
*skb
;
1360 while ((skb
= __skb_dequeue(list
)) != NULL
)
1365 * __dev_alloc_skb - allocate an skbuff for receiving
1366 * @length: length to allocate
1367 * @gfp_mask: get_free_pages mask, passed to alloc_skb
1369 * Allocate a new &sk_buff and assign it a usage count of one. The
1370 * buffer has unspecified headroom built in. Users should allocate
1371 * the headroom they think they need without accounting for the
1372 * built in space. The built in space is used for optimisations.
1374 * %NULL is returned if there is no free memory.
1376 static inline struct sk_buff
*__dev_alloc_skb(unsigned int length
,
1379 struct sk_buff
*skb
= alloc_skb(length
+ NET_SKB_PAD_ALLOC
, gfp_mask
);
1381 skb_reserve(skb
, NET_SKB_PAD_ALLOC
);
1386 * dev_alloc_skb - allocate an skbuff for receiving
1387 * @length: length to allocate
1389 * Allocate a new &sk_buff and assign it a usage count of one. The
1390 * buffer has unspecified headroom built in. Users should allocate
1391 * the headroom they think they need without accounting for the
1392 * built in space. The built in space is used for optimisations.
1394 * %NULL is returned if there is no free memory. Although this function
1395 * allocates memory it can be called from an interrupt.
1397 static inline struct sk_buff
*dev_alloc_skb(unsigned int length
)
1399 return __dev_alloc_skb(length
, GFP_ATOMIC
);
1402 extern struct sk_buff
*__netdev_alloc_skb(struct net_device
*dev
,
1403 unsigned int length
, gfp_t gfp_mask
);
1406 * netdev_alloc_skb - allocate an skbuff for rx on a specific device
1407 * @dev: network device to receive on
1408 * @length: length to allocate
1410 * Allocate a new &sk_buff and assign it a usage count of one. The
1411 * buffer has unspecified headroom built in. Users should allocate
1412 * the headroom they think they need without accounting for the
1413 * built in space. The built in space is used for optimisations.
1415 * %NULL is returned if there is no free memory. Although this function
1416 * allocates memory it can be called from an interrupt.
1418 static inline struct sk_buff
*netdev_alloc_skb(struct net_device
*dev
,
1419 unsigned int length
)
1421 return __netdev_alloc_skb(dev
, length
, GFP_ATOMIC
);
1425 * skb_clone_writable - is the header of a clone writable
1426 * @skb: buffer to check
1427 * @len: length up to which to write
1429 * Returns true if modifying the header part of the cloned buffer
1430 * does not requires the data to be copied.
1432 static inline int skb_clone_writable(struct sk_buff
*skb
, int len
)
1434 return !skb_header_cloned(skb
) &&
1435 skb_headroom(skb
) + len
<= skb
->hdr_len
;
1438 static inline int __skb_cow(struct sk_buff
*skb
, unsigned int headroom
,
1443 if (headroom
< NET_SKB_PAD
)
1444 headroom
= NET_SKB_PAD
;
1445 if (headroom
> skb_headroom(skb
))
1446 delta
= headroom
- skb_headroom(skb
);
1448 if (delta
|| cloned
)
1449 return pskb_expand_head(skb
, ALIGN(delta
, NET_SKB_PAD_ALLOC
), 0,
1455 * skb_cow - copy header of skb when it is required
1456 * @skb: buffer to cow
1457 * @headroom: needed headroom
1459 * If the skb passed lacks sufficient headroom or its data part
1460 * is shared, data is reallocated. If reallocation fails, an error
1461 * is returned and original skb is not changed.
1463 * The result is skb with writable area skb->head...skb->tail
1464 * and at least @headroom of space at head.
1466 static inline int skb_cow(struct sk_buff
*skb
, unsigned int headroom
)
1468 return __skb_cow(skb
, headroom
, skb_cloned(skb
));
1472 * skb_cow_head - skb_cow but only making the head writable
1473 * @skb: buffer to cow
1474 * @headroom: needed headroom
1476 * This function is identical to skb_cow except that we replace the
1477 * skb_cloned check by skb_header_cloned. It should be used when
1478 * you only need to push on some header and do not need to modify
1481 static inline int skb_cow_head(struct sk_buff
*skb
, unsigned int headroom
)
1483 return __skb_cow(skb
, headroom
, skb_header_cloned(skb
));
1487 * skb_padto - pad an skbuff up to a minimal size
1488 * @skb: buffer to pad
1489 * @len: minimal length
1491 * Pads up a buffer to ensure the trailing bytes exist and are
1492 * blanked. If the buffer already contains sufficient data it
1493 * is untouched. Otherwise it is extended. Returns zero on
1494 * success. The skb is freed on error.
1497 static inline int skb_padto(struct sk_buff
*skb
, unsigned int len
)
1499 unsigned int size
= skb
->len
;
1500 if (likely(size
>= len
))
1502 return skb_pad(skb
, len
-size
);
1505 static inline int skb_add_data(struct sk_buff
*skb
,
1506 char __user
*from
, int copy
)
1508 const int off
= skb
->len
;
1510 if (skb
->ip_summed
== CHECKSUM_NONE
) {
1512 __wsum csum
= csum_and_copy_from_user(from
, skb_put(skb
, copy
),
1515 skb
->csum
= csum_block_add(skb
->csum
, csum
, off
);
1518 } else if (!copy_from_user(skb_put(skb
, copy
), from
, copy
))
1521 __skb_trim(skb
, off
);
1525 static inline int skb_can_coalesce(struct sk_buff
*skb
, int i
,
1526 struct page
*page
, int off
)
1529 struct skb_frag_struct
*frag
= &skb_shinfo(skb
)->frags
[i
- 1];
1531 return page
== frag
->page
&&
1532 off
== frag
->page_offset
+ frag
->size
;
1537 static inline int __skb_linearize(struct sk_buff
*skb
)
1539 return __pskb_pull_tail(skb
, skb
->data_len
) ? 0 : -ENOMEM
;
1543 * skb_linearize - convert paged skb to linear one
1544 * @skb: buffer to linarize
1546 * If there is no free memory -ENOMEM is returned, otherwise zero
1547 * is returned and the old skb data released.
1549 static inline int skb_linearize(struct sk_buff
*skb
)
1551 return skb_is_nonlinear(skb
) ? __skb_linearize(skb
) : 0;
1555 * skb_linearize_cow - make sure skb is linear and writable
1556 * @skb: buffer to process
1558 * If there is no free memory -ENOMEM is returned, otherwise zero
1559 * is returned and the old skb data released.
1561 static inline int skb_linearize_cow(struct sk_buff
*skb
)
1563 return skb_is_nonlinear(skb
) || skb_cloned(skb
) ?
1564 __skb_linearize(skb
) : 0;
1568 * skb_postpull_rcsum - update checksum for received skb after pull
1569 * @skb: buffer to update
1570 * @start: start of data before pull
1571 * @len: length of data pulled
1573 * After doing a pull on a received packet, you need to call this to
1574 * update the CHECKSUM_COMPLETE checksum, or set ip_summed to
1575 * CHECKSUM_NONE so that it can be recomputed from scratch.
1578 static inline void skb_postpull_rcsum(struct sk_buff
*skb
,
1579 const void *start
, unsigned int len
)
1581 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
1582 skb
->csum
= csum_sub(skb
->csum
, csum_partial(start
, len
, 0));
1585 unsigned char *skb_pull_rcsum(struct sk_buff
*skb
, unsigned int len
);
1588 * pskb_trim_rcsum - trim received skb and update checksum
1589 * @skb: buffer to trim
1592 * This is exactly the same as pskb_trim except that it ensures the
1593 * checksum of received packets are still valid after the operation.
1596 static inline int pskb_trim_rcsum(struct sk_buff
*skb
, unsigned int len
)
1598 if (likely(len
>= skb
->len
))
1600 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
1601 skb
->ip_summed
= CHECKSUM_NONE
;
1602 return __pskb_trim(skb
, len
);
1605 #define skb_queue_walk(queue, skb) \
1606 for (skb = (queue)->next; \
1607 prefetch(skb->next), (skb != (struct sk_buff *)(queue)); \
1610 #define skb_queue_walk_safe(queue, skb, tmp) \
1611 for (skb = (queue)->next, tmp = skb->next; \
1612 skb != (struct sk_buff *)(queue); \
1613 skb = tmp, tmp = skb->next)
1615 #define skb_queue_reverse_walk(queue, skb) \
1616 for (skb = (queue)->prev; \
1617 prefetch(skb->prev), (skb != (struct sk_buff *)(queue)); \
1621 extern struct sk_buff
*skb_recv_datagram(struct sock
*sk
, unsigned flags
,
1622 int noblock
, int *err
);
1623 extern unsigned int datagram_poll(struct file
*file
, struct socket
*sock
,
1624 struct poll_table_struct
*wait
);
1625 extern int skb_copy_datagram_iovec(const struct sk_buff
*from
,
1626 int offset
, struct iovec
*to
,
1628 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff
*skb
,
1631 extern void skb_free_datagram(struct sock
*sk
, struct sk_buff
*skb
);
1632 extern void skb_kill_datagram(struct sock
*sk
, struct sk_buff
*skb
,
1633 unsigned int flags
);
1634 extern __wsum
skb_checksum(const struct sk_buff
*skb
, int offset
,
1635 int len
, __wsum csum
);
1636 extern int skb_copy_bits(const struct sk_buff
*skb
, int offset
,
1638 extern int skb_store_bits(struct sk_buff
*skb
, int offset
,
1639 const void *from
, int len
);
1640 extern __wsum
skb_copy_and_csum_bits(const struct sk_buff
*skb
,
1641 int offset
, u8
*to
, int len
,
1643 extern int skb_splice_bits(struct sk_buff
*skb
,
1644 unsigned int offset
,
1645 struct pipe_inode_info
*pipe
,
1647 unsigned int flags
);
1648 extern void skb_copy_and_csum_dev(const struct sk_buff
*skb
, u8
*to
);
1649 extern void skb_split(struct sk_buff
*skb
,
1650 struct sk_buff
*skb1
, const u32 len
);
1652 extern struct sk_buff
*skb_segment(struct sk_buff
*skb
, int features
);
1654 static inline void *skb_header_pointer(const struct sk_buff
*skb
, int offset
,
1655 int len
, void *buffer
)
1657 int hlen
= skb_headlen(skb
);
1659 if (hlen
- offset
>= len
)
1660 return skb
->data
+ offset
;
1662 if (skb_copy_bits(skb
, offset
, buffer
, len
) < 0)
1668 static inline void skb_copy_from_linear_data(const struct sk_buff
*skb
,
1670 const unsigned int len
)
1672 memcpy(to
, skb
->data
, len
);
1675 static inline void skb_copy_from_linear_data_offset(const struct sk_buff
*skb
,
1676 const int offset
, void *to
,
1677 const unsigned int len
)
1679 memcpy(to
, skb
->data
+ offset
, len
);
1682 static inline void skb_copy_to_linear_data(struct sk_buff
*skb
,
1684 const unsigned int len
)
1686 memcpy(skb
->data
, from
, len
);
1689 static inline void skb_copy_to_linear_data_offset(struct sk_buff
*skb
,
1692 const unsigned int len
)
1694 memcpy(skb
->data
+ offset
, from
, len
);
1697 extern void skb_init(void);
1700 * skb_get_timestamp - get timestamp from a skb
1701 * @skb: skb to get stamp from
1702 * @stamp: pointer to struct timeval to store stamp in
1704 * Timestamps are stored in the skb as offsets to a base timestamp.
1705 * This function converts the offset back to a struct timeval and stores
1708 static inline void skb_get_timestamp(const struct sk_buff
*skb
, struct timeval
*stamp
)
1710 *stamp
= ktime_to_timeval(skb
->tstamp
);
1713 static inline void __net_timestamp(struct sk_buff
*skb
)
1715 skb
->tstamp
= ktime_get_real();
1718 static inline ktime_t
net_timedelta(ktime_t t
)
1720 return ktime_sub(ktime_get_real(), t
);
1723 static inline ktime_t
net_invalid_timestamp(void)
1725 return ktime_set(0, 0);
1728 extern __sum16
__skb_checksum_complete_head(struct sk_buff
*skb
, int len
);
1729 extern __sum16
__skb_checksum_complete(struct sk_buff
*skb
);
1731 static inline int skb_csum_unnecessary(const struct sk_buff
*skb
)
1733 return skb
->ip_summed
& CHECKSUM_UNNECESSARY
;
1737 * skb_checksum_complete - Calculate checksum of an entire packet
1738 * @skb: packet to process
1740 * This function calculates the checksum over the entire packet plus
1741 * the value of skb->csum. The latter can be used to supply the
1742 * checksum of a pseudo header as used by TCP/UDP. It returns the
1745 * For protocols that contain complete checksums such as ICMP/TCP/UDP,
1746 * this function can be used to verify that checksum on received
1747 * packets. In that case the function should return zero if the
1748 * checksum is correct. In particular, this function will return zero
1749 * if skb->ip_summed is CHECKSUM_UNNECESSARY which indicates that the
1750 * hardware has already verified the correctness of the checksum.
1752 static inline unsigned int skb_checksum_complete(struct sk_buff
*skb
)
1754 return skb_csum_unnecessary(skb
) ?
1755 0 : __skb_checksum_complete(skb
);
1758 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1759 extern void nf_conntrack_destroy(struct nf_conntrack
*nfct
);
1760 static inline void nf_conntrack_put(struct nf_conntrack
*nfct
)
1762 if (nfct
&& atomic_dec_and_test(&nfct
->use
))
1763 nf_conntrack_destroy(nfct
);
1765 static inline void nf_conntrack_get(struct nf_conntrack
*nfct
)
1768 atomic_inc(&nfct
->use
);
1770 static inline void nf_conntrack_get_reasm(struct sk_buff
*skb
)
1773 atomic_inc(&skb
->users
);
1775 static inline void nf_conntrack_put_reasm(struct sk_buff
*skb
)
1781 #ifdef CONFIG_BRIDGE_NETFILTER
1782 static inline void nf_bridge_put(struct nf_bridge_info
*nf_bridge
)
1784 if (nf_bridge
&& atomic_dec_and_test(&nf_bridge
->use
))
1787 static inline void nf_bridge_get(struct nf_bridge_info
*nf_bridge
)
1790 atomic_inc(&nf_bridge
->use
);
1792 #endif /* CONFIG_BRIDGE_NETFILTER */
1793 static inline void nf_reset(struct sk_buff
*skb
)
1795 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1796 nf_conntrack_put(skb
->nfct
);
1798 nf_conntrack_put_reasm(skb
->nfct_reasm
);
1799 skb
->nfct_reasm
= NULL
;
1801 #ifdef CONFIG_BRIDGE_NETFILTER
1802 nf_bridge_put(skb
->nf_bridge
);
1803 skb
->nf_bridge
= NULL
;
1807 /* Note: This doesn't put any conntrack and bridge info in dst. */
1808 static inline void __nf_copy(struct sk_buff
*dst
, const struct sk_buff
*src
)
1810 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1811 dst
->nfct
= src
->nfct
;
1812 nf_conntrack_get(src
->nfct
);
1813 dst
->nfctinfo
= src
->nfctinfo
;
1814 dst
->nfct_reasm
= src
->nfct_reasm
;
1815 nf_conntrack_get_reasm(src
->nfct_reasm
);
1817 #ifdef CONFIG_BRIDGE_NETFILTER
1818 dst
->nf_bridge
= src
->nf_bridge
;
1819 nf_bridge_get(src
->nf_bridge
);
1821 #if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1822 dst
->imq_flags
= src
->imq_flags
;
1823 dst
->nf_info
= src
->nf_info
;
1827 static inline void nf_copy(struct sk_buff
*dst
, const struct sk_buff
*src
)
1829 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1830 nf_conntrack_put(dst
->nfct
);
1831 nf_conntrack_put_reasm(dst
->nfct_reasm
);
1833 #ifdef CONFIG_BRIDGE_NETFILTER
1834 nf_bridge_put(dst
->nf_bridge
);
1836 __nf_copy(dst
, src
);
1839 #ifdef CONFIG_NETWORK_SECMARK
1840 static inline void skb_copy_secmark(struct sk_buff
*to
, const struct sk_buff
*from
)
1842 to
->secmark
= from
->secmark
;
1845 static inline void skb_init_secmark(struct sk_buff
*skb
)
1850 static inline void skb_copy_secmark(struct sk_buff
*to
, const struct sk_buff
*from
)
1853 static inline void skb_init_secmark(struct sk_buff
*skb
)
1857 static inline int skb_is_gso(const struct sk_buff
*skb
)
1859 return skb_shinfo(skb
)->gso_size
;
1862 static inline void skb_forward_csum(struct sk_buff
*skb
)
1864 /* Unfortunately we don't support this one. Any brave souls? */
1865 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
1866 skb
->ip_summed
= CHECKSUM_NONE
;
1869 #endif /* __KERNEL__ */
1870 #endif /* _LINUX_SKBUFF_H */