#!/bin/bash

BADIPS=${1:?}  # badips.config file
OUTDIR=${2:-.}

# https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xhtml
#   - 35 reserved /8's: 0 10 127 224-255
#   - UK Ministry of Defence: 25/8
#   - Amateur Radio: 44.0.0.0/9, 44.128.0.0/10
#   - US Postal Service: 56/8

# 2019-04-08: decided to unblock DoD prefixes
#   - US Department of Defense: 6, 11, 21, 22, 26, 28, 29, 30, 33, 55, 214, 215

awk '{print $1 "/" $2}' "$BADIPS" \
    | aggregate -q -t > "$OUTDIR/badips.prefixes.aggr"

# TODO why aren't these in the badips.config file?
for i in "0.0.0.0/8" "10.0.0.0/8" "25.0.0.0/8" "44.0.0.0/9" "44.128.0.0/10" "56.0.0.0/8" "127.0.0.0/8" "224.0.0.0/3"; do
    echo $i >> $OUTDIR/badips.prefixes.aggr
done
