2 * Copyright (c) 2014 VMware, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __NET_PROTO_H_
18 #define __NET_PROTO_H_ 1
24 #define ETH_HEADER_LENGTH 14
25 #define ETH_ADDR_LENGTH 6
27 * There is a more inclusive definition of ethernet header (Eth_Header) in
28 * OvsEth.h that is used for packet parsing. For simple cases, , use the following definition.
30 typedef struct EthHdr {
31 UINT8 Destination[ETH_ADDR_LENGTH];
32 UINT8 Source[ETH_ADDR_LENGTH];
39 #define IP_HDR_MIN_LENGTH 20
40 #define TCP_HDR_MIN_LENGTH 20
41 #define TCP_CSUM_OFFSET 16
42 #define UDP_CSUM_OFFSET 6
43 #define ICMP_CSUM_OFFSET 2
44 #define INET_CSUM_LENGTH (sizeof(UINT16))
46 #define IP4_UNITS_TO_BYTES(x) ((x) << 2)
47 #define IP4_BYTES_TO_UNITS(x) ((x) >> 2)
49 // length unit for ip->ihl, tcp->doff
50 typedef UINT32 IP4UnitLength;
52 #define IP4_LENGTH_UNIT (sizeof(IP4UnitLength))
53 #define IP4_HDR_MIN_LENGTH_IN_UNITS (IP_HDR_MIN_LENGTH / IP4_LENGTH_UNIT)
54 #define TCP_HDR_MIN_LENGTH_IN_UNITS (TCP_HDR_MIN_LENGTH / IP4_LENGTH_UNIT)
56 #define IP4_IHL_NO_OPTIONS IP4_HDR_MIN_LENGTH_IN_UNITS
57 #define IP4_HDR_LEN(iph) IP4_UNITS_TO_BYTES((iph)->ihl)
59 // length unit for ip->frag_off
60 typedef UINT64 IP4FragUnitLength;
62 #define IP4_FRAG_UNIT_LENGTH (sizeof(IP4FragUnitLength))
64 // length UINT for ipv6 header length.
65 typedef UINT64 IP6UnitLength;
67 #define TCP_HDR_LEN(tcph) IP4_UNITS_TO_BYTES((tcph)->doff)
68 #define TCP_DATA_LENGTH(iph, tcph) (ntohs(iph->tot_len) - \
69 IP4_HDR_LEN(iph) - TCP_HDR_LEN(tcph))
71 #define TCP_DATA_OFFSET_NO_OPTIONS TCP_HDR_MIN_LENGTH_IN_UNITS
72 #define TCP_DATA_OFFSET_WITH_TIMESTAMP 8
75 * This is the maximum value for the length field in the IP header. The meaning
76 * varies with IP protocols:
77 * IPv4: the total ip length (including ip header and extention)
78 * IPv6: the IP payload length (including IP extensions)
80 #define IP_MAX_PACKET 0xFFFF
82 #define IPPROTO_ICMP 1
83 #define IPPROTO_IGMP 2
84 #define IPPROTO_UDP 17
85 #define IPPROTO_GRE 47
87 #define IPPROTO_SCTP 132
88 #define IPPROTO_RSVD 0xff
90 #define IPPROTO_HOPOPTS 0 /* Hop-by-hop option header */
91 #define IPPROTO_IPV6 41 /* IPv6 in IPv6 */
92 #define IPPROTO_ROUTING 43 /* Routing header */
93 #define IPPROTO_FRAGMENT 44 /* Fragmentation/reassembly header */
94 #define IPPROTO_GRE 47 /* General Routing Encapsulation */
95 #define IPPROTO_ESP 50 /* Encap. Security Payload */
96 #define IPPROTO_AH 51 /* Authentication header */
97 #define IPPROTO_ICMPV6 58 /* ICMP for IPv6 */
98 #define IPPROTO_NONE 59 /* No next header */
99 #define IPPROTO_DSTOPTS 60 /* Destination options header */
100 #define IPPROTO_ETHERIP 97 /* etherIp tunneled protocol */
103 #define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */
104 #define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisment */
106 /* IPv6 Neighbor discovery option header. */
107 #define ND_OPT_SOURCE_LINKADDR 1
108 #define ND_OPT_TARGET_LINKADDR 2
110 /* Collides with MS definition (opposite order) */
111 #define IP6F_OFF_HOST_ORDER_MASK 0xfff8
113 #define ARPOP_REQUEST 1 /* ARP request. */
114 #define ARPOP_REPLY 2 /* ARP reply. */
115 #define RARPOP_REQUEST 3 /* RARP request. */
116 #define RARPOP_REPLY 4 /* RARP reply. */
118 /* all ARP NBO's assume short ar_op */
119 #define ARPOP_REQUEST_NBO 0x0100 /* NBO ARP request. */
120 #define ARPOP_REPLY_NBO 0x0200 /* NBO ARP reply. */
121 #define RARPOP_REQUEST_NBO 0x0300 /* NBO RARP request. */
122 #define RARPOP_REPLY_NBO 0x0300 /* NBO RARP reply. */
124 #define ICMP_ECHO 8 /* Echo Request */
125 #define ICMP_ECHOREPLY 0 /* Echo Reply */
126 #define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
128 /* IGMP related constants */
129 #define IGMP_UNKNOWN 0x00 /* For IGMP packets where we don't know the type */
130 /* Eg: Fragmented packets without the header */
132 /* Constants from RFC 3376 */
133 #define IGMP_QUERY 0x11 /* IGMP Host Membership Query. */
134 #define IGMP_V1REPORT 0x12 /* IGMPv1 Host Membership Report. */
135 #define IGMP_V2REPORT 0x16 /* IGMPv2 Host Membership Report. */
136 #define IGMP_V3REPORT 0x22 /* IGMPv3 Host Membership Report. */
137 #define IGMP_V2LEAVE 0x17 /* IGMPv2 Leave. */
139 /* Constants from RFC 2710 and RFC 3810 */
140 #define MLD_QUERY 0x82 /* Multicast Listener Query. */
141 #define MLD_V1REPORT 0x83 /* Multicast Listener V1 Report. */
142 #define MLD_V2REPORT 0x8F /* Multicast Listener V2 Report. */
143 #define MLD_DONE 0x84 /* Multicast Listener Done. */
145 /* IPv4 offset flags */
146 #define IP_CE 0x8000 /* Flag: "Congestion" */
147 #define IP_DF 0x4000 /* Flag: "Don't Fragment" */
148 #define IP_MF 0x2000 /* Flag: "More Fragments" */
149 #define IP_OFFSET 0x1FFF /* "Fragment Offset" part */
151 #define IP_OFFSET_NBO 0xFF1F /* "Fragment Offset" part, NBO */
152 #define IP_DF_NBO 0x0040 /* NBO version of don't fragment */
153 #define IP_MF_NBO 0x0020 /* NBO version of more fragments */
155 #define IPOPT_RTRALT 0x94
157 /* IP Explicit Congestion Notification bits (TOS field) */
158 #define IP_ECN_NOT_ECT 0
159 #define IP_ECN_ECT_1 1
160 #define IP_ECN_ECT_0 2
162 #define IP_ECN_MASK 3
165 #define TCP_OPT_NOP 1 /* Padding */
166 #define TCP_OPT_EOL 0 /* End of options */
167 #define TCP_OPT_MSS 2 /* Segment size negotiating */
168 #define TCP_OPT_WINDOW 3 /* Window scaling */
169 #define TCP_OPT_SACK_PERM 4 /* SACK Permitted */
170 #define TCP_OPT_SACK 5 /* SACK Block */
171 #define TCP_OPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */
172 #define TCP_OPT_MD5SIG 19 /* MD5 Signature (RFC2385) */
174 #define TCP_OPT_LEN_MSS 4
175 #define TCP_OPT_LEN_WINDOW 3
176 #define TCP_OPT_LEN_SACK_PERM 2
177 #define TCP_OPT_LEN_TIMESTAMP 10
178 #define TCP_OPT_LEN_MD5SIG 18
180 #define SOCKET_IPPROTO_HOPOPTS IPPROTO_HOPOPTS
181 #define SOCKET_IPPROTO_ROUTING IPPROTO_ROUTING
182 #define SOCKET_IPPROTO_FRAGMENT IPPROTO_FRAGMENT
183 #define SOCKET_IPPROTO_AH IPPROTO_AH
184 #define SOCKET_IPPROTO_ICMPV6 IPPROTO_ICMPV6
185 #define SOCKET_IPPROTO_NONE IPPROTO_NONE
186 #define SOCKET_IPPROTO_DSTOPTS IPPROTO_DSTOPTS
187 #define SOCKET_IPPROTO_EON 80
188 #define SOCKET_IPPROTO_ETHERIP IPPROTO_ETHERIP
189 #define SOCKET_IPPROTO_ENCAP 98
190 #define SOCKET_IPPROTO_PIM 103
191 #define SOCKET_IPPROTO_IPCOMP 108
192 #define SOCKET_IPPROTO_CARP 112
193 #define SOCKET_IPPROTO_PFSYNC 240
194 #define SOCKET_IPPROTO_RAW IPPROTO_RSVD
196 typedef union _OVS_PACKET_HDR_INFO {
209 UINT16 tcpCsumNeeded:1;
210 UINT16 udpCsumNeeded:1;
211 UINT16 udpCsumZero:1;
215 } OVS_PACKET_HDR_INFO, *POVS_PACKET_HDR_INFO;
217 typedef struct IPHdr {
235 * BEWARE, it is incorrect. The first 4 bits of flow_lbl
236 * are glued to priority now, forming "class".
239 typedef struct IPv6Hdr {
248 struct in6_addr saddr;
249 struct in6_addr daddr;
252 // Generic IPv6 extension header
253 typedef struct IPv6ExtHdr {
254 UINT8 nextHeader; // type of the next header
255 UINT8 hdrExtLen; // length of header extensions (beyond 8 bytes)
260 typedef struct IPv6FragHdr {
267 typedef struct IPv6NdOptHdr {
272 typedef struct ICMPHdr {
278 typedef struct ICMPEcho {
283 typedef struct UDPHdr {
290 typedef struct TCPHdr {
310 typedef struct SCTPHdr {
317 typedef struct PseudoHdr {
325 typedef struct PseudoHdrIPv6 {
326 UINT8 sourceIPAddr[16];
327 UINT8 destIPAddr[16];
335 UINT16 ar_hrd; /* Format of hardware address. */
336 UINT16 ar_pro; /* Format of protocol address. */
337 UINT8 ar_hln; /* Length of hardware address. */
338 UINT8 ar_pln; /* Length of protocol address. */
339 UINT16 ar_op; /* ARP opcode (command). */
342 typedef struct EtherArp {
343 struct ArpHdr ea_hdr; /* fixed-size header */
344 Eth_Address arp_sha; /* sender hardware address */
345 UINT8 arp_spa[4]; /* sender protocol address */
346 Eth_Address arp_tha; /* target hardware address */
347 UINT8 arp_tpa[4]; /* target protocol address */
350 typedef struct IGMPHdr {
352 UINT8 maxResponseTime;
357 typedef struct IGMPV3Trailer {
365 typedef struct IPOpt {
374 #define SOCKET_IPPROTO_IP 0
375 #define SOCKET_IPPROTO_ICMP 1
376 #define SOCKET_IPPROTO_TCP 6
377 #define SOCKET_IPPROTO_UDP 17
378 #define SOCKET_IPPROTO_GRE 47
379 #define SOCKET_IPPROTO_SCTP 132
381 #endif /* __NET_PROTO_H_ */