Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pkg/ip/addr_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ const SETTLE_INTERVAL = 50 * time.Millisecond
// There is no easy way to wait for this as an event, so just loop until the
// addresses are no longer tentative.
// If any addresses are still tentative after timeout seconds, then error.
func SettleAddresses(ifName string, timeout int) error {
func SettleAddresses(ifName string, timeout time.Duration) error {
link, err := netlinksafe.LinkByName(ifName)
if err != nil {
return fmt.Errorf("failed to retrieve link: %v", err)
}

deadline := time.Now().Add(time.Duration(timeout) * time.Second)
deadline := time.Now().Add(timeout)
for {
addrs, err := netlinksafe.AddrList(link, netlink.FAMILY_ALL)
addrs, err := netlinksafe.AddrList(link, netlink.FAMILY_V6)
if err != nil {
return fmt.Errorf("could not list addresses: %v", err)
}
Expand All @@ -50,7 +50,13 @@ func SettleAddresses(ifName string, timeout int) error {

ok := true
for _, addr := range addrs {
if addr.Flags&(syscall.IFA_F_TENTATIVE|syscall.IFA_F_DADFAILED) > 0 {
if addr.Flags&(syscall.IFA_F_DADFAILED) != 0 {
return fmt.Errorf("link %s has address %s in DADFAILED state",
ifName,
addr.IP.String())
}

if addr.Flags&(syscall.IFA_F_TENTATIVE) != 0 {
ok = false
break // Break out of the `range addrs`, not the `for`
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/ipam/ipam_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"net"
"os"
"time"

"github.com/vishvananda/netlink"

Expand All @@ -31,6 +32,8 @@ const (
// Note: use slash as separator so we can have dots in interface name (VLANs)
DisableIPv6SysctlTemplate = "net/ipv6/conf/%s/disable_ipv6"
KeepAddrOnDownSysctlTemplate = "net/ipv6/conf/%s/keep_addr_on_down"

dadSettleTimeout = 5 * time.Second
)

// ConfigureIface takes the result of IPAM plugin and
Expand Down Expand Up @@ -111,7 +114,10 @@ func ConfigureIface(ifName string, res *current.Result) error {
}

if v6gw != nil {
ip.SettleAddresses(ifName, 10)
err = ip.SettleAddresses(ifName, dadSettleTimeout)
if err != nil {
return fmt.Errorf("failed to settle addresses for %q: %v", ifName, err)
}
}

for _, r := range res.Routes {
Expand Down