跳到主要内容

7. v3MP 的过程元素

本节描述 SNMPv3 Message Processing Model 在生成和处理 SNMP 消息时遵循的过程. SNMPv3 Message Processing Model 在生成和处理消息时会与 Security Subsystem 交互.

7.1. 准备外发 SNMP 消息​

本节描述 SNMPv3 Message Processing Model 在准备外发 SNMP 消息时遵循的过程.

该过程由 Dispatcher 使用抽象服务接口 prepareOutgoingMessage 调用.

过程:

  1. Message Processing Model 使用 Local Configuration Datastore (LCD) 确定本地 SNMP engine 支持的最大消息大小. 这由 [RFC3411] 中的 snmpEngineMaxMessageSize 表示. Message Processing Model 还确定本地 SNMP engine 的 snmpEngineID, 它由 [RFC3411] 中的 snmpEngineID 表示.

  2. 如果 contextEngineID 长度为零, 或者它不等于本地 SNMP engine 的 snmpEngineID, 则:

    a. 如果 pduType 的值是 Confirmed Class PDU 类型 (Get, GetNext, GetBulk, Set 或 Inform), 则:

    • v3MP 创建 msgID. msgID 用于协调请求与响应.

    b. 如果 pduType 的值是 Unconfirmed Class PDU 类型 (Trap, Report, Response), 则:

    • v3MP 创建 msgID. msgID 不用于协调请求与响应, 但由 v3MP 内部使用.
  3. v3MP 创建 msgMaxSize. msgMaxSize 是以下两者的最小值:

    • 本地 SNMP engine 支持的最大消息大小 (snmpEngineMaxMessageSize).
    • 用于发送消息的传输域和传输地址所能支持的最大消息大小.
  4. v3MP 创建 msgFlags. msgFlags 基于 securityLevel 创建:

    • 如果 securityLevel 指定 noAuthNoPriv, 则 msgFlags auth bit = 0 且 priv bit = 0.
    • 如果 securityLevel 指定 authNoPriv, 则 msgFlags auth bit = 1 且 priv bit = 0.
    • 如果 securityLevel 指定 authPriv, 则 msgFlags auth bit = 1 且 priv bit = 1.
  5. 如果 pduType 是 Confirmed Class PDU 类型, 则 msgFlags reportable bit 设置为 1. 否则, msgFlags reportable bit 设置为 0.

  6. v3MP 使用 contextEngineID, contextName 和 PDU 的值创建 scopedPDU.

  7. v3MP 为外发消息创建 msgSecurityParameters 字段. 这是通过使用抽象服务接口 generateRequestMsg 或 generateResponseMsg (视情况而定) 调用由 securityModel 参数标识的 Security Model 完成的.

    a. 如果准备 Request 或 Notification, v3MP 使用抽象 generateRequestMsg 服务接口调用 Security Model:

statusInformation = generateRequestMsg(
IN messageProcessingModel -- SNMPv3 in this case
IN globalData -- msgID, msgMaxSize, msgFlags, msgSecurityModel
IN maxMessageSize -- maximum message size as determined above
IN securityModel -- Security Model in use
IN securityEngineID -- authoritative SNMP engine
IN securityName -- principal
IN securityLevel -- Level of Security requested
IN scopedPDU -- message to be secured
OUT securityParameters -- filled in by Security Model
OUT wholeMsg -- complete generated message
OUT wholeMsgLength -- length of the generated message
)

b. 如果准备 Response, v3MP 使用抽象 generateResponseMsg 服务接口调用 Security Model:

statusInformation = generateResponseMsg(
IN messageProcessingModel -- SNMPv3 in this case
IN globalData -- msgID, msgMaxSize, msgFlags, msgSecurityModel
IN maxMessageSize -- maximum message size as determined above
IN securityModel -- Security Model in use
IN securityEngineID -- authoritative SNMP engine
IN securityName -- principal
IN securityLevel -- Level of Security
IN scopedPDU -- message to be secured
IN securityStateReference -- reference to security state information
OUT securityParameters -- filled in by Security Model
OUT wholeMsg -- complete generated message
OUT wholeMsgLength -- length of the generated message
)
  1. 如果 statusInformation 指示错误, v3MP 将 statusInformation 返回给 Dispatcher. 消息处理停止.

  2. 如果 statusInformation 指示成功, v3MP 将 outgoingMessage 和 outgoingMessageLength 返回给 Dispatcher.

