]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/skbuff.h
[SPLICE]: Don't assume regular pages in splice_to_pipe()
[net-next-2.6.git] / include / linux / skbuff.h
CommitLineData
1da177e4
LT
1/*
2 * Definitions for the 'struct sk_buff' memory handlers.
3 *
4 * Authors:
5 * Alan Cox, <gw4pts@gw4pts.ampr.org>
6 * Florian La Roche, <rzsfl@rz.uni-sb.de>
7 *
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.
12 */
13
14#ifndef _LINUX_SKBUFF_H
15#define _LINUX_SKBUFF_H
16
1da177e4
LT
17#include <linux/kernel.h>
18#include <linux/compiler.h>
19#include <linux/time.h>
20#include <linux/cache.h>
21
22#include <asm/atomic.h>
23#include <asm/types.h>
24#include <linux/spinlock.h>
1da177e4 25#include <linux/net.h>
3fc7e8a6 26#include <linux/textsearch.h>
1da177e4 27#include <net/checksum.h>
a80958f4 28#include <linux/rcupdate.h>
97fc2f08 29#include <linux/dmaengine.h>
b7aa0bf7 30#include <linux/hrtimer.h>
1da177e4
LT
31
32#define HAVE_ALLOC_SKB /* For the drivers to know */
33#define HAVE_ALIGNABLE_SKB /* Ditto 8) */
1da177e4 34
60476372 35/* Don't change this without changing skb_csum_unnecessary! */
1da177e4 36#define CHECKSUM_NONE 0
60476372
HX
37#define CHECKSUM_UNNECESSARY 1
38#define CHECKSUM_COMPLETE 2
39#define CHECKSUM_PARTIAL 3
1da177e4
LT
40
41#define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \
42 ~(SMP_CACHE_BYTES - 1))
fc910a27 43#define SKB_WITH_OVERHEAD(X) \
deea84b0 44 ((X) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
fc910a27
DM
45#define SKB_MAX_ORDER(X, ORDER) \
46 SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X))
1da177e4
LT
47#define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0))
48#define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2))
49
50/* A. Checksumming of received packets by device.
51 *
52 * NONE: device failed to checksum this packet.
53 * skb->csum is undefined.
54 *
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)
60 *
84fa7933 61 * COMPLETE: the most generic way. Device supplied checksum of _all_
1da177e4
LT
62 * the packet as seen by netif_rx in skb->csum.
63 * NOTE: Even if device supports only some protocols, but
84fa7933 64 * is able to produce some skb->csum, it MUST use COMPLETE,
1da177e4
LT
65 * not UNNECESSARY.
66 *
c6c6e3e0
HX
67 * PARTIAL: identical to the case for output below. This may occur
68 * on a packet received directly from another Linux OS, e.g.,
69 * a virtualised Linux kernel on the same host. The packet can
70 * be treated in the same way as UNNECESSARY except that on
71 * output (i.e., forwarding) the checksum must be filled in
72 * by the OS or the hardware.
73 *
1da177e4
LT
74 * B. Checksumming on output.
75 *
76 * NONE: skb is checksummed by protocol or csum is not required.
77 *
84fa7933 78 * PARTIAL: device is required to csum packet as seen by hard_start_xmit
c6c6e3e0
HX
79 * from skb->csum_start to the end and to record the checksum
80 * at skb->csum_start + skb->csum_offset.
1da177e4
LT
81 *
82 * Device must show its capabilities in dev->features, set
83 * at device setup time.
84 * NETIF_F_HW_CSUM - it is clever device, it is able to checksum
85 * everything.
86 * NETIF_F_NO_CSUM - loopback or reliable single hop media.
87 * NETIF_F_IP_CSUM - device is dumb. It is able to csum only
88 * TCP/UDP over IPv4. Sigh. Vendors like this
89 * way by an unknown reason. Though, see comment above
90 * about CHECKSUM_UNNECESSARY. 8)
c6c6e3e0 91 * NETIF_F_IPV6_CSUM about as dumb as the last one but does IPv6 instead.
1da177e4
LT
92 *
93 * Any questions? No questions, good. --ANK
94 */
95
1da177e4 96struct net_device;
716ea3a7 97struct scatterlist;
1da177e4 98
5f79e0f9 99#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1da177e4
LT
100struct nf_conntrack {
101 atomic_t use;
1da177e4 102};
5f79e0f9 103#endif
1da177e4
LT
104
105#ifdef CONFIG_BRIDGE_NETFILTER
106struct nf_bridge_info {
107 atomic_t use;
108 struct net_device *physindev;
109 struct net_device *physoutdev;
110#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
111 struct net_device *netoutdev;
112#endif
113 unsigned int mask;
114 unsigned long data[32 / sizeof(unsigned long)];
115};
116#endif
117
1da177e4
LT
118struct sk_buff_head {
119 /* These two members must be first. */
120 struct sk_buff *next;
121 struct sk_buff *prev;
122
123 __u32 qlen;
124 spinlock_t lock;
125};
126
127struct sk_buff;
128
129/* To allow 64K frame to be packed as single skb without frag_list */
130#define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2)
131
132typedef struct skb_frag_struct skb_frag_t;
133
134struct skb_frag_struct {
135 struct page *page;
a309bb07
DM
136 __u32 page_offset;
137 __u32 size;
1da177e4
LT
138};
139
140/* This data is invariant across clones and lives at
141 * the end of the header data, ie. at skb->end.
142 */
143struct skb_shared_info {
144 atomic_t dataref;
4947d3ef 145 unsigned short nr_frags;
7967168c
HX
146 unsigned short gso_size;
147 /* Warning: this field is not always filled in (UFO)! */
148 unsigned short gso_segs;
149 unsigned short gso_type;
ae08e1f0 150 __be32 ip6_frag_id;
1da177e4
LT
151 struct sk_buff *frag_list;
152 skb_frag_t frags[MAX_SKB_FRAGS];
153};
154
155/* We divide dataref into two halves. The higher 16 bits hold references
156 * to the payload part of skb->data. The lower 16 bits hold references to
334a8132
PM
157 * the entire skb->data. A clone of a headerless skb holds the length of
158 * the header in skb->hdr_len.
1da177e4
LT
159 *
160 * All users must obey the rule that the skb->data reference count must be
161 * greater than or equal to the payload reference count.
162 *
163 * Holding a reference to the payload part means that the user does not
164 * care about modifications to the header part of skb->data.
165 */
166#define SKB_DATAREF_SHIFT 16
167#define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1)
168
d179cd12
DM
169
170enum {
171 SKB_FCLONE_UNAVAILABLE,
172 SKB_FCLONE_ORIG,
173 SKB_FCLONE_CLONE,
174};
175
7967168c
HX
176enum {
177 SKB_GSO_TCPV4 = 1 << 0,
f83ef8c0 178 SKB_GSO_UDP = 1 << 1,
576a30eb
HX
179
180 /* This indicates the skb is from an untrusted source. */
181 SKB_GSO_DODGY = 1 << 2,
b0da8537
MC
182
183 /* This indicates the tcp segment has CWR set. */
f83ef8c0
HX
184 SKB_GSO_TCP_ECN = 1 << 3,
185
186 SKB_GSO_TCPV6 = 1 << 4,
7967168c
HX
187};
188
2e07fa9c
ACM
189#if BITS_PER_LONG > 32
190#define NET_SKBUFF_DATA_USES_OFFSET 1
191#endif
192
193#ifdef NET_SKBUFF_DATA_USES_OFFSET
194typedef unsigned int sk_buff_data_t;
195#else
196typedef unsigned char *sk_buff_data_t;
197#endif
198
1da177e4
LT
199/**
200 * struct sk_buff - socket buffer
201 * @next: Next buffer in list
202 * @prev: Previous buffer in list
1da177e4 203 * @sk: Socket we are owned by
325ed823 204 * @tstamp: Time we arrived
1da177e4 205 * @dev: Device we arrived on/are leaving by
be52178b 206 * @transport_header: Transport layer header
b0e380b1
ACM
207 * @network_header: Network layer header
208 * @mac_header: Link layer header
67be2dd1
MW
209 * @dst: destination entry
210 * @sp: the security path, used for xfrm
1da177e4
LT
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
334a8132 215 * @hdr_len: writable header length of cloned skb
663ead3b
HX
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
67be2dd1 219 * @local_df: allow local fragmentation
1da177e4
LT
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
c83c2486 223 * @fclone: skbuff clone status
1da177e4
LT
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
1da177e4
LT
228 * @truesize: Buffer size
229 * @head: Head of buffer
230 * @data: Data head pointer
231 * @tail: Tail pointer
232 * @end: End pointer
233 * @destructor: Destruct function
82e91ffe 234 * @mark: Generic packet mark
1da177e4 235 * @nfct: Associated connection, if any
c83c2486 236 * @ipvs_property: skbuff is owned by ipvs
ba9dda3a 237 * @nf_trace: netfilter packet trace flag
1da177e4 238 * @nfctinfo: Relationship of this skb to the connection
461ddf3b 239 * @nfct_reasm: netfilter conntrack re-assembly pointer
1da177e4 240 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
f25f4e44
PWJ
241 * @iif: ifindex of device we arrived on
242 * @queue_mapping: Queue mapping for multiqueue devices
1da177e4
LT
243 * @tc_index: Traffic control index
244 * @tc_verd: traffic control verdict
f4b8ea78
RD
245 * @dma_cookie: a cookie to one of several possible DMA operations
246 * done by skb DMA functions
984bc16c 247 * @secmark: security marking
1da177e4
LT
248 */
249
250struct sk_buff {
251 /* These two members must be first. */
252 struct sk_buff *next;
253 struct sk_buff *prev;
254
1da177e4 255 struct sock *sk;
b7aa0bf7 256 ktime_t tstamp;
1da177e4 257 struct net_device *dev;
1da177e4 258
1da177e4
LT
259 struct dst_entry *dst;
260 struct sec_path *sp;
261
262 /*
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.
267 */
3e3850e9 268 char cb[48];
1da177e4
LT
269
270 unsigned int len,
334a8132
PM
271 data_len;
272 __u16 mac_len,
273 hdr_len;
ff1dcadb
AV
274 union {
275 __wsum csum;
663ead3b
HX
276 struct {
277 __u16 csum_start;
278 __u16 csum_offset;
279 };
ff1dcadb 280 };
1da177e4 281 __u32 priority;
1cbb3380
TG
282 __u8 local_df:1,
283 cloned:1,
284 ip_summed:2,
6869c4d8
HW
285 nohdr:1,
286 nfctinfo:3;
d179cd12 287 __u8 pkt_type:3,
b84f4cc9 288 fclone:2,
ba9dda3a
JK
289 ipvs_property:1,
290 nf_trace:1;
a0d3bea3 291 __be16 protocol;
1da177e4
LT
292
293 void (*destructor)(struct sk_buff *skb);
9fb9cbb1 294#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
5f79e0f9 295 struct nf_conntrack *nfct;
9fb9cbb1
YK
296 struct sk_buff *nfct_reasm;
297#endif
1da177e4
LT
298#ifdef CONFIG_BRIDGE_NETFILTER
299 struct nf_bridge_info *nf_bridge;
300#endif
f25f4e44
PWJ
301
302 int iif;
e3fa259b 303#ifdef CONFIG_NETDEVICES_MULTIQUEUE
f25f4e44 304 __u16 queue_mapping;
e3fa259b 305#endif
1da177e4 306#ifdef CONFIG_NET_SCHED
b6b99eb5 307 __u16 tc_index; /* traffic control index */
1da177e4 308#ifdef CONFIG_NET_CLS_ACT
b6b99eb5 309 __u16 tc_verd; /* traffic control verdict */
1da177e4 310#endif
1da177e4 311#endif
f25f4e44
PWJ
312 /* 2 byte hole */
313
97fc2f08
CL
314#ifdef CONFIG_NET_DMA
315 dma_cookie_t dma_cookie;
316#endif
984bc16c
JM
317#ifdef CONFIG_NETWORK_SECMARK
318 __u32 secmark;
319#endif
1da177e4 320
82e91ffe 321 __u32 mark;
1da177e4 322
27a884dc
ACM
323 sk_buff_data_t transport_header;
324 sk_buff_data_t network_header;
325 sk_buff_data_t mac_header;
1da177e4 326 /* These elements must be at the end, see alloc_skb() for details. */
27a884dc 327 sk_buff_data_t tail;
4305b541 328 sk_buff_data_t end;
1da177e4 329 unsigned char *head,
4305b541 330 *data;
27a884dc
ACM
331 unsigned int truesize;
332 atomic_t users;
1da177e4
LT
333};
334
335#ifdef __KERNEL__
336/*
337 * Handling routines are only of interest to the kernel
338 */
339#include <linux/slab.h>
340
341#include <asm/system.h>
342