Skip to content

Commit

Permalink
on network change remove the current IP address from the DNS list
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-nettica committed Jul 1, 2024
1 parent 1e11b6f commit 2ad3836
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/v1/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func updateNet(c *gin.Context) {

updateMTU := false
updateAddress := false
updateDNS := false
updateAllowed := false
updateFailSafe := false
updatePresharedKey := false
Expand All @@ -247,6 +248,7 @@ func updateNet(c *gin.Context) {
if !util.CompareArrays(data.Default.Address, net.Default.Address) {
log.Infof("updateNet: updateAddress for %s %v", data.NetName, data.Default.Address)
updateAddress = true
updateDNS = true
}
if !util.CompareArrays(data.Default.AllowedIPs, net.Default.AllowedIPs) {
log.Infof("updateNet: updateAllowed for %s %v", data.NetName, data.Default.AllowedIPs)
Expand Down Expand Up @@ -279,6 +281,22 @@ func updateNet(c *gin.Context) {
v.Current.Mtu = data.Default.Mtu
changed = true
}
if updateDNS {
log.Infof("updateNet: updateDNS for %s %v", v.Id, data.Default.Address)
v.Default.Dns = data.Default.Dns
for x, dns := range v.Current.Dns {
if dns == v.Current.Address[0] {
v.Current.Dns = append(v.Current.Dns[:x], v.Current.Dns[x+1:]...)
break
}
ip, err := util.GetIpFromCidr(v.Current.Address[0])
if err == nil && dns == ip {
v.Current.Dns = append(v.Current.Dns[:x], v.Current.Dns[x+1:]...)
break
}
}
changed = true
}
if updateAddress && !util.CompareArrays(v.Default.Address, data.Default.Address) {
log.Infof("updateNet: updateAddress for %s %v", v.Id, data.Default.Address)
v.Default.Address = data.Default.Address
Expand Down

0 comments on commit 2ad3836

Please sign in to comment.