7.2. 从传入 SNMP 消息准备数据元素​

本节描述 SNMPv3 Message Processing Model 从传入 SNMP 消息准备数据元素时遵循的过程.

该过程由 Dispatcher 使用抽象服务接口 prepareDataElements 调用.

过程:

  1. v3MP 解析传入消息以提取以下字段:

    • msgVersion
    • msgID
    • msgMaxSize
    • msgFlags
    • msgSecurityModel
    • msgSecurityParameters
    • scopedPduData
  2. 如果 msgVersion 不是 3, v3MP 向 Dispatcher 返回错误. 消息处理停止.

  3. 如果 scopedPduData 无法解析, 则递增 snmpInASNParseErrs 计数器 [RFC3418]. v3MP 向 Dispatcher 返回错误. 消息处理停止.

  4. 解析 msgFlags 以提取 auth, priv 和 reportable 位.

  5. 如果 auth 位为 0 且 priv 位为 1, 这是错误. 递增 snmpInvalidMsgs 计数器 [RFC3418]. v3MP 向 Dispatcher 返回错误. 消息处理停止.

  6. securityLevel 根据 msgFlags 确定:

    • 如果 auth bit = 0 且 priv bit = 0, 则 securityLevel = noAuthNoPriv.
    • 如果 auth bit = 1 且 priv bit = 0, 则 securityLevel = authNoPriv.
    • 如果 auth bit = 1 且 priv bit = 1, 则 securityLevel = authPriv.
  7. v3MP 使用抽象 processIncomingMsg 服务接口调用由 msgSecurityModel 标识的 Security Model:

statusInformation = processIncomingMsg(
IN messageProcessingModel -- SNMPv3 in this case
IN maxMessageSize -- maximum message size as determined by sender
IN securityParameters -- security parameters from incoming message
IN securityModel -- Security Model in use
IN securityLevel -- Level of Security
IN wholeMsg -- the whole message
IN wholeMsgLength -- length of the whole message
OUT securityEngineID -- authoritative SNMP engine
OUT securityName -- identification of the principal
OUT scopedPDU -- message (plaintext)
OUT maxSizeResponseScopedPDU -- maximum size of Response PDU
OUT securityStateReference -- reference to security state information
)
  1. 如果 statusInformation 指示错误:

    a. 如果 reportable 位为 1 且 pduType 是 Confirmed Class PDU, v3MP 使用 usmStatsUnknownEngineIDs, usmStatsNotInTimeWindows, usmStatsUnknownUserNames, usmStatsWrongDigests, usmStatsDecryptionErrors 或其他适当错误计数器构造 Report PDU, 并使用 returnResponsePdu 服务接口调用 Dispatcher.

    b. v3MP 将错误返回给 Dispatcher. 消息处理停止.

  2. 如果 statusInformation 指示成功:

    a. 解析 scopedPDU 以提取:

    • contextEngineID
    • contextName
    • data (PDU)

    b. 如果 scopedPDU 无法解析, 则递增 snmpInASNParseErrs 计数器. v3MP 向 Dispatcher 返回错误. 消息处理停止.

  3. 解析 PDU 以确定 pduType 和其他 PDU 特定信息:

a. 如果 PDU 无法解析, 则递增 snmpInASNParseErrs 计数器. v3MP 向 Dispatcher 返回错误. 消息处理停止.

  1. v3MP 向 Dispatcher 返回以下数据元素:
  • messageProcessingModel (SNMPv3 为 3)
  • securityModel
  • securityName
  • securityLevel
  • contextEngineID
  • contextName
  • pduVersion
  • PDU
  • pduType
  • sendPduHandle (如适用, 从 PDU 中的 request-id 提取)
  • maxSizeResponseScopedPDU
  • statusInformation (success)
  • stateReference (来自 Security Model 的 securityStateReference)
  1. 处理完成.