aboutsummaryrefslogtreecommitdiffstats
path: root/dhcp-to-dns.rsc
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2023-04-12 23:43:45 +0200
committerGravatar Christian Hesse <mail@eworm.de>2023-04-24 22:26:26 +0200
commit79cdefbd1e3c10f6ed87b705d1993eaf9d219d47 (patch)
treea50db1c741930b30e1100b64e9f7022597173b86 /dhcp-to-dns.rsc
parent517bb4ede8192b2e6bce765f56fa684581f998e3 (diff)
dhcp-to-dns: handle change of domain
Diffstat (limited to 'dhcp-to-dns.rsc')
-rw-r--r--dhcp-to-dns.rsc21
1 files changed, 11 insertions, 10 deletions
diff --git a/dhcp-to-dns.rsc b/dhcp-to-dns.rsc
index 8a2cf0b..9d785d2 100644
--- a/dhcp-to-dns.rsc
+++ b/dhcp-to-dns.rsc
@@ -49,7 +49,7 @@ $ScriptLock $0 false 10;
:local Found false;
$LogPrintExit2 info $0 ("Lease expired for " . $MacAddress . " (" . $DnsRecordVal->"name" . "), deleting DNS entry.") false;
/ip/dns/static/remove $DnsRecord;
- /ip/dns/static/remove [ find where type=CNAME cname=($DnsRecordVal->"name") comment=($DnsRecordVal->"comment") ];
+ /ip/dns/static/remove [ find where type=CNAME comment=($DnsRecordVal->"comment") ];
}
}
@@ -76,26 +76,27 @@ $ScriptLock $0 false 10;
:if ([ :len $DnsRecord ] > 0) do={
:local DnsRecordVal [ /ip/dns/static/get $DnsRecord ];
- :if ($DnsRecordVal->"address" = $LeaseVal->"address") do={
- $LogPrintExit2 debug $0 ("DNS entry for " . ($MacDash . "." . $Domain) . " does not need updating.") false;
+ :if ($DnsRecordVal->"address" = $LeaseVal->"address" && $DnsRecordVal->"name" = ($MacDash . "." . $Domain)) do={
+ $LogPrintExit2 debug $0 ("DNS entry for " . $LeaseVal->"mac-address" . " does not need updating.") false;
} else={
- $LogPrintExit2 info $0 ("Replacing DNS entry for " . ($MacDash . "." . $Domain) . ", new address is " . $LeaseVal->"address" . ".") false;
- /ip/dns/static/set address=($LeaseVal->"address") $DnsRecord;
+ $LogPrintExit2 info $0 ("Replacing DNS entry for " . $LeaseVal->"mac-address" . " (" . ($MacDash . "." . $Domain) . " -> " . $LeaseVal->"address" . ").") false;
+ /ip/dns/static/set address=($LeaseVal->"address") name=($MacDash . "." . $Domain) $DnsRecord;
}
- :local Cname [ /ip/dns/static/find where type=CNAME cname=($MacDash . "." . $Domain) comment=$Comment ];
+ :local Cname [ /ip/dns/static/find where comment=$Comment type=CNAME ];
:if ([ :len $Cname ] = 0 && [ :len $HostName ] > 0) do={
- $LogPrintExit2 info $0 ("Host name appeared, adding CNAME " . ($HostName . "." . $Domain) . " pointing to " . ($MacDash . "." . $Domain) . ".") false;
+ $LogPrintExit2 info $0 ("Host name appeared, adding CNAME (" . ($HostName . "." . $Domain) . " -> " . ($MacDash . "." . $Domain) . ").") false;
/ip/dns/static/add name=($HostName . "." . $Domain) type=CNAME cname=($MacDash . "." . $Domain) ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
}
:if ([ :len $Cname ] > 0 && [ /ip/dns/static/get $Cname name ] != ($HostName . "." . $Domain)) do={
- $LogPrintExit2 info $0 ("Host name changed, updating CNAME (pointing to " . ($MacDash . "." . $Domain) . ") to " . ($HostName . "." . $Domain) . ".") false;
- /ip/dns/static/set name=($HostName . "." . $Domain) $Cname;
+ $LogPrintExit2 info $0 ("Host name or domain changed, updating CNAME (" . ($HostName . "." . $Domain) . " -> " . ($MacDash . "." . $Domain) . ").") false;
+ /ip/dns/static/set name=($HostName . "." . $Domain) cname=($MacDash . "." . $Domain) $Cname;
}
} else={
- $LogPrintExit2 info $0 ("Adding new DNS entry for " . ($MacDash . "." . $Domain) . ", address is " . $LeaseVal->"address" . ".") false;
+ $LogPrintExit2 info $0 ("Adding new DNS entry for " . $LeaseVal->"mac-address" . " (" . ($MacDash . "." . $Domain) . " -> " . $LeaseVal->"address" . ").") false;
/ip/dns/static/add name=($MacDash . "." . $Domain) type=A address=($LeaseVal->"address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
:if ([ :len $HostName ] > 0) do={
+ $LogPrintExit2 info $0 ("Adding new CNAME (" . ($HostName . "." . $Domain) . " -> " . ($MacDash . "." . $Domain) . ").") false;
/ip/dns/static/add name=($HostName . "." . $Domain) type=CNAME cname=($MacDash . "." . $Domain) ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
}
}