mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 11:43:25 +02:00
location-functions.pl: Add address_has_flag() function.
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>
This commit is contained in:
committed by
Michael Tremer
parent
b868abd251
commit
d443f504aa
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user