@@ -17,6 +17,7 @@ import (
1717 "github.com/pkg/errors"
1818)
1919
20+ // TODO redesign hnsclient on windows
2021const (
2122 // Name of the external hns network
2223 ExtHnsNetworkName = "ext"
@@ -53,6 +54,9 @@ const (
5354 // Name of the loopback adapter needed to create Host NC apipa network
5455 hostNCLoopbackAdapterName = "LoopbackAdapterHostNCConnectivity"
5556
57+ // HNS rehydration issue requires this GW to be different than the loopback adapter ip, so we set it to .2
58+ defaultHnsGwIPAddress = "169.254.128.2"
59+ hnsLoopbackAdapterIPAddress = "169.254.128.1"
5660 // protocolTCP indicates the TCP protocol identifier in HCN
5761 protocolTCP = "6"
5862
@@ -301,7 +305,7 @@ func createHostNCApipaNetwork(
301305 if interfaceExists , _ := networkcontainers .InterfaceExists (hostNCLoopbackAdapterName ); ! interfaceExists {
302306 ipconfig := cns.IPConfiguration {
303307 IPSubnet : cns.IPSubnet {
304- IPAddress : localIPConfiguration . GatewayIPAddress ,
308+ IPAddress : hnsLoopbackAdapterIPAddress ,
305309 PrefixLength : localIPConfiguration .IPSubnet .PrefixLength ,
306310 },
307311 GatewayIPAddress : localIPConfiguration .GatewayIPAddress ,
@@ -510,7 +514,7 @@ func configureHostNCApipaEndpoint(
510514 endpointPolicies , err := configureAclSettingHostNCApipaEndpoint (
511515 protocolList ,
512516 networkContainerApipaIP ,
513- hostApipaIP ,
517+ hnsLoopbackAdapterIPAddress ,
514518 allowNCToHostCommunication ,
515519 allowHostToNCCommunication ,
516520 ncPolicies )
@@ -573,6 +577,7 @@ func CreateHostNCApipaEndpoint(
573577 return endpoint .Id , nil
574578 }
575579
580+ updateGwForLocalIPConfiguration (& localIPConfiguration )
576581 if network , err = createHostNCApipaNetwork (localIPConfiguration ); err != nil {
577582 logger .Errorf ("[Azure CNS] Failed to create HostNCApipaNetwork. Error: %v" , err )
578583 return "" , err
@@ -604,6 +609,17 @@ func CreateHostNCApipaEndpoint(
604609 return endpoint .Id , nil
605610}
606611
612+ // updateGwForLocalIPConfiguration applies change on gw IP address for apipa NW and endpoint.
613+ // 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.
614+ // This func is to overwrite the address to 169.254.128.2 when the gateway address is 169.254.128.1
615+ func updateGwForLocalIPConfiguration (localIPConfiguration * cns.IPConfiguration ) {
616+ // When gw address is 169.254.128.1, should use .2 instead. If gw address is not .1, that mean this value is
617+ // configured from dnc, we should keep it
618+ if localIPConfiguration .GatewayIPAddress == "169.254.128.1" {
619+ localIPConfiguration .GatewayIPAddress = defaultHnsGwIPAddress
620+ }
621+ }
622+
607623func getHostNCApipaEndpointName (
608624 networkContainerID string ) string {
609625 return hostNCApipaEndpointNamePrefix + "-" + networkContainerID
0 commit comments