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
21 #define IFNAMSIZ IF_NAMESIZE
22 #include "../ovsext/Netlink/Netlink.h"
24 #define OVS_DRIVER_MAJOR_VER 1
25 #define OVS_DRIVER_MINOR_VER 0
27 #define OVS_DEVICE_TYPE 45000
28 #define OVS_IOCTL_TYPE OVS_DEVICE_TYPE
29 #define OVS_DP_NUMBER ((uint32_t) 0)
30 #define OVSWIN_DEVICE_NAME_MAX_LENGTH 32
32 #define IFF_RUNNING 0x20
33 #define IFF_PROMISC 0x40
35 #define OVS_MAX_OPAQUE_NETWORK_ID_LEN 128
37 #define OVS_NT_DEVICE_NAME L"\\Device\\OvsIoctl"
38 #define OVS_DOS_DEVICE_NAME L"\\DosDevices\\OvsIoctl"
39 #define OVS_USER_DEVICE_PATH TEXT("\\\\.\\OvsIoctl")
41 #define OVS_IOCTL_DP_START 0x100
42 #define OVS_IOCTL_DP_DUMP \
43 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DP_START + 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
44 #define OVS_IOCTL_DP_GET \
45 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DP_START + 0x1, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
46 #define OVS_IOCTL_DP_SET \
47 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DP_START + 0x2, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
48 #define OVS_IOCTL_DP_TIMESTAMP_SET \
49 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DP_START + 0x3, METHOD_BUFFERED, FILE_ANY_ACCESS)
52 #define OVS_IOCTL_VPORT_START 0x200
53 #define OVS_IOCTL_VPORT_DUMP \
54 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x0, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
55 #define OVS_IOCTL_VPORT_GET \
56 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x1, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
57 #define OVS_IOCTL_VPORT_SET \
58 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x2, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
59 #define OVS_IOCTL_VPORT_ADD \
60 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x3, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
61 #define OVS_IOCTL_VPORT_DEL \
62 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x4, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
63 #define OVS_IOCTL_VPORT_EXT_INFO \
64 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_VPORT_START + 0x5, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
66 #define OVS_IOCTL_FLOW_START 0x300
67 #define OVS_IOCTL_FLOW_DUMP \
68 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_FLOW_START + 0x0, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
69 #define OVS_IOCTL_FLOW_GET \
70 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_FLOW_START + 0x1, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
72 #define OVS_IOCTL_FLOW_PUT \
73 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_FLOW_START + 0x2, METHOD_BUFFERED, FILE_ANY_ACCESS)
74 #define OVS_IOCTL_FLOW_FLUSH \
75 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_FLOW_START + 0x3, METHOD_BUFFERED, FILE_WRITE_ACCESS)
78 #define OVS_IOCTL_QOS_START 0x400
79 #define OVS_IOCTL_QOS_QUEUE_DUMP \
80 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_QOS_START + 0x0, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
81 #define OVS_IOCTL_QOS_QUEUE_GET \
82 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_QOS_START + 0x1, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
83 #define OVS_IOCTL_QOS_QUEUE_SET \
84 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_QOS_START + 0x2, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
87 #define OVS_IOCTL_DATAPATH_START 0x500
88 #define OVS_IOCTL_DATAPATH_SUBSCRIBE \
89 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x0, METHOD_BUFFERED, FILE_WRITE_ACCESS)
90 #define OVS_IOCTL_DATAPATH_READ \
91 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x1, METHOD_OUT_DIRECT, FILE_READ_ACCESS)
92 #define OVS_IOCTL_DATAPATH_EXECUTE \
93 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x2, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
94 #define OVS_IOCTL_DATAPATH_OPERATE \
95 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x3, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
96 #define OVS_IOCTL_DATAPATH_PURGE \
97 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x4, METHOD_NEITHER, FILE_ANY_ACCESS)
98 #define OVS_IOCTL_DATAPATH_WAIT \
99 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_DATAPATH_START + 0x5, METHOD_NEITHER, FILE_ANY_ACCESS)
103 #define OVS_IOCTL_EVENT_START 0x600
104 #define OVS_IOCTL_EVENT_SUBSCRIBE \
105 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_EVENT_START + 0x0, METHOD_BUFFERED, FILE_WRITE_ACCESS)
106 #define OVS_IOCTL_EVENT_POLL \
107 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_EVENT_START + 0x1, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
108 #define OVS_IOCTL_EVENT_WAIT \
109 CTL_CODE (OVS_DEVICE_TYPE, OVS_IOCTL_EVENT_START + 0x2, METHOD_BUFFERED, FILE_ANY_ACCESS)
112 #define OVS_IOCTL_VERSION_START 0x700
113 #define OVS_IOCTL_VERSION_GET \
114 CTL_CODE(OVS_DEVICE_TYPE, OVS_IOCTL_VERSION_START + 0x0, METHOD_BUFFERED, FILE_ANY_ACCESS)
116 typedef __declspec(align(8)) uint64_t Ovs64AlignedU64;
117 typedef __declspec(align(8)) ovs_be64 Ovs64AlignedBe64;
118 #pragma pack(push, 1)
121 typedef struct _OVS_DP_INFO {
125 Ovs64AlignedU64 nHit;
126 Ovs64AlignedU64 nMissed;
127 Ovs64AlignedU64 nLost;
128 Ovs64AlignedU64 nFlows;
129 } OVS_DP_INFO, *POVS_DP_INFO;
132 typedef struct _OVS_VERSION {
135 } OVS_VERSION, *POVS_VERSION;
137 #define OVS_MAX_PORT_NAME_LENGTH IFNAMSIZ
139 typedef struct _OVS_VPORT_GET {
142 char name[OVS_MAX_PORT_NAME_LENGTH];
143 } OVS_VPORT_GET, *POVS_VPORT_GET;
145 static __inline const char *
146 OvsVportTypeToStr(OVS_VPORT_TYPE t)
149 #define STR(t) case OVS_VPORT_TYPE_##t : return "VPORT_##t";
161 return "Invalid type";
164 #define MAC_ADDRESS_LEN 6
166 typedef struct _OVS_VPORT_INFO {
169 char name[OVS_MAX_PORT_NAME_LENGTH];
173 Ovs64AlignedU64 rxPackets;
174 Ovs64AlignedU64 txPackets;
175 Ovs64AlignedU64 rxBytes;
176 Ovs64AlignedU64 txBytes;
177 Ovs64AlignedU64 rxErrors;
178 Ovs64AlignedU64 txErrors;
179 Ovs64AlignedU64 rxDropped;
180 Ovs64AlignedU64 txDropped;
182 uint8_t macAddress[MAC_ADDRESS_LEN];
184 } OVS_VPORT_INFO, *POVS_VPORT_INFO;
186 typedef struct _OVS_VPORT_ADD_REQUEST {
189 char name[OVS_MAX_PORT_NAME_LENGTH];
192 } OVS_VPORT_ADD_REQUEST, *POVS_VPORT_ADD_REQUEST;
195 typedef struct _OVS_VPORT_DELETE_REQUEST {
198 char name[OVS_MAX_PORT_NAME_LENGTH];
199 } OVS_VPORT_DELETE_REQUEST, *POVS_VPORT_DELETE_REQUEST;
202 #define OVS_MAX_VM_UUID_LEN 128
203 #define OVS_MAX_VIF_UUID_LEN 128
205 typedef struct _OVS_VPORT_EXT_INFO {
208 uint8_t macAddress[MAC_ADDRESS_LEN];
209 uint8_t permMACAddress[MAC_ADDRESS_LEN];
210 uint8_t vmMACAddress[MAC_ADDRESS_LEN];
215 char name[OVS_MAX_PORT_NAME_LENGTH];
217 char vmUUID[OVS_MAX_VM_UUID_LEN];
218 char vifUUID[OVS_MAX_VIF_UUID_LEN];
219 } OVS_VPORT_EXT_INFO, *POVS_VPORT_EXT_INFO;
223 #define OVSWIN_VLAN_CFI 0x1000
224 #define OVSWIN_INPORT_INVALID 0xffffffff
226 /* Used for OvsFlowKey's dlType member for frames that have no Ethernet type,
227 * that is, pure 802.2 frames. */
228 #define OVSWIN_DL_TYPE_NONE 0x5ff
230 /* Fragment bits, used for IPv4 and IPv6, always zero for non-IP flows. */
231 #define OVSWIN_NW_FRAG_ANY (1 << 0) /* Set for any IP frag. */
232 #define OVSWIN_NW_FRAG_LATER (1 << 1) /* Set for IP frag with nonzero
234 #define OVSWIN_NW_FRAG_MASK (OVSWIN_NW_FRAG_ANY | OVSWIN_NW_FRAG_LATER)
236 typedef struct L4Key {
237 ovs_be16 tpSrc; /* TCP/UDP/SCTP source port. */
238 ovs_be16 tpDst; /* TCP/UDP/SCTP destination port. */
241 typedef struct Ipkey {
242 ovs_be32 nwSrc; /* IPv4 source address. */
243 ovs_be32 nwDst; /* IPv4 destination address. */
244 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
245 uint8_t nwTos; /* IP ToS (including DSCP and ECN). */
246 uint8_t nwTtl; /* IP TTL/Hop Limit. */
247 uint8_t nwFrag; /* FLOW_FRAG_* flags. */
249 } IpKey; /* Size of 16 byte. */
251 typedef struct ArpKey {
252 ovs_be32 nwSrc; /* IPv4 source address. */
253 ovs_be32 nwDst; /* IPv4 destination address. */
254 uint8_t arpSha[6]; /* ARP/ND source hardware address. */
255 uint8_t arpTha[6]; /* ARP/ND target hardware address. */
256 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
258 } ArpKey; /* Size of 24 byte. */
260 typedef struct Ipv6Key {
261 struct in6_addr ipv6Src; /* IPv6 source address. */
262 struct in6_addr ipv6Dst; /* IPv6 destination address. */
263 ovs_be32 ipv6Label; /* IPv6 flow label. */
264 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
265 uint8_t nwTos; /* IP ToS (including DSCP and ECN). */
266 uint8_t nwTtl; /* IP TTL/Hop Limit. */
267 uint8_t nwFrag; /* FLOW_FRAG_* flags. */
270 } Ipv6Key; /* Size of 48 byte. */
272 typedef struct Icmp6Key {
273 struct in6_addr ipv6Src; /* IPv6 source address. */
274 struct in6_addr ipv6Dst; /* IPv6 destination address. */
275 ovs_be32 ipv6Label; /* IPv6 flow label. */
276 uint8_t nwProto; /* IP protocol or low 8 bits of ARP opcode. */
277 uint8_t nwTos; /* IP ToS (including DSCP and ECN). */
278 uint8_t nwTtl; /* IP TTL/Hop Limit. */
279 uint8_t nwFrag; /* FLOW_FRAG_* flags. */
281 uint8_t arpSha[6]; /* ARP/ND source hardware address. */
282 uint8_t arpTha[6]; /* ARP/ND target hardware address. */
283 struct in6_addr ndTarget; /* IPv6 neighbor discovery (ND) target. */
284 } Icmp6Key; /* Size of 72 byte. */
286 typedef struct L2Key {
287 uint32_t inPort; /* Port number of input port. */
295 uint8_t dlSrc[6]; /* Ethernet source address. */
296 uint8_t dlDst[6]; /* Ethernet destination address. */
297 ovs_be16 vlanTci; /* If 802.1Q, TCI | VLAN_CFI; otherwise 0. */
298 ovs_be16 dlType; /* Ethernet frame type. */
299 } L2Key; /* Size of 24 byte. */
301 /* Number of packet attributes required to store OVS tunnel key. */
302 #define NUM_PKT_ATTR_REQUIRED 3
304 typedef union OvsIPv4TunnelKey {
320 uint64_t attr[NUM_PKT_ATTR_REQUIRED];
323 typedef __declspec(align(8)) struct OvsFlowKey {
324 OvsIPv4TunnelKey tunKey; /* 24 bytes */
325 L2Key l2; /* 24 bytes */
327 IpKey ipKey; /* size 16 */
328 ArpKey arpKey; /* size 24 */
329 Ipv6Key ipv6Key; /* size 48 */
330 Icmp6Key icmp6Key; /* size 72 */
334 #define OVS_WIN_TUNNEL_KEY_SIZE (sizeof (OvsIPv4TunnelKey))
335 #define OVS_L2_KEY_SIZE (sizeof (L2Key))
336 #define OVS_IP_KEY_SIZE (sizeof (IpKey))
337 #define OVS_IPV6_KEY_SIZE (sizeof (Ipv6Key))
338 #define OVS_ARP_KEY_SIZE (sizeof (ArpKey))
339 #define OVS_ICMPV6_KEY_SIZE (sizeof (Icmp6Key))
341 typedef struct OvsFlowStats {
342 Ovs64AlignedU64 packetCount;
343 Ovs64AlignedU64 byteCount;
348 typedef struct OvsFlowInfo {
350 struct OvsFlowStats stats;
356 FLOW_GET_KEY = 0x00000001,
357 FLOW_GET_STATS = 0x00000010,
358 FLOW_GET_ACTIONS = 0x00000100,
361 typedef struct OvsFlowDumpInput {
363 uint32_t position[2]; /* Offset hint to the start of flow dump. */
364 /* 0 - index of the hash table.
365 * 1 - nth element in the hash table index. */
366 uint32_t getFlags; /* Information to get in addition to keys. */
371 typedef struct OvsFlowDumpOutput {
372 /* Hint for the next flow dump operation. */
373 uint32_t position[2];
375 /* #flows (currently 0 or 1). In case the buffer is too small to output all
376 * actions, this field indicates actual size needed to dump all actions. */
382 typedef struct OvsFlowGetInput {
385 uint32_t getFlags; /* Information to get in addition to keys. */
386 uint32_t actionsLen; /* Sizeof of buffer for actions. */
389 typedef struct OvsFlowGetOutput {
390 OvsFlowInfo info; /* Variable length. */
394 typedef enum OvsFlowPutFlags {
395 OVSWIN_FLOW_PUT_CREATE = 1 << 0,
396 OVSWIN_FLOW_PUT_MODIFY = 1 << 1,
397 OVSWIN_FLOW_PUT_DELETE = 1 << 2,
399 OVSWIN_FLOW_PUT_CLEAR = 1 << 3
403 typedef struct OvsFlowPut {
411 #define OVS_MIN_PACKET_SIZE 60
412 typedef struct _OVS_PACKET_INFO {
414 uint32_t userDataLen;
419 OvsIPv4TunnelKey tunnelKey;
421 /* Includes user data defined as chain of netlink attributes followed by the
424 } OVS_PACKET_INFO, *POVS_PACKET_INFO;
426 typedef struct OvsPacketExecute {
437 typedef struct _OVS_EVENT_SUBSCRIBE {
442 } OVS_EVENT_SUBSCRIBE, *POVS_EVENT_SUBSCRIBE;
444 typedef struct _OVS_EVENT_POLL {
447 } OVS_EVENT_POLL, *POVS_EVENT_POLL;
450 OVS_EVENT_CONNECT = ((uint32_t)0x1 << 0),
451 OVS_EVENT_DISCONNECT = ((uint32_t)0x1 << 1),
452 OVS_EVENT_LINK_UP = ((uint32_t)0x1 << 2),
453 OVS_EVENT_LINK_DOWN = ((uint32_t)0x1 << 3),
454 OVS_EVENT_MAC_CHANGE = ((uint32_t)0x1 << 4),
455 OVS_EVENT_MTU_CHANGE = ((uint32_t)0x1 << 5),
456 OVS_EVENT_MASK_ALL = 0x3f,
460 typedef struct _OVS_EVENT_ENTRY {
463 } OVS_EVENT_ENTRY, *POVS_EVENT_ENTRY;
465 #define OVS_DEFAULT_PORT_NO 0xffffffff
466 #define OVS_DEFAULT_EVENT_STATUS 0xffffffff
468 typedef struct _OVS_EVENT_STATUS {
469 uint32_t numberEntries;
470 OVS_EVENT_ENTRY eventEntries[0];
471 } OVS_EVENT_STATUS, *POVS_EVENT_STATUS;
475 #endif /* __OVS_PUB_H_ */