Skip to content

ospf6d: Fix OSPFv3 SNMP interface state mapping #18697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

miteshkanjariya
Copy link

@miteshkanjariya miteshkanjariya commented Apr 21, 2025

The OSPFv3 SNMP implementation was incorrectly returning internal state values directly without mapping them to the OSPFv3 MIB state values defined in RFC 5643. This caused a mismatch between the SNMP output and the actual interface states.

Added a mapping function to convert internal OSPFv3 interface states to their corresponding OSPFv3 MIB state values:

  • OSPF6_INTERFACE_DOWN (1) -> down(1)
  • OSPF6_INTERFACE_LOOPBACK (2) -> loopback(2)
  • OSPF6_INTERFACE_WAITING (3) -> waiting(3)
  • OSPF6_INTERFACE_POINTTOPOINT (4) -> pointToPoint(4)
  • OSPF6_INTERFACE_DR (7) -> designatedRouter(5)
  • OSPF6_INTERFACE_BDR (6) -> backupDesignatedRouter(6)
  • OSPF6_INTERFACE_DROTHER (5) -> otherDesignatedRouter(7)

This ensures that SNMP queries return the correct state values according to the OSPFv3 MIB specification.

Ticket: #4402285
Ticket: #4362862

UT:

before the fix:

root@uut# snmpwalk -v2c -c public localhost 1.3.6.1.2.1.191 | grep IfState

OSPFV3-MIB::ospfv3IfState.3.0 = INTEGER: otherDesignatedRouter(7)
OSPFV3-MIB::ospfv3IfState.4.0 = INTEGER: otherDesignatedRouter(7)
OSPFV3-MIB::ospfv3IfState.5.0 = INTEGER: standby(8)

root@uut:mgmt# vtysh -c "show ipv6 ospf interface swp1 json" 
{
  "swp1":{
    "status":"up",
    "type":"BROADCAST",
    "interfaceId":3,
    "internetAddress":[
      {
        "type":"inet6",
        "address":"2000:1000:1000:1000::2/80"
      },
      {
        "type":"inet6",
        "address":"fe80::202:ff:fe00:c/64"
      }
    ],
    "attachedToArea":true,
    "instanceId":0,
    "interfaceMtu":9216,
    "autoDetect":9216,
    "mtuMismatchDetection":"enabled",
    "areaId":"0.0.0.0",
    "cost":10,
    "ospf6InterfaceState":"BDR",
    "transmitDelaySec":1,
    "priority":1,
    "timerIntervalsConfigHello":10,
    "timerIntervalsConfigDead":40,
    "timerIntervalsConfigRetransmit":5,
    "timerPassiveIface":false,
    "dr":"0.0.0.5",
    "bdr":"0.0.0.8",
    "numberOfInterfaceScopedLsa":2,
    "pendingLsaLsUpdateCount":0,
    "pendingLsaLsUpdateTime":"00:00:00",
    "lsUpdateSendThread":"off",
    "pendingLsaLsUpdate":[
    ],
    "pendingLsaLsAckCount":0,
    "pendingLsaLsAckTime":"00:00:00",
    "lsAckSendThread":"off",
    "pendingLsaLsAck":[
    ],
    "grHelloDelaySecs":10,
    "authInfo":{
      "authType":"NULL"
    }
  }
}
root@uut# vtysh -c "show ipv6 ospf interface swp2 json" 
{
  "swp2":{
    "status":"up",
    "type":"BROADCAST",
    "interfaceId":4,
    "internetAddress":[
      {
        "type":"inet6",
        "address":"3000:1000:1000:1000::1/80"
      },
      {
        "type":"inet6",
        "address":"fe80::202:ff:fe00:d/64"
      }
    ],
    "attachedToArea":true,
    "instanceId":0,
    "interfaceMtu":9216,
    "autoDetect":9216,
    "mtuMismatchDetection":"enabled",
    "areaId":"0.0.0.1",
    "cost":10,
    "ospf6InterfaceState":"BDR",
    "transmitDelaySec":1,
    "priority":1,
    "timerIntervalsConfigHello":10,
    "timerIntervalsConfigDead":40,
    "timerIntervalsConfigRetransmit":5,
    "timerPassiveIface":false,
    "dr":"0.0.0.7",
    "bdr":"0.0.0.8",
    "numberOfInterfaceScopedLsa":2,
    "pendingLsaLsUpdateCount":0,
    "pendingLsaLsUpdateTime":"00:00:00",
    "lsUpdateSendThread":"off",
    "pendingLsaLsUpdate":[
    ],
    "pendingLsaLsAckCount":0,
    "pendingLsaLsAckTime":"00:00:00",
    "lsAckSendThread":"off",
    "pendingLsaLsAck":[
    ],
    "grHelloDelaySecs":10,
    "authInfo":{
      "authType":"NULL"
    }
  }
}
root@uut# vtysh -c "show ipv6 ospf interface swp3 json" 
{
  "swp3":{
    "status":"up",
    "type":"BROADCAST",
    "interfaceId":5,
    "internetAddress":[
      {
        "type":"inet6",
        "address":"3000:1000:1000:1000:1::1/80"
      },
      {
        "type":"inet6",
        "address":"fe80::202:ff:fe00:e/64"
      }
    ],
    "attachedToArea":true,
    "instanceId":0,
    "interfaceMtu":9216,
    "autoDetect":9216,
    "mtuMismatchDetection":"enabled",
    "areaId":"0.0.0.1",
    "cost":10,
    "ospf6InterfaceState":"DR",
    "transmitDelaySec":1,
    "priority":1,
    "timerIntervalsConfigHello":10,
    "timerIntervalsConfigDead":40,
    "timerIntervalsConfigRetransmit":5,
    "timerPassiveIface":false,
    "dr":"0.0.0.8",
    "bdr":"0.0.0.0",
    "numberOfInterfaceScopedLsa":1,
    "pendingLsaLsUpdateCount":0,
    "pendingLsaLsUpdateTime":"00:00:00",
    "lsUpdateSendThread":"off",
    "pendingLsaLsUpdate":[
    ],
    "pendingLsaLsAckCount":0,
    "pendingLsaLsAckTime":"00:00:00",
    "lsAckSendThread":"off",
    "pendingLsaLsAck":[
    ],
    "grHelloDelaySecs":10,
    "authInfo":{
      "authType":"NULL"
    }
  }
}
root@uut# 

After the fix:

root@uut# snmpwalk -v2c -c public localhost 1.3.6.1.2.1.191 | grep IfState

OSPFV3-MIB::ospfv3IfState.3.0 = INTEGER: backupDesignatedRouter(6)
OSPFV3-MIB::ospfv3IfState.4.0 = INTEGER: backupDesignatedRouter(6)
OSPFV3-MIB::ospfv3IfState.5.0 = INTEGER: designatedRouter(5)

root@uut# vtysh -c "show ipv6 ospf interface swp1 json" 
{
  "swp1":{
    "status":"up",
    "type":"BROADCAST",
    "interfaceId":3,
    "internetAddress":[
      {
        "type":"inet6",
        "address":"2000:1000:1000:1000::2/80"
      },
      {
        "type":"inet6",
        "address":"fe80::202:ff:fe00:c/64"
      }
    ],
    "attachedToArea":true,
    "instanceId":0,
    "interfaceMtu":9216,
    "autoDetect":9216,
    "mtuMismatchDetection":"enabled",
    "areaId":"0.0.0.0",
    "cost":10,
    "ospf6InterfaceState":"BDR",
    "transmitDelaySec":1,
    "priority":1,
    "timerIntervalsConfigHello":10,
    "timerIntervalsConfigDead":40,
    "timerIntervalsConfigRetransmit":5,
    "timerPassiveIface":false,
    "dr":"0.0.0.5",
    "bdr":"0.0.0.8",
    "numberOfInterfaceScopedLsa":2,
    "pendingLsaLsUpdateCount":0,
    "pendingLsaLsUpdateTime":"00:00:00",
    "lsUpdateSendThread":"off",
    "pendingLsaLsUpdate":[
    ],
    "pendingLsaLsAckCount":0,
    "pendingLsaLsAckTime":"00:00:00",
    "lsAckSendThread":"off",
    "pendingLsaLsAck":[
    ],
    "grHelloDelaySecs":10,
    "authInfo":{
      "authType":"NULL"
    }
  }
}
root@uut# vtysh -c "show ipv6 ospf interface swp2 json" 
{
  "swp2":{
    "status":"up",
    "type":"BROADCAST",
    "interfaceId":4,
    "internetAddress":[
      {
        "type":"inet6",
        "address":"3000:1000:1000:1000::1/80"
      },
      {
        "type":"inet6",
        "address":"fe80::202:ff:fe00:d/64"
      }
    ],
    "attachedToArea":true,
    "instanceId":0,
    "interfaceMtu":9216,
    "autoDetect":9216,
    "mtuMismatchDetection":"enabled",
    "areaId":"0.0.0.1",
    "cost":10,
    "ospf6InterfaceState":"BDR",
    "transmitDelaySec":1,
    "priority":1,
    "timerIntervalsConfigHello":10,
    "timerIntervalsConfigDead":40,
    "timerIntervalsConfigRetransmit":5,
    "timerPassiveIface":false,
    "dr":"0.0.0.7",
    "bdr":"0.0.0.8",
    "numberOfInterfaceScopedLsa":2,
    "pendingLsaLsUpdateCount":0,
    "pendingLsaLsUpdateTime":"00:00:00",
    "lsUpdateSendThread":"off",
    "pendingLsaLsUpdate":[
    ],
    "pendingLsaLsAckCount":0,
    "pendingLsaLsAckTime":"00:00:00",
    "lsAckSendThread":"off",
    "pendingLsaLsAck":[
    ],
    "grHelloDelaySecs":10,
    "authInfo":{
      "authType":"NULL"
    }
  }
}
root@uut# vtysh -c "show ipv6 ospf interface swp3 json" 
{
  "swp3":{
    "status":"up",
    "type":"BROADCAST",
    "interfaceId":5,
    "internetAddress":[
      {
        "type":"inet6",
        "address":"3000:1000:1000:1000:1::1/80"
      },
      {
        "type":"inet6",
        "address":"fe80::202:ff:fe00:e/64"
      }
    ],
    "attachedToArea":true,
    "instanceId":0,
    "interfaceMtu":9216,
    "autoDetect":9216,
    "mtuMismatchDetection":"enabled",
    "areaId":"0.0.0.1",
    "cost":10,
    "ospf6InterfaceState":"DR",
    "transmitDelaySec":1,
    "priority":1,
    "timerIntervalsConfigHello":10,
    "timerIntervalsConfigDead":40,
    "timerIntervalsConfigRetransmit":5,
    "timerPassiveIface":false,
    "dr":"0.0.0.8",
    "bdr":"0.0.0.0",
    "numberOfInterfaceScopedLsa":1,
    "pendingLsaLsUpdateCount":0,
    "pendingLsaLsUpdateTime":"00:00:00",
    "lsUpdateSendThread":"off",
    "pendingLsaLsUpdate":[
    ],
    "pendingLsaLsAckCount":0,
    "pendingLsaLsAckTime":"00:00:00",
    "lsAckSendThread":"off",
    "pendingLsaLsAck":[
    ],
    "grHelloDelaySecs":10,
    "authInfo":{
      "authType":"NULL"
    }
  }
}
root@uut#


The OSPFv3 SNMP implementation was incorrectly returning internal state
values directly without mapping them to the OSPFv3 MIB state values
defined in RFC 5643. This caused a mismatch between the SNMP output
and the actual interface states.

Added a mapping function to convert internal OSPFv3 interface states
to their corresponding OSPFv3 MIB state values:
- OSPF6_INTERFACE_DOWN (1) -> down(1)
- OSPF6_INTERFACE_LOOPBACK (2) -> loopback(2)
- OSPF6_INTERFACE_WAITING (3) -> waiting(3)
- OSPF6_INTERFACE_POINTTOPOINT (4) -> pointToPoint(4)
- OSPF6_INTERFACE_DR (7) -> designatedRouter(5)
- OSPF6_INTERFACE_BDR (6) -> backupDesignatedRouter(6)
- OSPF6_INTERFACE_DROTHER (5) -> otherDesignatedRouter(7)

This ensures that SNMP queries return the correct state values
according to the OSPFv3 MIB specification.

Ticket: #4402285
Ticket: #4362862

Signed-off-by: Mitesh Kanjariya <[email protected]>
Copy link
Member

@riw777 riw777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

{
switch (state) {
case OSPF6_INTERFACE_DOWN:
return 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have actual defines returned?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to return it this way instead of returning actual # defines for the matching ones and magic number for the not-matching ones.

Alternatively, we could create new define for SNMP and return those
for example #OSPFV6_INTERFACE_DOWN_SNMP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants