Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * INET An implementation of the TCP/IP protocol suite for the LINUX |
| 3 | * operating system. INET is implemented using the BSD Socket |
| 4 | * interface as the means of communication with the user level. |
| 5 | * |
| 6 | * Definitions for the IP protocol. |
| 7 | * |
| 8 | * Version: @(#)ip.h 1.0.2 04/28/93 |
| 9 | * |
| 10 | * Authors: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version |
| 15 | * 2 of the License, or (at your option) any later version. |
| 16 | */ |
| 17 | #ifndef _LINUX_IP_H |
| 18 | #define _LINUX_IP_H |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 19 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/byteorder.h> |
| 21 | |
| 22 | #define IPTOS_TOS_MASK 0x1E |
| 23 | #define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK) |
| 24 | #define IPTOS_LOWDELAY 0x10 |
| 25 | #define IPTOS_THROUGHPUT 0x08 |
| 26 | #define IPTOS_RELIABILITY 0x04 |
| 27 | #define IPTOS_MINCOST 0x02 |
| 28 | |
| 29 | #define IPTOS_PREC_MASK 0xE0 |
| 30 | #define IPTOS_PREC(tos) ((tos)&IPTOS_PREC_MASK) |
| 31 | #define IPTOS_PREC_NETCONTROL 0xe0 |
| 32 | #define IPTOS_PREC_INTERNETCONTROL 0xc0 |
| 33 | #define IPTOS_PREC_CRITIC_ECP 0xa0 |
| 34 | #define IPTOS_PREC_FLASHOVERRIDE 0x80 |
| 35 | #define IPTOS_PREC_FLASH 0x60 |
| 36 | #define IPTOS_PREC_IMMEDIATE 0x40 |
| 37 | #define IPTOS_PREC_PRIORITY 0x20 |
| 38 | #define IPTOS_PREC_ROUTINE 0x00 |
| 39 | |
| 40 | |
| 41 | /* IP options */ |
| 42 | #define IPOPT_COPY 0x80 |
| 43 | #define IPOPT_CLASS_MASK 0x60 |
| 44 | #define IPOPT_NUMBER_MASK 0x1f |
| 45 | |
| 46 | #define IPOPT_COPIED(o) ((o)&IPOPT_COPY) |
| 47 | #define IPOPT_CLASS(o) ((o)&IPOPT_CLASS_MASK) |
| 48 | #define IPOPT_NUMBER(o) ((o)&IPOPT_NUMBER_MASK) |
| 49 | |
| 50 | #define IPOPT_CONTROL 0x00 |
| 51 | #define IPOPT_RESERVED1 0x20 |
| 52 | #define IPOPT_MEASUREMENT 0x40 |
| 53 | #define IPOPT_RESERVED2 0x60 |
| 54 | |
| 55 | #define IPOPT_END (0 |IPOPT_CONTROL) |
| 56 | #define IPOPT_NOOP (1 |IPOPT_CONTROL) |
| 57 | #define IPOPT_SEC (2 |IPOPT_CONTROL|IPOPT_COPY) |
| 58 | #define IPOPT_LSRR (3 |IPOPT_CONTROL|IPOPT_COPY) |
| 59 | #define IPOPT_TIMESTAMP (4 |IPOPT_MEASUREMENT) |
Paul Moore | 11a03f7 | 2006-08-03 16:46:20 -0700 | [diff] [blame] | 60 | #define IPOPT_CIPSO (6 |IPOPT_CONTROL|IPOPT_COPY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define IPOPT_RR (7 |IPOPT_CONTROL) |
| 62 | #define IPOPT_SID (8 |IPOPT_CONTROL|IPOPT_COPY) |
| 63 | #define IPOPT_SSRR (9 |IPOPT_CONTROL|IPOPT_COPY) |
| 64 | #define IPOPT_RA (20|IPOPT_CONTROL|IPOPT_COPY) |
| 65 | |
| 66 | #define IPVERSION 4 |
| 67 | #define MAXTTL 255 |
| 68 | #define IPDEFTTL 64 |
| 69 | |
| 70 | #define IPOPT_OPTVAL 0 |
| 71 | #define IPOPT_OLEN 1 |
| 72 | #define IPOPT_OFFSET 2 |
| 73 | #define IPOPT_MINOFF 4 |
| 74 | #define MAX_IPOPTLEN 40 |
| 75 | #define IPOPT_NOP IPOPT_NOOP |
| 76 | #define IPOPT_EOL IPOPT_END |
| 77 | #define IPOPT_TS IPOPT_TIMESTAMP |
| 78 | |
| 79 | #define IPOPT_TS_TSONLY 0 /* timestamps only */ |
| 80 | #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ |
| 81 | #define IPOPT_TS_PRESPEC 3 /* specified modules only */ |
| 82 | |
Diego Beltrami | 0a69452 | 2006-10-03 23:47:05 -0700 | [diff] [blame] | 83 | #define IPV4_BEET_PHMAXLEN 8 |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | struct iphdr { |
| 86 | #if defined(__LITTLE_ENDIAN_BITFIELD) |
| 87 | __u8 ihl:4, |
| 88 | version:4; |
| 89 | #elif defined (__BIG_ENDIAN_BITFIELD) |
| 90 | __u8 version:4, |
| 91 | ihl:4; |
| 92 | #else |
| 93 | #error "Please fix <asm/byteorder.h>" |
| 94 | #endif |
| 95 | __u8 tos; |
Alexey Dobriyan | 76ab608 | 2006-01-06 13:24:29 -0800 | [diff] [blame] | 96 | __be16 tot_len; |
| 97 | __be16 id; |
| 98 | __be16 frag_off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | __u8 ttl; |
| 100 | __u8 protocol; |
Al Viro | 9981a0e | 2006-11-14 21:24:30 -0800 | [diff] [blame] | 101 | __sum16 check; |
Alexey Dobriyan | 76ab608 | 2006-01-06 13:24:29 -0800 | [diff] [blame] | 102 | __be32 saddr; |
| 103 | __be32 daddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /*The options start here. */ |
| 105 | }; |
| 106 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 107 | #ifdef __KERNEL__ |
| 108 | #include <linux/skbuff.h> |
| 109 | |
| 110 | static inline struct iphdr *ip_hdr(const struct sk_buff *skb) |
| 111 | { |
| 112 | return (struct iphdr *)skb_network_header(skb); |
| 113 | } |
Arnaldo Carvalho de Melo | b0061ce | 2007-04-25 18:02:22 -0700 | [diff] [blame] | 114 | |
| 115 | static inline struct iphdr *ipip_hdr(const struct sk_buff *skb) |
| 116 | { |
Arnaldo Carvalho de Melo | 9c70220 | 2007-04-25 18:04:18 -0700 | [diff] [blame] | 117 | return (struct iphdr *)skb_transport_header(skb); |
Arnaldo Carvalho de Melo | b0061ce | 2007-04-25 18:02:22 -0700 | [diff] [blame] | 118 | } |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 119 | #endif |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | struct ip_auth_hdr { |
| 122 | __u8 nexthdr; |
| 123 | __u8 hdrlen; /* This one is measured in 32 bit units! */ |
Al Viro | 046d033 | 2006-09-26 21:24:24 -0700 | [diff] [blame] | 124 | __be16 reserved; |
| 125 | __be32 spi; |
| 126 | __be32 seq_no; /* Sequence number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | __u8 auth_data[0]; /* Variable len but >=4. Mind the 64 bit alignment! */ |
| 128 | }; |
| 129 | |
| 130 | struct ip_esp_hdr { |
Al Viro | 046d033 | 2006-09-26 21:24:24 -0700 | [diff] [blame] | 131 | __be32 spi; |
| 132 | __be32 seq_no; /* Sequence number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | __u8 enc_data[0]; /* Variable len but >=8. Mind the 64 bit alignment! */ |
| 134 | }; |
| 135 | |
| 136 | struct ip_comp_hdr { |
| 137 | __u8 nexthdr; |
| 138 | __u8 flags; |
Al Viro | 046d033 | 2006-09-26 21:24:24 -0700 | [diff] [blame] | 139 | __be16 cpi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Diego Beltrami | 0a69452 | 2006-10-03 23:47:05 -0700 | [diff] [blame] | 142 | struct ip_beet_phdr { |
| 143 | __u8 nexthdr; |
| 144 | __u8 hdrlen; |
| 145 | __u8 padlen; |
| 146 | __u8 reserved; |
| 147 | }; |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #endif /* _LINUX_IP_H */ |