Nut/OS  4.10.3
API Reference
SNMP

Simple network management protocol. More...

Collaboration diagram for SNMP:

Data Structures

struct  _viewEntry
struct  _communityEntry
struct  _SNMPVAR
struct  _SNMP_VARLIST
struct  SNMP_PDU
struct  SNMP_SESSION
struct  _SUBTREE

Defines

#define SNMP_PORT   161
 Standard UDP port for SNMP agents to receive requests messages.
#define SNMP_TRAP_PORT   162
 Standard UDP port for SNMP managers to receive notificaion messages.
#define SNMP_MAX_LEN   500
 Default maximum message size.
#define SNMP_VERSION_1   0
 SNMPv1.
#define SNMP_VERSION_2C   1
 SNMPv2c.
#define SNMP_VERSION_3   3
 SNMPv3.
#define SNMP_MSG_GET   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0)
#define SNMP_MSG_GETNEXT   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1)
#define SNMP_MSG_RESPONSE   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x2)
#define SNMP_MSG_SET   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x3)
#define SNMP_MSG_TRAP   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4)
#define SNMP_MSG_GETBULK   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x5)
#define SNMP_MSG_INFORM   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x6)
#define SNMP_MSG_TRAP2   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x7)
#define SNMP_MSG_REPORT   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x8)
#define SNMP_NOSUCHOBJECT   (ASN_CONTEXT | ASN_PRIMITIVE | 0x0)
#define SNMP_NOSUCHINSTANCE   (ASN_CONTEXT | ASN_PRIMITIVE | 0x1)
#define SNMP_ENDOFMIBVIEW   (ASN_CONTEXT | ASN_PRIMITIVE | 0x2)
#define SNMP_ERR_NOERROR   0
#define SNMP_ERR_TOOBIG   1
#define SNMP_ERR_NOSUCHNAME   2
#define SNMP_ERR_BADVALUE   3
#define SNMP_ERR_READONLY   4
#define SNMP_ERR_GENERR   5
#define SNMP_ERR_NOACCESS   6
#define SNMP_ERR_WRONGTYPE   7
#define SNMP_ERR_WRONGLENGTH   8
#define SNMP_ERR_WRONGENCODING   9
#define SNMP_ERR_WRONGVALUE   10
#define SNMP_ERR_NOCREATION   11
#define SNMP_ERR_INCONSISTENTVALUE   12
#define SNMP_ERR_RESOURCEUNAVAILABLE   13
#define SNMP_ERR_COMMITFAILED   14
#define SNMP_ERR_UNDOFAILED   15
#define SNMP_ERR_AUTHORIZATIONERROR   16
#define SNMP_ERR_NOTWRITABLE   17
#define SNMP_ERR_INCONSISTENTNAME   18
#define SNMP_TRAP_COLDSTART   0
#define SNMP_TRAP_WARMSTART   1
#define SNMP_TRAP_LINKDOWN   2
#define SNMP_TRAP_LINKUP   3
#define SNMP_TRAP_AUTHFAIL   4
#define SNMP_TRAP_EGPNEIGHBORLOSS   5
#define SNMP_TRAP_ENTERPRISESPECIFIC   6
#define SNMP_OID_INTERNET   1, 3, 6, 1
#define SNMP_OID_ENTERPRISES   SNMP_OID_INTERNET, 4, 1
#define SNMP_OID_MIB2   SNMP_OID_INTERNET, 2, 1
#define SNMP_OID_SNMPV2   SNMP_OID_INTERNET, 6
#define SNMP_OID_SNMPMODULES   SNMP_OID_SNMPV2, 3
#define SNMP_PARSE_ERROR   -1
#define SNMP_BUILD_ERROR   -2
#define MAX_SID_LEN   32
 Maximum length of a community name.
#define MAX_NAME_LEN   128
 Maximum number of sub IDs in an OID.
