| Commit message (Collapse) | Author | Age | Files | Lines |
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
Query the service state with `sc query windivert` at startup, as this
is observed to resolve the bad state described in commit 168a88b8
("windows: fix some kind of race").
This is a defensive measure against the driver uninstall introduced by
that commit. Normally the uninstall is attempted only after all
handles opened by the current process are closed, but if another
process still holds an open WinDivert handle at that point, the driver
can remain stuck in a bad state on subsequent runs.
Link: https://github.com/basil00/WinDivert/issues/406
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
| |
Uninstalling before all handles were closed resulted in a os error
1058 when try to open windivert. (sc stop windivert fixed it)
Assumed the uninstallation would fail if the handle was still
active, but it seems the initial uninstallation actually succeeded,
while the subsequent attempt to close the remaining handles failed.
Closing send handle that hadn't been closed previously and then
explicitly performed the uninstallation fixes the issue.
|
| |
|
|
|
|
|
| |
This allows the WinDivert.sys can be removed after the program
terminates, without needing to run `sc stop windivert`.
Bug: https://github.com/dilluti0n/dpibreak/issues/21
|
| | |
|
| |
|
|
|
| |
This inturrupts blocking recv() calls resulting WinDivert service can
be safely removed.
|
| |
|
|
| |
See error message
|
| | |
|
| |
|
|
| |
Result should be unusable after Pkt is dropped, not rx is dropped.
|
| |
|
|
|
|
|
|
|
| |
While solving it, introduced Pkt abstraction so that advance() is
automatically executed upon dropping it.
This change still allows access to mmapped pointers within the
Pkt.net() and enables the addition of other slice fields (such as mac)
later.
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| |
|
|
|
|
|
|
|
| |
cleanup_rules() relies on the global flag IS_NFT_NOT_SUPPORTED, which
is always False before install_rule is called. Fixed it to always
attempt cleanup for ipt/ip6/nft at startup.
At the same time, implement Drop so that firewall cleanup occurs when
dies due to ?.
|
| | |
|
| |
|
|
|
|
| |
It would be better if libc_s did not provide signalfd. The
open_signalfd() function itself has issues, such as sigprocmask being
applied elsewhere before opening it.
|
| |
|
|
|
| |
This is likely new feature in kernel. (mayby 5.6 or something near
there)
|
| | |
|
| |
|
|
|
|
|
| |
Here mmap/munmap wrapper remain unsafe since mmap returns a pointer
causes a memory leak when munmap is not called while dropping, and
munmap has strict rule (PAGE_SIZE aligned) for addr defined on
munmap(2).
|
| | |
|
| |
|
|
|
|
|
|
|
| |
The existing implementation was unsafe because UB could occur if a
user-space pointer referenced by the struct sock_fprog was incorrectly
passed. Rust safe model allows pointer creation and makes
dereferencing unsafe. In this case, dereferencing happenes in
kernel-space, Rust cannot guarantee this. So it must be handled
separately.
|
| |
|
|
|
|
| |
Treating optval as just a &[u8] in setsockopt() is not appropriate for
usage patterns where a struct is put into optval. Rust treats casting
a struct to &[u8] as unsafe.
|
| | |
|
| | |
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
When I updated nix to 0.31, `nix::fcntl::flock` became deprecated and
unusable. At first I try to refactor `lock_pid_file()` to use the
`lock` method of the `nix::fcntl::Flock` struct, but a situation arose
where `set_len(0)` could not be called due to ownership issues. Linux
system calls are fundamentally simple, stable, and backward
compatible. Therefore, a compat layer is not necessary.
Anticipating that this might happen again, this commit introduce the
`libc_s`, which handles simple error processing for unsafe ffis in
libc syscall bindings.
|
| |
|
|
|
|
| |
Keeping poll_once() separate just caused more headaches. It was also
rebuilding the fds array every single time. Since poll() only
overwrites revents, doing that on every loop was totally unnecessary.
|
| |
|
|
|
|
| |
This integrates well with the main poll loop and removes the global
AtomicBool RUNNING, which previously did nothing but detect interrupts
before entering the loop.
|
| |
|
|
|
|
|
|
| |
When both fds are ready in the same wakeup, the SYN/ACK that triggered
rx_ready is causally prior to the ClientHello waiting in the nfqueue.
Process the rxring first so HopTab is populated before handle_packet
runs find_hop, reducing the race window for HopLookupError::NotFound
under load.
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previous BPF filter only matched IPv4 due to tcpdump failing to
generate a correct combined IPv4/IPv6 filter. Replaced with manually
split filter that handles both ip and ip6 paths.
Also increase FRAME_SIZE from 128 to 256 to resolve this error:
[WARNING] put_hop: IPv6 Packet Error: Not enough data to decode 'IPv6
packet'. 80 byte(s) would be required, but only 62 byte(s) are
available based on the slice length.
tpacket_hdr(~66) + eth(14) + ipv6(40) + tcp+options(60) = ~180 bytes,
which exceeded the previous 128-byte limit.
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| |
|
|
| |
This size is for windivert buffer, not internal pkt buffer capacity.
|
| |
|
|
|
|
|
|
|
| |
Replace generic spawn_recv with recv_loop macro that encapsulates the
buffer allocation and receive loop. Divert handle now runs directly on
the main thread, while sniff handle spawns a dedicated thread only when
fake_autottl is enabled. This eliminates the mpsc channel, Event enum,
and the race condition where concurrent open_handle calls during driver
initialization could cause error 1058.
|
| |
|
|
|
|
| |
Non-daemon mode exits via process::exit(0) on Ctrl-C, and daemon mode
is managed by SCM, so the RUNNING atomic flag and graceful shutdown
loop are both unnecessary. Remove them along with the ctrlc handler.
|
| |
|
|
|
|
|
|
|
|
| |
In non-daemon mode, WinDivert driver closes all handles on process
exit, so explicit cleanup is unnecessary. Call std::process::exit(0)
directly from the Ctrl-C handler instead of relying on RUNNING flag
and graceful shutdown loop.
Also move trap_exit() call before spawn_recv() to ensure the handler
is registered before any threads are spawned.
|
| |
|
|
|
|
|
|
| |
- Remove global RUNNING, trap_exit, EnsureCleanup, MESSAGE_AT_RUN from main.rs
- Move each into platform-specific modules (linux.rs, windows.rs)
- Move MESSAGE_AT_RUN to platform.rs
- Inline cleanup logic into run() instead of separate cleanup() fn
- Remove service_run_1() indirection in windows.rs
|
| | |
|
| |
|
|
|
|
| |
Move handle lifecycle into spawn_recv so each handle is properly
closed when RUNNING becomes false. Filter and flags are passed in
instead of a pre-opened handle.
|
| | |
|
| |
|
|
|
|
| |
windows: add cleanup for SEND_HANDLE
windows: fix every packet goes to send-only handle
|
| |
|
|
|
|
|
| |
Conditionally initialize rxring only when fake_autottl is enabled.
Extract poll_once() using libc::poll directly; fd=-1 trick eliminates
the need for conditional branching on optional rxring fd, as poll sets
revents=0 for negative fds per POSIX. Drop nix poll feature.
|