Broadcom SDK and wireless driver: another attempt to update to ver. 5.10.147.0
[tomato.git] / release / src-rt / linux / linux-2.6 / include / linux / skbuff.h
blob1a15a1ee65209b8ff88cf3858424453321fb5e4e
1 /*
2 * Definitions for the 'struct sk_buff' memory handlers.
4 * Authors:
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) - sizeof(struct skb_shared_info)) & \
45 ~(SMP_CACHE_BYTES - 1))
46 #define SKB_MAX_ORDER(X, ORDER) \
47 SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X))
48 #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0))
49 #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2))
51 /* A. Checksumming of received packets by device.
53 * NONE: device failed to checksum this packet.
54 * skb->csum is undefined.
56 * UNNECESSARY: device parsed packet and wouldbe verified checksum.
57 * skb->csum is undefined.
58 * It is bad option, but, unfortunately, many of vendors do this.
59 * Apparently with secret goal to sell you new device, when you
60 * will add new protocol to your host. F.e. IPv6. 8)
62 * COMPLETE: the most generic way. Device supplied checksum of _all_
63 * the packet as seen by netif_rx in skb->csum.
64 * NOTE: Even if device supports only some protocols, but
65 * is able to produce some skb->csum, it MUST use COMPLETE,
66 * not UNNECESSARY.
68 * B. Checksumming on output.
70 * NONE: skb is checksummed by protocol or csum is not required.
72 * PARTIAL: device is required to csum packet as seen by hard_start_xmit
73 * from skb->transport_header to the end and to record the checksum
74 * at skb->transport_header + skb->csum.
76 * Device must show its capabilities in dev->features, set
77 * at device setup time.
78 * NETIF_F_HW_CSUM - it is clever device, it is able to checksum
79 * everything.
80 * NETIF_F_NO_CSUM - loopback or reliable single hop media.
81 * NETIF_F_IP_CSUM - device is dumb. It is able to csum only
82 * TCP/UDP over IPv4. Sigh. Vendors like this
83 * way by an unknown reason. Though, see comment above
84 * about CHECKSUM_UNNECESSARY. 8)
86 * Any questions? No questions, good. --ANK
89 struct net_device;
90 struct scatterlist;
92 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
93 struct nf_conntrack {
94 atomic_t use;
96 #endif
98 #ifdef CONFIG_BRIDGE_NETFILTER
99 struct nf_bridge_info {
100 atomic_t use;
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;
105 #endif
106 unsigned int mask;
107 unsigned long data[32 / sizeof(unsigned long)];
109 #endif
111 struct sk_buff_head {
112 /* These two members must be first. */
113 struct sk_buff *next;
114 struct sk_buff *prev;
116 __u32 qlen;
117 spinlock_t lock;
120 struct sk_buff;
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 {
128 struct page *page;
129 __u16 page_offset;
130 __u16 size;
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 {
137 atomic_t dataref;
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;
143 __be32 ip6_frag_id;
144 struct sk_buff *frag_list;
145 skb_frag_t frags[MAX_SKB_FRAGS];
148 /* We divide dataref into two halves. The higher 16 bits hold references
149 * to the payload part of skb->data. The lower 16 bits hold references to
150 * the entire skb->data. A clone of a headerless skb holds the length of
151 * the header in skb->hdr_len.
153 * All users must obey the rule that the skb->data reference count must be
154 * greater than or equal to the payload reference count.
156 * Holding a reference to the payload part means that the user does not
157 * care about modifications to the header part of skb->data.
159 #define SKB_DATAREF_SHIFT 16
160 #define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1)
163 enum {
164 SKB_FCLONE_UNAVAILABLE,
165 SKB_FCLONE_ORIG,
166 SKB_FCLONE_CLONE,
169 enum {
170 SKB_GSO_TCPV4 = 1 << 0,
171 SKB_GSO_UDP = 1 << 1,
173 /* This indicates the skb is from an untrusted source. */
174 SKB_GSO_DODGY = 1 << 2,
176 /* This indicates the tcp segment has CWR set. */
177 SKB_GSO_TCP_ECN = 1 << 3,
179 SKB_GSO_TCPV6 = 1 << 4,
182 #if BITS_PER_LONG > 32
183 #define NET_SKBUFF_DATA_USES_OFFSET 1
184 #endif
186 #ifdef NET_SKBUFF_DATA_USES_OFFSET
187 typedef unsigned int sk_buff_data_t;
188 #else
189 typedef unsigned char *sk_buff_data_t;
190 #endif
192 /**
193 * struct sk_buff - socket buffer
194 * @next: Next buffer in list
195 * @prev: Previous buffer in list
196 * @sk: Socket we are owned by
197 * @tstamp: Time we arrived
198 * @dev: Device we arrived on/are leaving by
199 * @iif: ifindex of device we arrived on
200 * @transport_header: Transport layer header
201 * @network_header: Network layer header
202 * @mac_header: Link layer header
203 * @dst: destination entry
204 * @sp: the security path, used for xfrm
205 * @cb: Control buffer. Free for use by every layer. Put private vars here
206 * @len: Length of actual data
207 * @data_len: Data length
208 * @mac_len: Length of link layer header
209 * @hdr_len: writable header length of cloned skb
210 * @csum: Checksum (must include start/offset pair)
211 * @csum_start: Offset from skb->head where checksumming should start
212 * @csum_offset: Offset from csum_start where checksum should be stored
213 * @local_df: allow local fragmentation
214 * @cloned: Head may be cloned (check refcnt to be sure)
215 * @nohdr: Payload reference only, must not modify header
216 * @pkt_type: Packet class
217 * @fclone: skbuff clone status
218 * @ip_summed: Driver fed us an IP checksum
219 * @priority: Packet queueing priority
220 * @users: User count - see {datagram,tcp}.c
221 * @protocol: Packet protocol from driver
222 * @truesize: Buffer size
223 * @head: Head of buffer
224 * @data: Data head pointer
225 * @tail: Tail pointer
226 * @end: End pointer
227 * @destructor: Destruct function
228 * @mark: Generic packet mark
229 * @nfct: Associated connection, if any
230 * @ipvs_property: skbuff is owned by ipvs
231 * @nfctinfo: Relationship of this skb to the connection
232 * @nfct_reasm: netfilter conntrack re-assembly pointer
233 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
234 * @tc_index: Traffic control index
235 * @tc_verd: traffic control verdict
236 * @dma_cookie: a cookie to one of several possible DMA operations
237 * done by skb DMA functions
238 * @secmark: security marking
241 struct sk_buff {
242 /* These two members must be first. */
243 struct sk_buff *next;
244 struct sk_buff *prev;
246 struct sock *sk;
247 ktime_t tstamp;
248 struct net_device *dev;
249 int iif;
250 /* 4 byte hole on 64 bit*/
252 struct dst_entry *dst;
253 struct sec_path *sp;
256 * This is the control buffer. It is free to use for every
257 * layer. Please put your private variables there. If you
258 * want to keep them across layers you have to do a skb_clone()
259 * first. This is owned by whoever has the skb queued ATM.
261 char cb[48];
263 unsigned int len,
264 data_len;
265 __u16 mac_len,
266 hdr_len;
267 union {
268 __wsum csum;
269 struct {
270 __u16 csum_start;
271 __u16 csum_offset;
274 __u32 priority;
275 __u8 local_df:1,
276 cloned:1,
277 ip_summed:2,
278 nohdr:1,
279 nfctinfo:3;
280 __u8 pkt_type:3,
281 fclone:2,
282 ipvs_property:1;
283 __be16 protocol;
285 void (*destructor)(struct sk_buff *skb);
287 __u32 mark;
289 sk_buff_data_t transport_header;
290 sk_buff_data_t network_header;
291 sk_buff_data_t mac_header;
292 sk_buff_data_t tail;
293 sk_buff_data_t end;
294 unsigned char *head,
295 *data;
296 unsigned int truesize;
297 atomic_t users;
298 unsigned char wl_idx;
299 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
300 struct nf_conntrack *nfct;
301 struct sk_buff *nfct_reasm;
302 /* Cache info */
303 __u32 nfcache;
304 #endif
305 #ifdef CONFIG_BRIDGE_NETFILTER
306 struct nf_bridge_info *nf_bridge;
307 #endif
308 #ifdef CONFIG_NET_SCHED
309 __u16 tc_index; /* traffic control index */
310 #ifdef CONFIG_NET_CLS_ACT
311 __u16 tc_verd; /* traffic control verdict */
312 #endif
313 #endif
314 #ifdef CONFIG_NET_DMA
315 dma_cookie_t dma_cookie;
316 #endif
317 #ifdef CONFIG_NETWORK_SECMARK
318 __u32 secmark;
319 #endif
320 #if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
321 unsigned char imq_flags;
322 struct nf_info *nf_info;
323 #endif
324 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
325 /* Cache info */
326 __u32 nfcache;
327 #endif
330 #ifdef __KERNEL__
332 * Handling routines are only of interest to the kernel
334 #include <linux/slab.h>
336 #include <asm/system.h>
338 extern void kfree_skb(struct sk_buff *skb);
339 extern void __kfree_skb(struct sk_buff *skb);
340 extern struct sk_buff *__alloc_skb(unsigned int size,
341 gfp_t priority, int fclone, int node);
342 static inline struct sk_buff *alloc_skb(unsigned int size,
343 gfp_t priority)
345 return __alloc_skb(size, priority, 0, -1);
348 static inline struct sk_buff *alloc_skb_fclone(unsigned int size,
349 gfp_t priority)
351 return __alloc_skb(size, priority, 1, -1);
354 extern void kfree_skbmem(struct sk_buff *skb);
355 extern struct sk_buff *skb_clone(struct sk_buff *skb,
356 gfp_t priority);
357 extern struct sk_buff *skb_copy(const struct sk_buff *skb,
358 gfp_t priority);
359 extern struct sk_buff *pskb_copy(struct sk_buff *skb,
360 gfp_t gfp_mask);
361 extern int pskb_expand_head(struct sk_buff *skb,
362 int nhead, int ntail,
363 gfp_t gfp_mask);
364 extern struct sk_buff *skb_realloc_headroom(struct sk_buff *skb,
365 unsigned int headroom);
366 extern struct sk_buff *skb_copy_expand(const struct sk_buff *skb,
367 int newheadroom, int newtailroom,
368 gfp_t priority);
369 extern int skb_to_sgvec(struct sk_buff *skb,
370 struct scatterlist *sg, int offset,
371 int len);
372 extern int skb_cow_data(struct sk_buff *skb, int tailbits,
373 struct sk_buff **trailer);
374 extern int skb_pad(struct sk_buff *skb, int pad);
375 #define dev_kfree_skb(a) kfree_skb(a)
376 extern void skb_over_panic(struct sk_buff *skb, int len,
377 void *here);
378 extern void skb_under_panic(struct sk_buff *skb, int len,
379 void *here);
380 extern void skb_truesize_bug(struct sk_buff *skb);
382 static inline void skb_truesize_check(struct sk_buff *skb)
384 if (unlikely((int)skb->truesize < sizeof(struct sk_buff) + skb->len))
385 skb_truesize_bug(skb);
388 extern int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb,
389 int getfrag(void *from, char *to, int offset,
390 int len,int odd, struct sk_buff *skb),
391 void *from, int length);
393 struct skb_seq_state
395 __u32 lower_offset;
396 __u32 upper_offset;
397 __u32 frag_idx;
398 __u32 stepped_offset;
399 struct sk_buff *root_skb;
400 struct sk_buff *cur_skb;
401 __u8 *frag_data;
404 extern void skb_prepare_seq_read(struct sk_buff *skb,
405 unsigned int from, unsigned int to,
406 struct skb_seq_state *st);
407 extern unsigned int skb_seq_read(unsigned int consumed, const u8 **data,
408 struct skb_seq_state *st);
409 extern void skb_abort_seq_read(struct skb_seq_state *st);
411 extern unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
412 unsigned int to, struct ts_config *config,
413 struct ts_state *state);
415 #ifdef NET_SKBUFF_DATA_USES_OFFSET
416 static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)
418 return skb->head + skb->end;
420 #else
421 static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)
423 return skb->end;
425 #endif
427 /* Internal */
428 #define skb_shinfo(SKB) ((struct skb_shared_info *)(skb_end_pointer(SKB)))
431 * skb_queue_empty - check if a queue is empty
432 * @list: queue head
434 * Returns true if the queue is empty, false otherwise.
436 static inline int skb_queue_empty(const struct sk_buff_head *list)
438 return list->next == (struct sk_buff *)list;
442 * skb_get - reference buffer
443 * @skb: buffer to reference
445 * Makes another reference to a socket buffer and returns a pointer
446 * to the buffer.
448 static inline struct sk_buff *skb_get(struct sk_buff *skb)
450 atomic_inc(&skb->users);
451 return skb;
455 * If users == 1, we are the only owner and are can avoid redundant
456 * atomic change.
460 * skb_cloned - is the buffer a clone
461 * @skb: buffer to check
463 * Returns true if the buffer was generated with skb_clone() and is
464 * one of multiple shared copies of the buffer. Cloned buffers are
465 * shared data so must not be written to under normal circumstances.
467 static inline int skb_cloned(const struct sk_buff *skb)
469 return skb->cloned &&
470 (atomic_read(&skb_shinfo(skb)->dataref) & SKB_DATAREF_MASK) != 1;
474 * skb_header_cloned - is the header a clone
475 * @skb: buffer to check
477 * Returns true if modifying the header part of the buffer requires
478 * the data to be copied.
480 static inline int skb_header_cloned(const struct sk_buff *skb)
482 int dataref;
484 if (!skb->cloned)
485 return 0;
487 dataref = atomic_read(&skb_shinfo(skb)->dataref);
488 dataref = (dataref & SKB_DATAREF_MASK) - (dataref >> SKB_DATAREF_SHIFT);
489 return dataref != 1;
493 * skb_header_release - release reference to header
494 * @skb: buffer to operate on
496 * Drop a reference to the header part of the buffer. This is done
497 * by acquiring a payload reference. You must not read from the header
498 * part of skb->data after this.
500 static inline void skb_header_release(struct sk_buff *skb)
502 BUG_ON(skb->nohdr);
503 skb->nohdr = 1;
504 atomic_add(1 << SKB_DATAREF_SHIFT, &skb_shinfo(skb)->dataref);
508 * skb_shared - is the buffer shared
509 * @skb: buffer to check
511 * Returns true if more than one person has a reference to this
512 * buffer.
514 static inline int skb_shared(const struct sk_buff *skb)
516 return atomic_read(&skb->users) != 1;
520 * skb_share_check - check if buffer is shared and if so clone it
521 * @skb: buffer to check
522 * @pri: priority for memory allocation
524 * If the buffer is shared the buffer is cloned and the old copy
525 * drops a reference. A new clone with a single reference is returned.
526 * If the buffer is not shared the original buffer is returned. When
527 * being called from interrupt status or with spinlocks held pri must
528 * be GFP_ATOMIC.
530 * NULL is returned on a memory allocation failure.
532 static inline struct sk_buff *skb_share_check(struct sk_buff *skb,
533 gfp_t pri)
535 might_sleep_if(pri & __GFP_WAIT);
536 if (skb_shared(skb)) {
537 struct sk_buff *nskb = skb_clone(skb, pri);
538 kfree_skb(skb);
539 skb = nskb;
541 return skb;
545 * Copy shared buffers into a new sk_buff. We effectively do COW on
546 * packets to handle cases where we have a local reader and forward
547 * and a couple of other messy ones. The normal one is tcpdumping
548 * a packet thats being forwarded.
552 * skb_unshare - make a copy of a shared buffer
553 * @skb: buffer to check
554 * @pri: priority for memory allocation
556 * If the socket buffer is a clone then this function creates a new
557 * copy of the data, drops a reference count on the old copy and returns
558 * the new copy with the reference count at 1. If the buffer is not a clone
559 * the original buffer is returned. When called with a spinlock held or
560 * from interrupt state @pri must be %GFP_ATOMIC
562 * %NULL is returned on a memory allocation failure.
564 static inline struct sk_buff *skb_unshare(struct sk_buff *skb,
565 gfp_t pri)
567 might_sleep_if(pri & __GFP_WAIT);
568 if (skb_cloned(skb)) {
569 struct sk_buff *nskb = skb_copy(skb, pri);
570 kfree_skb(skb); /* Free our shared copy */
571 skb = nskb;
573 return skb;
577 * skb_peek
578 * @list_: list to peek at
580 * Peek an &sk_buff. Unlike most other operations you _MUST_
581 * be careful with this one. A peek leaves the buffer on the
582 * list and someone else may run off with it. You must hold
583 * the appropriate locks or have a private queue to do this.
585 * Returns %NULL for an empty list or a pointer to the head element.
586 * The reference count is not incremented and the reference is therefore
587 * volatile. Use with caution.
589 static inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
591 struct sk_buff *list = ((struct sk_buff *)list_)->next;
592 if (list == (struct sk_buff *)list_)
593 list = NULL;
594 return list;
598 * skb_peek_tail
599 * @list_: list to peek at
601 * Peek an &sk_buff. Unlike most other operations you _MUST_
602 * be careful with this one. A peek leaves the buffer on the
603 * list and someone else may run off with it. You must hold
604 * the appropriate locks or have a private queue to do this.
606 * Returns %NULL for an empty list or a pointer to the tail element.
607 * The reference count is not incremented and the reference is therefore
608 * volatile. Use with caution.
610 static inline struct sk_buff *skb_peek_tail(struct sk_buff_head *list_)
612 struct sk_buff *list = ((struct sk_buff *)list_)->prev;
613 if (list == (struct sk_buff *)list_)
614 list = NULL;
615 return list;
619 * skb_queue_len - get queue length
620 * @list_: list to measure
622 * Return the length of an &sk_buff queue.
624 static inline __u32 skb_queue_len(const struct sk_buff_head *list_)
626 return list_->qlen;
630 * This function creates a split out lock class for each invocation;
631 * this is needed for now since a whole lot of users of the skb-queue
632 * infrastructure in drivers have different locking usage (in hardirq)
633 * than the networking core (in softirq only). In the long run either the
634 * network layer or drivers should need annotation to consolidate the
635 * main types of usage into 3 classes.
637 static inline void skb_queue_head_init(struct sk_buff_head *list)
639 spin_lock_init(&list->lock);
640 list->prev = list->next = (struct sk_buff *)list;
641 list->qlen = 0;
644 static inline void skb_queue_head_init_class(struct sk_buff_head *list,
645 struct lock_class_key *class)
647 skb_queue_head_init(list);
648 lockdep_set_class(&list->lock, class);
652 * Insert an sk_buff at the start of a list.
654 * The "__skb_xxxx()" functions are the non-atomic ones that
655 * can only be called with interrupts disabled.
659 * __skb_queue_after - queue a buffer at the list head
660 * @list: list to use
661 * @prev: place after this buffer
662 * @newsk: buffer to queue
664 * Queue a buffer int the middle of a list. This function takes no locks
665 * and you must therefore hold required locks before calling it.
667 * A buffer cannot be placed on two lists at the same time.
669 static inline void __skb_queue_after(struct sk_buff_head *list,
670 struct sk_buff *prev,
671 struct sk_buff *newsk)
673 struct sk_buff *next;
674 list->qlen++;
676 next = prev->next;
677 newsk->next = next;
678 newsk->prev = prev;
679 next->prev = prev->next = newsk;
683 * __skb_queue_head - queue a buffer at the list head
684 * @list: list to use
685 * @newsk: buffer to queue
687 * Queue a buffer at the start of a list. This function takes no locks
688 * and you must therefore hold required locks before calling it.
690 * A buffer cannot be placed on two lists at the same time.
692 extern void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk);
693 static inline void __skb_queue_head(struct sk_buff_head *list,
694 struct sk_buff *newsk)
696 __skb_queue_after(list, (struct sk_buff *)list, newsk);
700 * __skb_queue_tail - queue a buffer at the list tail
701 * @list: list to use
702 * @newsk: buffer to queue
704 * Queue a buffer at the end of a list. This function takes no locks
705 * and you must therefore hold required locks before calling it.
707 * A buffer cannot be placed on two lists at the same time.
709 extern void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk);
710 static inline void __skb_queue_tail(struct sk_buff_head *list,
711 struct sk_buff *newsk)
713 struct sk_buff *prev, *next;
715 list->qlen++;
716 next = (struct sk_buff *)list;
717 prev = next->prev;
718 newsk->next = next;
719 newsk->prev = prev;
720 next->prev = prev->next = newsk;
725 * __skb_dequeue - remove from the head of the queue
726 * @list: list to dequeue from
728 * Remove the head of the list. This function does not take any locks
729 * so must be used with appropriate locks held only. The head item is
730 * returned or %NULL if the list is empty.
732 extern struct sk_buff *skb_dequeue(struct sk_buff_head *list);
733 static inline struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
735 struct sk_buff *next, *prev, *result;
737 prev = (struct sk_buff *) list;
738 next = prev->next;
739 result = NULL;
740 if (next != prev) {
741 result = next;
742 next = next->next;
743 list->qlen--;
744 next->prev = prev;
745 prev->next = next;
746 result->next = result->prev = NULL;
748 return result;
753 * Insert a packet on a list.
755 extern void skb_insert(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list);
756 static inline void __skb_insert(struct sk_buff *newsk,
757 struct sk_buff *prev, struct sk_buff *next,
758 struct sk_buff_head *list)
760 newsk->next = next;
761 newsk->prev = prev;
762 next->prev = prev->next = newsk;
763 list->qlen++;
767 * Place a packet after a given packet in a list.
769 extern void skb_append(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list);
770 static inline void __skb_append(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head *list)
772 __skb_insert(newsk, old, old->next, list);
776 * remove sk_buff from list. _Must_ be called atomically, and with
777 * the list known..
779 extern void skb_unlink(struct sk_buff *skb, struct sk_buff_head *list);
780 static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
782 struct sk_buff *next, *prev;
784 list->qlen--;
785 next = skb->next;
786 prev = skb->prev;
787 skb->next = skb->prev = NULL;
788 next->prev = prev;
789 prev->next = next;
793 /* XXX: more streamlined implementation */
796 * __skb_dequeue_tail - remove from the tail of the queue
797 * @list: list to dequeue from
799 * Remove the tail of the list. This function does not take any locks
800 * so must be used with appropriate locks held only. The tail item is
801 * returned or %NULL if the list is empty.
803 extern struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list);
804 static inline struct sk_buff *__skb_dequeue_tail(struct sk_buff_head *list)
806 struct sk_buff *skb = skb_peek_tail(list);
807 if (skb)
808 __skb_unlink(skb, list);
809 return skb;
813 static inline int skb_is_nonlinear(const struct sk_buff *skb)
815 return skb->data_len;
818 static inline unsigned int skb_headlen(const struct sk_buff *skb)
820 return skb->len - skb->data_len;
823 static inline int skb_pagelen(const struct sk_buff *skb)
825 int i, len = 0;
827 for (i = (int)skb_shinfo(skb)->nr_frags - 1; i >= 0; i--)
828 len += skb_shinfo(skb)->frags[i].size;
829 return len + skb_headlen(skb);
832 static inline void skb_fill_page_desc(struct sk_buff *skb, int i,
833 struct page *page, int off, int size)
835 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
837 frag->page = page;
838 frag->page_offset = off;
839 frag->size = size;
840 skb_shinfo(skb)->nr_frags = i + 1;
843 #define SKB_PAGE_ASSERT(skb) BUG_ON(skb_shinfo(skb)->nr_frags)
844 #define SKB_FRAG_ASSERT(skb) BUG_ON(skb_shinfo(skb)->frag_list)
845 #define SKB_LINEAR_ASSERT(skb) BUG_ON(skb_is_nonlinear(skb))
847 #ifdef NET_SKBUFF_DATA_USES_OFFSET
848 static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb)
850 return skb->head + skb->tail;
853 static inline void skb_reset_tail_pointer(struct sk_buff *skb)
855 skb->tail = skb->data - skb->head;
858 static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset)
860 skb_reset_tail_pointer(skb);
861 skb->tail += offset;
863 #else /* NET_SKBUFF_DATA_USES_OFFSET */
864 static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb)
866 return skb->tail;
869 static inline void skb_reset_tail_pointer(struct sk_buff *skb)
871 skb->tail = skb->data;
874 static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset)
876 skb->tail = skb->data + offset;
879 #endif /* NET_SKBUFF_DATA_USES_OFFSET */
882 * Add data to an sk_buff
884 static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len)
886 unsigned char *tmp = skb_tail_pointer(skb);
887 SKB_LINEAR_ASSERT(skb);
888 skb->tail += len;
889 skb->len += len;
890 return tmp;
894 * skb_put - add data to a buffer
895 * @skb: buffer to use
896 * @len: amount of data to add
898 * This function extends the used data area of the buffer. If this would
899 * exceed the total buffer size the kernel will panic. A pointer to the
900 * first byte of the extra data is returned.
902 static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
904 unsigned char *tmp = skb_tail_pointer(skb);
905 SKB_LINEAR_ASSERT(skb);
906 skb->tail += len;
907 skb->len += len;
908 if (unlikely(skb->tail > skb->end))
909 skb_over_panic(skb, len, current_text_addr());
910 return tmp;
913 static inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len)
915 skb->data -= len;
916 skb->len += len;
917 return skb->data;
921 * skb_push - add data to the start of a buffer
922 * @skb: buffer to use
923 * @len: amount of data to add
925 * This function extends the used data area of the buffer at the buffer
926 * start. If this would exceed the total buffer headroom the kernel will
927 * panic. A pointer to the first byte of the extra data is returned.
929 static inline unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
931 skb->data -= len;
932 skb->len += len;
933 if (unlikely(skb->data<skb->head))
934 skb_under_panic(skb, len, current_text_addr());
935 return skb->data;
938 static inline unsigned char *__skb_pull(struct sk_buff *skb, unsigned int len)
940 skb->len -= len;
941 BUG_ON(skb->len < skb->data_len);
942 return skb->data += len;
946 * skb_pull - remove data from the start of a buffer
947 * @skb: buffer to use
948 * @len: amount of data to remove
950 * This function removes data from the start of a buffer, returning
951 * the memory to the headroom. A pointer to the next data in the buffer
952 * is returned. Once the data has been pulled future pushes will overwrite
953 * the old data.
955 static inline unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
957 return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
960 extern unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta);
962 static inline unsigned char *__pskb_pull(struct sk_buff *skb, unsigned int len)
964 if (len > skb_headlen(skb) &&
965 !__pskb_pull_tail(skb, len-skb_headlen(skb)))
966 return NULL;
967 skb->len -= len;
968 return skb->data += len;
971 static inline unsigned char *pskb_pull(struct sk_buff *skb, unsigned int len)
973 return unlikely(len > skb->len) ? NULL : __pskb_pull(skb, len);
976 static inline int pskb_may_pull(struct sk_buff *skb, unsigned int len)
978 if (likely(len <= skb_headlen(skb)))
979 return 1;
980 if (unlikely(len > skb->len))
981 return 0;
982 return __pskb_pull_tail(skb, len-skb_headlen(skb)) != NULL;
986 * skb_headroom - bytes at buffer head
987 * @skb: buffer to check
989 * Return the number of bytes of free space at the head of an &sk_buff.
991 static inline int skb_headroom(const struct sk_buff *skb)
993 return skb->data - skb->head;
997 * skb_tailroom - bytes at buffer end
998 * @skb: buffer to check
1000 * Return the number of bytes of free space at the tail of an sk_buff
1002 static inline int skb_tailroom(const struct sk_buff *skb)
1004 return skb_is_nonlinear(skb) ? 0 : skb->end - skb->tail;
1008 * skb_reserve - adjust headroom
1009 * @skb: buffer to alter
1010 * @len: bytes to move
1012 * Increase the headroom of an empty &sk_buff by reducing the tail
1013 * room. This is only allowed for an empty buffer.
1015 static inline void skb_reserve(struct sk_buff *skb, int len)
1017 skb->data += len;
1018 skb->tail += len;
1021 #ifdef NET_SKBUFF_DATA_USES_OFFSET
1022 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
1024 return skb->head + skb->transport_header;
1027 static inline void skb_reset_transport_header(struct sk_buff *skb)
1029 skb->transport_header = skb->data - skb->head;
1032 static inline void skb_set_transport_header(struct sk_buff *skb,
1033 const int offset)
1035 skb_reset_transport_header(skb);
1036 skb->transport_header += offset;
1039 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
1041 return skb->head + skb->network_header;
1044 static inline void skb_reset_network_header(struct sk_buff *skb)
1046 skb->network_header = skb->data - skb->head;
1049 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
1051 skb_reset_network_header(skb);
1052 skb->network_header += offset;
1055 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
1057 return skb->head + skb->mac_header;
1060 static inline int skb_mac_header_was_set(const struct sk_buff *skb)
1062 return skb->mac_header != ~0U;
1065 static inline void skb_reset_mac_header(struct sk_buff *skb)
1067 skb->mac_header = skb->data - skb->head;
1070 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
1072 skb_reset_mac_header(skb);
1073 skb->mac_header += offset;
1076 #else /* NET_SKBUFF_DATA_USES_OFFSET */
1078 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
1080 return skb->transport_header;
1083 static inline void skb_reset_transport_header(struct sk_buff *skb)
1085 skb->transport_header = skb->data;
1088 static inline void skb_set_transport_header(struct sk_buff *skb,
1089 const int offset)
1091 skb->transport_header = skb->data + offset;
1094 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
1096 return skb->network_header;
1099 static inline void skb_reset_network_header(struct sk_buff *skb)
1101 skb->network_header = skb->data;
1104 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
1106 skb->network_header = skb->data + offset;
1109 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
1111 return skb->mac_header;
1114 static inline int skb_mac_header_was_set(const struct sk_buff *skb)
1116 return skb->mac_header != NULL;
1119 static inline void skb_reset_mac_header(struct sk_buff *skb)
1121 skb->mac_header = skb->data;
1124 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
1126 skb->mac_header = skb->data + offset;
1128 #endif /* NET_SKBUFF_DATA_USES_OFFSET */
1130 static inline int skb_transport_offset(const struct sk_buff *skb)
1132 return skb_transport_header(skb) - skb->data;
1135 static inline u32 skb_network_header_len(const struct sk_buff *skb)
1137 return skb->transport_header - skb->network_header;
1140 static inline int skb_network_offset(const struct sk_buff *skb)
1142 return skb_network_header(skb) - skb->data;
1146 * CPUs often take a performance hit when accessing unaligned memory
1147 * locations. The actual performance hit varies, it can be small if the
1148 * hardware handles it or large if we have to take an exception and fix it
1149 * in software.
1151 * Since an ethernet header is 14 bytes network drivers often end up with
1152 * the IP header at an unaligned offset. The IP header can be aligned by
1153 * shifting the start of the packet by 2 bytes. Drivers should do this
1154 * with:
1156 * skb_reserve(NET_IP_ALIGN);
1158 * The downside to this alignment of the IP header is that the DMA is now
1159 * unaligned. On some architectures the cost of an unaligned DMA is high
1160 * and this cost outweighs the gains made by aligning the IP header.
1162 * Since this trade off varies between architectures, we allow NET_IP_ALIGN
1163 * to be overridden.
1165 #ifndef NET_IP_ALIGN
1166 #define NET_IP_ALIGN 2
1167 #endif
1170 * The networking layer reserves some headroom in skb data (via
1171 * dev_alloc_skb). This is used to avoid having to reallocate skb data when
1172 * the header has to grow. In the default case, if the header has to grow
1173 * 16 bytes or less we avoid the reallocation.
1175 * Unfortunately this headroom changes the DMA alignment of the resulting
1176 * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive
1177 * on some architectures. An architecture can override this value,
1178 * perhaps setting it to a cacheline in size (since that will maintain
1179 * cacheline alignment of the DMA). It must be a power of 2.
1181 * Various parts of the networking layer expect at least 16 bytes of
1182 * headroom, you should not reduce this.
1184 * This has been changed to 64 to acommodate for routing between ethernet
1185 * and wireless, but only for new allocations
1187 #ifndef NET_SKB_PAD
1188 #define NET_SKB_PAD 16
1189 #endif
1191 #ifndef NET_SKB_PAD_ALLOC
1192 #define NET_SKB_PAD_ALLOC 64
1193 #endif
1195 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
1197 static inline void __skb_trim(struct sk_buff *skb, unsigned int len)
1199 if (unlikely(skb->data_len)) {
1200 WARN_ON(1);
1201 return;
1203 skb->len = len;
1204 skb_set_tail_pointer(skb, len);
1208 * skb_trim - remove end from a buffer
1209 * @skb: buffer to alter
1210 * @len: new length
1212 * Cut the length of a buffer down by removing data from the tail. If
1213 * the buffer is already under the length specified it is not modified.
1214 * The skb must be linear.
1216 static inline void skb_trim(struct sk_buff *skb, unsigned int len)
1218 if (skb->len > len)
1219 __skb_trim(skb, len);
1223 static inline int __pskb_trim(struct sk_buff *skb, unsigned int len)
1225 if (skb->data_len)
1226 return ___pskb_trim(skb, len);
1227 __skb_trim(skb, len);
1228 return 0;
1231 static inline int pskb_trim(struct sk_buff *skb, unsigned int len)
1233 return (len < skb->len) ? __pskb_trim(skb, len) : 0;
1237 * pskb_trim_unique - remove end from a paged unique (not cloned) buffer
1238 * @skb: buffer to alter
1239 * @len: new length
1241 * This is identical to pskb_trim except that the caller knows that
1242 * the skb is not cloned so we should never get an error due to out-
1243 * of-memory.
1245 static inline void pskb_trim_unique(struct sk_buff *skb, unsigned int len)
1247 int err = pskb_trim(skb, len);
1248 BUG_ON(err);
1252 * skb_orphan - orphan a buffer
1253 * @skb: buffer to orphan
1255 * If a buffer currently has an owner then we call the owner's
1256 * destructor function and make the @skb unowned. The buffer continues
1257 * to exist but is no longer charged to its former owner.
1259 static inline void skb_orphan(struct sk_buff *skb)
1261 if (skb->destructor)
1262 skb->destructor(skb);
1263 skb->destructor = NULL;
1264 skb->sk = NULL;
1268 * __skb_queue_purge - empty a list
1269 * @list: list to empty
1271 * Delete all buffers on an &sk_buff list. Each buffer is removed from
1272 * the list and one reference dropped. This function does not take the
1273 * list lock and the caller must hold the relevant locks to use it.
1275 extern void skb_queue_purge(struct sk_buff_head *list);
1276 static inline void __skb_queue_purge(struct sk_buff_head *list)
1278 struct sk_buff *skb;
1279 while ((skb = __skb_dequeue(list)) != NULL)
1280 kfree_skb(skb);
1284 * __dev_alloc_skb - allocate an skbuff for receiving
1285 * @length: length to allocate
1286 * @gfp_mask: get_free_pages mask, passed to alloc_skb
1288 * Allocate a new &sk_buff and assign it a usage count of one. The
1289 * buffer has unspecified headroom built in. Users should allocate
1290 * the headroom they think they need without accounting for the
1291 * built in space. The built in space is used for optimisations.
1293 * %NULL is returned if there is no free memory.
1295 static inline struct sk_buff *__dev_alloc_skb(unsigned int length,
1296 gfp_t gfp_mask)
1298 struct sk_buff *skb = alloc_skb(length + NET_SKB_PAD_ALLOC, gfp_mask);
1299 if (likely(skb))
1300 skb_reserve(skb, NET_SKB_PAD_ALLOC);
1301 return skb;
1305 * dev_alloc_skb - allocate an skbuff for receiving
1306 * @length: length to allocate
1308 * Allocate a new &sk_buff and assign it a usage count of one. The
1309 * buffer has unspecified headroom built in. Users should allocate
1310 * the headroom they think they need without accounting for the
1311 * built in space. The built in space is used for optimisations.
1313 * %NULL is returned if there is no free memory. Although this function
1314 * allocates memory it can be called from an interrupt.
1316 static inline struct sk_buff *dev_alloc_skb(unsigned int length)
1318 return __dev_alloc_skb(length, GFP_ATOMIC);
1321 extern struct sk_buff *__netdev_alloc_skb(struct net_device *dev,
1322 unsigned int length, gfp_t gfp_mask);
1325 * netdev_alloc_skb - allocate an skbuff for rx on a specific device
1326 * @dev: network device to receive on
1327 * @length: length to allocate
1329 * Allocate a new &sk_buff and assign it a usage count of one. The
1330 * buffer has unspecified headroom built in. Users should allocate
1331 * the headroom they think they need without accounting for the
1332 * built in space. The built in space is used for optimisations.
1334 * %NULL is returned if there is no free memory. Although this function
1335 * allocates memory it can be called from an interrupt.
1337 static inline struct sk_buff *netdev_alloc_skb(struct net_device *dev,
1338 unsigned int length)
1340 return __netdev_alloc_skb(dev, length, GFP_ATOMIC);
1344 * skb_clone_writable - is the header of a clone writable
1345 * @skb: buffer to check
1346 * @len: length up to which to write
1348 * Returns true if modifying the header part of the cloned buffer
1349 * does not requires the data to be copied.
1351 static inline int skb_clone_writable(struct sk_buff *skb, int len)
1353 return !skb_header_cloned(skb) &&
1354 skb_headroom(skb) + len <= skb->hdr_len;
1358 * skb_cow - copy header of skb when it is required
1359 * @skb: buffer to cow
1360 * @headroom: needed headroom
1362 * If the skb passed lacks sufficient headroom or its data part
1363 * is shared, data is reallocated. If reallocation fails, an error
1364 * is returned and original skb is not changed.
1366 * The result is skb with writable area skb->head...skb->tail
1367 * and at least @headroom of space at head.
1369 static inline int skb_cow(struct sk_buff *skb, unsigned int headroom)
1371 int delta = (headroom > NET_SKB_PAD ? headroom : NET_SKB_PAD) -
1372 skb_headroom(skb);
1374 if (delta < 0)
1375 delta = 0;
1377 if (delta || skb_cloned(skb))
1378 return pskb_expand_head(skb, (delta + (NET_SKB_PAD_ALLOC-1)) &
1379 ~(NET_SKB_PAD_ALLOC-1), 0, GFP_ATOMIC);
1380 return 0;
1384 * skb_padto - pad an skbuff up to a minimal size
1385 * @skb: buffer to pad
1386 * @len: minimal length
1388 * Pads up a buffer to ensure the trailing bytes exist and are
1389 * blanked. If the buffer already contains sufficient data it
1390 * is untouched. Otherwise it is extended. Returns zero on
1391 * success. The skb is freed on error.
1394 static inline int skb_padto(struct sk_buff *skb, unsigned int len)
1396 unsigned int size = skb->len;
1397 if (likely(size >= len))
1398 return 0;
1399 return skb_pad(skb, len-size);
1402 static inline int skb_add_data(struct sk_buff *skb,
1403 char __user *from, int copy)
1405 const int off = skb->len;
1407 if (skb->ip_summed == CHECKSUM_NONE) {
1408 int err = 0;
1409 __wsum csum = csum_and_copy_from_user(from, skb_put(skb, copy),
1410 copy, 0, &err);
1411 if (!err) {
1412 skb->csum = csum_block_add(skb->csum, csum, off);
1413 return 0;
1415 } else if (!copy_from_user(skb_put(skb, copy), from, copy))
1416 return 0;
1418 __skb_trim(skb, off);
1419 return -EFAULT;
1422 static inline int skb_can_coalesce(struct sk_buff *skb, int i,
1423 struct page *page, int off)
1425 if (i) {
1426 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
1428 return page == frag->page &&
1429 off == frag->page_offset + frag->size;
1431 return 0;
1434 static inline int __skb_linearize(struct sk_buff *skb)
1436 return __pskb_pull_tail(skb, skb->data_len) ? 0 : -ENOMEM;
1440 * skb_linearize - convert paged skb to linear one
1441 * @skb: buffer to linarize
1443 * If there is no free memory -ENOMEM is returned, otherwise zero
1444 * is returned and the old skb data released.
1446 static inline int skb_linearize(struct sk_buff *skb)
1448 return skb_is_nonlinear(skb) ? __skb_linearize(skb) : 0;
1452 * skb_linearize_cow - make sure skb is linear and writable
1453 * @skb: buffer to process
1455 * If there is no free memory -ENOMEM is returned, otherwise zero
1456 * is returned and the old skb data released.
1458 static inline int skb_linearize_cow(struct sk_buff *skb)
1460 return skb_is_nonlinear(skb) || skb_cloned(skb) ?
1461 __skb_linearize(skb) : 0;
1465 * skb_postpull_rcsum - update checksum for received skb after pull
1466 * @skb: buffer to update
1467 * @start: start of data before pull
1468 * @len: length of data pulled
1470 * After doing a pull on a received packet, you need to call this to
1471 * update the CHECKSUM_COMPLETE checksum, or set ip_summed to
1472 * CHECKSUM_NONE so that it can be recomputed from scratch.
1475 static inline void skb_postpull_rcsum(struct sk_buff *skb,
1476 const void *start, unsigned int len)
1478 if (skb->ip_summed == CHECKSUM_COMPLETE)
1479 skb->csum = csum_sub(skb->csum, csum_partial(start, len, 0));
1482 unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len);
1485 * pskb_trim_rcsum - trim received skb and update checksum
1486 * @skb: buffer to trim
1487 * @len: new length
1489 * This is exactly the same as pskb_trim except that it ensures the
1490 * checksum of received packets are still valid after the operation.
1493 static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len)
1495 if (likely(len >= skb->len))
1496 return 0;
1497 if (skb->ip_summed == CHECKSUM_COMPLETE)
1498 skb->ip_summed = CHECKSUM_NONE;
1499 return __pskb_trim(skb, len);
1502 #define skb_queue_walk(queue, skb) \
1503 for (skb = (queue)->next; \
1504 prefetch(skb->next), (skb != (struct sk_buff *)(queue)); \
1505 skb = skb->next)
1507 #define skb_queue_walk_safe(queue, skb, tmp) \
1508 for (skb = (queue)->next, tmp = skb->next; \
1509 skb != (struct sk_buff *)(queue); \
1510 skb = tmp, tmp = skb->next)
1512 #define skb_queue_reverse_walk(queue, skb) \
1513 for (skb = (queue)->prev; \
1514 prefetch(skb->prev), (skb != (struct sk_buff *)(queue)); \
1515 skb = skb->prev)
1518 extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
1519 int noblock, int *err);
1520 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
1521 struct poll_table_struct *wait);
1522 extern int skb_copy_datagram_iovec(const struct sk_buff *from,
1523 int offset, struct iovec *to,
1524 int size);
1525 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
1526 int hlen,
1527 struct iovec *iov);
1528 extern void skb_free_datagram(struct sock *sk, struct sk_buff *skb);
1529 extern void skb_kill_datagram(struct sock *sk, struct sk_buff *skb,
1530 unsigned int flags);
1531 extern __wsum skb_checksum(const struct sk_buff *skb, int offset,
1532 int len, __wsum csum);
1533 extern int skb_copy_bits(const struct sk_buff *skb, int offset,
1534 void *to, int len);
1535 extern int skb_store_bits(struct sk_buff *skb, int offset,
1536 const void *from, int len);
1537 extern __wsum skb_copy_and_csum_bits(const struct sk_buff *skb,
1538 int offset, u8 *to, int len,
1539 __wsum csum);
1540 extern void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to);
1541 extern void skb_split(struct sk_buff *skb,
1542 struct sk_buff *skb1, const u32 len);
1544 extern struct sk_buff *skb_segment(struct sk_buff *skb, int features);
1546 static inline void *skb_header_pointer(const struct sk_buff *skb, int offset,
1547 int len, void *buffer)
1549 int hlen = skb_headlen(skb);
1551 if (hlen - offset >= len)
1552 return skb->data + offset;
1554 if (skb_copy_bits(skb, offset, buffer, len) < 0)
1555 return NULL;
1557 return buffer;
1560 static inline void skb_copy_from_linear_data(const struct sk_buff *skb,
1561 void *to,
1562 const unsigned int len)
1564 memcpy(to, skb->data, len);
1567 static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb,
1568 const int offset, void *to,
1569 const unsigned int len)
1571 memcpy(to, skb->data + offset, len);
1574 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
1575 const void *from,
1576 const unsigned int len)
1578 memcpy(skb->data, from, len);
1581 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
1582 const int offset,
1583 const void *from,
1584 const unsigned int len)
1586 memcpy(skb->data + offset, from, len);
1589 extern void skb_init(void);
1592 * skb_get_timestamp - get timestamp from a skb
1593 * @skb: skb to get stamp from
1594 * @stamp: pointer to struct timeval to store stamp in
1596 * Timestamps are stored in the skb as offsets to a base timestamp.
1597 * This function converts the offset back to a struct timeval and stores
1598 * it in stamp.
1600 static inline void skb_get_timestamp(const struct sk_buff *skb, struct timeval *stamp)
1602 *stamp = ktime_to_timeval(skb->tstamp);
1605 static inline void __net_timestamp(struct sk_buff *skb)
1607 skb->tstamp = ktime_get_real();
1610 static inline ktime_t net_timedelta(ktime_t t)
1612 return ktime_sub(ktime_get_real(), t);
1615 static inline ktime_t net_invalid_timestamp(void)
1617 return ktime_set(0, 0);
1620 extern __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len);
1621 extern __sum16 __skb_checksum_complete(struct sk_buff *skb);
1623 static inline int skb_csum_unnecessary(const struct sk_buff *skb)
1625 return skb->ip_summed & CHECKSUM_UNNECESSARY;
1629 * skb_checksum_complete - Calculate checksum of an entire packet
1630 * @skb: packet to process
1632 * This function calculates the checksum over the entire packet plus
1633 * the value of skb->csum. The latter can be used to supply the
1634 * checksum of a pseudo header as used by TCP/UDP. It returns the
1635 * checksum.
1637 * For protocols that contain complete checksums such as ICMP/TCP/UDP,
1638 * this function can be used to verify that checksum on received
1639 * packets. In that case the function should return zero if the
1640 * checksum is correct. In particular, this function will return zero
1641 * if skb->ip_summed is CHECKSUM_UNNECESSARY which indicates that the
1642 * hardware has already verified the correctness of the checksum.
1644 static inline unsigned int skb_checksum_complete(struct sk_buff *skb)
1646 return skb_csum_unnecessary(skb) ?
1647 0 : __skb_checksum_complete(skb);
1650 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1651 extern void nf_conntrack_destroy(struct nf_conntrack *nfct);
1652 static inline void nf_conntrack_put(struct nf_conntrack *nfct)
1654 if (nfct && atomic_dec_and_test(&nfct->use))
1655 nf_conntrack_destroy(nfct);
1657 static inline void nf_conntrack_get(struct nf_conntrack *nfct)
1659 if (nfct)
1660 atomic_inc(&nfct->use);
1662 static inline void nf_conntrack_get_reasm(struct sk_buff *skb)
1664 if (skb)
1665 atomic_inc(&skb->users);
1667 static inline void nf_conntrack_put_reasm(struct sk_buff *skb)
1669 if (skb)
1670 kfree_skb(skb);
1672 #endif
1673 #ifdef CONFIG_BRIDGE_NETFILTER
1674 static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1676 if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
1677 kfree(nf_bridge);
1679 static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1681 if (nf_bridge)
1682 atomic_inc(&nf_bridge->use);
1684 #endif /* CONFIG_BRIDGE_NETFILTER */
1685 static inline void nf_reset(struct sk_buff *skb)
1687 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1688 nf_conntrack_put(skb->nfct);
1689 skb->nfct = NULL;
1690 nf_conntrack_put_reasm(skb->nfct_reasm);
1691 skb->nfct_reasm = NULL;
1692 #endif
1693 #ifdef CONFIG_BRIDGE_NETFILTER
1694 nf_bridge_put(skb->nf_bridge);
1695 skb->nf_bridge = NULL;
1696 #endif
1699 /* Note: This doesn't put any conntrack and bridge info in dst. */
1700 static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src)
1702 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1703 dst->nfct = src->nfct;
1704 nf_conntrack_get(src->nfct);
1705 dst->nfctinfo = src->nfctinfo;
1706 dst->nfct_reasm = src->nfct_reasm;
1707 nf_conntrack_get_reasm(src->nfct_reasm);
1708 #endif
1709 #ifdef CONFIG_BRIDGE_NETFILTER
1710 dst->nf_bridge = src->nf_bridge;
1711 nf_bridge_get(src->nf_bridge);
1712 #endif
1713 #if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1714 dst->imq_flags = src->imq_flags;
1715 dst->nf_info = src->nf_info;
1716 #endif
1719 static inline void nf_copy(struct sk_buff *dst, const struct sk_buff *src)
1721 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1722 nf_conntrack_put(dst->nfct);
1723 nf_conntrack_put_reasm(dst->nfct_reasm);
1724 #endif
1725 #ifdef CONFIG_BRIDGE_NETFILTER
1726 nf_bridge_put(dst->nf_bridge);
1727 #endif
1728 __nf_copy(dst, src);
1731 #ifdef CONFIG_NETWORK_SECMARK
1732 static inline void skb_copy_secmark(struct sk_buff *to, const struct sk_buff *from)
1734 to->secmark = from->secmark;
1737 static inline void skb_init_secmark(struct sk_buff *skb)
1739 skb->secmark = 0;
1741 #else
1742 static inline void skb_copy_secmark(struct sk_buff *to, const struct sk_buff *from)
1745 static inline void skb_init_secmark(struct sk_buff *skb)
1747 #endif
1749 static inline int skb_is_gso(const struct sk_buff *skb)
1751 return skb_shinfo(skb)->gso_size;
1754 static inline void skb_forward_csum(struct sk_buff *skb)
1756 /* Unfortunately we don't support this one. Any brave souls? */
1757 if (skb->ip_summed == CHECKSUM_COMPLETE)
1758 skb->ip_summed = CHECKSUM_NONE;
1761 #endif /* __KERNEL__ */
1762 #endif /* _LINUX_SKBUFF_H */