mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2025-12-09 03:19:29 +00:00
global-functions: introduce $NetMask6
RouterOS does not support bit shifting on IPv6 data types, so we have to split the problem: * each 16 bit block is calculated separately, as number * the complete netmask is assembled in a loop, as string * the final string is casted to correct data type
This commit is contained in:
parent
c62f236251
commit
6ad6f9aa08
1 changed files with 19 additions and 0 deletions
|
|
@ -62,6 +62,7 @@
|
|||
:global MIN;
|
||||
:global MkDir;
|
||||
:global NetMask4;
|
||||
:global NetMask6;
|
||||
:global NotificationFunctions;
|
||||
:global ParseDate;
|
||||
:global ParseKeyValueStore;
|
||||
|
|
@ -998,6 +999,24 @@
|
|||
:return ((255.255.255.255 << (32 - $CIDR)) & 255.255.255.255);
|
||||
}
|
||||
|
||||
# return an IPv6 netmask for CIDR
|
||||
:set NetMask6 do={
|
||||
:local FuncName $0;
|
||||
:local CIDR [ :tostr $1 ];
|
||||
|
||||
:global IfThenElse;
|
||||
:global MAX;
|
||||
:global MIN;
|
||||
|
||||
: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 ];
|
||||
}
|
||||
|
||||
# prepare NotificationFunctions array
|
||||
:if ([ :typeof $NotificationFunctions ] != "array") do={
|
||||
:set NotificationFunctions ({});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue