Repository: librenms/librenms (language: php)

Issue:
Loss of VRF's on Cisco 89x Routers after upgrade
### The problem

Since the update from 24.2.0 to 24.8.0 the interface data in LNMS of our 89x Cisco IOS Routers do not contain the vrf anymore although the configuration of the router did not change and the vrf's are still configured. This affects several 100 routers ...

### Output of ./validate.php

```txt
As an example we have a 892 Cisco Router that has the following configuration:
02.r.pap.ch.sahb.ce#sh run int vlan10
Building configuration...

Current configuration : 467 bytes
!
interface Vlan10
description {RPN2107}
vrf forwarding UCO_SAHB_LAN
ip address 192.168.61.253 255.255.255.0
ip access-group iACL_NTS in
ip helper-address 10.10.50.10
ip helper-address 10.10.50.11
no ip redirects
no ip unreachables
no ip proxy-arp
standby version 2
standby 10 ip 192.168.61.254
standby 10 priority 90
standby 10 preempt
standby 10 authentication md5 key-string 7 08146F61362A243F3034202504
ip tcp adjust-mss 1260
arp timeout 300
end

02.r.pap.ch.sahb.ce#exit

If we do a discovery we get this vrf specific raw data:

Load disco module vrf ####



[VRF ] OID - .1.3.6.1.3.118.1.2.2.1.4.12.85.67.79.95.83.65.72.66.95.76.65.78
[VRF ] RD - 0:0:00:44.04
[VRF ] DESC -
[VRF ] PORTS -
.

    > Runtime for discovery module 'vrf': 0.2840 seconds with 2256 bytes
    > SNMP: [4/0.28s] MySQL: [5/0.01s] InfluxDB: [0/0.00s] RRD: [0/0.00s] 

Unload disco module vrf ####


and the api call for the corresponding interface (shortened):
https://librenms.nts.ch/api/v0/ports/12278
{
"status": "ok",
"port": [
{
"port_id": 12278,
"device_id": 117,
"ifDescr": "Vlan10",
"ifName": "Vl10",
"ifAlias": "{RPN2107}",
"ifVrf": 0,
"poll_time": 1727774165,
"poll_prev": 1727773865,
"poll_period": 300
}
],
"count": 1
}

The vrf information is not retrieved anymore ... But in the former LNMS version this worked flawlessly.

The same procedure as above for a Cisco 1100 IOS XE Router with same configuration:

raw data:
Load disco module vrf ####



[VRF UCO_SAHB_LAN] OID - 1
[VRF UCO_SAHB_LAN] RD -
[VRF UCO_SAHB_LAN] DESC -
[VRF UCO_SAHB_LAN] PORTS - Gi0/0/0.34422003 Gi0/0/0.34422004 Vlan10
....

https://librenms.nts.ch/api/v0/ports/78264

{
"status": "ok",
"port": [
{
"port_id": 78264,
"device_id": 1511,
"ifDescr": "Vlan10",
"ifName": "Vl10",
"ifAlias": "{RPN2107} VRF:UCO_SAHB_LAN #HSRP",
"ifVrf": 3840,
"poll_time": 1727773991,
"poll_prev": 1727773692,
"poll_period": 299
}
],
"count": 1
}
As one can see, the vrf information is correctly retrieved.
```


### What was the last working version of LibreNMS?

24.2.0

### Anything in the logs that might be useful for us?

_No response_


Discussion / hints:
Can you add a screen shot of what you see in the UI with the filtering options in the menu shown?
Hi  
Thank you to get in touch! I hope i understand right:  
![Selection_20241002_001](https://github.com/user-attachments/assets/fb3d52a2-f6bf-4ac3-a1e4-8159c48a62e4)  
Interface VLAN 10 is configured in a VRF  
Please let me know, if you need another Screenshot

Further you can see two CPEs (active/backup Setup) which should have the equal VRFs configured:
Cisco C89x Router without any VRF:  
![No_VRF](https://github.com/user-attachments/assets/6d6b1778-8ffd-45e9-b681-4ca44bd5907f)  

Cisco IST11xx Router with correct VRF:  
![VRF_exists](https://github.com/user-attachments/assets/df1ec4b1-c67d-41e6-a43d-ca1f0f1c1365)  


LibreNMS should use the exact same code for both models... I wonder what is different?
Do you have a SNMP OID, which is used for the VRF query?  
So i can try with a manual request on Cisco C89x Routers, and of course on ISR11xx Router as well
Run discovery with -d (and -v to show private info) and it will show you every snmp query LibreNMS makes.
I've attached both variants: C897 with not displayed VRF and ISR11xx with displayed VRFs:

**OK** - ISR11xx
[discovery_Cisco_ISR11xx_VRF_is_displayed.txt](https://github.com/user-attachments/files/17256471/discovery_Cisco_ISR11xx_VRF_is_displayed.txt)

**Not OK** - C897
[discovery_Cisco_C897_VRF_not_displayed.txt](https://github.com/user-attachments/files/17256472/discovery_Cisco_C897_VRF_not_displayed.txt)

From my Point of view, i can not see any VRF requests in both of the files!  
I found the responsible rows, and will now go ahead for a PR. 



Fix patch:
diff --git a/includes/discovery/vrf.inc.php b/includes/discovery/vrf.inc.php
index a86bfd17f330..fbc34eb5e299 100644
--- a/includes/discovery/vrf.inc.php
+++ b/includes/discovery/vrf.inc.php
@@ -21,7 +21,8 @@
         if (empty($rds)) {
             $rds = snmp_walk($device, 'mplsVpnVrfRouteDistinguisher', '-Osqn', 'MPLS-VPN-MIB', null);
 
-            if (empty($rds) && $device['os_group'] == 'cisco') {
+            // Cisco Catalyst C800 Routers does not correct answer on SNMP OID 'mplsVpnVrfRouteDistinguisher'
+            if ((empty($rds) || (substr($device['hardware'], 0, 2) == 'C8' && $device['os'] == 'ios')) && $device['os_group'] == 'cisco') {
                 // Use CISCO-VRF-MIB if others don't work
                 $rds = snmp_walk($device, 'cvVrfName', '-Osqn', 'CISCO-VRF-MIB', null);
                 $rds = str_replace('.1.3.6.1.4.1.9.9.711.1.1.1.1.2.', '', $rds);


Test patch: