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
8 changes: 8 additions & 0 deletions cns/restserver/restserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,14 @@ func (service *HTTPRestService) getNetworkContainerByOrchestratorContext(w http.
return
}

// getNetworkContainerByOrchestratorContext gets called for multitenancy and
// setting the SDNRemoteArpMacAddress regKey is essential for the multitenancy
// to work correctly in case of windows platform. Return if there is an error
if err = platform.SetSdnRemoteArpMacAddress(); err != nil {
log.Printf("[Azure CNS] SetSdnRemoteArpMacAddress failed with error: %s", err.Error())
return
}

getNetworkContainerResponse := service.getNetworkContainerResponse(req)
returnCode := getNetworkContainerResponse.Response.ReturnCode
err = service.Listener.Encode(w, &getNetworkContainerResponse)
Expand Down
6 changes: 6 additions & 0 deletions platform/os_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,9 @@ func KillProcessByName(processName string) error {
_, err := ExecuteCommand(cmd)
return err
}

// SetSdnRemoteArpMacAddress sets the regkey for SDNRemoteArpMacAddress needed for multitenancy
// This operation is specific to windows OS
func SetSdnRemoteArpMacAddress() error {
return nil
}
64 changes: 64 additions & 0 deletions platform/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,27 @@ const (

// DNCRuntimePath is the path where DNC state files are stored.
DNCRuntimePath = ""

// SDNRemoteArpMacAddress is the registry key for the remote arp mac address.
// This is set for multitenancy to get arp response from within VM
// for vlan tagged arp requests
SDNRemoteArpMacAddress = "12-34-56-78-9a-bc"

// Command to get SDNRemoteArpMacAddress registry key
GetSdnRemoteArpMacAddressCommand = "(Get-ItemProperty " +
"-Path HKLM:\\SYSTEM\\CurrentControlSet\\Services\\hns\\State -Name SDNRemoteArpMacAddress).SDNRemoteArpMacAddress"

// Command to set SDNRemoteArpMacAddress registry key
SetSdnRemoteArpMacAddressCommand = "Set-ItemProperty " +
"-Path HKLM:\\SYSTEM\\CurrentControlSet\\Services\\hns\\State -Name SDNRemoteArpMacAddress -Value \"12-34-56-78-9a-bc\""

// Command to restart HNS service
RestartHnsServiceCommand = "Restart-Service -Name hns"
)

// Flag to check if sdnRemoteArpMacAddress registry key is set
var sdnRemoteArpMacAddressSet = false

// GetOSInfo returns OS version information.
func GetOSInfo() string {
return "windows"
Expand Down Expand Up @@ -118,3 +137,48 @@ func KillProcessByName(processName string) {
cmd := fmt.Sprintf("taskkill /IM %v /F", processName)
ExecuteCommand(cmd)
}

// executePowershellCommand executes powershell command
func executePowershellCommand(command string) (string, error) {
ps, err := exec.LookPath("powershell.exe")
if err != nil {
return "", fmt.Errorf("Failed to find powershell executable")
}

cmd := exec.Command(ps, command)
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Run()

return strings.TrimSpace(stdout.String()), nil
}

// SetSdnRemoteArpMacAddress sets the regkey for SDNRemoteArpMacAddress needed for multitenancy
func SetSdnRemoteArpMacAddress() error {
if sdnRemoteArpMacAddressSet == false {
result, err := executePowershellCommand(GetSdnRemoteArpMacAddressCommand)
if err != nil {
return err
}

// Set the reg key if not already set or has incorrect value
if result != SDNRemoteArpMacAddress {
if _, err = executePowershellCommand(SetSdnRemoteArpMacAddressCommand); err != nil {
log.Printf("Failed to set SDNRemoteArpMacAddress due to error %s", err.Error())
return err
}

log.Printf("[Azure CNS] SDNRemoteArpMacAddress regKey set successfully. Restarting hns service.")
if _, err := executePowershellCommand(RestartHnsServiceCommand); err != nil {
log.Printf("Failed to Restart HNS Service due to error %s", err.Error())
return err
}
}

sdnRemoteArpMacAddressSet = true
}

return nil
}