Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ In DNS `Proxy` mode, DNS takes precedence over LAN bypass: a query addressed to

## Local listener replies and TCP close handling

ProxiFyre redirects a matched connection to a local listener and translates the listener's replies back before the application sees them. Two rules apply to every proxied connection, not only to DNS:
ProxiFyre redirects a matched connection to a local listener and translates the listener's replies back before the application sees them. Three rules apply to every proxied connection, not only to DNS:

- **A reply that cannot be translated back is dropped.** A reply from a local listener is addressed to the original server only because redirection swapped the addresses, so it must never reach the network. It is dropped when its TCP connection or UDP endpoint is no longer tracked, when it is the first fragment of a fragmented reply, or when its SOCKS5 relay header is malformed or of the other address family. Earlier releases passed such packets toward the original server. The first such drop after the service starts is logged once as a warning, and a count is logged at `Info` level at most every five seconds while drops continue. Later fragments of a fragmented reply carry no ports, cannot be attributed to a listener, and are still passed.
- **A TCP connection is tracked through its whole close.** The FIN/ACK exchange is translated in both directions instead of reaching the real server. A reset (RST) ends the connection immediately; segments the local proxy had already sent when the reset arrived are dropped without the warning and are counted at `Debug` level only.
- **ICMP errors about proxied UDP replies are dropped.** A UDP reply reaches the application as if it came from the remote endpoint, although it came from the proxy. If the application has already closed its socket when the reply arrives, Windows answers with an ICMP "port unreachable" error (ICMPv6 "destination unreachable" for IPv6) addressed to that remote endpoint. The error is sent from the computer's own address, outside the proxy, and quotes the reply, so it would reveal the computer's address and the reply's contents to the remote endpoint. ProxiFyre drops an outbound ICMP or ICMPv6 error when the UDP datagram it quotes was addressed to a local port whose UDP traffic ProxiFyre redirected to a proxy within the last 15 minutes. This applies in either DNS mode, to every rule that proxies `UDP`. It also covers a datagram that port received directly from the network: the sender already knows the computer's address, and only its error report is lost. Other ICMP traffic, such as `ping`, neighbor discovery and errors about unproxied traffic, is passed. The first such drop after the service starts is logged at `Info`, naming the local port, and later ones are counted at `Debug`. Proxied TCP is not affected: Windows answers a TCP segment for a closed connection with a reset, which is translated like any other segment (see above).

When a rule proxies `UDP` for an address family, or in DNS `Proxy` mode, outbound ICMP of that family (ICMPv6 for IPv6) is filtered by ProxiFyre rather than passed by the driver. The filter is placed ahead of the LAN bypass filters. ICMP that is not dropped is passed unchanged. If the filter cannot be installed, the service does not start; a proxy added while the service runs is then rejected instead.

