]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
network-functions.pl: Add function to check for valid networks.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 15 Jan 2015 20:08:37 +0000 (21:08 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 15 Jan 2015 20:08:37 +0000 (21:08 +0100)
The "check_network" function is able to process inputs in prefix
or dotted decimal notations.

config/cfgroot/network-functions.pl

index 029ffc09eee5308dddc5d777e7eb11417e347e3b..9ac38d0e3b29efb63298342c773fc06688fb68ea 100644 (file)
@@ -144,6 +144,22 @@ sub check_netmask($) {
 
        return (exists $NETMASK2PREFIX{$netmask});
 }
+# Returns True for all valid inputs like a.b.c.d/a.b.c.d
+# or a.b.c.d/a.
+sub check_network($$) {
+       my $network = shift;
+
+       my ($address, $netmask) = split(/\//, $network, 2);
+
+       # Check for a valid IP address.
+       my $result = &check_ip_address($address);
+       unless ($result) {
+               return $result;
+       }
+
+       # Check if we got a valid netmask or prefix.
+       return &check_netmask($netmask) || &check_prefix($netmask);
+}
 
 # Returns True for all valid inputs like a.b.c.d/a.b.c.d.
 sub check_ip_address_and_netmask($$) {