datapath-windows: Support attribute OVS_KEY_ATTR_TCP_FLAGS
[cascardo/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 typedef struct L4Key {
66     ovs_be16 tpSrc;              /* TCP/UDP/SCTP source port. */
67     ovs_be16 tpDst;              /* TCP/UDP/SCTP destination port. */
68     ovs_be16 flags;              /* TCP flags */
69     uint8_t  pad[2];
70 } L4Key;
71
72 typedef struct Ipkey {
73     ovs_be32 nwSrc;              /* IPv4 source address. */
74     ovs_be32 nwDst;              /* IPv4 destination address. */
75     uint8_t nwProto;             /* IP protocol or low 8 bits of ARP opcode. */
76     uint8_t nwTos;               /* IP ToS (including DSCP and ECN). */
77     uint8_t nwTtl;               /* IP TTL/Hop Limit. */
78     uint8_t nwFrag;              /* FLOW_FRAG_* flags. */
79     L4Key   l4;
80 } IpKey;  /* Size of 20 byte. */
81
82 typedef struct ArpKey {
83     ovs_be32 nwSrc;              /* IPv4 source address. */
84     ovs_be32 nwDst;              /* IPv4 destination address. */
85     uint8_t arpSha[6];           /* ARP/ND source hardware address. */
86     uint8_t arpTha[6];           /* ARP/ND target hardware address. */
87     uint8_t nwProto;             /* IP protocol or low 8 bits of ARP opcode. */
88     uint8_t pad[3];
89 } ArpKey; /* Size of 24 byte. */
90
91 typedef struct Ipv6Key {
92     struct in6_addr ipv6Src;     /* IPv6 source address. */
93     struct in6_addr ipv6Dst;     /* IPv6 destination address. */
94     ovs_be32 ipv6Label;          /* IPv6 flow label. */
95     uint8_t nwProto;             /* IP protocol or low 8 bits of ARP opcode. */
96     uint8_t nwTos;               /* IP ToS (including DSCP and ECN). */
97     uint8_t nwTtl;               /* IP TTL/Hop Limit. */
98     uint8_t nwFrag;              /* FLOW_FRAG_* flags. */
99     L4Key  l4;
100 } Ipv6Key;  /* Size of 48 byte. */
101
102 typedef struct Icmp6Key {
103     struct in6_addr ipv6Src;     /* IPv6 source address. */
104     struct in6_addr ipv6Dst;     /* IPv6 destination address. */
105     ovs_be32 ipv6Label;          /* IPv6 flow label. */
106     uint8_t nwProto;             /* IP protocol or low 8 bits of ARP opcode. */
107     uint8_t nwTos;               /* IP ToS (including DSCP and ECN). */
108     uint8_t nwTtl;               /* IP TTL/Hop Limit. */
109     uint8_t nwFrag;              /* FLOW_FRAG_* flags. */
110     L4Key  l4;
111     uint8_t arpSha[6];           /* ARP/ND source hardware address. */
112     uint8_t arpTha[6];           /* ARP/ND target hardware address. */
113     struct in6_addr ndTarget;    /* IPv6 neighbor discovery (ND) target. */
114 } Icmp6Key; /* Size of 76 byte. */
115
116 typedef struct L2Key {
117     uint32_t inPort;             /* Port number of input port. */
118     union {
119         struct {
120             uint16_t offset;
121             uint16_t keyLen;
122         };
123         uint32_t val;
124     };
125     uint8_t dlSrc[6];            /* Ethernet source address. */
126     uint8_t dlDst[6];            /* Ethernet destination address. */
127     ovs_be16 vlanTci;            /* If 802.1Q, TCI | VLAN_CFI; otherwise 0. */
128     ovs_be16 dlType;             /* Ethernet frame type. */
129 } L2Key;  /* Size of 24 byte. */
130
131 /* Number of packet attributes required to store OVS tunnel key. */
132 #define NUM_PKT_ATTR_REQUIRED 3
133
134 typedef union OvsIPv4TunnelKey {
135     struct {
136         ovs_be32 dst;
137         ovs_be32 src;
138         ovs_be64 tunnelId;
139         uint16_t flags;
140         uint8_t  tos;
141         uint8_t  ttl;
142         union {
143             uint32_t pad;
144             struct {
145                 ovs_be16 dst_port;
146                 uint16_t flow_hash;
147             };
148         };
149     };
150     uint64_t attr[NUM_PKT_ATTR_REQUIRED];
151 } OvsIPv4TunnelKey;
152
153 typedef __declspec(align(8)) struct OvsFlowKey {
154     OvsIPv4TunnelKey tunKey;     /* 24 bytes */
155     L2Key l2;                    /* 24 bytes */
156     union {
157         IpKey ipKey;             /* size 16 */
158         ArpKey arpKey;           /* size 24 */
159         Ipv6Key ipv6Key;         /* size 48 */
160         Icmp6Key icmp6Key;       /* size 72 */
161     };
162 } OvsFlowKey;
163
164 #define OVS_WIN_TUNNEL_KEY_SIZE (sizeof (OvsIPv4TunnelKey))
165 #define OVS_L2_KEY_SIZE (sizeof (L2Key))
166 #define OVS_IP_KEY_SIZE (sizeof (IpKey))
167 #define OVS_IPV6_KEY_SIZE (sizeof (Ipv6Key))
168 #define OVS_ARP_KEY_SIZE (sizeof (ArpKey))
169 #define OVS_ICMPV6_KEY_SIZE (sizeof (Icmp6Key))
170
171 typedef struct OvsFlowStats {
172     Ovs64AlignedU64 packetCount;
173     Ovs64AlignedU64 byteCount;
174     uint32_t used;
175     uint8_t tcpFlags;
176 } OvsFlowStats;
177
178 typedef struct OvsFlowInfo {
179     OvsFlowKey key;
180     struct OvsFlowStats stats;
181     uint32_t actionsLen;
182     PNL_ATTR actions;
183 } OvsFlowInfo;
184
185 enum GetFlags {
186     FLOW_GET_KEY =       0x00000001,
187     FLOW_GET_STATS =     0x00000010,
188     FLOW_GET_ACTIONS =   0x00000100,
189 };
190
191 typedef struct OvsFlowDumpInput {
192     uint32_t dpNo;
193     uint32_t position[2];   /* Offset hint to the start of flow dump. */
194                             /* 0 - index of the hash table.
195                              * 1 - nth element in the hash table index. */
196     uint32_t getFlags;      /* Information to get in addition to keys. */
197     uint32_t actionsLen;
198 } OvsFlowDumpInput;
199
200
201 typedef struct OvsFlowDumpOutput {
202     /* Hint for the next flow dump operation. */
203     uint32_t position[2];
204
205     /* #flows (currently 0 or 1). In case the buffer is too small to output all
206      * actions, this field indicates actual size needed to dump all actions. */
207     uint32_t n;
208
209     OvsFlowInfo flow;
210 } OvsFlowDumpOutput;
211
212 typedef struct OvsFlowGetInput {
213     uint32_t dpNo;
214     OvsFlowKey key;
215     uint32_t getFlags;           /* Information to get in addition to keys. */
216     uint32_t actionsLen;         /* Sizeof of buffer for actions. */
217 } OvsFlowGetInput;
218
219 typedef struct OvsFlowGetOutput {
220     OvsFlowInfo info;            /* Variable length. */
221 } OvsFlowGetOutput;
222
223
224 typedef enum OvsFlowPutFlags {
225     OVSWIN_FLOW_PUT_CREATE = 1 << 0,
226     OVSWIN_FLOW_PUT_MODIFY = 1 << 1,
227     OVSWIN_FLOW_PUT_DELETE = 1 << 2,
228
229     OVSWIN_FLOW_PUT_CLEAR = 1 << 3
230 } OvsFlowPutFlags;
231
232
233 typedef struct OvsFlowPut {
234     uint32_t dpNo;
235     uint32_t actionsLen;
236     OvsFlowKey key;
237     uint32_t flags;
238     PNL_ATTR  actions;
239 } OvsFlowPut;
240
241 #define OVS_MIN_PACKET_SIZE 60
242 typedef struct _OVS_PACKET_INFO {
243     uint32_t totalLen;
244     uint32_t userDataLen;
245     uint32_t packetLen;
246     uint32_t queue;
247     uint32_t inPort;
248     uint32_t cmd;
249     OvsIPv4TunnelKey tunnelKey;
250     uint8_t *payload;
251     /* Includes user data defined as chain of netlink attributes followed by the
252      * packet data. */
253     uint8_t  data[0];
254 } OVS_PACKET_INFO, *POVS_PACKET_INFO;
255
256 typedef struct OvsPacketExecute {
257    uint32_t dpNo;
258    uint32_t inPort;
259
260    uint32_t packetLen;
261    uint32_t actionsLen;
262    PCHAR packetBuf;
263    PNL_ATTR actions;
264 } OvsPacketExecute;
265
266
267 typedef struct _OVS_EVENT_SUBSCRIBE {
268     uint32_t cookie;
269     uint32_t dpNo;
270     uint32_t subscribe;
271     uint32_t mask;
272 } OVS_EVENT_SUBSCRIBE, *POVS_EVENT_SUBSCRIBE;
273
274 typedef struct _OVS_EVENT_POLL {
275     uint32_t cookie;
276     uint32_t dpNo;
277 } OVS_EVENT_POLL, *POVS_EVENT_POLL;
278
279 enum {
280     OVS_EVENT_CONNECT       = ((uint32_t)0x1 << 0),
281     OVS_EVENT_DISCONNECT    = ((uint32_t)0x1 << 1),
282     OVS_EVENT_LINK_UP       = ((uint32_t)0x1 << 2),
283     OVS_EVENT_LINK_DOWN     = ((uint32_t)0x1 << 3),
284     OVS_EVENT_MAC_CHANGE    = ((uint32_t)0x1 << 4),
285     OVS_EVENT_MTU_CHANGE    = ((uint32_t)0x1 << 5),
286     OVS_EVENT_MASK_ALL      = 0x3f,
287 };
288
289
290 typedef struct _OVS_EVENT_ENTRY {
291     uint32_t portNo;
292     uint32_t status;
293 } OVS_EVENT_ENTRY, *POVS_EVENT_ENTRY;
294
295 #define OVS_DEFAULT_PORT_NO 0xffffffff
296 #define OVS_DEFAULT_EVENT_STATUS  0xffffffff
297
298 typedef struct _OVS_EVENT_STATUS {
299     uint32_t numberEntries;
300     OVS_EVENT_ENTRY eventEntries[0];
301 } OVS_EVENT_STATUS, *POVS_EVENT_STATUS;
302
303 #pragma pack(pop)
304
305 #endif /* __DP_INTERNAL_H_ */