I realized it should have some choice of “style” for how the PVID/vlan-id is converted to an IP address. And, just note, you can always use that part of the $pvid2array and $prettyprint code without the rest of the automatic config stuff, like you want to a way to pick a subnet for a VLAN
Currently only one “style” is used, but I’m thing of adding some option to use a different scheme to convert the PVID/vlan-id into a subnet.
The current scheme is what I’m calling “bytes” – that will use 192.168.<0-254>.0 for VLAN IDs below 255. Above 255 to max of 4094, a 172.<16-30>.<0-254>.0 is used. Keep in mind in express in HEX would look like 0x0ABB – for the 172.0x0A.0xBB.0 (with the 0x0A being added by 0x0F… which makes it (base10) range 16-32. (With newer “:convert to=byte-array” breaking up the PVID in 2 parts).
Basically if always use VLAN ID below 255, you’ll get a 192.168. to keep things one-to-one between subnet part and VLAN ID. Since the “bytes” does get confusing…
style=bytes
$prettyprint [$pvid2array style=bytes 99]
{
“cidrnet”: “192.168.99.0/24”,
“vlanid”: 99
}
$prettyprint [$pvid2array style=bytes 1234]
{
“cidrnet”: “172.19.210.0/24”,
“vlanid”: 1234
}
bytes are still linear
… so for 123**5** it’s still the next /24 subnet:
$prettyprint [$pvid2array style=bytes 123**5]
{
“cidrnet”: "172.19.211**.0/24",
“vlanid”: 1235
}
The newer schemes I came up with are “split10” and “bytes10”, which use 10.x.x.x.
The “split10” uses the base10 parts of the PVID to make the IP address… so VLAN 123 is 10.1.23 - this skeps the binary/hex and make the VLAN readable just from the subnet.
style=split10
$prettyprint [$pvid2array style=split10 99]
{
“cidrnet”: “10.0.99.0/24”,
“vlanid”: 99
}
$prettyprint [$pvid2array style=split10 1234]
{
“cidrnet”: “10.12.34.0/24”,
“vlanid”: 1234
}
Likely less useful than above, the same scheme use in “default” bytes scheme, except it ALWAYS uses the 10.x.x.x private range:
style=bytes10
$prettyprint [$pvid2array style=bytes10 99]
{
“cidrnet”: “10.0.99.0/24”,
“vlanid”: 99
}
$prettyprint [$pvid2array style=bytes10 1234]
{
“cidrnet”: “10.5.210.0/24”,
“vlanid”: 1234
}
Anyway, if anyone has suggestion/improvement/bugs LMK here. I’ll probably update the script with minor cleanup this weekend. And likely some “$lsvlan” to print a table of the various config (IP, dhcp, etc) for each VLAN interface in one list…