Skip to content

SnmpClient not working when sending v3 traps #22

@DenizOezcan

Description

@DenizOezcan

When using the SnmpClient to send v3 traps I get following exception:
FreeDSx\Snmp\Exception\ProtocolException : Expected a SNMPv3 response, but got: v0

The problem is, that \FreeDSx\Snmp\Protocol\ClientProtocolHandler::sendRequestGetResponse returns null for a SNMPv3 trap, as no response is expected. This causes the exception mentioned above being thrown due to the following logic in \FreeDSx\Snmp\Protocol\ClientProtocolHandler::sendV3Message from line 206 and following :

            $response = $this->sendRequestGetResponse($message);

            if ($response instanceof MessageResponseV3) {
                $response = $securityModule->handleIncomingMessage($response, $options);
            }
            if (!$response instanceof MessageResponseV3) {
                throw new ProtocolException(sprintf(
                    'Expected a SNMPv3 response, but got: v%d',
                    $response instanceof MessageResponseInterface ? $response->getVersion() : 0
                ));
            }

This could be fixed with a null check, e.g.:

            $response = $this->sendRequestGetResponse($message);
            
            if(null === $response) {
                return null;
            }

            if ($response instanceof MessageResponseV3) {
                $response = $securityModule->handleIncomingMessage($response, $options);
            }
            if (!$response instanceof MessageResponseV3) {
                throw new ProtocolException(sprintf(
                    'Expected a SNMPv3 response, but got: v%d',
                    $response instanceof MessageResponseInterface ? $response->getVersion() : 0
                ));
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions