]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/skbuff.h
[AF_UNIX]: Make code static.
[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
DM
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))
1da177e4
LT
48#define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0))
49#define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2))
50
51/* A. Checksumming of received packets by device.
52 *
53 * NONE: device failed to checksum this packet.
54 * skb->csum is undefined.
55 *
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)
61 *
84fa7933 62 * COMPLETE: the most generic way. Device supplied checksum of _all_
1da177e4
LT
63 * the packet as seen by netif_rx in skb->csum.
64 * NOTE: Even if device supports only some protocols, but
84fa7933 65 * is able to produce some skb->csum, it MUST use COMPLETE,
1da177e4
LT
66 * not UNNECESSARY.
67 *
c6c6e3e0
HX
68 * PARTIAL: identical to the case for output below. This may occur
69 * on a packet received directly from another Linux OS, e.g.,
70 * a virtualised Linux kernel on the same host. The packet can
71 * be treated in the same way as UNNECESSARY except that on
72 * output (i.e., forwarding) the checksum must be filled in
73 * by the OS or the hardware.
74 *
1da177e4
LT
75 * B. Checksumming on output.
76 *
77 * NONE: skb is checksummed by protocol or csum is not required.
78 *
84fa7933 79 * PARTIAL: device is required to csum packet as seen by hard_start_xmit
c6c6e3e0
HX
80 * from skb->csum_start to the end and to record the checksum
81 * at skb->csum_start + skb->csum_offset.
1da177e4
LT
82 *
83 * Device must show its capabilities in dev->features, set
84 * at device setup time.
85 * NETIF_F_HW_CSUM - it is clever device, it is able to checksum
86 * everything.
87 * NETIF_F_NO_CSUM - loopback or reliable single hop media.
88 * NETIF_F_IP_CSUM - device is dumb. It is able to csum only
89 * TCP/UDP over IPv4. Sigh. Vendors like this
90 * way by an unknown reason. Though, see comment above
91 * about CHECKSUM_UNNECESSARY. 8)
c6c6e3e0 92 * NETIF_F_IPV6_CSUM about as dumb as the last one but does IPv6 instead.
1da177e4
LT
93 *
94 * Any questions? No questions, good. --ANK
95 */
96
1da177e4 97struct net_device;
716ea3a7 98struct scatterlist;
1da177e4 99
5f79e0f9 100#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1da177e4
LT
101struct nf_conntrack {
102 atomic_t use;
1da177e4 103};
5f79e0f9 104#endif
1da177e4
LT
105
106#ifdef CONFIG_BRIDGE_NETFILTER
107struct nf_bridge_info {
108 atomic_t use;
109 struct net_device *physindev;
110 struct net_device *physoutdev;
111#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
112 struct net_device *netoutdev;
113#endif
114 unsigned int mask;
115 unsigned long data[32 / sizeof(unsigned long)];
116};
117#endif
118
1da177e4
LT
119struct sk_buff_head {
120 /* These two members must be first. */
121 struct sk_buff *next;
122 struct sk_buff *prev;
123
124 __u32 qlen;
125 spinlock_t lock;
126};
127
128struct sk_buff;
129
130/* To allow 64K frame to be packed as single skb without frag_list */
131#define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2)
132
133typedef struct skb_frag_struct skb_frag_t;
134
135struct skb_frag_struct {
136 struct page *page;
137 __u16 page_offset;
138 __u16 size;
139};
140
141/* This data is invariant across clones and lives at
142 * the end of the header data, ie. at skb->end.
143 */
144struct skb_shared_info {
145 atomic_t dataref;
4947d3ef 146 unsigned short nr_frags;
7967168c
HX
147 unsigned short gso_size;
148 /* Warning: this field is not always filled in (UFO)! */
149 unsigned short gso_segs;
150 unsigned short gso_type;
ae08e1f0 151 __be32 ip6_frag_id;
1da177e4
LT
152 struct sk_buff *frag_list;
153 skb_frag_t frags[MAX_SKB_FRAGS];
154};
155
156/* We divide dataref into two halves. The higher 16 bits hold references
157 * to the payload part of skb->data. The lower 16 bits hold references to
334a8132
PM
158 * the entire skb->data. A clone of a headerless skb holds the length of
159 * the header in skb->hdr_len.
1da177e4
LT
160 *
161 * All users must obey the rule that the skb->data reference count must be
162 * greater than or equal to the payload reference count.
163 *
164 * Holding a reference to the payload part means that the user does not
165 * care about modifications to the header part of skb->data.
166 */
167#define SKB_DATAREF_SHIFT 16
168#define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1)
169
d179cd12
DM
170
171enum {
172 SKB_FCLONE_UNAVAILABLE,
173 SKB_FCLONE_ORIG,
174 SKB_FCLONE_CLONE,
175};
176
7967168c
HX
177enum {
178 SKB_GSO_TCPV4 = 1 << 0,
f83ef8c0 179 SKB_GSO_UDP = 1 << 1,
576a30eb
HX
180
181 /* This indicates the skb is from an untrusted source. */
182 SKB_GSO_DODGY = 1 << 2,
b0da8537
MC
183
184 /* This indicates the tcp segment has CWR set. */
f83ef8c0
HX
185 SKB_GSO_TCP_ECN = 1 << 3,
186
187 SKB_GSO_TCPV6 = 1 << 4,
7967168c
HX
188};
189
2e07fa9c
ACM
190#if BITS_PER_LONG > 32
191#define NET_SKBUFF_DATA_USES_OFFSET 1
192#endif
193
194#ifdef NET_SKBUFF_DATA_USES_OFFSET
195typedef unsigned int sk_buff_data_t;
196#else
197typedef unsigned char *sk_buff_data_t;
198#endif
199
1da177e4
LT
200/**
201 * struct sk_buff - socket buffer
202 * @next: Next buffer in list
203 * @prev: Previous buffer in list
1da177e4 204 * @sk: Socket we are owned by
325ed823 205 * @tstamp: Time we arrived
1da177e4 206 * @dev: Device we arrived on/are leaving by
be52178b 207 * @transport_header: Transport layer header
b0e380b1
ACM
208 * @network_header: Network layer header
209 * @mac_header: Link layer header
67be2dd1
MW
210 * @dst: destination entry
211 * @sp: the security path, used for xfrm
1da177e4
LT
212 * @cb: Control buffer. Free for use by every layer. Put private vars here
213 * @len: Length of actual data
214 * @data_len: Data length
215 * @mac_len: Length of link layer header
334a8132 216 * @hdr_len: writable header length of cloned skb
663ead3b
HX
217 * @csum: Checksum (must include start/offset pair)
218 * @csum_start: Offset from skb->head where checksumming should start
219 * @csum_offset: Offset from csum_start where checksum should be stored
67be2dd1 220 * @local_df: allow local fragmentation
1da177e4
LT
221 * @cloned: Head may be cloned (check refcnt to be sure)
222 * @nohdr: Payload reference only, must not modify header
223 * @pkt_type: Packet class
c83c2486 224 * @fclone: skbuff clone status
1da177e4
LT
225 * @ip_summed: Driver fed us an IP checksum
226 * @priority: Packet queueing priority
227 * @users: User count - see {datagram,tcp}.c
228 * @protocol: Packet protocol from driver
1da177e4
LT
229 * @truesize: Buffer size
230 * @head: Head of buffer
231 * @data: Data head pointer
232 * @tail: Tail pointer
233 * @end: End pointer
234 * @destructor: Destruct function
82e91ffe 235 * @mark: Generic packet mark
1da177e4 236 * @nfct: Associated connection, if any
c83c2486 237 * @ipvs_property: skbuff is owned by ipvs
ba9dda3a 238 * @nf_trace: netfilter packet trace flag
1da177e4 239 * @nfctinfo: Relationship of this skb to the connection
461ddf3b 240 * @nfct_reasm: netfilter conntrack re-assembly pointer
1da177e4 241 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
f25f4e44
PWJ
242 * @iif: ifindex of device we arrived on
243 * @queue_mapping: Queue mapping for multiqueue devices
1da177e4
LT
244 * @tc_index: Traffic control index
245 * @tc_verd: traffic control verdict
f4b8ea78
RD
246 * @dma_cookie: a cookie to one of several possible DMA operations
247 * done by skb DMA functions
984bc16c 248 * @secmark: security marking
1da177e4
LT
249 */
250
251struct sk_buff {
252 /* These two members must be first. */
253 struct sk_buff *next;
254 struct sk_buff *prev;
255
1da177e4 256 struct sock *sk;
b7aa0bf7 257 ktime_t tstamp;
1da177e4 258 struct net_device *dev;
1da177e4 259
1da177e4
LT
260 struct dst_entry *dst;
261 struct sec_path *sp;
262
263 /*
264 * This is the control buffer. It is free to use for every
265 * layer. Please put your private variables there. If you
266 * want to keep them across layers you have to do a skb_clone()
267 * first. This is owned by whoever has the skb queued ATM.
268 */
3e3850e9 269 char cb[48];
1da177e4
LT
270
271 unsigned int len,
334a8132
PM
272 data_len;
273 __u16 mac_len,
274 hdr_len;
ff1dcadb
AV
275 union {
276 __wsum csum;
663ead3b
HX
277 struct {
278 __u16 csum_start;
279 __u16 csum_offset;
280 };
ff1dcadb 281 };
1da177e4 282 __u32 priority;
1cbb3380
TG
283 __u8 local_df:1,
284 cloned:1,
285 ip_summed:2,
6869c4d8
HW
286 nohdr:1,
287 nfctinfo:3;
d179cd12 288 __u8 pkt_type:3,
b84f4cc9 289 fclone:2,
ba9dda3a
JK
290 ipvs_property:1,
291 nf_trace:1;
a0d3bea3 292 __be16 protocol;
1da177e4
LT
293
294 void (*destructor)(struct sk_buff *skb);
9fb9cbb1 295#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
5f79e0f9 296 struct nf_conntrack *nfct;
9fb9cbb1
YK
297 struct sk_buff *nfct_reasm;
298#endif
1da177e4
LT
299#ifdef CONFIG_BRIDGE_NETFILTER
300 struct nf_bridge_info *nf_bridge;
301#endif
f25f4e44
PWJ
302
303 int iif;
304 __u16 queue_mapping;
305
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