Right now, our numeric validator can only validate decimal numbers. Trying to give it something else will cause errors:
vyos@vyos# /usr/libexec/vyos/validators/numeric 0x999 && echo Valid '0x999' is not a valid number
There are use cases for hex values, though, like ethertype numbers, connection marks, etc.
OCaml's built-in int_of_string already supports radix prefixes, so we don't need to write anything to support that — it's only our regex validation that doesn't support non-decimal numbers.
utop # int_of_string "0xDEADBEEF" ;; - : int = 3735928559
However, the UI design is an interesting question. To answer it, we need to find out:
- Are there any use cases where a target application allows either decimal or non-decimal numbers, so that 32 and 0x20 are equally acceptable?
- Are there any use cases for non-decimal ranges, like 0x20-0x30?
- Do we want to allow mixed ranges like 0x20-48?
My feeling is that the base should be orthogonal to everything else, but I'm not sure if we should go for an "allow" or a "require" approach.
If we go for "require", people still can write something like numeric --octal --hex --decimal 0x20 to allow any supported base. If we go for "allow", we may still need "require" options for cases when the number can only be hex, for example.