From 6f2375786817e87421cb737c4b9c361bc52adf6e Mon Sep 17 00:00:00 2001 From: Stefan Junker Date: Thu, 19 Nov 2015 11:08:04 +0100 Subject: [PATCH] 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. --- plugins/ipam/dhcp/lease.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/ipam/dhcp/lease.go b/plugins/ipam/dhcp/lease.go index c8bfb8d9..90c223c7 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 {