From patchwork Sun Aug 30 10:36:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3412 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4BfV9s0mv9z3x1r for ; Sun, 30 Aug 2020 10:36:17 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4BfV9r4LCFztD; Sun, 30 Aug 2020 10:36:16 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BfV9q712Mz2yCW; Sun, 30 Aug 2020 10:36:15 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4BfV9p2cbWz2xZx; Sun, 30 Aug 2020 10:36:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4BfV9m1Yv8zlJ; Sun, 30 Aug 2020 10:36:12 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1598783772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=pZ0YSObMwXr04IaRq9hONY1miOjZZv2VpKEP20Yv6qQ=; b=OfOiFTFl3g+pQnPHYMqfzD7Dno3QlJ+GQsNAy0Ko1L5OFhYhULQrUISeq32mh3eF8dhDLN oWPMbcx77ceQVoCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1598783772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=pZ0YSObMwXr04IaRq9hONY1miOjZZv2VpKEP20Yv6qQ=; b=A1zWyUCNQyv3MYDFK2W5x07XBxA9qMyKD9HlAw9LG0HFN1Kle+Q9+bAHZwIRLTkXK2MQj8 4SC2XcUiOPSDwZAyHlm/0oZJcxFk/5mVJErqWQ9kimer0T8P3qgiY2vONHcdKDozI5EDK+ OM2QgnYa+MB6KN2DTxV18uYCqg75cgE7iy4PH45NSTgm86dDgOTWRgJCYSfDRsPcOiWHba 1yBOcXR6ds705pOXFoajr1xX4tgAa9wlY+ICxKhZk+RxViU92Ea2qenJWYhPgoNYAgXfle n/1M+DiNJRgYtiDU04ZYWCUrQojxfHLKe/cOtdzCCoBcR5hpa6Tj5xQlEBgnXw== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH 1/3] perl: Add lookup_network_has_flag() function. Date: Sun, 30 Aug 2020 12:36:00 +0200 Message-Id: <20200830103602.6816-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org Errors-To: location-bounces@lists.ipfire.org Sender: "Location" 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 --- 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; From patchwork Sun Aug 30 10:36:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3415 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4BfV9v4bpZz3x2X for ; Sun, 30 Aug 2020 10:36:19 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4BfV9t0xmZzwt; Sun, 30 Aug 2020 10:36:18 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BfV9r0h6Gz2xk6; Sun, 30 Aug 2020 10:36:16 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4BfV9p6cl9z2xCd; Sun, 30 Aug 2020 10:36:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4BfV9p37B2zp4; Sun, 30 Aug 2020 10:36:14 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1598783774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vGn+9NLt1z11EpreuORSLg9u7+TINna69/ANmt4NYbc=; b=COu7smj721XXbaCaS6KMw06C381d7P+QDx6cyUydTmJaxiz5YZX7lAizZmqRk9Vb6q1aB0 dLIi4v4/3VONZCCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1598783774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vGn+9NLt1z11EpreuORSLg9u7+TINna69/ANmt4NYbc=; b=kwrT6rGOeFa+LsBaaUeBnZ4yh5A6e0y7REsD1G7fYgOtg/jGNCzbomQsS1T/oII+Z2Yy6W PSaJA+lgOcMjU2DQTBrPkSmC39d1/kVZMY+prbrLOxksX3D6LTkwyv5DaYf3jnOsq3YMam g11HSQoS7GwbJbQz6BVpJMf6vuMFMZYDwMJxKWyCL4ItC1o+PepcSsjrZtqh3orLPdMYAs Wd2Aun9dzv2CtlFke6jAwQKpK3iEQbEWdfns+TdEXoAdg4BAGyDkBX2+vUw/sLHGFsSWAA bRIgmy9KSmzHcGi1YA9aFsifU40F/qs1aopQs4J1iwafgBpZ1rtOItSc6qZVYQ== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH 2/3] Add example network flag to the python create-database example script. Date: Sun, 30 Aug 2020 12:36:01 +0200 Message-Id: <20200830103602.6816-2-stefan.schantl@ipfire.org> In-Reply-To: <20200830103602.6816-1-stefan.schantl@ipfire.org> References: <20200830103602.6816-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org Errors-To: location-bounces@lists.ipfire.org Sender: "Location" Signed-off-by: Stefan Schantl --- 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) From patchwork Sun Aug 30 10:36:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3417 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4BfV9w5ZK5z3x1r for ; Sun, 30 Aug 2020 10:36:20 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4BfV9t47ZgzxF; Sun, 30 Aug 2020 10:36:18 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BfV9r1RYyz3041; Sun, 30 Aug 2020 10:36:16 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4BfV9q2LlTz2xCd; Sun, 30 Aug 2020 10:36:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4BfV9p6fsyzp7; Sun, 30 Aug 2020 10:36:14 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1598783775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/h2mBcpWrnCGD6RZ1rW+QnB6i/7k85I19wPDoUhxo+Y=; b=rXhTFk64ymziz9MXqQxnVU5648hBTq6Ecn437k0wvoYktzn9+e1KeL5SMMNXuIJ3sFAH3A UtbxbCjArB8ra1Dw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1598783775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/h2mBcpWrnCGD6RZ1rW+QnB6i/7k85I19wPDoUhxo+Y=; b=Z3qBRvjvb7ST8CXDaYsp+XVW8HbjLecahQHn9U/3Ue/BHicwhtKc2/tdag65TCHFFQegH5 AAl+OpaXiZNqHrJ3w5rrUgJO+XjFBGanxyx2iRLBhXRVV9CmzTi+f61Wr8g7H7tAHZDLQ7 edg0Ax0Mvqm5bl+j8Wl5tSOhY1ab0s6QRdL/fdO8SezkBKX7RE0lw8LgFmKicPRw7sjEQd Z4jue6QVa4aXsMMT13Wz8eiebc/qGA91ZnxXeOzE6Pxe9yzF0jRFNabazMmMKRVISLgDj5 QqfvYE5UZ59A6PBdVEEWAjh4uqeWmGY0e9XGPoW+lGRiP+h1AGhyc2OdM5ZLAg== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH 3/3] perl: Add test for the lookup_network_has_flag() function Date: Sun, 30 Aug 2020 12:36:02 +0200 Message-Id: <20200830103602.6816-3-stefan.schantl@ipfire.org> In-Reply-To: <20200830103602.6816-1-stefan.schantl@ipfire.org> References: <20200830103602.6816-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org Errors-To: location-bounces@lists.ipfire.org Sender: "Location" Signed-off-by: Stefan Schantl --- 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.");