mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-04-16 18:19:36 +00:00
63 lines
2.1 KiB
Text
63 lines
2.1 KiB
Text
#!rsc by RouterOS
|
|
# RouterOS script: dhcpv6-client-lease
|
|
# Copyright (c) 2026 Christian Hesse <mail@eworm.de>
|
|
# https://rsc.eworm.de/COPYING.md
|
|
#
|
|
# requires RouterOS, version=7.19
|
|
#
|
|
# run scripts on IPv6 DHCP client lease
|
|
# https://rsc.eworm.de/doc/dhcpv6-client-lease.md
|
|
|
|
:local ExitOK false;
|
|
:onerror Err {
|
|
:global GlobalConfigReady; :global GlobalFunctionsReady;
|
|
:retry { :if ($GlobalConfigReady != true || $GlobalFunctionsReady != true) \
|
|
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
|
|
:local ScriptName [ :jobname ];
|
|
|
|
:global Grep;
|
|
:global LogPrint;
|
|
:global ParseKeyValueStore;
|
|
:global ScriptLock;
|
|
|
|
:if ([ $ScriptLock $ScriptName 10 ] = false) do={
|
|
:set ExitOK true;
|
|
:error false;
|
|
}
|
|
|
|
:if (([ :typeof $"na-address" ] = "nothing" || [ :typeof $"na-valid" ] = "nothing") && \
|
|
([ :typeof $"pd-prefix" ] = "nothing" || [ :typeof $"pd-valid" ] = "nothing")) do={
|
|
$LogPrint error $ScriptName ("This script is supposed to run from ipv6 dhcp-client.");
|
|
:set ExitOK true;
|
|
:error false;
|
|
}
|
|
|
|
:global DHCPv6ClientLeaseVars {
|
|
"na-address"=$"na-address";
|
|
"na-valid"=$"na-valid";
|
|
"pd-prefix"=$"pd-prefix";
|
|
"pd-valid"=$"pd-valid";
|
|
"options"=$"options" };
|
|
|
|
:local RunOrder ({});
|
|
:foreach Script in=[ /system/script/find where source~("\n# provides: dhcpv6-client-lease\\b") ] do={
|
|
:local ScriptVal [ /system/script/get $Script ];
|
|
:local Store [ $ParseKeyValueStore [ $Grep ($ScriptVal->"source") ("\23 provides: dhcpv6-client-lease, ") ] ];
|
|
|
|
:set ($RunOrder->($Store->"order" . "-" . $ScriptVal->"name")) ($ScriptVal->"name");
|
|
}
|
|
|
|
:foreach Order,Script in=$RunOrder do={
|
|
:onerror Err {
|
|
$LogPrint debug $ScriptName ("Running script with order " . $Order . ": " . $Script);
|
|
/system/script/run $Script;
|
|
} do={
|
|
$LogPrint warning $ScriptName ("Running script '" . $Script . "' failed: " . $Err);
|
|
}
|
|
}
|
|
|
|
:set DHCPv6ClientLeaseVars;
|
|
} do={
|
|
:global DHCPv6ClientLeaseVars; :set DHCPv6ClientLeaseVars;
|
|
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
|
|
}
|