mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-04-16 18:19:36 +00:00
Compare commits
3 commits
78bd74c544
...
2612045644
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2612045644 | ||
|
|
1029c39973 | ||
|
|
64a024833e |
2 changed files with 67 additions and 4 deletions
59
ipv6-dhcp-client-script.rsc
Normal file
59
ipv6-dhcp-client-script.rsc
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#!rsc by RouterOS
|
||||
# RouterOS script: ipv6-dhcp-client-script
|
||||
# Copyright (c) 2026 Christian Hesse <mail@eworm.de>
|
||||
# https://rsc.eworm.de/COPYING.md
|
||||
#
|
||||
# requires RouterOS, version=7.22
|
||||
#
|
||||
# TODO
|
||||
# https://rsc.eworm.de/doc/ipv6-dhcp-client-script.md
|
||||
|
||||
: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 ] = false) do={
|
||||
:exit;
|
||||
}
|
||||
|
||||
: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.");
|
||||
:exit;
|
||||
}
|
||||
|
||||
:global IPv6DHCPClientEnvVars {
|
||||
"na-address"=$"na-address";
|
||||
"na-valid"=$"na-valid";
|
||||
"pd-prefix"=$"pd-prefix";
|
||||
"pd-valid"=$"pd-valid" };
|
||||
|
||||
:local RunOrder ({});
|
||||
:foreach Script in=[ /system/script/find where source~("\n# provides: ipv6-dhcp-client-script\\b") ] do={
|
||||
:local ScriptVal [ /system/script/get $Script ];
|
||||
:local Store [ $ParseKeyValueStore [ $Grep ($ScriptVal->"source") ("\23 provides: ipv6-dhcp-client-script, ") ] ];
|
||||
|
||||
: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 IPv6DHCPClientEnvVars;
|
||||
} do={
|
||||
:global IPv6DHCPClientEnvVars; :set IPv6DHCPClientEnvVars;
|
||||
:global ExitOnError; $ExitOnError [ :jobname ] $Err;
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
# https://rsc.eworm.de/COPYING.md
|
||||
#
|
||||
# requires RouterOS, version=7.22
|
||||
# provides: ipv6-dhcp-client-script, order=40
|
||||
#
|
||||
# update firewall and dns settings on IPv6 prefix change
|
||||
# https://rsc.eworm.de/doc/ipv6-update.md
|
||||
|
|
@ -14,14 +15,17 @@
|
|||
do={ :error ("Global config and/or functions not ready."); }; } delay=500ms max=50;
|
||||
:local ScriptName [ :jobname ];
|
||||
|
||||
:global EitherOr;
|
||||
:global LogPrint;
|
||||
:global ParseKeyValueStore;
|
||||
:global ScriptLock;
|
||||
|
||||
:local NaAddress $"na-address";
|
||||
:local NaValid $"na-valid";
|
||||
:local PdPrefix $"pd-prefix";
|
||||
:local PdValid $"pd-valid";
|
||||
:global IPv6DHCPClientEnvVars;
|
||||
|
||||
:local NaAddress [ $EitherOr $"na-address" ($IPv6DHCPClientEnvVars->"na-address") ];
|
||||
:local NaValid [ $EitherOr $"na-valid" ($IPv6DHCPClientEnvVars->"na-valid") ];
|
||||
:local PdPrefix [ $EitherOr $"pd-prefix" ($IPv6DHCPClientEnvVars->"pd-prefix") ];
|
||||
:local PdValid [ $EitherOr $"pd-valid" ($IPv6DHCPClientEnvVars->"pd-valid") ];
|
||||
|
||||
:if ([ $ScriptLock $ScriptName ] = false) do={
|
||||
:exit;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue