From patchwork Tue Nov 3 14:28:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_M=C3=BCller?= X-Patchwork-Id: 3630 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 4CQXGN2MRhz3why for ; Tue, 3 Nov 2020 14:29:00 +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 4CQXGM2rrSzpW; Tue, 3 Nov 2020 14:28:59 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CQXGM1Qbfz2xrJ; Tue, 3 Nov 2020 14:28:59 +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) 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 mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CQXGK6t0pz2xd0 for ; Tue, 3 Nov 2020 14:28:57 +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) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4CQXGJ4jlYzRh for ; Tue, 3 Nov 2020 14:28:56 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1604413737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tZ29ZGJZNB0FjbpQ2pdjUNDP1FyM+sRwNaE39dK/agU=; b=KHMnA8ZFW1zSoAeWBBFq+w8eHRRA8hDS4p5Tnd0R/fb7G2fAfGXBWws/Vu3e1udrGUuGro 3x3GiE8WWB9sNxCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1604413737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tZ29ZGJZNB0FjbpQ2pdjUNDP1FyM+sRwNaE39dK/agU=; b=Ggf39/Qb8bN4Ky5afw2rnk2jvmwSN1PhyTa9SLh4jaCqZD7wMoTTg8M4zlBVPr8hD2aoHq 2t3WrJ/i04ZGetJloDv9HBohO89BH7hgREWIrgB7D57ZFF4iecrASIMMI7HZpFVlQUeSVL ysMJTLeJ6wzUPewKDjT/RJQwDBwTN+yXn5HrSO2IHRMdactmmUNj2DGPC85s8hLA77XGmc IJivFxqJUHrXdOaZ2DLQTMmClgyCjYmg8mYqTqsOq54h8o4VgLSkmKqLy4wYAOUTuVwLnf oNH4R+Gxp8u9gYRPa2xyKb9CHy+tkxneS+hg2wXrm9gFoB1ZY3rAt86+Q6/lKw== To: "IPFire: Development-List" From: =?utf-8?q?Peter_M=C3=BCller?= Subject: [PATCH 1/4] location-functions.pl: add functions for fetching AS information Message-ID: <8cce16a8-5a92-acbb-28e7-68df2a95d887@ipfire.org> Date: Tue, 3 Nov 2020 15:28:53 +0100 MIME-Version: 1.0 Content-Language: en-US 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" Signed-off-by: Peter Müller --- config/cfgroot/location-functions.pl | 68 +++++++++++++++++++--------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl index 2cfe7f908..ee03a6611 100644 --- a/config/cfgroot/location-functions.pl +++ b/config/cfgroot/location-functions.pl @@ -1,25 +1,23 @@ #!/usr/bin/perl -w -############################################################################ -# # -# This file is part of the IPFire Firewall. # -# # -# IPFire is free software; you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation; either version 2 of the License, or # -# (at your option) any later version. # -# # -# IPFire is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with IPFire; if not, write to the Free Software # -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# # -# Copyright (C) 2015 - 2020 IPFire Team . # -# # -############################################################################ +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2020 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### package Location::Functions; @@ -83,7 +81,7 @@ sub verify ($) { } # -## Function to the the country code of a given address. +## Function to get the country code of a given address. # sub lookup_country_code($$) { my ($db_handle, $address) = @_; @@ -221,4 +219,30 @@ sub address_has_flags($) { return @flags; } +# +## Function to get the Autonomous System Number of a given address. +# +sub lookup_asn($$) { + my ($db_handle, $address) = @_; + + # Lookup the given address. + my $asn = &Location::lookup_asn($db_handle, $address); + + # Return the number of the Autonomous System + return $asn; +} + +# +## Function to get the name of an Autonomous System. +# +sub get_as_name($$) { + my ($db_handle, $asn) = @_; + + # Fetch the name of this AS... + my $as_name = &Location::get_as_name($db_handle, $asn); + + # Return the name of the Autonomous System + return $as_name; +} + 1;