Commit Graph
44 Commits
Author SHA1 Message Date
basil00 54e627e82b Add byte ordering helper functions to WinDivert.
Some sample programs were linking to WinSock2
just for ntohl()/ntohs().  This dependency can
now be removed.
2018-11-16 07:50:04 +08:00
basil00 67ad628a1f Add pseudo-random pkt matching to WinDivert (#156)
- Adds 3 new "pseudo-random" filter expressions:
  * random8 (8bit)
  * random16 (16bit)
  * random32 (32bit)
  Not really "random", but these values are based
  on a hash of the packet headers & timestamp.
  These are useful for traffic sampling, e.g.:
  "random8 < 100" matches ~39% of all packets.
- Add new WinDivertHelperHashPacket() helper
  function.  The algorithm is an xxHash variant.
2018-11-14 09:40:17 +08:00
basil00 312050accb Add a new WinDivertShutdown() function (#156).
This function allows the user application to
"shutdown" a handle in anticipation of a
call to WinDivertClose().  When a handle has
been shutdown, new packets will no longer be
queued.  However, existing queued packets can
still be read by WinDivertRecv().  When the
queue is emptied, WinDivertRecv() will fail
with ERROR_NO_DATA.

The WinDivertShutdown() function is analogous
to the shutdown() socket function.

This change also simplifies events.
2018-11-11 09:44:24 +08:00
basil00 3e40705178 Fix address formatting in sample programs. 2018-11-05 09:44:25 +08:00
basil00 1ccf486132 Calculate full checksums for reinjected packets. 2018-11-04 08:47:39 +08:00
basil00 4f7ff88664 Add batched recv/send to WinDivert (#156).
This change allows multiple packets to be
received/sent at once, reducing overheads.  To
exploit this feature, applications need to use
the WinDivertRecvEx()/WinDivertSendEx()
functions with the new addrLen parameter.  The
passthru example has been modified to use
batching.

The DEBUG flag has been retired since it
conflicts with batching, and was not very
useful anyway.
2018-11-03 08:40:34 +08:00
basil00 3966ec1287 Add a WINDIVERT_FLAG_PARTIAL flag.
This suppresses ERROR_INSUFFICIENT_BUFFER errors
if the passed buffer is too small.  Applications
can set this flag if they want to do partial
reads.
2018-10-30 08:56:43 +08:00
basil00 de4245f95e Event & REFLECT layer fixes.
- Make event bitwise-OR-able.
- Simplify event names.
- Fix REFLECT serialization.
  (setting AutomaticSerialization=TRUE does not
   work.)
- Preallocate REFLECT memory.
2018-10-29 05:40:03 +08:00
basil00 fd75e6d42a Add a new SOCKET layer to WinDivert (see #156).
Adds a new SOCKET layer for monitoring socket
events, such as BIND, LISTEN, CONNECT,
and ACCEPT.  These events occur before the
flow is established (and unlike the FLOW layer)
it is possible to block/drop SOCKET events.

Otherwise, this layer is very similar to the
FLOW layer, so the PID is available and injection
is not possible.  This commit should be
considered to be a WIP.

Other changes:
- New socketdump.exe sample.  Prints socket
  events.
- Improve IPv6 address parsing.
- New helper functions:
  * WinDivertHelperFormatIPv4Address
  * WinDivertHelperFormatIPv6Address
- Fix REFLECT bugs.
- The network 5-tuple can now be accessed at
  the NETWORK layer.
- Various cleanups.
2018-10-25 10:25:41 +08:00
basil00 2ab1ddf1d2 Make it possible to filter based on events.
E.g., "event == FLOW_ESTABLISHED".
2018-10-22 08:38:12 +08:00
basil00 f0dd1224b1 Add a new REFLECT layer to WinDivert (see #156).
Adds a new REFLECT layer for monitoring WinDivert
handles.  This includes:
- three new REFLECT events: ESTABLISHED, OPEN and
  CLOSE;
- modifying the ADDRESS for REFLECT data:
  open time, process-id, layer, flags, and
  priority of the opened handle; and
- allowing WinDivertRecv() to read a
  representation of the opened filter.

This change also includes a new "object"
representation for WinDivert filter strings.
The API has been updated as follows:
- WinDivertHelperCompileFilter (replaces
  CheckFilter) compiles filter strings into the
  object form; and
- WinDivertHelperFormatFilter can "decompile" an
  object back into a human-readable filter
  string.

Other:
- New NO_INSTALL flag.
- New windivertctl.exe sample program.
2018-10-21 10:12:19 +08:00
basil00 6250568974 Add a new FLOW layer into WinDivert.
Adds a new WINDIVERT_LAYER_FLOW layer that can:
- Track when flows are established
- Track when existing flows are deleted
2018-09-30 09:07:16 +08:00
basil00 822dca9c3f Use snprintf() instead of sprintf_s().
The latter does not seem to work for MINGW.
2018-07-03 09:37:14 +08:00
basil00 6ac22c1650 Retire MSVC-2012 and (non-driver) WDDK builds.
The new MINGW build should be compatible with all
major compilers, including Visual Studio 201X.
2018-07-02 19:23:49 +08:00
basil00 1543e958e6 Dual-license WinDivert under the LGPLv3 and GPLv2.
This allows projects that are strictly "GPLv2
only" to use WinDivert without licensing issues.
See the FSF's compatibility matrix here:
https://www.gnu.org/licenses/gpl-faq.en.html

This change does not affect existing projects
that can continue to use the LGPLv3 as before.

Also, bump the WinDivert version to 1.4.1.
2018-04-04 18:41:45 +08:00
basil00 a67886e4b4 Fix passthru bug introduced by recent commit. 2018-01-16 00:14:09 +08:00
basil00 e2106ea2c6 Allow an optional priority argument for passthru. 2018-01-13 16:21:17 +08:00
basil00 aea3a3a858 Add support for pseudo IP/TCP/UDP checksums.
Most NIC cards support checksum offloading,
meaning that it is not necessary to calculate the
full IP/TCP/UDP checksums for injected packets.
WINDIVERT_ADDRESS has been extended to include 3
extra flags that indicate if the packet has full
or pseudo checksums.  This is a WIP.
2017-11-09 22:11:13 +08:00
basil00 bbf6a34aa6 Add Loopback and Timestamp fields to addresses.
- Loopback=1 for loopback packets, 0 otherwise.
- Timestamp is the time when packet captured.
2017-11-05 12:12:19 +08:00
basil00 135e084ef7 Minor bugfix (streamdump). 2016-01-31 19:42:06 +08:00
basil00 3386987f6a Fix compilation of streamdump for MSVC. 2016-01-31 17:21:44 +08:00
basil00 cd1bfff998 Bump copyright year. 2016-01-19 11:15:48 +08:00
basil00 7cfc3e2e72 Further integrate the streamdump sample.
Untested.
2016-01-19 10:57:47 +08:00
basil00 eda0a86589 Add a new sample program: streamdump
Streamdump demonstrates how to handle streams using WinDivert.

This is a WIP.
2016-01-11 10:36:10 +08:00
basil00 609ab63594 Add a NO_REPLACE for WinDivertHelperCalcChecksums
The WINDIVERT_HELPER_NO_REPLACE flag tells WinDivertHelperCalcChecksums not to
recalculate and replace non-zero checksum fields.  This is useful for
reconstructing the checksums for packets returned by WinDivertRecv(), where
all non-zero checksum fields are already valid.  This allows WinDivert1.2
to achieve similar efficiency as WinDivert1.1, where checksums were calculated
by the driver.

Note that for modified packets, the WINDIVERT_HELPER_NO_REPLACE flag should
not be used, as all checksums need to be recalculated from scratch anyway.
2015-07-25 13:24:28 +08:00
basil00 3bcf1ae7a0 Update samples & test programs to the new version. 2015-07-19 11:40:02 +08:00
basil00 130e25c05b Bump copyright year. 2015-07-17 19:13:55 +08:00
basil00 874d147b9b - Update copyright year.
- Use exact version number in driver binary.
2014-03-24 18:15: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 8878d79300 - Fix Issue #7 2013-11-30 12:56:36 +08:00
basil00 38f1f3a16d - Towards WinDivert 1.1:
* Re-brand "DIVERT" to "WINDIVERT" throughout the code-base.
* New flags:
  > WINDIVERT_FLAG_PASSTHRU: Do not drop nor capture packets.  Useful
    for injection-only handles.
  > WINDIVERT_FLAG_NO_CHECKSUM: Do not guarantee that diverted packets
    have a correct checksum.
  NOTE: Not yet tested!
* New default values and limits for various WinDivert parameters,
  including WINDIVERT_PARAM_QUEUE_LEN, WINDIVERT_PARAM_QUEUE_TIME, and
  the maximum filter length.
* New extended WinDivert functions that support asynchronous I/O:
  > WinDivertRecvEx(..)
  > WinDivertSendEx(..)
  NOTE: Not yet tested!
* The WinDivert driver now services reads (receives) out-of-band.
  The motivation is because WFP callouts are run at DISPATCH_LEVEL, so
  we should not be doing expensive work in the ClassifyFn.  This is also
  the same reason why the filter length has been restricted.
2013-06-30 15:58:21 +08:00
basil00 e0e1feabad - Update support to Visual Studio 2012. 2013-06-25 23:22:41 +08:00
Daan Raman 0266a1048f Type error compiling examples on VS2012
Casting the divert layer argument for the DivertOpen function resolves
a type error in VS2012.
2013-03-07 11:40:13 +01:00
basil00 89bf2fb622 - New VERSION 1.0.2
- Add a CHANGELOG
- Add note to webfilter.c
- CHANGELOG and VERSION now included in release packages.
2012-12-25 18:26:23 +08:00
basil00 498fbaab98 - MSVC build system now supports x64
- passthru.c now compiles on all 3 compilers.
2012-03-31 18:32:01 +08:00
basil00 53b45c4e8c - Complete build-system revamp.
* Updated sources files to target install\WDDK
  * Remove wdfinstaller.h dependency from dll/divert.dll
  * Fix passthru error in newer compilers.
2012-03-27 17:39:46 +08:00
basil00 6dfed99c28 Build system revamp:
- VS2010 support added via msvc-build.bat and *.vcxproj files
- MinGW now also builds example programs
- Documentation and examples are now included in the binary packages
2012-03-26 21:55:55 +08:00
basil00 f9b1619adb - Fix bad priority in the webfilter sample.
- Minor comments tweaks.
2012-02-22 11:00:05 +08:00
basil00 13b2ab4418 ***MAJOR UPDATE***
Name and version:

* Now officially called 'WinDivert'
* Now officially working towards a version 1.0 release

New features:

* WinDivert now supports a packet-sniffing mode.  This mode merely
  copies packets, and does not drop the original.
* WinDivert now also supports a packet-dropping mode.
* WinDivert now supports filter priorities.
* WinDivert now supports a forwarded packet layer (WARNING: untested).
* WinDivert now supports get/set parameters such as packet queue length and
  time.
* WinDivert now supports larger filters (but use at own risk).
* WinDivert now uninstalls the driver on program exit/library unload
* Different versions of WinDivert can co-exist on the same machine
  (WARNING: untested, as there is currently only one version).

New License:

* WinDivert is now LGPL.  This is less restrictive than the GPL so WinDivert
  can be linked to by commercial software (under the terms of the LGPL
  license).

Technical:

* Cleaner IOCTL interface.
* Cleaner driver implementation.
* Thread local events in WinDivert.dll
* Many minor tweaks and fixes.
2012-02-21 23:18:45 +08:00
basil00 a205259bec - Divert driver and library now fully support multi-threaded code. This
includes making the driver handle I/O requests in parallel, and changing
  the library such that it uses overlapped I/O.  Overall the package is
  now significantly faster.
- The divert driver now only adds WFP callouts when a filter is set,
  instead of when a handle is created.
- The divert driver now attempts to avoid adding WFP callouts that are
  superfluous with respect to the filter.
- The divert driver now explicitly deletes filters and callouts during
  cleanup.  This appears to resolve a bug where network connectivity is
  sometimes lost.
- Added a new sample program: passthru.exe.  This example doesn't do anything
  interesting but is useful for speed testing.
- Rename build.sh to mingw-build.sh to avoid confusion.
2011-11-08 23:54:01 +08:00
basil00 0ff63cda99 - Make the package compile for i386
- Make the pAddr arg for DivertRecv() optional
- Make the i386 user binaries compatible with an amd64 driver.
  (useful for projects not yet ported to amd64)
2011-08-23 22:18:02 +08:00
basil00 ee386df032 Figured out a way to split the "address" part of the buffer from the packet
data itself.  This makes for a much cleaner interface.

sys/divert.c
dll/divert.c
include/*.h
	DivertRecv and DivertSend now use IOCTLs instead of reads/writes.
	The 'address' parameter is passed by pointer to the driver, which
	writes directly to it (after sanity checks).
	This means that the data buffer now only contains the packet, which
	help to avoid some messy code.

examples/*/*.c
	Update the examples to reflect the new API.

doc/divert.html
	Update the documentation to reflect the new API.
2011-08-21 17:59:13 +08:00
basil00 019f9d509b First commit of the Windows Divert project 2011-08-19 20:11:17 +08:00