lib/Rex/Hardware/Network/Solaris.pm

filter: Statementstmt 11.5% 16 / 139 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 50.0% 5 / 10 Podpod 0.0% 0 / 5 totaltotal 9.4% 21 / 223 CC 31 SCAR 50.4
CC
31
Cov
8%
netstat
306.0
default_gateway
72.0
route
56.0
CRAP 154.7
« lib/Rex/Commands/Cron.pm ↑ Summary lib/Rex/Box/VBox.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Hardware::Network::Solaris;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Helper::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub get_network_devices {
Subroutine get_network_devices: not called CC=1 SCAR=6.9
Pod undocumented
17  
18 0 my @device_list = map { /^([a-z0-9]+)\:/i } i_run "ifconfig -a";
19  
20 0 @device_list = array_uniq(@device_list);
21 0 return \@device_list;
22  
23 }
24  
25 0 ▶sub get_network_configuration {
Subroutine get_network_configuration: not called CC=2 SCAR=17.9
Pod undocumented
26  
27 0 my $devices = get_network_devices();
28  
29 0 my $device_info = {};
30  
31 0 for my $dev ( @{$devices} ) {
32  
33 0 my $ifconfig = i_run("ifconfig $dev");
34  
35 0 $device_info->{$dev} = {
36 ip => [ ( $ifconfig =~ m/inet (\d+\.\d+\.\d+\.\d+)/ ) ]->[0],
37 netmask => [ ( $ifconfig =~ m/(netmask 0x|netmask )([a-f0-9]+)/ ) ]->[1],
38 broadcast => [ ( $ifconfig =~ m/broadcast (\d+\.\d+\.\d+\.\d+)/ ) ]->[0],
39 mac => [
40 ( $ifconfig =~ m/(ether|address:|lladdr) (..?:..?:..?:..?:..?:..?)/ )
41 ]->[1],
42 is_bridge => 0,
43 };
44  
45 }
46  
47 0 return $device_info;
48  
49 }
50  
51 0 ▶sub route {
Subroutine route: not called CC=7 SCAR=40.3
Pod undocumented
52  
53 0 my @ret = ();
54  
55 0 my @route = i_run "netstat -nr", fail_ok => 1;
56 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
57 0 die("Error running netstat");
58 }
59  
60 0 shift @route;
61 0 shift @route; # remove first 2 lines
62 0 shift @route;
63 0 shift @route; # remove first 2 lines
64  
65 0 for my $route_entry (@route) {
66  
67 0 ▶ if ( $route_entry =~ m/^$/
Branch: 1 branch
BranchTrueFalseTotal
if ($route_entry =~ /^$/u or $route_entry =~ /^Routing Table:/u or $route_entry =~ /^\s+Destination/u or $route_entry =~ /^---------/u) 0 0 0
Condition0%0/9
$route_entry =~ /^$/u or $route_entry =~ /^Routing Table:/u or $route_entry =~ /^\s+Destination/u or $route_entry =~ /^---------/u
l!l&&r!l&&!r
000
$route_entry =~ /^$/u or $route_entry =~ /^Routing Table:/u or $route_entry =~ /^\s+Destination/u
l!l&&r!l&&!r
000
$route_entry =~ /^$/u or $route_entry =~ /^Routing Table:/u
l!l&&r!l&&!r
000
MC/DC0%0/4
$route_entry =~ /^$/u or $route_entry =~ /^Routing Table:/u or $route_entry =~ /^\s+Destination/u or $route_entry =~ /^---------/u
$route_entry =~ /^$/u $route_entry =~ /^Routing Table:/u $route_entry =~ /^\s+Destination/u $route_entry =~ /^---------/u
Truth table0%0/5
A or B or C or D
A= $route_entry =~ /^$/uB= $route_entry =~ /^Routing Table:/uC= $route_entry =~ /^\s+Destination/uD= $route_entry =~ /^---------/u
ABCDresult
1XXX1
01XX1
001X1
00011
00000
68 || $route_entry =~ m/^Routing Table:/
69 || $route_entry =~ m/^\s+Destination/
70 || $route_entry =~ m/^---------/ )
71 {
72 0 next;
73 }
74  
75 0 my ( $dest, $gw, $flags, $ref, $use, $iface ) =
76 split( /\s+/, $route_entry, 6 );
77 0 push(
78 @ret,
79 {
80 destination => $dest,
81 gateway => $gw,
82 flags => $flags,
83 ref => $ref,
84 use => $use,
85 iface => $iface,
86 }
87 );
88 }
89  
90 0 return @ret;
91  
92 }
93  
94 0 ▶sub default_gateway {
Subroutine default_gateway: not called CC=8 SCAR=42.8
Pod undocumented
95  
96 0 my ( $class, $new_default_gw ) = @_;
97  
98 0 ▶ if ($new_default_gw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_default_gw) { } 0 0 0
99 0 ▶ if ( default_gateway() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (default_gateway()) 0 0 0
100 0 i_run "route delete default " . default_gateway(), fail_ok => 1;
101 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
102 0 die("Error running route del default");
103 }
104 }
105  
106 0 i_run "route add default $new_default_gw", fail_ok => 1;
107 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
108 0 die("Error route add default");
109 }
110  
111 }
112 else {
113 0 my @route = route();
114  
115 my ($default_route) = grep {
116 0 $_->{"flags"} =~ m/UG/
117 && ( $_->{"destination"} eq "0.0.0.0"
118 0 ▶ || $_->{"destination"} eq "default" )
Condition0%0/6
$_->{'flags'} =~ /UG/u && ($_->{'destination'} eq '0.0.0.0' || $_->{'destination'} eq 'default')
!ll&&!rl&&r
000
$_->{"destination"} eq "0.0.0.0" or $_->{"destination"} eq "default"
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{'flags'} =~ /UG/u && ($_->{'destination'} eq '0.0.0.0' || $_->{'destination'} eq 'default')
$_->{'flags'} =~ /UG/u $_->{"destination"} eq "0.0.0.0" $_->{"destination"} eq "default"
Truth table0%0/4
A && B or C
A= $_->{'flags'} =~ /UG/uB= $_->{"destination"} eq "0.0.0.0"C= $_->{"destination"} eq "default"
ABCresult
0XX0
1000
11X1
1011
119 } @route;
120 0 ▶ return $default_route->{"gateway"} if $default_route;
Branch: 1 branch
BranchTrueFalseTotal
if $default_route 0 0 0
121 }
122 }
123  
124 0 ▶sub netstat {
Subroutine netstat: not called CC=17 SCAR=57.2
Pod undocumented
125  
126 0 my @ret;
127 0 my @netstat = i_run "netstat -na -f inet -f inet6", fail_ok => 1;
128 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
129 0 die("Error running netstat");
130 }
131  
132 0 my ( $proto, $udp_v4, $udp_v6, $tcp_v4, $tcp_v6, $sctp );
133 0 for my $line (@netstat) {
134  
135 0 ▶ if ( $line =~ m/^$/
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^$/u or $line =~ /^\s+Local/u or $line =~ /^--------/u) 0 0 0
Condition0%0/6
$line =~ /^$/u or $line =~ /^\s+Local/u or $line =~ /^--------/u
l!l&&r!l&&!r
000
$line =~ /^$/u or $line =~ /^\s+Local/u
l!l&&r!l&&!r
000
MC/DC0%0/3
$line =~ /^$/u or $line =~ /^\s+Local/u or $line =~ /^--------/u
$line =~ /^$/u $line =~ /^\s+Local/u $line =~ /^--------/u
Truth table0%0/4
A or B or C
A= $line =~ /^$/uB= $line =~ /^\s+Local/uC= $line =~ /^--------/u
ABCresult
1XX1
01X1
0011
0000
136 || $line =~ m/^\s+Local/
137 || $line =~ m/^--------/ )
138 {
139 0 next;
140 }
141  
142 0 ▶ if ( $line =~ m/^UDP: IPv4/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^UDP: IPv4/u) 0 0 0
143 0 $udp_v4 = 0;
144 0 $udp_v6 = 0;
145 0 $tcp_v4 = 0;
146 0 $tcp_v6 = 0;
147 0 $sctp = 0;
148 0 $udp_v4 = 1;
149 0 $proto = "udp";
150 0 next;
151 }
152  
153 0 ▶ if ( $line =~ m/^UDP: IPv6/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^UDP: IPv6/u) 0 0 0
154 0 $udp_v4 = 0;
155 0 $udp_v6 = 0;
156 0 $tcp_v4 = 0;
157 0 $tcp_v6 = 0;
158 0 $sctp = 0;
159 0 $udp_v6 = 1;
160 0 $proto = "udp6";
161 0 next;
162 }
163  
164 0 ▶ if ( $line =~ m/^TCP: IPv4/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^TCP: IPv4/u) 0 0 0
165 0 $udp_v4 = 0;
166 0 $udp_v6 = 0;
167 0 $tcp_v4 = 0;
168 0 $tcp_v6 = 0;
169 0 $sctp = 0;
170 0 $tcp_v4 = 1;
171 0 $proto = "tcp";
172 0 next;
173 }
174  
175 0 ▶ if ( $line =~ m/^TCP: IPv6/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^TCP: IPv6/u) 0 0 0
176 0 $udp_v4 = 0;
177 0 $udp_v6 = 0;
178 0 $tcp_v4 = 0;
179 0 $tcp_v6 = 0;
180 0 $sctp = 0;
181 0 $tcp_v6 = 1;
182 0 $proto = "tcp6";
183 0 next;
184 }
185  
186 0 ▶ if ( $line =~ m/^SCTP:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^SCTP:/u) 0 0 0
187 0 $udp_v4 = 0;
188 0 $udp_v6 = 0;
189 0 $tcp_v4 = 0;
190 0 $tcp_v6 = 0;
191 0 $sctp = 0;
192 0 $sctp = 1;
193 0 $proto = "sctp";
194 0 next;
195 }
196  
197 0 $line =~ s/^\s+//;
198  
199 0 ▶ if ($udp_v4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($udp_v4) 0 0 0
200 0 $line = " $line";
201 0 my ( $local_addr, $remote_addr, $state ) =
202 ( $line =~ m/\s+?([^\s]+)\s+([^\s]+)?\s+([^\s]+)/ );
203 0 push(
204 @ret,
205 {
206 proto => $proto,
207 local_addr => $local_addr,
208 foreign_addr => $remote_addr,
209 state => $state,
210 }
211 );
212 0 next;
213 }
214  
215 0 ▶ if ($udp_v6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($udp_v6) 0 0 0
216 0 $line = " $line";
217 0 my ( $local_addr, $remote_addr, $state, $if ) =
218 ( $line =~ m/\s+?([^\s]+)\s+([^\s]+)?\s+([^\s]+)\s+([^\s]+)/ );
219 0 push(
220 @ret,
221 {
222 proto => $proto,
223 local_addr => $local_addr,
224 foreign_addr => $remote_addr,
225 state => $state,
226 if => $if,
227 }
228 );
229 0 next;
230 }
231  
232 0 ▶ if ($tcp_v4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tcp_v4) 0 0 0
233 0 my ( $local_addr, $remote_addr, $swind, $sendq, $rwind, $recvq, $state )
234 = split( /\s+/, $line, 7 );
235 0 push(
236 @ret,
237 {
238 proto => $proto,
239 local_addr => $local_addr,
240 foreign_addr => $remote_addr,
241 swind => $swind,
242 sendq => $sendq,
243 rwind => $rwind,
244 recvq => $recvq,
245 state => $state,
246 }
247 );
248 0 next;
249 }
250  
251 0 ▶ if ($tcp_v6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tcp_v6) 0 0 0
252 0 my ( $local_addr, $remote_addr, $swind, $sendq, $rwind, $recvq, $state,
253 $if )
254 = split( /\s+/, $line, 8 );
255 0 push(
256 @ret,
257 {
258 proto => $proto,
259 local_addr => $local_addr,
260 foreign_addr => $remote_addr,
261 swind => $swind,
262 sendq => $sendq,
263 rwind => $rwind,
264 recvq => $recvq,
265 state => $state,
266 if => $if,
267 }
268 );
269 0 next;
270 }
271  
272 0 ▶ if ($sctp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sctp) 0 0 0
273 0 my ( $local_addr, $remote_addr, $swind, $sendq, $rwind, $recvq, $strs,
274 $state )
275 = split( /\s+/, $line, 8 );
276 0 push(
277 @ret,
278 {
279 proto => $proto,
280 local_addr => $local_addr,
281 foreign_addr => $remote_addr,
282 swind => $swind,
283 sendq => $sendq,
284 rwind => $rwind,
285 recvq => $recvq,
286 state => $state,
287 strsio => $strs,
288 }
289 );
290 0 next;
291 }
292  
293 }
294  
295 0 @netstat = i_run "netstat -na -f unix", fail_ok => 1;
296 0 shift @netstat;
297 0 shift @netstat;
298 0 shift @netstat;
299  
300 0 for my $line (@netstat) {
301 0 my ( $address, $type, $vnode, $conn, $local_addr, $remote_addr ) =
302 split( /\s+/, $line, 7 );
303  
304 0 my $data = {
305 proto => "unix",
306 address => $address,
307 type => $type,
308 nvnode => $vnode,
309 conn => $conn,
310 path => $local_addr,
311 };
312  
313 0 push( @ret, $data );
314  
315 }
316  
317 0 return @ret;
318  
319 }
320  
321 1 1;
« lib/Rex/Commands/Cron.pm ↑ Summary lib/Rex/Box/VBox.pm »