#----------------------------------------------------------------------------
# /etc/rc.d/rc320.route - configuration of additional routes
# was file /etc/rc.d/route
#
# Creation:     02.01.2001 fm
# Last Update:  $Id: rc320.route 9625 2005-08-25 21:16:46Z jw5 $
#----------------------------------------------------------------------------

if [ 0"$IP_ROUTE_N" -gt 0 ]
then
  begin_script ROUTE "setting up additional routes ..."
 
  dgw=
  ddev=
  for idx in `seq 1 $IP_ROUTE_N`
  do
    eval route='$IP_ROUTE_'$idx
    set $route
    net=$1
    gw=$2
    case $gw in
      @*) 
	translate_ip_net $gw
	if is_error
	then
	    log_error "can't extract ip address from IP_ROUTE_${idx}='$route'"
	    continue
	fi
	gw=$res
	;;
    esac

    if ! netcalc isip $gw
    then
      dev=$3
    else
      gw=
      dev=$2
    fi
    if [ "$net" = "0.0.0.0/0" ]
    then
      dgw=$gw
      ddev=$dev
    else
      network=`netcalc network $net`
      netmask=`netcalc netmask $net`
      [ "$dev" ] && dev="dev $dev"
      [ "$gw" ] && gw="gw $gw"
      if ! route add -net $network netmask $netmask $gw $dev > /tmp/route.$$ 2>&1
      then
	log_error "Error setting route: route add -net $network netmask $netmask $gw $dev"
	log_error < /tmp/route.$$
      fi
    fi
  done
  rm -f /tmp/route.$$

  end_script
fi

if [ "$dgw" -o "$ddev" ]
then
  begin_script IP_DEFAULT_GATEWAY "setting up default gateyway ..."
  [ "$dev" ] && dev="dev $ddev"
  [ "$gw" ] && gw="gw $dgw"
  route add default $gw $dev
  ip_up_events=no
  end_script
fi
