aboutsummaryrefslogtreecommitdiffstats
path: root/api (follow)
Commit message (Collapse)AuthorAgeFilesLines
* api: log Windows error message too when creating folder or file failsSimon Rozman2021-04-131-2/+2
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: fix fallback log line printf templateSimon Rozman2021-04-101-1/+1
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* Fix © in resourcesSimon Rozman2021-03-191-0/+2
| | | | | | | | The \xa9 is © on Windows-125x code pages. When Wintun was compiled on a Windows computer using UTF-8 as default code page (for "non-Unicode" programs), the Copyright notice in resources was wrong. Signed-off-by: Simon Rozman <simon@rozman.si>
* project: add support for intermediate versioningSimon Rozman2021-03-191-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | While the Wintun driver is typically released only at <major>.<minor> milestones, the wintun.dll did see some intermediate releases. To make MSI logic correctly decide to upgrade local wintun.dll file, the version inscribed in wintun.dll file resources should increment in those intermediate releases. MSI ignores file timestamps. One could use REINSTALLMODE=emus Installer property to force copying wintun.dll when its version doesn't change. But REINSTALLMODE applies to all files in the MSI session and would be an additional requirement when authoring MSI packages with wintun.dll. Bumping only the final ZIP filename version is not sufficient. Therefore, a <major>.<minor> or <major>.<minor>.<build> versioning is introduced. Furthermore, we no longer distinguish between WintunVersion and WintunVersionStr. All our releases used strictly numeric <major>.<minor> notation, making WintunVersion and WintunVersionStr always the same. When the driver didn't change, just bump the version in wintun.proj and run `msbuild wintun.proj /t:Zip` to rebuild the wintun.dll and make the new ZIP file. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: make .h filenames lowercase for building with MinGW on LinuxSimon Rozman2021-03-161-2/+2
| | | | | | | | MinGW supplies all Windows header files using lowercase filenames. This makes some of the #include lines in wintun.h fail to resolve the .h files correctly on a case-sensitive filesystem. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: elevate to SYSTEM in WintunEnumAdapters()Simon Rozman2021-03-081-3/+10
| | | | | | | | | | | | | | The WintunEnumAdapters() requires namespace mutex. However, NamespaceTakePoolMutex() works as SYSTEM user only. WireGuard is using the WintunEnumAdapters() in its manager service to cleanup stale adapters. As the WireGuard manager service is running as SYSTEM, this requirement was not apparent before. This commit also extends the example project to list its existing adapters at start. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: upgrade logging0.10.2Simon Rozman2021-02-1610-177/+431
| | | | | | | Log runtime information to quickly check whether the values are sane when analyzing error logs sent in by users. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: tighten function parameter code analysis annotationsSimon Rozman2021-02-041-6/+5
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: truncate long log lines with …Simon Rozman2021-02-041-3/+5
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: unify NetCfgInstanceId registry retrievalSimon Rozman2021-02-041-26/+22
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: ensure that device object exists before returning from open/create0.10.1Jason A. Donenfeld2021-02-031-13/+62
| | | | | | | | | | | | | | | | | Some users are seeing errors like this after rebooting from Windows Update: 2021-01-28 18:39:45.220197: [TUN] Creating Wintun interface 2021-01-28 18:39:49.420116: [TUN] [Wintun] CreateAdapter: Creating adapter 2021-01-28 18:39:53.704007: [TUN] [Wintun] OpenDeviceObject: Failed to connect to adapter: The system cannot find the path specified. (Code 0x00000003) 2021-01-28 18:39:53.704007: [TUN] [Wintun] WintunStartSession: Failed to open adapter device object 2021-01-28 18:39:54.097037: [TUN] Unable to create Wintun interface: Error starting session: The system cannot find the path specified. It appears that creation of the device object file might happen asynchronously, so this commit polls for it. Reported-by: Artem Kuroptev <artem@kuroptev.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: bump copyrightJason A. Donenfeld2021-01-3023-24/+24
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: use custom devpkey for poolJason A. Donenfeld2021-01-301-2/+28
| | | | | | | | | | It seems like the friendly name is still getting reset sometimes. Rather than swimming upstream, it turns out we can just use a custom devpkey that, according to msdn, is respected. https://docs.microsoft.com/en-us/windows-hardware/drivers/install/creating-custom-device-properties Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: close private namespace when unloading DLLJason A. Donenfeld2020-12-171-12/+16
| | | | | | | | | | | | | | Prior, people making calls to LoadLibrary/FreeLibrary would experience a failure to create or open adapters, because the private namespace was already loaded into the process and not cleaned up on DLL detachment. While this pattern is probably a misuse of the library, we should still support cleaning that up. This commit makes the right calls to free the boundary descriptor and close the private namespace. It does not, however, destroy the private namespace using the flag on the second parameter, in case of races with other processes. Reported-by: Brad Spencer <bspencer@blackberry.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: delay load remaining dlls to work around forwarder gotchas0.9.2Jason A. Donenfeld2020-11-271-2/+2
| | | | | | | | | RtlGenRandom forwards to cryptbase.dll, which is not in KnownDlls. Therefore it's not a good idea to link to advapi32.dll at link time. How many other gotchas of unusual forwarded functions are there? I don't really want to find out. Therefore, delay load everything else. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: skip notifying driver when there are no receive packets yetSimon Rozman2020-11-271-3/+5
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: allow header to be mitJason A. Donenfeld2020-11-271-1/+1
| | | | | | | This doesn't change much, but it does make it mildly more convenient plop this into mixed-use codebases. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: do not make dead gateway detection failures fatal0.9.1Jason A. Donenfeld2020-11-171-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: retry on ERROR_TRANSACTION_NOT_ACTIVE when disabling dead GW detectSimon Rozman2020-11-171-18/+27
| | | | | | | | There seems to be a race in the TCP/IP adapter registry key. Sometimes, the adapter TCP/IP key is created, but setting the value EnableDeadGWDetect fails with ERROR_TRANSACTION_NOT_ACTIVE. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: remove useless lineJason A. Donenfeld2020-11-171-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: remove return value from logger functionJason A. Donenfeld2020-11-102-6/+3
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: relax IsPoolMember estimationJason A. Donenfeld2020-11-091-27/+14
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: do not call UpdateDriverForPlugAndPlayDevicesWJason A. Donenfeld2020-11-092-13/+5
| | | | | | | This seems to reset a number of device properties, and our update flow seems to update old adapters without needing to call this. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: take pool mutex when deletingJason A. Donenfeld2020-11-091-1/+10
| | | | | | | This prevents us from racing with driver deletion. Mutexes are recursive, so we shouldn't deadlock if called from Enum. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: account for adapter disappearing during deletionJason A. Donenfeld2020-11-091-4/+6
| | | | | | This makes the race less fatal. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: manipulate process token if thread token didn't require impersonationJason A. Donenfeld2020-11-071-8/+11
| | | | | | Otherwise rundll32.exe fails if we're already SYSTEM. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: fix Function and Prefix logging orderSimon Rozman2020-11-071-1/+1
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: fix LastError overrideSimon Rozman2020-11-071-3/+4
| | | | | | | | | The LastError was overridden by the stdout reader thread exit code masking the true reason why ExecuteRunDll32() failed and even worse: as the thread exited gracefully, the true reason was overridden by ERROR_SUCCESS and returning TRUE (success). Signed-off-by: Simon Rozman <simon@rozman.si>
* api: avoid loading version.dll if not usedJason A. Donenfeld2020-11-061-3/+14
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: include arm64 in amd64Jason A. Donenfeld2020-11-052-2/+2
| | | | | | ARM64 will still run AMD64 apps. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: remove WintunOpenAdapterDeviceObjectJason A. Donenfeld2020-11-055-21/+14
| | | | | | | Discourage use of kernel interface, which gives us more flexibility if we ever want to change it. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: rearrange wintun.h to have better grouping and improve docsJason A. Donenfeld2020-11-051-26/+27
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: rename WintunGetAdapter to WintunOpenAdapterJason A. Donenfeld2020-11-053-10/+10
| | | | | | "Create" and "Open" natural names for these. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: rename ReceiveRelease to ReleaseReceivePacketJason A. Donenfeld2020-11-053-9/+7
| | | | | | | | This makes the API parallel: Wintun*Allocate*SendPacket -> WintunSendPacket WintunReceivePacket -> Wintun*Release*ReceivePacket Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: add cfgmgr32.dll to delayed load listJason A. Donenfeld2020-11-051-2/+2
| | | | | | It's in the registry but not in the NT object key. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: fix typo in ring-management function prototype declarationsSimon Rozman2020-11-051-5/+5
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: document enum argument properlyJason A. Donenfeld2020-11-041-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: document log enumJason A. Donenfeld2020-11-041-3/+6
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: remove enum name for logger levelJason A. Donenfeld2020-11-041-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: document adapter handle return value properlyJason A. Donenfeld2020-11-041-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: CALLBACK_FUNC -> CALLBACKJason A. Donenfeld2020-11-044-9/+9
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: upgrade nci.lib and wintun-inf.h buildingSimon Rozman2020-11-042-9/+32
| | | | | | | The additional build steps performed are now attached to the build process using BeforeTargets/AfterTargets. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: rename GetVersion to GetRunningDriverVersionJason A. Donenfeld2020-11-043-4/+4
| | | | | | | This makes our intentions a lot more clear, and in case we ever add other version functions, makes the forward path simpler. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: use a logging alloc functionJason A. Donenfeld2020-11-048-131/+96
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: concatenate function name at runtimeJason A. Donenfeld2020-11-043-18/+29
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: include the rundll32 helpers the MSVC-typical waySimon Rozman2020-11-044-6/+8
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: translate NTSTATUS to Win32 error codesSimon Rozman2020-11-043-13/+15
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: use GetLastError() to report failures like standard Win32Simon Rozman2020-11-0417-981/+1266
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* wintun: extract inf driverver at compile time into C headerJason A. Donenfeld2020-11-032-111/+5
| | | | | | | | | | | | This requires us to make some insane conversions between INF date, JavaScript time, and finally Windows file time. The point is to mimic SystemTimeToFileTime, which is what SpInf.dll's pSetupStringToDriverDate does on the YYYY-MM-DD from the INF. The result is that we no longer have to parse an ancient text format in C at runtime. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: move nci.lib generation to custom stepJason A. Donenfeld2020-11-031-4/+7
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>