]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
ids-functions.pl: Add function to get the available network zones
authorStefan Schantl <stefan.schantl@ipfire.org>
Sat, 4 Aug 2018 14:48:27 +0000 (16:48 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 5 Aug 2018 08:33:46 +0000 (10:33 +0200)
The get_available_network_zones() function uses the /var/ipfire/ethernet/settings
file and translates the configured mode into an array, which contains the names
of the configured network zones.

The array will be returned and easily can be used to loop over this list of
available network zones and perform any kind of actions in other scripts.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ids-functions.pl

index 9c469413d425033050f9fd81eced0b864eb3859c..acf097bb828ad73dd488b4eee385e7dc0f555ff8 100644 (file)
@@ -254,4 +254,40 @@ sub _store_error_message ($) {
         close (ERRORFILE);
 }
 
+#
+## 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'};
+
+       # Hash which contains the conversation from the config mode
+       # to the existing network interface names. They are stored like
+       # an array.
+       #
+       # Mode "0" red is a modem and green
+       # Mode "1" red is a netdev and green
+       # Mode "2" red, green and orange
+       # Mode "3" red, green and blue
+       # Mode "4" red, green, blue, orange
+       my %config_type_to_interfaces = (
+               "0" => [ "red", "green" ],
+               "1" => [ "red", "green" ],
+               "2" => [ "red", "green", "orange" ],
+               "3" => [ "red", "green", "blue" ],
+               "4" => [ "red", "green", "blue", "orange" ]
+       );
+
+       # Obtain and dereference the corresponding network interaces based on the read
+       # network config type.
+       my @network_zones = @{ $config_type_to_interfaces{$config_type} };
+
+       # Return them.
+       return @network_zones;
+}
+
 1;