mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added initial IPv6 Address discovery for TP-LINK Jetstream (#13484)
* Added initial IPv6 Address discovery for TP-LINK Jetstream * styleci cleanup * styleci cleanup * styleci cleanup * split OS specific code in separate file * styleci cleanup
This commit is contained in:
@@ -1,51 +1,57 @@
|
||||
<?php
|
||||
|
||||
use LibreNMS\Config;
|
||||
|
||||
foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
|
||||
$device['context_name'] = $context_name;
|
||||
|
||||
$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', ['-Osq', '-Ln'], 'IP-MIB');
|
||||
$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids);
|
||||
$oids = str_replace('"', '', $oids);
|
||||
$oids = str_replace('IP-MIB::', '', $oids);
|
||||
$oids = trim($oids);
|
||||
if (file_exists(Config::get('install_dir') . "/includes/discovery/ipv6-addresses/{$device['os']}.inc.php")) {
|
||||
include Config::get('install_dir') . "/includes/discovery/ipv6-addresses/{$device['os']}.inc.php";
|
||||
} else {
|
||||
$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', ['-Osq', '-Ln'], 'IP-MIB');
|
||||
$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids);
|
||||
$oids = str_replace('"', '', $oids);
|
||||
$oids = str_replace('IP-MIB::', '', $oids);
|
||||
$oids = trim($oids);
|
||||
|
||||
foreach (explode("\n", $oids) as $data) {
|
||||
if ($data) {
|
||||
$data = trim($data);
|
||||
[$ipv6addr,$ifIndex] = explode(' ', $data);
|
||||
$oid = '';
|
||||
$sep = '';
|
||||
$adsep = '';
|
||||
unset($ipv6_address);
|
||||
$do = '0';
|
||||
foreach (explode(':', $ipv6addr) as $part) {
|
||||
$n = hexdec($part);
|
||||
$oid = "$oid" . "$sep" . "$n";
|
||||
$sep = '.';
|
||||
$ipv6_address = $ipv6_address . "$adsep" . $part;
|
||||
$do++;
|
||||
if ($do == 2) {
|
||||
$adsep = ':';
|
||||
$do = '0';
|
||||
} else {
|
||||
$adsep = '';
|
||||
foreach (explode("\n", $oids) as $data) {
|
||||
if ($data) {
|
||||
$data = trim($data);
|
||||
[$ipv6addr,$ifIndex] = explode(' ', $data);
|
||||
$oid = '';
|
||||
$sep = '';
|
||||
$adsep = '';
|
||||
unset($ipv6_address);
|
||||
$do = '0';
|
||||
foreach (explode(':', $ipv6addr) as $part) {
|
||||
$n = hexdec($part);
|
||||
$oid = "$oid" . "$sep" . "$n";
|
||||
$sep = '.';
|
||||
$ipv6_address = $ipv6_address . "$adsep" . $part;
|
||||
$do++;
|
||||
if ($do == 2) {
|
||||
$adsep = ':';
|
||||
$do = '0';
|
||||
} else {
|
||||
$adsep = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB');
|
||||
$ipv6_prefixlen = explode('.', $ipv6_prefixlen);
|
||||
$ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen));
|
||||
$ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB');
|
||||
$ipv6_prefixlen = explode('.', $ipv6_prefixlen);
|
||||
$ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen));
|
||||
|
||||
if (Str::contains($ipv6_prefixlen, 'SNMPv2-SMI::zeroDotZero')) {
|
||||
d_echo('Incomplete IPv6 data in IF-MIB');
|
||||
$oids = trim(Str::replaceFirst($data, '', $oids));
|
||||
}
|
||||
if (Str::contains($ipv6_prefixlen, 'SNMPv2-SMI::zeroDotZero')) {
|
||||
d_echo('Incomplete IPv6 data in IF-MIB');
|
||||
$oids = trim(Str::replaceFirst($data, '', $oids));
|
||||
}
|
||||
|
||||
$ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB');
|
||||
$ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB');
|
||||
|
||||
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']);
|
||||
} //end if
|
||||
} //end foreach
|
||||
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']);
|
||||
} //end if
|
||||
} //end foreach
|
||||
} //end 'else'
|
||||
|
||||
if (empty($oids)) {
|
||||
$oids = snmp_walk($device, 'ipv6AddrPfxLength', ['-OsqnU', '-Ln'], 'IPV6-MIB');
|
||||
|
44
includes/discovery/ipv6-addresses/jetstream.inc.php
Normal file
44
includes/discovery/ipv6-addresses/jetstream.inc.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* jetstream.inc.php
|
||||
*
|
||||
* IPv6 address discovery file for Jetstream OS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @link https://www.librenms.org
|
||||
*
|
||||
* @author Peca Nesovanovic <peca.nesovanovic@sattrakt.com>
|
||||
*/
|
||||
$oids = snmp_walk($device, 'ipv6ParaConfigAddrTable', ['-OsQ', '-Ln', '-Cc'], 'TPLINK-IPV6ADDR-MIB');
|
||||
$oids = trim($oids);
|
||||
$v6data = [];
|
||||
foreach (explode("\n", $oids) as $data) {
|
||||
$param = explode('.', $data)[0];
|
||||
$index = explode('.', $data)[1]; //iFindex
|
||||
$atype = explode('.', $data)[3];
|
||||
$erase = $param . '.' . $index . '.ipv6.' . $atype . '.'; //this will be erased from line
|
||||
$link = trim(explode('=', str_replace($erase, '', $data))[0]);
|
||||
$value = trim(explode('=', $data)[1]);
|
||||
if ($param == 'ipv6ParaConfigAddress') {
|
||||
$v6data[$link]['index'] = $index;
|
||||
$split = str_split(str_replace(' ', '', strtolower($value)), 4); //convert space delimited hex IPv6 address to array, every forth char
|
||||
$v6data[$link]['addr'] = implode(':', $split); //assemble array in 0000:1111 format
|
||||
$v6data[$link]['origin'] = ($atype == 'autoIp' ? 'linklayer' : 'manual'); //address type
|
||||
}
|
||||
if ($param == 'ipv6ParaConfigPrefixLength') {
|
||||
$prefixlen = intval($value);
|
||||
discover_process_ipv6($valid, $v6data[$link]['index'], $v6data[$link]['addr'], $prefixlen, $v6data[$link]['origin'], $device['context_name']);
|
||||
}
|
||||
} //end foreach
|
Reference in New Issue
Block a user