From: Stefan Junker Date: Thu, 19 Nov 2015 10:08:04 +0000 (+0100) Subject: dhcp: detect if link is down and attempt to set up X-Git-Url: https://git.halfball.org/?a=commitdiff_plain;h=6f2375786817e87421cb737c4b9c361bc52adf6e;p=plugins.git dhcp: detect if link is down and attempt to set up With this we still get the "network is down" error, but after the 2nd retry the interface is up and the dhcp request works. --- diff --git a/plugins/ipam/dhcp/lease.go b/plugins/ipam/dhcp/lease.go index c8bfb8d..90c223c 100644 --- a/plugins/ipam/dhcp/lease.go +++ b/plugins/ipam/dhcp/lease.go @@ -118,6 +118,13 @@ func (l *DHCPLease) acquire() error { } defer c.Close() + if (l.link.Attrs().Flags & net.FlagUp) != net.FlagUp { + log.Printf("Link %q down. Attempting to set up", l.link.Attrs().Name) + if err = netlink.LinkSetUp(l.link); err != nil { + return err + } + } + pkt, err := backoffRetry(func() (*dhcp4.Packet, error) { ok, ack, err := c.Request() switch {