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