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