@@ -34,8 +34,27 @@ const (
3434
3535 // DNCRuntimePath is the path where DNC state files are stored.
3636 DNCRuntimePath = ""
37+
38+ // SDNRemoteArpMacAddress is the registry key for the remote arp mac address.
39+ // This is set for multitenancy to get arp response from within VM
40+ // for vlan tagged arp requests
41+ SDNRemoteArpMacAddress = "12-34-56-78-9a-bc"
42+
43+ // Command to get SDNRemoteArpMacAddress registry key
44+ GetSdnRemoteArpMacAddressCommand = "(Get-ItemProperty " +
45+ "-Path HKLM:\\ SYSTEM\\ CurrentControlSet\\ Services\\ hns\\ State -Name SDNRemoteArpMacAddress).SDNRemoteArpMacAddress"
46+
47+ // Command to set SDNRemoteArpMacAddress registry key
48+ SetSdnRemoteArpMacAddressCommand = "Set-ItemProperty " +
49+ "-Path HKLM:\\ SYSTEM\\ CurrentControlSet\\ Services\\ hns\\ State -Name SDNRemoteArpMacAddress -Value \" 12-34-56-78-9a-bc\" "
50+
51+ // Command to restart HNS service
52+ RestartHnsServiceCommand = "Restart-Service -Name hns"
3753)
3854
55+ // Flag to check if sdnRemoteArpMacAddress registry key is set
56+ var sdnRemoteArpMacAddressSet = false
57+
3958// GetOSInfo returns OS version information.
4059func GetOSInfo () string {
4160 return "windows"
@@ -118,3 +137,48 @@ func KillProcessByName(processName string) {
118137 cmd := fmt .Sprintf ("taskkill /IM %v /F" , processName )
119138 ExecuteCommand (cmd )
120139}
140+
141+ // executePowershellCommand executes powershell command
142+ func executePowershellCommand (command string ) (string , error ) {
143+ ps , err := exec .LookPath ("powershell.exe" )
144+ if err != nil {
145+ return "" , fmt .Errorf ("Failed to find powershell executable" )
146+ }
147+
148+ cmd := exec .Command (ps , command )
149+ var stdout bytes.Buffer
150+ var stderr bytes.Buffer
151+ cmd .Stdout = & stdout
152+ cmd .Stderr = & stderr
153+ cmd .Run ()
154+
155+ return strings .TrimSpace (stdout .String ()), nil
156+ }
157+
158+ // SetSdnRemoteArpMacAddress sets the regkey for SDNRemoteArpMacAddress needed for multitenancy
159+ func SetSdnRemoteArpMacAddress () error {
160+ if sdnRemoteArpMacAddressSet == false {
161+ result , err := executePowershellCommand (GetSdnRemoteArpMacAddressCommand )
162+ if err != nil {
163+ return err
164+ }
165+
166+ // Set the reg key if not already set or has incorrect value
167+ if result != SDNRemoteArpMacAddress {
168+ if _ , err = executePowershellCommand (SetSdnRemoteArpMacAddressCommand ); err != nil {
169+ log .Printf ("Failed to set SDNRemoteArpMacAddress due to error %s" , err .Error ())
170+ return err
171+ }
172+
173+ log .Printf ("[Azure CNS] SDNRemoteArpMacAddress regKey set successfully. Restarting hns service." )
174+ if _ , err := executePowershellCommand (RestartHnsServiceCommand ); err != nil {
175+ log .Printf ("Failed to Restart HNS Service due to error %s" , err .Error ())
176+ return err
177+ }
178+ }
179+
180+ sdnRemoteArpMacAddressSet = true
181+ }
182+
183+ return nil
184+ }
0 commit comments