From 6e09c172dbd7fe2ea8acceb692816e72c4b84cdc Mon Sep 17 00:00:00 2001 From: Zakk Date: Fri, 18 Sep 2026 05:07:03 +1000 Subject: [PATCH] fix(transparent): restore the redirect ingress wildcard, trim whitelist IPs, keep DNS readiness advisory Three regressions from the previous transparent-proxy commit: - the redirect ingress rules lost the "*" to "+" translation, so an excluded interface pattern such as docker* stopped matching and Docker traffic was redirected; the egress rules and both tproxy directions still translated it; - the whitelist now parses its entries, and the GUI submits the textarea lines as typed, so a pasted CIDR with surrounding whitespace aborted the whole setup where the shell used to swallow it; - the DNS readiness probe resolves a name, so a dead or slow upstream failed it even with the listener up, and the core could no longer start at all. The probe is now advisory: it still waits when DNS is healthy, but a failure is logged instead of aborting the start. --- service/kernel/iptables/redirect.go | 4 ++-- service/kernel/iptables/utils.go | 6 ++++++ service/kernel/v2ray/transparent.go | 8 ++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/service/kernel/iptables/redirect.go b/service/kernel/iptables/redirect.go index 3c79f8ed..15ab3ed7 100644 --- a/service/kernel/iptables/redirect.go +++ b/service/kernel/iptables/redirect.go @@ -85,7 +85,7 @@ iptables -w 2 -t nat -A DNS_REDIRECT -p tcp -j REDIRECT --to-port 52353 iptables -w 2 -t nat -A DNS_REDIRECT -p udp -j REDIRECT --to-port 52353 ` for _, v := range excludedInterfaces { - commands += fmt.Sprintf("iptables -w 2 -t nat -A TP_RULE -i %s -j RETURN\n", v) + commands += fmt.Sprintf("iptables -w 2 -t nat -A TP_RULE -i %s -j RETURN\n", strings.ReplaceAll(v, "*", "+")) } // OUTPUT 路径使用 -o 匹配输出网卡(本地流量在 OUTPUT 链中 -i 始终为 lo) for _, v := range excludedInterfaces { @@ -135,7 +135,7 @@ ip6tables -w 2 -t nat -A TP_RULE -d ff00::/8 -j RETURN ip6tables -w 2 -t nat -A TP_RULE -m mark --mark 0x80/0x80 -j RETURN ` for _, v := range excludedInterfaces { - commands += fmt.Sprintf("ip6tables -w 2 -t nat -A TP_RULE -i %s -j RETURN\n", v) + commands += fmt.Sprintf("ip6tables -w 2 -t nat -A TP_RULE -i %s -j RETURN\n", strings.ReplaceAll(v, "*", "+")) } // IPv6 OUTPUT 路径使用 -o 匹配输出网卡 for _, v := range excludedInterfaces { diff --git a/service/kernel/iptables/utils.go b/service/kernel/iptables/utils.go index eaf86e26..115027e7 100644 --- a/service/kernel/iptables/utils.go +++ b/service/kernel/iptables/utils.go @@ -105,6 +105,12 @@ func GetWhiteListIPs() ([]string, []string, error) { ipv6List = append(ipv6List, ipv6s...) } for _, v := range dataModal.CustomIps { + // The GUI submits the textarea lines as typed, so a pasted CIDR can + // carry surrounding whitespace that net.ParseCIDR does not accept. + v = strings.TrimSpace(v) + if v == "" { + continue + } if net.ParseIP(v) == nil { if _, _, err := net.ParseCIDR(v); err != nil { return nil, nil, fmt.Errorf("invalid tproxy whitelist IP/CIDR %q", v) diff --git a/service/kernel/v2ray/transparent.go b/service/kernel/v2ray/transparent.go index a6abf767..3e46d410 100644 --- a/service/kernel/v2ray/transparent.go +++ b/service/kernel/v2ray/transparent.go @@ -155,9 +155,13 @@ func writeTransparentProxyRules(tmpl *Template) (err error) { dnsAddr = tmpl.Setting.DnsListenAddr } if err := waitForDnsPort(dnsAddr, 5*time.Second); err != nil { - return fmt.Errorf("dns module not ready: %w", err) + // The probe resolves a name, so a dead or slow upstream fails it + // even though the listener is up. Waiting is worth it when DNS is + // healthy, but it must not be the reason the core cannot start. + log.Warn("DNS module did not answer on %s yet, applying transparent proxy rules anyway: %v", dnsAddr, err) + } else { + log.Trace("DNS module is ready on %s, setting up transparent proxy rules", dnsAddr) } - log.Trace("DNS module is ready on %s, setting up transparent proxy rules", dnsAddr) } cleanupResidualTransparentProxyRules() setting := configure.GetSettingNotNil()