use interface as hostctl profile

This commit is contained in:
Matthew R. Kasun
2022-03-18 10:10:34 -04:00
parent ef0d34c119
commit 3b12f55de0

View File

@@ -204,19 +204,19 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) {
return return
} }
if cfg.Node.DNSOn == "yes" { if cfg.Node.DNSOn == "yes" {
if err := setHostDNS(peerUpdate.DNS, cfg.Node.Network, ncutils.IsWindows()); err != nil { if err := setHostDNS(peerUpdate.DNS, cfg.Node.Interface, ncutils.IsWindows()); err != nil {
ncutils.Log("error updating /etc/hosts " + err.Error()) ncutils.Log("error updating /etc/hosts " + err.Error())
return return
} }
} else { } else {
if err := removeHostDNS(cfg.Node.Network, ncutils.IsWindows()); err != nil { if err := removeHostDNS(cfg.Node.Interface, ncutils.IsWindows()); err != nil {
ncutils.Log("error removing profile from /etc/hosts " + err.Error()) ncutils.Log("error removing profile from /etc/hosts " + err.Error())
return return
} }
} }
} }
func setHostDNS(dns, network string, windows bool) error { func setHostDNS(dns, iface string, windows bool) error {
etchosts := "/etc/hosts" etchosts := "/etc/hosts"
if windows { if windows {
etchosts = "c:\\windows\\system32\\drivers\\etc\\hosts" etchosts = "c:\\windows\\system32\\drivers\\etc\\hosts"
@@ -230,7 +230,7 @@ func setHostDNS(dns, network string, windows bool) error {
if err != nil { if err != nil {
return err return err
} }
profile.Name = network profile.Name = iface
profile.Status = types.Enabled profile.Status = types.Enabled
if err := hosts.ReplaceProfile(profile); err != nil { if err := hosts.ReplaceProfile(profile); err != nil {
return err return err
@@ -241,7 +241,7 @@ func setHostDNS(dns, network string, windows bool) error {
return nil return nil
} }
func removeHostDNS(network string, windows bool) error { func removeHostDNS(iface string, windows bool) error {
etchosts := "/etc/hosts" etchosts := "/etc/hosts"
if windows { if windows {
etchosts = "c:\\windows\\system32\\drivers\\etc\\hosts" etchosts = "c:\\windows\\system32\\drivers\\etc\\hosts"
@@ -250,7 +250,10 @@ func removeHostDNS(network string, windows bool) error {
if err != nil { if err != nil {
return err return err
} }
if err := hosts.RemoveProfile(network); err != nil { if err := hosts.RemoveProfile(iface); err != nil {
if err == types.ErrUnknownProfile {
return nil
}
return err return err
} }
if err := hosts.Flush(); err != nil { if err := hosts.Flush(); err != nil {