4 # Copyright (C) 2009 Universita` di Pisa
7 # This script is the frontend to be used with
9 # It allows to configure dummynet pipes and queues.
12 # - send command to the vsys input pipe
14 # - get the reply from the output vsys pipe
15 # - show the output to the user
18 # ./netconfig -p 9898 <dummynet configuration parameters>
19 # mandatory fields are the port to be configured
20 # and dummynet configuration parameters
22 PIPE_IN=/vsys/ipfw-be.in
23 PIPE_OUT=/vsys/ipfw-be.out
24 LOGFILE=/tmp/netconfig.log
26 SED=/bin/sed # used to extract the profile name
27 DEBUG=0 # 0 disable debug messages
28 prog=$0 # this program
30 # Print the first argument and exit
36 # if $DEBUG is enabled, print a debug message
37 # $1 the message to print
40 [ "${DEBUG}" != "0" ] && echo "$1" >> ${LOGFILE}
43 # print the usage and exit
47 Usage: $prog -p port [-U] [-t timeout[STRING]] ipfw_configuration_parameters \n
52 -p specify the port to configure \n
53 -d delete specified rules and pipes \n
54 -t specify the timeout. STRING can be "1minute" or "4hours" (default 1 hour) \n
56 ipfw configuration parameters (mandatory) \n
57 extra-delay <filename> bw <value> delay <value> proto... plr... \n
59 ipfw show show the ipfw ruleset
60 ipfw pipe show the configured pipes
65 # parse input line and fill missing fields
68 # counters used to check if at least
69 # two ipfw configuration parameters are present
70 local OPT_ARGS=2 # optional (timeout)
71 local MAND_ARGS=2 # mandatory (port)
75 while getopts ":hdp:t:" opt; do
84 # check for mandatory arguments
85 [ -z ${PORT} ] && abort "a port value is mandatory";
87 # the default value for the timeout is 1H
88 if [ -z ${TIMEOUT} ]; then
90 OPT_ARGS=$((${OPT_ARGS}-2))
93 # check for deletion flag
94 if [ -z ${DELETE} ]; then
97 # if d is present configuration is not required
98 MAND_ARGS=$((${MAND_ARGS}-2))
101 # compute residue argument, we need at least 2
102 # mandatory arguments (for ipfw), exit on error
103 # debug "Passed args $# Mandatory ${MAND_ARGS} Optional ${OPT_ARGS} Extra $(($#-${MAND_ARGS}-${OPT_ARGS}))"
104 if [ $(($#-${MAND_ARGS}-${OPT_ARGS})) -lt 2 ]; then
109 # the backend expects lines in the format:
112 # port timeout configuration_string
115 # allow ipfw show and ipfw pipe show commands
116 if [ x$1 = x"ipfw" ]; then
118 echo "ipfw" >> ${PIPE_IN}
121 else if [ x$1 = x"pipe" ]; then
122 echo "pipe" >> ${PIPE_IN}
130 shift $((${OPTIND}-1));
134 debug "DELETE ${DELETE}"
135 debug "TIMEOUT ${TIMEOUT}"
136 debug "PIPE_CONFIGURATION $*"
138 # format CMD as expected by the backend script
139 CMD="${PORT} ${TIMEOUT} ${DELETE} $*";
142 debug "Sending: ${CMD}"
143 echo ${CMD} >> ${PIPE_IN}