#!/bin/sh
#
# Start the network....
#

ifname=eth0

wait_linkup() {
    echo -n "waiting eth0 link up "
    for i in `/usr/bin/seq 1 300`
    do
		if [ -e /sys/class/net/$ifname/carrier ];then
			cat /sys/class/net/$ifname/carrier | grep 1
			if [ $? == 0 ] ; then
				break
			fi
		fi
		/sbin/ip link set eth0 up
		usleep 100000
    done
}

case "$1" in
  start)
 	echo "Starting network..."
	/sbin/ifup -a
	wait_linkup

	# txqueuelen (default:1000)
#	ifconfig eth0 txqueuelen 2000

	# rx-checksumming (default:on), tx-checksumming (default:on), generic-receive-offload (default:on)
	ethtool -K eth0 tx off rx off gso off gro off

	# Set coalesce options
#	ethtool -C eth0 rx-usecs 0 tx-frames 1

	# 100Mb/s Full Duplex
	grep "100M" /proc/cmdline >/dev/null 2>&1
	if [ $? -eq 0 ]; then
		ethtool -s eth0 speed 100 duplex full
	fi
	;;
  stop)
	echo -n "Stopping network..."
	/sbin/ifdown -a
	;;
  restart|reload)
	"$0" stop
	"$0" start
	;;
  *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?
