Skip to content

Commit fd36e39

Browse files
committed
address feedback, move send request to before hns network creation
1 parent 4b357e2 commit fd36e39

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

dhcp/dhcp_windows.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
)
1313

1414
const (
15-
dummyIPAddressStr = "169.254.128.10"
16-
dummySubnetMask = "255.255.128.0"
17-
addIPAddressTimeout = 10 * time.Second
18-
deleteIPAddressTimeout = 2 * time.Second
15+
dummyIPAddressStr = "169.254.128.10"
16+
dummySubnetMask = "255.255.128.0"
17+
addIPAddressDelay = 4 * time.Second
18+
deleteIPAddressDelay = 2 * time.Second
1919

20-
socketTimeout = 1000
20+
socketTimeoutMillis = 1000
2121
)
2222

2323
var (
@@ -53,7 +53,7 @@ func NewSocket(destAddr windows.SockaddrInet4) (*Socket, error) {
5353
return ret, errors.Wrap(err, "error setting SO_BROADCAST")
5454
}
5555
// Set timeout
56-
if err = windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_RCVTIMEO, socketTimeout); err != nil {
56+
if err = windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_RCVTIMEO, socketTimeoutMillis); err != nil {
5757
return ret, errors.Wrap(err, "error setting receive timeout")
5858
}
5959
return ret, nil
@@ -99,7 +99,7 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
9999
if err != nil {
100100
c.logger.Info("Could not remove dummy ip", zap.String("output", ret), zap.Error(err))
101101
}
102-
time.Sleep(deleteIPAddressTimeout)
102+
time.Sleep(deleteIPAddressDelay)
103103

104104
// create dummy ip so we can direct the packet to the correct interface
105105
ret, err = c.execClient.ExecuteCommand(ctx, "netsh", "interface", "ipv4", "add", "address", ifName, dummyIPAddressStr, dummySubnetMask)
@@ -114,7 +114,7 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
114114
}
115115
}()
116116
// it takes time for the address to be assigned
117-
time.Sleep(addIPAddressTimeout)
117+
time.Sleep(addIPAddressDelay)
118118

119119
// now begin the dhcp request
120120
txid, err := GenerateTransactionID()

network/endpoint_windows.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"net"
1010
"strings"
11-
"time"
1211

1312
"github.com/Azure/azure-container-networking/cns"
1413
"github.com/Azure/azure-container-networking/netio"
@@ -142,21 +141,6 @@ func (nw *network) getEndpointWithVFDevice(plc platform.ExecClient, epInfo *Endp
142141
return ep, nil
143142
}
144143

145-
func (nw *network) sendDHCPDiscoverOnSecondary(client dhcpClient, mac net.HardwareAddr, ifName string) error {
146-
// issue dhcp discover packet to ensure mapping created for dns via wireserver to work
147-
// we do not use the response for anything
148-
numSecs := 15 // we need to wait for the address to be assigned
149-
timeout := time.Duration(numSecs) * time.Second
150-
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(timeout))
151-
defer cancel()
152-
logger.Info("Sending DHCP packet", zap.Any("macAddress", mac), zap.String("ifName", ifName))
153-
err := client.DiscoverRequest(ctx, mac, ifName)
154-
if err != nil {
155-
return errors.Wrapf(err, "failed to issue dhcp discover packet to create mapping in host")
156-
}
157-
return nil
158-
}
159-
160144
// newEndpointImpl creates a new endpoint in the network.
161145
func (nw *network) newEndpointImpl(
162146
cli apipaClient,
@@ -172,12 +156,6 @@ func (nw *network) newEndpointImpl(
172156
if epInfo.NICType == cns.BackendNIC {
173157
return nw.getEndpointWithVFDevice(plc, epInfo)
174158
}
175-
if epInfo.NICType == cns.NodeNetworkInterfaceFrontendNIC {
176-
// use master interface name, interface name, or adapter name?
177-
if err := nw.sendDHCPDiscoverOnSecondary(dhcpc, epInfo.MacAddress, epInfo.MasterIfName); err != nil {
178-
return nil, err
179-
}
180-
}
181159

182160
if useHnsV2, err := UseHnsV2(epInfo.NetNsPath); useHnsV2 {
183161
if err != nil {

network/network_windows.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package network
55

66
import (
7+
"context"
78
"encoding/json"
89
"fmt"
10+
"net"
911
"strconv"
1012
"strings"
1113
"time"
@@ -433,8 +435,30 @@ func (nm *networkManager) newNetworkImplHnsV2(nwInfo *EndpointInfo, extIf *exter
433435
return nw, nil
434436
}
435437

438+
func (nw *networkManager) sendDHCPDiscoverOnSecondary(client dhcpClient, mac net.HardwareAddr, ifName string) error {
439+
// issue dhcp discover packet to ensure mapping created for dns via wireserver to work
440+
// we do not use the response for anything
441+
numSecs := 15 // we need to wait for the address to be assigned
442+
timeout := time.Duration(numSecs) * time.Second
443+
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(timeout))
444+
defer cancel()
445+
logger.Info("Sending DHCP packet", zap.Any("macAddress", mac), zap.String("ifName", ifName))
446+
err := client.DiscoverRequest(ctx, mac, ifName)
447+
if err != nil {
448+
return errors.Wrapf(err, "failed to issue dhcp discover packet to create mapping in host")
449+
}
450+
return nil
451+
}
452+
436453
// NewNetworkImpl creates a new container network.
437454
func (nm *networkManager) newNetworkImpl(nwInfo *EndpointInfo, extIf *externalInterface) (*network, error) {
455+
if nwInfo.NICType == cns.NodeNetworkInterfaceFrontendNIC {
456+
// use master interface name, interface name, or adapter name?
457+
if err := nm.sendDHCPDiscoverOnSecondary(nm.dhcpClient, nwInfo.MacAddress, nwInfo.MasterIfName); err != nil {
458+
return nil, err
459+
}
460+
}
461+
438462
if useHnsV2, err := UseHnsV2(nwInfo.NetNs); useHnsV2 {
439463
if err != nil {
440464
return nil, err

0 commit comments

Comments
 (0)