datapath-windows: Increase the maximum size of port name.
[cascardo/ovs.git] / datapath-windows / include / OvsPub.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 __OVS_PUB_H_
18 #define __OVS_PUB_H_ 1
19
20 #include <netioapi.h>
21 #define IFNAMSIZ IF_NAMESIZE
22 #include "../ovsext/Netlink/Netlink.h"
23
24 #define OVS_DRIVER_MAJOR_VER 1
25 #define OVS_DRIVER_MINOR_VER 0
26
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
31
32 #define IFF_RUNNING 0x20
33 #define IFF_PROMISC 0x40
34
35 #define OVS_MAX_OPAQUE_NETWORK_ID_LEN 128
36
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")
40
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)
50
51
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)
65
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)
71
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)
76
77
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)
85
86
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)
100
101
102
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)
110
111
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)
115
116 typedef __declspec(align(8)) uint64_t Ovs64AlignedU64;
117 typedef __declspec(align(8)) ovs_be64 Ovs64AlignedBe64;
118 #pragma pack(push, 1)
119
120
121 typedef struct _OVS_DP_INFO {
122     char name[128];
123     uint32_t dpNo;
124     uint32_t queue;
125     Ovs64AlignedU64 nHit;
126     Ovs64AlignedU64 nMissed;
127     Ovs64AlignedU64 nLost;
128     Ovs64AlignedU64 nFlows;
129 } OVS_DP_INFO, *POVS_DP_INFO;
130
131
132 typedef struct _OVS_VERSION {
133     uint8_t mjrDrvVer;
134     uint8_t mnrDrvVer;
135 } OVS_VERSION, *POVS_VERSION;
136
137 #define OVS_MAX_PORT_NAME_LENGTH IFNAMSIZ
138
139 typedef struct _OVS_VPORT_GET {
140     uint32_t dpNo;
141     uint32_t portNo;
142     char     name[OVS_MAX_PORT_NAME_LENGTH];
143 } OVS_VPORT_GET, *POVS_VPORT_GET;
144
145 static __inline const char *
146 OvsVportTypeToStr(OVS_VPORT_TYPE t)
147 {
148     switch(t) {
149 #define STR(t) case OVS_VPORT_TYPE_##t : return "VPORT_##t";
150     STR(UNSPEC)
151     STR(NETDEV)
152     STR(INTERNAL)
153     STR(GRE)
154     STR(GRE64)
155     STR(VXLAN)
156     STR(GENEVE)
157     STR(LISP)
158     }
159 #undef STR
160
161     return "Invalid type";
162 }
163
164 #define MAC_ADDRESS_LEN 6
165
166 typedef struct _OVS_VPORT_INFO {
167     uint32_t dpNo;
168     uint32_t portNo;
169     char name[OVS_MAX_PORT_NAME_LENGTH];
170     uint32_t type;
171     uint32_t queue;
172
173     Ovs64AlignedU64 rxPackets;
174     Ovs64AlignedU64 txPackets;
175     Ovs64AlignedU64 rxBytes;
176     Ovs64AlignedU64 txBytes;
177     Ovs64AlignedU64 rxErrors;
178     Ovs64AlignedU64 txErrors;
179     Ovs64AlignedU64 rxDropped;
180     Ovs64AlignedU64 txDropped;
181
182     uint8_t macAddress[MAC_ADDRESS_LEN];
183     uint16_t pad;
184 } OVS_VPORT_INFO, *POVS_VPORT_INFO;
185
186 typedef struct _OVS_VPORT_ADD_REQUEST {
187     uint32_t dpNo;
188     uint32_t type;
189     char name[OVS_MAX_PORT_NAME_LENGTH];
190     uint16_t dstPort;
191     uint16_t pad[3];
192 } OVS_VPORT_ADD_REQUEST, *POVS_VPORT_ADD_REQUEST;
193
194
195 typedef struct _OVS_VPORT_DELETE_REQUEST {
196     uint32_t dpNo;
197     uint32_t portNo;
198     char name[OVS_MAX_PORT_NAME_LENGTH];
199 } OVS_VPORT_DELETE_REQUEST, *POVS_VPORT_DELETE_REQUEST;
200
201
202 #define OVS_MAX_VM_UUID_LEN 128
203 #define OVS_MAX_VIF_UUID_LEN 128
204
205 typedef struct _OVS_VPORT_EXT_INFO {
206     uint32_t dpNo;
207     uint32_t portNo;
208     uint8_t macAddress[MAC_ADDRESS_LEN];
209     uint8_t permMACAddress[MAC_ADDRESS_LEN];
210     uint8_t vmMACAddress[MAC_ADDRESS_LEN];
211     uint16_t nicIndex;
212     uint32_t portId;
213     uint32_t type;
214     uint32_t mtu;
215     char name[OVS_MAX_PORT_NAME_LENGTH];
216     uint32_t status;
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;
220
221
222 /* Flows. */
223 #define OVSWIN_VLAN_CFI 0x1000
224 #define OVSWIN_INPORT_INVALID 0xffffffff
225
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
229
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
233                                          * offset. */
234 #define OVSWIN_NW_FRAG_MASK  (OVSWIN_NW_FRAG_ANY | OVSWIN_NW_FRAG_LATER)
235
236 typedef struct L4Key {
237     ovs_be16 tpSrc;              /* TCP/UDP/SCTP source port. */
238     ovs_be16 tpDst;              /* TCP/UDP/SCTP destination port. */
239 } L4Key;
240
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. */
248     L4Key   l4;
249 } IpKey;  /* Size of 16 byte. */
250
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. */
257     uint8_t pad[3];
258 } ArpKey; /* Size of 24 byte. */
259
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. */
268     L4Key  l4;
269     uint32_t pad;
270 } Ipv6Key;  /* Size of 48 byte. */
271
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. */
280     L4Key  l4;
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. */
285
286 typedef struct L2Key {
287     uint32_t inPort;             /* Port number of input port. */
288     union {
289         struct {
290             uint16_t offset;
291             uint16_t keyLen;
292         };
293         uint32_t val;
294     };
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. */
300
301 /* Number of packet attributes required to store OVS tunnel key. */
302 #define NUM_PKT_ATTR_REQUIRED 3
303
304 typedef union OvsIPv4TunnelKey {
305     struct {
306         ovs_be32 dst;
307         ovs_be32 src;
308         ovs_be64 tunnelId;
309         uint16_t flags;
310         uint8_t  tos;
311         uint8_t  ttl;
312         union {
313             uint32_t pad;
314             struct {
315                 ovs_be16 dst_port;
316                 uint16_t flow_hash;
317             };
318         };
319     };
320     uint64_t attr[NUM_PKT_ATTR_REQUIRED];
321 } OvsIPv4TunnelKey;
322
323 typedef __declspec(align(8)) struct OvsFlowKey {
324     OvsIPv4TunnelKey tunKey;     /* 24 bytes */
325     L2Key l2;                    /* 24 bytes */
326     union {
327         IpKey ipKey;             /* size 16 */
328         ArpKey arpKey;           /* size 24 */
329         Ipv6Key ipv6Key;         /* size 48 */
330         Icmp6Key icmp6Key;       /* size 72 */
331     };
332 } OvsFlowKey;
333
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))
340
341 typedef struct OvsFlowStats {
342     Ovs64AlignedU64 packetCount;
343     Ovs64AlignedU64 byteCount;
344     uint32_t used;
345     uint8_t tcpFlags;
346 } OvsFlowStats;
347
348 typedef struct OvsFlowInfo {
349     OvsFlowKey key;
350     struct OvsFlowStats stats;
351     uint32_t actionsLen;
352     PNL_ATTR actions;
353 } OvsFlowInfo;
354
355 enum GetFlags {
356     FLOW_GET_KEY =       0x00000001,
357     FLOW_GET_STATS =     0x00000010,
358     FLOW_GET_ACTIONS =   0x00000100,
359 };
360
361 typedef struct OvsFlowDumpInput {
362     uint32_t dpNo;
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. */
367     uint32_t actionsLen;
368 } OvsFlowDumpInput;
369
370
371 typedef struct OvsFlowDumpOutput {
372     /* Hint for the next flow dump operation. */
373     uint32_t position[2];
374
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. */
377     uint32_t n;
378
379     OvsFlowInfo flow;
380 } OvsFlowDumpOutput;
381
382 typedef struct OvsFlowGetInput {
383     uint32_t dpNo;
384     OvsFlowKey key;
385     uint32_t getFlags;           /* Information to get in addition to keys. */
386     uint32_t actionsLen;         /* Sizeof of buffer for actions. */
387 } OvsFlowGetInput;
388
389 typedef struct OvsFlowGetOutput {
390     OvsFlowInfo info;            /* Variable length. */
391 } OvsFlowGetOutput;
392
393
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,
398
399     OVSWIN_FLOW_PUT_CLEAR = 1 << 3
400 } OvsFlowPutFlags;
401
402
403 typedef struct OvsFlowPut {
404     uint32_t dpNo;
405     uint32_t actionsLen;
406     OvsFlowKey key;
407     uint32_t flags;
408     PNL_ATTR  actions;
409 } OvsFlowPut;
410
411 #define OVS_MIN_PACKET_SIZE 60
412 typedef struct _OVS_PACKET_INFO {
413     uint32_t totalLen;
414     uint32_t userDataLen;
415     uint32_t packetLen;
416     uint32_t queue;
417     uint32_t inPort;
418     uint32_t cmd;
419     OvsIPv4TunnelKey tunnelKey;
420     uint8_t *payload;
421     /* Includes user data defined as chain of netlink attributes followed by the
422      * packet data. */
423     uint8_t  data[0];
424 } OVS_PACKET_INFO, *POVS_PACKET_INFO;
425
426 typedef struct OvsPacketExecute {
427    uint32_t dpNo;
428    uint32_t inPort;
429
430    uint32_t packetLen;
431    uint32_t actionsLen;
432    PCHAR packetBuf;
433    PNL_ATTR actions;
434 } OvsPacketExecute;
435
436
437 typedef struct _OVS_EVENT_SUBSCRIBE {
438     uint32_t cookie;
439     uint32_t dpNo;
440     uint32_t subscribe;
441     uint32_t mask;
442 } OVS_EVENT_SUBSCRIBE, *POVS_EVENT_SUBSCRIBE;
443
444 typedef struct _OVS_EVENT_POLL {
445     uint32_t cookie;
446     uint32_t dpNo;
447 } OVS_EVENT_POLL, *POVS_EVENT_POLL;
448
449 enum {
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,
457 };
458
459
460 typedef struct _OVS_EVENT_ENTRY {
461     uint32_t portNo;
462     uint32_t status;
463 } OVS_EVENT_ENTRY, *POVS_EVENT_ENTRY;
464
465 #define OVS_DEFAULT_PORT_NO 0xffffffff
466 #define OVS_DEFAULT_EVENT_STATUS  0xffffffff
467
468 typedef struct _OVS_EVENT_STATUS {
469     uint32_t numberEntries;
470     OVS_EVENT_ENTRY eventEntries[0];
471 } OVS_EVENT_STATUS, *POVS_EVENT_STATUS;
472
473 #pragma pack(pop)
474
475 #endif /* __OVS_PUB_H_ */