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
23 #define ETH_ADDR_LENGTH 6
25 * There is a more inclusive definition of ethernet header (Eth_Header) in
26 * OvsEth.h that is used for packet parsing. For simple cases, , use the following definition.
28 typedef struct EthHdr {
29 UINT8 Destination[ETH_ADDR_LENGTH];
30 UINT8 Source[ETH_ADDR_LENGTH];
37 #define IP_HDR_MIN_LENGTH 20
38 #define TCP_HDR_MIN_LENGTH 20
39 #define TCP_CSUM_OFFSET 16
40 #define UDP_CSUM_OFFSET 6
41 #define ICMP_CSUM_OFFSET 2
42 #define INET_CSUM_LENGTH (sizeof(UINT16))
44 #define IP4_UNITS_TO_BYTES(x) ((x) << 2)
45 #define IP4_BYTES_TO_UNITS(x) ((x) >> 2)
47 // length unit for ip->ihl, tcp->doff
48 typedef UINT32 IP4UnitLength;
50 #define IP4_LENGTH_UNIT (sizeof(IP4UnitLength))
51 #define IP4_HDR_MIN_LENGTH_IN_UNITS (IP_HDR_MIN_LENGTH / IP4_LENGTH_UNIT)
52 #define TCP_HDR_MIN_LENGTH_IN_UNITS (TCP_HDR_MIN_LENGTH / IP4_LENGTH_UNIT)
54 #define IP4_IHL_NO_OPTIONS IP4_HDR_MIN_LENGTH_IN_UNITS
55 #define IP4_HDR_LEN(iph) IP4_UNITS_TO_BYTES((iph)->ihl)
57 // length unit for ip->frag_off
58 typedef UINT64 IP4FragUnitLength;
60 #define IP4_FRAG_UNIT_LENGTH (sizeof(IP4FragUnitLength))
62 // length UINT for ipv6 header length.
63 typedef UINT64 IP6UnitLength;
65 #define TCP_HDR_LEN(tcph) IP4_UNITS_TO_BYTES((tcph)->doff)
66 #define TCP_DATA_LENGTH(iph, tcph) (ntohs(iph->tot_len) - \
67 IP4_HDR_LEN(iph) - TCP_HDR_LEN(tcph))
69 #define TCP_DATA_OFFSET_NO_OPTIONS TCP_HDR_MIN_LENGTH_IN_UNITS
70 #define TCP_DATA_OFFSET_WITH_TIMESTAMP 8
73 * This is the maximum value for the length field in the IP header. The meaning
74 * varies with IP protocols:
75 * IPv4: the total ip length (including ip header and extention)
76 * IPv6: the IP payload length (including IP extensions)
78 #define IP_MAX_PACKET 0xFFFF
80 #define IPPROTO_ICMP 1
81 #define IPPROTO_IGMP 2
82 #define IPPROTO_UDP 17
83 #define IPPROTO_GRE 47
85 #define IPPROTO_SCTP 132
86 #define IPPROTO_RSVD 0xff
88 #define IPPROTO_HOPOPTS 0 /* Hop-by-hop option header */
89 #define IPPROTO_IPV6 41 /* IPv6 in IPv6 */
90 #define IPPROTO_ROUTING 43 /* Routing header */
91 #define IPPROTO_FRAGMENT 44 /* Fragmentation/reassembly header */
92 #define IPPROTO_GRE 47 /* General Routing Encapsulation */
93 #define IPPROTO_ESP 50 /* Encap. Security Payload */
94 #define IPPROTO_AH 51 /* Authentication header */
95 #define IPPROTO_ICMPV6 58 /* ICMP for IPv6 */
96 #define IPPROTO_NONE 59 /* No next header */
97 #define IPPROTO_DSTOPTS 60 /* Destination options header */
98 #define IPPROTO_ETHERIP 97 /* etherIp tunneled protocol */
101 #define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */
102 #define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisment */
104 /* IPv6 Neighbor discovery option header. */
105 #define ND_OPT_SOURCE_LINKADDR 1
106 #define ND_OPT_TARGET_LINKADDR 2
108 /* Collides with MS definition (opposite order) */
109 #define IP6F_OFF_HOST_ORDER_MASK 0xfff8
111 #define ARPOP_REQUEST 1 /* ARP request. */
112 #define ARPOP_REPLY 2 /* ARP reply. */
113 #define RARPOP_REQUEST 3 /* RARP request. */
114 #define RARPOP_REPLY 4 /* RARP reply. */
116 /* all ARP NBO's assume short ar_op */
117 #define ARPOP_REQUEST_NBO 0x0100 /* NBO ARP request. */
118 #define ARPOP_REPLY_NBO 0x0200 /* NBO ARP reply. */
119 #define RARPOP_REQUEST_NBO 0x0300 /* NBO RARP request. */
120 #define RARPOP_REPLY_NBO 0x0300 /* NBO RARP reply. */
122 #define ICMP_ECHO 8 /* Echo Request */
123 #define ICMP_ECHOREPLY 0 /* Echo Reply */
124 #define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
126 /* IGMP related constants */
127 #define IGMP_UNKNOWN 0x00 /* For IGMP packets where we don't know the type */
128 /* Eg: Fragmented packets without the header */
130 /* Constants from RFC 3376 */
131 #define IGMP_QUERY 0x11 /* IGMP Host Membership Query. */
132 #define IGMP_V1REPORT 0x12 /* IGMPv1 Host Membership Report. */
133 #define IGMP_V2REPORT 0x16 /* IGMPv2 Host Membership Report. */
134 #define IGMP_V3REPORT 0x22 /* IGMPv3 Host Membership Report. */
135 #define IGMP_V2LEAVE 0x17 /* IGMPv2 Leave. */
137 /* Constants from RFC 2710 and RFC 3810 */
138 #define MLD_QUERY 0x82 /* Multicast Listener Query. */
139 #define MLD_V1REPORT 0x83 /* Multicast Listener V1 Report. */
140 #define MLD_V2REPORT 0x8F /* Multicast Listener V2 Report. */
141 #define MLD_DONE 0x84 /* Multicast Listener Done. */
143 /* IPv4 offset flags */
144 #define IP_CE 0x8000 /* Flag: "Congestion" */
145 #define IP_DF 0x4000 /* Flag: "Don't Fragment" */
146 #define IP_MF 0x2000 /* Flag: "More Fragments" */
147 #define IP_OFFSET 0x1FFF /* "Fragment Offset" part */
149 #define IP_OFFSET_NBO 0xFF1F /* "Fragment Offset" part, NBO */
150 #define IP_DF_NBO 0x0040 /* NBO version of don't fragment */
151 #define IP_MF_NBO 0x0020 /* NBO version of more fragments */
153 #define IPOPT_RTRALT 0x94
155 /* IP Explicit Congestion Notification bits (TOS field) */
156 #define IP_ECN_NOT_ECT 0
157 #define IP_ECN_ECT_1 1
158 #define IP_ECN_ECT_0 2
160 #define IP_ECN_MASK 3
163 #define TCP_OPT_NOP 1 /* Padding */
164 #define TCP_OPT_EOL 0 /* End of options */
165 #define TCP_OPT_MSS 2 /* Segment size negotiating */
166 #define TCP_OPT_WINDOW 3 /* Window scaling */
167 #define TCP_OPT_SACK_PERM 4 /* SACK Permitted */
168 #define TCP_OPT_SACK 5 /* SACK Block */
169 #define TCP_OPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */
170 #define TCP_OPT_MD5SIG 19 /* MD5 Signature (RFC2385) */
172 #define TCP_OPT_LEN_MSS 4
173 #define TCP_OPT_LEN_WINDOW 3
174 #define TCP_OPT_LEN_SACK_PERM 2
175 #define TCP_OPT_LEN_TIMESTAMP 10
176 #define TCP_OPT_LEN_MD5SIG 18
178 #define SOCKET_IPPROTO_HOPOPTS IPPROTO_HOPOPTS
179 #define SOCKET_IPPROTO_ROUTING IPPROTO_ROUTING
180 #define SOCKET_IPPROTO_FRAGMENT IPPROTO_FRAGMENT
181 #define SOCKET_IPPROTO_AH IPPROTO_AH
182 #define SOCKET_IPPROTO_ICMPV6 IPPROTO_ICMPV6
183 #define SOCKET_IPPROTO_NONE IPPROTO_NONE
184 #define SOCKET_IPPROTO_DSTOPTS IPPROTO_DSTOPTS
185 #define SOCKET_IPPROTO_EON 80
186 #define SOCKET_IPPROTO_ETHERIP IPPROTO_ETHERIP
187 #define SOCKET_IPPROTO_ENCAP 98
188 #define SOCKET_IPPROTO_PIM 103
189 #define SOCKET_IPPROTO_IPCOMP 108
190 #define SOCKET_IPPROTO_CARP 112
191 #define SOCKET_IPPROTO_PFSYNC 240
192 #define SOCKET_IPPROTO_RAW IPPROTO_RSVD
194 typedef union _OVS_PACKET_HDR_INFO {
207 UINT16 tcpCsumNeeded:1;
208 UINT16 udpCsumNeeded:1;
209 UINT16 udpCsumZero:1;
213 } OVS_PACKET_HDR_INFO, *POVS_PACKET_HDR_INFO;
215 typedef struct IPHdr {
233 * BEWARE, it is incorrect. The first 4 bits of flow_lbl
234 * are glued to priority now, forming "class".
237 typedef struct IPv6Hdr {
246 struct in6_addr saddr;
247 struct in6_addr daddr;
250 // Generic IPv6 extension header
251 typedef struct IPv6ExtHdr {
252 UINT8 nextHeader; // type of the next header
253 UINT8 hdrExtLen; // length of header extensions (beyond 8 bytes)
258 typedef struct IPv6FragHdr {
265 typedef struct IPv6NdOptHdr {
270 typedef struct ICMPHdr {
276 typedef struct ICMPEcho {
281 typedef struct UDPHdr {
288 typedef struct TCPHdr {
308 typedef struct SCTPHdr {
315 typedef struct PseudoHdr {
323 typedef struct PseudoHdrIPv6 {
324 UINT8 sourceIPAddr[16];
325 UINT8 destIPAddr[16];
333 UINT16 ar_hrd; /* Format of hardware address. */
334 UINT16 ar_pro; /* Format of protocol address. */
335 UINT8 ar_hln; /* Length of hardware address. */
336 UINT8 ar_pln; /* Length of protocol address. */
337 UINT16 ar_op; /* ARP opcode (command). */
340 typedef struct EtherArp {
341 struct ArpHdr ea_hdr; /* fixed-size header */
342 Eth_Address arp_sha; /* sender hardware address */
343 UINT8 arp_spa[4]; /* sender protocol address */
344 Eth_Address arp_tha; /* target hardware address */
345 UINT8 arp_tpa[4]; /* target protocol address */
348 typedef struct IGMPHdr {
350 UINT8 maxResponseTime;
355 typedef struct IGMPV3Trailer {
363 typedef struct IPOpt {
372 #define SOCKET_IPPROTO_IP 0
373 #define SOCKET_IPPROTO_ICMP 1
374 #define SOCKET_IPPROTO_TCP 6
375 #define SOCKET_IPPROTO_UDP 17
376 #define SOCKET_IPPROTO_GRE 47
377 #define SOCKET_IPPROTO_SCTP 132
379 #endif /* __NET_PROTO_H_ */