#! /bin/sh
#
# Copyright (c) 2001-2002 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# /etc/init.d/boot.ipconfig
#
### BEGIN INIT INFO
# Provides:          boot.ipconfig
# Required-Start: 
# Should-Start: setserial boot.isapnp boot.sysctl
# Required-Stop:
# Default-Start:     B
# Default-Stop:
# Description:       run ip configuration hooks
### END INIT INFO

. /etc/rc.status
. /etc/sysconfig/sysctl

rc_reset

case "$1" in
  start|restart)
   #
   # Enable "dynamic IP patch"
   #
   if test -n "$IP_DYNIP" -a "$IP_DYNIP" != no -a \
    -e /proc/sys/net/ipv4/ip_dynaddr ; then
    echo -n "Enabling dynamic IP patch"
    case "$IP_DYNIP" in
	yes)    echo 7         ; ECHO_RETURN=$rc_done ;;
	[1-9])  echo $IP_DYNIP ; ECHO_RETURN=$rc_done ;;
	*)      ECHO_RETURN=" invalid IP_DYNIP=$IP_DYNIP $rc_skipped" ;;
    esac > /proc/sys/net/ipv4/ip_dynaddr || ECHO_RETURN=$rc_failed
    echo -e "$ECHO_RETURN"
   fi

   #
   # Enable syn flood protection
   #
   if test -n "$IP_TCP_SYNCOOKIES" -a "$IP_TCP_SYNCOOKIES" != no -a \
    -e /proc/sys/net/ipv4/tcp_syncookies ; then
    echo -n "Enabling syn flood protection"
    case "$IP_TCP_SYNCOOKIES" in
        yes)    echo 1         ; ECHO_RETURN=$rc_done ;;
        *)      ECHO_RETURN=" invalid IP_TCP_SYNCOOKIES=$IP_TCP_SYNCOOKIES $rc_skipped" ;;
    esac > /proc/sys/net/ipv4/tcp_syncookies || ECHO_RETURN=$rc_failed
    echo -e "$ECHO_RETURN"
   fi


   #
   # Enable IP forwarding ?
   #
   if test -e /proc/sys/net/ipv4/ip_forward -a -n "$IP_FORWARD" ; then
    case $IP_FORWARD in
      yes)
        echo -n "Enabling IP forwarding"
        echo "1" > /proc/sys/net/ipv4/ip_forward
      ;;
      *)
        echo -n "Disabling IP forwarding"
        echo "0" > /proc/sys/net/ipv4/ip_forward
      ;;
    esac
    rc_status -v -r
   fi
   #
   # Enable IPv6 forwarding ?
   #
   LOAD_IPV6="no"
   case $IPV6_FORWARD in
      yes) LOAD_IPV6="yes" ;;
   esac
   case $IPV6_PRIVACY in
      yes) LOAD_IPV6="yes" ;;
   esac
   test -n "$IPV6_MLD_VERSION" && LOAD_IPV6="yes"
   test "$LOAD_IPV6" = "yes" && /sbin/modprobe ipv6 >/dev/null 2>&1
   #
   if test -e /proc/sys/net/ipv6/conf/all/forwarding -a -n "$IPV6_FORWARD" ; then
    case $IPV6_FORWARD in
      yes)
	echo -n "Enabling IPv6 forwarding"
	echo "1" > /proc/sys/net/ipv6/conf/all/forwarding
	;;
      *)
	echo -n "Disabling IPv6 forwarding"
	echo "0" > /proc/sys/net/ipv6/conf/all/forwarding
	;;
    esac
    rc_status -v -r
   fi
    #
    # Enable IPv6 privacy?
    #
    if test -e /proc/sys/net/ipv6/conf/all/use_tempaddr -a -n "$IPV6_PRIVACY"; then
    case $IPV6_PRIVACY in
      yes)
       echo -n "Enabling IPv6 privacy"
       echo "1" > /proc/sys/net/ipv6/conf/all/use_tempaddr
       ;;
      *)
       echo -n "Disabling IPv6 privacy"
       echo "0" > /proc/sys/net/ipv6/conf/all/use_tempaddr
       ;;
    esac
    rc_status -v -r
    fi
    #
    # Set MLD version?
    #
    if test -e /proc/sys/net/ipv6/conf/all/force_mld_version -a -n "$IPV6_MLD_VERSION"; then
	echo -n "Setting MLD version to $IPV6_MLD_VERSION"
	echo "$IPV6_MLD_VERSION" > /proc/sys/net/ipv6/conf/all/force_mld_version
    fi
    rc_status -v -r
   ;;
  stop)
    # skip / nothing to do
    ;;
  status)
    rc_failed 4
    rc_status -v
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart}"
    exit 1
    ;;
esac

rc_exit

