]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
firewall-lib.pl: Add get_custom_group_addresses() function
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 16 Apr 2023 14:17:11 +0000 (16:17 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 16 Apr 2023 14:17:11 +0000 (16:17 +0200)
This function is used to get the host/nework address of
each element of a given custom group name.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/firewall/firewall-lib.pl

index 767a9675de5f6eef0c92d529de3212461025f10a..b7d3ff95857d3a8572a92df3597baedc2e968047 100644 (file)
@@ -663,4 +663,41 @@ sub get_custom_groups () {
        return @groups;
 }
 
+sub get_custom_group_addresses ($) {
+       my ($group_name) = @_;
+
+       # Array to store the found addresses/networks.
+       my @addresses = ();
+
+       # Loop through the hash of customgroups.
+       foreach my $key (keys %customgrp) {
+               # Skip entries which does not belong to the current processed
+               # group.
+               next unless($customgrp{$key}[0] eq $group_name);
+
+               # Call function to get the configured address of the current processed entry.
+               my @tmp = &get_address($customgrp{$key}[3], $customgrp{$key}[2], "tgt");
+
+               # The result is passed as a nested array, assign it to a better usable variable.
+               my $address = $tmp[0][0];
+
+               # Skip the entry if no address could be determined or it equals to "none".
+               next unless($address);
+               next if ($address eq "none");
+
+               # Normalize addresses of single hosts.
+               $address =~ s|/32||;
+               $address =~ s|/255.255.255.255||;       
+
+               # Assign the address to the addresses array.
+               push(@addresses, $address);
+       }
+
+       # Remove any double entries.
+       @addresses = &General::uniq(@addresses);
+
+       # Return the addresses array.
+       return @addresses;
+}
+
 return 1;