| 1 | # SNMP::Info::Layer2::Aerohive | ||
| 2 | # | ||
| 3 | # Copyright (c) 2018 Eric Miller | ||
| 4 | # All rights reserved. | ||
| 5 | # | ||
| 6 | # Redistribution and use in source and binary forms, with or without | ||
| 7 | # modification, are permitted provided that the following conditions are met: | ||
| 8 | # | ||
| 9 | # * Redistributions of source code must retain the above copyright notice, | ||
| 10 | # this list of conditions and the following disclaimer. | ||
| 11 | # * Redistributions in binary form must reproduce the above copyright | ||
| 12 | # notice, this list of conditions and the following disclaimer in the | ||
| 13 | # documentation and/or other materials provided with the distribution. | ||
| 14 | # * Neither the name of the University of California, Santa Cruz nor the | ||
| 15 | # names of its contributors may be used to endorse or promote products | ||
| 16 | # derived from this software without specific prior written permission. | ||
| 17 | # | ||
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 22 | # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 28 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 29 | |||
| 30 | package SNMP::Info::Layer2::Aerohive; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::Layer2; | ||
| 36 | |||
| 37 | @SNMP::Info::Layer2::Aerohive::ISA = qw/SNMP::Info::Layer2 Exporter/; | ||
| 38 | @SNMP::Info::Layer2::Aerohive::EXPORT_OK = qw//; | ||
| 39 | |||
| 40 | our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE); | ||
| 41 | |||
| 42 | $VERSION = '3.985003'; | ||
| 43 | |||
| 44 | %MIBS = ( | ||
| 45 | %SNMP::Info::Layer2::MIBS, | ||
| 46 | 'AH-SYSTEM-MIB' => 'ahSystemSerial', | ||
| 47 | 'AH-INTERFACE-MIB' => 'ahSSIDName', | ||
| 48 | ); | ||
| 49 | |||
| 50 | %GLOBALS = ( | ||
| 51 | %SNMP::Info::Layer2::GLOBALS, | ||
| 52 | |||
| 53 | # AH-SYSTEM-MIB | ||
| 54 | 'ah_serial' => 'ahSystemSerial', | ||
| 55 | 'os_bin' => 'ahFirmwareVersion', | ||
| 56 | 'ah_devmode' => 'ahDeviceMode', | ||
| 57 | # not documented in the most recent mib, | ||
| 58 | # but this is the base mac for the device | ||
| 59 | 'ah_mac' => '.1.3.6.1.4.1.26928.1.3.2.0', | ||
| 60 | ); | ||
| 61 | |||
| 62 | %FUNCS = ( | ||
| 63 | %SNMP::Info::Layer2::FUNCS, | ||
| 64 | |||
| 65 | # AH-INTERFACE-MIB::ahRadioAttributeTable | ||
| 66 | 'i_80211channel' => 'ahRadioChannel', | ||
| 67 | 'dot11_cur_tx_pwr_mw' => 'ahRadioTxPower', | ||
| 68 | |||
| 69 | # AH-INTERFACE-MIB::ahXIfTable | ||
| 70 | 'ah_i_ssidlist' => 'ahSSIDName', | ||
| 71 | 'ah_i_name' => 'ahIfName', | ||
| 72 | |||
| 73 | # AH-INTERFACE-MIB::ahAssociationTable | ||
| 74 | 'ah_c_txrate' => 'ahClientLastTxRate', | ||
| 75 | 'cd11_uptime' => 'ahClientLinkUptime', | ||
| 76 | 'cd11_sigstrength' => 'ahClientRSSI', | ||
| 77 | 'cd11_rxpkt' => 'ahClientRxDataFrames', | ||
| 78 | 'cd11_txpkt' => 'ahClientTxDataFrames', | ||
| 79 | 'cd11_rxbyte' => 'ahClientRxDataOctets', | ||
| 80 | 'cd11_txbyte' => 'ahClientTxDataOctets', | ||
| 81 | 'cd11_ssid' => 'ahClientSSID', | ||
| 82 | 'ah_c_vlan' => 'ahClientVLAN', | ||
| 83 | 'ah_c_ip' => 'ahClientIP', | ||
| 84 | ); | ||
| 85 | |||
| 86 | %MUNGE | ||
| 87 | = ( %SNMP::Info::Layer2::MUNGE, 'at_paddr' => \&SNMP::Info::munge_mac, ); | ||
| 88 | |||
| 89 | # hiveos does not have sysServices | ||
| 90 | sub layers { | ||
| 91 | return '00000111'; | ||
| 92 | } | ||
| 93 | |||
| 94 | sub vendor { | ||
| 95 | return 'aerohive'; | ||
| 96 | } | ||
| 97 | |||
| 98 | sub os { | ||
| 99 | return 'hiveos'; | ||
| 100 | } | ||
| 101 | |||
| 102 | sub serial { | ||
| 103 | my $aerohive = shift; | ||
| 104 | |||
| 105 | return $aerohive->ah_serial() | ||
| 106 | || $aerohive->SUPER::serial(); | ||
| 107 | } | ||
| 108 | |||
| 109 | sub os_ver { | ||
| 110 | my $aerohive = shift; | ||
| 111 | my $ah_ver = $aerohive->os_bin(); | ||
| 112 | my $descr = $aerohive->description(); | ||
| 113 | |||
| 114 | if ( defined ($ah_ver) && $ah_ver =~ m/\b(?:HiveOS|IQ\sEngine)\s(\d+\.\w+)\b/ix ) { | ||
| 115 | return $1; | ||
| 116 | } | ||
| 117 | if ( defined ($descr) && $descr =~ m/\bHiveOS\s(\d+\.\w+)\b/ix ) { | ||
| 118 | return $1; | ||
| 119 | } | ||
| 120 | return; | ||
| 121 | } | ||
| 122 | |||
| 123 | sub mac { | ||
| 124 | my $aerohive = shift; | ||
| 125 | my $ahmac = $aerohive->ah_mac(); | ||
| 126 | |||
| 127 | # newer hiveos version just return the mac address | ||
| 128 | if (defined $ahmac) { | ||
| 129 | # aerohive has a 0000:0000:0000 mac format by default, | ||
| 130 | # change to 00:00:00:00:00:00 | ||
| 131 | $ahmac =~ s/(..)(..:?)/$1:$2/g; | ||
| 132 | return $ahmac; | ||
| 133 | } | ||
| 134 | |||
| 135 | my @macs; | ||
| 136 | my $macs = $aerohive->i_mac(); | ||
| 137 | foreach my $iid (keys %$macs) { | ||
| 138 | if (defined $macs->{$iid}) { | ||
| 139 | push( @macs, $macs->{$iid} ); | ||
| 140 | } | ||
| 141 | @macs = sort(@macs); | ||
| 142 | } | ||
| 143 | return $macs[0]; | ||
| 144 | } | ||
| 145 | |||
| 146 | sub model { | ||
| 147 | my $aerohive = shift; | ||
| 148 | my $descr = $aerohive->description(); | ||
| 149 | my $ahdevmode = $aerohive->ah_devmode(); | ||
| 150 | |||
| 151 | if ( defined ($ahdevmode) and length $ahdevmode ) { | ||
| 152 | return $ahdevmode; | ||
| 153 | } | ||
| 154 | if ( defined ($descr) && $descr =~ m/\b(?:Hive|)(AP\d+)\b/ix ) { | ||
| 155 | return $1; | ||
| 156 | } | ||
| 157 | return; | ||
| 158 | } | ||
| 159 | |||
| 160 | # A WLAN interface is named <radio name>.<n>, and ahRadioAttributeTable has | ||
| 161 | # a row for each radio. No column or ifStackTable gives the parent. | ||
| 162 | sub _wlan_radios { | ||
| 163 | my $aerohive = shift; | ||
| 164 | |||
| 165 | my $names = $aerohive->ah_i_name() || {}; | ||
| 166 | my $channels = $aerohive->i_80211channel() || {}; | ||
| 167 | |||
| 168 | my %radio_by_name; | ||
| 169 | foreach my $iid ( keys %$channels ) { | ||
| 170 | my $name = $names->{$iid}; | ||
| 171 | $radio_by_name{$name} = $iid if defined $name; | ||
| 172 | } | ||
| 173 | |||
| 174 | my %wlan_radios; | ||
| 175 | foreach my $iid ( keys %$names ) { | ||
| 176 | next unless $names->{$iid} =~ /^(.+)\.\d+$/; | ||
| 177 | my $radio = $radio_by_name{$1}; | ||
| 178 | $wlan_radios{$iid} = $radio if defined $radio; | ||
| 179 | } | ||
| 180 | return \%wlan_radios; | ||
| 181 | } | ||
| 182 | |||
| 183 | sub interfaces { | ||
| 184 | my $aerohive = shift; | ||
| 185 | my $interfaces = $aerohive->i_index(); | ||
| 186 | my $i_descr = $aerohive->ah_i_name(); | ||
| 187 | my $wlans = $aerohive->_wlan_radios(); | ||
| 188 | |||
| 189 | my %if; | ||
| 190 | foreach my $iid ( keys %$interfaces ) { | ||
| 191 | next if exists $wlans->{$iid}; | ||
| 192 | my $descr = $i_descr->{$iid}; | ||
| 193 | next unless defined $descr; | ||
| 194 | $if{$iid} = $descr if ( defined $descr and length $descr ); | ||
| 195 | } | ||
| 196 | |||
| 197 | return \%if | ||
| 198 | } | ||
| 199 | |||
| 200 | sub i_ssidlist { | ||
| 201 | my $aerohive = shift; | ||
| 202 | my $partial = shift; | ||
| 203 | |||
| 204 | my $ssids = $aerohive->ah_i_ssidlist($partial) || {}; | ||
| 205 | my $wlans = $aerohive->_wlan_radios(); | ||
| 206 | |||
| 207 | my %i_ssidlist; | ||
| 208 | foreach my $iid ( keys %$ssids ) { | ||
| 209 | my $ssid = $ssids->{$iid}; | ||
| 210 | next if $ssid =~ /N\/A/i; | ||
| 211 | |||
| 212 | my $port = $wlans->{$iid} // $iid; | ||
| 213 | $i_ssidlist{"$port.$iid"} = $ssid; | ||
| 214 | } | ||
| 215 | return \%i_ssidlist; | ||
| 216 | } | ||
| 217 | |||
| 218 | sub i_ssidmac { | ||
| 219 | my $aerohive = shift; | ||
| 220 | my $partial = shift; | ||
| 221 | |||
| 222 | my $ssids = $aerohive->i_ssidlist($partial) || {}; | ||
| 223 | my $macs = $aerohive->i_mac($partial) || {}; | ||
| 224 | |||
| 225 | my %i_ssidmac; | ||
| 226 | foreach my $key ( keys %$ssids ) { | ||
| 227 | my ($wlan) = $key =~ /(\d+)$/; | ||
| 228 | my $mac = $macs->{$wlan}; | ||
| 229 | next unless $mac; | ||
| 230 | |||
| 231 | $i_ssidmac{$key} = $mac; | ||
| 232 | } | ||
| 233 | return \%i_ssidmac; | ||
| 234 | } | ||
| 235 | |||
| 236 | # Break up the ahAssociationEntry INDEX into ifIndex and MAC Address. | ||
| 237 | sub _ah_association_index { | ||
| 238 | my $idx = shift; | ||
| 239 | my @values = split( /\./, $idx ); | ||
| 240 | my $ifindex = shift(@values); | ||
| 241 | my $length = shift(@values); | ||
| 242 | return ( $ifindex, join( ':', map { sprintf "%02x", $_ } @values ) ); | ||
| 243 | } | ||
| 244 | |||
| 245 | sub cd11_txrate { | ||
| 246 | my $aerohive = shift; | ||
| 247 | my $partial = shift; | ||
| 248 | |||
| 249 | my $rates = $aerohive->ah_c_txrate($partial) || {}; | ||
| 250 | |||
| 251 | # Every row is kept, even with no usable rate: the client, forwarding | ||
| 252 | # and ARP methods take their keys from this one. | ||
| 253 | my %cd11_txrate; | ||
| 254 | foreach my $idx ( keys %$rates ) { | ||
| 255 | my $kbps = $rates->{$idx}; | ||
| 256 | $cd11_txrate{$idx} | ||
| 257 | = ( defined $kbps and $kbps =~ /^\d+$/ ) ? [ $kbps / 1000 ] : []; | ||
| 258 | } | ||
| 259 | return \%cd11_txrate; | ||
| 260 | } | ||
| 261 | |||
| 262 | sub cd11_port { | ||
| 263 | my $aerohive = shift; | ||
| 264 | |||
| 265 | my $cd11_txrate = $aerohive->cd11_txrate(); | ||
| 266 | my $interfaces = $aerohive->interfaces(); | ||
| 267 | my $wlans = $aerohive->_wlan_radios(); | ||
| 268 | |||
| 269 | my %ret; | ||
| 270 | foreach ( keys %$cd11_txrate ) { | ||
| 271 | my ( $ifindex, $mac ) = _ah_association_index($_); | ||
| 272 | $ret{$_} = $interfaces->{ $wlans->{$ifindex} // $ifindex }; | ||
| 273 | } | ||
| 274 | return \%ret; | ||
| 275 | } | ||
| 276 | |||
| 277 | sub cd11_mac { | ||
| 278 | my $aerohive = shift; | ||
| 279 | |||
| 280 | my $cd11_txrate = $aerohive->cd11_txrate(); | ||
| 281 | |||
| 282 | my %ret; | ||
| 283 | foreach ( keys %$cd11_txrate ) { | ||
| 284 | my ( $ifindex, $mac ) = _ah_association_index($_); | ||
| 285 | $ret{$_} = $mac; | ||
| 286 | } | ||
| 287 | return \%ret; | ||
| 288 | } | ||
| 289 | |||
| 290 | # Does not support the standard Bridge MIB | ||
| 291 | sub bp_index { | ||
| 292 | my $aerohive = shift; | ||
| 293 | my $partial = shift; | ||
| 294 | |||
| 295 | # somewhere caching is doing something strange, without load_ | ||
| 296 | # netdisco can't find bp_index mappings & will not registerer | ||
| 297 | # any clients. netdisco/netdisco#496 | ||
| 298 | my $i_index = $aerohive->load_i_index($partial) || {}; | ||
| 299 | my $wlans = $aerohive->_wlan_radios(); | ||
| 300 | |||
| 301 | my %bp_index; | ||
| 302 | foreach my $iid ( keys %$i_index ) { | ||
| 303 | my $index = $i_index->{$iid}; | ||
| 304 | next unless defined $index; | ||
| 305 | |||
| 306 | $bp_index{$index} = $wlans->{$iid} // $iid; | ||
| 307 | } | ||
| 308 | |||
| 309 | return \%bp_index; | ||
| 310 | } | ||
| 311 | |||
| 312 | sub qb_fw_port { | ||
| 313 | my $aerohive = shift; | ||
| 314 | my $partial = shift; | ||
| 315 | |||
| 316 | my $txrate = $aerohive->cd11_txrate($partial) || {}; | ||
| 317 | |||
| 318 | my $qb_fw_port = {}; | ||
| 319 | foreach my $idx ( keys %$txrate ) { | ||
| 320 | my ( $fdb_id, $mac ) = _ah_association_index($idx); | ||
| 321 | $qb_fw_port->{$idx} = $fdb_id; | ||
| 322 | } | ||
| 323 | return $qb_fw_port; | ||
| 324 | } | ||
| 325 | |||
| 326 | sub qb_fw_mac { | ||
| 327 | my $aerohive = shift; | ||
| 328 | my $partial = shift; | ||
| 329 | |||
| 330 | my $txrate = $aerohive->cd11_txrate($partial) || {}; | ||
| 331 | |||
| 332 | my $qb_fw_mac = {}; | ||
| 333 | foreach my $idx ( keys %$txrate ) { | ||
| 334 | my ( $fdb_id, $mac ) = _ah_association_index($idx); | ||
| 335 | $qb_fw_mac->{$idx} = $mac; | ||
| 336 | } | ||
| 337 | return $qb_fw_mac; | ||
| 338 | } | ||
| 339 | |||
| 340 | sub qb_fw_vlan { | ||
| 341 | my $aerohive = shift; | ||
| 342 | my $partial = shift; | ||
| 343 | |||
| 344 | my $vlans = $aerohive->ah_c_vlan($partial) || {}; | ||
| 345 | |||
| 346 | my $qb_fw_vlan = {}; | ||
| 347 | foreach my $idx ( keys %$vlans ) { | ||
| 348 | my $vlan = $vlans->{$idx}; | ||
| 349 | next unless defined $vlan; | ||
| 350 | $qb_fw_vlan->{$idx} = $vlan; | ||
| 351 | } | ||
| 352 | return $qb_fw_vlan; | ||
| 353 | } | ||
| 354 | |||
| 355 | # arpnip: | ||
| 356 | # | ||
| 357 | # This is the AP snooping on the MAC->IP mappings. | ||
| 358 | # Pretending this is arpnip data allows us to get MAC->IP | ||
| 359 | # mappings even for stations that only communicate locally. | ||
| 360 | |||
| 361 | sub at_paddr { | ||
| 362 | my $aerohive = shift; | ||
| 363 | |||
| 364 | my $txrate = $aerohive->cd11_txrate() || {}; | ||
| 365 | |||
| 366 | my $at_paddr = {}; | ||
| 367 | foreach my $idx ( keys %$txrate ) { | ||
| 368 | my ( $fdb_id, $mac ) = _ah_association_index($idx); | ||
| 369 | $at_paddr->{$idx} = $mac; | ||
| 370 | } | ||
| 371 | return $at_paddr; | ||
| 372 | } | ||
| 373 | |||
| 374 | sub at_netaddr { | ||
| 375 | my $aerohive = shift; | ||
| 376 | |||
| 377 | my $ips = $aerohive->ah_c_ip() || {}; | ||
| 378 | |||
| 379 | my $ret = {}; | ||
| 380 | foreach my $idx ( keys %$ips ) { | ||
| 381 | next if ( $ips->{$idx} eq '0.0.0.0' ); | ||
| 382 | $ret->{$idx} = $ips->{$idx}; | ||
| 383 | } | ||
| 384 | return $ret; | ||
| 385 | } | ||
| 386 | |||
| 387 | 1; | ||
| 388 | |||
| 389 | __END__ |