#!/bin/sh
# Begin /etc/rc.d/init.d/network

. /etc/rc.d/init.d/network_functions
. /etc/sysconfig/network

# Could be called by binary, make sure context is right
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib
. /etc/profile
cd /

start_network()
{
  configure_hostname
  start_loopback
  configure_tcp

  if [ "${ETHERNET}" = "yes" ]; then
    if [ -f /etc/rc.d/init.d/ethernet ]; then  
      /etc/rc.d/init.d/ethernet start
    fi
  fi
  if [ "${SLIP}" = "yes" ]; then
    if [ -f /etc/rc.d/init.d/slip ]; then  
      /etc/rc.d/init.d/slip start  >/dev/null 2>&1 &
    fi
  fi
  if [ "${ROUTER}" = "yes" ]; then
    if [ -f /etc/rc.d/init.d/router ]; then  
      /etc/rc.d/init.d/router start
    fi
  fi
  if [ "${FIREWALL}" = "yes" ]; then
    if [ -x /etc/rc.d/init.d/firewall ]; then
      /etc/rc.d/init.d/firewall start
    fi
  fi
}

stop_network()
{
  # stop_loopback
  if [ "${ETHERNET}" = "yes" ]; then
    if [ -f /etc/rc.d/init.d/ethernet ]; then  
      /etc/rc.d/init.d/ethernet stop
    else
      echo "/etc/rc.d/init.d/ethernet no such file"
    fi
  fi
  if [ "${SLIP}" = "yes" ]; then
    if [ -f /etc/rc.d/init.d/slip ]; then  
      /etc/rc.d/init.d/slip stop
    else
      echo "/etc/rc.d/init.d/slip no such file"
    fi
  fi
  if [ "${ROUTER}" = "yes" ]; then
    if [ -f /etc/rc.d/init.d/router ]; then  
      /etc/rc.d/init.d/router stop
    else
      echo "/etc/rc.d/init.d/router no such file"
    fi
  fi

  # Flush rules in all cases
  if [ -x /etc/rc.d/init.d/firewall ]; then
    /etc/rc.d/init.d/firewall stop
  fi

}


case "$1" in
  start)
    start_network
    ;;

  stop)
    stop_network
    ;;

  restart)
    stop_network
    start_network
    ;;

  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    ;;
esac

# End /etc/rc.d/init.d/network
