From 29f1787a4d0877592a341a3afff5c32e82dfeb38 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Tue, 3 May 2022 23:28:02 +0800 Subject: [PATCH] chore: add default router when tun enable --- config/config.go | 4 ++-- listener/tun/ipstack/commons/router_linux.go | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index f77a8a18..0337fb09 100644 --- a/config/config.go +++ b/config/config.go @@ -267,10 +267,10 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) { Tun: RawTun{ Enable: false, Device: "", - AutoDetectInterface: true, Stack: C.TunGvisor, DNSHijack: []string{"0.0.0.0:53"}, // default hijack all dns query - AutoRoute: true, + AutoRoute: false, + AutoDetectInterface: false, }, IPTables: IPTables{ Enable: false, diff --git a/listener/tun/ipstack/commons/router_linux.go b/listener/tun/ipstack/commons/router_linux.go index 5fa5d79a..af14d481 100644 --- a/listener/tun/ipstack/commons/router_linux.go +++ b/listener/tun/ipstack/commons/router_linux.go @@ -19,13 +19,15 @@ func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int, ip = addr.Masked().Addr().Next() ) - _, err := cmd.ExecCmd(fmt.Sprintf("ip addr add %s dev %s", ip.String(), interfaceName)) - if err != nil { + if _, err := cmd.ExecCmd(fmt.Sprintf("ip addr add %s dev %s", ip.String(), interfaceName)); err != nil { return err } - _, err = cmd.ExecCmd(fmt.Sprintf("ip link set %s up", interfaceName)) - if err != nil { + if _, err = cmd.ExecCmd(fmt.Sprintf("ip link set %s up", interfaceName)); err != nil { + return err + } + + if err = execRouterCmd("add", addr, interfaceName, "198.18.0.1", "main"); err != nil { return err }