Add a comment to the NAT masquerade rule that be moved on top... like "ONTOP"
Schedule this:
/ip firewall nat
:if ( ([find]->0) != ([find where comment="ONTOP"]->0) ) do={
move [find where comment="ONTOP"] destination=*0
}
If "ONTOP" not exist, or NAT is empty, this script do not give error.
Traduced:
If on the IP / Firewall / NAT the .id of first item of all rules is not the same .id of the rule that have "ONTOP" as comment,
move the rule that have "ONTOP" as comment on first place.
EDIT:
The script is not meant to move multiple rules, but:
if multiple rules have ONTOP as a comment, after the script they are brought to the front in the reverse order in which they appear within the rule order.
For example if the rules are:
/ip firewall nat
add action=log chain=srcnat log-prefix=77
add action=log chain=srcnat comment=ONTOP log-prefix=11
add action=log chain=srcnat log-prefix=22
add action=log chain=srcnat comment=ONTOP log-prefix=55
add action=log chain=srcnat log-prefix=6
add action=log chain=srcnat comment=ONTOP log-prefix=4
add action=log chain=srcnat log-prefix=99
add action=log chain=srcnat comment=ONTOP log-prefix=158
after the script the order is:
/ip firewall nat
add action=log chain=srcnat comment=ONTOP log-prefix=158
add action=log chain=srcnat comment=ONTOP log-prefix=4
add action=log chain=srcnat comment=ONTOP log-prefix=55
add action=log chain=srcnat comment=ONTOP log-prefix=11
add action=log chain=srcnat log-prefix=77
add action=log chain=srcnat log-prefix=22
add action=log chain=srcnat log-prefix=6
add action=log chain=srcnat log-prefix=99
If is needed to move an ordered block of rules on top,
assign comment like ONTOP1, ONTOP2 ... ONTOP10, ONTOP11, etc.
On script are checked only first 100 "ONTOP", but if more is needed ( ??? !!! ) can be used an higher number
If some number is deleted or forgetted, no problems or errors.
/ip firewall nat
:for x from=100 to=0 step=-1 do={
:if ( ([find]->0) != ([find where comment="ONTOP$x"]->0) ) do={
move [find where comment="ONTOP$x"] destination=*0
}
}
and from this:
/ip firewall nat
add action=log chain=srcnat log-prefix=77
add action=log chain=srcnat comment=ONTOP2 log-prefix=11
add action=log chain=srcnat log-prefix=22
add action=log chain=srcnat comment=ONTOP3 log-prefix=55
add action=log chain=srcnat log-prefix=6
add action=log chain=srcnat comment=ONTOP55 log-prefix=4
add action=log chain=srcnat log-prefix=99
add action=log chain=srcnat comment=ONTOP9 log-prefix=158
can be obtained this:
/ip firewall nat
add action=log chain=srcnat comment=ONTOP2 log-prefix=11
add action=log chain=srcnat comment=ONTOP3 log-prefix=55
add action=log chain=srcnat comment=ONTOP9 log-prefix=158
add action=log chain=srcnat comment=ONTOP55 log-prefix=4
add action=log chain=srcnat log-prefix=77
add action=log chain=srcnat log-prefix=22
add action=log chain=srcnat log-prefix=6
add action=log chain=srcnat log-prefix=99