Skip to content
Edit this page

Routing and Services

Beyond core proxy protocols, Wind separates rule evaluation, ACL compilation, GeoData snapshots, custom DNS, ACME certificate management, and protocol-agnostic forwarders into independent crates.

ACL and Rule Engine (wind-acl / wind-rule)

wind-rule: Leaf Rule Model

wind-rule has zero internal Wind dependencies and parses/evaluates MetaCubeX/Clash rules:

  • Domains: DOMAIN, DOMAIN-SUFFIX, DOMAIN-KEYWORD (all reject empty values), DOMAIN-WILDCARD (precompiled regex), DOMAIN-REGEX, GEOSITE.
  • Destination & source IPs: IP-CIDR, IP-CIDR6, IP-SUFFIX, IP-ASN, GEOIP, SRC-GEOIP, SRC-IP-ASN, SRC-IP-CIDR, SRC-IP-SUFFIX.
  • Ports, network & metadata: DST-PORT, SRC-PORT (single or inclusive ranges), NETWORK (tcp/udp), IN-PORT, IN-TYPE, IN-USER, IN-NAME, PROCESS-PATH, PROCESS-PATH-REGEX, PROCESS-NAME, PROCESS-NAME-REGEX, UID, DSCP.
  • Combinators & fallback: AND, OR, NOT, MATCH.

Current boundaries: RULE-SET always evaluates to false; SUB-RULE retains legacy nested-rule semantics without external named sub-rule lookup.

wind-acl: IR, Verified Optimization, and Guards

wind-acl lowers multiple surface syntaxes into an nftables-style Ruleset (see ACL IR Specification) and implements wind_core::Router:

  • Multi-dialect precedence: AclEngineBuilder merges three rule sources in fixed order: apernet (Hysteria 2 function-call syntax) → rules (raw wind_rule::Rule) → clash (Clash/Mihomo).
  • Verus-verified optimization: Two order-preserving passes run on the entry chain:
  • Adjacent side-effect-free typed Domain/Ip/Port leaves sharing the same (stmts, terminal_verdict) (Forward/Reject/Drop/Return) fold into NamedSets.
  • Adjacent same-side Port rules with empty stmts and pairwise-disjoint ranges fold into a VerdictMap.
  • Context and GeoData wiring: AclEngine populates MatchContext from FlowContext (destination/source IP & port, network, inbound name/type/port, UTF-8 IN-USER) and automatically binds geoip_lookup/geosite_lookup when AclEngineBuilder::geodata(Arc<GeoData>) is set (emitting a build warning if Geo rules are configured without geodata). IP-ASN/SRC-IP-ASN and PROCESS-*/UID/DSCP are not populated automatically yet.
  • Loopback and private guards (GuardConfig):
  • Run before IR evaluation and require a Resolver at build time when enabled;
  • drop_loopback canonicalizes IPv4-mapped IPv6 addresses and blocks 127.0.0.0/8, ::1, and unspecified 0.0.0.0/::;
  • drop_private calls Verus-verified wind_core::is_private_ip covering RFC 1918 (10/8, 172.16/12, 192.168/16), link-local (169.254/16, fe80::/10), CGNAT (100.64/10), and IPv6 unique-local (fc00::/7) plus IPv4-mapped forms;
  • Pins the validated resolved IP via Router::route_with_target to defeat DNS rebinding, and re-validates every subsequent UDP datagram via prepare_udp_target.

Zero-Copy GeoData Snapshots (wind-geodata)

wind-geodata compiles V2Ray/sing-box geosite.dat and geoip.dat binaries into memmap2-backed snapshots for real-time ACL queries:

  • Format and atomic build: Uses a 16-byte aligned header (MAGIC = "WINDGEO\0", FORMAT_VERSION = 1, 4 reserved bytes) followed by rkyv 0.8 data. build_and_open writes a process-unique temporary file and publishes via atomic rename.
  • Load-time validation: Beyond rkyv::access, validate_offsets() checks all slice bounds, sorted category/country names, lexicographic domain order, and sorted disjoint IPv4/IPv6 intervals (verified in Verus). Queries run zero-copy binary searches and support IPs belonging to multiple overlapping tags.
  • Current boundaries: Supports GeoSite Full (exact), Domain (suffix), and Plain (keyword); does not support GeoSite regexes, @attr filtering, or built-in .dat downloading.

Custom DNS (wind-dns)

wind-dns implements wind_core::Resolver on top of hickory-resolver 0.26 with DnsConfig (deny_unknown_fields):

Field Default Description
mode system Preset or custom: system, cloudflare / -tls / -https, google / -tls / -https, quad9 / -tls / -https, custom
servers [] Custom upstreams: bare IP[:53] (UDP+TCP fallback), udp://, tcp://, tls://ip[:853][#sni], https://ip[:443][#sni]
timeout Resolver default Per-query timeout
attempts Resolver default Query retry count
stack_prefer V4first Address-family preference (V4only, V6only, V4first, V6first)
  • In system mode, wind_dns::build returns Ok(None) so callers fall back to wind_core::SystemResolver.
  • Literal IP targets bypass DNS lookup; an empty post-filter address set returns an explicit error.
  • Current boundaries: No DoQ/DoH3, split-horizon domain routing, custom hosts table, or FakeIP; encrypted transports use aws-lc-rs and webpki-roots.

ACME and Self-Signed Certificates (wind-acme)

wind-acme has no internal Wind dependencies and offers two independent feature-gated modes:

Feature Target backend Mechanism
resolver (default) rustls / Quinn Built on rustls-acme fork; start_acme_with_cert returns (Arc<dyn ResolvesServerCert>, watch::Receiver<Option<CertPem>>) and starts an on-demand TCP port 80 HTTP-01 listener only during challenges
http01 BoringSSL / Quiche or file-backed setups Built on instant-acme 0.8; ensure_acme_cert (one-shot) and watch_acme_cert (continuous watcher emitting matched cert/key PEM pairs for CertStore::update), persisting account keys to <key>.account.json (0600 on Unix, checked against directory_url)

The http01 feature also provides selfsigned::ensure_self_signed_cert_files for generating and auto-renewing 45-day ECDSA P-256 end-entity self-signed certificates.

  • Current boundaries: HTTP-01 challenges only (no DNS-01 or TLS-ALPN-01).

Base Primitives (wind-base)

wind-base supplies protocol-independent building blocks:

  • DirectOutbound: Direct TCP/UDP egress supporting bind_ipv4, bind_ipv6, bind_device, stream_timeout, tcp_keepalive, per-outbound ip_mode (StackPrefer), TCP Fast Open (tfo), and Linux/Android routing_mark (SO_MARK) and mptcp (IPPROTO_MPTCP).
  • LazyOutbound: Defers async outbound construction until the first flow. Concurrent callers share one initialization future safely even if the first caller cancels; construction failures enter a permanent Failed state.
  • LoadBalanceOutbound: See Inbounds and Outbounds: load-balance.
  • TunnelTcpInbound / TunnelUdpInbound: Fixed-target forwarding listeners; see Chained Proxies.
  • loopback::check_loopback: Lightweight literal check rejecting 127.0.0.0/8 and ::1; use wind-acl's GuardConfig when domain resolution or private/unspecified IP blocking is needed.