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;