[PATCH] RFC1213-MIB::atTable indices are not encoded/resolved correctly
See original GitHub issueVersion: Branch master at commit 0f32c00d89eae2f86b2282ffc50805e059be5492
pysnmp/smi/mibs/RFC1213-MIB.py defines the atNetAddress
index of atTable
erroneously as IpAddress
, while the correct type is NetworkAddress
. Since the two types have different OID encoding (NetworkAddress
is equivalent to the modern InetAddressType
-InetAddress
combo and has an extra octet at the beginning which specifies the address type), PySNMP fails to encode or decode atNetAddress
index.
To reproduce:
import pysnmp.debug
from pysnmp.smi.builder import MibBuilder
from pysnmp.smi.view import MibViewController
from pysnmp.smi.rfc1902 import ObjectIdentity
from pysnmp.proto.rfc1155 import IpAddress
from pysnmp.proto.rfc1902 import ObjectName
import user
builder = MibBuilder()
builder.loadModules('RFC1213-MIB')
view = MibViewController(builder)
pysnmp.debug.setLogger(pysnmp.debug.Debug('all'))
ident = ObjectIdentity('RFC1213-MIB', 'atIfIndex', 7, IpAddress('143.248.1.177'))
ident.resolveWithMib(view)
print(ident.getOid())
ident2 = ObjectIdentity(ObjectName('1.3.6.1.2.1.3.1.1.1.7.1.143.248.1.177'))
ident2.resolveWithMib(view)
print(ident2.getMibSymbol())
Results in:
2017-10-06 10:37:45,703 pysnmp: running pysnmp version 4.4.1
2017-10-06 10:37:45,703 pysnmp: debug category 'all' enabled
2017-10-06 10:37:45,792 pysnmp: trying DirMibSource('/Users/eugene.kim/.pysnmp/mibs')
2017-10-06 10:37:45,792 pysnmp: addMibSources: new MIB sources [ZipMibSource('pysnmp/smi/mibs'), ZipMibSource('pysnmp/smi/mibs/instances'), DirMibSource('pysnmp_mibs'), DirMibSource('/Users/eugene.kim/.pysnmp/mibs')]
2017-10-06 10:37:45,792 pysnmp: indexMib: re-indexing MIB view
2017-10-06 10:37:45,795 pysnmp: getNodeNameByOid: resolved :1.3.6.1.2.1.3.1.1.1 -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry', 'atIfIndex').()
2017-10-06 10:37:45,795 pysnmp: resolved ('RFC1213-MIB', 'atIfIndex', 7, IpAddress(hexValue='8ff801b1')) into prefix ObjectName('1.3.6.1.2.1.3.1.1.1') and suffix ()
2017-10-06 10:37:45,795 pysnmp: getNodeNameByOid: resolved :(1, 3, 6, 1, 2, 1, 3, 1, 1) -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry').()
2017-10-06 10:37:45,795 pysnmp: resolved indices are (Integer32(7), IpAddress(hexValue='8ff801b1'))
1.3.6.1.2.1.3.1.1.1.7.143.248.1.177
2017-10-06 10:37:45,795 pysnmp: resolving 1.3.6.1.2.1.3.1.1.1.7.1.143.248.1.177 as OID or label
2017-10-06 10:37:45,796 pysnmp: getNodeNameByOid: resolved :1.3.6.1.2.1.3.1.1.1.7.1.143.248.1.177 -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry', 'atIfIndex').7.1.143.248.1.177
2017-10-06 10:37:45,796 pysnmp: resolved (ObjectName('1.3.6.1.2.1.3.1.1.1.7.1.143.248.1.177'),) into prefix ObjectName('1.3.6.1.2.1.3.1.1.1') and suffix ObjectName('7.1.143.248.1.177')
2017-10-06 10:37:45,796 pysnmp: getNodeNameByOid: resolved :1.3.6.1.2.1.3.1.1.1 -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry', 'atIfIndex').()
2017-10-06 10:37:45,796 pysnmp: resolved prefix ObjectName('1.3.6.1.2.1.3.1.1.1') into MIB node MibTableColumn((1, 3, 6, 1, 2, 1, 3, 1, 1, 1), Integer32())
2017-10-06 10:37:45,796 pysnmp: getNodeNameByOid: resolved :(1, 3, 6, 1, 2, 1, 3, 1, 1) -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry').()
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/eugene.kim/Work/ESI/snmp2es/z.py", line 20, in <module>
ident2.resolveWithMib(view)
File "/Users/eugene.kim/venvs/playground36/lib/python3.6/site-packages/pysnmp-4.4.1-py3.6.egg/pysnmp/smi/rfc1902.py", line 450, in resolveWithMib
File "<string>", line 1223, in getIndicesFromInstId
pysnmp.smi.error.SmiError: Excessive instance identifier sub-OIDs left at MibTableRow((1, 3, 6, 1, 2, 1, 3, 1, 1), None): 177
Note:
- The OID-encoded
atNetAddress
143.248.1.177
lacks theNetworkAddress
type selector value1
at the beginning; - The buggy code could not resolve a correctly encoded index (
ident2
) because it did not expect theNetworkAddress
type selector value before the IP address literal. What happened instead is: 1) the buggy code erroneously decoded the address as1.143.248.1
(the type selector value plus the first 3 sub-identifiers of the IP address), then 2) raised an exception upon seeing 177, which the last octet of the IP address.
#87 fixes this issue (note: #87 requires etingof/pyasn1#85), to yield correct result:
2017-10-06 10:49:52,165 pysnmp: running pysnmp version 4.4.1
2017-10-06 10:49:52,166 pysnmp: debug category 'all' enabled
2017-10-06 10:49:52,254 pysnmp: trying DirMibSource('/Users/eugene.kim/.pysnmp/mibs')
2017-10-06 10:49:52,254 pysnmp: addMibSources: new MIB sources [ZipMibSource('pysnmp/smi/mibs'), ZipMibSource('pysnmp/smi/mibs/instances'), DirMibSource('pysnmp_mibs'), DirMibSource('/Users/eugene.kim/.pysnmp/mibs')]
2017-10-06 10:49:52,254 pysnmp: indexMib: re-indexing MIB view
2017-10-06 10:49:52,256 pysnmp: getNodeNameByOid: resolved :1.3.6.1.2.1.3.1.1.1 -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry', 'atIfIndex').()
2017-10-06 10:49:52,256 pysnmp: resolved ('RFC1213-MIB', 'atIfIndex', 7, IpAddress(hexValue='8ff801b1')) into prefix ObjectName('1.3.6.1.2.1.3.1.1.1') and suffix ()
2017-10-06 10:49:52,256 pysnmp: getNodeNameByOid: resolved :(1, 3, 6, 1, 2, 1, 3, 1, 1) -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry').()
2017-10-06 10:49:52,257 pysnmp: resolved indices are (Integer32(7), NetworkAddress().setComponentByPosition(0, IpAddress(hexValue='8ff801b1')))
1.3.6.1.2.1.3.1.1.1.7.1.143.248.1.177
2017-10-06 10:49:52,257 pysnmp: resolving 1.3.6.1.2.1.3.1.1.1.7.1.143.248.1.177 as OID or label
2017-10-06 10:49:52,257 pysnmp: getNodeNameByOid: resolved :1.3.6.1.2.1.3.1.1.1.7.1.143.248.1.177 -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry', 'atIfIndex').7.1.143.248.1.177
2017-10-06 10:49:52,257 pysnmp: resolved (ObjectName('1.3.6.1.2.1.3.1.1.1.7.1.143.248.1.177'),) into prefix ObjectName('1.3.6.1.2.1.3.1.1.1') and suffix ObjectName('7.1.143.248.1.177')
2017-10-06 10:49:52,257 pysnmp: getNodeNameByOid: resolved :1.3.6.1.2.1.3.1.1.1 -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry', 'atIfIndex').()
2017-10-06 10:49:52,257 pysnmp: resolved prefix ObjectName('1.3.6.1.2.1.3.1.1.1') into MIB node MibTableColumn((1, 3, 6, 1, 2, 1, 3, 1, 1, 1), Integer32())
2017-10-06 10:49:52,257 pysnmp: getNodeNameByOid: resolved :(1, 3, 6, 1, 2, 1, 3, 1, 1) -> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'at', 'atTable', 'atEntry').()
2017-10-06 10:49:52,258 pysnmp: resolved indices are (Integer32(7), NetworkAddress().setComponentByPosition(0, IpAddress(hexValue='8ff801b1')))
('RFC1213-MIB', 'atIfIndex', (Integer32(7), NetworkAddress().setComponentByPosition(0, IpAddress(hexValue='8ff801b1'))))
Note:
- The
atNetAddress
of 143.248.1.177 is now correctly encoded as1.143.248.1.177
; - A correctly formatted instance OID is now correctly decoded.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
26 Network Management and SNMP
Here is some sample data, not showing all columns that the actual MIB-2 table includes, and not (yet) showing any OIDs. The header...
Read more >RFC 1213 - Management Information Base for Network ...
Management Information Base for Network Management of TCP/IP-based internets: MIB-II (RFC 1213, March 1991)
Read more >GitHub - markabrahams/node-net-snmp
If an OID string is passed which does not represent a table the resulting object produced to hold table data will be empty,...
Read more >Cisco Unified Communications Manager and IM and ...
Each entry in this table has an index to the sysApplInstallPkg table to ... The DateAndTime the application instance was determined to be...
Read more >17 Common MIB Design Errors - MIB Smithy User's Guide
As well, MIB Smithy can often automatically correct common errors such as the ... There are no actual tables in SMI or SNMP,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That was the original design, then it occurred to me that there may be other
Choice
-based index types which will require similar cloning logic.However, after seeing that SNMPv2-SMI now allows only simple-type indices, I agree that we don’t need to clutter PyASN1 anticipating something that is already disallowed by the RFC. 😃
I’ll update this PR to revert to the original version. Please disregard the PyASN1 PR.
Merged