Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions platform/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Loading