]> git.ipfire.org Git - location/location-database.git/commitdiff
database: Set flags when parsing A1-A3
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 15 Nov 2019 15:34:26 +0000 (15:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 15 Nov 2019 15:34:26 +0000 (15:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tools/database.py

index 823faaf6eb1e29d0230fa727df3e78426da26381..252229f58c2b5cb7a9cef3c91959d7593dbe06d0 100644 (file)
@@ -47,15 +47,20 @@ class Database(object):
        def write(self, path):
                self.writer.write(path)
 
-       def import_rir(self, rir):
-               with open(rir.filename_asnums, "rb") as f:
+       def import_ases(self, filename):
+               with open(filename, "rb") as f:
                        for block in util.iterate_over_blocks(f):
                                self._parse_asnum_block(block)
 
-               with open(rir.filename_networks, "rb") as f:
+       def import_networks(self, filename):
+               with open(filename, "rb") as f:
                        for block in util.iterate_over_blocks(f):
                                self._parse_network_block(block)
 
+       def import_rir(self, rir):
+               self.import_ases(rir.filename_asnums)
+               self.import_networks(rir.filename_networks)
+
        def _parse_asnum_block(self, block):
                asn  = None
                name = None
@@ -103,8 +108,19 @@ class Database(object):
                                logging.warning("Skipping network %s, because one already exists at this address" % network)
                                return
 
-                       # Save attributes
-                       n.country_code = country
+                       # Translate some special country codes into flags
+                       if country == "A1":
+                               n.set_flag(location.NETWORK_FLAG_ANONYMOUS_PROXY)
+                       elif country == "A2":
+                               n.set_flag(location.NETWORK_FLAG_SATELLITE_PROVIDER)
+                       elif country == "A3":
+                               n.set_flag(location.NETWORK_FLAG_ANYCAST)
+
+                       # Set all other country codes
+                       else:
+                               n.country_code = country
+
+                       # Set ASN if available
                        if asn:
                                n.asn = asn