From mboxrd@z Thu Jan  1 00:00:00 1970
From: Peter =?utf-8?q?M=C3=BCller?= <peter.mueller@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH v2 1/3] location-functions.pl: add functions for fetching AS
 information
Date: Wed, 11 Nov 2020 15:14:09 +0100
Message-ID: <6a9f9a66-1105-0844-7f56-826b22adfaff@ipfire.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============4238555089110369791=="
List-Id: <development.lists.ipfire.org>

--===============4238555089110369791==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

The second version of this patch only unifies the licence banner, but
leaves GPLv2 untouched. In addition, functions have been changed to use
a script-wide location database handle, as introduced in commit
b62d7e0cc71cc1ff23d66dd8baf0f5f3c5c7a29b.

Signed-off-by: Peter M=C3=BCller <peter.mueller(a)ipfire.org>
---
 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-f=
unctions.pl
index fdf2c6efe..b7465c5ef 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 <info(a)ipfire.org>.                =
 #
-#                                                                          #
-############################################################################
+############################################################################=
###
+#                                                                           =
  #
+# IPFire.org - A linux based firewall                                       =
  #
+# Copyright (C) 2007-2020  IPFire Team  <info(a)ipfire.org>                 =
    #
+#                                                                           =
  #
+# 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 2 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 <http://www.gnu.org/licenses/>.     =
  #
+#                                                                           =
  #
+############################################################################=
###
=20
 package Location::Functions;
=20
@@ -86,7 +84,7 @@ sub verify ($) {
 }
=20
 #
-## 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 ($address) =3D @_;
@@ -236,6 +234,32 @@ sub address_has_flags($) {
 	return @flags;
 }
=20
+#
+## Function to get the Autonomous System Number of a given address.
+#
+sub lookup_asn($) {
+	my ($address) =3D @_;
+
+	# Lookup the given address.
+	my $asn =3D &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 ($asn) =3D @_;
+
+	# Fetch the name of this AS...
+	my $as_name =3D &Location::get_as_name($db_handle, $asn);
+
+	# Return the name of the Autonomous System
+	return $as_name;
+}
+
 # Custom END declaration which will be executed when perl
 # ends, to release the database handle to libloc.
 END {
--=20
2.26.2

--===============4238555089110369791==--