#!/bin/sh
#
# 
#
# Version:      0.0.2
#
# chkconfig: 2345 90 10
# description: Starts and stops Network Address Translation for K12Linux/LTS
#
	
PRIVATE_IP_RANGE="192.168.0.0/255.255.255.0"
PUBLIC_ETHERNET="eth1"

# Source function library.
. /etc/init.d/functions

start() {
	echo -n "Starting up Network Address Translation: "

	# permit forwarding of IP packets
	echo 1 > /proc/sys/net/ipv4/ip_forward

	# make sure the ipchains module is loaded
	[ "`/sbin/lsmod | grep ^ipchains`" ] || /sbin/modprobe ipchains

	# masquerade addresses originating from 192.168.0.X
	/sbin/ipchains -A forward -s $PRIVATE_IP_RANGE -d 0.0.0.0/0.0.0.0 -i $PUBLIC_ETHERNET -j MASQ 

	echo
	return 0
}	
stop() {
	echo -n "Stopping Network Address Translation: "
	echo 0 > /proc/sys/net/ipv4/ip_forward
	/sbin/ipchains -D forward -s $PRIVATE_IP_RANGE -d 0.0.0.0/0.0.0.0 -i $PUBLIC_ETHERNET -j MASQ 
	echo
	return 0
}	

restart() {
	    stop
	    start
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|reload)
  	restart
	;;
  *)
	echo "*** Usage: nat {start|stop|restart}"
	exit 1
esac

exit $?
