]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
rules.pl: Fix automatic ipset sets cleanup.
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 25 Apr 2022 19:01:29 +0000 (21:01 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sat, 7 May 2022 09:42:47 +0000 (11:42 +0200)
The array of used/loaded ipsets needs to be reloaded before
the cleanup can be started to also handle sets which are loaded during
runtime.

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

index 649bd49f03f838e70ab9014008f1a0bc8a1a60b4..799b2667d87dc36f5f72961b00dd7e8a983141de 100644 (file)
@@ -137,7 +137,7 @@ undef (@dummy);
 
 sub main {
        # Get currently used ipset sets.
-       &ipset_get_sets();
+       @ipset_used_sets = &ipset_get_sets();
 
        # Flush all chains.
        &flush();
@@ -993,6 +993,8 @@ sub firewall_chain_exists ($) {
 }
 
 sub ipset_get_sets () {
+       my @sets;
+
        # Get all currently used ipset lists and store them in an array.
        my @output = `$IPSET -n list`;
 
@@ -1002,14 +1004,17 @@ sub ipset_get_sets () {
                chomp($set);
 
                # Add the set the array of used sets.
-               push(@ipset_used_sets, $set);
+               push(@sets, $set);
        }
 
        # Display used sets in debug mode.
        if($DEBUG) {
                print "Used ipset sets:\n";
-               print "@ipset_used_sets\n\n";
+               print "@sets\n\n";
        }
+
+       # Return the array of sets.
+       return @sets;
 }
 
 sub ipset_restore ($) {
@@ -1089,6 +1094,9 @@ sub ipset_call_restore ($) {
 }
 
 sub ipset_cleanup () {
+       # Reload the array of used sets.
+       @ipset_used_sets = &ipset_get_sets();
+
        # Loop through the array of used sets.
        foreach my $set (@ipset_used_sets) {
                # Check if this set is still in use.