Files
Zakk a4c0a5a37c fix(transparent): validate rule inputs, real DNS readiness probe, rule cleanup
Interface names and whitelist IPs from the settings were interpolated
into iptables/nft command text run through sh -c; they are now validated
(interface names may still use the "*" wildcard, translated to "+" for
iptables) and rejected with a message naming the value. nftTproxy emitted
"elements = { }" for an empty whitelist, an nft syntax error that failed
the whole setup. waitForDnsPort dialed UDP, which succeeds without a
listener; it now sends a DNS query and waits for an answer. The resolv
hijacker's ticker goroutine never exited because Stop does not close the
channel. A failing transparent pre-stop hook skipped rule deletion and
left the tproxy chains and resolv hijack behind. The DNS REDIRECT rules
ran through raw ExecCommands instead of the iptables backend setter, so
nft-only hosts silently skipped them. On darwin/BSD sysctl was invoked
with the whole command line as the program name.
2026-09-18 02:53:32 +10:00

31 lines
616 B
Go

//go:build darwin || dragonfly || freebsd || (js && wasm) || netbsd || openbsd
// +build darwin dragonfly freebsd js,wasm netbsd openbsd
package ipforward
import (
"fmt"
"os/exec"
"strings"
"syscall"
)
func IsIpForwardOn() bool {
out, err := syscall.Sysctl("net.inet.ip.forwarding")
return err == nil && strings.TrimSpace(out) == "1"
}
func WriteIpForward(on bool) (err error) {
defer func() {
if err != nil {
err = fmt.Errorf("WriteIpForward: %w", err)
}
}()
val := "0"
if on {
val = "1"
}
_, err = exec.Command("sysctl", "-w", "net.inet.ip.forwarding="+val).CombinedOutput()
return err
}