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
25 #define __DATAPATH_H_ 1
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
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)
38 typedef struct _OVS_DEVICE_EXTENSION {
39 INT numberOpenInstance;
41 } OVS_DEVICE_EXTENSION, *POVS_DEVICE_EXTENSION;
43 // forward declaration
44 typedef struct _OVS_USER_PACKET_QUEUE OVS_USER_PACKET_QUEUE,
45 *POVS_USER_PACKET_QUEUE;
48 * Private context for each handle on the device.
50 typedef struct _OVS_OPEN_INSTANCE {
52 PFILE_OBJECT fileObject;
54 POVS_USER_PACKET_QUEUE packetQueue;
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.
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.
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
77 } dumpState; /* data to support dump commands. */
78 LIST_ENTRY pidLink; /* Links the instance to
80 } OVS_OPEN_INSTANCE, *POVS_OPEN_INSTANCE;
82 NDIS_STATUS OvsCreateDeviceObject(NDIS_HANDLE ovsExtDriverHandle);
83 VOID OvsDeleteDeviceObject();
87 POVS_OPEN_INSTANCE OvsGetOpenInstance(PFILE_OBJECT fileObject,
90 NTSTATUS OvsCompleteIrpRequest(PIRP irp, ULONG_PTR infoPtr, NTSTATUS status);
92 VOID OvsAcquireCtrlLock();
93 VOID OvsReleaseCtrlLock();
96 * Utility structure and functions to collect in one place all the parameters
97 * passed during a call from userspace.
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;
112 InitUserParamsCtx(PIRP irp,
113 POVS_OPEN_INSTANCE ovsInstance,
120 POVS_USER_PARAMS_CONTEXT usrParamsCtx)
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;
132 NTSTATUS InitUserDumpState(POVS_OPEN_INSTANCE instance,
133 POVS_MESSAGE ovsMsg);
135 VOID FreeUserDumpState(POVS_OPEN_INSTANCE instance);
137 NTSTATUS OvsSetupDumpStart(POVS_USER_PARAMS_CONTEXT usrParamsCtx);
139 #endif /* __DATAPATH_H_ */