]> git.ipfire.org Git - location/libloc.git/log
location/libloc.git
2 years agonetwork: Implement bit length function for IPv4
Michael Tremer [Mon, 7 Mar 2022 10:01:23 +0000 (10:01 +0000)] 
network: Implement bit length function for IPv4

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork: Allow creating any valid networks
Michael Tremer [Sun, 6 Mar 2022 15:08:47 +0000 (15:08 +0000)] 
network: Allow creating any valid networks

Formerly, we did not allow creating special networks like ::1/128, ::/0,
127.0.0.0/8, and so on.

In order to represent all bogons, we will have to allow this.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork-list: Rewrite summarize algorithm
Michael Tremer [Sun, 6 Mar 2022 15:06:17 +0000 (15:06 +0000)] 
network-list: Rewrite summarize algorithm

The former algorithm did a lot of trial and error which is slow and
probably returned wrong results.

This one determines the correct prefix size quickly.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork: Drop functions moved in an earlier commit
Michael Tremer [Sun, 6 Mar 2022 15:05:17 +0000 (15:05 +0000)] 
network: Drop functions moved in an earlier commit

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork: Add function that counts the bit length of an addres
Michael Tremer [Sun, 6 Mar 2022 14:28:26 +0000 (14:28 +0000)] 
network: Add function that counts the bit length of an addres

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork: Move a couple of helper functions into headers
Michael Tremer [Sat, 5 Mar 2022 16:00:43 +0000 (16:00 +0000)] 
network: Move a couple of helper functions into headers

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation: Fix output of list-* commands
Michael Tremer [Sat, 5 Mar 2022 14:26:48 +0000 (14:26 +0000)] 
location: Fix output of list-* commands

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoimporter: Skip empty lines
Michael Tremer [Sat, 5 Mar 2022 13:26:23 +0000 (13:26 +0000)] 
importer: Skip empty lines

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoimporter: Silently ignore any table headers
Michael Tremer [Sat, 5 Mar 2022 13:15:36 +0000 (13:15 +0000)] 
importer: Silently ignore any table headers

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoimporter: Correctly hande response codes from Bird
Michael Tremer [Sat, 5 Mar 2022 13:15:07 +0000 (13:15 +0000)] 
importer: Correctly hande response codes from Bird

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodatabase: Return something when no filter criteria is configured
Michael Tremer [Sat, 5 Mar 2022 12:04:44 +0000 (12:04 +0000)] 
database: Return something when no filter criteria is configured

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoimporter: Parse aggregated networks
Michael Tremer [Sat, 5 Mar 2022 11:56:40 +0000 (11:56 +0000)] 
importer: Parse aggregated networks

This patch adds code to parse any aggregated networks.

Bird does not automatically show the last ASN of the path, but we can
collect all networks that we can see without any ASN and perform
"show route <network> all" on them to gather this information.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoBump release to 0.9.11 0.9.11
Michael Tremer [Thu, 3 Mar 2022 10:41:22 +0000 (10:41 +0000)] 
Bump release to 0.9.11

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoexport: Sightly refactor export logic
Michael Tremer [Thu, 3 Mar 2022 09:33:42 +0000 (09:33 +0000)] 
export: Sightly refactor export logic

This patch moves creating the "tag" (formerly known as prefix) into the
writer class, so that we can modify it based on what output format we
have.

ipset and nftables will need disjunct names for IPv6 and IPv4 because
they cannot handle mixed sets.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoexport: Fix filtering logic
Michael Tremer [Thu, 3 Mar 2022 08:48:14 +0000 (08:48 +0000)] 
export: Fix filtering logic

It is possible to filter for what kind of network should be exported.

This worked well when the filter list only contained country codes, or
when it only contained ASNs. If there was a mix, only networks that
match both (i.e. virtually nothing) matched.

This patch fixes that we will use for either of them.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer: Fix parsing LACNIC-flavoured inetnums
Peter Müller [Tue, 1 Mar 2022 21:52:39 +0000 (21:52 +0000)] 
location-importer: Fix parsing LACNIC-flavoured inetnums

My fault, again. :-/

Reported-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoipset: The minimum hashsize is 64
Michael Tremer [Wed, 2 Mar 2022 10:58:51 +0000 (10:58 +0000)] 
ipset: The minimum hashsize is 64

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoexport: Allow exporting to stdout
Michael Tremer [Wed, 2 Mar 2022 10:53:04 +0000 (10:53 +0000)] 
export: Allow exporting to stdout

This is useful if you want to pipe output straight into another program.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation: Print proper error message for any uncaught exceptions
Michael Tremer [Wed, 2 Mar 2022 10:50:34 +0000 (10:50 +0000)] 
location: Print proper error message for any uncaught exceptions

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoexport: Conditionally enable flattening
Michael Tremer [Wed, 2 Mar 2022 10:26:41 +0000 (10:26 +0000)] 
export: Conditionally enable flattening

By default, we enabled flattening of the network tree when we export it.

However, this is only required for xt_geoip since the other formats can
deal with overlapping networks and would even benefit from a shorter
list.

Therefore this is now only enabled when needed which results in shorter
export times (9 seconds instead of 2.5 minutes) and the full ipset is
about 20% smaller when loaded into memory than before.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoipset: Set maxelem to a fixed size
Michael Tremer [Wed, 2 Mar 2022 10:18:16 +0000 (10:18 +0000)] 
ipset: Set maxelem to a fixed size

When we try to load a changed set which might have more entries, a
previous maxelem could have been smaller preventing us from adding new
entries.

We also cannot run the "create" command with a changed maxelem
parameter which is why this patch set the value to something that should
be large enough for everything.

The downside of this is also, that we cannot modify the hashsize when we
reload a set, which is probably okay, since sets should not change too
much in size and therefore will only run *slightly* less efficient - if
at all.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoipset: Fix hash type for IPv6
Michael Tremer [Tue, 1 Mar 2022 13:01:23 +0000 (13:01 +0000)] 
ipset: Fix hash type for IPv6

IPv6 exports could not be loaded because sets were created as type
"inet" instead of "inet6" which is fixed by this patch.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoipset: Optimise hash table size
Michael Tremer [Tue, 1 Mar 2022 12:44:21 +0000 (12:44 +0000)] 
ipset: Optimise hash table size

ipset uses a hash table internally which can be dynamically sized to
chose whether more space efficiency or performance is required.

Previously to this patch, we always set the size of the hash table to
1024 buckets. Having large sets with almost half a million entries, this
is not performing well since we will spend a lot of time in searching
the linked list.

This will probably perform even slower on systems with smaller cache
sizes like the IPFire Mini Appliance.

Having more buckets that are sparesely filled, will result in less
memory fetches at the cost of more wastage. Throughout the whole IPv4
set, this ranges from about 50 MB for a factor of 4, to about 100 MB for
a factor of 0.75.

Since memory of this quantity is cheap and since we want to increase
throughput, I have chosen to set the fill factor to 0.75.

Logistically, it is a little bit complicated to know this in advance
when we have to write the header, so we will write the entire file
first, and then come back to write the header again. This is required to
keep memory consumption down during the export.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoexport: Remove prefix when exporting countries.
Stefan Schantl [Thu, 24 Feb 2022 17:52:13 +0000 (18:52 +0100)] 
export: Remove prefix when exporting countries.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoBump release to 0.9.10 0.9.10
Michael Tremer [Wed, 16 Feb 2022 08:54:50 +0000 (08:54 +0000)] 
Bump release to 0.9.10

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoexport: Make ipset files easily reloadable
Michael Tremer [Fri, 11 Feb 2022 17:14:02 +0000 (17:14 +0000)] 
export: Make ipset files easily reloadable

This change allows to "restore" a file multiple times without problems.

If the set already exists, the create command will skip it and we will
flush any existing content to load the new one.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: Do not make things more complicated than they are
Peter Müller [Sat, 18 Dec 2021 12:57:45 +0000 (13:57 +0100)] 
location-importer.in: Do not make things more complicated than they are

Suggested-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: Add country code for AWS's "il-central-1" zone
Peter Müller [Fri, 11 Feb 2022 09:57:47 +0000 (09:57 +0000)] 
location-importer.in: Add country code for AWS's "il-central-1" zone

Reported-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoman: Add man pages for all loc_database_* functions
Michael Tremer [Sun, 2 Jan 2022 14:59:07 +0000 (14:59 +0000)] 
man: Add man pages for all loc_database_* functions

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoMakefile: Split man pages into multiple lists
Michael Tremer [Sun, 2 Jan 2022 14:19:21 +0000 (14:19 +0000)] 
Makefile: Split man pages into multiple lists

This isn't pretty but makes substitution rules easier and working
correctly.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoman: Add man page for loc_database_new
Michael Tremer [Sun, 2 Jan 2022 14:16:01 +0000 (14:16 +0000)] 
man: Add man page for loc_database_new

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoman: Add pages for top level functions
Michael Tremer [Sun, 2 Jan 2022 11:55:00 +0000 (11:55 +0000)] 
man: Add pages for top level functions

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer: Replace "UK" with "GB"
Peter Müller [Sun, 12 Dec 2021 09:11:43 +0000 (10:11 +0100)] 
location-importer: Replace "UK" with "GB"

