aboutsummaryrefslogtreecommitdiffstats
path: root/wintun.proj (unfollow)
Commit message (Collapse)AuthorFilesLines
2019-07-31Assert that adapter is always running when client is registering ringsSimon Rozman1-0/+2
By attaching to NDIS device instead of creating our own device for I/O, the adapter is always running before client is able to connect and register rings. NDIS also won't allow adapter to pause with connected clients. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-31Cleanup TUN_FLAGS_PRESENTSimon Rozman1-8/+2
With no PnP notifications and custom surprise removal code we do not need the TUN_FLAGS_PRESENT any more. The traffic is stopped when handle is closed or adapter is somehow paused. Though by reusing the NDIS device for our I/O, the adapter will not be able to pause with a client connected. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-31Add handle closing ioctlJason A. Donenfeld5-11/+131
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-31Reinitialize active NBL remove lock to allow adapter reuseSimon Rozman1-1/+3
Before the TunProcessReceiveData() thread terminates or adapter is paused, we wait for all receive NBLs to be returned. Unfortunately, IoReleaseRemoveLockAndWait() leaves the remove lock in non reusable state. To be able to start receiving packets on existing adapter again, we (re)initialize the remove lock on ring registration or adapter resume. The former addresses TunProcessReceiveData()'s IoReleaseRemoveLockAndWait() call, the later addresses the TunPause()'s. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-19Compile on 32-bit and arm64Jason A. Donenfeld1-6/+8
No popcnt intrinsic on arm, no PopulationCount64 function on 32bit. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-19Use more specific IOCTL codeJason A. Donenfeld2-3/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18Require the usual SDDL_DEVOBJ_SYS_ALL permissionsJason A. Donenfeld1-36/+96
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18Make receiving NBLs asynchronousSimon Rozman1-26/+105
This commit moves NBL post-processing (moving ring head, releasing NBL) to MINIPORT_RETURN_NET_BUFFER_LISTS handler. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-18Minimize TransitionLock when receiving packetsSimon Rozman1-13/+11
We do not need to share-lock the TransitionLock for the whole life of receiver thread. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-18Fix insane coding styleJason A. Donenfeld1-2/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18Fix awkward comment styleJason A. Donenfeld1-3/+3
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18Do not hijack PNP notifierJason A. Donenfeld1-35/+1
We no longer pend send-side NBLs, so we don't have a real use for this. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18Switch to paged dispatch handlersJason A. Donenfeld1-4/+7
We're not totally sure this is kosher, unfortunately. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-18Minimize TransitionLock when sending packetsSimon Rozman1-7/+9
We do not need to share-lock the TransitionLock for complete NBL chain. This commit should improve better state transition response, thou until NDIS is sending a single NBL per MINIPORT_SEND_NET_BUFFER_LISTS call, this should not have a considerable effect. Since the skibNbl: call of NdisMSendNetBufferListsComplete() is made inside the TransactionLock at dispatch IRQL, a dispatch IRQL hint was added to the NdisMSendNetBufferListsComplete() call. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-18Piggy-back on top of NDIS' device object instead of adding our ownJason A. Donenfeld6-333/+86
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-17README: clarify ring usageJason A. Donenfeld1-32/+41
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-17Replace TUN_FLAGS_CONNECTED by an eventSimon Rozman1-18/+18
On client closing the handle there is a potential race if somebody resets the TailMoved event of receive ring at the right time. Rather than rely on TailMoved event, we introduce our own Disconnected notification event and have the receive thread wait on both. The Disconnected event is also usable as TUN_FLAGS_CONNECTED substitute. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-17Improve lock retention when sendingSimon Rozman1-44/+123
NDIS may call MINIPORT_SEND_NET_BUFFER_LISTS from parallel threads to queue as many packets as fast as possible. Initial implementation of ring buffers used a spin lock to completely serialize sending packets making it sub-optimal and burning large amount of CPU. This commit uses locked section to allocate space for packet(s) in the ring. It copies the packets unlocked, then it locks again to adjust the ring tail. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-17Spin for a bit before falling back to event objectJason A. Donenfeld1-8/+31
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-16Switch to ring buffers for exchanging packetsSimon Rozman3-846/+495
This demonstrates the use of ring buffers in its simplest, purest form. No performance optimizations were made. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-09README: correct path of deviceJason A. Donenfeld1-1/+1
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Shay Sharon <Shay.Sharon@audiocodes.com>
2019-07-08Rename remaining status -> Status and ctx -> CtxSimon Rozman1-19/+19
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-05Remove TunMapIrpJason A. Donenfeld1-28/+8
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-05Simplify ActiveNblCount decrementJason A. Donenfeld1-12/+7
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-05Rename NBL -> NblOdd Stranne1-34/+34
Signed-off-by: Odd Stranne <odd@mullvad.net>
2019-07-05Rename labels to be more consistentOdd Stranne1-49/+48
Signed-off-by: Odd Stranne <odd@mullvad.net>
2019-07-05Make error branching more compactOdd Stranne1-41/+29
Signed-off-by: Odd Stranne <odd@mullvad.net>
2019-07-05Treat ReferenceCount as an atomicJason A. Donenfeld1-1/+1
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-05Cleanup atomic gettersJason A. Donenfeld1-20/+39
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-05Version bump0.4Jason A. Donenfeld1-2/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-05Return with proper error status for bad addressJason A. Donenfeld1-1/+1
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-05Do not take extra ActiveNBL when holding TransitionLockJason A. Donenfeld1-5/+1
The transition lock ensures that TunPause won't drop its last reference until the shared transition lock is dropped. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-05Do not complete pause if we're not runningJason A. Donenfeld1-43/+17
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-05Decrease alignment requirements to 4Jason A. Donenfeld3-14/+11
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-05Do not use _RESOURCES but rather allocate our own copyJason A. Donenfeld2-35/+42
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Fixes: 09dc932 ("Create copies of NBLs to complete them faster")
2019-07-04Add _IRQL_requires_same_ support to clang formattingSimon Rozman2-6/+13
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-04Declare TUN_MEMORY_TAG in network-byte orderSimon Rozman1-9/+10
...due to popular demand. Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-04CleanupSimon Rozman1-4/+3
Signed-off-by: Simon Rozman <simon@rozman.si>
2019-07-04Version bump0.3Jason A. Donenfeld1-2/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-04Create copies of NBLs to complete them fasterJason A. Donenfeld1-3/+3
It turns out that waiting for them to come back in the return function introduces extremely high latency. We need to eventually stop doing this and move to a proper ring buffer. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Reorder ReturnNBL and DispatchWriteJason A. Donenfeld1-36/+36
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Receiving happens at dispatch level due to transition lockJason A. Donenfeld1-12/+10
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Read userspace packet size once, before checksJason A. Donenfeld1-8/+10
Otherwise userspace can twiddle things between checks. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Use NDIS variable style for localsJason A. Donenfeld1-465/+471
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Use only multi-line commentsJason A. Donenfeld1-37/+36
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Account for device removal before initializationJason A. Donenfeld1-0/+2
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Use synchronize_rcu()-like semantics for exclusive transition lockJason A. Donenfeld1-8/+12
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Fix up comment about replacement for ->ReservedJason A. Donenfeld1-3/+6
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Simplify IRP processing after mappingJason A. Donenfeld1-52/+13
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-07-03Allow buffer mapping to happen concurrentlyJason A. Donenfeld1-17/+39
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>