]> git.proxmox.com Git - mirror_ovs.git/blob - datapath-windows/ovsext/DpInternal.h
datapath-windows: Clean up properly in case of driver init failure.
[mirror_ovs.git] / datapath-windows / ovsext / DpInternal.h
1 /*
2 * Copyright (c) 2014 VMware, Inc.
3 *
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:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #ifndef __DP_INTERNAL_H_
18 #define __DP_INTERNAL_H_ 1
19
20 #include <netioapi.h>
21 #define IFNAMSIZ IF_NAMESIZE
22 #include "../ovsext/Netlink/Netlink.h"
23
24 #define OVS_DP_NUMBER ((uint32_t) 0)
25
26 typedef __declspec(align(8)) uint64_t Ovs64AlignedU64;
27 typedef __declspec(align(8)) ovs_be64 Ovs64AlignedBe64;
28 #pragma pack(push, 1)
29
30 #define OVS_MAX_PORT_NAME_LENGTH IFNAMSIZ
31
32 typedef struct _OVS_VPORT_GET {
33 uint32_t dpNo;
34 uint32_t portNo;
35 char name[OVS_MAX_PORT_NAME_LENGTH];
36 } OVS_VPORT_GET, *POVS_VPORT_GET;
37
38 #define OVS_MAX_VM_UUID_LEN 128
39 #define OVS_MAX_VIF_UUID_LEN 128
40
41 typedef struct _OVS_VPORT_EXT_INFO {
42 uint32_t dpNo;
43 uint32_t portNo;
44 uint8_t macAddress[ETH_ADDR_LEN];
45 uint8_t permMACAddress[ETH_ADDR_LEN];
46 uint8_t vmMACAddress[ETH_ADDR_LEN];
47 uint16_t nicIndex;
48 uint32_t portId;
49 uint32_t type;
50 uint32_t mtu;
51 char name[OVS_MAX_PORT_NAME_LENGTH];
52 uint32_t status;
53 char vmUUID[OVS_MAX_VM_UUID_LEN];
54 char vifUUID[OVS_MAX_VIF_UUID_LEN];
55 } OVS_VPORT_EXT_INFO, *POVS_VPORT_EXT_INFO;
56
57
58 /* Flows. */
59 #define OVSWIN_VLAN_CFI 0x1000
60
61 /* Used for OvsFlowKey's dlType member for frames that have no Ethernet type,
62 * that is, pure 802.2 frames. */
63 #define OVSWIN_DL_TYPE_NONE 0x5ff
64
65 /* Fragment bits, used for IPv4 and IPv6, always zero for non-IP flows. */
66 #define OVSWIN_NW_FRAG_ANY (1 << 0) /* Set for any IP frag. */
67 #define OVSWIN_NW_FRAG_LATER (1 << 1) /* Set for IP frag with nonzero
68 * offset. */
69 #define OVSWIN_NW_FRAG_MASK (OVSWIN_NW_FRAG_ANY | OVSWIN_NW_FRAG_LATER)
70
71 typedef struct L4Key {
72 ovs_be16 tpSrc; /* TCP/UDP/SCTP source port. */
73 ovs_be16 tpDst; /* TCP/UDP/SCTP destination port. */
74 } L4Key;
75
76 typedef struct Ipkey {
77 ovs_be32 nwSrc; /* IPv4 source address. */
78 ovs_be32 nwDst; /* IPv4 destination address. */
79 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
80 uint8_t nwTos; /* IP ToS (including DSCP and ECN). */
81 uint8_t nwTtl; /* IP TTL/Hop Limit. */
82 uint8_t nwFrag; /* FLOW_FRAG_* flags. */
83 L4Key l4;
84 } IpKey; /* Size of 16 byte. */
85
86 typedef struct ArpKey {
87 ovs_be32 nwSrc; /* IPv4 source address. */
88 ovs_be32 nwDst; /* IPv4 destination address. */
89 uint8_t arpSha[6]; /* ARP/ND source hardware address. */
90 uint8_t arpTha[6]; /* ARP/ND target hardware address. */
91 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
92 uint8_t pad[3];
93 } ArpKey; /* Size of 24 byte. */
94
95 typedef struct Ipv6Key {
96 struct in6_addr ipv6Src; /* IPv6 source address. */
97 struct in6_addr ipv6Dst; /* IPv6 destination address. */
98 ovs_be32 ipv6Label; /* IPv6 flow label. */
99 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
100 uint8_t nwTos; /* IP ToS (including DSCP and ECN). */
101 uint8_t nwTtl; /* IP TTL/Hop Limit. */
102 uint8_t nwFrag; /* FLOW_FRAG_* flags. */
103 L4Key l4;
104 uint32_t pad;
105 } Ipv6Key; /* Size of 48 byte. */
106
107 typedef struct Icmp6Key {
108 struct in6_addr ipv6Src; /* IPv6 source address. */
109 struct in6_addr ipv6Dst; /* IPv6 destination address. */
110 ovs_be32 ipv6Label; /* IPv6 flow label. */
111 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
112 uint8_t nwTos; /* IP ToS (including DSCP and ECN). */
113 uint8_t nwTtl; /* IP TTL/Hop Limit. */
114 uint8_t nwFrag; /* FLOW_FRAG_* flags. */
115 L4Key l4;
116 uint8_t arpSha[6]; /* ARP/ND source hardware address. */
117 uint8_t arpTha[6]; /* ARP/ND target hardware address. */
118 struct in6_addr ndTarget; /* IPv6 neighbor discovery (ND) target. */
119 } Icmp6Key; /* Size of 72 byte. */
120
121 typedef struct L2Key {
122 uint32_t inPort; /* Port number of input port. */
123 union {
124 struct {
125 uint16_t offset;
126 uint16_t keyLen;
127 };
128 uint32_t val;
129 };
130 uint8_t dlSrc[6]; /* Ethernet source address. */
131 uint8_t dlDst[6]; /* Ethernet destination address. */
132 ovs_be16 vlanTci; /* If 802.1Q, TCI | VLAN_CFI; otherwise 0. */
133 ovs_be16 dlType; /* Ethernet frame type. */
134 } L2Key; /* Size of 24 byte. */
135
136 /* Number of packet attributes required to store OVS tunnel key. */
137 #define NUM_PKT_ATTR_REQUIRED 3
138
139 typedef union OvsIPv4TunnelKey {
140 struct {
141 ovs_be32 dst;
142 ovs_be32 src;
143 ovs_be64 tunnelId;
144 uint16_t flags;
145 uint8_t tos;
146 uint8_t ttl;
147 union {
148 uint32_t pad;
149 struct {
150 ovs_be16 dst_port;
151 uint16_t flow_hash;
152 };
153 };
154 };
155 uint64_t attr[NUM_PKT_ATTR_REQUIRED];
156 } OvsIPv4TunnelKey;
157
158 typedef __declspec(align(8)) struct OvsFlowKey {
159 OvsIPv4TunnelKey tunKey; /* 24 bytes */
160 L2Key l2; /* 24 bytes */
161 union {
162 IpKey ipKey; /* size 16 */
163 ArpKey arpKey; /* size 24 */
164 Ipv6Key ipv6Key; /* size 48 */
165 Icmp6Key icmp6Key; /* size 72 */
166 };
167 } OvsFlowKey;
168
169 #define OVS_WIN_TUNNEL_KEY_SIZE (sizeof (OvsIPv4TunnelKey))
170 #define OVS_L2_KEY_SIZE (sizeof (L2Key))
171 #define OVS_IP_KEY_SIZE (sizeof (IpKey))
172 #define OVS_IPV6_KEY_SIZE (sizeof (Ipv6Key))
173 #define OVS_ARP_KEY_SIZE (sizeof (ArpKey))
174 #define OVS_ICMPV6_KEY_SIZE (sizeof (Icmp6Key))
175
176 typedef struct OvsFlowStats {
177 Ovs64AlignedU64 packetCount;
178 Ovs64AlignedU64 byteCount;
179 uint32_t used;
180 uint8_t tcpFlags;
181 } OvsFlowStats;
182
183 typedef struct OvsFlowInfo {
184 OvsFlowKey key;
185 struct OvsFlowStats stats;
186 uint32_t actionsLen;
187 PNL_ATTR actions;
188 } OvsFlowInfo;
189
190 enum GetFlags {
191 FLOW_GET_KEY = 0x00000001,
192 FLOW_GET_STATS = 0x00000010,
193 FLOW_GET_ACTIONS = 0x00000100,
194 };
195
196 typedef struct OvsFlowDumpInput {
197 uint32_t dpNo;
198 uint32_t position[2]; /* Offset hint to the start of flow dump. */
199 /* 0 - index of the hash table.
200 * 1 - nth element in the hash table index. */
201 uint32_t getFlags; /* Information to get in addition to keys. */
202 uint32_t actionsLen;
203 } OvsFlowDumpInput;
204
205
206 typedef struct OvsFlowDumpOutput {
207 /* Hint for the next flow dump operation. */
208 uint32_t position[2];
209
210 /* #flows (currently 0 or 1). In case the buffer is too small to output all
211 * actions, this field indicates actual size needed to dump all actions. */
212 uint32_t n;
213
214 OvsFlowInfo flow;
215 } OvsFlowDumpOutput;
216
217 typedef struct OvsFlowGetInput {
218 uint32_t dpNo;
219 OvsFlowKey key;
220 uint32_t getFlags; /* Information to get in addition to keys. */
221 uint32_t actionsLen; /* Sizeof of buffer for actions. */
222 } OvsFlowGetInput;
223
224 typedef struct OvsFlowGetOutput {
225 OvsFlowInfo info; /* Variable length. */
226 } OvsFlowGetOutput;
227
228
229 typedef enum OvsFlowPutFlags {
230 OVSWIN_FLOW_PUT_CREATE = 1 << 0,
231 OVSWIN_FLOW_PUT_MODIFY = 1 << 1,
232 OVSWIN_FLOW_PUT_DELETE = 1 << 2,
233
234 OVSWIN_FLOW_PUT_CLEAR = 1 << 3
235 } OvsFlowPutFlags;
236
237
238 typedef struct OvsFlowPut {
239 uint32_t dpNo;
240 uint32_t actionsLen;
241 OvsFlowKey key;
242 uint32_t flags;
243 PNL_ATTR actions;
244 } OvsFlowPut;
245
246 #define OVS_MIN_PACKET_SIZE 60
247 typedef struct _OVS_PACKET_INFO {
248 uint32_t totalLen;
249 uint32_t userDataLen;
250 uint32_t packetLen;
251 uint32_t queue;
252 uint32_t inPort;
253 uint32_t cmd;
254 OvsIPv4TunnelKey tunnelKey;
255 uint8_t *payload;
256 /* Includes user data defined as chain of netlink attributes followed by the
257 * packet data. */
258 uint8_t data[0];
259 } OVS_PACKET_INFO, *POVS_PACKET_INFO;
260
261 typedef struct OvsPacketExecute {
262 uint32_t dpNo;
263 uint32_t inPort;
264
265 uint32_t packetLen;
266 uint32_t actionsLen;
267 PCHAR packetBuf;
268 PNL_ATTR actions;
269 } OvsPacketExecute;
270
271
272 typedef struct _OVS_EVENT_SUBSCRIBE {
273 uint32_t cookie;
274 uint32_t dpNo;
275 uint32_t subscribe;
276 uint32_t mask;
277 } OVS_EVENT_SUBSCRIBE, *POVS_EVENT_SUBSCRIBE;
278
279 typedef struct _OVS_EVENT_POLL {
280 uint32_t cookie;
281 uint32_t dpNo;
282 } OVS_EVENT_POLL, *POVS_EVENT_POLL;
283
284 enum {
285 OVS_EVENT_CONNECT = ((uint32_t)0x1 << 0),
286 OVS_EVENT_DISCONNECT = ((uint32_t)0x1 << 1),
287 OVS_EVENT_LINK_UP = ((uint32_t)0x1 << 2),
288 OVS_EVENT_LINK_DOWN = ((uint32_t)0x1 << 3),
289 OVS_EVENT_MAC_CHANGE = ((uint32_t)0x1 << 4),
290 OVS_EVENT_MTU_CHANGE = ((uint32_t)0x1 << 5),
291 OVS_EVENT_MASK_ALL = 0x3f,
292 };
293
294
295 typedef struct _OVS_EVENT_ENTRY {
296 uint32_t portNo;
297 uint32_t status;
298 } OVS_EVENT_ENTRY, *POVS_EVENT_ENTRY;
299
300 #define OVS_DEFAULT_PORT_NO 0xffffffff
301 #define OVS_DEFAULT_EVENT_STATUS 0xffffffff
302
303 typedef struct _OVS_EVENT_STATUS {
304 uint32_t numberEntries;
305 OVS_EVENT_ENTRY eventEntries[0];
306 } OVS_EVENT_STATUS, *POVS_EVENT_STATUS;
307
308 #pragma pack(pop)
309
310 #endif /* __DP_INTERNAL_H_ */