A proxied TCP connection that stays idle for more than 5 minutes loses its redirect entry; see [Limitations](#limitations).

Expand Down Expand Up @@ -187,7 +190,7 @@ Whether name resolution still succeeds after a drop depends on Windows: it retri

Windows retries a failed query and, for UDP answers marked truncated, retries over TCP; both go through the same proxy. ProxiFyre does not inspect payloads to decide what is DNS: only destination port 53 is classified.

An answer can arrive after the application has closed its socket, for example the answer to a query Windows had already retransmitted. Windows then reports the datagram with an ICMP "port unreachable" error addressed to the DNS server the application queried, and that error quotes the answer. Because the answer came from the DNS proxy and not from that server, ProxiFyre drops outbound ICMP and ICMPv6 errors that quote a packet sent from port 53 in `Proxy` mode, so the answer does not leave the computer in clear. Other ICMP traffic, such as `ping`, is passed. The first such drop after the service starts is logged at `Info` and later ones are counted at `Debug`.
An answer can arrive after the application has closed its socket, for example the answer to a query Windows had already retransmitted. Windows then reports the datagram with an ICMP "port unreachable" error addressed to the DNS server the application queried, and that error quotes the answer. Because the answer came from the DNS proxy and not from that server, ProxiFyre drops outbound ICMP and ICMPv6 errors that quote a packet sent from port 53 in `Proxy` mode, so the answer does not leave the computer in clear. Other ICMP traffic, such as `ping`, is passed. The first such drop after the service starts is logged at `Info` and later ones are counted at `Debug`. The same protection applies to application UDP that a rule proxies, in either mode; see [Local listener replies and TCP close handling](#local-listener-replies-and-tcp-close-handling).

If the selected proxy cannot be created when the service starts (for example its host name does not resolve or its listeners cannot be opened), the service still starts but **all DNS is blocked until the service is restarted** after the cause is fixed. The engine log says so explicitly. An unknown `mode` value stops the service from starting instead of being treated as `Direct`.

Expand Down
3 changes: 2 additions & 1 deletion docs/gui.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,5 @@ The routing policy and the packet rewriting are covered by automated tests (`net
13. **Relay source and shared IDs.** If the SOCKS5 server reports an address other than the queried DNS server as the source of UDP replies (for example its own IPv4 address), confirm lookups succeed without and with `serverOverride`, to an IPv4 resolver and to an IPv6 resolver. Run many lookups in parallel (for example `1..200 | ForEach-Object -Parallel { Resolve-DnsName "host$_.example.com" -DnsOnly -ErrorAction SilentlyContinue }` in PowerShell 7) and confirm each one gets its own answer.
14. **SOCKS5 server used as a resolver.** Send a lookup to the SOCKS5 server's own IP address (`Resolve-DnsName example.com -Server <socks-ip> -DnsOnly`). Confirm the query goes through the proxy, not directly. If the server listens on TCP port 53 or returns a UDP relay on port 53, also confirm ProxiFyre still reaches it and the one-time `Info` line about the relay appears.
15. **Limited mode.** Repeat step 2 in the optional unelevated console mode.
16. **GUI.** On the **Settings / Diagnostics** tab at 100% and 150% scaling, confirm the DNS routing group and the Uninstall button are reachable (scrolling is expected). Confirm Alt+M, Alt+P, and Alt+S focus the mode, proxy, and override fields; that the DNS proxy selection survives **Move Up**/**Move Down** and a reload; that **Duplicate** does not copy the id; and that removing the selected rule shows the missing id and fails validation.
16. **ICMP errors about proxied UDP replies.** With `Direct` DNS and a rule that proxies `UDP` for a test application, capture on the physical adapter (`pktmon filter add -t ICMP`, `pktmon filter add -t ICMPv6`, `pktmon start --capture --comp nics`, then `pktmon stop` and `pktmon etl2pcap PktMon.etl`; or Wireshark with `icmp.type == 3 || icmpv6.type == 1`). From the application, send a UDP datagram to a server that answers after a delay, over IPv4 and over IPv6, and close the socket before the reply arrives but not at once: keep it open for about 50 ms after sending. A socket that closes within a few milliseconds is gone before ProxiFyre can attribute its datagram to the application, so the datagram is sent directly, the server answers directly, and the ICMP error about that direct reply is passed. The reply has to arrive after the close, so with a SOCKS5 server that answers faster than that, use a server that delays its reply. For example, query a DNS server on a port other than 53 that answers slowly, send a STUN binding request, or use a UDP echo server that delays its reply. Confirm in the capture that no datagram went from the application to the server directly and that the SOCKS5 server relays the reply, that no ICMP type 3 or ICMPv6 type 1 message addressed to the server leaves the adapter, and that the engine log has one "Dropped an ICMP error about a proxied UDP reply" line naming the client port. Repeat the test with the rule disabled: the error now leaves the adapter, which shows the test provokes it. Confirm `ping` and `ping -6` to the server still work, and that the same check passes in `Proxy` mode.
17. **GUI.** On the **Settings / Diagnostics** tab at 100% and 150% scaling, confirm the DNS routing group and the Uninstall button are reachable (scrolling is expected). Confirm Alt+M, Alt+P, and Alt+S focus the mode, proxy, and override fields; that the DNS proxy selection survives **Move Up**/**Move Down** and a reload; that **Duplicate** does not copy the id; and that removing the selected rule shows the missing id and fails validation.
22 changes: 20 additions & 2 deletions netlib/src/ndisapi/socks5_udp_local_redirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace ndisapi
/// </summary>
std::atomic_bool terminate_{ false };

/// How long a client endpoint is kept after its last translated datagram.
static constexpr std::chrono::minutes endpoint_timeout{ 15 };

/**
* @brief Starts the background cleanup thread.
*
Expand All @@ -64,8 +67,7 @@ namespace ndisapi
tools::generic::erase_if(endpoints_, endpoints_.begin(), endpoints_.end(),
[&current_time, this](auto&& a)
{
using namespace std::chrono_literals;
if (current_time - a.second > 15min)
if (current_time - a.second > endpoint_timeout)
{
NETLIB_DEBUG(
"DELETE UDP client endpoint (timeout): : {}",
Expand Down Expand Up @@ -176,6 +178,22 @@ namespace ndisapi
proxy_port_ = htons(proxy_port);
}

/**
* @brief Whether @p client_port (host byte order) has an endpoint entry that has not
* timed out, i.e. its datagrams are, or were within endpoint_timeout, redirected
* and replies to it are delivered by a local listener.
*
* Used to recognize an outbound ICMP error about such a reply (decide_icmp_error()):
* the entry outlives the client's socket, which is exactly when the stack reports a
* late reply with an error addressed to the remote peer.
*/
[[nodiscard]] bool is_active_endpoint(const u_short client_port)
{
std::scoped_lock lock(lock_);
const auto it = endpoints_.find(htons(client_port));
return it != endpoints_.cend() && std::chrono::steady_clock::now() - it->second <= endpoint_timeout;
}

/**
* @brief Checks if the UDP session for the given packet is new.
*
Expand Down
Loading
Loading