]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
location-functions.pl: Add address_has_flag() function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Tue, 22 Sep 2020 18:25:01 +0000 (20:25 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 24 Sep 2020 17:36:38 +0000 (17:36 +0000)
This function can be used to check if a given address has
one of the known flags like "Anonymous Proxy".

If this is true, the mapped special country code will be returned.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/location-functions.pl

index c8ccd94c2ee8a4733fb4f197f8b022e0a8494f3f..b0b8cd086605712bb047a964fe221e308e518daf 100644 (file)
@@ -33,6 +33,13 @@ my %not_iso_3166_location = (
        "A3" => "Worldwide Anycast Instance",
 );
 
+# Hash which contains possible network flags and their mapped location codes.
+my %network_flags = (
+       "LOC_NETWORK_FLAG_ANONYMOUS_PROXY" => "A1",
+       "LOC_NETWORK_FLAG_SATELLITE_PROVIDER" => "A2",
+       "LOC_NETWORK_FLAG_ANYCAST" => "A3",
+);
+
 # Array which contains special country codes.
 my @special_locations = ( "A1", "A2", "A3" );
 
@@ -183,4 +190,26 @@ sub get_locations() {
        return @sorted_locations;
 }
 
+# Function to check if a given address has a special flag.
+sub address_has_flag($) {
+       my ($address) = @_;
+
+       # Init libloc database handle.
+       my $db_handle = &init();
+
+       # Loop through the hash of possible network flags.
+       foreach my $flag (keys(%network_flags)) {
+               # Check if the address has the current flag.
+               if (&Location::lookup_network_has_flag($db_handle, $address, $flag)) {
+                       # The given address has the requested flag.
+                       #
+                       # Grab the mapped location code for this flag.
+                       $mapped_code = $network_flags{$flag};
+
+                       # Return the code.
+                       return $mapped_code;
+               }
+       }
+}
+
 1;