);
my %ipset_loaded_sets = ();
+my %set_loader = ();
my $configfwdfw = "${General::swroot}/firewall/config";
my $configinput = "${General::swroot}/firewall/input";
my $POLICY_FORWARD_ACTION = $fwoptions{"FWPOLICY"};
my $POLICY_OUTPUT_ACTION = $fwoptions{"FWPOLICY1"};
+# Register set loaders.
+®ister_set_loader("Location::Functions::load_location", @locations);
+®ister_set_loader("IPblocklist::Functions::load_blocklist", @blocklists);
+
#workaround to suppress a warning when a variable is used only once
my @dummy = ( $Location::Functions::ipset_db_directory );
undef (@dummy);
return $ret;
}
+
+sub load_set($) {
+ my ($setname) = @_;
+
+ # Skip the set if the requested allready has been loaded during
+ # this script run.
+ return if($ipset_loaded_sets{$setname});
+
+ # Print a message if debug is enabled.
+ print "Loading set $setname\n" if ($DEBUG);
+
+ # Obtain the correct loader for the requested set.
+ my $loader = &get_set_loader($setname);
+
+ # Load the set.
+ &$loader($setname);
+
+ # Mark the set as loaded.
+ $ipset_loaded_sets{$setname} = "1";
+}
+
+sub register_set_loader ($@) {
+ my ($function, @elements) = @_;
+
+ # Loop through the given array.
+ foreach my $element (@elements) {
+ $set_loader{$element} = \&$function;
+ }
+}
+
+sub get_set_loader ($) {
+ my ($element) = @_;
+
+ return $set_loader{$element};
+}