#!/bin/sh
# LEG19032005
# /etc/network/bogons
#
# List of bogon prefixes to block from routing

IP=ip
#IP=echo

# to activate bogon blogging add:
#
# up   IFACE=bogon rtconfig
# down IFACE=bogon rtconfig
#
# to the first or second interface in interfaces(5)

# Reference http://www.cymru.com/Bogons/
# Obtain: wget http://www.cymru.com/Documents/bogon-bn-agg.txt
#
BOGONS=/etc/network/bogon-bn-agg.txt

function rt_bogon () {
    if [ ! -r $BOGONS ]; then
	echo bogons:error:$BOGONS not found
	exit 1
    fi
    cat $BOGONS |\
    while read; do 
	$IP route $1 prohibit $REPLY
    done
}

# create /etc/networks from /etc/networks.local and
# wget -c http://www.cymru.com/Documents/bogon-bn-nonagg.txt
#
# Note: this is not satisfactory, route does not resolve prefixes
#       nicely 
#
BOGONS=/etc/network/bogon-bn-nonagg.txt
function update_networks () {
    if [ ! -r $BOGONS ]; then
	echo bogons:error:$BOGONS not found
	exit 1
    fi

    cat /etc/networks.local
    cat $BOGONS |\
    while read; do
        echo bogon $REPLY
    done \
	| sed 's/\(\.0\)\+\/.\+$//'


}

if [ "$0" == "update-networks" ]; then
    update_networks > /etc/networks
fi
