snmp_agent.c File Reference

SNMP agent (Simple Network Management Protocol) More...

#include "core/net.h"
#include "snmp/snmp_agent.h"
#include "snmp/snmp_agent_dispatch.h"
#include "snmp/snmp_agent_pdu.h"
#include "snmp/snmp_agent_misc.h"
#include "snmp/snmp_agent_trap.h"
#include "snmp/snmp_agent_inform.h"
#include "mibs/mib2_module.h"
#include "core/crypto.h"
#include "encoding/asn1.h"
#include "encoding/oid.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   SNMP_TRACE_LEVEL
 

Functions

void snmpAgentGetDefaultSettings (SnmpAgentSettings *settings)
 Initialize settings with default values. More...
 
error_t snmpAgentInit (SnmpAgentContext *context, const SnmpAgentSettings *settings)
 SNMP agent initialization. More...
 
error_t snmpAgentStart (SnmpAgentContext *context)
 Start SNMP agent. More...
 
error_t snmpAgentLoadMib (SnmpAgentContext *context, const MibModule *module)
 Load a MIB module. More...
 
error_t snmpAgentUnloadMib (SnmpAgentContext *context, const MibModule *module)
 Unload a MIB module. More...
 
error_t snmpAgentSetVersion (SnmpAgentContext *context, SnmpVersion versionMin, SnmpVersion versionMax)
 Set minimum and maximum versions permitted. More...
 
error_t snmpAgentSetEngineBoots (SnmpAgentContext *context, int32_t engineBoots)
 Set the value of the snmpEngineBoots variable. More...
 
error_t snmpAgentGetEngineBoots (SnmpAgentContext *context, int32_t *engineBoots)
 Get the value of the snmpEngineBoots variable. More...
 
error_t snmpAgentSetEnterpriseOid (SnmpAgentContext *context, const uint8_t *enterpriseOid, size_t enterpriseOidLen)
 Set enterprise OID. More...
 
error_t snmpAgentSetContextEngine (SnmpAgentContext *context, const void *contextEngine, size_t contextEngineLen)
 Set context engine identifier. More...
 
error_t snmpAgentSetContextName (SnmpAgentContext *context, const char_t *contextName)
 Set context name. More...
 
error_t snmpAgentCreateCommunity (SnmpAgentContext *context, const char_t *community, SnmpAccess mode)
 Create a new community string. More...
 
error_t snmpAgentDeleteCommunity (SnmpAgentContext *context, const char_t *community)
 Remove a community string. More...
 
error_t snmpAgentCreateUser (SnmpAgentContext *context, const char_t *userName, SnmpAccess mode, SnmpKeyFormat keyFormat, SnmpAuthProtocol authProtocol, const void *authKey, SnmpPrivProtocol privProtocol, const void *privKey)
 Create a new user. More...
 
error_t snmpAgentDeleteUser (SnmpAgentContext *context, const char_t *userName)
 Remove existing user. More...
 
error_t snmpAgentJoinGroup (SnmpAgentContext *context, const char_t *userName, SnmpSecurityModel securityModel, const char_t *groupName)
 Join a group of users. More...
 
error_t snmpAgentLeaveGroup (SnmpAgentContext *context, const char_t *userName, SnmpSecurityModel securityModel)
 Leave a group of users. More...
 
error_t snmpAgentCreateAccess (SnmpAgentContext *context, const char_t *groupName, SnmpSecurityModel securityModel, SnmpSecurityLevel securityLevel, const char_t *contextPrefix, SnmpContextMatch contextMatch, const char_t *readViewName, const char_t *writeViewName, const char_t *notifyViewName)
 Create access policy for the specified group name. More...
 
error_t snmpAgentDeleteAccess (SnmpAgentContext *context, const char_t *groupName, SnmpSecurityModel securityModel, SnmpSecurityLevel securityLevel, const char_t *contextPrefix)
 Delete an existing access policy. More...
 
error_t snmpAgentCreateView (SnmpAgentContext *context, const char_t *viewName, const uint8_t *subtree, size_t subtreeLen, const uint8_t *mask, size_t maskLen, SnmpViewType type)
 Create a new MIB view. More...
 
error_t snmpAgentDeleteView (SnmpAgentContext *context, const char_t *viewName, const uint8_t *subtree, size_t subtreeLen)
 Delete an existing MIB view. More...
 
error_t snmpAgentSendTrap (SnmpAgentContext *context, const IpAddr *destIpAddr, SnmpVersion version, const char_t *userName, uint_t genericTrapType, uint_t specificTrapCode, const SnmpTrapObject *objectList, uint_t objectListSize)
 Send SNMP trap notification. More...
 
error_t snmpAgentSendInform (SnmpAgentContext *context, const IpAddr *destIpAddr, SnmpVersion version, const char_t *userName, uint_t genericTrapType, uint_t specificTrapCode, const SnmpTrapObject *objectList, uint_t objectListSize)
 Send SNMP inform request. More...
 
void snmpAgentTask (SnmpAgentContext *context)
 SNMP agent task. More...
 

Detailed Description

SNMP agent (Simple Network Management Protocol)

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Description

SNMP is a simple protocol by which management information for a network element may be inspected or altered by logically remote users. Refer to the following RFCs for complete details:

  • RFC 1157: A Simple Network Management Protocol (SNMP)
  • RFC 1905: Protocol Operations for Version 2 of the Simple Network Management Protocol (SNMPv2)
  • RFC 3410: Introduction and Applicability Statements for Internet Standard Management Framework
  • RFC 3411: An Architecture for Describing SNMP Management Frameworks
  • RFC 3412: Message Processing and Dispatching for the SNMP
  • RFC 3413: Simple Network Management Protocol (SNMP) Applications
  • RFC 3584: Coexistence between Version 1, Version 2, and Version 3 of SNMP Framework
Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file snmp_agent.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   SNMP_TRACE_LEVEL

Definition at line 46 of file snmp_agent.c.

Function Documentation

◆ snmpAgentCreateAccess()

error_t snmpAgentCreateAccess ( SnmpAgentContext context,
const char_t groupName,
SnmpSecurityModel  securityModel,
SnmpSecurityLevel  securityLevel,
const char_t contextPrefix,
SnmpContextMatch  contextMatch,
const char_t readViewName,
const char_t writeViewName,
const char_t notifyViewName 
)

Create access policy for the specified group name.

Parameters
[in]contextPointer to the SNMP agent context
[in]groupNameNULL-terminated string that contains the group name
[in]securityModelSecurity model
[in]securityLevelSecurity level
[in]contextPrefixNULL-terminated string that contains the context name prefix
[in]contextMatchContext match
[in]readViewNameNULL-terminated string that contains the read view name
[in]writeViewNameNULL-terminated string that contains the write view name
[in]notifyViewNameNULL-terminated string that contains the notify view name
Returns
Error code

Definition at line 1139 of file snmp_agent.c.

◆ snmpAgentCreateCommunity()

error_t snmpAgentCreateCommunity ( SnmpAgentContext context,
const char_t community,
SnmpAccess  mode 
)

Create a new community string.

Parameters
[in]contextPointer to the SNMP agent context
[in]communityNULL-terminated string that contains the community name
[in]modeAccess rights
Returns
Error code

Definition at line 601 of file snmp_agent.c.

◆ snmpAgentCreateUser()

error_t snmpAgentCreateUser ( SnmpAgentContext context,
const char_t userName,
SnmpAccess  mode,
SnmpKeyFormat  keyFormat,
SnmpAuthProtocol  authProtocol,
const void *  authKey,
SnmpPrivProtocol  privProtocol,
const void *  privKey 
)

Create a new user.

Parameters
[in]contextPointer to the SNMP agent context
[in]userNameNULL-terminated string that contains the user name
[in]modeAccess rights
[in]keyFormatKey format (ASCII password or raw key)
[in]authProtocolAuthentication type
[in]authKeyKey to be used for data authentication
[in]privProtocolPrivacy type
[in]privKeyKey to be used for data encryption
Returns
Error code

Definition at line 733 of file snmp_agent.c.

◆ snmpAgentCreateView()

error_t snmpAgentCreateView ( SnmpAgentContext context,
const char_t viewName,
const uint8_t *  subtree,
size_t  subtreeLen,
const uint8_t *  mask,
size_t  maskLen,
SnmpViewType  type 
)

Create a new MIB view.

Parameters
[in]contextPointer to the SNMP agent context
[in]viewNameNULL-terminated string that contains the view name
[in]subtreePointer to the subtree
[in]subtreeLenLength of the subtree, in bytes
[in]maskPointer to the bit mask
[in]maskLenLength of the bit mask
[in]typeView type
Returns
Error code

Definition at line 1334 of file snmp_agent.c.

◆ snmpAgentDeleteAccess()

error_t snmpAgentDeleteAccess ( SnmpAgentContext context,
const char_t groupName,
SnmpSecurityModel  securityModel,
SnmpSecurityLevel  securityLevel,
const char_t contextPrefix 
)

Delete an existing access policy.

Parameters
[in]contextPointer to the SNMP agent context
[in]groupNameNULL-terminated string that contains the group name
[in]securityModelSecurity model
[in]securityLevelSecurity level
[in]contextPrefixNULL-terminated string that contains the context name prefix
Returns
Error code

Definition at line 1274 of file snmp_agent.c.

◆ snmpAgentDeleteCommunity()

error_t snmpAgentDeleteCommunity ( SnmpAgentContext context,
const char_t community 
)

Remove a community string.

Parameters
[in]contextPointer to the SNMP agent context
[in]communityNULL-terminated string that contains the community name
Returns
Error code

Definition at line 675 of file snmp_agent.c.

◆ snmpAgentDeleteUser()

error_t snmpAgentDeleteUser ( SnmpAgentContext context,
const char_t userName 
)

Remove existing user.

Parameters
[in]contextPointer to the SNMP agent context
[in]userNameNULL-terminated string that contains the user name
Returns
Error code

Definition at line 931 of file snmp_agent.c.

◆ snmpAgentDeleteView()

error_t snmpAgentDeleteView ( SnmpAgentContext context,
const char_t viewName,
const uint8_t *  subtree,
size_t  subtreeLen 
)

Delete an existing MIB view.

Parameters
[in]contextPointer to the SNMP agent context
[in]viewNameNULL-terminated string that contains the view name
[in]subtreePointer to the subtree
[in]subtreeLenLength of the subtree, in bytes
Returns
Error code

Definition at line 1436 of file snmp_agent.c.

◆ snmpAgentGetDefaultSettings()

void snmpAgentGetDefaultSettings ( SnmpAgentSettings settings)

Initialize settings with default values.

Parameters
[out]settingsStructure that contains SNMP agent settings

Definition at line 71 of file snmp_agent.c.

◆ snmpAgentGetEngineBoots()

error_t snmpAgentGetEngineBoots ( SnmpAgentContext context,
int32_t *  engineBoots 
)

Get the value of the snmpEngineBoots variable.

Parameters
[in]contextPointer to the SNMP agent context
[out]engineBootsNumber of times the SNMP engine has re-booted
Returns
Error code

Definition at line 459 of file snmp_agent.c.

◆ snmpAgentInit()

error_t snmpAgentInit ( SnmpAgentContext context,
const SnmpAgentSettings settings 
)

SNMP agent initialization.

Parameters
[in]contextPointer to the SNMP agent context
[in]settingsSNMP agent specific settings
Returns
Error code

Definition at line 98 of file snmp_agent.c.

◆ snmpAgentJoinGroup()

error_t snmpAgentJoinGroup ( SnmpAgentContext context,
const char_t userName,
SnmpSecurityModel  securityModel,
const char_t groupName 
)

Join a group of users.

Parameters
[in]contextPointer to the SNMP agent context
[in]userNameNULL-terminated string that contains the user name
[in]securityModelSecurity model
[in]groupNameNULL-terminated string that contains the group name
Returns
Error code

Definition at line 985 of file snmp_agent.c.

◆ snmpAgentLeaveGroup()

error_t snmpAgentLeaveGroup ( SnmpAgentContext context,
const char_t userName,
SnmpSecurityModel  securityModel 
)

Leave a group of users.

Parameters
[in]contextPointer to the SNMP agent context
[in]userNameNULL-terminated string that contains the user name
[in]securityModelSecurity model
Returns
Error code

Definition at line 1078 of file snmp_agent.c.

◆ snmpAgentLoadMib()

error_t snmpAgentLoadMib ( SnmpAgentContext context,
const MibModule module 
)

Load a MIB module.

Parameters
[in]contextPointer to the SNMP agent context
[in]modulePointer the MIB module to be loaded
Returns
Error code

Definition at line 255 of file snmp_agent.c.

◆ snmpAgentSendInform()