Apparently, LACNIC does not to proper input validation on supplied
country codes, so people can use "UK", while they probably mean "GB"
instead.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer: Improve regex for catching historic/orphaned data
Peter Müller [Sun, 12 Dec 2021 09:05:15 +0000 (10:05 +0100)] 
location-importer: Improve regex for catching historic/orphaned data

This silences a bunch of warnings due to allocations at APNIC having
country code set to "ZZ", which are completely irrelevant to us.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoProcess LACNIC geofeed as well
Peter Müller [Sat, 11 Dec 2021 21:59:22 +0000 (22:59 +0100)] 
Process LACNIC geofeed as well

This improves country code accurarcy for suballocations within IP space
managed by LACNIC, as the delegated-extended-latest file only provides
country code information at the top level of an allocated network.

Sadly, lacnic.db.gz does not contain descriptions or names of Autonomous
Systems within the space maintained by LACNIC.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer: Set "is_drop" to "True" even in case of conflicts
Peter Müller [Sat, 11 Dec 2021 18:01:54 +0000 (19:01 +0100)] 
location-importer: Set "is_drop" to "True" even in case of conflicts

Previously, any present override for a given network or ASN would have
caused the SQL statement not to conduct anything at all. Since "is_drop"
is the only flag being actually set here, it makes sense to do so in
case of already present overrides as well.

The effect of this is limited: Our own override files are always
considered at last, so in case of conflicts they will be the ultima
ratio. This is an intended behaviour, but slipped my mind when I filed
bug #12728, so this patch can only be seen as a partial solution - the
rest is not a bug, but a feature. :-)

Partially fixes: #12728

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodebian: Fix broken build
Michael Tremer [Tue, 23 Nov 2021 11:08:16 +0000 (11:08 +0000)] 
debian: Fix broken build

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodebian: Remove riscv64 which doesn't build
Michael Tremer [Tue, 23 Nov 2021 10:20:05 +0000 (10:20 +0000)] 
debian: Remove riscv64 which doesn't build

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoRevert "debian: dh no longer knows "--with python3""
Michael Tremer [Tue, 23 Nov 2021 10:12:41 +0000 (10:12 +0000)] 
Revert "debian: dh no longer knows "--with python3""

This reverts commit 2ca0603f557dc47c3aba2ccc2aa6447ee61e1a03.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodebian: Add builds for Debian Bookworm and riscv64
Michael Tremer [Sat, 20 Nov 2021 15:30:01 +0000 (15:30 +0000)] 
debian: Add builds for Debian Bookworm and riscv64

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodebian: dh no longer knows "--with python3"
Michael Tremer [Sat, 20 Nov 2021 15:25:42 +0000 (15:25 +0000)] 
debian: dh no longer knows "--with python3"

This does not seem to be necessary any more since the build works fine
without the switch.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoBump release to 0.9.9 0.9.9
Michael Tremer [Sat, 20 Nov 2021 15:13:33 +0000 (15:13 +0000)] 
Bump release to 0.9.9

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodebian: Update libloc1.symbols
Michael Tremer [Sat, 20 Nov 2021 15:11:04 +0000 (15:11 +0000)] 
debian: Update libloc1.symbols

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: Add Spamhaus DROP lists
Peter Müller [Mon, 1 Nov 2021 18:24:37 +0000 (19:24 +0100)] 
location-importer.in: Add Spamhaus DROP lists

A while ago, it was discussed whether or not libloc should become an
"opinionated database", i. e. including any information on a network's
reputation.

In general, this idea was dismissed as libloc is neither intended nor
suitable for such tasks, and we do not want to make (political?)
decisions like these for various reasons. All we do is to provide a
useful location database in a neutral way, and leave it up to our users
on how to react on certain results.

However, there is a problematic area. Take AS55303 as an example: We
_know_ this is to be a dirty network, tampering with RIR data and
hijacking IP space, and strongly recommend against processing any
connection originating from or directed to it.

Since it appears to be loaded with proxies used by miscreants for
abusive purposes, all we can do at the time of writing is to flag it
as "anonymous proxy", but we lack possibility of telling our users
something like "this is not a safe area". The very same goes for known
bulletproof ISPs, IP hijackers, and so forth.

