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