Skip to content

Commit

Permalink
Merge pull request #13 from Rubensei/feature/add-tests
Browse files Browse the repository at this point in the history
Add basic test suite
  • Loading branch information
Rubensei authored Nov 3, 2024
2 parents c2afb5d + dc4039f commit 1ec7a47
Show file tree
Hide file tree
Showing 22 changed files with 1,476 additions and 311 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ on:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch: {}
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name || github.run_id }}
cancel-in-progress: true
name: check
name: check & test
jobs:
check:
runs-on: windows-latest
Expand All @@ -19,7 +20,7 @@ jobs:
compiler: [msvc, gnu]
feature: [vendored, static]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Install stable
Expand All @@ -28,11 +29,13 @@ jobs:
targets: x86_64-pc-windows-${{ matrix.compiler }}
- name: cargo check
run: cargo check --target x86_64-pc-windows-${{ matrix.compiler }} --features ${{ matrix.feature }}
- name: cargo test
run: cargo test --target x86_64-pc-windows-${{ matrix.compiler }} --features ${{ matrix.feature }}
doc:
runs-on: windows-latest
name: docs / stable
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Install stable
Expand All @@ -48,9 +51,9 @@ jobs:
strategy:
fail-fast: false
matrix:
msrv: [1.64]
msrv: ["1.74"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Install stable
Expand Down
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,34 @@ and this project adheres to

### Added

- Add `wait` methods back
- Add `wait` recv methods back
- Partial single recv `WinDivert::partial_recv()`
- `WinDivertSendError`
- Add `WinDivert<()>::install(path: &Path)`
- Internal abstractions over low level apis to facilitate testing

### Changed

- MSRV bumped to 1.74
- `WinDivertError` has a `Send` variant
- `WinDivert::recv()` and `WinDivert::recv_ex()` buffer made mandatory on data
capturing layers and removed from non capturing layers.
capturing layers and removed from non-capturing layers.
- Bumped `windows-rs` to 0.51.1
- Code refactor and cleanup
- Removed IOError variant from `WinDivertError`

### Fixed

- All generic OS errors will be properly handled as `WinDivertError::OsError`

## [Unreleased-sys]

### Changed

- Bumped `windows-rs` to 0.51.1
- Remove `windows` to decouple this crate from `windows-sys`
- Replace `std::os::raw` with `core::ffi`
- Fix typo in enum variant name: `WinDivertEvent::FlowStablished` to
`WinDivertEvent::FlowEstablished`

## [0.6.0]

Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["windivert-sys", "windivert"]
resolver = "2"
members = ["windivert-sys", "windivert"]
8 changes: 2 additions & 6 deletions windivert-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "windivert-sys"
version = "0.11.0-alpha.1"
version = "0.11.0-alpha.3"
description = "Raw FFI bindings for WinDivert user mode library"
authors = ["Ruben Serrano Izquierdo <rserranoizq@gmail.com>"]
repository = "https://github.com/Rubensei/windivert-rust.git"
Expand All @@ -11,7 +11,7 @@ categories = ["external-ffi-bindings"]
readme = "../README.md"
license = "LGPL-3.0-or-later"
edition = "2021"
rust-version = "1.64"
rust-version = "1.61"
links = "WinDivert"
build = "build/main.rs"

Expand All @@ -26,10 +26,6 @@ static = ["vendored"]
[dependencies]
thiserror = "1"

[dependencies.windows]
version = "0.51.1"
features = ["Win32_Foundation", "Win32_System_IO"]

[build-dependencies]
cc = "1.0"

Expand Down
110 changes: 54 additions & 56 deletions windivert-sys/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ pub mod header;
pub mod ioctl;

mod bitfield;
use std::ffi::c_void;

pub(crate) use bitfield::BitfieldUnit;
mod error;
pub use error::*;
mod newtypes;
pub use newtypes::*;

use windows::Win32::{
Foundation::{BOOL, HANDLE},
System::IO::OVERLAPPED,
};
/// Default value for queue length parameter.
pub const WINDIVERT_PARAM_QUEUE_LENGTH_DEFAULT: u64 = 4096;
/// Minimum valid value for queue length parameter.
Expand Down Expand Up @@ -49,71 +44,77 @@ pub const WINDIVERT_MTU_MAX: u32 = 65575;
extern "C" {
/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_open)
pub fn WinDivertOpen(
filter: *const ::std::os::raw::c_char,
filter: *const core::ffi::c_char,
layer: WinDivertLayer,
priority: i16,
flags: WinDivertFlags,
) -> HANDLE;
) -> std::os::windows::raw::HANDLE;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_recv)
pub fn WinDivertRecv(
handle: HANDLE,
pPacket: *mut ::std::os::raw::c_void,
handle: *mut core::ffi::c_void,
pPacket: *mut core::ffi::c_void,
packetLen: u32,
pRecvLen: *mut u32,
pAddr: *mut address::WINDIVERT_ADDRESS,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_recv_ex)
pub fn WinDivertRecvEx(
handle: HANDLE,
pPacket: *mut ::std::os::raw::c_void,
handle: *mut core::ffi::c_void,
pPacket: *mut core::ffi::c_void,
packetLen: u32,
pRecvLen: *mut u32,
flags: u64,
pAddr: *mut address::WINDIVERT_ADDRESS,
pAddrLen: *mut u32,
lpOverlapped: *mut OVERLAPPED,
) -> BOOL;
lpOverlapped: *mut core::ffi::c_void,
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_send)
pub fn WinDivertSend(
handle: HANDLE,
pPacket: *const ::std::os::raw::c_void,
handle: *mut core::ffi::c_void,
pPacket: *const core::ffi::c_void,
packetLen: u32,
pSendLen: *mut u32,
pAddr: *const address::WINDIVERT_ADDRESS,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_send_ex)
pub fn WinDivertSendEx(
handle: HANDLE,
pPacket: *const ::std::os::raw::c_void,
handle: *mut core::ffi::c_void,
pPacket: *const core::ffi::c_void,
packetLen: u32,
pSendLen: *mut u32,
flags: u64,
pAddr: *const address::WINDIVERT_ADDRESS,
addrLen: u32,
lpOverlapped: *mut OVERLAPPED,
) -> BOOL;
lpOverlapped: *mut core::ffi::c_void,
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_shutdown)
pub fn WinDivertShutdown(handle: HANDLE, how: WinDivertShutdownMode) -> BOOL;
pub fn WinDivertShutdown(handle: *mut core::ffi::c_void, how: WinDivertShutdownMode) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_close)
pub fn WinDivertClose(handle: HANDLE) -> BOOL;
pub fn WinDivertClose(handle: *mut core::ffi::c_void) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_set_param)
pub fn WinDivertSetParam(handle: HANDLE, param: WinDivertParam, value: u64) -> BOOL;
pub fn WinDivertSetParam(
handle: *mut core::ffi::c_void,
param: WinDivertParam,
value: u64,
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_get_param)
pub fn WinDivertGetParam(handle: HANDLE, param: WinDivertParam, pValue: *mut u64) -> BOOL;
}
pub fn WinDivertGetParam(
handle: *mut core::ffi::c_void,
param: WinDivertParam,
pValue: *mut u64,
) -> i32;

