line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Device::Network::ConfigParser::Linux::iproute2; |
2
|
|
|
|
|
|
|
# ABSTRACT: Parse output from utilities associated with the iproute2 package |
3
|
|
|
|
|
|
|
our $VERSION = '0.006'; # VERSION |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1227
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
8
|
1
|
|
|
1
|
|
247
|
use Modern::Perl; |
|
1
|
|
|
|
|
6535
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
905
|
use Parse::RecDescent; |
|
1
|
|
|
|
|
25014
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
542
|
use Data::Dumper; |
|
1
|
|
|
|
|
5078
|
|
|
1
|
|
|
|
|
66
|
|
11
|
1
|
|
|
1
|
|
348
|
use JSON; |
|
1
|
|
|
|
|
5716
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
127
|
use Exporter qw{import}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
170
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw{get_parser get_output_drivers parse_config post_process}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Device::Network::ConfigParser::Linux::iproute2 - parse output from utilities associated with the iproute2 package. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 VERSION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
version 0.006 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This module is intended to be used in conjunction with L, however there's nothing stopping it being used on its own. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SUBROUTINES |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 get_parser |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
For more information on the subroutine, see L. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Thos module currently recognised the following output: |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=over 4 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item * 'ip route' output |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=back |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub get_parser { |
46
|
1
|
|
|
1
|
1
|
532
|
return new Parse::RecDescent(q{ |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
startrule: config_line(s) { $item[1] } |
49
|
|
|
|
|
|
|
config_line: ip_route(s) { { ip_route => $item{'ip_route(s)'} } } | |
50
|
|
|
|
|
|
|
not_parsed { $item[1] } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
ip_route: destination nexthop_ip(?) device proto(?) scope(?) source(?) metric(?) { |
53
|
|
|
|
|
|
|
{ |
54
|
|
|
|
|
|
|
destination => $item{destination}, |
55
|
|
|
|
|
|
|
next_hop => $item{'nexthop_ip(?)'}, |
56
|
|
|
|
|
|
|
device => $item{device}, |
57
|
|
|
|
|
|
|
proto => $item{proto}, |
58
|
|
|
|
|
|
|
scope => $item{'scope(?)'}, |
59
|
|
|
|
|
|
|
source => $item{'source(?)'}, |
60
|
|
|
|
|
|
|
metric => $item{'metric(?))'} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
destination: ipv4 cidr { { network => $item{ipv4}, cidr => $item{cidr} } } | 'default' { { network => '0.0.0.0', cidr => '0' } } |
65
|
|
|
|
|
|
|
nexthop_ip: 'via' ipv4 { $item{ipv4} } |
66
|
|
|
|
|
|
|
device: 'dev' m{[-\w]+} { $item{__PATTERN1__} } |
67
|
|
|
|
|
|
|
proto: 'proto' m{\w+} { $item{__PATTERN1__} } |
68
|
|
|
|
|
|
|
scope: 'scope' m{\w+} { $item{__PATTERN1__} } |
69
|
|
|
|
|
|
|
source: 'src' ipv4 { $item{ipv4} } |
70
|
|
|
|
|
|
|
metric: 'metric' m{\d+} { $item{__PATTERN1__} } |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
not_parsed: m{\N+} { { type => $item{__RULE__}, line => $item{__PATTERN1__} } } |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
ipv4: m{\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}} { $item{__PATTERN1__} } |
75
|
|
|
|
|
|
|
netmask: m{\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}} { $item{__PATTERN1__} } |
76
|
|
|
|
|
|
|
ipv6: m{[0-9a-f:]+} { $item{__PATTERN1__} } |
77
|
|
|
|
|
|
|
cidr: '/' m{\d{1,2}} { $item{__PATTERN1__} } |
78
|
|
|
|
|
|
|
}); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 parse_config |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
For more information on the subroutine, see L. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub parse_config { |
89
|
0
|
|
|
0
|
1
|
|
my ($parser, $config_contents) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $parse_tree = $parser->startrule($config_contents); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $parse_tree; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 post_process |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
For more information on the subroutine, see L. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This module does not post-process the data structure. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub post_process { |
107
|
0
|
|
|
0
|
1
|
|
my ($parsed_config) = @_; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $parsed_config; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 get_output_drivers |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
For more information on the subroutine, see L. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This module does not export any output drivers. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub get_output_drivers { |
122
|
|
|
|
|
|
|
return { |
123
|
0
|
|
|
0
|
1
|
|
}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Greg Foletta, C<< >> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 BUGS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
133
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
134
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SUPPORT |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
perldoc Device::CheckPoint::ConfigParse |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
You can also look for information at: |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=over 4 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * CPAN Ratings |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * Search CPAN |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright 2017 Greg Foletta. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
177
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
178
|
|
|
|
|
|
|
copy of the full license at: |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
183
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
184
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
185
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
188
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
189
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
192
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
195
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
196
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
197
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
198
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
199
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
200
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
201
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
204
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
205
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
206
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
207
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
208
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
209
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
210
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
1; # End of Device::CheckPoint::ConfigParse |