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.
18 #define __OVS_PUB_H_ 1
20 #include "../ovsext/Netlink.h"
22 #define OVS_DRIVER_MAJOR_VER 1
23 #define OVS_DRIVER_MINOR_VER 0
25 #define OVS_DEVICE_TYPE 45000
26 #define OVS_IOCTL_TYPE OVS_DEVICE_TYPE
27 #define OVS_DP_NUMBER ((uint32_t) 0)
28 #define OVSWIN_DEVICE_NAME_MAX_LENGTH 32
30 #define IFF_RUNNING 0x20
31 #define IFF_PROMISC 0x40
33 #define OVS_MAX_OPAQUE_NETWORK_ID_LEN 128
35 #define OVS_NT_DEVICE_NAME L"\\Device\\OvsIoctl"
36 #define OVS_DOS_DEVICE_NAME L"\\DosDevices\\OvsIoctl"
37 #define OVS_USER_DEVICE_PATH TEXT("\\\\.\\OvsIoctl")
39 #define OVS_IOCTL_DP_START 0x100
40 #define OVS_IOCTL_DP_DUMP \
41 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DP_START + 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
42 #define OVS_IOCTL_DP_GET \
43 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DP_START + 0x1, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
44 #define OVS_IOCTL_DP_SET \
45 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DP_START + 0x2, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
46 #define OVS_IOCTL_DP_TIMESTAMP_SET \
47 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DP_START + 0x3, METHOD_BUFFERED, FILE_ANY_ACCESS)
50 #define OVS_IOCTL_VPORT_START 0x200
51 #define OVS_IOCTL_VPORT_DUMP \
52 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x0, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
53 #define OVS_IOCTL_VPORT_GET \
54 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x1, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
55 #define OVS_IOCTL_VPORT_SET \
56 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x2, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
57 #define OVS_IOCTL_VPORT_ADD \
58 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x3, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
59 #define OVS_IOCTL_VPORT_DEL \
60 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x4, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
61 #define OVS_IOCTL_VPORT_EXT_INFO \
62 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x5, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
64 #define OVS_IOCTL_FLOW_START 0x300
65 #define OVS_IOCTL_FLOW_DUMP \
66 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_FLOW_START + 0x0, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
67 #define OVS_IOCTL_FLOW_GET \
68 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_FLOW_START + 0x1, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
70 #define OVS_IOCTL_FLOW_PUT \
71 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_FLOW_START + 0x2, METHOD_BUFFERED, FILE_ANY_ACCESS)
72 #define OVS_IOCTL_FLOW_FLUSH \
73 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_FLOW_START + 0x3, METHOD_BUFFERED, FILE_WRITE_ACCESS)
76 #define OVS_IOCTL_QOS_START 0x400
77 #define OVS_IOCTL_QOS_QUEUE_DUMP \
78 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_QOS_START + 0x0, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
79 #define OVS_IOCTL_QOS_QUEUE_GET \
80 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_QOS_START + 0x1, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
81 #define OVS_IOCTL_QOS_QUEUE_SET \
82 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_QOS_START + 0x2, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
85 #define OVS_IOCTL_DATAPATH_START 0x500
86 #define OVS_IOCTL_DATAPATH_SUBSCRIBE \
87 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x0, METHOD_BUFFERED, FILE_WRITE_ACCESS)
88 #define OVS_IOCTL_DATAPATH_READ \
89 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x1, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
90 #define OVS_IOCTL_DATAPATH_EXECUTE \
91 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x2, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
92 #define OVS_IOCTL_DATAPATH_OPERATE \
93 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x3, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
94 #define OVS_IOCTL_DATAPATH_PURGE \
95 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x4, METHOD_NEITHER, FILE_ANY_ACCESS)
96 #define OVS_IOCTL_DATAPATH_WAIT \
97 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x5, METHOD_NEITHER, FILE_ANY_ACCESS)
101 #define OVS_IOCTL_EVENT_START 0x600
102 #define OVS_IOCTL_EVENT_SUBSCRIBE \
103 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_EVENT_START + 0x0, METHOD_BUFFERED, FILE_WRITE_ACCESS)
104 #define OVS_IOCTL_EVENT_POLL \
105 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_EVENT_START + 0x1, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
106 #define OVS_IOCTL_EVENT_WAIT \
107 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_EVENT_START + 0x2, METHOD_BUFFERED, FILE_ANY_ACCESS)
110 #define OVS_IOCTL_VERSION_START 0x700
111 #define OVS_IOCTL_VERSION_GET \
112 CTL_CODE(OVS_DEVICE_TYPE, OVS_IOCTL_VERSION_START + 0x0, METHOD_BUFFERED, FILE_ANY_ACCESS)
114 typedef __declspec(align(8)) uint64_t Ovs64AlignedU64;
115 typedef __declspec(align(8)) ovs_be64 Ovs64AlignedBe64;
116 #pragma pack(push, 1)
119 typedef struct _OVS_DP_INFO {
123 Ovs64AlignedU64 nHit;
124 Ovs64AlignedU64 nMissed;
125 Ovs64AlignedU64 nLost;
126 Ovs64AlignedU64 nFlows;
127 } OVS_DP_INFO, *POVS_DP_INFO;
130 typedef struct _OVS_VERSION {
133 } OVS_VERSION, *POVS_VERSION;
137 #define OVS_MAX_PORT_NAME_LENGTH 32
139 typedef struct _OVS_VPORT_GET {
142 char name[OVS_MAX_PORT_NAME_LENGTH];
143 } OVS_VPORT_GET, *POVS_VPORT_GET;
147 OVSWIN_VPORT_TYPE_UNKNOWN,
148 OVSWIN_VPORT_TYPE_RESERVED,
149 OVSWIN_VPORT_TYPE_EXTERNAL,
150 OVSWIN_VPORT_TYPE_INTERNAL,
151 OVSWIN_VPORT_TYPE_SYNTHETIC,
152 OVSWIN_VPORT_TYPE_EMULATED,
153 OVSWIN_VPORT_TYPE_GRE,
154 OVSWIN_VPORT_TYPE_GRE64,
155 OVSWIN_VPORT_TYPE_VXLAN,
156 OVSWIN_VPORT_TYPE_LOCAL, /* For bridge local port. */
159 static __inline const char *
160 OvsVportTypeToStr(OVS_VPORT_TYPE t)
163 #define STR(t) case OVSWIN_VPORT_TYPE_##t : return "VPORT_##t";
176 return "Invalid type";
179 #define MAC_ADDRESS_LEN 6
181 typedef struct _OVS_VPORT_INFO {
184 char name[OVS_MAX_PORT_NAME_LENGTH];
188 Ovs64AlignedU64 rxPackets;
189 Ovs64AlignedU64 txPackets;
190 Ovs64AlignedU64 rxBytes;
191 Ovs64AlignedU64 txBytes;
192 Ovs64AlignedU64 rxErrors;
193 Ovs64AlignedU64 txErrors;
194 Ovs64AlignedU64 rxDropped;
195 Ovs64AlignedU64 txDropped;
197 uint8_t macAddress[MAC_ADDRESS_LEN];
199 } OVS_VPORT_INFO, *POVS_VPORT_INFO;
201 typedef struct _OVS_VPORT_ADD_REQUEST {
204 char name[OVS_MAX_PORT_NAME_LENGTH];
207 } OVS_VPORT_ADD_REQUEST, *POVS_VPORT_ADD_REQUEST;
210 typedef struct _OVS_VPORT_DELETE_REQUEST {
213 char name[OVS_MAX_PORT_NAME_LENGTH];
214 } OVS_VPORT_DELETE_REQUEST, *POVS_VPORT_DELETE_REQUEST;
217 #define OVS_MAX_VM_UUID_LEN 128
218 #define OVS_MAX_VIF_UUID_LEN 128
220 typedef struct _OVS_VPORT_EXT_INFO {
223 uint8_t macAddress[MAC_ADDRESS_LEN];
224 uint8_t permMACAddress[MAC_ADDRESS_LEN];
225 uint8_t vmMACAddress[MAC_ADDRESS_LEN];
230 char name[OVS_MAX_PORT_NAME_LENGTH];
232 char vmUUID[OVS_MAX_VM_UUID_LEN];
233 char vifUUID[OVS_MAX_VIF_UUID_LEN];
234 } OVS_VPORT_EXT_INFO, *POVS_VPORT_EXT_INFO;
238 #define OVSWIN_VLAN_CFI 0x1000
239 #define OVSWIN_INPORT_INVALID 0xffffffff
241 /* Used for OvsFlowKey's dlType member for frames that have no Ethernet type,
242 * that is, pure 802.2 frames. */
243 #define OVSWIN_DL_TYPE_NONE 0x5ff
245 /* Fragment bits, used for IPv4 and IPv6, always zero for non-IP flows. */
246 #define OVSWIN_NW_FRAG_ANY (1 << 0) /* Set for any IP frag. */
247 #define OVSWIN_NW_FRAG_LATER (1 << 1) /* Set for IP frag with nonzero
249 #define OVSWIN_NW_FRAG_MASK (OVSWIN_NW_FRAG_ANY | OVSWIN_NW_FRAG_LATER)
251 typedef struct L4Key {
252 ovs_be16 tpSrc; /* TCP/UDP/SCTP source port. */
253 ovs_be16 tpDst; /* TCP/UDP/SCTP destination port. */
256 typedef struct Ipkey {
257 ovs_be32 nwSrc; /* IPv4 source address. */
258 ovs_be32 nwDst; /* IPv4 destination address. */
259 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
260 uint8_t nwTos; /* IP ToS (including DSCP and ECN). */
261 uint8_t nwTtl; /* IP TTL/Hop Limit. */
262 uint8_t nwFrag; /* FLOW_FRAG_* flags. */
264 } IpKey; /* Size of 16 byte. */
266 typedef struct ArpKey {
267 ovs_be32 nwSrc; /* IPv4 source address. */
268 ovs_be32 nwDst; /* IPv4 destination address. */
269 uint8_t arpSha[6]; /* ARP/ND source hardware address. */
270 uint8_t arpTha[6]; /* ARP/ND target hardware address. */
271 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
273 } ArpKey; /* Size of 24 byte. */
275 typedef struct Ipv6Key {
276 struct in6_addr ipv6Src; /* IPv6 source address. */
277 struct in6_addr ipv6Dst; /* IPv6 destination address. */
278 ovs_be32 ipv6Label; /* IPv6 flow label. */
279 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
280 uint8_t nwTos; /* IP ToS (including DSCP and ECN). */
281 uint8_t nwTtl; /* IP TTL/Hop Limit. */
282 uint8_t nwFrag; /* FLOW_FRAG_* flags. */
285 } Ipv6Key; /* Size of 48 byte. */
287 typedef struct Icmp6Key {
288 struct in6_addr ipv6Src; /* IPv6 source address. */
289 struct in6_addr ipv6Dst; /* IPv6 destination address. */
290 ovs_be32 ipv6Label; /* IPv6 flow label. */
291 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
292 uint8_t nwTos; /* IP ToS (including DSCP and ECN). */
293 uint8_t nwTtl; /* IP TTL/Hop Limit. */
294 uint8_t nwFrag; /* FLOW_FRAG_* flags. */
296 uint8_t arpSha[6]; /* ARP/ND source hardware address. */
297 uint8_t arpTha[6]; /* ARP/ND target hardware address. */
298 struct in6_addr ndTarget; /* IPv6 neighbor discovery (ND) target. */
299 } Icmp6Key; /* Size of 72 byte. */
301 typedef struct L2Key {
302 uint32_t inPort; /* Port number of input port. */
310 uint8_t dlSrc[6]; /* Ethernet source address. */
311 uint8_t dlDst[6]; /* Ethernet destination address. */
312 ovs_be16 vlanTci; /* If 802.1Q, TCI | VLAN_CFI; otherwise 0. */
313 ovs_be16 dlType; /* Ethernet frame type. */
314 } L2Key; /* Size of 24 byte. */
316 /* Number of packet attributes required to store OVS tunnel key. */
317 #define NUM_PKT_ATTR_REQUIRED 3
319 typedef union OvsIPv4TunnelKey {
335 uint64_t attr[NUM_PKT_ATTR_REQUIRED];
338 typedef __declspec(align(8)) struct OvsFlowKey {
339 OvsIPv4TunnelKey tunKey; /* 24 bytes */
340 L2Key l2; /* 24 bytes */
342 IpKey ipKey; /* size 16 */
343 ArpKey arpKey; /* size 24 */
344 Ipv6Key ipv6Key; /* size 48 */
345 Icmp6Key icmp6Key; /* size 72 */
349 #define OVS_WIN_TUNNEL_KEY_SIZE (sizeof (OvsIPv4TunnelKey))
350 #define OVS_L2_KEY_SIZE (sizeof (L2Key))
351 #define OVS_IP_KEY_SIZE (sizeof (IpKey))
352 #define OVS_IPV6_KEY_SIZE (sizeof (Ipv6Key))
353 #define OVS_ARP_KEY_SIZE (sizeof (ArpKey))
354 #define OVS_ICMPV6_KEY_SIZE (sizeof (Icmp6Key))
356 typedef struct OvsFlowStats {
357 Ovs64AlignedU64 packetCount;
358 Ovs64AlignedU64 byteCount;
363 typedef struct OvsFlowInfo {
365 struct OvsFlowStats stats;
371 FLOW_GET_KEY = 0x00000001,
372 FLOW_GET_STATS = 0x00000010,
373 FLOW_GET_ACTIONS = 0x00000100,
376 typedef struct OvsFlowDumpInput {
378 uint32_t position[2]; /* Offset hint to the start of flow dump. */
379 /* 0 - index of the hash table.
380 * 1 - nth element in the hash table index. */
381 uint32_t getFlags; /* Information to get in addition to keys. */
386 typedef struct OvsFlowDumpOutput {
387 /* Hint for the next flow dump operation. */
388 uint32_t position[2];
390 /* #flows (currently 0 or 1). In case the buffer is too small to output all
391 * actions, this field indicates actual size needed to dump all actions. */
397 typedef struct OvsFlowGetInput {
400 uint32_t getFlags; /* Information to get in addition to keys. */
401 uint32_t actionsLen; /* Sizeof of buffer for actions. */
404 typedef struct OvsFlowGetOutput {
405 OvsFlowInfo info; /* Variable length. */
409 typedef enum OvsFlowPutFlags {
410 OVSWIN_FLOW_PUT_CREATE = 1 << 0,
411 OVSWIN_FLOW_PUT_MODIFY = 1 << 1,
412 OVSWIN_FLOW_PUT_DELETE = 1 << 2,
414 OVSWIN_FLOW_PUT_CLEAR = 1 << 3
418 typedef struct OvsFlowPut {
423 NL_ATTR actions[0]; /* Variable length indicated by actionsLen. */
426 #define OVS_MIN_PACKET_SIZE 60
427 typedef struct _OVS_PACKET_INFO {
429 uint32_t userDataLen;
434 OvsIPv4TunnelKey tunnelKey;
435 /* Includes user data defined as chain of netlink attributes followed by the
438 } OVS_PACKET_INFO, *POVS_PACKET_INFO;
440 typedef struct OvsPacketExecute {
447 /* Variable size blob with packet data first, followed by action
455 typedef struct _OVS_EVENT_SUBSCRIBE {
460 } OVS_EVENT_SUBSCRIBE, *POVS_EVENT_SUBSCRIBE;
462 typedef struct _OVS_EVENT_POLL {
465 } OVS_EVENT_POLL, *POVS_EVENT_POLL;
468 OVS_EVENT_CONNECT = ((uint32_t)0x1 << 0),
469 OVS_EVENT_DISCONNECT = ((uint32_t)0x1 << 1),
470 OVS_EVENT_LINK_UP = ((uint32_t)0x1 << 2),
471 OVS_EVENT_LINK_DOWN = ((uint32_t)0x1 << 3),
472 OVS_EVENT_MAC_CHANGE = ((uint32_t)0x1 << 4),
473 OVS_EVENT_MTU_CHANGE = ((uint32_t)0x1 << 5),
474 OVS_EVENT_MASK_ALL = 0x3f,
478 typedef struct _OVS_EVENT_ENTRY {
481 } OVS_EVENT_ENTRY, *POVS_EVENT_ENTRY;
483 #define OVS_DEFAULT_PORT_NO 0xffffffff
484 #define OVS_DEFAULT_EVENT_STATUS 0xffffffff
486 typedef struct _OVS_EVENT_STATUS {
487 uint32_t numberEntries;
488 OVS_EVENT_ENTRY eventEntries[0];
489 } OVS_EVENT_STATUS, *POVS_EVENT_STATUS;
493 #endif /* __OVS_PUB_H_ */