fix: remove existing wiretrustee interface if existed

This commit is contained in:
braginini 2021-08-26 18:04:19 +02:00
parent d4a24ac001
commit 3c4b0b3a4b

View File

@ -30,8 +30,27 @@ func CreateWithKernel(iface string, address string) error {
attrs: &attrs, attrs: &attrs,
} }
// check if interface exists
l, err := netlink.LinkByName(WgInterfaceDefault)
if err != nil {
switch err.(type) {
case netlink.LinkNotFoundError:
break
default:
return err
}
}
// remove if interface exists
if l != nil {
err = netlink.LinkDel(&link)
if err != nil {
return err
}
}
log.Debugf("adding device: %s", iface) log.Debugf("adding device: %s", iface)
err := netlink.LinkAdd(&link) err = netlink.LinkAdd(&link)
if os.IsExist(err) { if os.IsExist(err) {
log.Infof("interface %s already exists. Will reuse.", iface) log.Infof("interface %s already exists. Will reuse.", iface)
} else if err != nil { } else if err != nil {