lokinet/llarp/win32/windivert.hpp
Jason Rhinelander 9ddf7413af
Windows DNS fixes
- windivert was being set up *before* DNS is set up, so the DNS port was
  nullopt and thus we couldn't properly identify upstream DNS traffic.
- close() doesn't close a socket on Windows, so the socket-bind-close
  approach to get a free UDP port wasn't actually closing, and thus
  unbound upstream constrained to the given port were completely
  failing.
- The unbound thread was accessing the same shared_ptr instance as the
  outer code, which isn't thread-safe; changed it to copy a weak_ptr
  into the lambda instead.
- Exclude upstream DNS traffic in the filter rather than capturing and
  reinjecting it.
2022-09-19 20:26:37 -03:00

22 lines
761 B
C++

#pragma once
#include <memory>
#include <string>
#include <windows.h>
#include <llarp/vpn/i_packet_io.hpp>
namespace llarp::win32::WinDivert
{
/// format an ipv4 in host order to string such that a windivert filter spec can understand it
std::string
format_ip(uint32_t ip);
/// create a packet interceptor that uses windivert.
/// filter_spec describes the kind of traffic we wish to intercept.
/// pass in a callable that wakes up the main event loop.
/// we hide all implementation details from other compilation units to prevent issues with
/// linkage that may arrise.
std::shared_ptr<llarp::vpn::I_Packet_IO>
make_interceptor(const std::string& filter_spec, std::function<void(void)> wakeup);
} // namespace llarp::win32::WinDivert