From 81a3df67ea887e6cc6d2ae6c9bcfbfd1bfbb16ee Mon Sep 17 00:00:00 2001 From: Jerry Date: Mon, 11 May 2020 23:40:23 +0800 Subject: [PATCH] roa.py: support rfc8416 --- scripts/roa.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/roa.py b/scripts/roa.py index 7c87e05..f8103fb 100755 --- a/scripts/roa.py +++ b/scripts/roa.py @@ -173,6 +173,7 @@ if __name__ == "__main__": parser.add_argument('-m', '--max', type=int, default=29, help='set ipv4 max prefix length') parser.add_argument('-M', '--max6', type=int, default=64, help='set ipv6 max prefix length') parser.add_argument('-j', '--json', action='store_true', help='output json') + parser.add_argument('-r', '--rfc8416', action='store_true', help='output rfc8416') parser.add_argument('-o', '--output', default='', help='write output to file') parser.add_argument('-4', '--ipv4', action='store_true', help='print ipv4 only') parser.add_argument('-6', '--ipv6', action='store_true', help='print ipv6 only') @@ -235,6 +236,17 @@ if __name__ == "__main__": for r in (*roa4, *roa6): d_output['roas'].append({k:v for k, v in r.items() if k in VALID_KEYS}) output = json.dumps(d_output, indent=2) + elif args.rfc8416: + import json + l_prefix = list() + d_output = {'slurmVersion': 1, 'validationOutputFilters': {'prefixFilters': list(), + 'bgpsecFilters': list()}, 'locallyAddedAssertions': {'bgpsecAssertions': list(), + 'prefixAssertions': l_prefix}} + for r in (*roa4, *roa6): + vkeys = ["netname", "maxLength", *VALID_KEYS] + substk = lambda k: "maxPrefixLength" if k == 'maxLength' else ("comment" if k == "netname" else k) + l_prefix.append({substk(k):v for k, v in r.items() if k in vkeys}) + output = json.dumps(d_output, indent=2) else: output += "# NeoNetwork ROA tool\n" pattern = 'route %s max %d as %d;'