Date: Tue, 07 Nov 2000 14:21:02 +1300 From: Andrew Walters X-Mailer: Mozilla 4.6 [en] (X11; I; Linux 2.2.16 i686) To: Michele Andreoli Subject: Re: (slightly) improved diald Michele Andreoli wrote: > > On Sun, Nov 05, 2000 at 03:44:50PM +1300, Andrew Walters nicely wrote: --snip-- > > I've tweaked the mu-diald script so that it does not drop links when DNS > > is not used for a while while other traffic (ie a large HTTP download) > > is. --snip-- > Fine! A very good idea. --snip > I will add, thank you and also will put a reference to your name. Thanks - this will be my first ever contribution to a Linux distribution! Cool! :) I've tidied the script up a bit and added an option - $LISTENPORTS for custom port numbers to listen to. For this to work, you'll have to add a question to your diald setup script asking what ports (besides http ftp smtp pop3 imap4) to listen for (like irc, nntp, etc). Thanks for the oppourtunity to do this Andrew --------------59809A96A9567875AB3A3D29 Content-Type: text/plain; charset=us-ascii; name="mu-diald" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mu-diald" #!/bin/ash # an hyper-rustic diald for muLinux # (C) 1999 by M. Andreoli # [hack: IP accounting (outgoing) on port 53 (dns) - udp] # Modified by Andrew Walters # [hack: IP accounting (outgoing) on standard traffic ports 80,21,25,110,143 - # tcp while connected] #set -x if [ -r /etc/diald.conf ] ; then . /etc/diald.conf else # testing value NAMESERVER=195.223.180.8 NETWORK=192.168.1.0 ACOUSTIC_LOG=TRUE SLEEP_TIME=1 IDLE_LIMIT=30 TEST_COMMAND="cat /tmp/started" START_COMMAND="echo start > /tmp/started" STOP_COMMAND=": > /tmp/started" > /tmp/started fi # parse options case $1 in -t) verbose=yes ;; -h) echo "Usage: diald [-t|-h]" exit ;; esac # functions LOG() { [ "$verbose" ] && echo $@ } acoustic_log() { [ "$ACOUSTIC_LOG" = FALSE ] && return case $1 in incoming) LOG DNS request incoming # wave -c 40 2 ;; started) LOG service started wave -c 110 1 wave -c 220 2 ;; stopped) LOG service stopped wave -c 40 6 ;; esac } # set IP accounting policy LOG IP accounting setup: DNS $NAMESERVER ipfwadm -A -f ipfwadm -A in -i -P udp -S $NETWORK/24 -D $NAMESERVER 53 [ "$verbose" ] && ipfwadm -l -A -n # main loop idle=0 prev=0 LOG starting main loop ... while [ 1 ] do set -- `cat /proc/net/ip_acct` shift 7; acc=$4 if [ "$acc" -gt "$prev" ] ; then idle=0 acoustic_log incoming prev=$acc conn="`eval ${TEST_COMMAND}`" if [ -z "$conn" ] ; then LOG starting service ... eval $START_COMMAND # wait for OK while [ -z "`eval ${TEST_COMMAND}`" ] ; do sleep 1 done # now monitor for HTTP traffic instead LOG Now monitoring standard TCP traffic (HTTP, FTP, SMTP, POP3, IMAP4, $LISTENPORTS ipfwadm -A -f ipfwadm -A in -i -P tcp -S $NETWORK/24 -D 0.0.0.0/0 80 21 25 110 149 $LISTENPORTS [ "$verbose" ] && ipfwadm -l -A -n acoustic_log started fi else if [ "`eval $TEST_COMMAND`" ] ; then LOG idle=$idle idle=`expr $idle + 1` fi fi # check idle time if [ "$idle" -gt "$IDLE_LIMIT" ] ; then eval $STOP_COMMAND LOG IDLE_LIMIT reached! acoustic_log service stopped ipfwadm -A -f LOG Now monitoring DNS traffic ipfwadm -A in -i -P udp -S $NETWORK/24 -D $NAMESERVER 53 [ "$verbose" ] && ipfwadm -l -A -n idle=0 prev=0 fi sleep $SLEEP_TIME done # end --------------59809A96A9567875AB3A3D29--