From bd1aa6a1850a1436ffebc094c34f38e770289f0b Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 15 May 2020 13:54:46 +0000 Subject: [PATCH] location-impoter: Allow overriding country by AS override Signed-off-by: Michael Tremer --- src/python/location-importer.in | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/python/location-importer.in b/src/python/location-importer.in index ea6d485..f9c87f6 100644 --- a/src/python/location-importer.in +++ b/src/python/location-importer.in @@ -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", -- 2.39.2