]> git.ipfire.org Git - location/libloc.git/commitdiff
location-impoter: Allow overriding country by AS override
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 15 May 2020 13:54:46 +0000 (13:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 15 May 2020 13:54:46 +0000 (13:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/location-importer.in

index ea6d48527c8139760e38c6ee6c407c6cd8376009..f9c87f672ed9577688208fdeed6749633abcfb14 100644 (file)
@@ -155,6 +155,7 @@ class CLI(object):
                                CREATE TABLE IF NOT EXISTS autnum_overrides(
                                        number bigint NOT NULL,
                                        name text,
+                                       country text,
                                        is_anonymous_proxy boolean DEFAULT FALSE,
                                        is_satellite_provider boolean DEFAULT FALSE,
                                        is_anycast boolean DEFAULT FALSE
@@ -221,7 +222,21 @@ class CLI(object):
                                DISTINCT ON (announcements.network)
                                announcements.network AS network,
                                announcements.autnum AS autnum,
-                               networks.country AS country,
+
+                               -- Country
+                               COALESCE(
+                                       (
+                                               SELECT country FROM network_overrides overrides
+                                                       WHERE announcements.network <<= overrides.network
+                                                       ORDER BY masklen(overrides.network) DESC
+                                                       LIMIT 1
+                                       ),
+                                       (
+                                               SELECT country FROM autnum_overrides overrides
+                                                       WHERE announcements.autnum = overrides.number
+                                       ),
+                                       networks.country
+                               ) AS country,
 
                                -- Must be part of returned values for ORDER BY clause
                                masklen(networks.network) AS sort,
@@ -626,12 +641,15 @@ class CLI(object):
                                                                INSERT INTO autnum_overrides(
                                                                        number,
                                                                        name,
+                                                                       country,
                                                                        is_anonymous_proxy,
                                                                        is_satellite_provider,
                                                                        is_anycast
-                                                               ) VALUES(%s, %s, %s, %s, %s)
+                                                               ) VALUES(%s, %s, %s, %s, %s, %s)
                                                                ON CONFLICT DO NOTHING""",
-                                                               autnum, block.get("name"),
+                                                               autnum,
+                                                               block.get("name"),
+                                                               block.get("country"),
                                                                block.get("is-anonymous-proxy") == "yes",
                                                                block.get("is-satellite-provider") == "yes",
                                                                block.get("is-anycast") == "yes",