This patch therefore suggests to populate the "is_drop" flag introduced
in libloc 0.9.8 (albeit currently unused in production) with the
contents of Spamhaus' DROP lists (https://www.spamhaus.org/drop/), to
have at least the baddest of the bad covered. The very same lists are,
in fact, included in popular IPS rulesets as well - a decent amount of
IPFire users is therefore likely to have them already enabled, but in a
very costly way.

It is not planned to go further, partly because there is no other feed
publicly available, which would come with the same intention,
volatility, and FP rate.

The third version of this patch makes use of an auxiliary function to
sanitise ASNs, hence avoiding boilerplate code, and treats any line
starting with a semicolon as a comment, which should be sufficient.
Further, extracting ASNs from the ASN-DROP feed is done in a more clear
way, avoiding code snippets hard to read.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer: Introduce auxiliary function to sanitise ASNs
Peter Müller [Mon, 1 Nov 2021 18:24:14 +0000 (19:24 +0100)] 
location-importer: Introduce auxiliary function to sanitise ASNs

The third version of this patch does this in an even more Pythonic way.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoimporter.py: Import JPNIC feed as well
Peter Müller [Sat, 23 Oct 2021 06:54:23 +0000 (08:54 +0200)] 
importer.py: Import JPNIC feed as well

This adds names for - at the time of writing - 421 ASNs which were missing
before, as JPNIC does not mirror (all) information back to APNIC.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation.txt: Improve manpage
Peter Müller [Sun, 10 Oct 2021 16:45:48 +0000 (18:45 +0200)] 
location.txt: Improve manpage

* Document "location version" feature.
* Improve section for reporting bugs in order to make bug reporting
  easier.

Fixes: #12698
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork: Rename "match" functions to "matches"
Michael Tremer [Thu, 30 Sep 2021 10:36:56 +0000 (10:36 +0000)] 
network: Rename "match" functions to "matches"

Gramatically, this makes more sense.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork: Make loc_network_match_country_code match special countries
Michael Tremer [Thu, 30 Sep 2021 10:34:09 +0000 (10:34 +0000)] 
network: Make loc_network_match_country_code match special countries

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agocountry: Make country codes beginning with X invalid
Michael Tremer [Thu, 30 Sep 2021 10:23:11 +0000 (10:23 +0000)] 
country: Make country codes beginning with X invalid

According to ISO3166, they are only allowed for "private use".

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agocountry: Add function that returns flags for special country
Michael Tremer [Thu, 30 Sep 2021 10:19:46 +0000 (10:19 +0000)] 
country: Add function that returns flags for special country

This allows for libloc to be better integrated into third-party
software.

If we would add extra flags, we would be able to extend it in libloc
without touching any third-party software.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoRemove overwriting default CPPFLAGS for libloc-internal
Michael Tremer [Thu, 30 Sep 2021 09:39:33 +0000 (09:39 +0000)] 
Remove overwriting default CPPFLAGS for libloc-internal

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoRemove LOC_EXPORT from loc_network_to_database_v1/loc_network_new_from_database_v1
Michael Tremer [Thu, 30 Sep 2021 09:29:22 +0000 (09:29 +0000)] 
Remove LOC_EXPORT from loc_network_to_database_v1/loc_network_new_from_database_v1

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoMake loc_network_tree_* functions propertly private
Michael Tremer [Thu, 30 Sep 2021 09:26:20 +0000 (09:26 +0000)] 
Make loc_network_tree_* functions propertly private

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agostringpool: Make functions properly private
Michael Tremer [Thu, 30 Sep 2021 09:23:29 +0000 (09:23 +0000)] 
stringpool: Make functions properly private

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agotest: Build an internal library for tests
Michael Tremer [Thu, 30 Sep 2021 09:21:00 +0000 (09:21 +0000)] 
test: Build an internal library for tests

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork: Drop useless loc_network_match_asn function
Michael Tremer [Wed, 29 Sep 2021 18:22:51 +0000 (18:22 +0000)] 
network: Drop useless loc_network_match_asn function

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork: Drop redundant loc_network_match_flag
Michael Tremer [Wed, 29 Sep 2021 18:21:31 +0000 (18:21 +0000)] 
network: Drop redundant loc_network_match_flag

There is loc_network_has_flag which does exactly the same

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoconfigure: Enable -fno-semantic-interposition by default
Michael Tremer [Wed, 29 Sep 2021 18:17:31 +0000 (18:17 +0000)] 
configure: Enable -fno-semantic-interposition by default

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodatabase: Make IP address const for lookup
Michael Tremer [Sat, 4 Sep 2021 15:11:48 +0000 (15:11 +0000)] 
database: Make IP address const for lookup

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodebian: Ensure changelog distribution is tagged
Valters Jansons [Thu, 23 Sep 2021 10:23:50 +0000 (13:23 +0300)] 
debian: Ensure changelog distribution is tagged

UNRELEASED should not be left as-is when actually releasing.
The latest changelog entry now point at unstable instead.

The simple d/genchangelog.sh now does `dch -r ''` automatically
to ensure this distribution update doesn't get lost along the way
on future invocations.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoBump release to 0.9.8 0.9.8
Michael Tremer [Tue, 21 Sep 2021 10:30:19 +0000 (10:30 +0000)] 
Bump release to 0.9.8

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoMove include files to /usr/include/libloc
Michael Tremer [Sat, 4 Sep 2021 13:38:44 +0000 (13:38 +0000)] 
Move include files to /usr/include/libloc

There was a discrepancy between the paths in the build environment and
the installed headers which could not be included in any third-party
software.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation: Implement listing bogons
Michael Tremer [Thu, 2 Sep 2021 13:25:37 +0000 (13:25 +0000)] 
location: Implement listing bogons

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agopython: Permit passing family to database enumerator
Michael Tremer [Thu, 2 Sep 2021 13:22:23 +0000 (13:22 +0000)] 
python: Permit passing family to database enumerator

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agonetwork: Move some helper functions into network.h
Michael Tremer [Thu, 2 Sep 2021 13:20:16 +0000 (13:20 +0000)] 
network: Move some helper functions into network.h

These are used in multiple places, but there is no good place where
those should go, yet.

To make them usable in more places, I am temporarily moving them here.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: Braindead me accidentally forgot a "break" statement
Peter Müller [Sun, 8 Aug 2021 21:31:58 +0000 (23:31 +0200)] 
location-importer.in: Braindead me accidentally forgot a "break" statement

This one apparently went down the drain between these two patches:
- https://patchwork.ipfire.org/project/location/patch/20210522125758.28770-1-peter.mueller@ipfire.org/
- https://patchwork.ipfire.org/project/location/patch/aefd1904-4b38-f5cf-ab1d-9d69636cf914@ipfire.org/

Due to other safeguards, the current damage in production is limited to:

location=# SELECT * FROM networks WHERE country = 'ZZ';
      network       | country | original_countries | source
--------------------+---------+--------------------+--------
 130.195.64.0/19    | ZZ      | {ZZ}               | APNIC
 130.195.96.0/19    | ZZ      | {ZZ}               | APNIC
 122.252.24.0/21    | ZZ      | {ZZ}               | APNIC
 2406:840:10::/48   | ZZ      | {ZZ}               | APNIC
 2406:840:fd0f::/48 | ZZ      | {ZZ}               | APNIC
(5 rows)

Fixes: #12673
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: Attempt to provide meaningful AS names if organisation handles...
Peter Müller [Mon, 19 Jul 2021 21:34:40 +0000 (21:34 +0000)] 
location-importer.in: Attempt to provide meaningful AS names if organisation handles are missing

A decent amount of autnum objects - especially, but not exclusively in
the APNIC sector - does not contain a link to an organisation handle.

In such cases, this patch is going to use the first description line of
the atunum object in question (if available) as a string for its name.
The overwhelming majority of affected ASNs contains a valuable
information there, so this is almost as good as having an organisation
handle linked to it.

Fixes: #12660
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodebian: Clean up 0.9.7 changelog
Valters Jansons [Sun, 11 Jul 2021 16:50:24 +0000 (19:50 +0300)] 
debian: Clean up 0.9.7 changelog

- Update for maintainer name and email address, as to reflect who
  actually prepared this release of the package. It was not me,
  but I was selected due to having the first commit on the package.

  To mitigate against this, when running the `debchange --release`
  (`dch -r`) command, environment variables DEBFULLNAME and DEBEMAIL
  should be configured properly for the current user.

- Removal of NMU comment on my name, as I am not really doing a
  non-maintainer upload. I would say the 'NMU' message is fairly
  useless on this repository, as it is self-maintained here.

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agostringpool: Avoid memory leak if mmap() fails
Michael Tremer [Sun, 11 Jul 2021 12:27:43 +0000 (12:27 +0000)] 
stringpool: Avoid memory leak if mmap() fails

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agostringpool: Slightly refactor initialization to help the compiler understand
Michael Tremer [Sun, 11 Jul 2021 12:21:31 +0000 (12:21 +0000)] 
stringpool: Slightly refactor initialization to help the compiler understand

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agostringpool: Do not call strlen() on potential NULL pointer
Michael Tremer [Sun, 11 Jul 2021 12:10:48 +0000 (12:10 +0000)] 
stringpool: Do not call strlen() on potential NULL pointer

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agostringpool: Allow adding empty strings
Michael Tremer [Sun, 11 Jul 2021 11:56:50 +0000 (11:56 +0000)] 
stringpool: Allow adding empty strings

This is what we do when we initialize the stringpool

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agowriter: Break when a network cound not be allocated
Michael Tremer [Sun, 11 Jul 2021 11:44:28 +0000 (11:44 +0000)] 
writer: Break when a network cound not be allocated

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoconfigure: Add option to enable GCC's -fanalyzer
Michael Tremer [Sun, 11 Jul 2021 11:37:44 +0000 (11:37 +0000)] 
configure: Add option to enable GCC's -fanalyzer

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoimporter: Do not try to initialise a column that cannot be NULL with NULL
Michael Tremer [Fri, 9 Jul 2021 18:30:28 +0000 (18:30 +0000)] 
importer: Do not try to initialise a column that cannot be NULL with NULL

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoBump version to 0.9.7 0.9.7
Michael Tremer [Fri, 9 Jul 2021 17:12:55 +0000 (17:12 +0000)] 
Bump version to 0.9.7

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodebian: Attribute all maintainers in changlog
Valters Jansons [Sun, 13 Jun 2021 16:16:25 +0000 (19:16 +0300)] 
debian: Attribute all maintainers in changlog

This commit further builds on historical changelog modifications,
to properly attribute all authors of the commits.

An additional d/genchangelog.sh script has been added. This allows
generation of changelog entries, internally using `debchange` (`dch`).
The script accepts an argument, which is the commit range to generate
entries for. Each commit's subject line (first line of body) is used,
along with author name and email. This information is added to the
changelog. Automatic detection (via `debchange` built-in functionality)
is used to determine whether these entries should be added to an
existing version number. If there is no UNRELEASED version, then a new
version is automatically tagged.

The new version tag will usually need to be modified, for example,
replacing an automatically generated 0.9.6-2 with 0.9.7-1.

The final release change (s/UNRELEASED/unstable/) needs to be done
manually as well, when the Git tag is actually being tagged.
`dch -r` can be useful for this particular purpose.

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-import.in: optimise regular expression for filtering ASN allocations to...
Peter Müller [Sun, 20 Jun 2021 10:43:07 +0000 (12:43 +0200)] 
location-import.in: optimise regular expression for filtering ASN allocations to other RIRs when parsing ARIN AS names file

https://lists.ipfire.org/pipermail/location/2021-June/000394.html

Reported-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agodebian: Add dpkg's symbols file
Valters Jansons [Fri, 11 Jun 2021 07:51:07 +0000 (10:51 +0300)] 
debian: Add dpkg's symbols file

There are muiltiple standards of listing symbols throughout the Linux
ecosystem. For `dpkg`, a d/package.symbols file tracks symbols, and in
which version they were added in. This is then used to allow dependency
checks/resolution.

See man:dpkg-gensymbols(1) for details about the generation,
and man:dpkg-shlibdeps(1) for how the symbols file ends up being used.

This commit adds a d/libloc1.symbols file, containing the current state
of the symbols. There is now also a d/gensymbols.sh script, which
generates this symbols file. The script tries to determine what Git
tags need to be checked for changes in symbols, by looking at current
maximum version referenced in symbols file.

After checking tags, the current revision is also processed, to allow
building symbols file for a yet unreleased version (prior to tagging it).
This is to allow symbols changes to be included in a tag.

Do keep in mind, that for the workflow above, when running the script,
the d/changelog file should contain information about what version the
current revision will be released at (potentially tagged as UNRELEASED
in the d/changelog file). Otherwise, if there is no version tagged,
the `dpkg-gensymbols` tool will use the old version information,
in turn incorrectly attributing new symbols to an old version.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agocountries: Fix matching invalid country codes
Michael Tremer [Thu, 10 Jun 2021 09:37:22 +0000 (09:37 +0000)] 
countries: Fix matching invalid country codes

When an invalid country code is entered, loc_country_new returns an
error which is interpreted as a match to the list since we check for a
non-zero return code.

Any invalid country codes are now silently ignored and not considered a
match.

Fixes: #12620 - "location list-networks-by-cc" returns garbage
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: import additional IP information for Amazon AWS IP networks
Peter Müller [Tue, 8 Jun 2021 09:55:41 +0000 (09:55 +0000)] 
location-importer.in: import additional IP information for Amazon AWS IP networks

Amazon publishes information regarding some of their IP networks
primarily used for AWS cloud services in a machine-readable format. To
improve libloc lookup results for these, we have little choice other
than importing and parsing them.

Unfortunately, there seems to be no machine-readable list of the
locations of their data centers or availability zones available. If
there _is_ any, please let the author know.

The second version of this patch adds a meaningful description for the
"source" column in the overrides tables, to make introduced changes
less intransparent.

Fixes: #12594
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: add source column for overrides as well
Peter Müller [Tue, 8 Jun 2021 09:55:40 +0000 (09:55 +0000)] 
location-importer.in: add source column for overrides as well

This allows us to track changes introduced by IP feeds from 3rd parties,
such as Amazon AWS, on the SQL server side.

In order not to break existing tables (which would required TRUNCATE),
there currently is no constraint set for the new column, but "NOT NULL"
is planned in the future.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: Import (technical) AS names from ARIN
Peter Müller [Tue, 8 Jun 2021 17:03:07 +0000 (17:03 +0000)] 
location-importer.in: Import (technical) AS names from ARIN

ARIN and LACNIC, unfortunately, do not seem to publish data containing
human readable AS names. For the former, we at least have a list of
tecnical names, which this patch fetches and inserts into the autnums
table.

While some of them do not seem to be suitable for human consumption (i.
e. being very cryptic), providing these data might be helpful
neverthelesss.

The second version of this patch contains some additional remarks on
efficient Python coding style from Michael, doing things more "pythonic".

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoImplement an additional flag for hostile networks safe to drop
Peter Müller [Fri, 4 Jun 2021 15:57:30 +0000 (17:57 +0200)] 
Implement an additional flag for hostile networks safe to drop

This patch implements an additional flag intended for networks and
Autonomous Systems being considered hostile. While libloc does not and
should not be an opinionated database, reality shows it is being used
this way.

