Commit Graph

532 Commits

Author SHA1 Message Date
Simon Rozman
18a9219507 Remove smvbuild.log on clean
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-18 15:32:08 +02:00
Simon Rozman
04ccd6744c Nuke output folder on clean
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-18 15:32:08 +02:00
Simon Rozman
c223393e7c Cleanup clean target
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-17 15:39:51 +02:00
Simon Rozman
bfa3b3f6cc MSM: Explicitly version driver files
wintun.inf and wintun.cat have no version resource. WiX linker cannot
determine their versions and the MSM will use file sizes and hashes for
update logic. By setting explicit file version and language, the version
will always be used to determine which version is newer on updates.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-17 15:39:51 +02:00
Simon Rozman
361dd60a04 MSM: Mark package as read-only
Thou, this serves as a hint only and provides no real enforcement.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-17 15:39:51 +02:00
Simon Rozman
baba7bb6d0 MSM: Mark package to require elevated and per-machine install
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-17 15:39:51 +02:00
Simon Rozman
1ec2a54a5c MSM: Mark module as language-independent
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-17 15:39:50 +02:00
Simon Rozman
1031ad44da Add MSM packaging support
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-16 16:11:24 +02:00
Simon Rozman
f8a2923b93 Reintroduce Windows 7 support
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-16 16:11:24 +02:00
Simon Rozman
84f3c3e455 Add ARM64 compiling support
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-15 13:35:23 +02:00
Simon Rozman
afef39616c Revise architecture naming convention
Adopt PROCESSOR_ARCHITECTURE environment variable platform designation,
make it lowercase, and unify output folder naming.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-15 13:35:23 +02:00
Jason A. Donenfeld
82655e6e0e Fixup readme markdown formatting
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-04-14 08:48:00 +02:00
Simon Rozman
6298787aa3 Establish command line building support
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-13 19:50:49 +02:00
Simon Rozman
207144965a Revise OID request return statuses
MINIPORT_OID_REQUEST handler should return:
- NDIS_STATUS_NOT_SUPPORTED => NDIS_STATUS_INVALID_OID if the OID
  request was not recognized.
- NDIS_STATUS_INVALID_OID => NDIS_STATUS_NOT_SUPPORTED if particular OID
  is not supported.
- NDIS_STATUS_INVALID_LENGTH => NDIS_STATUS_BUFFER_TOO_SHORT if output
  buffer is too short.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 15:35:39 +02:00
Simon Rozman
207e1c4896 Assist SDV in realizing that non-NULL IRP => non-NULL buffer
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 15:35:39 +02:00
Simon Rozman
4c47c2fbbf TunCanFitIntoIrp => TunWontFitIntoIrp
The function name was inverted and misleading.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 15:35:39 +02:00
Simon Rozman
366e8f1eef .gitignore Static Driver Verifier output
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 15:35:38 +02:00
Simon Rozman
5120529350 Fix output folder
The compiled result is put into $(SolutionDir)$(Platform)\
$(ConfigurationName) by default. Unfortunately Static Driver Verifier
sets the $(SolutionDir) without a trailing backslash, resulting some
files end up in a "wintunx64" folder of the project parent folder.

Until driver building and packaging is automated, the output folder has
been manually matched to the intermediate folder.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 15:35:38 +02:00
Simon Rozman
50a09cad71 Move #define NDIS... to ClCompile/PreprocessorDefinitions
These constants must be defined in the project file in order for Static
Driver Verifier to work correctly. Otherwise, SDV returns error MSB3073:
The command "staticdv /check:*" exited with code -1.

Since the ClCompile/PreprocessorDefinitions management became
cumbersome, all platform and configuration independent MSVC settings
were rearranged in a single <ItemDefinitionGroup>, while platform
independent but configuration dependent were rearranged to a conditional
<ItemDefinitionGroup>(s).

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 15:35:38 +02:00
Simon Rozman
4eb3c1f7c0 Enable code analysis on Release build and set it to DriverMustFixRules
Wintun will need to deliver code analysis results of Release build to
WHLK.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 15:35:38 +02:00
Simon Rozman
67ebf9fe4a Set UseDebugLibraries to true for debug driver builds
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 15:35:38 +02:00
Simon Rozman
9cda719d85 Fix indentation
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 08:09:33 +02:00
Simon Rozman
d9831a9197 InterlockedAdd/Subtract(val, 1) => InterlockedIncrement/Decrement(val)
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-12 08:09:33 +02:00
Simon Rozman
1770ac146d Wait for handles to close before returning from TunHaltEx()
This allows Windows to unload the driver from memory when the last
adapter is halted. Hence driver can be updated without a reboot.

Unfortunately, a client refusing to close device pipe handle can block
adapter halting indefinitely. So, we now have a new challenge to
address.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-11 19:30:23 +02:00
Simon Rozman
ca79fd1368 Revise I/O errors
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-11 19:30:23 +02:00
Simon Rozman
d3cc0570de Initialize ActiveTransactionCount to 1
This always sets the reference counter to predictable state on resume
and eliminates the need to bump it on pausing.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-11 19:30:23 +02:00
Simon Rozman
5cecd1536c Clean excessive miniport adapter state checks
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-11 14:08:20 +02:00
Simon Rozman
6d230d616e Clean unneeded TunSetOptions()
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-11 14:08:20 +02:00
Simon Rozman
83d3e175d9 Merge TUN_CTX and TUN_DEVEXT and save entire context in device extension
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-10 13:45:36 +02:00
Simon Rozman
cb741f4d1e Cancel pending IRPs and selectively block new ones when halted
This unblocks waiting clients and prevents new handles to be opened on
device pipe while allowing graceful cleanup.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-10 13:43:13 +02:00
Simon Rozman
df23e41a7f Fix spacing
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-10 13:43:13 +02:00
Simon Rozman
04f2cc318e Migrate device-specific data to device extension
This allows to keep all device pipe specific information to persist as
long as device is in use.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-09 15:20:03 +02:00
Simon Rozman
2fa408a92f Rename TunDriverUnload() => TunUnload()
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-09 15:17:02 +02:00
Simon Rozman
b5cf1f927b Adjust OID_GEN_TRANSMIT_BUFFER_SPACE hint properly
When transmitting, the adapter can actually take TUN_QUEUE_MAX_NBLS
packets at a time.

When receiving, the adapter gets up to TUN_EXCH_MAX_PACKETS packets at
a time.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-05 20:23:23 +02:00
Simon Rozman
5b529a9c50 Stop rewarding user thread on IRP buffer error
When driver cannot access IRP's MDL it shouldn't grand calling user
thread any priority boost. The IO_NETWORK_INCREMENT was overlooked on
copy&paste.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-05 20:23:22 +02:00
Simon Rozman
1369525e3a Don't cancel pending IRPs on adapter pause
Pausing an adapter requires it to stop processing network traffic. We
may still process I/O of the adapter device pipe.

By canceling all pending IRPs and refusing to serve any new IRPs on
adapter pause, we forcibly cut the client off to release resources and
allow graceful driver unload. This enabled a hot driver update without a
restart.

However, using a modified Wintun driver for NDISTEST utility the client
didn't behave the same way, keeping handles open when NDISTEST paused
Wintun adapter. The pause reset ctx->Device.RefCount to 0 which caused
negative reference count when client finally decided to close the Wintun
adapter device pipe handle.

Rather than introducing a complex fix to the adapter device pipe
reference counting, this commit simplifies it by allowing IRPs even when
adapter is paused. IRP_MJ_WRITE is an exception: client cannot write to
the adapter when it's paused.

This allows the client to stay connected, reduces ActiveTransactionCount
to NBL counting only, and cancels pending IRPs much later in
TunHaltEx().

