2 * Copyright (c) 2014 VMware, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
23 #if defined OVS_USE_NL_INTERFACE && OVS_USE_NL_INTERFACE == 0
29 #define __DATAPATH_H_ 1
32 * Structure of an error message sent as a reply from kernel.
34 typedef struct _OVS_MESSAGE_ERROR {
37 } OVS_MESSAGE_ERROR, *POVS_MESSAGE_ERROR;
40 * Device operations to tag netlink commands with. This is a bitmask since it
41 * is possible that a particular command can be invoked via different device
44 #define OVS_READ_DEV_OP (1 << 0)
45 #define OVS_WRITE_DEV_OP (1 << 1)
46 #define OVS_TRANSACTION_DEV_OP (1 << 2)
47 #define OVS_READ_EVENT_DEV_OP (1 << 3)
49 typedef struct _OVS_DEVICE_EXTENSION {
50 INT numberOpenInstance;
52 } OVS_DEVICE_EXTENSION, *POVS_DEVICE_EXTENSION;
55 * Private context for each handle on the device.
57 typedef struct _OVS_OPEN_INSTANCE {
59 PFILE_OBJECT fileObject;
65 * On platforms that support netlink natively, there's generally some form of
66 * serialization between concurrent calls to netlink sockets. However, OVS
67 * userspace guarantees that a given netlink handle is not concurrently used.
68 * Despite this, we do want to have some basic checks in the kernel to make
69 * sure that things don't break if there are concurrent calls.
71 * This is generally not an issue since kernel data structure access should
72 * be sychronized anyway. Only reason to have this safeguared is to protect
73 * the state in "state-aware" read calls which rely on previous state. This
74 * restriction might go away as the userspace code gets implemented.
79 POVS_MESSAGE ovsMsg; /* OVS message passed during dump start. */
80 UINT32 index[2]; /* markers to continue dump from. One or more
81 * of them may be used. Eg. in flow dump, the
82 * markers can store the row and the column
84 } dumpState; /* data to support dump commands. */
85 } OVS_OPEN_INSTANCE, *POVS_OPEN_INSTANCE;
87 NDIS_STATUS OvsCreateDeviceObject(NDIS_HANDLE ovsExtDriverHandle);
88 VOID OvsDeleteDeviceObject();
90 POVS_OPEN_INSTANCE OvsGetOpenInstance(PFILE_OBJECT fileObject,
93 NTSTATUS OvsCompleteIrpRequest(PIRP irp, ULONG_PTR infoPtr, NTSTATUS status);
95 VOID OvsAcquireCtrlLock();
96 VOID OvsReleaseCtrlLock();
98 /* XXX: Move this to netlink.[ch] eventually. */
99 VOID BuildReplyMsgFromMsgIn(POVS_MESSAGE msgIn, POVS_MESSAGE msgOut,
101 VOID BuildErrorMsg(POVS_MESSAGE msgIn, POVS_MESSAGE_ERROR msgOut,
105 * Utility structure and functions to collect in one place all the parameters
106 * passed during a call from userspace.
108 typedef struct _OVS_USER_PARAMS_CONTEXT {
109 PIRP irp; /* The IRP used for the userspace call. */
110 POVS_OPEN_INSTANCE ovsInstance; /* Private data of the device handle. */
111 UINT32 devOp; /* Device operation of the userspace call. */
112 POVS_MESSAGE ovsMsg; /* OVS message that userspace passed down. */
113 PVOID inputBuffer; /* Input data specified by userspace. Maybe NULL. */
114 UINT32 inputLength; /* Length of input buffer. */
115 PVOID outputBuffer; /* Output buffer specified by userspace for reading
116 * data. Maybe NULL. */
117 UINT32 outputLength; /* Length of output buffer. */
118 } OVS_USER_PARAMS_CONTEXT, *POVS_USER_PARAMS_CONTEXT;
121 InitUserParamsCtx(PIRP irp,
122 POVS_OPEN_INSTANCE ovsInstance,
129 POVS_USER_PARAMS_CONTEXT usrParamsCtx)
131 usrParamsCtx->irp = irp;
132 usrParamsCtx->ovsInstance = ovsInstance;
133 usrParamsCtx->devOp = devOp;
134 usrParamsCtx->ovsMsg = ovsMsg;
135 usrParamsCtx->inputBuffer = inputBuffer;
136 usrParamsCtx->inputLength = inputLength;
137 usrParamsCtx->outputBuffer = outputBuffer;
138 usrParamsCtx->outputLength = outputLength;
141 static __inline NTSTATUS
142 InitUserDumpState(POVS_OPEN_INSTANCE instance,
145 /* Clear the dumpState from a previous dump sequence. */
146 ASSERT(instance->dumpState.ovsMsg == NULL);
149 instance->dumpState.ovsMsg =
150 (POVS_MESSAGE) OvsAllocateMemory(sizeof (OVS_MESSAGE));
151 if (instance->dumpState.ovsMsg == NULL) {
152 return STATUS_NO_MEMORY;
154 RtlCopyMemory(instance->dumpState.ovsMsg, ovsMsg,
155 sizeof *instance->dumpState.ovsMsg);
156 RtlZeroMemory(instance->dumpState.index,
157 sizeof instance->dumpState.index);
159 return STATUS_SUCCESS;
163 FreeUserDumpState(POVS_OPEN_INSTANCE instance)
165 if (instance->dumpState.ovsMsg != NULL) {
166 OvsFreeMemory(instance->dumpState.ovsMsg);
167 RtlZeroMemory(&instance->dumpState, sizeof instance->dumpState);
171 NTSTATUS OvsSetupDumpStart(POVS_USER_PARAMS_CONTEXT usrParamsCtx);
173 #endif /* __DATAPATH_H_ */
175 #endif /* OVS_USE_NL_INTERFACE */