From 8f08304b75376d48162ad4c1fb5aa38d0ea6db29 Mon Sep 17 00:00:00 2001 From: naison <895703375@qq.com> Date: Sat, 21 Aug 2021 19:55:53 +0800 Subject: [PATCH] ignore linux error: File exists while add same route twice --- tuntap_linux.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tuntap_linux.go b/tuntap_linux.go index 20c609fb..29487733 100644 --- a/tuntap_linux.go +++ b/tuntap_linux.go @@ -1,8 +1,10 @@ package gost import ( + "errors" "fmt" "net" + "syscall" "github.com/docker/libcontainer/netlink" "github.com/go-log/log" @@ -149,7 +151,7 @@ func addTunRoutes(ifName string, routes ...IPRoute) error { } cmd := fmt.Sprintf("ip route add %s dev %s", route.Dest.String(), ifName) log.Logf("[tun] %s", cmd) - if err := netlink.AddRoute(route.Dest.String(), "", "", ifName); err != nil { + if err := netlink.AddRoute(route.Dest.String(), "", "", ifName); err != nil && !errors.Is(err, syscall.EEXIST) { return fmt.Errorf("%s: %v", cmd, err) } }