]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
network-functions.pl: Improve zone configuration functions
authorLeo-Andres Hofmann <hofmann@leo-andres.de>
Sun, 17 Jan 2021 14:20:04 +0000 (15:20 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 25 Jan 2021 19:32:40 +0000 (19:32 +0000)
Cache ethernet configuration in public variable "ethernet_settings",
add functions to simplify working with the network configuration.

Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/network-functions.pl

index 622731f96993acb7ef7998bfac1d4484d9a6c2dc..7bd6466e0c91e3b6ece894e1cae9b71a1f7cf3ed 100644 (file)
@@ -27,6 +27,14 @@ require "/var/ipfire/general-functions.pl";
 
 use Socket;
 
+# System ethernet configuration
+our %ethernet_settings = ();
+&General::readhash("${General::swroot}/ethernet/settings", \%ethernet_settings);
+
+# List of all possible network zones that can be configured
+our @known_network_zones = ("red", "green", "orange", "blue");
+
+# IPv4 netmask CIDR to dotted decimal notation conversion table
 my %PREFIX2NETMASK = (
        32 => "255.255.255.255",
        31 => "255.255.255.254",
@@ -448,12 +456,8 @@ sub get_mac_by_name($) {
 ## Function to get a list of all available network zones.
 #
 sub get_available_network_zones () {
-       # Get netsettings.
-       my %netsettings = ();
-       &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
-
        # Obtain the configuration type from the netsettings hash.
-       my $config_type = $netsettings{'CONFIG_TYPE'};
+       my $config_type = $ethernet_settings{'CONFIG_TYPE'};
 
        # Hash which contains the conversation from the config mode
        # to the existing network interface names. They are stored like
@@ -480,6 +484,32 @@ sub get_available_network_zones () {
        return @network_zones;
 }
 
+#
+## Function to check if a network zone is available in the current configuration
+#
+sub is_zone_available() {
+       my $zone = lc shift;
+       
+       # Make sure the zone is valid
+       die("Unknown network zone '$zone'") unless ($zone ~~ @known_network_zones);
+       
+       # Get available zones and return result
+       my @available_zones = get_available_network_zones();
+       return ($zone ~~ @available_zones);
+}
+
+#
+## Function to determine if the RED zone is in standard IP (or modem, PPP, VDSL, ...) mode
+#
+sub is_red_mode_ip() {
+       # Obtain the settings from the netsettings hash
+       my $config_type = $ethernet_settings{'CONFIG_TYPE'};
+       my $red_type = $ethernet_settings{'RED_TYPE'};
+
+       # RED must be a network device (configuration 1-4) with dynamic or static IP
+       return (($config_type ~~ [1..4]) && ($red_type ~~ ["DHCP", "STATIC"]));
+}
+
 1;
 
 # Remove the next line to enable the testsuite