1#!/usr/pkg/bin/perl 2# 3# $FreeBSD: src/usr.sbin/route6d/misc/chkrt,v 1.1 1999/12/28 02:37:10 shin Exp $ 4# $DragonFly: src/usr.sbin/route6d/misc/chkrt,v 1.2 2003/06/17 04:30:02 dillon Exp $ 5# 6$dump="/var/tmp/route6d_dump"; 7$pidfile="/var/run/route6d.pid"; 8 9system("rm -f $dump"); 10 11open(FD, "< $pidfile") || die "Can not open $pidfile"; 12$_ = <FD>; 13chop; 14close(FD); 15system("kill -INT $_"); 16 17open(NS, "/usr/local/v6/bin/netstat -r -n|") || die "Can not open netstat"; 18while (<NS>) { 19 chop; 20 next unless (/^3f/ || /^5f/); 21 @f = split(/\s+/); 22 $gw{$f[0]} = $f[1]; 23 $int{$f[0]} = $f[3]; 24} 25close(NS); 26 27$err=0; 28sleep(2); 29open(FD, "< $dump") || die "Can not open $dump"; 30while (<FD>) { 31 chop; 32 next unless (/^ 3f/ || /^ 5f/); 33 @f = split(/\s+/); 34 $dst = $f[1]; 35 $f[2] =~ /if\(\d:([a-z0-9]+)\)/; 36 $intf = $1; 37 $f[3] =~ /gw\(([a-z0-9:]+)\)/; 38 $gateway = $1; 39 $f[4] =~ /\[(\d+)\]/; 40 $metric = $1; 41 $f[5] =~ /age\((\d+)\)/; 42 $age = $1; 43 unless (defined($gw{$dst})) { 44 print "NOT FOUND: $dst $intf $gateway $metric $age\n"; 45 $err++; 46 next; 47 } 48 if ($gw{$dst} ne $gateway && $gw{$dst} !~ /link#\d+/) { 49 print "WRONG GW: $dst $intf $gateway $metric $age\n"; 50 print "kernel gw: $gw{$dst}\n"; 51 $err++; 52 next; 53 } 54 if ($int{$dst} ne $intf) { 55 print "WRONG IF: $dst $intf $gateway $metric $age\n"; 56 print "kernel if: $int{$dst}\n"; 57 $err++; 58 next; 59 } 60} 61close(FD); 62 63if ($err == 0) { 64 print "No error found\n"; 65} 66