From 9a362199f8c3cb90b1a042594c28df4874133037 Mon Sep 17 00:00:00 2001 From: braginini Date: Tue, 17 Aug 2021 18:05:51 +0200 Subject: [PATCH] fix: hotfix interface addr assignment --- iface/iface_linux.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/iface/iface_linux.go b/iface/iface_linux.go index 86c670785b6..c9d9d4afe7a 100644 --- a/iface/iface_linux.go +++ b/iface/iface_linux.go @@ -37,13 +37,6 @@ func CreateWithKernel(iface string, address string) error { } log.Debugf("adding address %s to interface: %s", address, iface) - addr, _ := netlink.ParseAddr(address) - err = netlink.AddrAdd(&link, addr) - if os.IsExist(err) { - log.Infof("interface %s already has the address: %s", iface, address) - } else if err != nil { - return err - } err = assignAddr(address, iface) if err != nil { return err @@ -77,6 +70,20 @@ func assignAddr(address, name string) error { attrs: &attrs, } + //delete existing addresses + list, err := netlink.AddrList(&link, 0) + if err != nil { + return err + } + if len(list) > 0 { + for _, a := range list { + err = netlink.AddrDel(&link, &a) + if err != nil { + return err + } + } + } + log.Debugf("adding address %s to interface: %s", address, attrs.Name) addr, _ := netlink.ParseAddr(address) err = netlink.AddrAdd(&link, addr)