#!/bin/bash
#
# Copyright (c) 2013 by Delphix.
# All rights reserved.
#

. /lib/svc/share/smf_include.sh

typeset -r NDDCMD=/usr/sbin/ndd
typeset -r \
TUNEABLES=("tcp_max_buf:4194304" "tcp_cwnd_max:4194304" "tcp_xmit_hiwat:4194304" "tcp_recv_hiwat:4194304")


#if [[ -z "$SMF_FMRI" ]]; then
#        echo "this script can only be invoked by smf(5)"
#        exit $SMF_EXIT_ERR_NOSMF
#fi

case "$1" in
start)
	echo "Tuning TCP Network Parameters"
	for i in ${!TUNEABLES[*]};do
		TUNEPROP=${TUNEABLES[$i]%%:*}
		TUNEVAL=${TUNEABLES[$i]##*:}
		OLDVAL=$(${NDDCMD} -get /dev/tcp ${TUNEPROP})
		${NDDCMD} -set /dev/tcp $TUNEPROP $TUNEVAL
		if [ "$?" -eq "0" ];then
			echo "${TUNEPROP} adjusted from ${OLDVAL} to ${TUNEVAL}"
		else
			echo "change of ${TUNEPROP} failed"
		fi
	done
	exit $SMF_EXIT_OK
        ;;

refresh)
        #
        # Check the IP filter debug settings
        #
        ;;

stop)
        ;;

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