Closed cavemandaveman closed 7 years ago
Actually, hold on this PR. I'm running into build issues when it's trying to install keepalived:
ERROR: unsatisfiable constraints:
add-0:
masked in: cache
satisfies: world[add]
keepalived (missing):
required by:
Okay the above issue is fixed if you merge in #15. Once that happens, I can rebase this.
Thanks. Merged that one. Just checking out this one.
Looks like your regex allows a first octet of 224 and upwards, just checkout out the rest
I think this works, what do you think?
^(([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-2][0-3])\.)(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-5][0-5])\.){2}([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-5][0-5])$
Any octet can be 0-255, why are you limiting the first at 223?
One other option I came across is ipcalc
which is preinstalled in Alpine. You can pass the IP and mask and it will tell you if it's valid or not.
A valid IP will exit 0:
/ # ipcalc -hp 192.168.0.11/23
PREFIX=23
HOSTNAME=192.168.0.11
and an invlaid IP will exit 1:
/ # ipcalc -hp 255.255.255.256/32
ipcalc: bad IP address: 255.255.255.256
This could replace the two regex conditionals for VIRTUAL_IP and VIRTUAL_MASK with a single command.
Anything above 223 on the first octet is a multicast address or reserved and shouldn't be used.
I'd rather stick with a regex to keep things as light as possible as others may not use alpine base. However, I'm happy to be swayed if others agree with @cavemandaveman - anyone?
I'm okay with regex, just threw out ipcalc as a suggestion. I updated this branch to include your revised expression.
Thanks, I thought I'd do some further testing, it looks like 10.11.022.3 is valid which isn't good, fixing...
Scratch that, it's good. Let's see when it next crops up! :-)
The regex wouldn't allow for 0s in any field. For example, if I need to use 192.168.0.11 (a valid IP) it would throw an error. It's a lot uglier, but it works!