mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-06-03 09:12:40 +00:00
introduce 'dhcpv6-client-lease' to run scripts on lease
This commit is contained in:
parent
e54a4572f7
commit
3a66eb4192
5 changed files with 131 additions and 1 deletions
|
|
@ -287,6 +287,7 @@ Available scripts
|
||||||
* [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md) (`dhcp-lease-comment`)
|
* [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md) (`dhcp-lease-comment`)
|
||||||
* [Create DNS records for DHCP leases](doc/dhcp-to-dns.md) (`dhcp-to-dns`)
|
* [Create DNS records for DHCP leases](doc/dhcp-to-dns.md) (`dhcp-to-dns`)
|
||||||
* [Run other scripts on IPv4 DHCP server lease](doc/dhcpv4-server-lease.md) (`dhcpv4-server-lease`)
|
* [Run other scripts on IPv4 DHCP server lease](doc/dhcpv4-server-lease.md) (`dhcpv4-server-lease`)
|
||||||
|
* [Run other scripts on IPv6 DHCP client lease](doc/dhcpv6-client-lease.md) (`dhcpv6-client-lease`)
|
||||||
* [Automatically upgrade firmware and reboot](doc/firmware-upgrade-reboot.md) (`firmware-upgrade-reboot`)
|
* [Automatically upgrade firmware and reboot](doc/firmware-upgrade-reboot.md) (`firmware-upgrade-reboot`)
|
||||||
* [Download, import and update firewall address-lists](doc/fw-addr-lists.md) (`fw-addr-lists`)
|
* [Download, import and update firewall address-lists](doc/fw-addr-lists.md) (`fw-addr-lists`)
|
||||||
* [Wait for global functions und modules](doc/global-wait.md) (`global-wait`)
|
* [Wait for global functions und modules](doc/global-wait.md) (`global-wait`)
|
||||||
|
|
|
||||||
63
dhcpv6-client-lease.rsc
Normal file
63
dhcpv6-client-lease.rsc
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
#!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;
|
||||||
|
}
|
||||||
65
doc/dhcpv6-client-lease.md
Normal file
65
doc/dhcpv6-client-lease.md
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
Run other scripts on IPv6 DHCP client lease
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
[](https://github.com/eworm-de/routeros-scripts/stargazers)
|
||||||
|
[](https://github.com/eworm-de/routeros-scripts/network)
|
||||||
|
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
||||||
|
[](https://mikrotik.com/download/changelogs/)
|
||||||
|
[](https://t.me/routeros_scripts)
|
||||||
|
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
|
||||||
|
|
||||||
|
[⬅️ Go back to main README](../README.md)
|
||||||
|
|
||||||
|
> ℹ️ **Info**: This script can not be used on its own but requires the base
|
||||||
|
> installation. See [main README](../README.md) for details.
|
||||||
|
|
||||||
|
Description
|
||||||
|
-----------
|
||||||
|
|
||||||
|
This script is supposed to run from IPv6 DHCP client as lease script. On a
|
||||||
|
DHCP leasse it runs each script containing the following line, where `##` is
|
||||||
|
a decimal number for ordering:
|
||||||
|
|
||||||
|
# provides: dhcpv6-client-lease, order=##
|
||||||
|
|
||||||
|
The lease script is started with some variables injected, but these are not
|
||||||
|
available in child scripts. However this script makes these variables
|
||||||
|
available with a global variable. This code is required in child script:
|
||||||
|
|
||||||
|
:global EitherOr;
|
||||||
|
|
||||||
|
:global DHCPv6ClientLeaseVars;
|
||||||
|
|
||||||
|
:local NaAddress [ $EitherOr $"na-address" ($DHCPv6ClientLeaseVars->"na-address") ];
|
||||||
|
:local NaValid [ $EitherOr $"na-valid" ($DHCPv6ClientLeaseVars->"na-valid") ];
|
||||||
|
:local PdPrefix [ $EitherOr $"pd-prefix" ($DHCPv6ClientLeaseVars->"pd-prefix") ];
|
||||||
|
:local PdValid [ $EitherOr $"pd-valid" ($DHCPv6ClientLeaseVars->"pd-valid") ];
|
||||||
|
:local Options [ $EitherOr $"options" ($DHCPv6ClientLeaseVars->"options") ];
|
||||||
|
|
||||||
|
The values are available under different name then, use `$PdPrefix` instead
|
||||||
|
of `$"pd-prefix"`, and so on. The resulting script supports both, being a
|
||||||
|
lease script itself or being run as child.
|
||||||
|
|
||||||
|
Currently it runs if available, in order:
|
||||||
|
|
||||||
|
* [ipv6-update](ipv6-update.md)
|
||||||
|
|
||||||
|
Requirements and installation
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
Just install the script:
|
||||||
|
|
||||||
|
$ScriptInstallUpdate dhcpv6-client-lease;
|
||||||
|
|
||||||
|
... and add it as `lease-script` to your dhcp client:
|
||||||
|
|
||||||
|
/ipv6/dhcp-client/set lease-script="dhcpv6-client-lease" [ find ];
|
||||||
|
|
||||||
|
See also
|
||||||
|
--------
|
||||||
|
|
||||||
|
* [Update configuration on IPv6 prefix change](ipv6-update.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
[⬅️ Go back to main README](../README.md)
|
||||||
|
[⬆️ Go back to top](#top)
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
# Git commit id & info, expected configuration version
|
# Git commit id & info, expected configuration version
|
||||||
:global CommitId "unknown";
|
:global CommitId "unknown";
|
||||||
:global CommitInfo "unknown";
|
:global CommitInfo "unknown";
|
||||||
:global ExpectedConfigVersion 140;
|
:global ExpectedConfigVersion 141;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@
|
||||||
138="RouterOS 7.19 is suffering an issue with certificate store. Fixing trust state for all certificates...";
|
138="RouterOS 7.19 is suffering an issue with certificate store. Fixing trust state for all certificates...";
|
||||||
139="Certificate Authorities will reduce the leaf certificate validity times soon. Thus the defaults for renewal and warning in 'check-certificates' were decreased.";
|
139="Certificate Authorities will reduce the leaf certificate validity times soon. Thus the defaults for renewal and warning in 'check-certificates' were decreased.";
|
||||||
140="The scripts 'lease-script' was renamed to 'dhcpv4-server-lease', configuration was updated automatically.";
|
140="The scripts 'lease-script' was renamed to 'dhcpv4-server-lease', configuration was updated automatically.";
|
||||||
|
141="Introduced script 'dhcpv6-client-lease' to run several scripts on IPv6 DHCP client lease.";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Migration steps to be applied on script updates
|
# Migration steps to be applied on script updates
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue