| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Hardware::Network::OpenBSD; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
14
|
use v5.12.5; |
|
|
1
|
|
|
|
|
3
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Rex::Logger; |
|
|
1
|
|
|
|
|
18
|
|
|
|
1
|
|
|
|
|
8
|
|
|
13
|
1
|
|
|
1
|
|
25
|
use Rex::Helper::Run; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
65
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Rex::Helper::Array; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
44
|
|
|
15
|
1
|
|
|
1
|
|
10
|
use Rex::Hardware::Network::FreeBSD; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
12
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub get_network_devices { |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
|
|
0
|
0
|
|
return Rex::Hardware::Network::FreeBSD::get_network_devices(); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get_network_configuration { |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
0
|
0
|
|
return Rex::Hardware::Network::FreeBSD::get_network_configuration(); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub route { |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
0
|
|
my @route = i_run "netstat -nr", fail_ok => 1; |
|
32
|
0
|
|
|
|
|
|
my @ret; |
|
33
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
34
|
0
|
|
|
|
|
|
die("Error running netstat"); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my ( $in_v6, $in_v4 ); |
|
38
|
0
|
|
|
|
|
|
for my $route_entry (@route) { |
|
39
|
0
|
0
|
|
|
|
|
if ( $route_entry eq "Internet:" ) { |
|
40
|
0
|
|
|
|
|
|
$in_v4 = 1; |
|
41
|
0
|
|
|
|
|
|
next; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if ( $route_entry eq "Internet6:" ) { |
|
45
|
0
|
|
|
|
|
|
$in_v6 = 1; |
|
46
|
0
|
|
|
|
|
|
$in_v4 = 0; |
|
47
|
0
|
|
|
|
|
|
next; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
if ( $route_entry =~ m/^$/ ) { |
|
51
|
0
|
|
|
|
|
|
$in_v6 = 0; |
|
52
|
0
|
|
|
|
|
|
$in_v4 = 0; |
|
53
|
0
|
|
|
|
|
|
next; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ( $route_entry =~ m/^AppleTalk/ ) { |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# kein appletalk ... |
|
59
|
0
|
|
|
|
|
|
next; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ( $route_entry =~ m/^Destination/ ) { |
|
63
|
0
|
|
|
|
|
|
next; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if ($in_v4) { |
|
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
|
0
|
|
|
|
|
if ($in_v6) { |
|
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
|
|
|
|
|
|
|
sub default_gateway { |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
0
|
0
|
|
my ( $class, $new_default_gw ) = @_; |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if ($new_default_gw) { |
|
113
|
0
|
0
|
|
|
|
|
if ( default_gateway() ) { |
|
114
|
0
|
|
|
|
|
|
i_run "route delete default", fail_ok => 1; |
|
115
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
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
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
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
|
0
|
0
|
|
|
|
|| $_->{"destination"} eq "default" ) |
|
133
|
|
|
|
|
|
|
} @route; |
|
134
|
0
|
0
|
|
|
|
|
return $default_route->{"gateway"} if $default_route; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub netstat { |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
0
|
0
|
|
my @ret; |
|
141
|
0
|
|
|
|
|
|
my @netstat = i_run "netstat -na", fail_ok => 1; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
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
|
0
|
|
|
|
|
if ( $line =~ m/^Proto\s*Recv/ ) { |
|
153
|
0
|
|
|
|
|
|
$in_inet = 1; |
|
154
|
0
|
|
|
|
|
|
next; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^Active Internet/ ) { |
|
158
|
0
|
|
|
|
|
|
next; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^Active UNIX/ ) { |
|
162
|
0
|
|
|
|
|
|
$in_inet = 0; |
|
163
|
0
|
|
|
|
|
|
$in_unix = 1; |
|
164
|
0
|
|
|
|
|
|
next; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^Address\s*Type/ ) { |
|
168
|
0
|
|
|
|
|
|
next; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
if ($in_inet) { |
|
172
|
0
|
|
|
|
|
|
my ( $proto, $recvq, $sendq, $local_addr, $foreign_addr, $state ) = |
|
173
|
|
|
|
|
|
|
split( /\s+/, $line, 6 ); |
|
174
|
0
|
0
|
|
|
|
|
if ( $proto eq "tcp4" ) { $proto = "tcp"; } |
|
|
0
|
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
if ($in_unix) { |
|
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; |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |