This function can be used to check if a given address or network has one of the following network flags.
* LOC_NETWORK_FLAG_ANONYMOUS_PROXY * LOC_NETWORK_FLAG_SATELLITE_PROVIDER * LOC_NETWORK_FLAG_ANYCAST
It will return true if the given flag is set.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- src/perl/Location.xs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
diff --git a/src/perl/Location.xs b/src/perl/Location.xs index 7afa3e7..1cb2e21 100644 --- a/src/perl/Location.xs +++ b/src/perl/Location.xs @@ -181,6 +181,42 @@ lookup_country_code(db, address) OUTPUT: RETVAL
+bool +lookup_network_has_flag(db, address, flag) + struct loc_database* db; + char* address; + char* flag; + + CODE: + RETVAL = false; + + enum loc_network_flags iv = 0; + + if (strcmp("LOC_NETWORK_FLAG_ANONYMOUS_PROXY", flag) == 0) + iv |= LOC_NETWORK_FLAG_ANONYMOUS_PROXY; + else if (strcmp("LOC_NETWORK_FLAG_SATELLITE_PROVIDER", flag) == 0) + iv |= LOC_NETWORK_FLAG_SATELLITE_PROVIDER; + else if (strcmp("LOC_NETWORK_FLAG_ANYCAST", flag) == 0) + iv |= LOC_NETWORK_FLAG_ANYCAST; + else + croak("Invalid flag"); + + // Lookup network + struct loc_network *network; + int err = loc_database_lookup_from_string(db, address, &network); + + if (!err) { + // Check if the network has the given flag. + if (loc_network_has_flag(network, iv)) { + RETVAL = true; + } + + loc_network_unref(network); + } + + OUTPUT: + RETVAL + SV* lookup_asn(db, address) struct loc_database* db;
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- examples/python/create-database.py | 1 + 1 file changed, 1 insertion(+)
diff --git a/examples/python/create-database.py b/examples/python/create-database.py index b57ad94..bf8838b 100644 --- a/examples/python/create-database.py +++ b/examples/python/create-database.py @@ -33,6 +33,7 @@ with open(private_key_path, "r") as pkey: n = w.add_network("2a07:1c44:5800::/40") n.country_code = "DE" n.asn = a.number + n.set_flag(location.NETWORK_FLAG_ANYCAST)
print(n)
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- src/perl/t/Location.t | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/perl/t/Location.t b/src/perl/t/Location.t index 0d9a1a5..a82bbb1 100644 --- a/src/perl/t/Location.t +++ b/src/perl/t/Location.t @@ -12,7 +12,7 @@ use warnings; my $testdb = $ENV{'database'}; my $keyfile = $ENV{'keyfile'};
-use Test::More tests => 9; +use Test::More tests => 10; BEGIN { use_ok('Location') };
######################### @@ -62,3 +62,6 @@ ok($as_name eq "Lightning Wire Labs GmbH", "Test 10 - Get name for AS204867.");
my @locations = &Location::database_countries($db); ok(@locations != 0, "Test 11 - Get database countries."); + +my $network_flag_anycast = &Location::lookup_network_has_flag($db, $address, "LOC_NETWORK_FLAG_ANYCAST"); +ok($network_flag_anycast, "Network has Anycast flag.");
Hello,
Thank you for sending those.
How are we going to proceed from here? Would you like to build the stuff that is needed for the web UI and if it all works I will tag a release? I would prefer to leave this open for as long we might have to add some more patches.
Best, -Michael
On 30 Aug 2020, at 11:36, Stefan Schantl stefan.schantl@ipfire.org wrote:
This function can be used to check if a given address or network has one of the following network flags.
- LOC_NETWORK_FLAG_ANONYMOUS_PROXY
- LOC_NETWORK_FLAG_SATELLITE_PROVIDER
- LOC_NETWORK_FLAG_ANYCAST
It will return true if the given flag is set.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
src/perl/Location.xs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
diff --git a/src/perl/Location.xs b/src/perl/Location.xs index 7afa3e7..1cb2e21 100644 --- a/src/perl/Location.xs +++ b/src/perl/Location.xs @@ -181,6 +181,42 @@ lookup_country_code(db, address) OUTPUT: RETVAL
+bool +lookup_network_has_flag(db, address, flag)
- struct loc_database* db;
- char* address;
- char* flag;
- CODE:
RETVAL = false;
enum loc_network_flags iv = 0;
if (strcmp("LOC_NETWORK_FLAG_ANONYMOUS_PROXY", flag) == 0)
iv |= LOC_NETWORK_FLAG_ANONYMOUS_PROXY;
else if (strcmp("LOC_NETWORK_FLAG_SATELLITE_PROVIDER", flag) == 0)
iv |= LOC_NETWORK_FLAG_SATELLITE_PROVIDER;
else if (strcmp("LOC_NETWORK_FLAG_ANYCAST", flag) == 0)
iv |= LOC_NETWORK_FLAG_ANYCAST;
else
croak("Invalid flag");
// Lookup network
struct loc_network *network;
int err = loc_database_lookup_from_string(db, address, &network);
if (!err) {
// Check if the network has the given flag.
if (loc_network_has_flag(network, iv)) {
RETVAL = true;
}
loc_network_unref(network);
}
- OUTPUT:
RETVAL
SV* lookup_asn(db, address) struct loc_database* db; -- 2.20.1