@@ -16,6 +16,7 @@ import (
16
16
"github.com/Microsoft/hcsshim/hcn"
17
17
)
18
18
19
+ // TODO redesign hnsclient on windows
19
20
const (
20
21
// Name of the external hns network
21
22
ExtHnsNetworkName = "ext"
@@ -52,6 +53,9 @@ const (
52
53
// Name of the loopback adapter needed to create Host NC apipa network
53
54
hostNCLoopbackAdapterName = "LoopbackAdapterHostNCConnectivity"
54
55
56
+ // HNS rehydration issue requires this GW to be different than the loopback adapter ip, so we set it to .2
57
+ defaultHnsGwIPAddress = "169.254.128.2"
58
+ hnsLoopbackAdapterIPAddress = "169.254.128.1"
55
59
// protocolTCP indicates the TCP protocol identifier in HCN
56
60
protocolTCP = "6"
57
61
@@ -297,7 +301,7 @@ func createHostNCApipaNetwork(
297
301
if interfaceExists , _ := networkcontainers .InterfaceExists (hostNCLoopbackAdapterName ); ! interfaceExists {
298
302
ipconfig := cns.IPConfiguration {
299
303
IPSubnet : cns.IPSubnet {
300
- IPAddress : localIPConfiguration . GatewayIPAddress ,
304
+ IPAddress : hnsLoopbackAdapterIPAddress ,
301
305
PrefixLength : localIPConfiguration .IPSubnet .PrefixLength ,
302
306
},
303
307
GatewayIPAddress : localIPConfiguration .GatewayIPAddress ,
@@ -506,7 +510,7 @@ func configureHostNCApipaEndpoint(
506
510
endpointPolicies , err := configureAclSettingHostNCApipaEndpoint (
507
511
protocolList ,
508
512
networkContainerApipaIP ,
509
- hostApipaIP ,
513
+ hnsLoopbackAdapterIPAddress ,
510
514
allowNCToHostCommunication ,
511
515
allowHostToNCCommunication ,
512
516
ncPolicies )
@@ -569,6 +573,7 @@ func CreateHostNCApipaEndpoint(
569
573
return endpoint .Id , nil
570
574
}
571
575
576
+ updateGwForLocalIPConfiguration (& localIPConfiguration )
572
577
if network , err = createHostNCApipaNetwork (localIPConfiguration ); err != nil {
573
578
logger .Errorf ("[Azure CNS] Failed to create HostNCApipaNetwork. Error: %v" , err )
574
579
return "" , err
@@ -600,6 +605,17 @@ func CreateHostNCApipaEndpoint(
600
605
return endpoint .Id , nil
601
606
}
602
607
608
+ // updateGwForLocalIPConfiguration applies change on gw IP address for apipa NW and endpoint.
609
+ // Currently, cns using the same ip address "169.254.128.1" for both apipa gw and loopback adapter. This cause conflict issue when hns get restarted and not able to rehydrate the apipa endpoints.
610
+ // This func is to overwrite the address to 169.254.128.2 when the gateway address is 169.254.128.1
611
+ func updateGwForLocalIPConfiguration (localIPConfiguration * cns.IPConfiguration ) {
612
+ // When gw address is 169.254.128.1, should use .2 instead. If gw address is not .1, that mean this value is
613
+ // configured from dnc, we should keep it
614
+ if localIPConfiguration .GatewayIPAddress == "169.254.128.1" {
615
+ localIPConfiguration .GatewayIPAddress = defaultHnsGwIPAddress
616
+ }
617
+ }
618
+
603
619
func getHostNCApipaEndpointName (
604
620
networkContainerID string ) string {
605
621
return hostNCApipaEndpointNamePrefix + "-" + networkContainerID
0 commit comments