From: Michael Tremer Date: Tue, 25 Aug 2015 20:55:40 +0000 (+0100) Subject: network-functions: Add check_subnet() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=883c5453d9aaeb3da2fbe879bc024c161d00ba21;p=people%2Fms%2Fipfire-2.x.git network-functions: Add check_subnet() Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index 1cd2814ec1..9dd752d5e6 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -163,6 +163,21 @@ sub check_ip_address_and_netmask($$) { return &check_netmask($netmask); } +# Returns True for all valid subnets like a.b.c.d/e or a.b.c.d/a.b.c.d +sub check_subnet($) { + my $subnet = shift; + + my ($address, $network) = split(/\//, $subnet, 2); + + # Check if the IP address is fine. + my $result = &check_ip_address($address); + unless ($result) { + return $result; + } + + return &check_prefix($network) || &check_netmask($network); +} + # For internal use only. Will take an IP address and # return it in a normalised style. Like 8.8.8.010 -> 8.8.8.8. sub _normalise_ip_address($) { diff --git a/config/rootfiles/core/94/filelists/files b/config/rootfiles/core/94/filelists/files index a603603973..d62794d8fd 100644 --- a/config/rootfiles/core/94/filelists/files +++ b/config/rootfiles/core/94/filelists/files @@ -5,3 +5,4 @@ srv/web/ipfire/cgi-bin/logs.cgi/log.dat srv/web/ipfire/cgi-bin/mail.cgi var/ipfire/langs var/ipfire/menu/40-services.menu +var/ipfire/network-functions.pl