The first two lines are what makes me wonder. When I add all the config lines to a “clean” router by hand, I get the expected result. As soon as I use system/reset-configuration , the order changes.
Sure you could mention, “just change the output order in whatever generates your config”, but changing that will be pain in the a** and I’d like to avoid that. I guess this “issue” is caused by how the config import with reset-configuration is implemented and it may not be considered a bug at all. But maybe someone has a helpful idea how I can get my expected result without doing too much magic in the config generator.
Does seem like a potential bug. Your approach looks right to me…
One hack I suppose you can try adding is adding “/routing/rule/print” in your config before the line with place-before=0. The print won’t show up, but maybe refreshes some cache to know there are rules. e.g. maybe in the context of defconf, it’s doesn’t know there are rules add yet… Or perhaps some “:delay 2s” also be worth a shot. Kinda thinking it just happen quick in defconf, so it may have fully committed the rules or whatnot when it comes to the place-before=0…
Any use of numerical id IS WRONG because you do not PRINT and do not read on terminal the number.
Any other use of the number IS WRONG.
Is not a bug, the OS do exactly what the user write…
If on place-before=0 the first line is “[…]=lte”,why on the 2nd place-before=0 “0” must be another record?
is not written “place-before=first”…
The number not change if you do not “print” again…
Butt a print is a termial command.
The ID of the line never change, simply are indexed on database, so internally you have after the commands *7,*8,*0,*1,*2,*3,*4,*5,*6
For have everytime the correct place-before on top, you must find everytime, and select the first on the list.
On 1st time is *0, but 2nd time is *7 and *8 is putted first, so at the end you have in the right order *8,*7,*0,*1,*2,*3,*4,*5,*6
[…]
/routing rule
add action=lookup-only-in-table disabled=no dst-address=0.0.0.0/0 src-address=192.168.253.230 table=main place-before=([find]->0)
[…]
/routing rule
add action=lookup-only-in-table disabled=no dst-address=192.168.252.0/24 src-address=192.168.253.230 table=wireguard place-before=([find]->0)
[…]
The script is not one interactive session
Each line on terminal is one new session, is why :local on script is keeped and on terminal disappear on new prompt…
try this, the ID are not consecutive, and not ordered, the route order are managed on another database table…
/routing rule> :put [find]
*1d;*16;*17;*18;*19;*1a;*1b;*1e;*1f;*20;*21;*22;*23;*24;*25
Only problem in your logic is that a “print” isn’t needed in CLI for it work. “/routing/rule/add place-before=0” works as expect (e.g. placing first) in CLI WITHOUT ever using print – just tried rebooting, opening a terminal, and place-before=0 with a routing rule.
I never write to write… print…
On new prompt every time you use one “number” the print often is implicit…
Is why everytime on new prompt place-before=0 is recalculated and is (often) the right value…
try on terminal to use two place-before=0 on same line with two “;” separate commands…
(or two commands between { } )
also for keep rules on order without hardly change the number on ([find]->x)
add useless rule with “placeholder” as comment on place-before=([find]->0)
then
“FIRST” place-before=[find where comment~“placeholder”]
“SECOND” place-before=[find where comment~“placeholder”]
“THIRD” place-before=[find where comment~“placeholder”]
“4” place-before=[find where comment~“placeholder”]
“5” place-before=[find where comment~“placeholder”]
“6” place-before=[find where comment~“placeholder”]
“7” place-before=[find where comment~“placeholder”]
…
and at the end
remove [find where comment~“placeholder”]
If your scripting skill is enough, after creation of the “placeholder”, for not recalc everytime the .id :
:local ph [find where comment~“placeholder”]
then
“FIRST” place-before=$ph
“SECOND” place-before=$ph
“THIRD” place-before=$ph
“4” place-before=$ph
“5” place-before=$ph
“6” place-before=$ph
“7” place-before=$ph