Commit Graph

40 Commits

Author SHA1 Message Date
Simon Rozman
1ccd623e94 api: make .h filenames lowercase for building with MinGW on Linux
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>
2021-03-16 10:11:00 +01:00
Jason A. Donenfeld
2628412d71 global: bump copyright
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2021-01-30 16:45:26 +01:00
Jason A. Donenfeld
6af568d1e0 api: allow header to be mit
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-27 14:52:01 +01:00
Jason A. Donenfeld
e73613ee24 api: remove return value from logger function
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-10 22:06:25 +01:00
Jason A. Donenfeld
9f3d466791 api: remove WintunOpenAdapterDeviceObject
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-05 16:58:43 +01:00
Jason A. Donenfeld
82c41bdb4b api: rearrange wintun.h to have better grouping and improve docs
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05 16:58:43 +01:00
Jason A. Donenfeld
1285b8f528 api: rename WintunGetAdapter to WintunOpenAdapter
"Create" and "Open" natural names for these.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05 16:58:43 +01:00
Jason A. Donenfeld
e9e790605a api: rename ReceiveRelease to ReleaseReceivePacket
This makes the API parallel:
Wintun*Allocate*SendPacket -> WintunSendPacket
WintunReceivePacket -> Wintun*Release*ReceivePacket

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-05 16:58:43 +01:00
Simon Rozman
abbf658211 api: fix typo in ring-management function prototype declarations
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-11-05 08:36:28 +01:00
Jason A. Donenfeld
3158b553c4 api: document enum argument properly
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-04 21:22:47 +01:00
Jason A. Donenfeld
fc27d8ccd2 api: document log enum
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-04 21:22:47 +01:00
Jason A. Donenfeld
65dee05229 api: remove enum name for logger level
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-04 21:22:47 +01:00
Jason A. Donenfeld
2b4e164d69 api: document adapter handle return value properly
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-04 16:19:53 +01:00
Jason A. Donenfeld
c26b16e06f api: CALLBACK_FUNC -> CALLBACK
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-04 16:46:24 +01:00
Jason A. Donenfeld
dc99f96da7 api: rename GetVersion to GetRunningDriverVersion
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>
2020-11-04 14:53:39 +01:00
Simon Rozman
552821f59a api: translate NTSTATUS to Win32 error codes
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-11-04 13:21:42 +01:00
Simon Rozman
f657e6fd27 api: use GetLastError() to report failures like standard Win32
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-11-04 13:21:42 +01:00
Jason A. Donenfeld
080b6896e0 api: constify pool argument
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-03 12:47:26 +01:00
Jason A. Donenfeld
8963f7258e api: remove guid getter
The iphlpapi takes both LUIDs and GUIDs but prefers LUIDs, so exposing
the NET_LUID makes sense. However, we were previously exposing the
configuration GUID, rather than the net GUID, which is confusing, so
just make it all go away.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-03 12:34:19 +01:00
Jason A. Donenfeld
2af7fbd64a api: use 'open' name since caller must close handle
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-03 12:31:49 +01:00
Jason A. Donenfeld
7dede73406 api: add pool/driver removal for uninstaller semantics
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-03 12:27:42 +01:00
Jason A. Donenfeld
64f39cd95d api: only return top two version nibbles
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-03 11:01:20 +01:00
Jason A. Donenfeld
ddacb5491a api: pass around NET_LUID instead of LUID
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-02 23:33:20 +01:00
Jason A. Donenfeld
f0f18ea4fb api: consistancy in exported interface
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-02 23:33:20 +01:00
Simon Rozman
283f6c8e63 api: install driver on demand
...and add API for uninstalling it.

Signed-off-by: Simon Rozman <simon@rozman.si>
2020-11-02 23:33:20 +01:00
Jason A. Donenfeld
c20e1683c2 api: separate read-wait handle into other function
Makes the API a bit more clear.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-02 16:38:56 +01:00
Jason A. Donenfeld
b5836e9fb9 api: make version function uniform
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-02 09:17:47 +01:00
Jason A. Donenfeld
334a5e619f api: cleanup names
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-11-01 00:00:14 +01:00
Simon Rozman
60ad907b99 api: check buffer overflows in runtime
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-31 19:11:57 +01:00
Jason A. Donenfeld
17bd620a36 api: do not require RebootRequired
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-31 19:11:56 +01:00
Jason A. Donenfeld
ffab1eabe3 api: RebootRequire is an _Out_
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-31 19:11:56 +01:00
Simon Rozman
efbc70635b api expose Send.TailMoved event to clients
This allows clients to use it in WaitForMultipleObjects().

Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-31 19:11:50 +01:00
Simon Rozman
c8004933c1 api: rename MAX_POOL to WINTUN_MAX_POOL
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-31 19:11:50 +01:00
Jason A. Donenfeld
0a8bf9d1ff api: only force close handles if requested
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-31 19:11:49 +01:00
Simon Rozman
e11897e343 api: depretiate WintunIsPacketAvailable()
Spinning on the WintunReceivePacket() while it returns
ERROR_NO_MORE_ITEMS achieves the same.

Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-31 10:41:46 +01:00
Simon Rozman
2439b05212 api: upgrade ring management
- Return pointer to ring buffer with packet data allowing clients to
  read/write directly. This eliminates one memcpy().

- Make sending/receiving packets thread-safe.

Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-31 10:15:15 +01:00
Simon Rozman
fbb9098393 api: allow wintun.h use in C++
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30 16:51:01 +01:00
Simon Rozman
4b8f879fd6 api: add ring management
Rather than every client reinvent the art of using the Wintun and its
ring buffers, we offer helper structs and functions to unify and
simplify Wintun usage.

Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30 16:51:01 +01:00
Simon Rozman
faf7d3771c api: connect rundll32 child with parent using stdout and stderr
The WintunCreateAdapter()+CreateAdapter() and WintunDeleteAdapter()+
DeleteAdapter() communicate using Unicode anonymous pipes now. This
allows the WintunCreateAdapter() to exactly determine the adapter
CreateAdapter() just created by its GUID rather than its name - avoiding
the possible ambiguity caused by same-adapter-name ordinal suffixes.
This also allows exact retrieval of the result code and pending reboot
flag from the rundll32 child process.

Furthermore, CreateAdapter() and DeleteAdapter() are now available in
_DEBUG for all platforms to allow testing. It took a #pragma comment(
linker, "/EXPORT") trick to stop compiler from decorating function names
and exporting as _CreateAdapter@16() and _DeleteAdapter@16() in x86.

Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30 16:51:01 +01:00
Simon Rozman
449876fdfd api: introduce wintun.h
The SDK header for deployment containing datatype and function
declarations for use by C/C++ clients.

As we shall not distribute MSVC wintun.lib files, making clients need to
use GetProcAddress(), this file contains function type declarations
rather then __declspec(dllimport) function declarations.

Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-30 16:51:01 +01:00