pierky / arouteserver

A tool to automatically build (and test) feature-rich configurations for BGP route servers.
https://arouteserver.readthedocs.org/
GNU General Public License v3.0
288 stars 46 forks source link

Add support for Registro.BR WHOIS source #28

Closed job closed 6 years ago

job commented 6 years ago

The Brazil NIR "NIC.BR" (the exclusive source for resources in Brazil, by delegation from LACNIC) does not have a traditional IRR. Instead a WHOIS database is used which in concept is similar to ARIN-WHOIS, but in terms of quality seems to be more accurate.

Registro.br (under the umbrella of NIC.BR) publishes a computer parse-able dump of the WHOIS registry which can be consumed to construct BGP filters.

The dump is published every weekday here: ftp://ftp.registro.br/pub/numeracao/origin/nicbr-asn-blk-latest.txt

the format is as following, a like like this:

AS6543|Ecospar Serv. e Part. Ltda.|35.809.342/0001-31|2804:69c::/32|200.219.0.0/21

can be transformed to the following IRR format:

route6: 2804:69c::/32
origin: AS6543
source: REGISTROBR

route: 200.219.0.0/21
origin: AS6543
source: REGISTROBR
job commented 6 years ago

here is some python code I use to parse this file:

#!/usr/bin/env python3

import csv
import datetime
import fileinput
import ipaddress as ip
import sys
import unicodedata

today = datetime.date.today()
records = {}
data = csv.reader(fileinput.input(mode='r'), delimiter='|')

for row in data:
    asn, org, orgid = row[:3]
    if not 0 < int(asn[2:]) < 4294967295:
        print("error")
        sys.exit(2)
    # attempt to make clean 7 bit data
    org = unicodedata.normalize('NFD', org).encode('ascii', 'ignore')
    org = str(org, 'ascii')
    prefixes = row[3:]
    for prefix in prefixes:
        ip.ip_network(prefix)
    records[asn] = {'org': org, 'orgid': orgid, 'prefixes': prefixes}
pierky commented 6 years ago

WIP - see the dev branch. Tests on BIRD are fine; still need to test it on the OpenBGPD side.