#!/bin/sh
# $Id: ifmetric.sh,v 1.5 2006/05/27 15:37:12 eha Exp eha $
# =============================================================================
# 
# Slackware script for customized setup of network interfaces.
# Parameters:
# $1  : interface name
# $2  : <pre|post|stop>
#
# If the script ends with 'RETURN=1', then rc.inet1 will omit further
# processing of the if_up / if_down function for this interface.
# You can use that for instance if you want total control over your interface
# configuration; put all your functionality in the pre() function and let that
# end with a "RETURN=1".
#
# =============================================================================
# 
# This is an example script for using ifmetric to change the interface metric
# of (for example) a wireless interface.
# When the computer has multiple interfaces, we want the fastest interface to
# route all the traffic. In most cases, a wireless interface will have lower
# bps than a wired interface.
# Set the metric to a value higher than zero, and any other existing (wired)
# interface with lower metric (the default is 0) will be favoured in routing
# network packets.  
#
# A package for ifmetric is available at
# http://www.slackware.com/~alien/slackbuilds/ifmetric/
#
# Eric Hameleers <alien@slackware.com>
#
# =============================================================================
# 

INTERFACE=$1
ACTION=$2
RETURN=${RETURN:-0}
IFMETRIC=${IFMETRIC[$i]:-5}

pre() {
  # Nothing to do here
  return
}

post() {
  [ -x /usr/sbin/ifmetric ] && /usr/sbin/ifmetric ${INTERFACE} ${IFMETRIC}
}

stop() {
  # Nothing to do here
  return
}

case "$ACTION" in
'pre')
  pre
  ;;
'post')
  post
  ;;
'stop')
  stop
  ;;
*)
  echo "usage $0 <INTERFACE> <pre|post|stop>"
esac

# This script must NEVER call 'exit' !
# It can end with 'return' so that the calling script rc.inet1 will stop further
# processing of the parent function (if_up or if_down).
# To end the script with 'return' you should set RETURN=1 in one of the
# "pre|post|stop" functions, where ever you deem it appropriate.

