pkg/iproute: ignore error if tunnel exists

This commit is contained in:
Lucas Serven 2019-01-21 19:54:09 +01:00
parent e989f0a25f
commit 630bced657
No known key found for this signature in database
GPG Key ID: 586FEAF680DA74AD

View File

@ -18,6 +18,7 @@ import (
"bytes"
"fmt"
"os/exec"
"strings"
"github.com/vishvananda/netlink"
)
@ -36,7 +37,9 @@ func NewIPIP(baseIndex int) (int, error) {
cmd := exec.Command("ip", "tunnel", "add", tunnelName, "mode", "ipip")
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
// Sometimes creating a tunnel returns the error "File exists,"
// in which case the interface exists and we can ignore the error.
if err := cmd.Run(); err != nil && !strings.Contains(stderr.String(), "File exists") {
return 0, fmt.Errorf("failed to create IPIP tunnel: %s", stderr.String())
}
link, err = netlink.LinkByName(tunnelName)