| 1 | # | ||||||||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | package Rex::Hardware::Network::OpenBSD; | ||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use Rex::Hardware::Network::FreeBSD; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub get_network_devices { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_network_devices: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 0 | return Rex::Hardware::Network::FreeBSD::get_network_devices(); | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub get_network_configuration { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_network_configuration: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 0 | return Rex::Hardware::Network::FreeBSD::get_network_configuration(); | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub route { | ||||||||||||||||||||||||||||||||
|
Subroutine
route: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 0 | my @route = i_run "netstat -nr", fail_ok => 1; | |||||||||||||||||||||||||||||||||
| 32 | 0 | my @ret; | |||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 34 | 0 | die("Error running netstat"); | |||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 0 | my ( $in_v6, $in_v4 ); | |||||||||||||||||||||||||||||||||
| 38 | 0 | for my $route_entry (@route) { | |||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ( $route_entry eq "Internet:" ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 40 | 0 | $in_v4 = 1; | |||||||||||||||||||||||||||||||||
| 41 | 0 | next; | |||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( $route_entry eq "Internet6:" ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | 0 | $in_v6 = 1; | |||||||||||||||||||||||||||||||||
| 46 | 0 | $in_v4 = 0; | |||||||||||||||||||||||||||||||||
| 47 | 0 | next; | |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( $route_entry =~ m/^$/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 51 | 0 | $in_v6 = 0; | |||||||||||||||||||||||||||||||||
| 52 | 0 | $in_v4 = 0; | |||||||||||||||||||||||||||||||||
| 53 | 0 | next; | |||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ( $route_entry =~ m/^AppleTalk/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | # kein appletalk ... | ||||||||||||||||||||||||||||||||||
| 59 | 0 | next; | |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( $route_entry =~ m/^Destination/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 63 | 0 | next; | |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($in_v4) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | 0 | my ( $dest, $gw, $flags, $refs, $use, $mtu, $prio, $netif ) = | |||||||||||||||||||||||||||||||||
| 68 | split( /\s+/, $route_entry, 8 ); | ||||||||||||||||||||||||||||||||||
| 69 | 0 | push( | |||||||||||||||||||||||||||||||||
| 70 | @ret, | ||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||
| 72 | destination => $dest, | ||||||||||||||||||||||||||||||||||
| 73 | gateway => $gw, | ||||||||||||||||||||||||||||||||||
| 74 | flags => $flags, | ||||||||||||||||||||||||||||||||||
| 75 | iface => $netif, | ||||||||||||||||||||||||||||||||||
| 76 | refs => $refs, | ||||||||||||||||||||||||||||||||||
| 77 | mtu => $mtu, | ||||||||||||||||||||||||||||||||||
| 78 | priority => $prio, | ||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 0 | next; | |||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ($in_v6) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 86 | 0 | my ( $dest, $gw, $flags, $refs, $use, $mtu, $prio, $netif ) = | |||||||||||||||||||||||||||||||||
| 87 | split( /\s+/, $route_entry, 8 ); | ||||||||||||||||||||||||||||||||||
| 88 | 0 | push( | |||||||||||||||||||||||||||||||||
| 89 | @ret, | ||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||
| 91 | destination => $dest, | ||||||||||||||||||||||||||||||||||
| 92 | gateway => $gw, | ||||||||||||||||||||||||||||||||||
| 93 | flags => $flags, | ||||||||||||||||||||||||||||||||||
| 94 | iface => $netif, | ||||||||||||||||||||||||||||||||||
| 95 | refs => $refs, | ||||||||||||||||||||||||||||||||||
| 96 | mtu => $mtu, | ||||||||||||||||||||||||||||||||||
| 97 | priority => $prio, | ||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 0 | return @ret; | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub default_gateway { | ||||||||||||||||||||||||||||||||
|
Subroutine
default_gateway: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 0 | my ( $class, $new_default_gw ) = @_; | |||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ($new_default_gw) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ( default_gateway() ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 114 | 0 | i_run "route delete default", fail_ok => 1; | |||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 116 | 0 | die("Error running route delete default"); | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | 0 | i_run "route add default $new_default_gw", fail_ok => 1; | |||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 122 | 0 | die("Error route add default"); | |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||
| 126 | else { | ||||||||||||||||||||||||||||||||||
| 127 | 0 | my @route = route(); | |||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | my ($default_route) = grep { | ||||||||||||||||||||||||||||||||||
| 130 | 0 | $_->{"flags"} =~ m/UG/ | |||||||||||||||||||||||||||||||||
| 131 | && ( $_->{"destination"} eq "0.0.0.0" | ||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | || $_->{"destination"} eq "default" ) | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$_->{'flags'} =~ /UG/u && ($_->{'destination'} eq '0.0.0.0' || $_->{'destination'} eq 'default')
$_->{"destination"} eq "0.0.0.0" or $_->{"destination"} eq "default"
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"
| |||||||||||||||||||||||||||||||||||
| 133 | } @route; | ||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return $default_route->{"gateway"} if $default_route; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub netstat { | ||||||||||||||||||||||||||||||||
|
Subroutine
netstat: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | 0 | my @ret; | |||||||||||||||||||||||||||||||||
| 141 | 0 | my @netstat = i_run "netstat -na", fail_ok => 1; | |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 144 | 0 | die("Error running netstat"); | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | 0 | shift @netstat; | |||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | 0 | my ( $in_inet, $in_unix ) = ( 0, 0 ); | |||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | 0 | for my $line (@netstat) { | |||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ( $line =~ m/^Proto\s*Recv/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 153 | 0 | $in_inet = 1; | |||||||||||||||||||||||||||||||||
| 154 | 0 | next; | |||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ( $line =~ m/^Active Internet/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 158 | 0 | next; | |||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if ( $line =~ m/^Active UNIX/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 162 | 0 | $in_inet = 0; | |||||||||||||||||||||||||||||||||
| 163 | 0 | $in_unix = 1; | |||||||||||||||||||||||||||||||||
| 164 | 0 | next; | |||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | if ( $line =~ m/^Address\s*Type/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | 0 | next; | |||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ($in_inet) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 172 | 0 | my ( $proto, $recvq, $sendq, $local_addr, $foreign_addr, $state ) = | |||||||||||||||||||||||||||||||||
| 173 | split( /\s+/, $line, 6 ); | ||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ( $proto eq "tcp4" ) { $proto = "tcp"; } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 175 | push( | ||||||||||||||||||||||||||||||||||
| 176 | 0 | @ret, | |||||||||||||||||||||||||||||||||
| 177 | { | ||||||||||||||||||||||||||||||||||
| 178 | proto => $proto, | ||||||||||||||||||||||||||||||||||
| 179 | recvq => $recvq, | ||||||||||||||||||||||||||||||||||
| 180 | sendq => $sendq, | ||||||||||||||||||||||||||||||||||
| 181 | local_addr => $local_addr, | ||||||||||||||||||||||||||||||||||
| 182 | foreign_addr => $foreign_addr, | ||||||||||||||||||||||||||||||||||
| 183 | state => $state, | ||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||
| 185 | ); | ||||||||||||||||||||||||||||||||||
| 186 | 0 | next; | |||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ($in_unix) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 190 | my ( | ||||||||||||||||||||||||||||||||||
| 191 | 0 | $address, $type, $recvq, $sendq, $inode, | |||||||||||||||||||||||||||||||||
| 192 | $conn, $refs, $nextref, $addr | ||||||||||||||||||||||||||||||||||
| 193 | ) = split( /\s+/, $line, 9 ); | ||||||||||||||||||||||||||||||||||
| 194 | 0 | push( | |||||||||||||||||||||||||||||||||
| 195 | @ret, | ||||||||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||||||||
| 197 | proto => "unix", | ||||||||||||||||||||||||||||||||||
| 198 | address => $address, | ||||||||||||||||||||||||||||||||||
| 199 | refcnt => $refs, | ||||||||||||||||||||||||||||||||||
| 200 | type => $type, | ||||||||||||||||||||||||||||||||||
| 201 | inode => $inode, | ||||||||||||||||||||||||||||||||||
| 202 | path => $addr, | ||||||||||||||||||||||||||||||||||
| 203 | recvq => $recvq, | ||||||||||||||||||||||||||||||||||
| 204 | sendq => $sendq, | ||||||||||||||||||||||||||||||||||
| 205 | conn => $conn, | ||||||||||||||||||||||||||||||||||
| 206 | nextref => $nextref, | ||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||
| 208 | ); | ||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | 0 | next; | |||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | 0 | return @ret; | |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | 1 | 1; | |||||||||||||||||||||||||||||||||