aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* Use explicit running boolean and use set instead of exchangeJason A. Donenfeld2019-07-311-24/+31
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Assert that adapter is always running when client is registering ringsSimon Rozman2019-07-311-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>
* Cleanup TUN_FLAGS_PRESENTSimon Rozman2019-07-311-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>
* Add handle closing ioctlJason A. Donenfeld2019-07-315-11/+131
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Reinitialize active NBL remove lock to allow adapter reuseSimon Rozman2019-07-311-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>
* Compile on 32-bit and arm64Jason A. Donenfeld2019-07-191-6/+8
| | | | | | No popcnt intrinsic on arm, no PopulationCount64 function on 32bit. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Use more specific IOCTL codeJason A. Donenfeld2019-07-192-3/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Require the usual SDDL_DEVOBJ_SYS_ALL permissionsJason A. Donenfeld2019-07-181-36/+96
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Make receiving NBLs asynchronousSimon Rozman2019-07-181-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>
* Minimize TransitionLock when receiving packetsSimon Rozman2019-07-181-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>
* Fix insane coding styleJason A. Donenfeld2019-07-181-2/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Fix awkward comment styleJason A. Donenfeld2019-07-181-3/+3
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Do not hijack PNP notifierJason A. Donenfeld2019-07-181-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>
* Switch to paged dispatch handlersJason A. Donenfeld2019-07-181-4/+7
| | | | | | We're not totally sure this is kosher, unfortunately. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Minimize TransitionLock when sending packetsSimon Rozman2019-07-181-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>
* Piggy-back on top of NDIS' device object instead of adding our ownJason A. Donenfeld2019-07-186-333/+86
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* README: clarify ring usageJason A. Donenfeld2019-07-171-32/+41
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Replace TUN_FLAGS_CONNECTED by an eventSimon Rozman2019-07-171-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>
* Improve lock retention when sendingSimon Rozman2019-07-171-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>
* Spin for a bit before falling back to event objectJason A. Donenfeld2019-07-171-8/+31
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Switch to ring buffers for exchanging packetsSimon Rozman2019-07-163-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>
* README: correct path of deviceJason A. Donenfeld2019-07-091-1/+1
| | | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Shay Sharon <Shay.Sharon@audiocodes.com>
* Rename remaining status -> Status and ctx -> CtxSimon Rozman2019-07-081-19/+19
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* Remove TunMapIrpJason A. Donenfeld2019-07-051-28/+8
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Simplify ActiveNblCount decrementJason A. Donenfeld2019-07-051-12/+7
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Rename NBL -> NblOdd Stranne2019-07-051-34/+34
| | | | Signed-off-by: Odd Stranne <odd@mullvad.net>
* Rename labels to be more consistentOdd Stranne2019-07-051-49/+48
| | | | Signed-off-by: Odd Stranne <odd@mullvad.net>
* Make error branching more compactOdd Stranne2019-07-051-41/+29
| | | | Signed-off-by: Odd Stranne <odd@mullvad.net>
* Treat ReferenceCount as an atomicJason A. Donenfeld2019-07-051-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Cleanup atomic gettersJason A. Donenfeld2019-07-051-20/+39
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Version bump0.4Jason A. Donenfeld2019-07-051-2/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Return with proper error status for bad addressJason A. Donenfeld2019-07-051-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Do not take extra ActiveNBL when holding TransitionLockJason A. Donenfeld2019-07-051-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>
* Do not complete pause if we're not runningJason A. Donenfeld2019-07-051-43/+17
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Decrease alignment requirements to 4Jason A. Donenfeld2019-07-053-14/+11
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Do not use _RESOURCES but rather allocate our own copyJason A. Donenfeld2019-07-052-35/+42
| | | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Fixes: 09dc932 ("Create copies of NBLs to complete them faster")
* Add _IRQL_requires_same_ support to clang formattingSimon Rozman2019-07-042-6/+13
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* Declare TUN_MEMORY_TAG in network-byte orderSimon Rozman2019-07-041-9/+10
| | | | | | ...due to popular demand. Signed-off-by: Simon Rozman <simon@rozman.si>
* CleanupSimon Rozman2019-07-041-4/+3
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* Version bump0.3Jason A. Donenfeld2019-07-041-2/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Create copies of NBLs to complete them fasterJason A. Donenfeld2019-07-041-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>
* Reorder ReturnNBL and DispatchWriteJason A. Donenfeld2019-07-031-36/+36
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Receiving happens at dispatch level due to transition lockJason A. Donenfeld2019-07-031-12/+10
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Read userspace packet size once, before checksJason A. Donenfeld2019-07-031-8/+10
| | | | | | Otherwise userspace can twiddle things between checks. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Use NDIS variable style for localsJason A. Donenfeld2019-07-031-465/+471
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Use only multi-line commentsJason A. Donenfeld2019-07-031-37/+36
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Account for device removal before initializationJason A. Donenfeld2019-07-031-0/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Use synchronize_rcu()-like semantics for exclusive transition lockJason A. Donenfeld2019-07-031-8/+12
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Fix up comment about replacement for ->ReservedJason A. Donenfeld2019-07-031-3/+6
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* Simplify IRP processing after mappingJason A. Donenfeld2019-07-031-52/+13
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>