extern "C" {
/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_parse_packet)
pub fn WinDivertHelperParsePacket(
pPacket: *const ::std::os::raw::c_void,
pPacket: *const core::ffi::c_void,
packetLen: u32,
ppIpHdr: *mut header::PWINDIVERT_IPHDR,
ppIpv6Hdr: *mut header::PWINDIVERT_IPV6HDR,
Expand All @@ -122,84 +123,81 @@ extern "C" {
ppIcmpv6Hdr: *mut header::PWINDIVERT_ICMPV6HDR,
ppTcpHdr: *mut header::PWINDIVERT_TCPHDR,
ppUdpHdr: *mut header::PWINDIVERT_UDPHDR,
ppData: *mut c_void,
ppData: *mut core::ffi::c_void,
pDataLen: *mut u32,
ppNext: *mut c_void,
ppNext: *mut core::ffi::c_void,
pNextLen: *mut u32,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_hash_packet)
pub fn WinDivertHelperHashPacket(
pPacket: *const ::std::os::raw::c_void,
pPacket: *const core::ffi::c_void,
packetLen: u32,
seed: u64,
) -> u64;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_parse_ipv4_address)
pub fn WinDivertHelperParseIPv4Address(
addrStr: *const ::std::os::raw::c_char,
addrStr: *const core::ffi::c_char,
pAddr: *mut u32,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_parse_ipv6_address)
pub fn WinDivertHelperParseIPv6Address(
addrStr: *const ::std::os::raw::c_char,
addrStr: *const core::ffi::c_char,
pAddr: *mut u32,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_format_ipv4_address)
pub fn WinDivertHelperFormatIPv4Address(
addr: u32,
buffer: *mut ::std::os::raw::c_char,
buffer: *mut core::ffi::c_char,
bufLen: u32,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_format_ipv6_address)
pub fn WinDivertHelperFormatIPv6Address(
pAddr: *const u32,
buffer: *mut ::std::os::raw::c_char,
buffer: *mut core::ffi::c_char,
bufLen: u32,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_calc_checksums)
pub fn WinDivertHelperCalcChecksums(
pPacket: *mut ::std::os::raw::c_void,
pPacket: *mut core::ffi::c_void,
packetLen: u32,
pAddr: *mut address::WINDIVERT_ADDRESS,
flags: ChecksumFlags,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_dec_ttl)
pub fn WinDivertHelperDecrementTTL(
pPacket: *mut ::std::os::raw::c_void,
packetLen: u32,
) -> BOOL;
pub fn WinDivertHelperDecrementTTL(pPacket: *mut core::ffi::c_void, packetLen: u32) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_compile_filter)
pub fn WinDivertHelperCompileFilter(
filter: *const ::std::os::raw::c_char,
filter: *const core::ffi::c_char,
layer: WinDivertLayer,
object: *mut ::std::os::raw::c_char,
object: *mut core::ffi::c_char,
objLen: u32,
errorStr: *mut *const ::std::os::raw::c_char,
errorStr: *mut *const core::ffi::c_char,
errorPos: *mut u32,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_eval_filter)
pub fn WinDivertHelperEvalFilter(
filter: *const ::std::os::raw::c_char,
pPacket: *const ::std::os::raw::c_void,
filter: *const core::ffi::c_char,
pPacket: *const core::ffi::c_void,
packetLen: u32,
pAddr: *const address::WINDIVERT_ADDRESS,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_format_filter)
pub fn WinDivertHelperFormatFilter(
filter: *const ::std::os::raw::c_char,
filter: *const core::ffi::c_char,
layer: WinDivertLayer,
buffer: *mut ::std::os::raw::c_char,
buffer: *mut core::ffi::c_char,
bufLen: u32,
) -> BOOL;
) -> i32;

/// Check the official [docs](https://reqrypt.org/windivert-doc.html#divert_helper_ntoh)
pub fn WinDivertHelperNtohs(x: u16) -> u16;
Expand Down
2 changes: 1 addition & 1 deletion windivert-sys/src/bindings/newtypes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{convert::TryFrom, u32};
use std::convert::TryFrom;

use super::WinDivertValueError;

Expand Down
Loading

0 comments on commit 1ec7a47

Please sign in to comment.