]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
firewall-lib.pl: Add get_custom_srvgrp_ports() function
authorStefan Schantl <stefan.schantl@ipfire.org>
Sat, 22 Apr 2023 07:38:48 +0000 (09:38 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sat, 22 Apr 2023 07:38:48 +0000 (09:38 +0200)
This function can be used to get all service port numbers which are
attached to a custom service group by it's name.

You also have to choose if you want to get the ports for TCP or UDP
services.

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

index 1e5a92c25f24e30daed5e374f2fb711be0e1de0c..54bc21ca44bc2f35d60559123e573d07a418bbb4 100644 (file)
@@ -698,4 +698,38 @@ sub get_custom_group_addresses ($) {
        return @addresses;
 }
 
-return 1;
+sub get_custom_srvgrp_ports ($$) {
+       my ($group_name, $proto) = @_;
+
+       # Array to store the found port numbers.
+       my @ports = ();
+
+       # Loop through the hash of customservicegrp
+       foreach my $key (keys %customservicegrp) {
+               # Skip entries which does not have the correct group name.
+               next unless($customservicegrp{$key}[0] eq "$group_name");
+
+               # Get created service name
+               my $service = $customservicegrp{$key}[2];
+
+               # Grab the configured port number for the service name
+               my $port = &get_srv_port($service, 1, $proto);
+
+               # Skip entry if no port could be grabbed.
+               next unless($port);
+
+               # Add the port to the array of ports.
+               push(@ports, $port);
+       }
+
+       # Remove any double entries.
+       @ports = &General::uniq(@ports);
+
+       # Sort the port numbers.
+       @ports = sort(@ports);
+
+       # Return the port array.
+       return @ports;
+}
+
+1;