aboutsummaryrefslogtreecommitdiffstats
path: root/api/logger.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2021-02-06api: implement %r format type for logging registry pathsr/simons-wild-n-crazy-printfSimon Rozman1-39/+182
Note: Once reviewed, merge with 728d6762cd95394f2541d4a3f3e7fdd17ecd8f2a Signed-off-by: Simon Rozman <simon@rozman.si>
2021-02-05api: upgrade loggingSimon Rozman10-177/+430
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>
2021-02-04api: tighten function parameter code analysis annotationsSimon Rozman1-6/+5
Signed-off-by: Simon Rozman <simon@rozman.si>
2021-02-04api: truncate long log lines with …Simon Rozman1-3/+5
Signed-off-by: Simon Rozman <simon@rozman.si>
2021-02-04api: unify NetCfgInstanceId registry retrievalSimon Rozman1-26/+22
Signed-off-by: Simon Rozman <simon@rozman.si>
2021-02-04README: document the Windows SDK version requirementSimon Rozman1-1/+1
Signed-off-by: Simon Rozman <simon@rozman.si>
2021-02-03api: ensure that device object exists before returning from open/create0.10.1Jason A. Donenfeld1-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>
2021-01-30global: bump copyrightJason A. Donenfeld30-32/+32
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2021-01-30api: use custom devpkey for poolJason A. Donenfeld1-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>
2020-12-17api: close private namespace when unloading DLLJason A. Donenfeld1-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>
2020-12-16version: bump0.10Jason A. Donenfeld1-2/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-12-16project: license prebuilt binaries more permissivelyJason A. Donenfeld3-2/+86
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-12-15driver: use IoAllocateMdl without being too cleverJason A. Donenfeld1-8/+17
Windows 7 doesn't like our trick of sticking MDLs into the NBL context area. So we do things more traditionally, by allocating an MDL with IoAllocateMdl and freeing it with IoFreeMdl. This means that we have to keep track of the MDL between allocation and free time, and we don't have any more miniport reserved pointers left in the NBL. So instead we walk the MdlChain field of the first NB, and free the one that has an address living inside of the non-partial MDL. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-12-13driver: use partial MDL for slicing ring, rather than NB's DataOffsetJason A. Donenfeld1-3/+12
Providing the DataOffset member of the NBL allocation function or setting that member in the NB header indicates to NDIS not only that the data starts at that offset, but that there's that amount of space *available for it to use as it wants* before that offset. This meant that NDIS was allowed to scribble data before the packet. This was bounded by the size of the ring, so there was never any risk of memory corruption, and since the ring is shared by userspace as well as the rest of the kernel, we've always taken care of reading from it closely, checking all values, and erroring out on corruption of the ring. So, if NDIS wrote before the first packet, this would wind up corrupting the RingTail and Alertable fields of the ring. The receiver thread would then notice this, error out, and set the RingHead to MAXULONG on its way out the door, so that userspace can detect it. And indeed wintun.dll then started returning EOF from its write function. Mostly this was not an issue, because we're not expecting for data to be pushed on the head of a packet on ingress. But WSL2's Hyper-V driver is actually pushing an ethernet header onto the front of the packet before passing it off to Linux. Practically speaking, this manifested itself in the RingTail and Alertable fields having Linux's MAC address! And then the adapter would be EOF'd. This was reported as happening after WSL2 sends the *first* packet, but not others, which makes sense, because it has to be at the beginning in order to corrupt those fields. This fixes the problem by simply using a new MDL for the span we want, instead of using the misunderstood DataOffset field. In order to not need to keep track of memory allocations, we allocate the MDL as part of the NBL's context area. And in order to avoid additional mappings, we use IoBuildPartialMdl, which returns an MDL_PARTIAL, which does not have an additional mapping that needs to be freed or unmapped. After making this change, WSL2 no longer appears to halt the adapter, and all works well. Fixes: be8d2cb ("Avoid allocating second MDL") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-12-02driver: use localtime in inf2catStefan Rinkes1-0/+1
Otherwise the build fails at odd hours of the day. Signed-off-by: Stefan Rinkes <stefan.rinkes@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-27api: delay load remaining dlls to work around forwarder gotchas0.9.2Jason A. Donenfeld1-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>
2020-11-27api: skip notifying driver when there are no receive packets yetSimon Rozman1-3/+5
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-11-27api: allow header to be mitJason A. Donenfeld1-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>
2020-11-17api: do not make dead gateway detection failures fatal0.9.1Jason A. Donenfeld1-1/+1
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-17api: retry on ERROR_TRANSACTION_NOT_ACTIVE when disabling dead GW detectSimon Rozman1-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>
2020-11-17api: remove useless lineJason A. Donenfeld1-1/+1
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-10api: remove return value from logger functionJason A. Donenfeld4-14/+6
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-09driver: do not allow compiler to reload PacketSizeJason A. Donenfeld1-1/+1
In theory, the compiler could reload PacketSize after the bounds check but before it's passed to NdisAllocateNetBufferAndNetBufferList. In practice, it's not actually doing that, but better safe than sorry. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-09version: bump0.9Jason A. Donenfeld1-2/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-09api: relax IsPoolMember estimationJason A. Donenfeld1-27/+14
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-09api: do not call UpdateDriverForPlugAndPlayDevicesWJason A. Donenfeld2-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>
2020-11-09api: take pool mutex when deletingJason A. Donenfeld1-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>
2020-11-09api: account for adapter disappearing during deletionJason A. Donenfeld1-4/+6
This makes the race less fatal. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-07api: manipulate process token if thread token didn't require impersonationJason A. Donenfeld1-8/+11
Otherwise rundll32.exe fails if we're already SYSTEM. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-07api: fix Function and Prefix logging orderSimon Rozman1-1/+1
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-11-07api: fix LastError overrideSimon Rozman1-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>
2020-11-06proj: use less scary caps for zip license fileJason A. Donenfeld1-1/+1
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-06api: avoid loading version.dll if not usedJason A. Donenfeld1-3/+14
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-06driver: move to subfolderSimon Rozman10-27/+24
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-11-05api: include arm64 in amd64Jason A. Donenfeld3-3/+4
ARM64 will still run AMD64 apps. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05api: remove WintunOpenAdapterDeviceObjectJason A. Donenfeld7-37/+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>
2020-11-05example: raise to 4MiBJason A. Donenfeld2-2/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05api: rearrange wintun.h to have better grouping and improve docsJason A. Donenfeld2-44/+45
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05api: rename WintunGetAdapter to WintunOpenAdapterJason A. Donenfeld5-22/+22
"Create" and "Open" natural names for these. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05api: rename ReceiveRelease to ReleaseReceivePacketJason A. Donenfeld5-17/+16
This makes the API parallel: Wintun*Allocate*SendPacket -> WintunSendPacket WintunReceivePacket -> Wintun*Release*ReceivePacket Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05README: improve code exampleJason A. Donenfeld1-2/+37
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05api: move InititalizeWintun to top to be easier to findJason A. Donenfeld1-33/+32
It's the primary function we want people copy and pasting. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05api: add cfgmgr32.dll to delayed load listJason A. Donenfeld1-2/+2
It's in the registry but not in the NT object key. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05wintun: simplify vcxprojJason A. Donenfeld1-86/+10
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05vs: cause example to be default selected run projectJason A. Donenfeld1-2/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05.gitignore: simplify build dir matchJason A. Donenfeld1-8/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05api: fix typo in ring-management function prototype declarationsSimon Rozman2-10/+10
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-11-04README: add reference and describe infoJason A. Donenfeld1-96/+343
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-04api: document enum argument properlyJason A. Donenfeld1-1/+1
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-04api: document log enumJason A. Donenfeld1-3/+6
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>