remove version in all files
[dpdk.git] / lib / librte_net / rte_ip.h
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without 
8  *   modification, are permitted provided that the following conditions 
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright 
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright 
14  *       notice, this list of conditions and the following disclaimer in 
15  *       the documentation and/or other materials provided with the 
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its 
18  *       contributors may be used to endorse or promote products derived 
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * 
33  */
34
35 /*
36  * Copyright (c) 1982, 1986, 1990, 1993
37  *      The Regents of the University of California.  All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in the
46  *    documentation and/or other materials provided with the distribution.
47  * 3. All advertising materials mentioning features or use of this software
48  *    must display the following acknowledgement:
49  *      This product includes software developed by the University of
50  *      California, Berkeley and its contributors.
51  * 4. Neither the name of the University nor the names of its contributors
52  *    may be used to endorse or promote products derived from this software
53  *    without specific prior written permission.
54  *
55  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65  * SUCH DAMAGE.
66  *
67  *      @(#)in.h        8.3 (Berkeley) 1/3/94
68  * $FreeBSD: src/sys/netinet/in.h,v 1.82 2003/10/25 09:37:10 ume Exp $
69  */
70
71 #ifndef _RTE_IP_H_
72 #define _RTE_IP_H_
73
74 /**
75  * @file
76  *
77  * IP-related defines
78  */
79
80 #include <stdint.h>
81
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85
86 /**
87  * IPv4 Header
88  */
89 struct ipv4_hdr {
90         uint8_t  version_ihl;           /**< version and header length */
91         uint8_t  type_of_service;       /**< type of service */
92         uint16_t total_length;          /**< length of packet */
93         uint16_t packet_id;             /**< packet ID */
94         uint16_t fragment_offset;       /**< fragmentation offset */
95         uint8_t  time_to_live;          /**< time to live */
96         uint8_t  next_proto_id;         /**< protocol ID */
97         uint16_t hdr_checksum;          /**< header checksum */
98         uint32_t src_addr;              /**< source address */
99         uint32_t dst_addr;              /**< destination address */
100 } __attribute__((__packed__));
101
102 /** Create IPv4 address */
103 #define IPv4(a,b,c,d) ((uint32_t)(((a) & 0xff) << 24) | \
104                                            (((b) & 0xff) << 16) | \
105                                            (((c) & 0xff) << 8)  | \
106                                            ((d) & 0xff))
107
108 /* IPv4 protocols */
109 #define IPPROTO_IP         0  /**< dummy for IP */
110 #define IPPROTO_HOPOPTS    0  /**< IP6 hop-by-hop options */
111 #define IPPROTO_ICMP       1  /**< control message protocol */
112 #define IPPROTO_IGMP       2  /**< group mgmt protocol */
113 #define IPPROTO_GGP        3  /**< gateway^2 (deprecated) */
114 #define IPPROTO_IPV4       4  /**< IPv4 encapsulation */
115 #define IPPROTO_TCP        6  /**< tcp */
116 #define IPPROTO_ST         7  /**< Stream protocol II */
117 #define IPPROTO_EGP        8  /**< exterior gateway protocol */
118 #define IPPROTO_PIGP       9  /**< private interior gateway */
119 #define IPPROTO_RCCMON    10  /**< BBN RCC Monitoring */
120 #define IPPROTO_NVPII     11  /**< network voice protocol*/
121 #define IPPROTO_PUP       12  /**< pup */
122 #define IPPROTO_ARGUS     13  /**< Argus */
123 #define IPPROTO_EMCON     14  /**< EMCON */
124 #define IPPROTO_XNET      15  /**< Cross Net Debugger */
125 #define IPPROTO_CHAOS     16  /**< Chaos*/
126 #define IPPROTO_UDP       17  /**< user datagram protocol */
127 #define IPPROTO_MUX       18  /**< Multiplexing */
128 #define IPPROTO_MEAS      19  /**< DCN Measurement Subsystems */
129 #define IPPROTO_HMP       20  /**< Host Monitoring */
130 #define IPPROTO_PRM       21  /**< Packet Radio Measurement */
131 #define IPPROTO_IDP       22  /**< xns idp */
132 #define IPPROTO_TRUNK1    23  /**< Trunk-1 */
133 #define IPPROTO_TRUNK2    24  /**< Trunk-2 */
134 #define IPPROTO_LEAF1     25  /**< Leaf-1 */
135 #define IPPROTO_LEAF2     26  /**< Leaf-2 */
136 #define IPPROTO_RDP       27  /**< Reliable Data */
137 #define IPPROTO_IRTP      28  /**< Reliable Transaction */
138 #define IPPROTO_TP        29  /**< tp-4 w/ class negotiation */
139 #define IPPROTO_BLT       30  /**< Bulk Data Transfer */
140 #define IPPROTO_NSP       31  /**< Network Services */
141 #define IPPROTO_INP       32  /**< Merit Internodal */
142 #define IPPROTO_SEP       33  /**< Sequential Exchange */
143 #define IPPROTO_3PC       34  /**< Third Party Connect */
144 #define IPPROTO_IDPR      35  /**< InterDomain Policy Routing */
145 #define IPPROTO_XTP       36  /**< XTP */
146 #define IPPROTO_DDP       37  /**< Datagram Delivery */
147 #define IPPROTO_CMTP      38  /**< Control Message Transport */
148 #define IPPROTO_TPXX      39  /**< TP++ Transport */
149 #define IPPROTO_IL        40  /**< IL transport protocol */
150 #define IPPROTO_IPV6      41  /**< IP6 header */
151 #define IPPROTO_SDRP      42  /**< Source Demand Routing */
152 #define IPPROTO_ROUTING   43  /**< IP6 routing header */
153 #define IPPROTO_FRAGMENT  44  /**< IP6 fragmentation header */
154 #define IPPROTO_IDRP      45  /**< InterDomain Routing*/
155 #define IPPROTO_RSVP      46  /**< resource reservation */
156 #define IPPROTO_GRE       47  /**< General Routing Encap. */
157 #define IPPROTO_MHRP      48  /**< Mobile Host Routing */
158 #define IPPROTO_BHA       49  /**< BHA */
159 #define IPPROTO_ESP       50  /**< IP6 Encap Sec. Payload */
160 #define IPPROTO_AH        51  /**< IP6 Auth Header */
161 #define IPPROTO_INLSP     52  /**< Integ. Net Layer Security */
162 #define IPPROTO_SWIPE     53  /**< IP with encryption */
163 #define IPPROTO_NHRP      54  /**< Next Hop Resolution */
164 /* 55-57: Unassigned */
165 #define IPPROTO_ICMPV6    58  /**< ICMP6 */
166 #define IPPROTO_NONE      59  /**< IP6 no next header */
167 #define IPPROTO_DSTOPTS   60  /**< IP6 destination option */
168 #define IPPROTO_AHIP      61  /**< any host internal protocol */
169 #define IPPROTO_CFTP      62  /**< CFTP */
170 #define IPPROTO_HELLO     63  /**< "hello" routing protocol */
171 #define IPPROTO_SATEXPAK  64  /**< SATNET/Backroom EXPAK */
172 #define IPPROTO_KRYPTOLAN 65  /**< Kryptolan */
173 #define IPPROTO_RVD       66  /**< Remote Virtual Disk */
174 #define IPPROTO_IPPC      67  /**< Pluribus Packet Core */
175 #define IPPROTO_ADFS      68  /**< Any distributed FS */
176 #define IPPROTO_SATMON    69  /**< Satnet Monitoring */
177 #define IPPROTO_VISA      70  /**< VISA Protocol */
178 #define IPPROTO_IPCV      71  /**< Packet Core Utility */
179 #define IPPROTO_CPNX      72  /**< Comp. Prot. Net. Executive */
180 #define IPPROTO_CPHB      73  /**< Comp. Prot. HeartBeat */
181 #define IPPROTO_WSN       74  /**< Wang Span Network */
182 #define IPPROTO_PVP       75  /**< Packet Video Protocol */
183 #define IPPROTO_BRSATMON  76  /**< BackRoom SATNET Monitoring */
184 #define IPPROTO_ND        77  /**< Sun net disk proto (temp.) */
185 #define IPPROTO_WBMON     78  /**< WIDEBAND Monitoring */
186 #define IPPROTO_WBEXPAK   79  /**< WIDEBAND EXPAK */
187 #define IPPROTO_EON       80  /**< ISO cnlp */
188 #define IPPROTO_VMTP      81  /**< VMTP */
189 #define IPPROTO_SVMTP     82  /**< Secure VMTP */
190 #define IPPROTO_VINES     83  /**< Banyon VINES */
191 #define IPPROTO_TTP       84  /**< TTP */
192 #define IPPROTO_IGP       85  /**< NSFNET-IGP */
193 #define IPPROTO_DGP       86  /**< dissimilar gateway prot. */
194 #define IPPROTO_TCF       87  /**< TCF */
195 #define IPPROTO_IGRP      88  /**< Cisco/GXS IGRP */
196 #define IPPROTO_OSPFIGP   89  /**< OSPFIGP */
197 #define IPPROTO_SRPC      90  /**< Strite RPC protocol */
198 #define IPPROTO_LARP      91  /**< Locus Address Resoloution */
199 #define IPPROTO_MTP       92  /**< Multicast Transport */
200 #define IPPROTO_AX25      93  /**< AX.25 Frames */
201 #define IPPROTO_IPEIP     94  /**< IP encapsulated in IP */
202 #define IPPROTO_MICP      95  /**< Mobile Int.ing control */
203 #define IPPROTO_SCCSP     96  /**< Semaphore Comm. security */
204 #define IPPROTO_ETHERIP   97  /**< Ethernet IP encapsulation */
205 #define IPPROTO_ENCAP     98  /**< encapsulation header */
206 #define IPPROTO_APES      99  /**< any private encr. scheme */
207 #define IPPROTO_GMTP     100  /**< GMTP */
208 #define IPPROTO_IPCOMP   108  /**< payload compression (IPComp) */
209 /* 101-254: Partly Unassigned */
210 #define IPPROTO_PIM      103  /**< Protocol Independent Mcast */
211 #define IPPROTO_PGM      113  /**< PGM */
212 #define IPPROTO_SCTP     132  /**< Stream Control Transport Protocol */
213 /* 255: Reserved */
214 /* BSD Private, local use, namespace incursion */
215 #define IPPROTO_DIVERT   254  /**< divert pseudo-protocol */
216 #define IPPROTO_RAW      255  /**< raw IP packet */
217 #define IPPROTO_MAX      256  /**< maximum protocol number */
218
219 /*
220  * IPv4 address types
221  */
222 #define IPV4_ANY              ((uint32_t)0x00000000) /**< 0.0.0.0 */
223 #define IPV4_LOOPBACK         ((uint32_t)0x7f000001) /**< 127.0.0.1 */
224 #define IPV4_BROADCAST        ((uint32_t)0xe0000000) /**< 224.0.0.0 */
225 #define IPV4_ALLHOSTS_GROUP   ((uint32_t)0xe0000001) /**< 224.0.0.1 */
226 #define IPV4_ALLRTRS_GROUP    ((uint32_t)0xe0000002) /**< 224.0.0.2 */
227 #define IPV4_MAX_LOCAL_GROUP  ((uint32_t)0xe00000ff) /**< 224.0.0.255 */
228
229 /*
230  * IPv4 Multicast-related macros
231  */
232 #define IPV4_MIN_MCAST  IPv4(224, 0, 0, 0)          /**< Minimal IPv4-multicast address */
233 #define IPV4_MAX_MCAST  IPv4(239, 255, 255, 255)    /**< Maximum IPv4 multicast address */
234
235 #define IS_IPV4_MCAST(x) \
236         ((x) >= IPV4_MIN_MCAST && (x) <= IPV4_MAX_MCAST) /**< check if IPv4 address is multicast */
237
238 /**
239  * IPv6 Header
240  */
241 struct ipv6_hdr {
242         uint32_t vtc_flow;     /**< IP version, traffic class & flow label. */
243         uint16_t payload_len;  /**< IP packet length - includes sizeof(ip_header). */
244         uint8_t  proto;        /**< Protocol, next header. */
245         uint8_t  hop_limits;   /**< Hop limits. */
246         uint8_t  src_addr[16]; /**< IP address of source host. */
247         uint8_t  dst_addr[16]; /**< IP address of destination host(s). */
248 } __attribute__((__packed__));
249
250 #ifdef __cplusplus
251 }
252 #endif
253
254 #endif /* _RTE_IP_H_ */