mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-02-23 08:39:34 +00:00
Implement IPv6 DNS records creation
This commit is contained in:
parent
d4e5194a65
commit
ea047b4e51
1 changed files with 31 additions and 0 deletions
|
|
@ -46,6 +46,18 @@ $ScriptLock $0 false 10;
|
|||
/ip/dns/static/remove [ find where type=CNAME comment=($DnsRecordVal->"comment") ];
|
||||
}
|
||||
}
|
||||
:foreach DnsRecord in=[ /ip/dns/static/find where comment~("^" . $CommentPrefix) type=AAAA ] do={
|
||||
:local DnsRecordVal [ /ip/dns/static/get $DnsRecord ];
|
||||
:local MacAddress [ $CharacterReplace ($DnsRecordVal->"comment") $CommentPrefix "" ];
|
||||
:if (([ :len [ /ip/dhcp-server/lease/find where active-mac-address=$MacAddress status=bound ] ] > 0) and ([ :len [ /ipv6/neighbor/find where mac-address=$MacAddress address=($DnsRecordVal->"address") status!=failed ] ] > 0)) do={
|
||||
$LogPrintExit2 debug $0 ("Lease and IPv6 neighbor for " . $MacAddress . " (" . $DnsRecordVal->"name" . ") still exists. Not deleting AAAA DNS entry.") false;
|
||||
} else={
|
||||
:local Found false;
|
||||
$LogPrintExit2 info $0 ("Lease expired or IPv6 neighbor failed for " . $MacAddress . " (" . $DnsRecordVal->"name" . "), deleting AAAA DNS entry.") false;
|
||||
/ip/dns/static/remove $DnsRecord;
|
||||
# /ip/dns/static/remove [ find where type=CNAME comment=($DnsRecordVal->"comment") ];
|
||||
}
|
||||
}
|
||||
|
||||
:foreach Lease in=[ /ip/dhcp-server/lease/find where status=bound ] do={
|
||||
:local LeaseVal;
|
||||
|
|
@ -101,6 +113,25 @@ $ScriptLock $0 false 10;
|
|||
/ip/dns/static/add name=($HostName . "." . $NetDomain) type=CNAME cname=($MacDash . "." . $NetDomain) ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
|
||||
}
|
||||
}
|
||||
|
||||
:local V6Neighbors [ /ipv6/neighbor/find where mac-address=($LeaseVal->"active-mac-address") (((address & ffff::) ^ fe80::) != ::) (status=reachable) ];
|
||||
:if ([ :len $V6Neighbors ] > 0) do={
|
||||
:local V6Neighbor ($V6Neighbors->0);
|
||||
:local V6NeighborVal [ /ipv6/neighbor/get $V6Neighbor ];
|
||||
:local DnsRecord [ /ip/dns/static/find where comment=$Comment type=AAAA ];
|
||||
:if ([ :len $DnsRecord ] > 0) do={
|
||||
:local DnsRecordVal [ /ip/dns/static/get $DnsRecord ];
|
||||
:if ($DnsRecordVal->"address" = $V6NeighborVal->"address" && $DnsRecordVal->"name" = ($MacDash . "." . $NetDomain)) do={
|
||||
$LogPrintExit2 debug $0 ("V6 DNS entry for " . $LeaseVal->"active-mac-address" . " does not need updating.") false;
|
||||
} else={
|
||||
$LogPrintExit2 info $0 ("Replacing V6 DNS entry for " . $LeaseVal->"active-mac-address" . " (" . ($MacDash . "." . $NetDomain) . " -> " . $V6NeighborVal->"address" . ").") false;
|
||||
/ip/dns/static/set address=($V6NeighborVal->"address") name=($MacDash . "." . $NetDomain) $DnsRecord;
|
||||
}
|
||||
} else={
|
||||
$LogPrintExit2 info $0 ("Adding new V6 DNS entry for " . $LeaseVal->"active-mac-address" . " (" . ($MacDash . "." . $NetDomain) . " -> " . $V6NeighborVal->"address" . ").") false;
|
||||
/ip/dns/static/add name=($MacDash . "." . $NetDomain) type=AAAA address=($V6NeighborVal->"address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
|
||||
}
|
||||
}
|
||||
} else={
|
||||
$LogPrintExit2 debug $0 ("No address available... Ignoring.") false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue