aboutsummaryrefslogtreecommitdiffstats
path: root/wintun.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2020-10-30api: log out-of-memory errors tooSimon Rozman3-36/+24
It's not likely the write to log will succeed in low memory condition thou. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: remove dead codeSimon Rozman2-14/+0
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: added missing allocation-failure checkSimon Rozman1-0/+2
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: stop double error status reportingSimon Rozman5-46/+46
When an internal function logs an error and its cause, it bloats the log when the caller logs the cause again. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: internal reorganizationSimon Rozman12-444/+424
Gather adapter management in adapter.h/.c (formerly devmgmt.h/.c) and unify HwID tests. Use "Namespace" namespace in all functions from namespace.h/.c. Fix char strings in LOG_... Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: simplify logger macros namesSimon Rozman6-143/+143
WINTUN_LOGGER_... => LOGGER_... => LOG_... Those macros are internal, so they don/t need to start with WINTUN_... Replacing the noun LOGGER_... with the verb LOG_... makes the code more natural to read now. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: implement driver version extraction from .inf fileSimon Rozman2-23/+175
With installer.dll the installer did the decision whether to install or upgrade the driver according to installer.dll version and hash stored in registry by MSM. With wintun.dll we need to know, which version of Wintun driver we are packing in the resources to decide about driver upgrade. The most accurate source of the driver version is the DriverVer directive in [Version] section of the driver's .inf file. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: disable driver management for wintun.dll that don't have a driverSimon Rozman2-96/+102
Namely the 32-bit ARM platform, which we will ship wintun.dll for ARM on ARM64 clients exclusively. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: unify and document resource loadingSimon Rozman3-30/+54
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: unify hardware ID stringSimon Rozman3-10/+6
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: unify callback function type namesSimon Rozman2-3/+3
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: add driver managementSimon Rozman9-15/+676
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: introduce loggingSimon Rozman12-217/+502
And other unifications with installer before merging. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: split api.hSimon Rozman8-116/+172
As the project grew, api.h got bloated. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: revise str/memcpySimon Rozman1-3/+3
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: make adapter name searching more efficientSimon Rozman1-4/+7
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: honor locale when comparing case-insensitiveSimon Rozman4-3/+26
Quote from MSDN: > You will need to call setlocale for _wcsicmp to work with Latin 1 > characters. The C locale is in effect by default, so, for example, ä > will not compare equal to Ä. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: fix trailing number detection in RemoveNumberedSuffix()Simon Rozman1-1/+1
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: add support for WoW64Simon Rozman9-12/+130
Some functions of SetupAPI only work when invoked from a native process. Registry and filesystem reflection makes them fail on WoW64. For WoW64 processes, a minimum set of rundll32 functions are provided. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: tighten source code annotationSimon Rozman2-4/+7
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: update documentationSimon Rozman3-99/+106
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: simplify workflowSimon Rozman1-54/+32
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: revise and unify error codesSimon Rozman1-7/+7
GetDevInfoData: Some functions returned ERROR_OBJECT_NOT_FOUND, others ERROR_FILE_NOT_FOUND when the needle was not found in the haystack. GetTcpipInterfaceRegPath: When IpConfig is an empty REG_MULTI_SZ, it is actually ERROR_INVALID_DATA - like other unexpected registry values - rather than a misleading ERROR_NETWORK_NOT_AVAILABLE. Failure in TakeNameMutex result in ERROR_INVALID_HANDLE rather than the ERROR_GEN_FAILURE with a misleading message: "A device attached to the system is not functioning." Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: tighten maximum registry key path lengthSimon Rozman3-15/+19
Maximum registry key path length is not 260 (MAX_PATH), but 255 (256 incl. zero terminator). Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: fix SPDRP_DEVICEDESC zero-terminationSimon Rozman1-1/+1
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: do the set-quiet-install laterSimon Rozman1-8/+4
Rather than setting the "quiet" flag to each and every device in the process of iterating, set it when actually creating/deleting it. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: cleanupSimon Rozman6-280/+293
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: add pre-compiled header supportSimon Rozman9-14/+40
...for super-fast compilation. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: rename WINSTATUS to WINTUN_STATUSSimon Rozman5-52/+52
...to reduce name collision probability. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: finish porting from wireguard-goSimon Rozman6-285/+1293
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: unify Win32 error typeSimon Rozman3-32/+40
This makes the code more readable and works around the clang-format.exe issues with _Return_type_success_ source annotation. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: port GetInterface member from wireguard-goSimon Rozman5-1/+776
Mind that this also fixes the order of adapter detection checks. A fast test to eliminate non-Wintun adapters from iteration to speed things up rendered the method incapable of detecting a non-Wintun adapter with the name we are looking for. ERROR_OBJECT_NOT_FOUND was replaced with ERROR_FILE_NOT_FOUND. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: port nci package from wireguard-goSimon Rozman5-0/+54
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: port tun\wintun\namespace_windows.go from wireguard-goSimon Rozman5-2/+222
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30api: add skeleton for wintun.dllSimon Rozman9-5/+316
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30msi-example: add ARM64 supportSimon Rozman3-10/+22
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30msi-example: remove unused parameter in call :msiSimon Rozman1-3/+3
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30Enable ARM64 MSM buildingSimon Rozman1-2/+2
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30installer: ignore light.exe internal errorSimon Rozman1-1/+1
Wix Toolset introduced an issue beginning with the v3.14.0.3827 release. When linking merge module, the light.exe displays an internal error: ``` WixLink: "C:\Program Files (x86)\WiX Toolset v3.14\bin\light.exe" -nologo -b o utput_dir="..\amd64\Release" -spdb -sw1076 -sw1079 -out "..\dist\wintu n-amd64-0.8.msm" "..\amd64\Release\installer-intermediate\installer.wi xobj" light.exe : error LGHT0204: ICEM10: The property 'ProductCode' is not al lowed in a Merge Module [C:\Users\Simon\Projekti\wintun\installer\instal ler.vcxproj] C:\Users\Simon\AppData\Local\Temp\xdyw3dnt\wintun-amd64-0.8.msm : error LGHT0204: ICE03: Table: Component Column: _IceM05Mark Missing specificat ions in _Validation Table (or Old Database) [C:\Users\Simon\Projekti\win tun\installer\installer.vcxproj] C:\Users\Simon\AppData\Local\Temp\xdyw3dnt\wintun-amd64-0.8.msm : error LGHT0204: ICE03: Table: File Column: _ICEM07CAB Missing specifications i n _Validation Table (or Old Database) [C:\Users\Simon\Projekti\wintun\in staller\installer.vcxproj] light.exe : error LGHT0217: Error executing ICE action 'ICE103'. The mos t common cause of this kind of ICE failure is an incorrectly registered scripting engine. See http://wixtoolset.org/documentation/error217/ for details and how to solve this problem. The following string format was n ot expected by the external UI message logger: "There is a problem with this Windows Installer package. A DLL required for this install to compl ete could not be run. Contact your support personnel or package vendor. ". [C:\Users\Simon\Projekti\wintun\installer\installer.vcxproj] The command ""C:\Program Files (x86)\WiX Toolset v3.14\bin\light.exe" -nologo -b output_dir="..\amd64\Release" -spdb -sw1076 -sw1079 -out " ..\dist\wintun-amd64-0.8.msm" "..\amd64\Release\installer-intermediate \installer.wixobj"" exited with code 217. ``` This error is not a direct consequence of anything being wrong in our source code. Fortunately, the utility still produces identical MSM file as previous WiX Toolset versions do. Unfortunately, it exits with code 217. However, we need recent v3.14 for ARM64 support. I know this is a huge issue for our build system, masking out any other potential true error, but the light.exe exit code has been temporarily ignored. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30installer: ARM64 requires msiexec version >=500Simon Rozman2-2/+6
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30Accept WoW64 clientsSimon Rozman1-10/+47
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30installer: ARM64 is always Windows 10Simon Rozman3-1/+11
ARM64 support was introduced in Windows 10. There is no need to pack the EV signed ARM64 driver for older Windows releases. The only use-case we do want to pack an EV signed ARM64 driver (or test signed) in the installer.dll is when we are doing the rundll32.exe tests. Therefore, the Debug version still packs it. If there is no driver available to pack, fail at compile time - rather than build an installer.dll that would fail at runtime. Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30Use standard volatile semanticsShawn Hoffman4-98/+40
Make all archs are use the standardized concept of volatile. This patch will cause the most changes to arm64 codegen. Signed-off-by: Shawn Hoffman <godisgovernment@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-30Fix potential TunDispatchSecurityDescriptor leakJason A. Donenfeld1-0/+3
TunDispatchSecurityDescriptor will leak if RtlAbsoluteToSelfRelativeSD fails. Add cleanup in error path. Reported-by: Shawn Hoffman <godisgovernment@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-30Use RtlSubAuthoritySid instead of directly poking SIDShawn Hoffman1-1/+1
Signed-off-by: Shawn Hoffman <godisgovernment@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-02-29Reschedule EvaluateWintun between InstallInitialize and InstallFinalize0.8.1Simon Rozman1-1/+1
WireGuard is always doing so-called "minor" upgrade. This makes it enough to run EvaluateWintun only once - somewhere after CostFinalize. The component state we bind our driver install/remove logic to will be a singleton: either be installed, left alone, or uninstalled. One single action for install product session and RemoveExistingProducts session. Other applications using Wintun might use the so-called "major" upgrade. In this scenario the existing product is completely uninstalled first. Including Wintun. The EvaluateWintun was called only once and it determined that Wintun driver should be uninstalled. Since the MSI did not execute EvaluateWintun again when installing the new product later, the Wintun remained uninstalled. In the case of major upgrades, the Wintun requires two separate action logics: what to do with Wintun on uninstall of the old product, and what to do with it when new product is installed. Therefore, EvaluateWintun has been moved between InstallInitialize and InstallFinalize to have MSI execute it in install and uninstall sessions. Reported-by: Dmitry Smirnov <dmitry.smirnov@netprotect.com> Tested-by: Simon Rozman <simon@rozman.si> Signed-off-by: Simon Rozman <simon@rozman.si> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-12-10Version bump0.8Jason A. Donenfeld1-2/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-12-10Invert skipPacket condition so code matchesJason A. Donenfeld1-2/+3
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-12-10Increment discarded packets properlyJason A. Donenfeld1-3/+1
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-12-10Process send NBLs in batchesSimon Rozman1-59/+63
When using packet forwarding on Windows computer, adjacent NBLs may represent packet fragments. Those NBLs must not be completed separately, but in a single NdisMSendNetBufferListsComplete() call. This fixes a bugcheck on Windows Server with RRAS role and IP forwarding packets to Wintun adapter. Signed-off-by: Simon Rozman <simon@rozman.si>