#!/bin/sh -
#
# Clone routing table SRC into routing table DST
#
# Rick van der Zwet <rick@wirelessleiden.nl>
#
SRC=${1:-0}
DST=${2:-1}

# Flush all routes and make sure to re-apply gateway (if existed)
gateway=`setfib $DST route -n get default  | route -n get default | awk '/gateway:/ {print $2}'`
setfib $DST route -qn flush
[ -n "$gateway" ] && setfib $DST route -qn add default $gateway

# Hack to sync remaining dynamic routes
setfib $SRC netstat -nr -f inet | grep -v 'default' | awk '/UGD/ {print $1" "$2}' | while read tgt gw; do
  setfib $DST route -qn add $tgt $gw
done



