| 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 | |
|---|
| 17 | #include <linux/kernel.h> |
|---|
| 18 | #include <sys/time.h> |
|---|
| 19 | #include <linux/cache.h> |
|---|
| 20 | |
|---|
| 21 | #include <asm/types.h> |
|---|
| 22 | #include <linux/poll.h> |
|---|
| 23 | #include <linux/net.h> |
|---|
| 24 | #include <net/checksum.h> |
|---|
| 25 | |
|---|
| 26 | #define HAVE_ALLOC_SKB /* For the drivers to know */ |
|---|
| 27 | #define HAVE_ALIGNABLE_SKB /* Ditto 8) */ |
|---|
| 28 | #define SLAB_SKB /* Slabified skbuffs */ |
|---|
| 29 | |
|---|
| 30 | #define CHECKSUM_NONE 0 |
|---|
| 31 | #define CHECKSUM_HW 1 |
|---|
| 32 | #define CHECKSUM_UNNECESSARY 2 |
|---|
| 33 | |
|---|
| 34 | #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \ |
|---|
| 35 | ~(SMP_CACHE_BYTES - 1)) |
|---|
| 36 | #define SKB_MAX_ORDER(X, ORDER) (((PAGE_SIZE << (ORDER)) - (X) - \ |
|---|
| 37 | sizeof(struct skb_shared_info)) & \ |
|---|
| 38 | ~(SMP_CACHE_BYTES - 1)) |
|---|
| 39 | #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) |
|---|
| 40 | #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2)) |
|---|
| 41 | |
|---|
| 42 | /* A. Checksumming of received packets by device. |
|---|
| 43 | * |
|---|
| 44 | * NONE: device failed to checksum this packet. |
|---|
| 45 | * skb->csum is undefined. |
|---|
| 46 | * |
|---|
| 47 | * UNNECESSARY: device parsed packet and wouldbe verified checksum. |
|---|
| 48 | * skb->csum is undefined. |
|---|
| 49 | * It is bad option, but, unfortunately, many of vendors do this. |
|---|
| 50 | * Apparently with secret goal to sell you new device, when you |
|---|
| 51 | * will add new protocol to your host. F.e. IPv6. 8) |
|---|
| 52 | * |
|---|
| 53 | * HW: the most generic way. Device supplied checksum of _all_ |
|---|
| 54 | * the packet as seen by netif_rx in skb->csum. |
|---|
| 55 | * NOTE: Even if device supports only some protocols, but |
|---|
| 56 | * is able to produce some skb->csum, it MUST use HW, |
|---|
| 57 | * not UNNECESSARY. |
|---|
| 58 | * |
|---|
| 59 | * B. Checksumming on output. |
|---|
| 60 | * |
|---|
| 61 | * NONE: skb is checksummed by protocol or csum is not required. |
|---|
| 62 | * |
|---|
| 63 | * HW: device is required to csum packet as seen by hard_start_xmit |
|---|
| 64 | * from skb->h.raw to the end and to record the checksum |
|---|
| 65 | * at skb->h.raw+skb->csum. |
|---|
| 66 | * |
|---|
| 67 | * Device must show its capabilities in dev->features, set |
|---|
| 68 | * at device setup time. |
|---|
| 69 | * NETIF_F_HW_CSUM - it is clever device, it is able to checksum |
|---|
| 70 | * everything. |
|---|
| 71 | * NETIF_F_NO_CSUM - loopback or reliable single hop media. |
|---|
| 72 | * NETIF_F_IP_CSUM - device is dumb. It is able to csum only |
|---|
| 73 | * TCP/UDP over IPv4. Sigh. Vendors like this |
|---|
| 74 | * way by an unknown reason. Though, see comment above |
|---|
| 75 | * about CHECKSUM_UNNECESSARY. 8) |
|---|
| 76 | * |
|---|
| 77 | * Any questions? No questions, good. --ANK |
|---|
| 78 | */ |
|---|
| 79 | |
|---|
| 80 | struct net_device; |
|---|
| 81 | |
|---|
| 82 | #ifdef CONFIG_NETFILTER |
|---|
| 83 | struct nf_conntrack { |
|---|
| 84 | atomic_t use; |
|---|
| 85 | void (*destroy)(struct nf_conntrack *); |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | #ifdef CONFIG_BRIDGE_NETFILTER |
|---|
| 89 | struct nf_bridge_info { |
|---|
| 90 | atomic_t use; |
|---|
| 91 | struct net_device *physindev; |
|---|
| 92 | struct net_device *physoutdev; |
|---|
| 93 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
|---|
| 94 | struct net_device *netoutdev; |
|---|
| 95 | #endif |
|---|
| 96 | unsigned int mask; |
|---|
| 97 | unsigned long data[32 / sizeof(unsigned long)]; |
|---|
| 98 | }; |
|---|
| 99 | #endif |
|---|
| 100 | |
|---|
| 101 | #endif |
|---|
| 102 | |
|---|
| 103 | struct sk_buff_head { |
|---|
| 104 | /* These two members must be first. */ |
|---|
| 105 | struct sk_buff *next; |
|---|
| 106 | struct sk_buff *prev; |
|---|
| 107 | |
|---|
| 108 | __u32 qlen; |
|---|
| 109 | spinlock_t lock; |
|---|
| 110 | }; |
|---|
| 111 | |
|---|
| 112 | struct sk_buff; |
|---|
| 113 | |
|---|
| 114 | /* To allow 64K frame to be packed as single skb without frag_list */ |
|---|
| 115 | #define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2) |
|---|
| 116 | |
|---|
| 117 | typedef struct skb_frag_struct skb_frag_t; |
|---|
| 118 | |
|---|
| 119 | struct skb_frag_struct { |
|---|
| 120 | struct page *page; |
|---|
| 121 | __u16 page_offset; |
|---|
| 122 | __u16 size; |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | /* This data is invariant across clones and lives at |
|---|
| 126 | * the end of the header data, ie. at skb->end. |
|---|
| 127 | */ |
|---|
| 128 | struct skb_shared_info { |
|---|
| 129 | atomic_t dataref; |
|---|
| 130 | unsigned int nr_frags; |
|---|
| 131 | unsigned short tso_size; |
|---|
| 132 | unsigned short tso_segs; |
|---|
| 133 | struct sk_buff *frag_list; |
|---|
| 134 | skb_frag_t frags[MAX_SKB_FRAGS]; |
|---|
| 135 | }; |
|---|
| 136 | |
|---|
| 137 | /* We divide dataref into two halves. The higher 16 bits hold references |
|---|
| 138 | * to the payload part of skb->data. The lower 16 bits hold references to |
|---|
| 139 | * the entire skb->data. It is up to the users of the skb to agree on |
|---|
| 140 | * where the payload starts. |
|---|
| 141 | * |
|---|
| 142 | * All users must obey the rule that the skb->data reference count must be |
|---|
| 143 | * greater than or equal to the payload reference count. |
|---|
| 144 | * |
|---|
| 145 | * Holding a reference to the payload part means that the user does not |
|---|
| 146 | * care about modifications to the header part of skb->data. |
|---|
| 147 | */ |
|---|
| 148 | #define SKB_DATAREF_SHIFT 16 |
|---|
| 149 | #define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1) |
|---|
| 150 | |
|---|
| 151 | /** |
|---|
| 152 | * struct sk_buff - socket buffer |
|---|
| 153 | * @next: Next buffer in list |
|---|
| 154 | * @prev: Previous buffer in list |
|---|
| 155 | * @list: List we are on |
|---|
| 156 | * @sk: Socket we are owned by |
|---|
| 157 | * @stamp: Time we arrived |
|---|
| 158 | * @dev: Device we arrived on/are leaving by |
|---|
| 159 | * @input_dev: Device we arrived on |
|---|
| 160 | * @real_dev: The real device we are using |
|---|
| 161 | * @h: Transport layer header |
|---|
| 162 | * @nh: Network layer header |
|---|
| 163 | * @mac: Link layer header |
|---|
| 164 | * @dst: destination entry |
|---|
| 165 | * @sp: the security path, used for xfrm |
|---|
| 166 | * @cb: Control buffer. Free for use by every layer. Put private vars here |
|---|
| 167 | * @len: Length of actual data |
|---|
| 168 | * @data_len: Data length |
|---|
| 169 | * @mac_len: Length of link layer header |
|---|
| 170 | * @csum: Checksum |
|---|
| 171 | * @local_df: allow local fragmentation |
|---|
| 172 | * @cloned: Head may be cloned (check refcnt to be sure) |
|---|
| 173 | * @nohdr: Payload reference only, must not modify header |
|---|
| 174 | * @pkt_type: Packet class |
|---|
| 175 | * @ip_summed: Driver fed us an IP checksum |
|---|
| 176 | * @priority: Packet queueing priority |
|---|
| 177 | * @users: User count - see {datagram,tcp}.c |
|---|
| 178 | * @protocol: Packet protocol from driver |
|---|
| 179 | * @security: Security level of packet |
|---|
| 180 | * @truesize: Buffer size |
|---|
| 181 | * @head: Head of buffer |
|---|
| 182 | * @data: Data head pointer |
|---|
| 183 | * @tail: Tail pointer |
|---|
| 184 | * @end: End pointer |
|---|
| 185 | * @destructor: Destruct function |
|---|
| 186 | * @nfmark: Can be used for communication between hooks |
|---|
| 187 | * @nfcache: Cache info |
|---|
| 188 | * @nfct: Associated connection, if any |
|---|
| 189 | * @nfctinfo: Relationship of this skb to the connection |
|---|
| 190 | * @nf_debug: Netfilter debugging |
|---|
| 191 | * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c |
|---|
| 192 | * @private: Data which is private to the HIPPI implementation |
|---|
| 193 | * @tc_index: Traffic control index |
|---|
| 194 | * @tc_verd: traffic control verdict |
|---|
| 195 | * @tc_classid: traffic control classid |
|---|
| 196 | */ |
|---|
| 197 | |
|---|
| 198 | struct sk_buff { |
|---|
| 199 | /* These two members must be first. */ |
|---|
| 200 | struct sk_buff *next; |
|---|
| 201 | struct sk_buff *prev; |
|---|
| 202 | |
|---|
| 203 | struct sk_buff_head *list; |
|---|
| 204 | struct sock *sk; |
|---|
| 205 | struct timeval stamp; |
|---|
| 206 | struct net_device *dev; |
|---|
| 207 | struct net_device *input_dev; |
|---|
| 208 | struct net_device *real_dev; |
|---|
| 209 | |
|---|
| 210 | union { |
|---|
| 211 | struct tcphdr *th; |
|---|
| 212 | struct udphdr *uh; |
|---|
| 213 | struct icmphdr *icmph; |
|---|
| 214 | struct igmphdr *igmph; |
|---|
| 215 | struct iphdr *ipiph; |
|---|
| 216 | struct ipv6hdr *ipv6h; |
|---|
| 217 | unsigned char *raw; |
|---|
| 218 | } h; |
|---|
| 219 | |
|---|
| 220 | union { |
|---|
| 221 | struct iphdr *iph; |
|---|
| 222 | struct ipv6hdr *ipv6h; |
|---|
| 223 | struct arphdr *arph; |
|---|
| 224 | unsigned char *raw; |
|---|
| 225 | } nh; |
|---|
| 226 | |
|---|
| 227 | union { |
|---|
| 228 | unsigned char *raw; |
|---|
| 229 | } mac; |
|---|
| 230 | |
|---|
| 231 | struct dst_entry *dst; |
|---|
| 232 | struct sec_path *sp; |
|---|
| 233 | |
|---|
| 234 | /* |
|---|
| 235 | * This is the control buffer. It is free to use for every |
|---|
| 236 | * layer. Please put your private variables there. If you |
|---|
| 237 | * want to keep them across layers you have to do a skb_clone() |
|---|
| 238 | * first. This is owned by whoever has the skb queued ATM. |
|---|
| 239 | */ |
|---|
| 240 | char cb[40]; |
|---|
| 241 | |
|---|
| 242 | unsigned int len, |
|---|
| 243 | data_len, |
|---|
| 244 | mac_len, |
|---|
| 245 | csum; |
|---|
| 246 | unsigned char local_df, |
|---|
| 247 | cloned:1, |
|---|
| 248 | nohdr:1, |
|---|
| 249 | pkt_type, |
|---|
| 250 | ip_summed; |
|---|
| 251 | __u32 priority; |
|---|
| 252 | unsigned short protocol, |
|---|
| 253 | security; |
|---|
| 254 | |
|---|
| 255 | void (*destructor)(struct sk_buff *skb); |
|---|
| 256 | #ifdef CONFIG_NETFILTER |
|---|
| 257 | unsigned long nfmark; |
|---|
| 258 | __u32 nfcache; |
|---|
| 259 | __u32 nfctinfo; |
|---|
| 260 | struct nf_conntrack *nfct; |
|---|
| 261 | #ifdef CONFIG_NETFILTER_DEBUG |
|---|
| 262 | unsigned int nf_debug; |
|---|
| 263 | #endif |
|---|
| 264 | #ifdef CONFIG_BRIDGE_NETFILTER |
|---|
| 265 | struct nf_bridge_info *nf_bridge; |
|---|
| 266 | #endif |
|---|
| 267 | #endif /* CONFIG_NETFILTER */ |
|---|
| 268 | #if defined(CONFIG_HIPPI) |
|---|
| 269 | union { |
|---|
| 270 | __u32 ifield; |
|---|
| 271 | } private; |
|---|
| 272 | #endif |
|---|
| 273 | #ifdef CONFIG_NET_SCHED |
|---|
| 274 | __u32 tc_index; /* traffic control index */ |
|---|
| 275 | #ifdef CONFIG_NET_CLS_ACT |
|---|
| 276 | __u32 tc_verd; /* traffic control verdict */ |
|---|
| 277 | __u32 tc_classid; /* traffic control classid */ |
|---|
| 278 | #endif |
|---|
| 279 | |
|---|
| 280 | #endif |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | /* These elements must be at the end, see alloc_skb() for details. */ |
|---|
| 284 | unsigned int truesize; |
|---|
| 285 | atomic_t users; |
|---|
| 286 | unsigned char *head, |
|---|
| 287 | *data, |
|---|
| 288 | *tail, |
|---|
| 289 | *end; |
|---|
| 290 | }; |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | #endif /* _LINUX_SKBUFF_H */ |
|---|