Hereby, we assign "XD" (drop) as a custom country code for networks
being flagged this way. According to ISO, "XA" to "XZ" are reserved for
"user-assgined codes" (https://www.iso.org/glossary-for-iso-3166.html),
so this is a safe thing to do.

This patch does not interfere with "A1" to "A3", which we currently
assign outside standardised country code ranges for historical reasons.

Neither does it specify any policy or source for tagging networks with a
"drop" flag. Doing so is beyond the scope of this - technical -
approach.

To avoid confusions with the SQL "DROP" command, "is_drop" will be used
as a column name for database operations.

Thanks to Michael for his remarks and ideas during the run-up.

Cc: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: track original countries more pythonic
Peter Müller [Wed, 2 Jun 2021 21:00:22 +0000 (23:00 +0200)] 
location-importer.in: track original countries more pythonic

https://lists.ipfire.org/pipermail/location/2021-May/000377.html

Reported-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: track original countries as well
Peter Müller [Sun, 30 May 2021 08:50:04 +0000 (10:50 +0200)] 
location-importer.in: track original countries as well

This helps us to determine how many network objects have more than one
country set, and what their original country code set looked like.

The third version of this patch uses ALTER TABLE to add the column for
original countries, preventing existing SQL setups from breaking, and is
correctly based against the current "master" branch.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agoimporter.py: add source information for RIR data feeds
Peter Müller [Sat, 22 May 2021 20:33:52 +0000 (20:33 +0000)] 
importer.py: add source information for RIR data feeds

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2 years agolocation-importer.in: keep track of sources for networks, ASNs, and organisations
Peter Müller [Sat, 22 May 2021 20:33:51 +0000 (20:33 +0000)] 
location-importer.in: keep track of sources for networks, ASNs, and organisations

This allows us to trace back concrete changes or anomalies to their RIR
source, without having to parse everything again. Further, it enables
adding 3rd party sources such as IP feeds from Amazon, without loosing
track of the changes introduced by them.

The second version of this patchset uses ALTER TABLE to add the source
columns, avoiding breaking existing SQL setups.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agolocation.in: fix search_networks() function call
Peter Müller [Sun, 16 May 2021 20:35:15 +0000 (22:35 +0200)] 
location.in: fix search_networks() function call

Fixes: #12617
Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agolocation-importer.in: emit warnings due to unknown country code for valid networks...
Peter Müller [Mon, 3 May 2021 17:14:29 +0000 (19:14 +0200)] 
location-importer.in: emit warnings due to unknown country code for valid networks only

This reduces log spam in case of processing RIR database, checking for
networks with unknown country codes assigned. If we would not have
written into the database, there is no need to warn about them.

Signed-off-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agodebian: Drop unintended files from location-python
Valters Jansons [Fri, 16 Apr 2021 13:06:10 +0000 (16:06 +0300)] 
debian: Drop unintended files from location-python

_location.la gets built and installed to site-packages/, however
an .la file is not expected to reside in the Python root. Additionally,
the dependency library listed does not have its respective .la file
installed. Further complicating the situation, dh-python moves the
site-packages/ files to dist-packages/ silently which then results in
a broken libdir left behind in the .la file.

The only reason the file is there is that it gets built inside the
source directory, which gets copied entirely to location-python package
as-is. Considering the situation, this commit ensures the .la files is
not packaged by deleting it from the package files subdirectory.

location-importer package pulls in two Python (.py) files from the
source directory. These files should not be included in the
location-python package as a result.

Resolves: lintian:
  unknown-file-in-python-module-directory,
  incorrect-libdir-in-la-file,
  non-empty-dependency_libs-in-la-file,
  binaries-have-file-conflict

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agodebian: Add all temporary files to Gitignore
Valters Jansons [Fri, 16 Apr 2021 13:06:05 +0000 (16:06 +0300)] 
debian: Add all temporary files to Gitignore

New packages have been added since the inception of the .gitignore and
as a result during build we see directories such as location-importer/
and files such as location-importer.debhelper.log.

This commit ensures all temporary subdirectories, and additional
generic build artifact files, are ignored by Git.

The subdirectory exceptions to this rule are:

- d/patches/ which may be used by Quilt
  considering the source format is '3.0 (quilt)',

- d/source/ for the format file,

- d/tests/ which may be used by autopkgtest
  to specify what test suites exist for the source.
  See: https://salsa.debian.org/ci-team/autopkgtest/-/raw/debian/5.16/doc/README.package-tests.rst

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agosystemd: Add Documentation= to location-update
Valters Jansons [Fri, 16 Apr 2021 13:06:12 +0000 (16:06 +0300)] 
systemd: Add Documentation= to location-update

Systemd units are expected to provide some documentation information
such as manpages, or direct links, which provide more details about
that unit. This commit simply links location-update.service to the
manual for location(8) followed by a fallback to the online manual.

See: https://manpages.debian.org/buster/systemd/systemd.unit.5.en.html#%5BUNIT%5D_SECTION_OPTIONS

Resolves: lintian: systemd-service-file-missing-documentation-key

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agodebian: Add watch configuration for uscan
Valters Jansons [Fri, 16 Apr 2021 13:06:11 +0000 (16:06 +0300)] 
debian: Add watch configuration for uscan

Packages defined as '3.0 (quilt)' are expected to provide information
about how the latest upstream information can be obtained,
as a special d/watch file. This can then get used by uscan(1).

To see how the metadata is utilized, and how the network requests
are made behind the scenes, you can locally run:
$ uscan --no-download --verbose --debug

Resolves: lintian: debian-watch-file-is-missing

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agodebian: Set 'Multi-Arch: foreign' hint for Python
Valters Jansons [Fri, 16 Apr 2021 13:06:07 +0000 (16:06 +0300)] 
debian: Set 'Multi-Arch: foreign' hint for Python

Due to the invocation of py3compile (via dh-python) in location-importer
and location-python packages, those packages have different bytecode for
varying architectures, and as a result are not 'Multi-Arch: same'.

Resolves: lintian: multi-arch-same-package-calls-pycompile

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agodebian: Add examples/python/ to documentation
Valters Jansons [Fri, 16 Apr 2021 13:06:09 +0000 (16:06 +0300)] 
debian: Add examples/python/ to documentation

Resolves: lintian: package-does-not-install-examples

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agodebian: Update copyright format link to use HTTPS
Valters Jansons [Fri, 16 Apr 2021 13:06:08 +0000 (16:06 +0300)] 
debian: Update copyright format link to use HTTPS

Resolves: lintian: insecure-copyright-format-uri

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agodebian: Move libloc1 to 'libs' section
Valters Jansons [Fri, 16 Apr 2021 13:06:06 +0000 (16:06 +0300)] 
debian: Move libloc1 to 'libs' section

Resolves: lintian: wrong-section-according-to-package-name

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
3 years agopo: Update translations
Valters Jansons [Thu, 15 Apr 2021 11:42:13 +0000 (14:42 +0300)] 
po: Update translations

POTFILES.in should not contain src/python/__init__.py file as it
is not present in the committed tree. It has its respective .in file
which is present instead.

This commit further ensures po/POTFILES.in generator avoids such
files that Git ignores (using git-check-ignore during find).

Signed-off-by: Valters Jansons <valter.jansons@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>