From owner-freebsd-hackers Tue Aug 26 01:53:06 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id BAA14790 for hackers-outgoing; Tue, 26 Aug 1997 01:53:06 -0700 (PDT) Received: from skylark.hilink.com.au (skylark.hilink.com.au [203.29.224.17]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id BAA14774 for ; Tue, 26 Aug 1997 01:53:03 -0700 (PDT) Received: from localhost (danny@localhost) by skylark.hilink.com.au (8.8.5/8.8.5) with SMTP id SAA21835 for ; Tue, 26 Aug 1997 18:52:59 +1000 (EST) Date: Tue, 26 Aug 1997 18:52:58 +1000 (EST) From: "Daniel O'Callaghan" To: freebsd-hackers@freebsd.org Subject: Re: Grabbing throughput stats within pppd. Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk On Tue, 26 Aug 1997, Adrian Chadd wrote: > For the pppd-clued people, is there a way I can grab the IP bytecount in and > out on the ppp interface? I'd much prefer a bytecount in and out on the > IP packets, if thats possible.. but if I have to resort to just bytecounts > on the interface, that will have to do. Use ipfw accounting. I'll attach some scripts which do ip-up/ip-down stuff on a per-user basis to help. The scripts below were whipped up for a friend, so they are not as polished at you might want :-) Danny #!/usr/bin/perl # # This is /etc/ppp/ip-up # # Argument format is: # iface dev speed localip remoteip unshift(@INC, "/usr/share/perl"); require "utmp.ph"; $iface = $ARGV[0]; $device = $ARGV[1]; $device =~ s#/dev/##; $recordsize = &UT_NAMESIZE + &UT_LINESIZE + &UT_HOSTSIZE + 4; $TEMPLATE = "A".&UT_NAMESIZE." A".&UT_LINESIZE." A".&UT_HOSTSIZE."L"; # calculate the rule number and destroy the rule in case it already # exists - we don't want duplicates. # The rule startpoint is unique for the interface, and there are # 10 available rules per interface. Could make it 100 per interface. $rule = $iface; $rule =~ s/sl|ppp//; if ($iface =~ /sl/ ){ $rule = ($rule+100)*10; } else { $rule = ($rule+200)*10; } system("/sbin/ipfw -q del $rule"); open(U, &_PATH_UTMP); while(read(U, $record, $recordsize) ) { ($ut_line, $ut_name, $ut_host, $ut_time) = unpack($TEMPLATE, $record); if( $ut_line eq $device ) { # # $iface.rules is run by /etc/ppp/ip-down to do the userstats # open(U, ">/var/run/$iface.rules"); ($uname, $passwd, $uid, $gid)=getpwnam($ut_name); print U "#!/bin/sh\n"; print U "/sbin/ipfw show | grep $iface\$ >> /var/account/$uname\n"; system("/sbin/ipfw -q add $rule accept tcp from any to any 80 in via $iface"); print U "/sbin/ipfw -q del $rule\n"; $rule++; system("/sbin/ipfw -q add $rule accept tcp from any to any 80 out via $iface"); print U "/sbin/ipfw -q del $rule\n"; $rule++; system("/sbin/ipfw -q add $rule accept ip from any to any in via $iface"); print U "/sbin/ipfw -q del $rule\n"; $rule++; system("/sbin/ipfw -q add $rule accept ip from any to any out via $iface"); print U "/sbin/ipfw -q del $rule\n"; exit(0); } } ------------------------------------- #!/bin/sh # # This is /etc/ppp/ip-down - very complex! # f=/var/run/$1.rules if [ -f $f ]; then sh $f rm $f fi