diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-02-08 11:16:52 +0100 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2019-02-08 11:16:52 +0100 |
commit | ed70cdf00443aed945a238f2a8b704fa8d9c255c (patch) | |
tree | 25901ce1bb494814057354e09b48c47ec6a73f52 | |
parent | fbaa6da636c20fb71e5af28eee9dba5133f0d42c (diff) | |
download | pysnmp-git-ed70cdf00443aed945a238f2a8b704fa8d9c255c.tar.gz |
Add missing SNMP PDU error classes
Added missing SNMP PDU error classes and their handling in
Command Responder
-rw-r--r-- | CHANGES.txt | 1 | ||||
-rw-r--r-- | pysnmp/entity/rfc3413/cmdrsp.py | 39 | ||||
-rw-r--r-- | pysnmp/proto/rfc1905.py | 13 | ||||
-rw-r--r-- | pysnmp/smi/error.py | 31 |
4 files changed, 70 insertions, 14 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 7f7e7618..1b5b75fd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,7 @@ Revision 4.4.9, released 2019-01-XX ----------------------------------- - Made MIB loader ignoring file and directory access errors +- Added missing SNMP PDU error classes and their handling in Command Responder - Fixed crash on MIB load failure in case of directory access error - Fixed socket transparency option (IPV6_TRANSPARENT)to make IPv6 transparent operation functional diff --git a/pysnmp/entity/rfc3413/cmdrsp.py b/pysnmp/entity/rfc3413/cmdrsp.py index 3e1db4f3..5cef0a14 100644 --- a/pysnmp/entity/rfc3413/cmdrsp.py +++ b/pysnmp/entity/rfc3413/cmdrsp.py @@ -138,6 +138,7 @@ class CommandResponderBase(object): self.handleMgmtOperation(snmpEngine, stateReference, contextName, PDU, (self.__verifyAccess, snmpEngine)) + # SNMPv2 SMI exceptions except pysnmp.smi.error.GenError: errorIndication = sys.exc_info()[1] @@ -148,38 +149,72 @@ class CommandResponderBase(object): statusInformation['oid'] = errorIndication['oid'] statusInformation['val'] = errorIndication['val'] - # PDU-level SMI errors + # Handle PDU-level SMI errors + + except pysnmp.smi.error.TooBigError: + errorStatus, errorIndex = 'tooBig', 0 + # rfc1905: 4.2.1.3 + varBinds = [] + + # this should never bubble up, SNMP exception objects should be passed as values + except pysnmp.smi.error.NoSuchNameError: + errorStatus, errorIndex = 'noSuchName', sys.exc_info()[1]['idx'] + 1 + + except pysnmp.smi.error.BadValueError: + errorStatus, errorIndex = 'badValue', sys.exc_info()[1]['idx'] + 1 + + except pysnmp.smi.error.ReadOnlyError: + errorStatus, errorIndex = 'readOnly', sys.exc_info()[1]['idx'] + 1 + + except pysnmp.smi.error.GenError: + errorStatus, errorIndex = 'genErr', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.NoAccessError: errorStatus, errorIndex = 'noAccess', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.WrongTypeError: errorStatus, errorIndex = 'wrongType', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.WrongLengthError: errorStatus, errorIndex = 'wrongLength', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.WrongEncodingError: errorStatus, errorIndex = 'wrongEncoding', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.WrongValueError: errorStatus, errorIndex = 'wrongValue', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.NoCreationError: errorStatus, errorIndex = 'noCreation', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.InconsistentValueError: errorStatus, errorIndex = 'inconsistentValue', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.ResourceUnavailableError: errorStatus, errorIndex = 'resourceUnavailable', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.CommitFailedError: errorStatus, errorIndex = 'commitFailed', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.UndoFailedError: errorStatus, errorIndex = 'undoFailed', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.AuthorizationError: errorStatus, errorIndex = 'authorizationError', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.NotWritableError: errorStatus, errorIndex = 'notWritable', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.InconsistentNameError: errorStatus, errorIndex = 'inconsistentName', sys.exc_info()[1]['idx'] + 1 + except pysnmp.smi.error.SmiError: - errorStatus, errorIndex = 'genErr', len(varBinds) and 1 or 0 + errorStatus, errorIndex = 'genErr', len(varBinds) and 1 + except pysnmp.error.PySnmpError: self.releaseStateInformation(stateReference) return + else: # successful request processor must release state info return diff --git a/pysnmp/proto/rfc1905.py b/pysnmp/proto/rfc1905.py index 4a229495..d5da3982 100644 --- a/pysnmp/proto/rfc1905.py +++ b/pysnmp/proto/rfc1905.py @@ -84,12 +84,13 @@ class VarBindList(univ.SequenceOf): errorStatus = univ.Integer( - namedValues=namedval.NamedValues(('noError', 0), ('tooBig', 1), ('noSuchName', 2), ('badValue', 3), ('readOnly', 4), - ('genErr', 5), ('noAccess', 6), ('wrongType', 7), ('wrongLength', 8), - ('wrongEncoding', 9), ('wrongValue', 10), ('noCreation', 11), - ('inconsistentValue', 12), ('resourceUnavailable', 13), ('commitFailed', 14), - ('undoFailed', 15), ('authorizationError', 16), ('notWritable', 17), - ('inconsistentName', 18)) + namedValues=namedval.NamedValues( + ('noError', 0), ('tooBig', 1), ('noSuchName', 2), ('badValue', 3), ('readOnly', 4), + ('genErr', 5), ('noAccess', 6), ('wrongType', 7), ('wrongLength', 8), + ('wrongEncoding', 9), ('wrongValue', 10), ('noCreation', 11), + ('inconsistentValue', 12), ('resourceUnavailable', 13), ('commitFailed', 14), + ('undoFailed', 15), ('authorizationError', 16), ('notWritable', 17), + ('inconsistentName', 18)) ) diff --git a/pysnmp/smi/error.py b/pysnmp/smi/error.py index 4b7ba5cc..a16dfe2b 100644 --- a/pysnmp/smi/error.py +++ b/pysnmp/smi/error.py @@ -43,7 +43,24 @@ class MibOperationError(SmiError): self.__outArgs.update(d) -# Aligned with SNMPv2 PDU error-status +# Aligned with SNMPv2 PDU error-status values + +class TooBigError(MibOperationError): + pass + + +class NoSuchNameError(MibOperationError): + pass + + +class BadValueError(MibOperationError): + pass + + +class ReadOnlyError(MibOperationError): + pass + + class GenError(MibOperationError): pass @@ -100,20 +117,22 @@ class InconsistentNameError(MibOperationError): pass -# Aligned with SNMPv2 Var-Bind exceptions -class NoSuchObjectError(MibOperationError): +# Aligned with SNMPv2 PDU exceptions or error-status values + +class NoSuchObjectError(NoSuchNameError): pass -class NoSuchInstanceError(MibOperationError): +class NoSuchInstanceError(NoSuchNameError): pass -class EndOfMibViewError(MibOperationError): +class EndOfMibViewError(NoSuchNameError): pass -# Row management +# SNMP table management exceptions + class TableRowManagement(MibOperationError): pass |