#!/bin/bash
# The usage of this script is:
# setrate <interface index> <inbound KByte/s rate> <outbound rate>
#
# To find the interface index, use "ipfw pipe show"; the pipes are are
# number 100-109, sequentially based on the unique occurrance of the
# interfaces passed to rc.firewall.
#
# For example, if you passed "en1 en1 en2 en0 en0" (passing different
# networks for each), then their interface indices would be 0 1 2 3 4.
# However, since pipes are not duplicated for the same interface, the
# interface indices available for calling setrate would be 0 2 3.
base=$1
if [[ -n "$2" && -n "$3" ]]; then
/sbin/ipfw -q pipe $((100 + base)) config bw ${2}Kbit/s
/sbin/ipfw -q pipe $((110 + base)) config bw ${3}Kbit/s
echo Set rate: inbound ${2}Kbit/s outbound ${3}Kbit/s
exit 0
fi
rate=$(/sbin/ipfw pipe show $((100 + base)) | head -1 | awk '{print $2}')
case $(cat /var/run/firewall-type) in
Home)
hour=$(($(expr $(date +%H))))
if (( $hour >= 0 && $hour <= 8 )); then
if [[ $rate != "1.450" ]]; then
/sbin/ipfw -q pipe $((100 + base)) config bw 1450Kbit/s
/sbin/ipfw -q pipe $((110 + base)) config bw 950Kbit/s
echo Set rate: inbound 1450Kbit/s outbound 950Kbit/s
fi
else
if [[ $rate != "750.000" ]]; then
/sbin/ipfw -q pipe $((100 + base)) config bw 750Kbit/s
/sbin/ipfw -q pipe $((110 + base)) config bw 500Kbit/s
echo Set rate: inbound 750Kbit/s outbound 500Kbit/s
fi
fi
;;
*)
if [[ $rate != "unlimited" ]]; then
/sbin/ipfw -q pipe $((100 + base)) config bw 0
/sbin/ipfw -q pipe $((110 + base)) config bw 0
echo Set rate: inbound unlimited outbound unlimited
fi
;;
esac