line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Linux::Networks; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
41865498
|
use strict; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
83
|
|
4
|
2
|
|
|
2
|
|
17
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
107
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1305
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
400
|
|
7
|
2
|
|
|
2
|
|
1338
|
use FusionInventory::Agent::Tools::Network; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
472
|
|
8
|
2
|
|
|
2
|
|
1475
|
use FusionInventory::Agent::Tools::Unix; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
174
|
|
9
|
2
|
|
|
2
|
|
1333
|
use FusionInventory::Agent::Tools::Linux; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
3359
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub isEnabled { |
12
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
13
|
0
|
0
|
|
|
|
0
|
return 0 if $params{no_category}->{network}; |
14
|
0
|
|
|
|
|
0
|
return 1; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub doInventory { |
18
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
21
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
0
|
my $routes = getRoutingTable(command => 'netstat -nr', logger => $logger); |
24
|
0
|
|
|
|
|
0
|
my $default = $routes->{'0.0.0.0'}; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
my @interfaces = _getInterfaces(logger => $logger); |
27
|
0
|
|
|
|
|
0
|
foreach my $interface (@interfaces) { |
28
|
|
|
|
|
|
|
# if the default gateway address and the interface address belongs to |
29
|
|
|
|
|
|
|
# the same network, that's the gateway for this network |
30
|
|
|
|
|
|
|
$interface->{IPGATEWAY} = $default if isSameNetwork( |
31
|
|
|
|
|
|
|
$default, $interface->{IPADDRESS}, $interface->{IPMASK} |
32
|
0
|
0
|
|
|
|
0
|
); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
35
|
|
|
|
|
|
|
section => 'NETWORKS', |
36
|
|
|
|
|
|
|
entry => $interface |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$inventory->setHardware({ |
41
|
0
|
|
|
|
|
0
|
DEFAULTGATEWAY => $default |
42
|
|
|
|
|
|
|
}); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _getInterfaces { |
46
|
0
|
|
|
0
|
|
0
|
my (%params) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
my @interfaces = _getInterfacesBase(logger => $logger); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
foreach my $interface (@interfaces) { |
53
|
|
|
|
|
|
|
$interface->{IPSUBNET} = getSubnetAddress( |
54
|
|
|
|
|
|
|
$interface->{IPADDRESS}, |
55
|
|
|
|
|
|
|
$interface->{IPMASK} |
56
|
0
|
|
|
|
|
0
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$interface->{IPDHCP} = getIpDhcp( |
59
|
|
|
|
|
|
|
$logger, |
60
|
|
|
|
|
|
|
$interface->{DESCRIPTION} |
61
|
0
|
|
|
|
|
0
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# check if it is a physical interface |
64
|
0
|
0
|
|
|
|
0
|
if (-d "/sys/class/net/$interface->{DESCRIPTION}/device") { |
65
|
0
|
|
|
|
|
0
|
my $info = _getUevent($interface->{DESCRIPTION}); |
66
|
|
|
|
|
|
|
$interface->{DRIVER} = $info->{DRIVER} |
67
|
0
|
0
|
|
|
|
0
|
if $info->{DRIVER}; |
68
|
|
|
|
|
|
|
$interface->{PCISLOT} = $info->{PCI_SLOT_NAME} |
69
|
0
|
0
|
|
|
|
0
|
if $info->{PCI_SLOT_NAME}; |
70
|
|
|
|
|
|
|
$interface->{PCIID} = |
71
|
|
|
|
|
|
|
$info->{PCI_ID} . ':' . $info->{PCI_SUBSYS_ID} |
72
|
0
|
0
|
0
|
|
|
0
|
if $info->{PCI_SUBSYS_ID} && $info->{PCI_ID}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
$interface->{VIRTUALDEV} = 0; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# check if it is a wifi interface, otherwise assume ethernet |
77
|
0
|
0
|
|
|
|
0
|
if (-d "/sys/class/net/$interface->{DESCRIPTION}/wireless") { |
|
|
0
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
$interface->{TYPE} = 'wifi'; |
79
|
0
|
|
|
|
|
0
|
my $info = _parseIwconfig(name => $interface->{DESCRIPTION}); |
80
|
0
|
|
|
|
|
0
|
$interface->{WIFI_MODE} = $info->{mode}; |
81
|
0
|
|
|
|
|
0
|
$interface->{WIFI_SSID} = $info->{SSID}; |
82
|
0
|
|
|
|
|
0
|
$interface->{WIFI_BSSID} = $info->{BSSID}; |
83
|
0
|
|
|
|
|
0
|
$interface->{WIFI_VERSION} = $info->{version}; |
84
|
|
|
|
|
|
|
} elsif (-f "/sys/class/net/$interface->{DESCRIPTION}/mode") { |
85
|
0
|
|
|
|
|
0
|
$interface->{TYPE} = 'infiniband'; |
86
|
|
|
|
|
|
|
} else { |
87
|
0
|
|
|
|
|
0
|
$interface->{TYPE} = 'ethernet'; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} else { |
91
|
0
|
|
|
|
|
0
|
$interface->{VIRTUALDEV} = 1; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
0
|
if ($interface->{DESCRIPTION} eq 'lo') { |
94
|
0
|
|
|
|
|
0
|
$interface->{TYPE} = 'loopback'; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
0
|
if ($interface->{DESCRIPTION} =~ m/^ppp/) { |
98
|
0
|
|
|
|
|
0
|
$interface->{TYPE} = 'dialup'; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# check if it is an alias or a tagged interface |
102
|
0
|
0
|
|
|
|
0
|
if ($interface->{DESCRIPTION} =~ m/^([\w\d]+)[:.]\d+$/) { |
103
|
0
|
|
|
|
|
0
|
$interface->{TYPE} = 'alias'; |
104
|
0
|
|
|
|
|
0
|
$interface->{BASE} = $1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
# check if is is a bridge |
107
|
0
|
0
|
|
|
|
0
|
if (-d "/sys/class/net/$interface->{DESCRIPTION}/brif") { |
108
|
0
|
|
|
|
|
0
|
$interface->{SLAVES} = _getSlaves($interface->{DESCRIPTION}); |
109
|
0
|
|
|
|
|
0
|
$interface->{TYPE} = 'bridge'; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# check if it is a bonding master |
113
|
0
|
0
|
|
|
|
0
|
if (-d "/sys/class/net/$interface->{DESCRIPTION}/bonding") { |
114
|
0
|
|
|
|
|
0
|
$interface->{SLAVES} = _getSlaves($interface->{DESCRIPTION}); |
115
|
0
|
|
|
|
|
0
|
$interface->{TYPE} = 'aggregate'; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# check if it is a bonding slave |
120
|
0
|
0
|
|
|
|
0
|
if (-d "/sys/class/net/$interface->{DESCRIPTION}/bonding_slave") { |
121
|
0
|
|
|
|
|
0
|
$interface->{MACADDR} = getFirstMatch( |
122
|
|
|
|
|
|
|
command => "ethtool -P $interface->{DESCRIPTION}", |
123
|
|
|
|
|
|
|
pattern => qr/^Permanent address: ($mac_address_pattern)$/, |
124
|
|
|
|
|
|
|
logger => $logger |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
0
|
if (-r "/sys/class/net/$interface->{DESCRIPTION}/speed") { |
129
|
0
|
|
|
|
|
0
|
$interface->{SPEED} = getFirstLine( |
130
|
|
|
|
|
|
|
file => "/sys/class/net/$interface->{DESCRIPTION}/speed" |
131
|
|
|
|
|
|
|
); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
return @interfaces; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub _getInterfacesBase { |
139
|
0
|
|
|
0
|
|
0
|
my (%params) = @_; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
142
|
0
|
|
|
|
|
0
|
$logger->debug("retrieving interfaces list:"); |
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
0
|
if (canRun('/sbin/ip')) { |
145
|
0
|
|
|
|
|
0
|
my @interfaces = getInterfacesFromIp(logger => $logger); |
146
|
0
|
|
|
|
|
0
|
$logger->debug_result( |
147
|
|
|
|
|
|
|
action => 'running /sbin/ip command', |
148
|
|
|
|
|
|
|
data => scalar @interfaces |
149
|
|
|
|
|
|
|
); |
150
|
0
|
0
|
|
|
|
0
|
return @interfaces if @interfaces; |
151
|
|
|
|
|
|
|
} else { |
152
|
0
|
|
|
|
|
0
|
$logger->debug_result( |
153
|
|
|
|
|
|
|
action => 'running /sbin/ip command', |
154
|
|
|
|
|
|
|
status => 'command not available' |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
0
|
if (canRun('/sbin/ifconfig')) { |
159
|
0
|
|
|
|
|
0
|
my @interfaces = getInterfacesFromIfconfig(logger => $logger); |
160
|
0
|
|
|
|
|
0
|
$logger->debug_result( |
161
|
|
|
|
|
|
|
action => 'running /sbin/ifconfig command', |
162
|
|
|
|
|
|
|
data => scalar @interfaces |
163
|
|
|
|
|
|
|
); |
164
|
0
|
0
|
|
|
|
0
|
return @interfaces if @interfaces; |
165
|
|
|
|
|
|
|
} else { |
166
|
0
|
|
|
|
|
0
|
$logger->debug_result( |
167
|
|
|
|
|
|
|
action => 'running /sbin/ifconfig command', |
168
|
|
|
|
|
|
|
status => 'command not available' |
169
|
|
|
|
|
|
|
); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
0
|
return; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _getSlaves { |
176
|
0
|
|
|
0
|
|
0
|
my ($name) = @_; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
my @slaves = |
179
|
0
|
|
|
|
|
0
|
map { $_ =~ /\/lower_(\w+)$/ } |
|
0
|
|
|
|
|
0
|
|
180
|
|
|
|
|
|
|
glob("/sys/class/net/$name/lower_*"); |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
0
|
return join (",", @slaves); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _getUevent { |
186
|
0
|
|
|
0
|
|
0
|
my ($name) = @_; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
0
|
my $file = "/sys/class/net/$name/device/uevent"; |
189
|
0
|
|
|
|
|
0
|
my $handle = getFileHandle(file => $file); |
190
|
0
|
0
|
|
|
|
0
|
return unless $handle; |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
0
|
my $info; |
193
|
0
|
|
|
|
|
0
|
while (my $line = <$handle>) { |
194
|
0
|
0
|
|
|
|
0
|
next unless $line =~ /^(\w+)=(\S+)$/; |
195
|
0
|
|
|
|
|
0
|
$info->{$1} = $2; |
196
|
|
|
|
|
|
|
} |
197
|
0
|
|
|
|
|
0
|
close $handle; |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
0
|
return $info; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub _parseIwconfig { |
203
|
2
|
|
|
2
|
|
12490
|
my (%params) = @_; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
my $handle = getFileHandle( |
206
|
|
|
|
|
|
|
%params, |
207
|
2
|
50
|
|
|
|
15
|
command => $params{name} ? "iwconfig $params{name}" : undef |
208
|
|
|
|
|
|
|
); |
209
|
2
|
50
|
|
|
|
7
|
return unless $handle; |
210
|
|
|
|
|
|
|
|
211
|
2
|
|
|
|
|
3
|
my $info; |
212
|
2
|
|
|
|
|
33
|
while (my $line = <$handle>) { |
213
|
14
|
100
|
|
|
|
44
|
$info->{version} = $1 |
214
|
|
|
|
|
|
|
if $line =~ /IEEE (\S+)/; |
215
|
14
|
100
|
|
|
|
35
|
$info->{SSID} = $1 |
216
|
|
|
|
|
|
|
if $line =~ /ESSID:"([^"]+)"/; |
217
|
14
|
100
|
|
|
|
40
|
$info->{mode} = $1 |
218
|
|
|
|
|
|
|
if $line =~ /Mode:(\S+)/; |
219
|
14
|
100
|
|
|
|
148
|
$info->{BSSID} = $1 |
220
|
|
|
|
|
|
|
if $line =~ /Access Point: ($mac_address_pattern)/; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
2
|
|
|
|
|
15
|
close $handle; |
224
|
|
|
|
|
|
|
|
225
|
2
|
|
|
|
|
10
|
return $info; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
1; |