1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- require 'psych'
- require 'ipaddr'
- prefixes = []
- exl = ["schema.json"]
- Dir['/var/lib/bird/crxn/entitydb/*.json'].each do |entity_file|
- if ! exl.include? File.basename(entity_file)
- entity_json = File.read entity_file
- entity = Psych.safe_load entity_json
- entity_prefixes = entity['route']
- final_prefixes = []
- # avoid injection of code
- entity_prefixes.each_pair do |prefix, value|
- ip = IPAddr.new prefix
- maxlen = "64";
- if value['max-len']
- maxlen = value['max-len'].to_i.to_s
- end
- if ip.ipv6? && ip.private?
- final_prefixes << "#{ip}/#{ip.prefix}{#{ip.prefix},#{maxlen}}"
- else
- puts "Found illeagl ip #{ip.inspect}"
- end
- end
- prefixes.push(*final_prefixes)
- end
- rescue
- puts "Generic error: #{$!}"
- end
- conf_file = File.new '/var/lib/bird/crxn/crxn_ips.conf', 'w'
- conf_file.puts 'define CRXN_IPs = ['
- conf_file.puts "\t#{prefixes.join(",\n\t")}"
- conf_file.puts '];'
- conf_file.close
|