Skip to content

Commit 5990ef7

Browse files
committed
add delay before returning from windows dhcp otherwise net adapter not found
1 parent fd36e39 commit 5990ef7

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

dhcp/dhcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (c *DHCP) receiveDHCPResponse(ctx context.Context, reader io.ReadCloser, xi
234234
if opcode != dhcpOpCodeReply {
235235
continue // opcode is not a reply, so continue
236236
}
237-
237+
c.logger.Info("Received DHCP reply packet", zap.Int("opCode", int(opcode)), zap.Any("transactionID", TransactionID(txid)))
238238
if TransactionID(txid) == xid {
239239
break
240240
}

dhcp/dhcp_windows.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
dummySubnetMask = "255.255.128.0"
1717
addIPAddressDelay = 4 * time.Second
1818
deleteIPAddressDelay = 2 * time.Second
19+
returnDelay = 8 * time.Second // time to wait before returning from DiscoverRequest
1920

2021
socketTimeoutMillis = 1000
2122
)
@@ -97,7 +98,7 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
9798
// delete dummy ip off the interface if it already exists
9899
ret, err := c.execClient.ExecuteCommand(ctx, "netsh", "interface", "ipv4", "delete", "address", ifName, dummyIPAddressStr)
99100
if err != nil {
100-
c.logger.Info("Could not remove dummy ip", zap.String("output", ret), zap.Error(err))
101+
c.logger.Info("Could not remove dummy ip, likely because it doesn't exist", zap.String("output", ret), zap.Error(err))
101102
}
102103
time.Sleep(deleteIPAddressDelay)
103104

@@ -110,8 +111,10 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
110111
defer func() {
111112
ret, cleanupErr := c.execClient.ExecuteCommand(ctx, "netsh", "interface", "ipv4", "delete", "address", ifName, dummyIPAddressStr)
112113
if cleanupErr != nil {
113-
c.logger.Info("Could not remove dummy ip on leaving function", zap.String("output", ret), zap.Error(err))
114+
c.logger.Info("Failed to remove dummy ip on leaving function", zap.String("output", ret), zap.Error(err))
114115
}
116+
// wait for nic to retrieve autoconfiguration ip
117+
time.Sleep(returnDelay)
115118
}()
116119
// it takes time for the address to be assigned
117120
time.Sleep(addIPAddressDelay)

network/network_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ func (nw *networkManager) sendDHCPDiscoverOnSecondary(client dhcpClient, mac net
447447
if err != nil {
448448
return errors.Wrapf(err, "failed to issue dhcp discover packet to create mapping in host")
449449
}
450+
logger.Info("Successfully received DHCP reply packet")
450451
return nil
451452
}
452453

0 commit comments

Comments
 (0)