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:
Peca Nesovanovic 2021-11-09 20:40:48 +01:00 committed by GitHub
parent 3fbe1c9aa1
commit 9f2de7d605
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9266 additions and 37 deletions

View File

@ -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');

View 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

View File

@ -0,0 +1,276 @@
TPLINK-IPV6ADDR-MIB DEFINITIONS ::= BEGIN
IMPORTS
RowStatus, DisplayString
FROM SNMPv2-TC
tplinkMgmt
FROM TPLINK-MIB
OBJECT-TYPE,IpAddress
FROM SNMPv2-SMI
InetAddress, InetAddressType
FROM INET-ADDRESS-MIB;
tplinkIpv6AddrMIB MODULE-IDENTITY
LAST-UPDATED "201512130930Z"
ORGANIZATION "TPLINK"
CONTACT-INFO "www.tplink.com"
DESCRIPTION "Private MIB for IPv6 address configuration."
REVISION "201212130930Z"
DESCRIPTION
"Initial version of this MIB module."
::= { tplinkMgmt 50 }
tplinkIpv6AddrMIBObjects OBJECT IDENTIFIER ::= { tplinkIpv6AddrMIB 1 }
tplinkIpv6RoutingConfig OBJECT IDENTIFIER ::= { tplinkIpv6AddrMIB 2 }
tplinkIpv6AddrNotifications OBJECT IDENTIFIER ::= { tplinkIpv6AddrMIB 3 }
ipv6ParaConfigAddrTable OBJECT-TYPE
SYNTAX SEQUENCE OF Ipv6ParaConfigAddrEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"The table of address information is relevant to the
switch's IPv6 addresses."
::= { tplinkIpv6AddrMIBObjects 1 }
ipv6ParaConfigAddrEntry OBJECT-TYPE
SYNTAX Ipv6ParaConfigAddrEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"Define the IPv6 address information."
INDEX
{
ipv6ParaConfigIfIndex,
ipv6ParaConfigAddrType,
ipv6ParaConfigSourceType,
ipv6ParaConfigAddress
}
::= { ipv6ParaConfigAddrTable 1 }
Ipv6ParaConfigAddrEntry ::=
SEQUENCE
{
ipv6ParaConfigIfIndex INTEGER,
ipv6ParaConfigIfDescription DisplayString,
ipv6ParaConfigAddrType InetAddressType,
ipv6ParaConfigAddress InetAddress,
ipv6ParaConfigPrefixLength INTEGER(1..128),
ipv6ParaConfigSourceType INTEGER,
ipv6ParaConfigRowStatus RowStatus
}
ipv6ParaConfigIfIndex OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The IfIndex of the interface"
::= { ipv6ParaConfigAddrEntry 1 }
ipv6ParaConfigIfDescription OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The description of the interface."
::= { ipv6ParaConfigAddrEntry 2 }
ipv6ParaConfigAddrType OBJECT-TYPE
SYNTAX InetAddressType
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The IP address type of the switch. The value must be ipv6."
::= { ipv6ParaConfigAddrEntry 3 }
ipv6ParaConfigAddress OBJECT-TYPE
SYNTAX InetAddress
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The IPv6 address of the switch."
::= { ipv6ParaConfigAddrEntry 4 }
ipv6ParaConfigPrefixLength OBJECT-TYPE
SYNTAX INTEGER(1..128)
MAX-ACCESS read-create
STATUS current
DESCRIPTION
"The length of the prefix (in bits) associated with
the IPv6 address of the switch."
::= { ipv6ParaConfigAddrEntry 5 }
ipv6ParaConfigSourceType OBJECT-TYPE
SYNTAX INTEGER
{
assignedIp(1),
assignedEUI64Ip(2),
assignedLinklocalIp(3),
autoIp(4),
dhcpv6(5),
negotiate(6)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Indicate the type of source of IPv6 address.
The value can be one of following:
'assignedIp':
Assigned global/site-local IPv6 address;
'assignedEUI64Ip':
Assigned global/site-local IPv6 address
by using EUI-64 interface identifier;
'assignedLinklocalIp':
Assigned link-local IPv6 address.
'autoIp':
Auto generated IPv6 address as a result
of non-linklocal anycast/unicast address
configuration;
'dhcpv6':
Assigned IPv6 address through DHCPv6
protocol;
'negotiate':
Assigned IPv6 address through negotiation;"
::= { ipv6ParaConfigAddrEntry 6 }
ipv6ParaConfigRowStatus OBJECT-TYPE
SYNTAX RowStatus
MAX-ACCESS read-create
STATUS current
DESCRIPTION
"the following values are states:
these values may be used as follow:
active(1),if the entry is being used.
notInService(2),destory the entry.
notReady(3),destory the entry.
createAndGo(4),not being used
createAndWait(5),creat a new entry
destroy(6),destory the entry.
When you create a new user,the default password
is admin."
::= { ipv6ParaConfigAddrEntry 7 }
ipv6ParaConfigCfgTable OBJECT-TYPE
SYNTAX SEQUENCE OF Ipv6ParaConfigCfgEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"The table of configuration information is relevant to the
switch's IPv6 addresses."
::= { tplinkIpv6AddrMIBObjects 2 }
ipv6ParaConfigCfgEntry OBJECT-TYPE
SYNTAX Ipv6ParaConfigCfgEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"Define the IPv6 address information."
INDEX
{
ipv6ParaConfigCfgIfIndex
}
::= { ipv6ParaConfigCfgTable 1 }
Ipv6ParaConfigCfgEntry ::=
SEQUENCE
{
ipv6ParaConfigCfgIfIndex INTEGER,
ipv6ParaConfigCfgIfDescription DisplayString,
ipv6ParaConfigAutoLinkLocalEnable INTEGER,
ipv6ParaConfigDhcpEnable INTEGER,
ipv6ParaConfigNegotiateEnable INTEGER,
ipv6ParaConfigIPv6Enable INTEGER
}
ipv6ParaConfigCfgIfIndex OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The IfIndex of the interface"
::= { ipv6ParaConfigCfgEntry 1 }
ipv6ParaConfigCfgIfDescription OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The description of the interface."
::= { ipv6ParaConfigCfgEntry 2 }
ipv6ParaConfigAutoLinkLocalEnable OBJECT-TYPE
SYNTAX INTEGER{
disable(0),
enable(1)
}
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"0. disable
1. enable
Enable/Disable IPv6 link-local address auto configuration mode."
::= { ipv6ParaConfigCfgEntry 3 }
ipv6ParaConfigDhcpEnable OBJECT-TYPE
SYNTAX INTEGER{
disable(0),
enable(1)
}
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"0. disable
1. enable
Enable/Disable IPv6 global address auto configuration via DHCPv6 Server."
::= { ipv6ParaConfigCfgEntry 4 }
ipv6ParaConfigNegotiateEnable OBJECT-TYPE
SYNTAX INTEGER{
disable(0),
enable(1)
}
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"0. disable
1. enable
Enable/Disable IPv6 global address auto configuration via RA message."
::= { ipv6ParaConfigCfgEntry 5 }
ipv6ParaConfigIPv6Enable OBJECT-TYPE
SYNTAX INTEGER{
disable(0),
enable(1)
}
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"0. disable
1. enable
Enable/Disable IPv6 function on the interface of switch."
::= { ipv6ParaConfigCfgEntry 6 }
ipv6GatewayConfig OBJECT IDENTIFIER ::= {tplinkIpv6AddrMIBObjects 3}
ipv6Gateway OBJECT-TYPE
SYNTAX OCTET STRING(SIZE(46))
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"The gateway of the ipv6 interface. Set '0' to delete the gateway."
::= { ipv6GatewayConfig 1 }
tpIpv6Routing OBJECT-TYPE
SYNTAX INTEGER{
disable(0),
enable(1)
}
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"0. disable
1. enable"
::= { tplinkIpv6RoutingConfig 1 }
END

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff