]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - usr.sbin/route6d/misc/chkrt
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / usr.sbin / route6d / misc / chkrt
1 #!/usr/bin/perl
2 #
3 # $FreeBSD$
4 #
5 $dump="/var/tmp/route6d_dump";
6 $pidfile="/var/run/route6d.pid";
7
8 system("rm -f $dump");
9
10 open(FD, "< $pidfile") || die "Can not open $pidfile";
11 $_ = <FD>;
12 chop;
13 close(FD);
14 system("kill -INT $_");
15
16 open(NS, "/usr/bin/netstat -r -n|") || die "Can not open netstat";
17 while (<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 }
24 close(NS);
25
26 $err=0;
27 sleep(2);
28 open(FD, "< $dump") || die "Can not open $dump";
29 while (<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 }
60 close(FD);
61
62 if ($err == 0) {
63         print "No error found\n";
64 }