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:
AclEngineBuildermerges three rule sources in fixed order:apernet(Hysteria 2 function-call syntax) →rules(rawwind_rule::Rule) →clash(Clash/Mihomo). - Verus-verified optimization: Two order-preserving passes run on the entry chain:
- Adjacent side-effect-free typed
Domain/Ip/Portleaves sharing the same(stmts, terminal_verdict)(Forward/Reject/Drop/Return) fold intoNamedSets. - Adjacent same-side
Portrules with emptystmtsand pairwise-disjoint ranges fold into aVerdictMap. - Context and GeoData wiring:
AclEnginepopulatesMatchContextfromFlowContext(destination/source IP & port, network, inbound name/type/port, UTF-8IN-USER) and automatically bindsgeoip_lookup/geosite_lookupwhenAclEngineBuilder::geodata(Arc<GeoData>)is set (emitting a build warning if Geo rules are configured without geodata).IP-ASN/SRC-IP-ASNandPROCESS-*/UID/DSCPare not populated automatically yet. - Loopback and private guards (
GuardConfig): - Run before IR evaluation and require a
Resolverat build time when enabled; drop_loopbackcanonicalizes IPv4-mapped IPv6 addresses and blocks127.0.0.0/8,::1, and unspecified0.0.0.0/::;drop_privatecalls Verus-verifiedwind_core::is_private_ipcovering 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_targetto defeat DNS rebinding, and re-validates every subsequent UDP datagram viaprepare_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 byrkyv 0.8data.build_and_openwrites a process-unique temporary file and publishes via atomicrename. - 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), andPlain(keyword); does not support GeoSite regexes,@attrfiltering, or built-in.datdownloading.
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
systemmode,wind_dns::buildreturnsOk(None)so callers fall back towind_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-rsandwebpki-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 supportingbind_ipv4,bind_ipv6,bind_device,stream_timeout,tcp_keepalive, per-outboundip_mode(StackPrefer), TCP Fast Open (tfo), and Linux/Androidrouting_mark(SO_MARK) andmptcp(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 permanentFailedstate.LoadBalanceOutbound: See Inbounds and Outbounds: load-balance.TunnelTcpInbound/TunnelUdpInbound: Fixed-target forwarding listeners; see Chained Proxies.loopback::check_loopback: Lightweight literal check rejecting127.0.0.0/8and::1; usewind-acl'sGuardConfigwhen domain resolution or private/unspecified IP blocking is needed.