]>
Commit | Line | Data |
---|---|---|
c803536e SS |
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 | #include "precomp.h" | |
18 | #include "OvsSwitch.h" | |
19 | #include "OvsIoctl.h" | |
20 | ||
21 | #ifdef OVS_DBG_MOD | |
22 | #undef OVS_DBG_MOD | |
23 | #endif | |
24 | #define OVS_DBG_MOD OVS_DBG_DRIVER | |
25 | #include "OvsDebug.h" | |
26 | ||
27 | /* Global handles. XXX: Some of them need not be global. */ | |
28 | /* | |
29 | * Maps to DriverObject and FilterDriverContext parameters in the NDIS filter | |
30 | * driver functions. | |
31 | * DriverObject is specified by NDIS. | |
32 | * FilterDriverContext is specified by the filter driver. | |
33 | */ | |
34 | NDIS_HANDLE gOvsExtDriverObject; | |
35 | ||
36 | /* | |
37 | * Maps to NdisFilterHandle parameter in the NDIS filter driver functions. | |
38 | * NdisFilterHandle is returned by NDISFRegisterFilterDriver. | |
39 | */ | |
40 | NDIS_HANDLE gOvsExtDriverHandle; | |
41 | ||
42 | /* | |
43 | * Maps to FilterModuleContext parameter in the NDIS filter driver functions. | |
44 | * FilterModuleContext is a allocated by the driver in the FilterAttach | |
45 | * function. | |
46 | */ | |
47 | extern POVS_SWITCH_CONTEXT gOvsSwitchContext; | |
48 | ||
07ee9d1e | 49 | static PWCHAR ovsExtFriendlyName = L"Open vSwitch Extension"; |
c803536e SS |
50 | static PWCHAR ovsExtServiceName = L"OVSExt"; |
51 | NDIS_STRING ovsExtGuidUC; | |
52 | NDIS_STRING ovsExtFriendlyNameUC; | |
53 | ||
54 | static PWCHAR ovsExtGuidStr = L"{583CC151-73EC-4A6A-8B47-578297AD7623}"; | |
55 | static const GUID ovsExtGuid = { | |
56 | 0x583cc151, | |
57 | 0x73ec, | |
58 | 0x4a6a, | |
59 | {0x8b, 0x47, 0x57, 0x82, 0x97, 0xad, 0x76, 0x23} | |
60 | }; | |
61 | ||
62 | /* Declarations of callback functions for the filter driver. */ | |
63 | DRIVER_UNLOAD OvsExtUnload; | |
64 | FILTER_NET_PNP_EVENT OvsExtNetPnPEvent; | |
65 | FILTER_STATUS OvsExtStatus; | |
66 | ||
67 | FILTER_ATTACH OvsExtAttach; | |
68 | FILTER_DETACH OvsExtDetach; | |
69 | FILTER_RESTART OvsExtRestart; | |
70 | FILTER_PAUSE OvsExtPause; | |
71 | ||
72 | FILTER_SEND_NET_BUFFER_LISTS OvsExtSendNBL; | |
73 | FILTER_SEND_NET_BUFFER_LISTS_COMPLETE OvsExtSendNBLComplete; | |
74 | FILTER_CANCEL_SEND_NET_BUFFER_LISTS OvsExtCancelSendNBL; | |
75 | FILTER_RECEIVE_NET_BUFFER_LISTS OvsExtReceiveNBL; | |
76 | FILTER_RETURN_NET_BUFFER_LISTS OvsExtReturnNBL; | |
77 | ||
78 | FILTER_OID_REQUEST OvsExtOidRequest; | |
79 | FILTER_OID_REQUEST_COMPLETE OvsExtOidRequestComplete; | |
80 | FILTER_CANCEL_OID_REQUEST OvsExtCancelOidRequest; | |
81 | ||
82 | ||
83 | /* | |
84 | * -------------------------------------------------------------------------- | |
85 | * Init/Load function for the OVSEXT filter Driver. | |
86 | * -------------------------------------------------------------------------- | |
87 | */ | |
88 | NTSTATUS | |
89 | DriverEntry(PDRIVER_OBJECT driverObject, | |
90 | PUNICODE_STRING registryPath) | |
91 | { | |
92 | NDIS_STATUS status; | |
93 | NDIS_FILTER_DRIVER_CHARACTERISTICS driverChars; | |
94 | ||
95 | UNREFERENCED_PARAMETER(registryPath); | |
96 | ||
97 | gOvsExtDriverObject = driverObject; | |
98 | ||
99 | RtlZeroMemory(&driverChars, sizeof driverChars); | |
100 | driverChars.Header.Type = NDIS_OBJECT_TYPE_FILTER_DRIVER_CHARACTERISTICS; | |
101 | driverChars.Header.Size = sizeof driverChars; | |
102 | driverChars.Header.Revision = NDIS_FILTER_CHARACTERISTICS_REVISION_2; | |
103 | driverChars.MajorNdisVersion = NDIS_FILTER_MAJOR_VERSION; | |
104 | driverChars.MinorNdisVersion = NDIS_FILTER_MINOR_VERSION; | |
105 | driverChars.MajorDriverVersion = 1; | |
106 | driverChars.MinorDriverVersion = 0; | |
107 | driverChars.Flags = 0; | |
108 | ||
109 | RtlInitUnicodeString(&driverChars.ServiceName, ovsExtServiceName); | |
110 | RtlInitUnicodeString(&ovsExtFriendlyNameUC, ovsExtFriendlyName); | |
111 | RtlInitUnicodeString(&ovsExtGuidUC, ovsExtGuidStr); | |
112 | ||
113 | driverChars.FriendlyName = ovsExtFriendlyNameUC; | |
114 | driverChars.UniqueName = ovsExtGuidUC; | |
115 | ||
116 | driverChars.AttachHandler = OvsExtAttach; | |
117 | driverChars.DetachHandler = OvsExtDetach; | |
118 | driverChars.RestartHandler = OvsExtRestart; | |
119 | driverChars.PauseHandler = OvsExtPause; | |
120 | ||
121 | driverChars.SendNetBufferListsHandler = OvsExtSendNBL; | |
122 | driverChars.SendNetBufferListsCompleteHandler = OvsExtSendNBLComplete; | |
123 | driverChars.CancelSendNetBufferListsHandler = OvsExtCancelSendNBL; | |
124 | driverChars.ReceiveNetBufferListsHandler = NULL; | |
125 | driverChars.ReturnNetBufferListsHandler = NULL; | |
126 | ||
127 | driverChars.OidRequestHandler = OvsExtOidRequest; | |
128 | driverChars.OidRequestCompleteHandler = OvsExtOidRequestComplete; | |
129 | driverChars.CancelOidRequestHandler = OvsExtCancelOidRequest; | |
130 | ||
131 | driverChars.DevicePnPEventNotifyHandler = NULL; | |
132 | driverChars.NetPnPEventHandler = OvsExtNetPnPEvent; | |
133 | driverChars.StatusHandler = NULL; | |
134 | ||
135 | driverObject->DriverUnload = OvsExtUnload; | |
136 | ||
137 | status = NdisFRegisterFilterDriver(driverObject, | |
138 | (NDIS_HANDLE) gOvsExtDriverObject, | |
139 | &driverChars, &gOvsExtDriverHandle); | |
140 | if (status != NDIS_STATUS_SUCCESS) { | |
141 | return status; | |
142 | } | |
143 | ||
144 | /* Create the communication channel for usersapce. */ | |
145 | status = OvsCreateDeviceObject(gOvsExtDriverHandle); | |
146 | if (status != NDIS_STATUS_SUCCESS) { | |
147 | NdisFDeregisterFilterDriver(gOvsExtDriverHandle); | |
148 | gOvsExtDriverHandle = NULL; | |
149 | } | |
150 | ||
151 | return status; | |
152 | } | |
153 | ||
154 | ||
155 | /* | |
156 | * -------------------------------------------------------------------------- | |
157 | * Un-init/Unload function for the OVS intermediate Driver. | |
158 | * -------------------------------------------------------------------------- | |
159 | */ | |
160 | VOID | |
161 | OvsExtUnload(struct _DRIVER_OBJECT *driverObject) | |
162 | { | |
163 | UNREFERENCED_PARAMETER(driverObject); | |
164 | ||
165 | OvsDeleteDeviceObject(); | |
166 | NdisFDeregisterFilterDriver(gOvsExtDriverHandle); | |
167 | } | |
168 | ||
169 | ||
170 | /* | |
171 | * -------------------------------------------------------------------------- | |
172 | * Implements filter driver's FilterStatus function. | |
173 | * -------------------------------------------------------------------------- | |
174 | */ | |
175 | VOID | |
176 | OvsExtStatus(NDIS_HANDLE filterModuleContext, | |
177 | PNDIS_STATUS_INDICATION statusIndication) | |
178 | { | |
179 | UNREFERENCED_PARAMETER(statusIndication); | |
180 | POVS_SWITCH_CONTEXT switchObject = (POVS_SWITCH_CONTEXT)filterModuleContext; | |
181 | ||
182 | NdisFIndicateStatus(switchObject->NdisFilterHandle, statusIndication); | |
183 | return; | |
184 | } |