]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - config/cfgroot/ids-functions.pl
ids-functions.pl: Add RED address and aliases to the HOME_NET
[people/pmueller/ipfire-2.x.git] / config / cfgroot / ids-functions.pl
index efe89b512f6f4530fae6c2eac23b2e14a8d0f267..a7c1585228bad394e927a32525e6ff612786fc3f 100644 (file)
@@ -597,9 +597,6 @@ sub generate_home_net_file() {
 
        # Loop through the array of available network zones.
        foreach my $zone (@network_zones) {
-               # Skip the red network - It never can be part to the home_net!
-               next if($zone eq "red");
-
                # Convert current zone name into upper case.
                $zone = uc($zone);
 
@@ -622,6 +619,24 @@ sub generate_home_net_file() {
                        # Add the generated network to the array of networks.
                        push(@networks, $network);
                }
+
+               # Check if the current processed zone is red.
+               if($zone eq "RED") {
+                       # Check if the configured RED_TYPE is static.
+                       if ($netsettings{'RED_TYPE'} eq "STATIC") {
+                               # Get configured and enabled aliases.
+                               my @aliases = &get_aliases();
+
+                               # Loop through the array.
+                               foreach my $alias (@aliases) {
+                                       # Add "/32" prefix.
+                                       my $network = join("/", $alias, "32");
+
+                                       # Add the generated network to the array of networks.
+                                       push(@networks, $network);
+                               }
+                       }
+               }
        }
 
        # Format home net declaration.
@@ -841,4 +856,50 @@ sub set_ownership($) {
                chown($uid, $gid, "$target");
        }
 }
+
+#
+## Function to read-in the aliases file and returns all configured and enabled aliases.
+#
+sub get_aliases() {
+       # Location of the aliases file.
+       my $aliases_file = "${General::swroot}/ethernet/aliases";
+
+       # Array to store the aliases.
+       my @aliases;
+
+       # Check if the file is empty.
+       if (-z $aliases_file) {
+               # Abort nothing to do.
+               return;
+       }
+
+       # Open the aliases file.
+       open(ALIASES, $aliases_file) or die "Could not open $aliases_file. $!\n";
+
+       # Loop through the file content.
+       while (my $line = <ALIASES>) {
+               # Remove newlines.
+               chomp($line);
+
+               # Splitt line content into single chunks.
+               my ($address, $state, $remark) = split(/\,/, $line);
+
+               # Check if the state of the current processed alias is "on".
+               if ($state eq "on") {
+                       # Check if the address is valid.
+                       if(&Network::check_ip_address($address)) {
+                               # Add the alias to the array of aliases.
+                               push(@aliases, $address);
+                       }
+               }
+       }
+
+       # Close file handle.
+       close(ALIASES);
+
+       # Return the array.
+       return @aliases;
+}
+
+
 1;