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