Since there is still I/O going on after TunHaltEx() returns now, the
driver is not unloaded from memory. This prevents driver updates without
a reboot. How can one gracefully terminate I/O in TunHaltEx() remains a
subject of further study.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-05 20:23:22 +02:00
Simon Rozman
7176236b4e Mark canceled NBL status as NDIS_STATUS_SEND_ABORTED
NDIS expects this from a miniport driver.

References: https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ndis/nc-ndis-miniport_cancel_send
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-05 12:57:31 +02:00
Simon Rozman
bf48214c8c Upgrade OID_GEN_XMIT_OK and OID_GEN_RCV_OK to support 64-bit counters
This commit addresses issues reported by NDISTEST/1c_64bitoids.

It also revises the OID request writing, as adaptive 32/64-bit responses
required by OID_GEN_XMIT_OK and OID_GEN_RCV_OK would grow the current
TunOidQuery() design quite complex and introduce duplicated code.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-05 12:57:22 +02:00
Simon Rozman
1c13736068 Access PowerState interlocked
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-05 12:51:15 +02:00
Simon Rozman
480000f429 Revert "Implement NDIS 6.30's NDIS_MINIPORT_ATTRIBUTES_NO_PAUSE_ON_SUSPEND"
This reverts commit 683cf83befbc8d95de3b13994851087306b19963.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 05:47:47 +02:00
Simon Rozman
1b9fee728b Upgrade NDIS_PM_CAPABILITIES to NDIS 6.30
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 05:47:47 +02:00
Simon Rozman
9436da8f7e Report correct NDIS version to NdisMRegisterMiniportDriver
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 05:47:47 +02:00
Simon Rozman
b6056b95d3 Add extra ASSERT to check PoweredTransactionCount is 0 on power-on
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 05:47:47 +02:00
Simon Rozman
e7d5cdc4f0 Implement NDIS 6.30's NDIS_MINIPORT_ATTRIBUTES_NO_PAUSE_ON_SUSPEND
NDIS >=6.30 allows bringing adapter to low-power state without pausing
it. As Wintun's pause cancels all pending IRP and we want to keep
disturbing client to a minimum, OID_PNP_SET_POWER cancels pending NBLs
and wait for active NBLs to finish only.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 03:37:24 +02:00
Simon Rozman
58900a4841 Implement dynamic NDIS 6.30 detection
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 03:37:24 +02:00
Simon Rozman
934923bbc1 Change TunOidSet/TunOidQuery() parameters
All parameters to TunOidSet/TunOidQuery() are contained inside a
NDIS_OID_REQUEST struct. But, the main rationale behind this commit is
that OID_PNP_SET_POWER set request will require pointer to original
NDIS_OID_REQUEST struct for NdisMOidRequestComplete() call, should we
want to implement pending PnP power-down.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 03:37:24 +02:00
Simon Rozman
8eefe85bb2 Move packet queue clearing into a reusable function
We will need this in OID_PNP_SET_POWER.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-04-03 03:37:23 +02:00
Jason A. Donenfeld
bba0f6aecf Do not call NdisMPauseComplete before TunPause returns
Otherwise we trigger a bugcheck on Server 2019.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-03-29 21:42:46 +01:00
Simon Rozman
7b3ea2a8a9 Reintroduce outgoing statistics
Outgoing statistics-keeping was accidentally dropped in
ed93692ca0049123979e0497aa3c4a4698f844cd. This commit reintroduces it.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-29 16:23:24 +01:00
Simon Rozman
f6972f147c Reintroduce .editorconfig and suggest tab usage
This time we don't impose 8-space tabulators, but merely suggest text
editors to use tabulator indenting. Otherwise, Visual Studio IDE
configured to use spaces instead of tabulators keeps corrupting
indentation.

Signed-off-by: Simon Rozman <simon@rozman.si>
2019-03-29 16:23:24 +01:00