| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Route::Table; |
|
2
|
2
|
|
|
2
|
|
33160
|
use 5.008; |
|
|
2
|
|
|
|
|
9
|
|
|
|
2
|
|
|
|
|
74
|
|
|
3
|
2
|
|
|
2
|
|
16
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
74
|
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
64
|
|
|
5
|
2
|
|
|
2
|
|
1438
|
use version; our ( $VERSION ) = '$Revision: 363 $' =~ m{(\d+)}xms; |
|
|
2
|
|
|
|
|
4528
|
|
|
|
2
|
|
|
|
|
13
|
|
|
6
|
2
|
|
|
2
|
|
2137
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use NetAddr::IP; |
|
8
|
|
|
|
|
|
|
use English qw( -no_match_vars ); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'routes' => ( is => 'ro', reader => 'all_routes' ); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub default_route |
|
13
|
|
|
|
|
|
|
{ |
|
14
|
|
|
|
|
|
|
my ( $self ) = @_; |
|
15
|
|
|
|
|
|
|
foreach my $route_ref ( @{ $self->all_routes() } ) |
|
16
|
|
|
|
|
|
|
{ |
|
17
|
|
|
|
|
|
|
if ( $route_ref->destination->addr eq '0.0.0.0' ) |
|
18
|
|
|
|
|
|
|
{ |
|
19
|
|
|
|
|
|
|
return $route_ref; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
return; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub from_system |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
|
|
|
|
|
|
require "Net/Route/Parser/$OSNAME.pm"; ## no critic (Modules::RequireBareWordIncludes) |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $parser_ref = "Net::Route::Parser::$OSNAME"->new(); |
|
31
|
|
|
|
|
|
|
my @routes = sort _up_routes_by_metric @{ $parser_ref->from_system() }; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
return Net::Route::Table->new( { 'routes' => \@routes } ); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _up_routes_by_metric |
|
37
|
|
|
|
|
|
|
{ |
|
38
|
|
|
|
|
|
|
my $is_up_sort = ( $a->is_active() <=> $b->is_active() ); |
|
39
|
|
|
|
|
|
|
if ( $is_up_sort == 0 ) |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
|
|
|
|
|
|
return ( $a->metric() <=> $b->metric() ); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
else |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
|
|
|
|
|
|
return $is_up_sort; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
no Moose; |
|
50
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
|
51
|
|
|
|
|
|
|
1; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Net::Route::Table - A routing table, such as your system's. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Net::Route::Table; |
|
62
|
|
|
|
|
|
|
$table_ref = Net::Route::Table->from_system(); |
|
63
|
|
|
|
|
|
|
my $default_route_ref = $table_ref->default_route(); |
|
64
|
|
|
|
|
|
|
my $routes_ref = $table_ref->all_routes(); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 VERSION |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Revision $Revision: 363 $. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This class represents a routing table. It can be read from the system and gives |
|
74
|
|
|
|
|
|
|
access to appropriate selections of routes. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 INTERFACE |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 Class Methods |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head3 from_system() |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Returns the system's routing table as a L<Net::Route::Table> object. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 Object Methods |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 default_route() |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns the current default route of the system as a L<Net::Route> object. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 all_routes() |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Returns the complete routing table as an arrayref of L<Net::Route> objects. The |
|
94
|
|
|
|
|
|
|
active routes are listed first, then the results are sorted by increasing |
|
95
|
|
|
|
|
|
|
metric. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Created by Alexandre Storoz, C<< <astoroz@straton-it.fr> >> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Maintained by Thomas Equeter, C<< <tequeter@straton-it.fr> >> |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Copyright (C) 2009 Straton IT. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
110
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
111
|
|
|
|
|
|
|
|