@@ -16,6 +16,7 @@ import (
1616 "github.com/Microsoft/hcsshim/hcn"
1717)
1818
19+ // TODO redesign hnsclient on windows
1920const (
2021 // Name of the external hns network
2122 ExtHnsNetworkName = "ext"
@@ -52,6 +53,9 @@ const (
5253 // Name of the loopback adapter needed to create Host NC apipa network
5354 hostNCLoopbackAdapterName = "LoopbackAdapterHostNCConnectivity"
5455
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"
5559 // protocolTCP indicates the TCP protocol identifier in HCN
5660 protocolTCP = "6"
5761
@@ -297,7 +301,7 @@ func createHostNCApipaNetwork(
297301 if interfaceExists , _ := networkcontainers .InterfaceExists (hostNCLoopbackAdapterName ); ! interfaceExists {
298302 ipconfig := cns.IPConfiguration {
299303 IPSubnet : cns.IPSubnet {
300- IPAddress : localIPConfiguration . GatewayIPAddress ,
304+ IPAddress : hnsLoopbackAdapterIPAddress ,
301305 PrefixLength : localIPConfiguration .IPSubnet .PrefixLength ,
302306 },
303307 GatewayIPAddress : localIPConfiguration .GatewayIPAddress ,
@@ -506,7 +510,7 @@ func configureHostNCApipaEndpoint(
506510 endpointPolicies , err := configureAclSettingHostNCApipaEndpoint (
507511 protocolList ,
508512 networkContainerApipaIP ,
509- hostApipaIP ,
513+ hnsLoopbackAdapterIPAddress ,
510514 allowNCToHostCommunication ,
511515 allowHostToNCCommunication ,
512516 ncPolicies )
@@ -569,6 +573,7 @@ func CreateHostNCApipaEndpoint(
569573 return endpoint .Id , nil
570574 }
571575
576+ updateGwForLocalIPConfiguration (& localIPConfiguration )
572577 if network , err = createHostNCApipaNetwork (localIPConfiguration ); err != nil {
573578 logger .Errorf ("[Azure CNS] Failed to create HostNCApipaNetwork. Error: %v" , err )
574579 return "" , err
@@ -600,6 +605,17 @@ func CreateHostNCApipaEndpoint(
600605 return endpoint .Id , nil
601606}
602607
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+
603619func getHostNCApipaEndpointName (
604620 networkContainerID string ) string {
605621 return hostNCApipaEndpointNamePrefix + "-" + networkContainerID
0 commit comments