mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2025-12-06 09:59:28 +00:00
global-functions: $NetMask6: implement simple caching
The calculation is quite complex for something that needs to be done frequently, for example by `fw-addr-lists`. The number of possible netmasks is limited, so let's cache the results that were calculated already.
This commit is contained in:
parent
6ad6f9aa08
commit
d7a6eb1d00
1 changed files with 13 additions and 1 deletions
|
|
@ -1008,13 +1008,25 @@
|
|||
:global MAX;
|
||||
:global MIN;
|
||||
|
||||
:global NetMask6Cache;
|
||||
|
||||
:if ([ :typeof ($NetMask6Cache->$CIDR) ] = "ip6") do={
|
||||
:return ($NetMask6Cache->$CIDR);
|
||||
}
|
||||
|
||||
:if ([ :typeof $NetMask6Cache ] = "nothing") do={
|
||||
:set NetMask6Cache ({});
|
||||
}
|
||||
|
||||
:local Mask "";
|
||||
:for I from=0 to=7 do={
|
||||
:set Mask ($Mask . \
|
||||
[ :convert from=num to=hex (0xffff - (0xffff >> [ :tonum [ $MIN [ $MAX ($CIDR - (16 * $I)) 0 ] 16 ] ])) ] . \
|
||||
[ $IfThenElse ($I < 7) ":" ]);
|
||||
}
|
||||
:return [ :toip6 $Mask ];
|
||||
:set Mask [ :toip6 $Mask ];
|
||||
:set ($NetMask6Cache->$CIDR) $Mask;
|
||||
:return $Mask;
|
||||
}
|
||||
|
||||
# prepare NotificationFunctions array
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue