Commit Graph
68 Commits
Author SHA1 Message Date
basil00 c4575b7059 Prevent block-clone-inject infinite loops.
- A partial fix for #41
- Decrements the TTL for reinjected packets.
- If (TTL==0), WinDivertRecv() will fail with:
  ERROR_HOST_UNREACHABLE = 1232
  which is better than looping.
2017-10-18 15:47:50 +08:00
basil00 f5f3559ae9 Various improvements
- Support NonPagedPoolNx for Windows 8, 10.
- More aggressive context locking
- Set MAXWORKERS=1 (seems to perform best).
2017-10-16 22:56:38 +08:00
basil00 d778639cbe Optimizations & bug fixes.
- Immediately reinject in SNIFF mode.
- Use a NET_BUFFER pool for cloned packets.
- Fix bug caused by pool mix up for cloned packets.
- Copy NET_BUFFER_LIST info for non-matching packets.
- Keep reference to original NET_BUFFER_LIST after cloning.
  (might not be necessary, but some sample drivers do).
2017-10-13 06:47:15 +08:00
basil00 11b9a74341 Queued packets now use the PagedPool.
This is possible since IRQL=PASSIVE_LEVEL.
2017-10-11 20:44:01 +08:00
basil00 2e1bfa8ca5 WinDivert driver overhaul.
This is a major update designed to modernize the WinDivert driver, including
optimizations, design improvements and bug fixes.  The new version has not
been fully tested and should be considered **UNSTABLE**.

- Most of the packet processing is now (almost) fully out-of-band.  This is a
  good since the classify function runs at DISPATCH_LEVEL.  The driver will
  still try to match at least one packet before moving the work out-of-band.
- Re-injected non-matching packets are now clones rather than copies.
- Queued packets are still copied.  This is because the driver should avoid
  keeping a reference to the original packet for very long.  Since we do not
  trust the user application to handle the packet in a timely fashion, it is
  better to copy rather than keep a reference.  That said, the driver now
  implements an optimization where it will service a read request immediately
  if possible (saving 1 packet copy).
- SNIFF mode also now works differently.  Previously, SNIFF mode would not
  block the original packet.  However, this is problematic under the new
  design since WinDivert cannot permit the packet and retain a reference to it
  at the same time.  The new version will block & absorb the original packet
  and re-inject a clone out-of-band.
- Packet time management has been replaced.  Previously, a timer was used to
  periodically wake up a function that would sweep away expired packets.  The
  new version explicitly timestamps every packet, and expired packets are
  cleaned up by the read service routine.
- The context->filter is now deallocated in the destroy callback to avoid
  possible a race condition with the callout function.  It is unclear if this
  is really necessary, however.
2017-10-10 23:14:37 +08:00
basil00 910a2e3050 Add new WINDIVERT_PARAM_QUEUE_SIZE parameter.
Controls the number of bytes used by the packet queue.
2017-10-01 15:33:58 +08:00
basil00 e69cc09cce Update WinDivert sublayer GUIDs for version 1.3. 2017-09-24 16:24:37 +08:00
basil00 7b7d92cd26 Bump version to WinDivert 1.3.0
This prevents the old 1.2 driver from being used by new 1.3 software.

Also, clean up the driver code.
2017-09-24 15:48:38 +08:00
basil00 200da2fba1 Complete WinDivertSend() IO requests immediately.
Currently, WinDivert waits until injection completes before completing the
corresponding IO request.  However, packet injection may take an arbitrarily
long time, such as waiting for a user-mode application.

The new version completes the IO request immediately, provided the call to the
corresponding WFP packet injection function did not return an error, thus
eliminating the problem.  The disadvantage is that some packet injection
errors may no longer be detected.
2017-09-23 20:09:04 +08:00
basil00 c13a27bb4f Update CHANGELOG and VERSION 2017-09-23 16:54:58 +08:00
basil00 ea95889a30 Possible fix for issue #90. 2017-09-12 20:18:41 +08:00
Mike Neuman 504132080a Bugfix: If the user's app exits (or crashes) before calling CloseHandle()
on the WinDivert handle, the driver's cleanup function cannot make FWPM
calls. The cleanup function detects this FWPM error and returns
without ever calling the Fwps cleanup functions (which are independent
of fwpm).

As a result, the driver will not unregister the callouts, which leaves
the Windows kernel confused. You can reproduce the problem by having
a user app close uncleanly, then "sc stop windivert1.2", then try to
re-run the app. You'll get "file not found" when StartService() is called.
2017-08-15 09:32:44 -07:00
basil00 cd1bfff998 Bump copyright year. 2016-01-19 11:15:48 +08:00
basil00 657285bef6 CHANGELOG tweaks & remove old .inf file. 2015-07-26 11:06:32 +08:00
basil00 f0be301f1d Expand tests & bug fixes.
Extend the number of tests to cover some of the new features.
Fix IPv6 address comparison which did not work correctly in some cases.
2015-07-25 23:16:48 +08:00
basil00 3fcb692478 Ensure offloaded checksums are zero.
WinDivert now treats all offloaded checksum fields as zero:
- WinDivertRecv() will zero all offloaded checksum fields.
- Filter matching will treat offloaded fields as zero.
2015-07-25 12:05:23 +08:00
basil00 54f8640b89 Build & bug fixes.
- Make WinDivert compile again under WDK/MSVC.
- Fix undiscovered bug where ip.TOS (8-bit field) was passed to ntohs.
2015-07-18 16:46:21 +08:00
basil00 130e25c05b Bump copyright year. 2015-07-17 19:13:55 +08:00
basil00 fdd5825f5d Bump version to WinDivert 1.2
Bump version and change magic numbers to make the driver incompatible with
older versions.  Also cleanup some driver checksum code missed by previous
commit.
2015-07-17 18:24:30 +08:00
basil00 e247f01c43 Remove automatic checksum calculation & legacy API
- As discussed in #37, the WINDIVERT_FLAG_NO_CHECKSUM behavior has become the
  default.  This means that outbound packets returned by WinDivertRecv() are
  no longer guaranteed to have valid checksums, thanks to TCP checksum
  offloading by the Windows TCP/IP stack.  The checksums can still be
  recovered by calling WinDivertHelperCalcChecksums() manually.
- Remove the old WinDivert1.0 legacy API, as nobody should still be using it.
2015-07-02 21:19:27 +08:00
basil00 b452e1ce29 - Fix failing test case caused by bad word ordering. 2014-11-17 23:57:49 +08:00
basil00 bf19fdf2f9 - Add an ICMPv6 test packet.
- Fix missing byte-swaps for ICMPv6 fields.
- Todo: 1 test-case fails.
2014-11-17 19:25:17 +08:00
basil00 ecd9ae59d3 - Re-implement WinDivertHelperParseIPv6Address(). Previous version was just
too bug-prone, so re-try from scratch.  New version works for several tests.
- Fix broken WinDivertAToX().
- New test case: IPv6 TCP SYN.
2014-11-16 13:31:07 +08:00
basil00 48075e2e5f - Fix broken implementation of WinDivertHelperParseIPv6Address().
- Fix IPv6 address word/byte ordering between DLL and SYS.
2014-11-15 15:06:16 +08:00
basil00 72d83fcb07 - Fix incorrect IPv6 pseudo header definition in the driver. 2014-11-15 13:51:16 +08:00
basil00 8d98da751c - WinDivert driver now skips IPv6 extension headers when filtering packets.
- windivert_filter() now uses Ndis(Advance/Retreat)NetBufferDataStart() to
  find packet headers.
- NOTE: This new code is not yet very well tested.
2014-11-15 00:57:17 +08:00
basil00 0a70d4120d - Remove duplicate code from last commit. 2014-11-13 18:52:16 +08:00
basil00 4edd82f55f - Ignore the checksum info for loopback packets. This info seems to be
unreliable for whatever reason, so better to ignore until a better solution
  is found.
2014-11-13 18:47:46 +08:00
basil00 7235b687b3 - WinDivertHelperParsePacket() now skips IPv6 extension headers. 2014-11-10 19:16:33 +08:00
basil00 7952724127 - Driver now calculates checksums for IPv6 packets (fix issue #28).
- Bump version to 1.1.7
2014-11-09 12:44:21 +08:00
basil00 bbf06c9503 - Fix missing '\'. 2014-09-16 00:04:07 +08:00
basil00 d43aa57014 - Reduce number of work items to 2; 4 was overkill. 2014-09-15 23:48:32 +08:00
basil00 50aecbda75 - Towards version 1.1.6 2014-09-05 12:36:55 +08:00
basil00 9a13606030 - Insert WinDivert as the highest weighted sublayer. 2014-05-19 19:18:10 +08:00
basil00 98c4a51fad - Fix issue #18 that causes a BSOD when a NULL pointer is passed as an
address parameter to either WinDivertRecv or WinDivertSend.
- Use better NT_STATUS codes for some errors.
- Bump the version number to WinDivert 1.1.4
2014-04-02 19:40:54 +08:00
basil00 874d147b9b - Update copyright year.
- Use exact version number in driver binary.
2014-03-24 18:15:05 +08:00
basil00 4b708f0c16 - Wrap the sublayer/filter/callout setup in transactions. This appears to
make it less likely to break networking if something goes wrong.  It may
  also solve issue #15.
- Fix bug in last commit.
2014-03-23 22:33:46 +08:00
basil00 7f0e697092 - Fix bug (see issue #14) where some outbound TCP packets were never handled
by the classify function and silently dropped.  This can degrade outbound
  speed significantly, as it forces the Windows TCP/IP stack to re-send the
  missing data.  Thanks to GhalemB who found the bug & fix.
2014-03-23 11:18:05 +08:00
basil00 33f6bec1e5 - Refactor driver unload functions.
- Packet direction fix for netfilter example.
- Bump version to 1.1.2-rc.
2013-12-25 11:28:01 +08:00
basil00 57934712c6 - Refactor the WFP interface:
* WinDivert sublayers are created and inserted when the driver is loaded.
  * All WinDivert callouts are installed at the same sublayer.
- Clean-up the implementation of priorities.
- Re-introduce deep copying for SNIFF mode.  This avoids referencing the
  sniffed packets.
- Fix-up the netfilter example:
  * Don't send RSTs to RST/FINs, this can start a RST war.
  * Don't inject ICMP outbound - this may not be a problem despite 1233 errors.
2013-12-23 11:03:02 +08:00
basil00 4f81c315d6 - Use FwpsAllocateCloneNetBufferList0 for the packet queue, as opposed to
copying the data.
2013-12-18 16:28:58 +08:00
basil00 76459ac3fe - Use WDF work items instead of threads. Also use multiple work items so
that read_service() can be run in parallel.
2013-12-18 09:54:01 +08:00
basil00 6ac77a644b - Fix some bugs introduced by recent commits. 2013-12-13 17:09:37 +08:00
basil00 8c2bb01565 - Several changes to simplify the WinDivert Driver installation:
1) Remove the dependency on the WdfCoInstaller*.dll file.  This file appears
     to be unnecessary for Windows 7 and up, and for patched Vista+2008.
  2) Remove the WinDivert.inf file (only used by the co-installer).
  3) 32/64-bit versions of the driver are now explicitly named, meaning that
     the two can co-exist in the same directory.
  4) The 32-bit WinDivert.dll can now automatically load the 64-bit driver on
     64-bit Windows.  This means it is possible to write 32-bit WinDivert
     applications that automatically work on 64-bit windows.
  5) WinDivert.dll now schedules the WinDivert service to be deleted right
     away.  This should fix some cases where the service is never deleted,
     even during reboot.
  6) Updated build scripts to reflect the changes.
2013-12-10 22:48:11 +08:00
basil00 7f3bbe94ee - Copy most of the packet after error checking. 2013-12-03 08:43:05 +08:00
basil00 8c48b0f1dd - Fix issue #8 by replacing incorrect function call NdisFreeNetBufferPool()
with NdisAllocateNetBufferListPool().
- Removed some dead code.
- Cleanup handles if DriverEntry() fails.
- Bump version.
2013-12-03 08:11:19 +08:00
basil00 8a4c62d981 - Verify that injected packets have the correct length (after copying). 2013-11-30 12:37:08 +08:00
basil00 4b7e6a08bb - Simplify the WinDivert callout code: no longer handles multiple
NET_BUFFERs in a single NET_BUFFER_LIST.  Apparently this should only
  ever occur in the FORWARD layer in certain circumstances, and even then each
  fragment should be indicated individually anyway.  This change removes a lot
  of needless complexity.
2013-10-07 22:57:16 +08:00
basil00 3eed5aca39 - Writes (via WinDivertSend()) are now copied before being injected.
This ensures that the user program does not clobber the buffer before the
  injection is complete.
- Update the changelog.
2013-09-28 23:25:51 +08:00
basil00 a59c70ae0a - WinDivert now queues copies of packets, rather than simply referencing
the original packet.  The former turns out to be problematic, since there is
  no guarantee that something else (e.g. another callout driver)
  modifies/overwrites the packet data whilst it is in the queue.  Copying the
  data is not ideal either, but seems to be the only way to ensure the packet
  is not changed later.
2013-09-21 10:43:42 +08:00