From patchwork Tue Sep 22 18:25: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: 3478 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 4BwqVz74s3z3wbW for ; Tue, 22 Sep 2020 18:25:47 +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 4BwqVw1RDfz12c; Tue, 22 Sep 2020 18:25:44 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BwqVv6G1Xz30Wv; Tue, 22 Sep 2020 18:25:43 +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 4BwqVt2Yjpz2xhT for ; Tue, 22 Sep 2020 18:25:42 +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 4BwqVt0Pjsz107; Tue, 22 Sep 2020 18:25:41 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1600799142; 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=GJ6aZgO/kqcQ+Bz+1RNbMwlvT7UDwI4SPvKNNUdi5po=; b=AEZHwm6p7YZhoRwQ2GUshoecZJlXTp7wR7U0Z4MjkaRuAS3s/IjYaskxhBz0OOaWmPnIf1 IzMGNX3YbqFoEkBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1600799142; 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=GJ6aZgO/kqcQ+Bz+1RNbMwlvT7UDwI4SPvKNNUdi5po=; b=uFMBxkvYbBbVbK27Q55/aEMAO0hwgXZdVHNlKkkUZzlkgyjBgn55XD7zIFU+GVn6nlMOqz 2gNWplzf0hzOSoRubHSxCzNMPZwjPtotIze4TQlk76SjJ4c1BONN/CyXtw0MXeRUYLK1rf /KEzkcti0qilHFskTvwnJH/gUF0GX4LVOu+tCi+vfk7lpqS5x0Pg7lO9xnnQ3F6OFbjYfO NPKJl/p6ufKFHs9OfBEjdn/d+/ZLQvFzbQGtRVzwmXQjtg5emCKLfYik5qrOkxicSaWIUQ lB9tLDqnQu2E9N5nE7Dxn9bcIL7Mm5WqO0f/IxsOLs6PP1lQktPVADtG8q16Ow== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 03/11] location-functions.pl: Add address_has_flag() function. Date: Tue, 22 Sep 2020 20:25:01 +0200 Message-Id: <20200922182509.18643-3-stefan.schantl@ipfire.org> In-Reply-To: <20200922182509.18643-1-stefan.schantl@ipfire.org> References: <20200922182509.18643-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" 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 --- config/cfgroot/location-functions.pl | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl index c8ccd94c2..b0b8cd086 100644 --- a/config/cfgroot/location-functions.pl +++ b/config/cfgroot/location-functions.pl @@ -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;