diff options
Diffstat (limited to 'include/linux/skbuff.h')
-rw-r--r-- | include/linux/skbuff.h | 412 |
1 files changed, 324 insertions, 88 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 4ff3940210d8..253a2b9be9d6 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h | |||
@@ -27,20 +27,24 @@ | |||
27 | #include <net/checksum.h> | 27 | #include <net/checksum.h> |
28 | #include <linux/rcupdate.h> | 28 | #include <linux/rcupdate.h> |
29 | #include <linux/dmaengine.h> | 29 | #include <linux/dmaengine.h> |
30 | #include <linux/hrtimer.h> | ||
30 | 31 | ||
31 | #define HAVE_ALLOC_SKB /* For the drivers to know */ | 32 | #define HAVE_ALLOC_SKB /* For the drivers to know */ |
32 | #define HAVE_ALIGNABLE_SKB /* Ditto 8) */ | 33 | #define HAVE_ALIGNABLE_SKB /* Ditto 8) */ |
33 | 34 | ||
35 | /* Don't change this without changing skb_csum_unnecessary! */ | ||
34 | #define CHECKSUM_NONE 0 | 36 | #define CHECKSUM_NONE 0 |
35 | #define CHECKSUM_PARTIAL 1 | 37 | #define CHECKSUM_UNNECESSARY 1 |
36 | #define CHECKSUM_UNNECESSARY 2 | 38 | #define CHECKSUM_COMPLETE 2 |
37 | #define CHECKSUM_COMPLETE 3 | 39 | #define CHECKSUM_PARTIAL 3 |
38 | 40 | ||
39 | #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \ | 41 | #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \ |
40 | ~(SMP_CACHE_BYTES - 1)) | 42 | ~(SMP_CACHE_BYTES - 1)) |
41 | #define SKB_MAX_ORDER(X, ORDER) (((PAGE_SIZE << (ORDER)) - (X) - \ | 43 | #define SKB_WITH_OVERHEAD(X) \ |
42 | sizeof(struct skb_shared_info)) & \ | 44 | (((X) - sizeof(struct skb_shared_info)) & \ |
43 | ~(SMP_CACHE_BYTES - 1)) | 45 | ~(SMP_CACHE_BYTES - 1)) |
46 | #define SKB_MAX_ORDER(X, ORDER) \ | ||
47 | SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X)) | ||
44 | #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) | 48 | #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) |
45 | #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2)) | 49 | #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2)) |
46 | 50 | ||
@@ -66,8 +70,8 @@ | |||
66 | * NONE: skb is checksummed by protocol or csum is not required. | 70 | * NONE: skb is checksummed by protocol or csum is not required. |
67 | * | 71 | * |
68 | * PARTIAL: device is required to csum packet as seen by hard_start_xmit | 72 | * PARTIAL: device is required to csum packet as seen by hard_start_xmit |
69 | * from skb->h.raw to the end and to record the checksum | 73 | * from skb->transport_header to the end and to record the checksum |
70 | * at skb->h.raw+skb->csum. | 74 | * at skb->transport_header + skb->csum. |
71 | * | 75 | * |
72 | * Device must show its capabilities in dev->features, set | 76 | * Device must show its capabilities in dev->features, set |
73 | * at device setup time. | 77 | * at device setup time. |
@@ -83,12 +87,13 @@ | |||
83 | */ | 87 | */ |
84 | 88 | ||
85 | struct net_device; | 89 | struct net_device; |
90 | struct scatterlist; | ||
86 | 91 | ||
87 | #ifdef CONFIG_NETFILTER | 92 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
88 | struct nf_conntrack { | 93 | struct nf_conntrack { |
89 | atomic_t use; | 94 | atomic_t use; |
90 | void (*destroy)(struct nf_conntrack *); | ||
91 | }; | 95 | }; |
96 | #endif | ||
92 | 97 | ||
93 | #ifdef CONFIG_BRIDGE_NETFILTER | 98 | #ifdef CONFIG_BRIDGE_NETFILTER |
94 | struct nf_bridge_info { | 99 | struct nf_bridge_info { |
@@ -103,8 +108,6 @@ struct nf_bridge_info { | |||
103 | }; | 108 | }; |
104 | #endif | 109 | #endif |
105 | 110 | ||
106 | #endif | ||
107 | |||
108 | struct sk_buff_head { | 111 | struct sk_buff_head { |
109 | /* These two members must be first. */ | 112 | /* These two members must be first. */ |
110 | struct sk_buff *next; | 113 | struct sk_buff *next; |
@@ -156,11 +159,6 @@ struct skb_shared_info { | |||
156 | #define SKB_DATAREF_SHIFT 16 | 159 | #define SKB_DATAREF_SHIFT 16 |
157 | #define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1) | 160 | #define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1) |
158 | 161 | ||
159 | struct skb_timeval { | ||
160 | u32 off_sec; | ||
161 | u32 off_usec; | ||
162 | }; | ||
163 | |||
164 | 162 | ||
165 | enum { | 163 | enum { |
166 | SKB_FCLONE_UNAVAILABLE, | 164 | SKB_FCLONE_UNAVAILABLE, |
@@ -181,6 +179,16 @@ enum { | |||
181 | SKB_GSO_TCPV6 = 1 << 4, | 179 | SKB_GSO_TCPV6 = 1 << 4, |
182 | }; | 180 | }; |
183 | 181 | ||
182 | #if BITS_PER_LONG > 32 | ||
183 | #define NET_SKBUFF_DATA_USES_OFFSET 1 | ||
184 | #endif | ||
185 | |||
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 | ||
191 | |||
184 | /** | 192 | /** |
185 | * struct sk_buff - socket buffer | 193 | * struct sk_buff - socket buffer |
186 | * @next: Next buffer in list | 194 | * @next: Next buffer in list |
@@ -188,17 +196,19 @@ enum { | |||
188 | * @sk: Socket we are owned by | 196 | * @sk: Socket we are owned by |
189 | * @tstamp: Time we arrived | 197 | * @tstamp: Time we arrived |
190 | * @dev: Device we arrived on/are leaving by | 198 | * @dev: Device we arrived on/are leaving by |
191 | * @input_dev: Device we arrived on | 199 | * @iif: ifindex of device we arrived on |
192 | * @h: Transport layer header | 200 | * @h: Transport layer header |
193 | * @nh: Network layer header | 201 | * @network_header: Network layer header |
194 | * @mac: Link layer header | 202 | * @mac_header: Link layer header |
195 | * @dst: destination entry | 203 | * @dst: destination entry |
196 | * @sp: the security path, used for xfrm | 204 | * @sp: the security path, used for xfrm |
197 | * @cb: Control buffer. Free for use by every layer. Put private vars here | 205 | * @cb: Control buffer. Free for use by every layer. Put private vars here |
198 | * @len: Length of actual data | 206 | * @len: Length of actual data |
199 | * @data_len: Data length | 207 | * @data_len: Data length |
200 | * @mac_len: Length of link layer header | 208 | * @mac_len: Length of link layer header |
201 | * @csum: Checksum | 209 | * @csum: Checksum (must include start/offset pair) |
210 | * @csum_start: Offset from skb->head where checksumming should start | ||
211 | * @csum_offset: Offset from csum_start where checksum should be stored | ||
202 | * @local_df: allow local fragmentation | 212 | * @local_df: allow local fragmentation |
203 | * @cloned: Head may be cloned (check refcnt to be sure) | 213 | * @cloned: Head may be cloned (check refcnt to be sure) |
204 | * @nohdr: Payload reference only, must not modify header | 214 | * @nohdr: Payload reference only, must not modify header |
@@ -233,30 +243,10 @@ struct sk_buff { | |||
233 | struct sk_buff *prev; | 243 | struct sk_buff *prev; |
234 | 244 | ||
235 | struct sock *sk; | 245 | struct sock *sk; |
236 | struct skb_timeval tstamp; | 246 | ktime_t tstamp; |
237 | struct net_device *dev; | 247 | struct net_device *dev; |
238 | struct net_device *input_dev; | 248 | int iif; |
239 | 249 | /* 4 byte hole on 64 bit*/ | |
240 | union { | ||
241 | struct tcphdr *th; | ||
242 | struct udphdr *uh; | ||
243 | struct icmphdr *icmph; | ||
244 | struct igmphdr *igmph; | ||
245 | struct iphdr *ipiph; | ||
246 | struct ipv6hdr *ipv6h; | ||
247 | unsigned char *raw; | ||
248 | } h; | ||
249 | |||
250 | union { | ||
251 | struct iphdr *iph; | ||
252 | struct ipv6hdr *ipv6h; | ||
253 | struct arphdr *arph; | ||
254 | unsigned char *raw; | ||
255 | } nh; | ||
256 | |||
257 | union { | ||
258 | unsigned char *raw; | ||
259 | } mac; | ||
260 | 250 | ||
261 | struct dst_entry *dst; | 251 | struct dst_entry *dst; |
262 | struct sec_path *sp; | 252 | struct sec_path *sp; |
@@ -274,7 +264,10 @@ struct sk_buff { | |||
274 | mac_len; | 264 | mac_len; |
275 | union { | 265 | union { |
276 | __wsum csum; | 266 | __wsum csum; |
277 | __u32 csum_offset; | 267 | struct { |
268 | __u16 csum_start; | ||
269 | __u16 csum_offset; | ||
270 | }; | ||
278 | }; | 271 | }; |
279 | __u32 priority; | 272 | __u32 priority; |
280 | __u8 local_df:1, | 273 | __u8 local_df:1, |
@@ -288,15 +281,13 @@ struct sk_buff { | |||
288 | __be16 protocol; | 281 | __be16 protocol; |
289 | 282 | ||
290 | void (*destructor)(struct sk_buff *skb); | 283 | void (*destructor)(struct sk_buff *skb); |
291 | #ifdef CONFIG_NETFILTER | ||
292 | struct nf_conntrack *nfct; | ||
293 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | 284 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
285 | struct nf_conntrack *nfct; | ||
294 | struct sk_buff *nfct_reasm; | 286 | struct sk_buff *nfct_reasm; |
295 | #endif | 287 | #endif |
296 | #ifdef CONFIG_BRIDGE_NETFILTER | 288 | #ifdef CONFIG_BRIDGE_NETFILTER |
297 | struct nf_bridge_info *nf_bridge; | 289 | struct nf_bridge_info *nf_bridge; |
298 | #endif | 290 | #endif |
299 | #endif /* CONFIG_NETFILTER */ | ||
300 | #ifdef CONFIG_NET_SCHED | 291 | #ifdef CONFIG_NET_SCHED |
301 | __u16 tc_index; /* traffic control index */ | 292 | __u16 tc_index; /* traffic control index */ |
302 | #ifdef CONFIG_NET_CLS_ACT | 293 | #ifdef CONFIG_NET_CLS_ACT |
@@ -312,13 +303,16 @@ struct sk_buff { | |||
312 | 303 | ||
313 | __u32 mark; | 304 | __u32 mark; |
314 | 305 | ||
306 | sk_buff_data_t transport_header; | ||
307 | sk_buff_data_t network_header; | ||
308 | sk_buff_data_t mac_header; | ||
315 | /* These elements must be at the end, see alloc_skb() for details. */ | 309 | /* These elements must be at the end, see alloc_skb() for details. */ |
310 | sk_buff_data_t tail; | ||
311 | sk_buff_data_t end; | ||
312 | unsigned char *head, | ||
313 | *data; | ||
316 | unsigned int truesize; | 314 | unsigned int truesize; |
317 | atomic_t users; | 315 | atomic_t users; |
318 | unsigned char *head, | ||
319 | *data, | ||
320 | *tail, | ||
321 | *end; | ||
322 | }; | 316 | }; |
323 | 317 | ||
324 | #ifdef __KERNEL__ | 318 | #ifdef __KERNEL__ |
@@ -345,9 +339,6 @@ static inline struct sk_buff *alloc_skb_fclone(unsigned int size, | |||
345 | return __alloc_skb(size, priority, 1, -1); | 339 | return __alloc_skb(size, priority, 1, -1); |
346 | } | 340 | } |
347 | 341 | ||
348 | extern struct sk_buff *alloc_skb_from_cache(struct kmem_cache *cp, | ||
349 | unsigned int size, | ||
350 | gfp_t priority); | ||
351 | extern void kfree_skbmem(struct sk_buff *skb); | 342 | extern void kfree_skbmem(struct sk_buff *skb); |
352 | extern struct sk_buff *skb_clone(struct sk_buff *skb, | 343 | extern struct sk_buff *skb_clone(struct sk_buff *skb, |
353 | gfp_t priority); | 344 | gfp_t priority); |
@@ -363,6 +354,11 @@ extern struct sk_buff *skb_realloc_headroom(struct sk_buff *skb, | |||
363 | extern struct sk_buff *skb_copy_expand(const struct sk_buff *skb, | 354 | extern struct sk_buff *skb_copy_expand(const struct sk_buff *skb, |
364 | int newheadroom, int newtailroom, | 355 | int newheadroom, int newtailroom, |
365 | gfp_t priority); | 356 | gfp_t priority); |
357 | extern int skb_to_sgvec(struct sk_buff *skb, | ||
358 | struct scatterlist *sg, int offset, | ||
359 | int len); | ||
360 | extern int skb_cow_data(struct sk_buff *skb, int tailbits, | ||
361 | struct sk_buff **trailer); | ||
366 | extern int skb_pad(struct sk_buff *skb, int pad); | 362 | extern int skb_pad(struct sk_buff *skb, int pad); |
367 | #define dev_kfree_skb(a) kfree_skb(a) | 363 | #define dev_kfree_skb(a) kfree_skb(a) |
368 | extern void skb_over_panic(struct sk_buff *skb, int len, | 364 | extern void skb_over_panic(struct sk_buff *skb, int len, |
@@ -404,8 +400,20 @@ extern unsigned int skb_find_text(struct sk_buff *skb, unsigned int from, | |||
404 | unsigned int to, struct ts_config *config, | 400 | unsigned int to, struct ts_config *config, |
405 | struct ts_state *state); | 401 | struct ts_state *state); |
406 | 402 | ||
403 | #ifdef NET_SKBUFF_DATA_USES_OFFSET | ||
404 | static inline unsigned char *skb_end_pointer(const struct sk_buff *skb) | ||
405 | { | ||
406 | return skb->head + skb->end; | ||
407 | } | ||
408 | #else | ||
409 | static inline unsigned char *skb_end_pointer(const struct sk_buff *skb) | ||
410 | { | ||
411 | return skb->end; | ||
412 | } | ||
413 | #endif | ||
414 | |||
407 | /* Internal */ | 415 | /* Internal */ |
408 | #define skb_shinfo(SKB) ((struct skb_shared_info *)((SKB)->end)) | 416 | #define skb_shinfo(SKB) ((struct skb_shared_info *)(skb_end_pointer(SKB))) |
409 | 417 | ||
410 | /** | 418 | /** |
411 | * skb_queue_empty - check if a queue is empty | 419 | * skb_queue_empty - check if a queue is empty |
@@ -621,6 +629,13 @@ static inline void skb_queue_head_init(struct sk_buff_head *list) | |||
621 | list->qlen = 0; | 629 | list->qlen = 0; |
622 | } | 630 | } |
623 | 631 | ||
632 | static inline void skb_queue_head_init_class(struct sk_buff_head *list, | ||
633 | struct lock_class_key *class) | ||
634 | { | ||
635 | skb_queue_head_init(list); | ||
636 | lockdep_set_class(&list->lock, class); | ||
637 | } | ||
638 | |||
624 | /* | 639 | /* |
625 | * Insert an sk_buff at the start of a list. | 640 | * Insert an sk_buff at the start of a list. |
626 | * | 641 | * |
@@ -817,12 +832,46 @@ static inline void skb_fill_page_desc(struct sk_buff *skb, int i, | |||
817 | #define SKB_FRAG_ASSERT(skb) BUG_ON(skb_shinfo(skb)->frag_list) | 832 | #define SKB_FRAG_ASSERT(skb) BUG_ON(skb_shinfo(skb)->frag_list) |
818 | #define SKB_LINEAR_ASSERT(skb) BUG_ON(skb_is_nonlinear(skb)) | 833 | #define SKB_LINEAR_ASSERT(skb) BUG_ON(skb_is_nonlinear(skb)) |
819 | 834 | ||
835 | #ifdef NET_SKBUFF_DATA_USES_OFFSET | ||
836 | static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb) | ||
837 | { | ||
838 | return skb->head + skb->tail; | ||
839 | } | ||
840 | |||
841 | static inline void skb_reset_tail_pointer(struct sk_buff *skb) | ||
842 | { | ||
843 | skb->tail = skb->data - skb->head; | ||
844 | } | ||
845 | |||
846 | static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset) | ||
847 | { | ||
848 | skb_reset_tail_pointer(skb); | ||
849 | skb->tail += offset; | ||
850 | } | ||
851 | #else /* NET_SKBUFF_DATA_USES_OFFSET */ | ||
852 | static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb) | ||
853 | { | ||
854 | return skb->tail; | ||
855 | } | ||
856 | |||
857 | static inline void skb_reset_tail_pointer(struct sk_buff *skb) | ||
858 | { | ||
859 | skb->tail = skb->data; | ||
860 | } | ||
861 | |||
862 | static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset) | ||
863 | { | ||
864 | skb->tail = skb->data + offset; | ||
865 | } | ||
866 | |||
867 | #endif /* NET_SKBUFF_DATA_USES_OFFSET */ | ||
868 | |||
820 | /* | 869 | /* |
821 | * Add data to an sk_buff | 870 | * Add data to an sk_buff |
822 | */ | 871 | */ |
823 | static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len) | 872 | static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len) |
824 | { | 873 | { |
825 | unsigned char *tmp = skb->tail; | 874 | unsigned char *tmp = skb_tail_pointer(skb); |
826 | SKB_LINEAR_ASSERT(skb); | 875 | SKB_LINEAR_ASSERT(skb); |
827 | skb->tail += len; | 876 | skb->tail += len; |
828 | skb->len += len; | 877 | skb->len += len; |
@@ -840,11 +889,11 @@ static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len) | |||
840 | */ | 889 | */ |
841 | static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len) | 890 | static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len) |
842 | { | 891 | { |
843 | unsigned char *tmp = skb->tail; | 892 | unsigned char *tmp = skb_tail_pointer(skb); |
844 | SKB_LINEAR_ASSERT(skb); | 893 | SKB_LINEAR_ASSERT(skb); |
845 | skb->tail += len; | 894 | skb->tail += len; |
846 | skb->len += len; | 895 | skb->len += len; |
847 | if (unlikely(skb->tail>skb->end)) | 896 | if (unlikely(skb->tail > skb->end)) |
848 | skb_over_panic(skb, len, current_text_addr()); | 897 | skb_over_panic(skb, len, current_text_addr()); |
849 | return tmp; | 898 | return tmp; |
850 | } | 899 | } |
@@ -957,6 +1006,130 @@ static inline void skb_reserve(struct sk_buff *skb, int len) | |||
957 | skb->tail += len; | 1006 | skb->tail += len; |
958 | } | 1007 | } |
959 | 1008 | ||
1009 | #ifdef NET_SKBUFF_DATA_USES_OFFSET | ||
1010 | static inline unsigned char *skb_transport_header(const struct sk_buff *skb) | ||
1011 | { | ||
1012 | return skb->head + skb->transport_header; | ||
1013 | } | ||
1014 | |||
1015 | static inline void skb_reset_transport_header(struct sk_buff *skb) | ||
1016 | { | ||
1017 | skb->transport_header = skb->data - skb->head; | ||
1018 | } | ||
1019 | |||
1020 | static inline void skb_set_transport_header(struct sk_buff *skb, | ||
1021 | const int offset) | ||
1022 | { | ||
1023 | skb_reset_transport_header(skb); | ||
1024 | skb->transport_header += offset; | ||
1025 | } | ||
1026 | |||
1027 | static inline unsigned char *skb_network_header(const struct sk_buff *skb) | ||
1028 | { | ||
1029 | return skb->head + skb->network_header; | ||
1030 | } | ||
1031 | |||
1032 | static inline void skb_reset_network_header(struct sk_buff *skb) | ||
1033 | { | ||
1034 | skb->network_header = skb->data - skb->head; | ||
1035 | } | ||
1036 | |||
1037 | static inline void skb_set_network_header(struct sk_buff *skb, const int offset) | ||
1038 | { | ||
1039 | skb_reset_network_header(skb); | ||
1040 | skb->network_header += offset; | ||
1041 | } | ||
1042 | |||
1043 | static inline unsigned char *skb_mac_header(const struct sk_buff *skb) | ||
1044 | { | ||
1045 | return skb->head + skb->mac_header; | ||
1046 | } | ||
1047 | |||
1048 | static inline int skb_mac_header_was_set(const struct sk_buff *skb) | ||
1049 | { | ||
1050 | return skb->mac_header != ~0U; | ||
1051 | } | ||
1052 | |||
1053 | static inline void skb_reset_mac_header(struct sk_buff *skb) | ||
1054 | { | ||
1055 | skb->mac_header = skb->data - skb->head; | ||
1056 | } | ||
1057 | |||
1058 | static inline void skb_set_mac_header(struct sk_buff *skb, const int offset) | ||
1059 | { | ||
1060 | skb_reset_mac_header(skb); | ||
1061 | skb->mac_header += offset; | ||
1062 | } | ||
1063 | |||
1064 | #else /* NET_SKBUFF_DATA_USES_OFFSET */ | ||
1065 | |||
1066 | static inline unsigned char *skb_transport_header(const struct sk_buff *skb) | ||
1067 | { | ||
1068 | return skb->transport_header; | ||
1069 | } | ||
1070 | |||
1071 | static inline void skb_reset_transport_header(struct sk_buff *skb) | ||
1072 | { | ||
1073 | skb->transport_header = skb->data; | ||
1074 | } | ||
1075 | |||
1076 | static inline void skb_set_transport_header(struct sk_buff *skb, | ||
1077 | const int offset) | ||
1078 | { | ||
1079 | skb->transport_header = skb->data + offset; | ||
1080 | } | ||
1081 | |||
1082 | static inline unsigned char *skb_network_header(const struct sk_buff *skb) | ||
1083 | { | ||
1084 | return skb->network_header; | ||
1085 | } | ||
1086 | |||
1087 | static inline void skb_reset_network_header(struct sk_buff *skb) | ||
1088 | { | ||
1089 | skb->network_header = skb->data; | ||
1090 | } | ||
1091 | |||
1092 | static inline void skb_set_network_header(struct sk_buff *skb, const int offset) | ||
1093 | { | ||
1094 | skb->network_header = skb->data + offset; | ||
1095 | } | ||
1096 | |||
1097 | static inline unsigned char *skb_mac_header(const struct sk_buff *skb) | ||
1098 | { | ||
1099 | return skb->mac_header; | ||
1100 | } | ||
1101 | |||
1102 | static inline int skb_mac_header_was_set(const struct sk_buff *skb) | ||
1103 | { | ||
1104 | return skb->mac_header != NULL; | ||
1105 | } | ||
1106 | |||
1107 | static inline void skb_reset_mac_header(struct sk_buff *skb) | ||
1108 | { | ||
1109 | skb->mac_header = skb->data; | ||
1110 | } | ||
1111 | |||
1112 | static inline void skb_set_mac_header(struct sk_buff *skb, const int offset) | ||
1113 | { | ||
1114 | skb->mac_header = skb->data + offset; | ||
1115 | } | ||
1116 | #endif /* NET_SKBUFF_DATA_USES_OFFSET */ | ||
1117 | |||
1118 | static inline int skb_transport_offset(const struct sk_buff *skb) | ||
1119 | { | ||
1120 | return skb_transport_header(skb) - skb->data; | ||
1121 | } | ||
1122 | |||
1123 | static inline u32 skb_network_header_len(const struct sk_buff *skb) | ||
1124 | { | ||
1125 | return skb->transport_header - skb->network_header; | ||
1126 | } | ||
1127 | |||
1128 | static inline int skb_network_offset(const struct sk_buff *skb) | ||
1129 | { | ||
1130 | return skb_network_header(skb) - skb->data; | ||
1131 | } | ||
1132 | |||
960 | /* | 1133 | /* |
961 | * CPUs often take a performance hit when accessing unaligned memory | 1134 | * CPUs often take a performance hit when accessing unaligned memory |
962 | * locations. The actual performance hit varies, it can be small if the | 1135 | * locations. The actual performance hit varies, it can be small if the |
@@ -1008,8 +1181,8 @@ static inline void __skb_trim(struct sk_buff *skb, unsigned int len) | |||
1008 | WARN_ON(1); | 1181 | WARN_ON(1); |
1009 | return; | 1182 | return; |
1010 | } | 1183 | } |
1011 | skb->len = len; | 1184 | skb->len = len; |
1012 | skb->tail = skb->data + len; | 1185 | skb_set_tail_pointer(skb, len); |
1013 | } | 1186 | } |
1014 | 1187 | ||
1015 | /** | 1188 | /** |
@@ -1298,6 +1471,11 @@ static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len) | |||
1298 | prefetch(skb->next), (skb != (struct sk_buff *)(queue)); \ | 1471 | prefetch(skb->next), (skb != (struct sk_buff *)(queue)); \ |
1299 | skb = skb->next) | 1472 | skb = skb->next) |
1300 | 1473 | ||
1474 | #define skb_queue_walk_safe(queue, skb, tmp) \ | ||
1475 | for (skb = (queue)->next, tmp = skb->next; \ | ||
1476 | skb != (struct sk_buff *)(queue); \ | ||
1477 | skb = tmp, tmp = skb->next) | ||
1478 | |||
1301 | #define skb_queue_reverse_walk(queue, skb) \ | 1479 | #define skb_queue_reverse_walk(queue, skb) \ |
1302 | for (skb = (queue)->prev; \ | 1480 | for (skb = (queue)->prev; \ |
1303 | prefetch(skb->prev), (skb != (struct sk_buff *)(queue)); \ | 1481 | prefetch(skb->prev), (skb != (struct sk_buff *)(queue)); \ |
@@ -1321,8 +1499,8 @@ extern __wsum skb_checksum(const struct sk_buff *skb, int offset, | |||
1321 | int len, __wsum csum); | 1499 | int len, __wsum csum); |
1322 | extern int skb_copy_bits(const struct sk_buff *skb, int offset, | 1500 | extern int skb_copy_bits(const struct sk_buff *skb, int offset, |
1323 | void *to, int len); | 1501 | void *to, int len); |
1324 | extern int skb_store_bits(const struct sk_buff *skb, int offset, | 1502 | extern int skb_store_bits(struct sk_buff *skb, int offset, |
1325 | void *from, int len); | 1503 | const void *from, int len); |
1326 | extern __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, | 1504 | extern __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, |
1327 | int offset, u8 *to, int len, | 1505 | int offset, u8 *to, int len, |
1328 | __wsum csum); | 1506 | __wsum csum); |
@@ -1346,8 +1524,36 @@ static inline void *skb_header_pointer(const struct sk_buff *skb, int offset, | |||
1346 | return buffer; | 1524 | return buffer; |
1347 | } | 1525 | } |
1348 | 1526 | ||
1527 | static inline void skb_copy_from_linear_data(const struct sk_buff *skb, | ||
1528 | void *to, | ||
1529 | const unsigned int len) | ||
1530 | { | ||
1531 | memcpy(to, skb->data, len); | ||
1532 | } | ||
1533 | |||
1534 | static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb, | ||
1535 | const int offset, void *to, | ||
1536 | const unsigned int len) | ||
1537 | { | ||
1538 | memcpy(to, skb->data + offset, len); | ||
1539 | } | ||
1540 | |||
1541 | static inline void skb_copy_to_linear_data(struct sk_buff *skb, | ||
1542 | const void *from, | ||
1543 | const unsigned int len) | ||
1544 | { | ||
1545 | memcpy(skb->data, from, len); | ||
1546 | } | ||
1547 | |||
1548 | static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb, | ||
1549 | const int offset, | ||
1550 | const void *from, | ||
1551 | const unsigned int len) | ||
1552 | { | ||
1553 | memcpy(skb->data + offset, from, len); | ||
1554 | } | ||
1555 | |||
1349 | extern void skb_init(void); | 1556 | extern void skb_init(void); |
1350 | extern void skb_add_mtu(int mtu); | ||
1351 | 1557 | ||
1352 | /** | 1558 | /** |
1353 | * skb_get_timestamp - get timestamp from a skb | 1559 | * skb_get_timestamp - get timestamp from a skb |
@@ -1360,29 +1566,28 @@ extern void skb_add_mtu(int mtu); | |||
1360 | */ | 1566 | */ |
1361 | static inline void skb_get_timestamp(const struct sk_buff *skb, struct timeval *stamp) | 1567 | static inline void skb_get_timestamp(const struct sk_buff *skb, struct timeval *stamp) |
1362 | { | 1568 | { |
1363 | stamp->tv_sec = skb->tstamp.off_sec; | 1569 | *stamp = ktime_to_timeval(skb->tstamp); |
1364 | stamp->tv_usec = skb->tstamp.off_usec; | ||
1365 | } | 1570 | } |
1366 | 1571 | ||
1367 | /** | 1572 | static inline void __net_timestamp(struct sk_buff *skb) |
1368 | * skb_set_timestamp - set timestamp of a skb | 1573 | { |
1369 | * @skb: skb to set stamp of | 1574 | skb->tstamp = ktime_get_real(); |
1370 | * @stamp: pointer to struct timeval to get stamp from | 1575 | } |
1371 | * | 1576 | |
1372 | * Timestamps are stored in the skb as offsets to a base timestamp. | 1577 | static inline ktime_t net_timedelta(ktime_t t) |
1373 | * This function converts a struct timeval to an offset and stores | ||
1374 | * it in the skb. | ||
1375 | */ | ||
1376 | static inline void skb_set_timestamp(struct sk_buff *skb, const struct timeval *stamp) | ||
1377 | { | 1578 | { |
1378 | skb->tstamp.off_sec = stamp->tv_sec; | 1579 | return ktime_sub(ktime_get_real(), t); |
1379 | skb->tstamp.off_usec = stamp->tv_usec; | ||
1380 | } | 1580 | } |
1381 | 1581 | ||
1382 | extern void __net_timestamp(struct sk_buff *skb); | ||
1383 | 1582 | ||
1583 | extern __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len); | ||
1384 | extern __sum16 __skb_checksum_complete(struct sk_buff *skb); | 1584 | extern __sum16 __skb_checksum_complete(struct sk_buff *skb); |
1385 | 1585 | ||
1586 | static inline int skb_csum_unnecessary(const struct sk_buff *skb) | ||
1587 | { | ||
1588 | return skb->ip_summed & CHECKSUM_UNNECESSARY; | ||
1589 | } | ||
1590 | |||
1386 | /** | 1591 | /** |
1387 | * skb_checksum_complete - Calculate checksum of an entire packet | 1592 | * skb_checksum_complete - Calculate checksum of an entire packet |
1388 | * @skb: packet to process | 1593 | * @skb: packet to process |
@@ -1401,22 +1606,22 @@ extern __sum16 __skb_checksum_complete(struct sk_buff *skb); | |||
1401 | */ | 1606 | */ |
1402 | static inline unsigned int skb_checksum_complete(struct sk_buff *skb) | 1607 | static inline unsigned int skb_checksum_complete(struct sk_buff *skb) |
1403 | { | 1608 | { |
1404 | return skb->ip_summed != CHECKSUM_UNNECESSARY && | 1609 | return skb_csum_unnecessary(skb) ? |
1405 | __skb_checksum_complete(skb); | 1610 | 0 : __skb_checksum_complete(skb); |
1406 | } | 1611 | } |
1407 | 1612 | ||
1408 | #ifdef CONFIG_NETFILTER | 1613 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
1614 | extern void nf_conntrack_destroy(struct nf_conntrack *nfct); | ||
1409 | static inline void nf_conntrack_put(struct nf_conntrack *nfct) | 1615 | static inline void nf_conntrack_put(struct nf_conntrack *nfct) |
1410 | { | 1616 | { |
1411 | if (nfct && atomic_dec_and_test(&nfct->use)) | 1617 | if (nfct && atomic_dec_and_test(&nfct->use)) |
1412 | nfct->destroy(nfct); | 1618 | nf_conntrack_destroy(nfct); |
1413 | } | 1619 | } |
1414 | static inline void nf_conntrack_get(struct nf_conntrack *nfct) | 1620 | static inline void nf_conntrack_get(struct nf_conntrack *nfct) |
1415 | { | 1621 | { |
1416 | if (nfct) | 1622 | if (nfct) |
1417 | atomic_inc(&nfct->use); | 1623 | atomic_inc(&nfct->use); |
1418 | } | 1624 | } |
1419 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | ||
1420 | static inline void nf_conntrack_get_reasm(struct sk_buff *skb) | 1625 | static inline void nf_conntrack_get_reasm(struct sk_buff *skb) |
1421 | { | 1626 | { |
1422 | if (skb) | 1627 | if (skb) |
@@ -1442,9 +1647,9 @@ static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge) | |||
1442 | #endif /* CONFIG_BRIDGE_NETFILTER */ | 1647 | #endif /* CONFIG_BRIDGE_NETFILTER */ |
1443 | static inline void nf_reset(struct sk_buff *skb) | 1648 | static inline void nf_reset(struct sk_buff *skb) |
1444 | { | 1649 | { |
1650 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | ||
1445 | nf_conntrack_put(skb->nfct); | 1651 | nf_conntrack_put(skb->nfct); |
1446 | skb->nfct = NULL; | 1652 | skb->nfct = NULL; |
1447 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | ||
1448 | nf_conntrack_put_reasm(skb->nfct_reasm); | 1653 | nf_conntrack_put_reasm(skb->nfct_reasm); |
1449 | skb->nfct_reasm = NULL; | 1654 | skb->nfct_reasm = NULL; |
1450 | #endif | 1655 | #endif |
@@ -1454,9 +1659,33 @@ static inline void nf_reset(struct sk_buff *skb) | |||
1454 | #endif | 1659 | #endif |
1455 | } | 1660 | } |
1456 | 1661 | ||
1457 | #else /* CONFIG_NETFILTER */ | 1662 | /* Note: This doesn't put any conntrack and bridge info in dst. */ |
1458 | static inline void nf_reset(struct sk_buff *skb) {} | 1663 | static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src) |
1459 | #endif /* CONFIG_NETFILTER */ | 1664 | { |
1665 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | ||
1666 | dst->nfct = src->nfct; | ||
1667 | nf_conntrack_get(src->nfct); | ||
1668 | dst->nfctinfo = src->nfctinfo; | ||
1669 | dst->nfct_reasm = src->nfct_reasm; | ||
1670 | nf_conntrack_get_reasm(src->nfct_reasm); | ||
1671 | #endif | ||
1672 | #ifdef CONFIG_BRIDGE_NETFILTER | ||
1673 | dst->nf_bridge = src->nf_bridge; | ||
1674 | nf_bridge_get(src->nf_bridge); | ||
1675 | #endif | ||
1676 | } | ||
1677 | |||
1678 | static inline void nf_copy(struct sk_buff *dst, const struct sk_buff *src) | ||
1679 | { | ||
1680 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | ||
1681 | nf_conntrack_put(dst->nfct); | ||
1682 | nf_conntrack_put_reasm(dst->nfct_reasm); | ||
1683 | #endif | ||
1684 | #ifdef CONFIG_BRIDGE_NETFILTER | ||
1685 | nf_bridge_put(dst->nf_bridge); | ||
1686 | #endif | ||
1687 | __nf_copy(dst, src); | ||
1688 | } | ||
1460 | 1689 | ||
1461 | #ifdef CONFIG_NETWORK_SECMARK | 1690 | #ifdef CONFIG_NETWORK_SECMARK |
1462 | static inline void skb_copy_secmark(struct sk_buff *to, const struct sk_buff *from) | 1691 | static inline void skb_copy_secmark(struct sk_buff *to, const struct sk_buff *from) |
@@ -1481,5 +1710,12 @@ static inline int skb_is_gso(const struct sk_buff *skb) | |||
1481 | return skb_shinfo(skb)->gso_size; | 1710 | return skb_shinfo(skb)->gso_size; |
1482 | } | 1711 | } |
1483 | 1712 | ||
1713 | static inline void skb_forward_csum(struct sk_buff *skb) | ||
1714 | { | ||
1715 | /* Unfortunately we don't support this one. Any brave souls? */ | ||
1716 | if (skb->ip_summed == CHECKSUM_COMPLETE) | ||
1717 | skb->ip_summed = CHECKSUM_NONE; | ||
1718 | } | ||
1719 | |||
1484 | #endif /* __KERNEL__ */ | 1720 | #endif /* __KERNEL__ */ |
1485 | #endif /* _LINUX_SKBUFF_H */ | 1721 | #endif /* _LINUX_SKBUFF_H */ |