error_t snmpAgentSendInform ( SnmpAgentContext context,
const IpAddr destIpAddr,
SnmpVersion  version,
const char_t userName,
uint_t  genericTrapType,
uint_t  specificTrapCode,
const SnmpTrapObject objectList,
uint_t  objectListSize 
)

Send SNMP inform request.

Parameters
[in]contextPointer to the SNMP agent context
[in]destIpAddrDestination IP address
[in]versionSNMP version identifier
[in]userNameUser name or community name
[in]genericTrapTypeGeneric trap type
[in]specificTrapCodeSpecific code
[in]objectListList of object names
[in]objectListSizeNumber of entries in the list
Returns
Error code

Definition at line 1570 of file snmp_agent.c.

◆ snmpAgentSendTrap()

error_t snmpAgentSendTrap ( SnmpAgentContext context,
const IpAddr destIpAddr,
SnmpVersion  version,
const char_t userName,
uint_t  genericTrapType,
uint_t  specificTrapCode,
const SnmpTrapObject objectList,
uint_t  objectListSize 
)

Send SNMP trap notification.

Parameters
[in]contextPointer to the SNMP agent context
[in]destIpAddrDestination IP address
[in]versionSNMP version identifier
[in]userNameUser name or community name
[in]genericTrapTypeGeneric trap type
[in]specificTrapCodeSpecific code
[in]objectListList of object names
[in]objectListSizeNumber of entries in the list
Returns
Error code

Definition at line 1495 of file snmp_agent.c.

◆ snmpAgentSetContextEngine()

error_t snmpAgentSetContextEngine ( SnmpAgentContext context,
const void *  contextEngine,
size_t  contextEngineLen 
)

Set context engine identifier.

Parameters
[in]contextPointer to the SNMP agent context
[in]contextEnginePointer to the context engine identifier
[in]contextEngineLenLength of the context engine identifier
Returns
Error code

Definition at line 523 of file snmp_agent.c.

◆ snmpAgentSetContextName()

error_t snmpAgentSetContextName ( SnmpAgentContext context,
const char_t contextName 
)

Set context name.

Parameters
[in]contextPointer to the SNMP agent context
[in]contextNameNULL-terminated string that contains the context name
Returns
Error code

Definition at line 560 of file snmp_agent.c.

◆ snmpAgentSetEngineBoots()

error_t snmpAgentSetEngineBoots ( SnmpAgentContext context,
int32_t  engineBoots 
)

Set the value of the snmpEngineBoots variable.

Parameters
[in]contextPointer to the SNMP agent context
[in]engineBootsNumber of times the SNMP engine has re-booted
Returns
Error code

Definition at line 420 of file snmp_agent.c.

◆ snmpAgentSetEnterpriseOid()

error_t snmpAgentSetEnterpriseOid ( SnmpAgentContext context,
const uint8_t *  enterpriseOid,
size_t  enterpriseOidLen 
)

Set enterprise OID.

Parameters
[in]contextPointer to the SNMP agent context
[in]enterpriseOidPointer to the enterprise OID
[in]enterpriseOidLenLength of the enterprise OID
Returns
Error code

Definition at line 490 of file snmp_agent.c.

◆ snmpAgentSetVersion()

error_t snmpAgentSetVersion ( SnmpAgentContext context,
SnmpVersion  versionMin,
SnmpVersion  versionMax 
)

Set minimum and maximum versions permitted.

Parameters
[in]contextPointer to the SNMP agent context
[in]versionMinMinimum version accepted by the SNMP agent
[in]versionMaxMaximum version accepted by the SNMP agent
Returns
Error code

Definition at line 389 of file snmp_agent.c.

◆ snmpAgentStart()

error_t snmpAgentStart ( SnmpAgentContext context)

Start SNMP agent.

Parameters
[in]contextPointer to the SNMP agent context
Returns
Error code

Definition at line 224 of file snmp_agent.c.

◆ snmpAgentTask()

void snmpAgentTask ( SnmpAgentContext context)

SNMP agent task.

Parameters
[in]contextPointer to the SNMP agent context

Definition at line 1849 of file snmp_agent.c.

◆ snmpAgentUnloadMib()

error_t snmpAgentUnloadMib ( SnmpAgentContext context,
const MibModule module 
)

Unload a MIB module.

Parameters
[in]contextPointer to the SNMP agent context
[in]modulePointer the MIB module to be unloaded
Returns
Error code

Definition at line 331 of file snmp_agent.c.