#define SNMP_ACT_RESERVE1   0
#define SNMP_ACT_RESERVE2   1
#define SNMP_ACT_COMMIT   2
#define SNMP_ACT_ACTION   3
#define SNMP_ACT_FREE   4
#define SNMP_MAX_MSG_SIZE   1472
#define SNMP_STAT_INPKTS   0
#define SNMP_STAT_OUTPKTS   1
#define SNMP_STAT_INBADVERSIONS   2
#define SNMP_STAT_INBADCOMMUNITYNAMES   3
#define SNMP_STAT_INBADCOMMUNITYUSES   4
#define SNMP_STAT_INASNPARSEERRS   5
#define SNMP_STAT_INTOOBIGS   6
#define SNMP_STAT_INNOSUCHNAMES   7
#define SNMP_STAT_INBADVALUES   8
#define SNMP_STAT_INREADONLYS   9
#define SNMP_STAT_INGENERRS   10
#define SNMP_STAT_INTOTALREQVARS   11
#define SNMP_STAT_INTOTALSETVARS   12
#define SNMP_STAT_INGETREQUESTS   13
#define SNMP_STAT_INGETNEXTS   14
#define SNMP_STAT_INSETREQUESTS   15
#define SNMP_STAT_INGETRESPONSES   16
#define SNMP_STAT_INTRAPS   17
#define SNMP_STAT_OUTTOOBIGS   18
#define SNMP_STAT_OUTNOSUCHNAMES   19
#define SNMP_STAT_OUTBADVALUES   20
#define SNMP_STAT_OUTGENERRS   21
#define SNMP_STAT_OUTGETREQUESTS   22
#define SNMP_STAT_OUTGETNEXTS   23
#define SNMP_STAT_OUTSETREQUESTS   24
#define SNMP_STAT_OUTGETRESPONSES   25
#define SNMP_STAT_OUTTRAPS   26
#define SNMP_STAT_ENABLEAUTHENTRAPS   27
#define SNMP_STAT_MAX   28
#define SNMP_VIEW_INCLUDED   1
#define SNMP_VIEW_EXCLUDED   2

Typedefs

typedef struct _viewEntry VIEW_LIST
typedef struct _communityEntry COMMUNITY_LIST
typedef int( WMETHOD )(int, uint8_t *, uint8_t, size_t, OID *, size_t)
typedef struct _SNMPVAR SNMPVAR
typedef struct _SNMP_VARLIST SNMP_VARLIST
typedef struct _SUBTREE SUBTREE

Functions

CONST uint8_tSnmpVarParse (CONST uint8_t *data, size_t *dlen, OID *name, size_t *nlen, uint8_t *type, uint8_t **value, size_t *vlen)
 Parse an SNMP variable.
uint8_tSnmpVarBuild (uint8_t *data, size_t *dlen, CONST OID *name, size_t nlen, uint8_t type, CONST uint8_t *value, size_t vlen)
 Build an SNMP variable.
int SnmpAgentProcessRequest (SNMP_SESSION *sess, CONST uint8_t *in_data, size_t in_len, uint8_t *out_data, size_t *out_len)
 Parse incoming and create outgoing packet.
int SnmpAgent (UDPSOCKET *sock)
 Run SNMP agent.
int SnmpOidLenCmp (CONST OID *name1, CONST OID *name2, size_t len)
 Compare object identifiers up to a specified length.
int SnmpOidCmp (CONST OID *name1, size_t len1, CONST OID *name2, size_t len2)
 Compare object identifiers.
int SnmpOidTreeCmp (CONST OID *objid, size_t objlen, CONST OID *treeid, size_t treelen)
 Compare object identifier with tree element.
int SnmpOidCmpIdx (CONST OID *name1, size_t len1, CONST OID *name2, size_t len2, OID index)
 Compare object identifiers with index added.
int SnmpOidEquals (CONST OID *name1, size_t len1, CONST OID *name2, size_t len2)
void SnmpStatsInc (int which)
uint32_t SnmpStatsGet (int which)
void SnmpStatsSet (int which, uint32_t value)
CONST uint8_tSnmpAuthParse (CONST uint8_t *data, size_t *length, uint8_t *sidp, size_t *slen, long *version)
 Parse header of community string based message.
uint8_tSnmpAuthBuild (SNMP_SESSION *session, uint8_t *data, size_t *length, size_t messagelen)
 Build header of community string based message.
int SnmpViewCreate (CONST char *name, CONST OID *subtree, size_t subtreelen, int type)
int SnmpViewFind (char *name)
int SnmpCommunityFind (CONST char *name, int *readView, int *writeView)
 Find community entry by name.
int SnmpCommunityCreate (CONST char *name, int readView, int writeView)
 Create a community entry.
int SnmpMibRegister (OID basename[], size_t baselen, SNMPVAR *vars, int num)
 Register MIB variables.
uint8_tSnmpMibFind (OID *name, size_t *namelen, uint8_t *type, size_t *len, uint16_t *acl, int exact, WMETHOD **wmethod, int *no_obj)
 Find MIB variable.
SNMP_PDUSnmpPduCreate (int cmd, CONST OID *name, size_t nlen)
 Create PDU with a given type and object ID.
int SnmpPduAddVariable (SNMP_PDU *pdu, OID *name, size_t nlen, uint8_t type, uint8_t *value, size_t vlen)
 Add variable to PDU.
void SnmpPduDestroy (SNMP_PDU *pdu)
 Destroy PDU.
SNMP_SESSIONSnmpSessionOpen (uint32_t ip, uint16_t port, uint8_t *id, size_t idlen)
 Open SNMP session.
void SnmpSessionClose (SNMP_SESSION *session)
 Close SNMP session.
int SnmpSessionSendPdu (SNMP_SESSION *session, SNMP_PDU *pdu)
 Send PDU.

Detailed Description

Simple network management protocol.


Define Documentation

#define SNMP_PORT   161

Standard UDP port for SNMP agents to receive requests messages.

Examples:
snmpd/snmpd.c.

Definition at line 56 of file snmp.h.

Referenced by main().

#define SNMP_TRAP_PORT   162

Standard UDP port for SNMP managers to receive notificaion messages.

Definition at line 62 of file snmp.h.

#define SNMP_MAX_LEN   500

Default maximum message size.

Definition at line 68 of file snmp.h.

Referenced by SnmpAgent(), and SnmpSessionSendPdu().

#define SNMP_VERSION_1   0

SNMPv1.

The original version, defined by RFC 1157.

Definition at line 75 of file snmp.h.

Referenced by SnmpAgentProcessRequest(), and SnmpAuthParse().

#define SNMP_VERSION_2C   1

SNMPv2c.

Community string-based SNMPv2, which was an attempt to combine the protocol operations of SNMPv2 with the security of SNMPv1, defined by RFCs 1901, 1905, and 1906.

Partly supplied by this code, work is in progress.

Definition at line 85 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_VERSION_3   3

SNMPv3.

An attempt by the IETF working group to merge the SNMPv2u and SNMPv2* proposals into a more widely accepted SNMPv3. The original version, defined by RFC 1157.

Not yet supported by this code.

Definition at line 95 of file snmp.h.

#define SNMP_MSG_GET   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0)

Definition at line 100 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_MSG_GETNEXT   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1)

Definition at line 101 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_MSG_RESPONSE   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x2)

Definition at line 102 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_MSG_SET   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x3)

Definition at line 103 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_MSG_TRAP   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4)

Definition at line 108 of file snmp.h.

Referenced by SnmpSessionSendPdu().

#define SNMP_MSG_GETBULK   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x5)

Definition at line 113 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_MSG_INFORM   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x6)

Definition at line 114 of file snmp.h.

#define SNMP_MSG_TRAP2   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x7)

Definition at line 115 of file snmp.h.

#define SNMP_MSG_REPORT   (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x8)

Definition at line 120 of file snmp.h.

#define SNMP_NOSUCHOBJECT   (ASN_CONTEXT | ASN_PRIMITIVE | 0x0)

Definition at line 125 of file snmp.h.

Referenced by SnmpVarBuild().

#define SNMP_NOSUCHINSTANCE   (ASN_CONTEXT | ASN_PRIMITIVE | 0x1)

Definition at line 126 of file snmp.h.

Referenced by SnmpVarBuild().

#define SNMP_ENDOFMIBVIEW   (ASN_CONTEXT | ASN_PRIMITIVE | 0x2)

Definition at line 127 of file snmp.h.

Referenced by SnmpVarBuild().

#define SNMP_ERR_NOERROR   0

Definition at line 132 of file snmp.h.

#define SNMP_ERR_TOOBIG   1

Definition at line 133 of file snmp.h.

#define SNMP_ERR_NOSUCHNAME   2

Definition at line 134 of file snmp.h.

#define SNMP_ERR_BADVALUE   3

Definition at line 135 of file snmp.h.

#define SNMP_ERR_READONLY   4

Definition at line 136 of file snmp.h.

#define SNMP_ERR_GENERR   5

Definition at line 137 of file snmp.h.

#define SNMP_ERR_NOACCESS   6

Definition at line 142 of file snmp.h.

#define SNMP_ERR_WRONGTYPE   7

Definition at line 143 of file snmp.h.

#define SNMP_ERR_WRONGLENGTH   8

Definition at line 144 of file snmp.h.

#define SNMP_ERR_WRONGENCODING   9

Definition at line 145 of file snmp.h.

#define SNMP_ERR_WRONGVALUE   10

Definition at line 146 of file snmp.h.

#define SNMP_ERR_NOCREATION   11

Definition at line 147 of file snmp.h.

#define SNMP_ERR_INCONSISTENTVALUE   12

Definition at line 148 of file snmp.h.

#define SNMP_ERR_RESOURCEUNAVAILABLE   13

Definition at line 149 of file snmp.h.

#define SNMP_ERR_COMMITFAILED   14

Definition at line 150 of file snmp.h.

#define SNMP_ERR_UNDOFAILED   15

Definition at line 151 of file snmp.h.

#define SNMP_ERR_AUTHORIZATIONERROR   16

Definition at line 152 of file snmp.h.

#define SNMP_ERR_NOTWRITABLE   17

Definition at line 153 of file snmp.h.

#define SNMP_ERR_INCONSISTENTNAME   18

Definition at line 154 of file snmp.h.

#define SNMP_TRAP_COLDSTART   0

Definition at line 159 of file snmp.h.

#define SNMP_TRAP_WARMSTART   1

Definition at line 160 of file snmp.h.

#define SNMP_TRAP_LINKDOWN   2

Definition at line 161 of file snmp.h.

#define SNMP_TRAP_LINKUP   3

Definition at line 162 of file snmp.h.

#define SNMP_TRAP_AUTHFAIL   4

Definition at line 163 of file snmp.h.

#define SNMP_TRAP_EGPNEIGHBORLOSS   5

Definition at line 164 of file snmp.h.

#define SNMP_TRAP_ENTERPRISESPECIFIC   6

Definition at line 165 of file snmp.h.

#define SNMP_OID_INTERNET   1, 3, 6, 1
Examples:
snmpd/snmpd.c.

Definition at line 170 of file snmp.h.

Referenced by main().

#define SNMP_OID_ENTERPRISES   SNMP_OID_INTERNET, 4, 1

Definition at line 171 of file snmp.h.

#define SNMP_OID_MIB2   SNMP_OID_INTERNET, 2, 1

Definition at line 172 of file snmp.h.

#define SNMP_OID_SNMPV2   SNMP_OID_INTERNET, 6

Definition at line 173 of file snmp.h.

#define SNMP_OID_SNMPMODULES   SNMP_OID_SNMPV2, 3

Definition at line 174 of file snmp.h.

#define SNMP_PARSE_ERROR   -1

Definition at line 178 of file snmp.h.

#define SNMP_BUILD_ERROR   -2

Definition at line 179 of file snmp.h.

#define MAX_SID_LEN   32

Maximum length of a community name.

Definition at line 182 of file snmp.h.

#define MAX_NAME_LEN   128

Maximum number of sub IDs in an OID.

Definition at line 184 of file snmp.h.

#define SNMP_ACT_RESERVE1   0

Definition at line 186 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_ACT_RESERVE2   1

Definition at line 187 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_ACT_COMMIT   2

Definition at line 188 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_ACT_ACTION   3

Definition at line 189 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_ACT_FREE   4

Definition at line 190 of file snmp.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_MAX_MSG_SIZE   1472
Examples:
snmpd/snmpd.c.

Definition at line 53 of file snmp_api.h.

Referenced by main().

#define SNMP_STAT_INPKTS   0

Definition at line 59 of file snmp_api.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_STAT_OUTPKTS   1

Definition at line 60 of file snmp_api.h.

Referenced by SnmpAgent().

#define SNMP_STAT_INBADVERSIONS   2

Definition at line 61 of file snmp_api.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_STAT_INBADCOMMUNITYNAMES   3

Definition at line 62 of file snmp_api.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_STAT_INBADCOMMUNITYUSES   4

Definition at line 63 of file snmp_api.h.

#define SNMP_STAT_INASNPARSEERRS   5

Definition at line 64 of file snmp_api.h.

Referenced by SnmpAgentProcessRequest().

#define SNMP_STAT_INTOOBIGS   6

Definition at line 65 of file snmp_api.h.

#define SNMP_STAT_INNOSUCHNAMES   7

Definition at line 66 of file snmp_api.h.

#define SNMP_STAT_INBADVALUES   8

Definition at line 67 of file snmp_api.h.

#define SNMP_STAT_INREADONLYS   9

Definition at line 68 of file snmp_api.h.

#define SNMP_STAT_INGENERRS   10

Definition at line 69 of file snmp_api.h.

#define SNMP_STAT_INTOTALREQVARS   11

Definition at line 70 of file snmp_api.h.

#define SNMP_STAT_INTOTALSETVARS   12

Definition at line 71 of file snmp_api.h.

#define SNMP_STAT_INGETREQUESTS   13

Definition at line 72 of file snmp_api.h.

#define SNMP_STAT_INGETNEXTS   14

Definition at line 73 of file snmp_api.h.

#define SNMP_STAT_INSETREQUESTS   15

Definition at line 74 of file snmp_api.h.

#define SNMP_STAT_INGETRESPONSES   16

Definition at line 75 of file snmp_api.h.

#define SNMP_STAT_INTRAPS   17

Definition at line 76 of file snmp_api.h.

#define SNMP_STAT_OUTTOOBIGS   18

Definition at line 77 of file snmp_api.h.

Referenced by SnmpVarBuild().

#define SNMP_STAT_OUTNOSUCHNAMES   19

Definition at line 78 of file snmp_api.h.

#define SNMP_STAT_OUTBADVALUES   20

Definition at line 79 of file snmp_api.h.

Referenced by SnmpVarBuild().

#define SNMP_STAT_OUTGENERRS   21

Definition at line 80 of file snmp_api.h.

#define SNMP_STAT_OUTGETREQUESTS   22

Definition at line 81 of file snmp_api.h.

#define SNMP_STAT_OUTGETNEXTS   23

Definition at line 82 of file snmp_api.h.

#define SNMP_STAT_OUTSETREQUESTS   24

Definition at line 83 of file snmp_api.h.

#define SNMP_STAT_OUTGETRESPONSES   25

Definition at line 84 of file snmp_api.h.

#define SNMP_STAT_OUTTRAPS   26

Definition at line 85 of file snmp_api.h.

#define SNMP_STAT_ENABLEAUTHENTRAPS   27

Definition at line 86 of file snmp_api.h.

#define SNMP_STAT_MAX   28

Definition at line 88 of file snmp_api.h.

Referenced by SnmpStatsGet(), SnmpStatsInc(), and SnmpStatsSet().

#define SNMP_VIEW_INCLUDED   1
Examples:
snmpd/snmpd.c.

Definition at line 56 of file snmp_config.h.

Referenced by main().

#define SNMP_VIEW_EXCLUDED   2

Definition at line 57 of file snmp_config.h.


Typedef Documentation

typedef struct _viewEntry VIEW_LIST
typedef int( WMETHOD)(int, uint8_t *, uint8_t, size_t, OID *, size_t)

Definition at line 53 of file snmp_mib.h.

typedef struct _SNMPVAR SNMPVAR
typedef struct _SNMP_VARLIST SNMP_VARLIST

Definition at line 54 of file snmp_pdu.h.

typedef struct _SUBTREE SUBTREE

Function Documentation

CONST uint8_t* SnmpVarParse ( CONST uint8_t data,
size_t *  dlen,
OID name,
size_t *  nlen,
uint8_t type,
uint8_t **  value,
size_t *  vlen 
)

Parse an SNMP variable.

Parameters:
dataPointer to start of the name/value pair.
dlenContains the number of valid bytes following the start of the variable. On exit, it is returned as the number of valid bytes following the end of this variable.
namePointer to a buffer that receives the name (OID).
nlenOn entry, this contains the maximum number of sub IDs accepted for the name. On exit, it is returned as the actual number sub IDs found in the name.
typePointer to the variable that receives the ASN type of the value.
valuePointer to variable that receives a pointer to the ASN1 encoded value of variable.
vlenPointer to the variable that receives the length of the value.
Returns:
Pointer to the first byte past the end of this name/value pair. Returns NULL on any error.

Definition at line 65 of file snmp.c.

References ASN_CONSTRUCTOR, ASN_OBJECT_ID, ASN_PRIMITIVE, ASN_SEQUENCE, ASN_UNIVERSAL, AsnHeaderParse(), AsnOidParse(), AsnSequenceParse(), and CONST.

Here is the call graph for this function:

uint8_t* SnmpVarBuild ( uint8_t data,
size_t *  dlen,
CONST OID name,
size_t  nlen,
uint8_t  type,
CONST uint8_t value,
size_t  vlen 
)

Build an SNMP variable.

Parameters:
dataPointer to start of the output buffer.
dlenContains the number of valid bytes following the start of the variable. On exit, it is returned as the number of valid bytes following the end of this variable.
nameName (OID).
nlenNumber of sub IDs of the name.
typeASN type of the value.
valuePointer to the value.
vlenLength of the value.
Returns:
Pointer to the first byte past the end of this name/value pair. Returns NULL on any error.

Definition at line 114 of file snmp.c.

References ASN_BIT_STR, ASN_CONSTRUCTOR, ASN_COUNTER, ASN_COUNTER64, ASN_GAUGE, ASN_INTEGER, ASN_IPADDRESS, ASN_NSAP, ASN_NULL, ASN_OBJECT_ID, ASN_OCTET_STR, ASN_OPAQUE, ASN_PRIMITIVE, ASN_SEQUENCE, ASN_TIMETICKS, ASN_UINTEGER, ASN_UNIVERSAL, AsnBitStringBuild(), AsnIntegerBuild(), AsnNullBuild(), AsnOctetStringBuild(), AsnOidBuild(), AsnSequenceBuild(), AsnUnsigned64Build(), AsnUnsignedBuild(), SNMP_ENDOFMIBVIEW, SNMP_NOSUCHINSTANCE, SNMP_NOSUCHOBJECT, SNMP_STAT_OUTBADVALUES, SNMP_STAT_OUTTOOBIGS, and SnmpStatsInc().

Here is the call graph for this function:

int SnmpAgentProcessRequest ( SNMP_SESSION sess,
CONST uint8_t in_data,
size_t  in_len,
uint8_t out_data,
size_t *  out_len 
)

Parse incoming and create outgoing packet.

Parameters:
in_dataPointer to the incoming packet.
in_lenNumber of valid bytes in the incoming packet.
out_dataPointer to a buffer for the outgoing packet.
out_lenPointer to the variable that receives the number of bytes in the outgoing packet.
out_lenPointer to a variable which contains the size of the output buffer on entry. On exit, it is returned as the number of valid bytes in the output buffer.
Returns:
0 upon success and -1 upon failure.

Definition at line 307 of file snmp_agent.c.

References ASN_INTEGER, ASN_PRIMITIVE, ASN_UNIVERSAL, AsnHeaderParse(), AsnIntegerBuild(), AsnIntegerParse(), AsnSequenceBuild(), CONST, SNMP_SESSION::sess_id, SNMP_SESSION::sess_id_len, SNMP_SESSION::sess_read_view, SNMP_SESSION::sess_version, SNMP_SESSION::sess_write_view, SNMP_ACT_ACTION, SNMP_ACT_COMMIT, SNMP_ACT_FREE, SNMP_ACT_RESERVE1, SNMP_ACT_RESERVE2, SNMP_MSG_GET, SNMP_MSG_GETBULK, SNMP_MSG_GETNEXT, SNMP_MSG_RESPONSE, SNMP_MSG_SET, SNMP_STAT_INASNPARSEERRS, SNMP_STAT_INBADCOMMUNITYNAMES, SNMP_STAT_INBADVERSIONS, SNMP_STAT_INPKTS, SNMP_VERSION_1, SNMP_VERSION_2C, SnmpAuthBuild(), SnmpAuthParse(), SnmpCommunityFind(), and SnmpStatsInc().

Referenced by SnmpAgent().

Here is the call graph for this function:

int SnmpAgent ( UDPSOCKET sock)

Run SNMP agent.

Normally runs in an endless loop, which is only left in case of an error.

Parameters:
sockUDP socket to use.
Returns:
Always -1.

Definition at line 468 of file snmp_agent.c.

References free(), malloc(), memset(), NutUdpReceiveFrom(), NutUdpSendTo(), SNMP_MAX_LEN, SNMP_STAT_OUTPKTS, SnmpAgentProcessRequest(), and SnmpStatsInc().

Referenced by main().

Here is the call graph for this function:

int SnmpOidLenCmp ( CONST OID name1,
CONST OID name2,
size_t  len 
)

Compare object identifiers up to a specified length.

Parameters:
name1First object identifier.
name2Second object identifier.
lenNumber of sub identifiers to compare.

Definition at line 56 of file snmp_api.c.

Referenced by SnmpOidCmp(), SnmpOidCmpIdx(), and SnmpOidTreeCmp().

int SnmpOidCmp ( CONST OID name1,
size_t  len1,
CONST OID name2,
size_t  len2 
)

Compare object identifiers.

Parameters:
name1First object identifier.
len1Length of first object identifier.
name2Second object identifier.
len2Length of second object identifier.
Returns:
0 if both are equal, 1 if first element is larger or -1 if first element is lower than the second one.

Definition at line 84 of file snmp_api.c.

References SnmpOidLenCmp().

Referenced by SnmpMibRegister().

Here is the call graph for this function:

int SnmpOidTreeCmp ( CONST OID objid,
size_t  objlen,
CONST OID treeid,
size_t  treelen 
)

Compare object identifier with tree element.

Parameters:
name1Object identifier.
len1Length of object identifier.
name2Tree identifier.
len2Length of tree identifier.
Returns:
0 if the object identifier is part of the subtree, -1 if it is located before the tree element or 1 if it is located after the tree element.

Definition at line 111 of file snmp_api.c.

References SnmpOidLenCmp().

Referenced by SnmpMibFind().

Here is the call graph for this function:

int SnmpOidCmpIdx ( CONST OID name1,
size_t  len1,
CONST OID name2,
size_t  len2,
OID  index 
)

Compare object identifiers with index added.

Parameters:
name1First object identifier.
len1Length of first object identifier.
name2Second object identifier.
len2Length of second object identifier.
indexIndex sub identifier.
Returns:
0 if both are equal, 1 if first element is larger or -1 if first element is lower than the second one.

Definition at line 134 of file snmp_api.c.

References SnmpOidLenCmp().

Here is the call graph for this function:

int SnmpOidEquals ( CONST OID name1,
size_t  len1,
CONST OID name2,
size_t  len2 
)

Definition at line 172 of file snmp_api.c.

References memcmp().

Here is the call graph for this function:

void SnmpStatsInc ( int  which)

Definition at line 181 of file snmp_api.c.

References SNMP_STAT_MAX.

Referenced by SnmpAgent(), SnmpAgentProcessRequest(), and SnmpVarBuild().

uint32_t SnmpStatsGet ( int  which)

Definition at line 188 of file snmp_api.c.

References SNMP_STAT_MAX.

void SnmpStatsSet ( int  which,
uint32_t  value 
)

Definition at line 196 of file snmp_api.c.

References SNMP_STAT_MAX.

CONST uint8_t* SnmpAuthParse ( CONST uint8_t data,
size_t *  length,
uint8_t sidp,
size_t *  slen,
long *  version 
)

Parse header of community string based message.

Retrieves version and community.

Parameters:
dataPoints to the message.
lengthBytes left in message.
sidpPointer to a buffer that receives the community string.
slenLength of the community string.
versionMessage version

Definition at line 54 of file snmp_auth.c.

References ASN_CONSTRUCTOR, ASN_SEQUENCE, AsnIntegerParse(), AsnOctetStringParse(), AsnSequenceParse(), and SNMP_VERSION_1.

Referenced by SnmpAgentProcessRequest().

Here is the call graph for this function:

uint8_t* SnmpAuthBuild ( SNMP_SESSION session,
uint8_t data,
size_t *  length,
size_t  messagelen 
)

Build header of community string based message.

Definition at line 81 of file snmp_auth.c.

References ASN_CONSTRUCTOR, ASN_INTEGER, ASN_OCTET_STR, ASN_PRIMITIVE, ASN_SEQUENCE, ASN_UNIVERSAL, AsnIntegerBuild(), AsnOctetStringBuild(), AsnSequenceBuild(), SNMP_SESSION::sess_id, SNMP_SESSION::sess_id_len, and SNMP_SESSION::sess_version.

Referenced by SnmpAgentProcessRequest().

Here is the call graph for this function:

int SnmpViewCreate ( CONST char *  name,
CONST OID subtree,
size_t  subtreelen,
int  type 
)
Parameters:
nameSymbolic name of this view.
typeEither SNMP_VIEW_INCLUDED or SNMP_VIEW_EXCLUDED.
Returns:
View index on success. Otherwise -1 is returned.

Definition at line 56 of file snmp_config.c.

References malloc(), memset(), _viewEntry::next, strcmp(), strcpy(), strlen(), _viewEntry::view_index, _viewEntry::view_name, _viewEntry::view_subtree, _viewEntry::view_subtree_len, and _viewEntry::view_type.

Referenced by main().

Here is the call graph for this function:

int SnmpViewFind ( char *  name)

Definition at line 98 of file snmp_config.c.

References _viewEntry::next, strcmp(), _viewEntry::view_index, and _viewEntry::view_name.

Here is the call graph for this function:

int SnmpCommunityFind ( CONST char *  name,
int *  readView,
int *  writeView 
)

Find community entry by name.

Parameters:
nameCommunity name.
readViewPointer to a variable that receives the view index for read access.
writeViewPointer to a variable that receives the view index for write access.
Returns:
0 on success, -1 otherwise.

Definition at line 124 of file snmp_config.c.

References _communityEntry::comm_name, _communityEntry::comm_read_view, _communityEntry::comm_write_view, _communityEntry::next, and strcmp().

Referenced by SnmpAgentProcessRequest().

Here is the call graph for this function:

int SnmpCommunityCreate ( CONST char *  name,
int  readView,
int  writeView 
)

Create a community entry.

Parameters:
nameCommunity name.
readViewView index for read access, obtained from a previous call to SnmpViewCreate().
writeViewView index for write access, obtained from a previous call to SnmpViewCreate().
Returns:
0 on success, -1 otherwise.

Definition at line 153 of file snmp_config.c.

References _communityEntry::comm_name, _communityEntry::comm_read_view, _communityEntry::comm_write_view, malloc(), memset(), _communityEntry::next, strcmp(), strcpy(), and strlen().

Referenced by main().

Here is the call graph for this function:

int SnmpMibRegister ( OID  basename[],
size_t  baselen,
SNMPVAR vars,
int  num 
)

Register MIB variables.

Definition at line 75 of file snmp_mib.c.

References malloc(), memcpy(), SnmpOidCmp(), _SUBTREE::sub_name, _SUBTREE::sub_namelen, _SUBTREE::sub_next, _SUBTREE::sub_numvars, and _SUBTREE::sub_vars.

Referenced by MibRegisterIfVars(), and MibRegisterSysVars().

Here is the call graph for this function:

uint8_t* SnmpMibFind ( OID name,
size_t *  namelen,
uint8_t type,
size_t *  len,
uint16_t acl,
int  exact,
WMETHOD **  wmethod,
int *  no_obj 
)

Find MIB variable.

Parameters:
name
namelen
type
len
acl
exact
wmethod
no_obj

Definition at line 114 of file snmp_mib.c.

References access(), free(), malloc(), memcpy(), SnmpOidTreeCmp(), _SUBTREE::sub_name, _SUBTREE::sub_namelen, _SUBTREE::sub_next, _SUBTREE::sub_numvars, _SUBTREE::sub_vars, _SNMPVAR::var_acl, _SNMPVAR::var_get, _SNMPVAR::var_name, _SNMPVAR::var_namelen, and _SNMPVAR::var_type.

Here is the call graph for this function:

SNMP_PDU* SnmpPduCreate ( int  cmd,
CONST OID name,
size_t  nlen 
)

Create PDU with a given type and object ID.

Parameters:
cmdPDU type.
nameObject identifier.
nlenNumber of sub IDs of the object identifier.

Definition at line 53 of file snmp_pdu.c.

References calloc, free(), malloc(), memcpy(), SNMP_PDU::pdu_cmd, SNMP_PDU::pdu_enterprise, and SNMP_PDU::pdu_enterprise_length.

Here is the call graph for this function:

int SnmpPduAddVariable ( SNMP_PDU pdu,
OID name,
size_t  nlen,
uint8_t  type,
uint8_t value,
size_t  vlen 
)

Add variable to PDU.

Parameters:
pduPointer to the PDU.
nameVariable name.
nlenNumber of sub IDs of the variable name.
typeVariable type.
valuePointer to the variable's value.
vlenLength of the variable value in byts.

Definition at line 83 of file snmp_pdu.c.

References ASN_COUNTER, ASN_GAUGE, ASN_INTEGER, ASN_TIMETICKS, ASN_UINTEGER, calloc, free(), malloc(), memcpy(), SNMP_PDU::pdu_variables, _SNMP_VARLIST::var_name, _SNMP_VARLIST::var_next, _SNMP_VARLIST::var_nlen, _SNMP_VARLIST::var_type, _SNMP_VARLIST::var_val, _SNMP_VARLIST::var_vlen, and _SNMP_VARLIST::var_vptr.

Here is the call graph for this function:

void SnmpPduDestroy ( SNMP_PDU pdu)

Destroy PDU.

Parameters:
pduPointer to the PDU info, obtained by a call to SnmpPduCreate().

Definition at line 137 of file snmp_pdu.c.

References free(), SNMP_PDU::pdu_enterprise, SNMP_PDU::pdu_variables, _SNMP_VARLIST::var_name, _SNMP_VARLIST::var_next, _SNMP_VARLIST::var_val, and _SNMP_VARLIST::var_vptr.

Here is the call graph for this function:

SNMP_SESSION* SnmpSessionOpen ( uint32_t  ip,
uint16_t  port,
uint8_t id,
size_t  idlen 
)

Open SNMP session.

Parameters:
ipRemote IP address.
portRemote port number.
idCommunity name.
idlenLength of the community name.
Returns:
Pointer to a newly created session info.

Definition at line 61 of file snmp_session.c.

References calloc, free(), memcpy(), NutUdpCreateSocket(), SNMP_SESSION::sess_id, SNMP_SESSION::sess_id_len, SNMP_SESSION::sess_rem_addr, SNMP_SESSION::sess_rem_port, and SNMP_SESSION::sess_sock.

Here is the call graph for this function:

void SnmpSessionClose ( SNMP_SESSION session)

Close SNMP session.

Parameters:
sessionPoints to the session info, obtained by calling SnmpSessionOpen().

Definition at line 90 of file snmp_session.c.

References free(), NutUdpDestroySocket(), and SNMP_SESSION::sess_sock.

Here is the call graph for this function:

int SnmpSessionSendPdu ( SNMP_SESSION session,
SNMP_PDU pdu 
)

Send PDU.

Parameters:
sessionPoints to the session info, obtained by calling SnmpSessionOpen().
pduPoints to the PDU info, obtained by calling SnmpPduCreate().
Returns:
0 on success, -1 otherwise.

Definition at line 256 of file snmp_session.c.

References free(), malloc(), NutUdpSendTo(), SNMP_PDU::pdu_cmd, SNMP_PDU::pdu_reqid, SNMP_SESSION::sess_rem_addr, SNMP_SESSION::sess_rem_port, SNMP_SESSION::sess_sock, SNMP_MAX_LEN, and SNMP_MSG_TRAP.

Here is the call graph for this function: