Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Aug 1997 18:52:58 +1000 (EST)
From:      "Daniel O'Callaghan" <danny@hilink.com.au>
To:        freebsd-hackers@freebsd.org
Subject:   Re: Grabbing throughput stats within pppd. 
Message-ID:  <Pine.BSF.3.95.970826184541.6297j-100000@skylark.hilink.com.au>

next in thread | raw e-mail | index | archive | help

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






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95.970826184541.6297j-100000>