Is there any way to convert an internal ID number such as “*30E” to an integer? Basically the opposite of the :toid function. I’m working on a script that adds about a hundred packet mangling rules that I need in a certain order or else traffic won’t route properly. Currently whenever I add a new rule I’m saving all of the internal ID’s that are returned to an array but since I don’t know the process involved in determining an internal ID number I can’t count by, or add or subtract to place rules accordingly. Maybe I’m just thinking about this in the wrong mindset. Is the internal ID a globally unique string that stays the same even if you use the move command? It’s not entirely clear on the wiki. I know I can do a [/ip firewall mangle print count-only] to find the last rule position.
After doing a little bit of testing with the move command, it does appear that the internal ID follows the rule wherever it’s placed. It still would be helpful to know how it is determined.
There’s the :tonum command, but I’m not sure if that would suffice.
AFAIK, the IDs don’t follow any particular pattern when generated. However, if you do a “print” to get all IDs (well… if you’re using them in a script, I suppose also add the “as-value” argument), you can count on their order to match the order they are evaluated by.
as boen_robot explained internal ids are not created in any particular order and any assumption that it is done so should be discarded.
most reliable thing would be to get IDs before you start adding items and then get the IDs when you finish adding items. (but in this case you will not know what rule is what)
To answer part of my own question earlier in this post, all you have to do would be to convert the value after the star symbol from hex to decimal to get the integer number of an internal ID but the ID assigned to the rule stays with the rule for its existence. I may end up writing a simple function to convert from hex to decimal as it would be nice to have this functionality in my tool belt.
For those of you searching for information on how to arrange existing firewall rules by the internal ID’s, using the “arrayPush” function I created in another post a long time ago, here is an example of how you can put all of the existing firewall mangle rules into an array for further manipulation.