|
@ -3,6 +3,7 @@ package main |
|
|
import ( |
|
|
import ( |
|
|
log "github.com/sirupsen/logrus" |
|
|
log "github.com/sirupsen/logrus" |
|
|
"os" |
|
|
"os" |
|
|
|
|
|
"strconv" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func loadDns() { |
|
|
func loadDns() { |
|
@ -47,3 +48,33 @@ func loadNetwork() { |
|
|
runCommand([]string{"ip", "-6", "route", "add", "default", "via", v6Gateway}) |
|
|
runCommand([]string{"ip", "-6", "route", "add", "default", "via", v6Gateway}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func loadTProxy() { |
|
|
|
|
|
log.Info("Setting up TProxy of IPv4") |
|
|
|
|
|
v4TableNum := strconv.Itoa(v4RouteTable) |
|
|
|
|
|
runCommand([]string{"ip", "-4", "rule", "add", "fwmark", "1", "table", v4TableNum}) |
|
|
|
|
|
runCommand([]string{"ip", "-4", "route", "add", "local", "0.0.0.0/0", "dev", "lo", "table", v4TableNum}) |
|
|
|
|
|
runCommand([]string{"iptables", "-t", "mangle", "-N", "XPROXY"}) |
|
|
|
|
|
for _, cidr := range v4Bypass { |
|
|
|
|
|
runCommand([]string{"iptables", "-t", "mangle", "-A", "XPROXY", "-d", cidr, "-j", "RETURN"}) |
|
|
|
|
|
} |
|
|
|
|
|
runCommand([]string{"iptables", "-t", "mangle", "-A", "XPROXY", "-p", "tcp", "-j", "TPROXY", |
|
|
|
|
|
"--on-port", strconv.Itoa(v4TProxyPort), "--tproxy-mark", "1"}) |
|
|
|
|
|
runCommand([]string{"iptables", "-t", "mangle", "-A", "XPROXY", "-p", "udp", "-j", "TPROXY", |
|
|
|
|
|
"--on-port", strconv.Itoa(v4TProxyPort), "--tproxy-mark", "1"}) |
|
|
|
|
|
runCommand([]string{"iptables", "-t", "mangle", "-A", "PREROUTING", "-j", "XPROXY"}) |
|
|
|
|
|
|
|
|
|
|
|
log.Info("Setting up TProxy of IPv6") |
|
|
|
|
|
v6TableNum := strconv.Itoa(v6RouteTable) |
|
|
|
|
|
runCommand([]string{"ip", "-6", "rule", "add", "fwmark", "1", "table", v6TableNum}) |
|
|
|
|
|
runCommand([]string{"ip", "-6", "route", "add", "local", "::/0", "dev", "lo", "table", v6TableNum}) |
|
|
|
|
|
runCommand([]string{"ip6tables", "-t", "mangle", "-N", "XPROXY6"}) |
|
|
|
|
|
for _, cidr := range v6Bypass { |
|
|
|
|
|
runCommand([]string{"ip6tables", "-t", "mangle", "-A", "XPROXY6", "-d", cidr, "-j", "RETURN"}) |
|
|
|
|
|
} |
|
|
|
|
|
runCommand([]string{"ip6tables", "-t", "mangle", "-A", "XPROXY6", "-p", "tcp", "-j", "TPROXY", |
|
|
|
|
|
"--on-port", strconv.Itoa(v6TProxyPort), "--tproxy-mark", "1"}) |
|
|
|
|
|
runCommand([]string{"ip6tables", "-t", "mangle", "-A", "XPROXY6", "-p", "udp", "-j", "TPROXY", |
|
|
|
|
|
"--on-port", strconv.Itoa(v6TProxyPort), "--tproxy-mark", "1"}) |
|
|
|
|
|
runCommand([]string{"ip6tables", "-t", "mangle", "-A", "PREROUTING", "-j", "XPROXY6"}) |
|
|
|
|
|
} |
|
|