From 469e60d6192944715eb0f749920c983bca3649be Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 9 Jun 2019 15:25:08 +0200 Subject: [PATCH] Implement logic to write network filter functions --- generate.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/generate.py b/generate.py index eb9a4dd..57d85cc 100755 --- a/generate.py +++ b/generate.py @@ -138,6 +138,19 @@ def create_roa_entries(route_objects, filter_rules, mode, f): elif mode == 'ipv6': f.write('route ' + route_object['route6'] + ' max ' + str(allowed_max_len) + ' as ' + origin + ';' + "\n") +def create_valid_network_function(filter_rules, mode, f): + f.write('function dn42_is_valid_' + mode + '_network() {\n') + f.write(' return net ~ [\n') + first_line_written = False + for id, filter_rule in filter_rules.items(): + if filter_rule['route_allowed']: + if first_line_written: + f.write(',\n') + f.write(' ' + filter_rule['network'] + '{' + str(filter_rule['min_length']) + ',' + str(filter_rule['max_length']) + '}') + if not first_line_written: + first_line_written = True + f.write('\n ];\n') + f.write('}\n') if __name__ == '__main__': # Get registry path over commandline argument @@ -154,8 +167,14 @@ if __name__ == '__main__': ipv4_route_objects = parse_route_objects(registry_path + '/data/route/') ipv6_route_objects = parse_route_objects(registry_path + '/data/route6/') # Create routes out of ipv4 route objects - with open('./roa_ipv4.conf', 'w') as target_file: + with open('./dn42_roa_ipv4.conf', 'w') as target_file: create_roa_entries(ipv4_route_objects, ipv4_filter_rules, 'ipv4', target_file) # Create routes out of ipv6 route objects - with open('./roa_ipv6.conf', 'w') as target_file: + with open('./dn42_roa_ipv6.conf', 'w') as target_file: create_roa_entries(ipv6_route_objects, ipv6_filter_rules, 'ipv6', target_file) + # Create ipv4 network validation function + with open('./dn42_valid_ipv4.conf', 'w') as target_file: + create_valid_network_function(ipv4_filter_rules, 'ipv4', target_file) + # Create ipv6 network validation function + with open('./dn42_valid_ipv6.conf', 'w') as target_file: + create_valid_network_function(ipv6_filter_rules, 'ipv6', target_file)