Tried to enter a firewall rule using netmask notation and was told it was bad. Tracked it to validate.awk. Updated the section starting with
#FIXME: add proper netmask validation to the following:
/usr/lib/webif/validate.awk
# FIXME: add proper netmask validation.. OK. Done.
($1 == "ip") || ($1 == "netmask") {
valid_type = 1
if ((value != "") && (value !~ /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\/?[0-9]?[0-9]?$/)) valid=0
else {
split(value, ipaddr, "\\.")
for (i = 1; i <= 4; i++) {
if ((ipaddr[i] < 0) || (ipaddr[i] > 255)) valid = 0
if ((i = 4) && ($1 == "netmask")){
split(ipaddr[4],lastoctet,"\\/")
if((lastoctet[1]<0) || (lastoctet[1]>255)) valid = 0
if((lastoctet[2]<0) || (lastoctet[2]>32)) valid = 0
}
else if ((ipaddr[i] < 0) || (ipaddr[i] > 255)) valid = 0
}
}
if (valid == 0) verr = "@TR<<Invalid value>>"
}
Fields that require netmask, such as now send "netmask" instead of "ip" to the validator. This is nice for source and destination firewall rules. I think the only place is these lines:
/www/cgi-bin/webif/firewall.sh
int|proto_valid|@TR<<Protocol>>||$proto_valid
string|FORM_target|@TR<<Target>>|required|$FORM_target
string|FORM_proto|@TR<<Protocol>>||$FORM_proto
netmask|FORM_src|@TR<<Source IP>>||$FORM_src
netmask|FORM_dest|@TR<<Destination IP>>||$FORM_dest
ports|FORM_sport|@TR<<Source Ports>>||$FORM_sport
ports|FORM_dport|@TR<<Destination Ports>>||$FORM_dport
ip|FORM_target_ip|@TR<<Forward to>>||$FORM_target_ip
port|FORM_target_port|@TR<<Port>>||$FORM_target_port
If I knew how to submit a proper patch, I would.
EDIT: I just realized that by netmask I was refering to something like 192.168.1.0/24 whereas the origional author meant the netmask from the lan.sh, or something like 255.255.255.0. Proper netmask filtering should then be checking the IP class and seeing if the subnet mask makes sense. I think my thing is still good, but it should be called something different.. maybe ipmask, or something. Left as above someone could enter "255.255.255.0/24" into the lan.sh netmask field... not good.
EDIT2: Fixed functional mistake in line. (valid=0 was cut out by copy/paste).
(Last edited by bobpaul on 31 Jul 2006, 14:26)