]> git.proxmox.com Git - mirror_ovs.git/blob - datapath-windows/ovsext/Conntrack.h
datapath-windows: Fix conntrack event handler
[mirror_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 UINT64 packetCount;
63 UINT64 byteCount;
64 } OVS_CT_KEY, *POVS_CT_KEY;
65
66 typedef struct OVS_CT_ENTRY {
67 OVS_CT_KEY key;
68 OVS_CT_KEY rev_key;
69 UINT64 expiration;
70 LIST_ENTRY link;
71 UINT32 mark;
72 UINT64 timestampStart;
73 struct ovs_key_ct_labels labels;
74 } OVS_CT_ENTRY, *POVS_CT_ENTRY;
75
76 typedef struct OvsConntrackKeyLookupCtx {
77 OVS_CT_KEY key;
78 POVS_CT_ENTRY entry;
79 UINT32 hash;
80 BOOLEAN reply;
81 BOOLEAN related;
82 } OvsConntrackKeyLookupCtx;
83
84 #define CT_HASH_TABLE_SIZE ((UINT32)1 << 10)
85 #define CT_HASH_TABLE_MASK (CT_HASH_TABLE_SIZE - 1)
86 #define CT_INTERVAL_SEC 10000000LL //1s
87 #define CT_ENTRY_TIMEOUT (2 * 60 * CT_INTERVAL_SEC) // 2m
88 #define CT_CLEANUP_INTERVAL (2 * 60 * CT_INTERVAL_SEC) // 2m
89
90
91 /* Given POINTER, the address of the given MEMBER in a STRUCT object, returns
92 the STRUCT object. */
93 #define CONTAINER_OF(POINTER, STRUCT, MEMBER) \
94 ((STRUCT *) (void *) ((char *) (POINTER) - \
95 offsetof (STRUCT, MEMBER)))
96
97 VOID OvsCleanupConntrack(VOID);
98 NTSTATUS OvsInitConntrack(POVS_SWITCH_CONTEXT context);
99
100 NDIS_STATUS OvsExecuteConntrackAction(PNET_BUFFER_LIST curNbl,
101 OVS_PACKET_HDR_INFO *layers,
102 OvsFlowKey *key,
103 const PNL_ATTR a);
104 BOOLEAN OvsConntrackValidateTcpPacket(const TCPHdr *tcp);
105 OVS_CT_ENTRY * OvsConntrackCreateTcpEntry(const TCPHdr *tcp,
106 PNET_BUFFER_LIST nbl,
107 UINT64 now);
108 NDIS_STATUS OvsCtMapTcpProtoInfoToNl(PNL_BUFFER nlBuf,
109 OVS_CT_ENTRY *conn_);
110 OVS_CT_ENTRY * OvsConntrackCreateOtherEntry(UINT64 now);
111 enum CT_UPDATE_RES OvsConntrackUpdateTcpEntry(OVS_CT_ENTRY* conn_,
112 const TCPHdr *tcp,
113 PNET_BUFFER_LIST nbl,
114 BOOLEAN reply,
115 UINT64 now);
116 enum ct_update_res OvsConntrackUpdateOtherEntry(OVS_CT_ENTRY *conn_,
117 BOOLEAN reply,
118 UINT64 now);
119 NTSTATUS
120 OvsCreateNlMsgFromCtEntry(POVS_CT_ENTRY entry,
121 PVOID outBuffer,
122 UINT32 outBufLen,
123 UINT8 eventType,
124 UINT32 nlmsgSeq,
125 UINT32 nlmsgPid,
126 UINT8 nfGenVersion,
127 UINT32 dpIfIndex);
128 #endif /* __OVS_CONNTRACK_H_ */