datapath-windows: Removed assert from FilterNetPnPEvent handler
[cascardo/ovs.git] / datapath-windows / ovsext / Datapath.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 /*
18  * XXX: OVS_USE_NL_INTERFACE is being used to keep the legacy DPIF interface
19  * alive while we transition over to the netlink based interface.
20  * OVS_USE_NL_INTERFACE = 0 => legacy inteface to use with dpif-windows.c
21  * OVS_USE_NL_INTERFACE = 1 => netlink inteface to use with ported dpif-linux.c
22  */
23
24 #ifndef __DATAPATH_H_
25 #define __DATAPATH_H_ 1
26
27 /*
28  * Device operations to tag netlink commands with. This is a bitmask since it
29  * is possible that a particular command can be invoked via different device
30  * operations.
31  */
32 #define OVS_READ_DEV_OP          (1 << 0)
33 #define OVS_WRITE_DEV_OP         (1 << 1)
34 #define OVS_TRANSACTION_DEV_OP   (1 << 2)
35 #define OVS_READ_EVENT_DEV_OP    (1 << 3)
36 #define OVS_READ_PACKET_DEV_OP   (1 << 4)
37
38 typedef struct _OVS_DEVICE_EXTENSION {
39     INT numberOpenInstance;
40     INT pidCount;
41 } OVS_DEVICE_EXTENSION, *POVS_DEVICE_EXTENSION;
42
43 // forward declaration
44 typedef struct _OVS_USER_PACKET_QUEUE OVS_USER_PACKET_QUEUE,
45                                       *POVS_USER_PACKET_QUEUE;
46
47 /*
48  * Private context for each handle on the device.
49  */
50 typedef struct _OVS_OPEN_INSTANCE {
51     UINT32 cookie;
52     PFILE_OBJECT fileObject;
53     PVOID eventQueue;
54     POVS_USER_PACKET_QUEUE packetQueue;
55     UINT32 pid;
56
57     /*
58      * On platforms that support netlink natively, there's generally some form of
59      * serialization between concurrent calls to netlink sockets. However, OVS
60      * userspace guarantees that a given netlink handle is not concurrently used.
61      * Despite this, we do want to have some basic checks in the kernel to make
62      * sure that things don't break if there are concurrent calls.
63      *
64      * This is generally not an issue since kernel data structure access should
65      * be sychronized anyway. Only reason to have this safeguared is to protect
66      * the state in "state-aware" read calls which rely on previous state. This
67      * restriction might go away as the userspace code gets implemented.
68      */
69      INT inUse;
70
71     struct {
72         POVS_MESSAGE ovsMsg;    /* OVS message passed during dump start. */
73         UINT32 index[2];        /* markers to continue dump from. One or more
74                                  * of them may be used. Eg. in flow dump, the
75                                  * markers can store the row and the column
76                                  * indices. */
77     } dumpState;                /* data to support dump commands. */
78     LIST_ENTRY             pidLink; /* Links the instance to
79                                      * pidHashArray */
80 } OVS_OPEN_INSTANCE, *POVS_OPEN_INSTANCE;
81
82 NDIS_STATUS OvsCreateDeviceObject(NDIS_HANDLE ovsExtDriverHandle);
83 VOID OvsDeleteDeviceObject();
84 VOID OvsInit();
85 VOID OvsCleanup();
86
87 POVS_OPEN_INSTANCE OvsGetOpenInstance(PFILE_OBJECT fileObject,
88                                       UINT32 dpNo);
89
90 NTSTATUS OvsCompleteIrpRequest(PIRP irp, ULONG_PTR infoPtr, NTSTATUS status);
91
92 VOID OvsAcquireCtrlLock();
93 VOID OvsReleaseCtrlLock();
94
95 /*
96  * Utility structure and functions to collect in one place all the parameters
97  * passed during a call from userspace.
98  */
99 typedef struct _OVS_USER_PARAMS_CONTEXT {
100     PIRP irp;            /* The IRP used for the userspace call. */
101     POVS_OPEN_INSTANCE ovsInstance; /* Private data of the device handle. */
102     UINT32 devOp;        /* Device operation of the userspace call. */
103     POVS_MESSAGE ovsMsg; /* OVS message that userspace passed down. */
104     PVOID inputBuffer;   /* Input data specified by userspace. Maybe NULL. */
105     UINT32 inputLength;  /* Length of input buffer. */
106     PVOID outputBuffer;  /* Output buffer specified by userspace for reading
107                           * data. Maybe NULL. */
108     UINT32 outputLength; /* Length of output buffer. */
109 } OVS_USER_PARAMS_CONTEXT, *POVS_USER_PARAMS_CONTEXT;
110
111 static __inline VOID
112 InitUserParamsCtx(PIRP irp,
113                   POVS_OPEN_INSTANCE ovsInstance,
114                   UINT32 devOp,
115                   POVS_MESSAGE ovsMsg,
116                   PVOID inputBuffer,
117                   UINT32 inputLength,
118                   PVOID outputBuffer,
119                   UINT32 outputLength,
120                   POVS_USER_PARAMS_CONTEXT usrParamsCtx)
121 {
122     usrParamsCtx->irp = irp;
123     usrParamsCtx->ovsInstance = ovsInstance;
124     usrParamsCtx->devOp = devOp;
125     usrParamsCtx->ovsMsg = ovsMsg;
126     usrParamsCtx->inputBuffer = inputBuffer;
127     usrParamsCtx->inputLength = inputLength;
128     usrParamsCtx->outputBuffer = outputBuffer;
129     usrParamsCtx->outputLength = outputLength;
130 }
131
132 NTSTATUS InitUserDumpState(POVS_OPEN_INSTANCE instance,
133                            POVS_MESSAGE ovsMsg);
134
135 VOID FreeUserDumpState(POVS_OPEN_INSTANCE instance);
136
137 NTSTATUS OvsSetupDumpStart(POVS_USER_PARAMS_CONTEXT usrParamsCtx);
138
139 #endif /* __DATAPATH_H_ */