#! /bin/sh

#./etc/rc.config

PROG="/sbin/ipchains"
WORLD_DEV="ppp0"
MODULES="ip_masq_autofw ip_masq_cuseeme ip_masq_ftp ip_masq_irc ip_masq_mfw \
ip_masq_portfw ip_masq_quake ip_masq_raudio ip_masq_user ip_masq_vdolive"

LOADED_MODULES=$(lsmod|grep ip_masq|cut -d " " -f1)

return=$rc_done

if [ ! -x $PROG ]
then
echo -n "Start masquerading failed- install ipchains"
return=$rc_failed
echo -e "$return"
exit 1
fi

case "$1" in
start)
echo -n "Starting masquerading"
echo "1" > /proc/sys/net/ipv4/ip_forward

$PROG -F || return=$rc_failed
$PROG -A forward -i $WORLD_DEV -j MASQ || return=$rc_failed

for i in $MODULES;do
insmod $i >/dev/null 2>&1 || return=$rc_failed;
done

echo -e "$return"
;;

stop)
echo -n "Shutting down masquerading"

$PROG -F || return=$rc_failed

test "$IP_FORWARD" = no && echo "0" > /proc/sys/net/ipv4/ip_forward

for i in $LOADED_MODULES;do
rmmod $i >/dev/null 2>&1 || return=$rc_failed;
done

echo -e "$return"
;;

*)

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

test "$return" = "$rc_done" || exit 1

exit 0



