#!/bin/sh
# 
# (C) 2004 Joerg Dorchain <joerg@dorchain.net>
#
# implements dhcp custom routes via a custom option
#
# in dhclient.conf have a line like
# option static-routes-subnet code 201 = array of { ip-address, ip-address, ip-address, integer 8 };
# and request that option from a the server (of course, the
# servers needs to be setup accordingly)
#
# Then place this script into /etc/dhcp/dhclient-exit-hooks.d/

loop_route_args() {
local action=$1;shift
while [ -n "$*" ]; do
	route $action -net $1 netmask $2 gw $3 metric $4;
	shift 4;
done
}

case "$reason" in
	MEDIUM|PREINIT)
	# nor for us
	return;
	;;
	BOUND|RENEW|REBIND|REBOOT|EXPIRE|FAIL|TIMEOUT)
	if [ "$old_static_routes_subnet" != "$new_static_routes_subnet" ]; then
	   loop_route_args del $old_static_routes_subnet
	   loop_route_args add $new_static_routes_subnet
	fi
	;;
	*)
	# unknown reason
	return;
	;;
esac;
