Skip to content

Commit

Permalink
fix: hotfix interface addr assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
braginini committed Aug 17, 2021
1 parent dd50f49 commit 9a36219
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions iface/iface_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9a36219

Please sign in to comment.