Last active
August 29, 2015 14:22
-
-
Save tcatm/898fa0bfaa1ac0007011 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit ac5f52daf419e0e8383fe860a1215f3a44717f0a (HEAD, refs/heads/master) | |
Author: Nils Schneider <[email protected]> | |
Date: Thu May 28 11:56:05 2015 +0200 | |
mkroa: refactor default_max_prefixlen | |
Rename default_max_prefixlen to min_prefixlen + some refactoring. | |
diff --git a/mkroa b/mkroa | |
index 9f44dc4..ef8948d 100755 | |
--- a/mkroa | |
+++ b/mkroa | |
@@ -38,8 +38,10 @@ class BirdRoaFormatter(Formatter): | |
return "\n".join(self.config) | |
-def create_config(srcdir, exclude, family, | |
- fmtclass, default_max_prefixlen): | |
+def add_roa(formatter, asn, community, network, prefixlen, default_max_prefixlen): | |
+ formatter.add_data(asn, community, network, max(prefixlen, default_max_prefixlen)) | |
+ | |
+def create_config(srcdir, exclude, family, fmtclass, default_max_prefixlen): | |
""" | |
Generates a configuration using all files in srcdir | |
(non-recursively) excluding communities from 'exclude'. | |
@@ -49,6 +51,12 @@ def create_config(srcdir, exclude, family, | |
""" | |
formatter = fmtclass() | |
+ if default_max_prefixlen == None: | |
+ if family == 'ipv6': | |
+ default_max_prefixlen = 64 | |
+ elif family == 'ipv4': | |
+ default_max_prefixlen = 24 | |
+ | |
for community, data in get_communities_data(srcdir, exclude): | |
try: | |
networks = data["networks"][family] | |
@@ -59,11 +67,7 @@ def create_config(srcdir, exclude, family, | |
for network in sorted(networks): | |
prefixlen = int(network.split("/")[1]) | |
- if prefixlen > default_max_prefixlen: | |
- max_prefixlen = prefixlen | |
- else: | |
- max_prefixlen = default_max_prefixlen | |
- formatter.add_data(asn, community, network, max_prefixlen) | |
+ add_roa(formatter, asn, community, network, prefixlen, default_max_prefixlen) | |
for delegate_asn, delegate_networks in delegate.items(): | |
for delegate_network in delegate_networks: | |
@@ -72,8 +76,8 @@ def create_config(srcdir, exclude, family, | |
continue | |
if family == 'ipv4' and ':' in delegate_network: | |
continue | |
- max_prefixlen = max(int(delegate_network.split("/")[1]), default_max_prefixlen) | |
- formatter.add_data(delegate_asn, community, delegate_network, max_prefixlen) | |
+ prefixlen = int(delegate_network.split("/")[1]) | |
+ add_roa(formatter, delegate_asn, community, delegate_network, prefixlen, default_max_prefixlen) | |
print(formatter.finalize()) | |
@@ -103,7 +107,7 @@ if __name__ == "__main__": | |
help="Exclude the comma-separated list of COMMUNITIES", | |
metavar="COMMUNITIES", | |
default=[]) | |
- parser.add_option("-m", "--max", dest="default_max_prefixlen", default=0, | |
+ parser.add_option("-m", "--max", dest="default_max_prefixlen", default=None, | |
type=int, help="max prefix length to accept") | |
parser.set_defaults(family="ipv6") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment