Skip to content
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

gosnmp sets SnmpPDU.Value to nil when type is Bitstring #1216

Closed
nathanlcarlson opened this issue Jul 15, 2024 · 4 comments
Closed

gosnmp sets SnmpPDU.Value to nil when type is Bitstring #1216

nathanlcarlson opened this issue Jul 15, 2024 · 4 comments
Labels

Comments

@nathanlcarlson
Copy link

Host operating system: output of uname -a

Docker on Mac

Linux cc14ccb5bd57 6.6.31-linuxkit #1 SMP PREEMPT_DYNAMIC Wed Jun 5 07:37:32 UTC 2024 x86_64 GNU/Linux

snmp_exporter version: output of snmp_exporter -version

snmp_exporter, version 0.24.0 (branch: HEAD, revision: c9fd025)
build user: root@fb4e1a1f31ed
build date: 20230829-12:20:02
go version: go1.21.0
platform: linux/amd64
tags: netgo

What device/snmpwalk OID are you using?

Two switches, "Switch A" and "Switch B" that are from separate manufacturers with separate OS's.
dot3adAggPortActorAdminState
dot3adAggPortActorOperState
1.2.840.10006.300.43.1.2.1.1.21 and 1.2.840.10006.300.43.1.2.1.1.23

If this is a new device, please link to the MIB(s).

https://github.com/librenms/librenms/blob/04101c2c6f7411b2f882b5ea05c6a5c1ef77cff5/mibs/IEEE8023-LAG-MIB

What did you do that produced an error?

modules:
  dot3ad:
    walk:
      - dot3adAggPortActorOperState
      - dot3adAggPortPartnerOperState
    lookups:
      - source_indexes: [dot3adAggPortIndex]
        lookup: dot3adAggPortActorSystemID
      - source_indexes: [dot3adAggPortIndex]
        lookup: dot3adAggPortActorPort
      - source_indexes: [dot3adAggPortIndex]
        lookup: dot3adAggPortSelectedAggID
      - source_indexes: [dot3adAggPortIndex]
        lookup: dot3adAggPortPartnerOperSystemID
      - source_indexes: [dot3adAggPortIndex]
        lookup: dot3adAggPortPartnerOperPort

What did you expect to see?

This worked as expected on Switch A, following the Bits support code in this exporter. It created a StateSet.

What did you see instead?

Switch B fails, reporting the following:

* error collecting metric Desc{fqName: "snmp_error", help: "BITS type was not a BISTRING on the wire.", constLabels: {}, variableLabels: []}: error for metric dot3adAggPortPartnerOperState with labels [{expected labels}]: <nil>

More investigation found that the switches report this OID as different types.
Switch A, that succeeds, reports a String:

$ snmpget -DALL -v 2c -c {community string} {host A}  1.2.840.10006.300.43.1.2.1.1.23.{index}
...
dumph_recv:         Value
dumpx_recv:          04 01 3D 
dumpv_recv:            String:	=
...

Switch B, that fails, reports a Bitstring:

$ snmpget -DALL -v 2c -c {community string} {host B} 1.2.840.10006.300.43.1.2.1.1.23.{index}
...
dumph_recv:         Value
dumpx_recv:          03 01 
dumpv_recv:            Bitstring: 03 
...

I created this issue gosnmp/gosnmp#472 as I'm not sure where this should be addressed.

@SuperQ SuperQ added the bug label Jul 15, 2024
@SuperQ
Copy link
Member

SuperQ commented Jul 15, 2024

Yes, I think this may need to be fixed upstream first.

@nathanlcarlson
Copy link
Author

I've done some more learning and think this may be more of a bug with Switch B. BITS "types" (not the ANS.1 Bitstring type, but rather an SNMP "construct", https://datatracker.ietf.org/doc/html/rfc1906#section-8 ) are meant to be encoded and reported as the ASN.1 Octet String type. Switch B seems to report the encoding type as 0x03, Bitstring, but then proceed to encode it as an Octet String. Somehow snmpget figures this out though, somewhere in here probably https://github.com/net-snmp/net-snmp/blob/master/snmplib/mib.c#L1809 . It is probably desirable for gosnmp to behave similarly, handling Bitstring as Octet String.

@nathanlcarlson
Copy link
Author

I'm not great with C, but it looks like this is where ASN Bitstring is parsed: https://github.com/net-snmp/net-snmp/blob/90a70ebd82ae1b545e7a58c1b3eb10981cb85adc/snmplib/asn1.c#L1824 . Doing some tracing on Switch B's output through this makes it seem like that Bitstring parsing code isn't that careful and essentially treats Bitstrings as Octet Strings.

Tracing that function also explains why Switch B reports Bitstring: 03 in the debug output when the actual BITS data is 3E. It is (unintentionally) just reporting 0x03, the Bitstring type code.

@nathanlcarlson
Copy link
Author

It seems the ASN.1 Bitstring type has no place, officially, in SNMP. Encoding a BITS construct as anything other than an Octet String is incorrect. It just happens to be that netsnmp (kind of) handles it. I'll close this and the other issue as I'm reasonably confident this is simply incorrect behavior from the switch.

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

No branches or pull requests

2 participants