use Location;
+require '/var/ipfire/ipset-functions.pl';
+
# Hash which contains country codes and their names which are special or not
# part of ISO 3166-1.
my %not_iso_3166_location = (
our $keyfile = "$location_dir/signing-key.pem";
# Directory which contains the exported databases.
-our $ipset_db_directory = "$location_dir/ipset";
+our $exported_db_directory = "$location_dir/exported";
+
+# File extension of the exported databases.
+our $exported_extension = ".networks";
# Create libloc database handle.
my $db_handle = &init();
return $as_name;
}
+#
+## Function to load a given location.
+##
+## This function uses the ipset-functions library to
+## load a given location set into the kernel.
+#
+sub load_location ($) {
+ my ($location) = @_;
+
+ # Generate path and file where the database for
+ # the given location lives.
+ my $file = "$exported_db_directory/$location";
+
+ # The database files have an "v4" as part of their name.
+ $file = $file . "v4";
+
+ # Add the file extension
+ $file = $file . "$exported_extension";
+
+ # Open the exported database file for reading.
+ open (FILE, $file) if (-f $file);
+
+ # Read-in the file content.
+ my @data = <FILE>;
+
+ # Close the file handle.
+ close(FILE);
+
+ # Return an error if the file could not be read or
+ # is empty.
+ return "No data" unless(@data);
+
+ # Call the ipset_load_set function to load the set.
+ my $error = &IPSet::Functions::ipset_load_set($location, @data);
+
+ # Return the error message if there was one.
+ return $error if($error);
+}
+
# Custom END declaration which will be executed when perl
# ends, to release the database handle to libloc.
END {