datapath-windows: Refactor Conntrack Module in Hyper-V
[cascardo/ovs.git] / datapath-windows / ovsext / Conntrack.h
1 /*
2  * Copyright (c) 2015, 2016 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_CONNTRACK_H_
18 #define __OVS_CONNTRACK_H_ 1
19
20 #include "precomp.h"
21 #include "Flow.h"
22
23 struct ct_addr {
24     union {
25         ovs_be32 ipv4;
26         struct in6_addr ipv6;
27         uint32_t ipv4_aligned;
28         struct in6_addr ipv6_aligned;
29     };
30 };
31
32 struct ct_endpoint {
33     struct ct_addr addr;
34     ovs_be16 port;
35     UINT16 pad;
36 };
37
38 typedef enum CT_UPDATE_RES {
39     CT_UPDATE_INVALID,
40     CT_UPDATE_VALID,
41     CT_UPDATE_NEW,
42 } CT_UPDATE_RES;
43
44 /* Metadata mark for masked write to conntrack mark */
45 typedef struct MD_MARK {
46     UINT32 value;
47     UINT32 mask;
48 } MD_MARK;
49
50 /* Metadata label for masked write to conntrack label. */
51 typedef struct MD_LABELS {
52     struct ovs_key_ct_labels value;
53     struct ovs_key_ct_labels mask;
54 } MD_LABELS;
55
56 typedef struct _OVS_CT_KEY {
57     struct ct_endpoint src;
58     struct ct_endpoint dst;
59     UINT16 dl_type;
60     UINT8 nw_proto;
61     UINT16 zone;
62 } OVS_CT_KEY, *POVS_CT_KEY;
63
64 typedef struct OVS_CT_ENTRY {
65     OVS_CT_KEY  key;
66     OVS_CT_KEY  rev_key;
67     UINT64      expiration;
68     LIST_ENTRY  link;
69     UINT32      mark;
70     struct ovs_key_ct_labels labels;
71 } OVS_CT_ENTRY, *POVS_CT_ENTRY;
72
73 typedef struct OvsConntrackKeyLookupCtx {
74     OVS_CT_KEY      key;
75     POVS_CT_ENTRY   entry;
76     UINT32          hash;
77     BOOLEAN         reply;
78     BOOLEAN         related;
79 } OvsConntrackKeyLookupCtx;
80
81 #define CT_HASH_TABLE_SIZE ((UINT32)1 << 10)
82 #define CT_HASH_TABLE_MASK (CT_HASH_TABLE_SIZE - 1)
83 #define CT_ENTRY_TIMEOUT (2 * 600000000)   // 2m
84 #define CT_CLEANUP_INTERVAL (2 * 600000000) // 2m
85 /* Given POINTER, the address of the given MEMBER in a STRUCT object, returns
86    the STRUCT object. */
87 #define CONTAINER_OF(POINTER, STRUCT, MEMBER)                           \
88         ((STRUCT *) (void *) ((char *) (POINTER) - \
89          offsetof (STRUCT, MEMBER)))
90
91 VOID OvsCleanupConntrack(VOID);
92 NTSTATUS OvsInitConntrack(POVS_SWITCH_CONTEXT context);
93
94 NDIS_STATUS OvsExecuteConntrackAction(PNET_BUFFER_LIST curNbl,
95                                       OVS_PACKET_HDR_INFO *layers,
96                                       OvsFlowKey *key,
97                                       const PNL_ATTR a);
98 BOOLEAN OvsConntrackValidateTcpPacket(const TCPHdr *tcp);
99 OVS_CT_ENTRY * OvsConntrackCreateTcpEntry(const TCPHdr *tcp,
100                                           PNET_BUFFER_LIST nbl,
101                                           UINT64 now);
102 enum CT_UPDATE_RES OvsConntrackUpdateTcpEntry(OVS_CT_ENTRY* conn_,
103                                               const TCPHdr *tcp,
104                                               PNET_BUFFER_LIST nbl,
105                                               BOOLEAN reply,
106                                               UINT64 now);
107 #endif /* __OVS_CONNTRACK_H_ */