diff --git a/cns/service/main.go b/cns/service/main.go index fb1655accd..a022fedf74 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -799,14 +799,11 @@ func main() { } // Setting the remote ARP MAC address to 12-34-56-78-9a-bc on windows for external traffic if HNS is enabled - arpCtx, arpCtxCancel := context.WithTimeout(rootCtx, 30*time.Second) - err = platform.SetSdnRemoteArpMacAddress(arpCtx) + err = platform.SetSdnRemoteArpMacAddress(rootCtx) if err != nil { logger.Errorf("Failed to set remote ARP MAC address: %v", err) - arpCtxCancel() return } - arpCtxCancel() // We are only setting the PriorityVLANTag in 'cns.Direct' mode, because it neatly maps today, to 'isUsingMultitenancy' // In the future, we would want to have a better CNS flag, to explicitly say, this CNS is using multitenancy diff --git a/platform/os_windows.go b/platform/os_windows.go index 1ce81b24d8..234182d203 100644 --- a/platform/os_windows.go +++ b/platform/os_windows.go @@ -247,9 +247,14 @@ func (p *execClient) ExecutePowershellCommandWithContext(ctx context.Context, co // SetSdnRemoteArpMacAddress sets the regkey for SDNRemoteArpMacAddress needed for multitenancy if hns is enabled func SetSdnRemoteArpMacAddress(ctx context.Context) error { - if err := setSDNRemoteARPRegKey(); err != nil { + changed, err := setSDNRemoteARPRegKey() + if err != nil { return err } + if !changed { + log.Printf("SDNRemoteArpMacAddress regKey already set, skipping HNS restart") + return nil + } log.Printf("SDNRemoteArpMacAddress regKey set successfully") if err := restartHNS(ctx); err != nil { return err @@ -258,26 +263,28 @@ func SetSdnRemoteArpMacAddress(ctx context.Context) error { return nil } -func setSDNRemoteARPRegKey() error { +// setSDNRemoteARPRegKey sets the SDNRemoteArpMacAddress registry key +// returns true if the key was changed, false if unchanged +func setSDNRemoteARPRegKey() (bool, error) { log.Printf("Setting SDNRemoteArpMacAddress regKey") // open the registry key k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Services\hns\State`, registry.READ|registry.SET_VALUE) if err != nil { if errors.Is(err, registry.ErrNotExist) { - return nil + return false, nil } - return errors.Wrap(err, "could not open registry key") + return false, errors.Wrap(err, "could not open registry key") } defer k.Close() // check the key value if v, _, _ := k.GetStringValue("SDNRemoteArpMacAddress"); v == SDNRemoteArpMacAddress { log.Printf("SDNRemoteArpMacAddress regKey already set") - return nil // already set + return false, nil // already set } if err = k.SetStringValue("SDNRemoteArpMacAddress", SDNRemoteArpMacAddress); err != nil { - return errors.Wrap(err, "could not set registry key") + return false, errors.Wrap(err, "could not set registry key") } - return nil + return true, nil } func restartHNS(ctx context.Context) error {