yumapro  24.10-1
YumaPro SDK
Loading...
Searching...
No Matches
Utility Functions

Utility functions for net-snmp agent for SNMP support. More...

Collaboration diagram for Utility Functions:

Functions

val_value_tagt_ypsnmp_bestmatch_next_index (yangapi_cb_t *rcb)
 Find the next best matching list entry in the Queue. More...
 
val_value_tagt_ypsnmp_get_first_getnextlist (yangapi_cb_t *rcb)
 Get the first list val_value structure in getnext_listQ. More...
 
val_value_tagt_ypsnmp_get_next_getnextlist (val_value_t *list)
 Get the next list val_value structure in getnext_listQ. More...
 
boolean agt_ypsnmp_match_obj (obj_template_t *targetobj, obj_template_t *curobj)
 Checks if the current object in the walker is the target object for the request. More...
 
boolean agt_ypsnmp_match_index (yangapi_cb_t *rcb, val_value_t *keyval)
 Checks if the current index in the walker is the target index for the request. More...
 
obj_template_tagt_ypsnmp_get_table_obj (obj_template_t *obj)
 Find the Table object of the current object. More...
 
obj_template_tagt_ypsnmp_get_parent_obj (obj_template_t *obj)
 Find the complex parent of the current leaf object. More...
 
boolean agt_ypsnmp_is_scalar_obj (obj_template_t *curobj)
 Check if the object is a scalar object. More...
 
boolean agt_ypsnmp_is_augmented_obj (obj_template_t *curobj)
 Check if the object is an augmented object. More...
 
xmlChar * agt_ypsnmp_convert_physaddr (val_value_t *val)
 Converts the value of ifPhysAddress leaf element from yang syntax to SMI syntax expected by snmp client. More...
 
netsnmp_variable_list * agt_ypsnmp_create_snmp_varbind_object (const oid *name, size_t name_length, u_char type, const void *value, size_t len)
 Allocates and creates a new netsnmp variable binding object. More...
 
void agt_ypsnmp_append_varbind_to_list (netsnmp_variable_list **list, netsnmp_variable_list *var)
 Adds the given netsnmp variable binding object to the end of the list of given pdu. More...
 
obj_oid_tagt_ypsnmp_convert_varbind_to_oid (netsnmp_variable_list *var_ptr)
 Converts an SNMP OID string into an internal object. More...
 
status_t agt_ypsnmp_set_varbind (ses_cb_t *scb, netsnmp_pdu *pdu, val_value_t *val, const obj_oid_t *oid_obj)
 Set the return Varbind based on the found value. More...
 
status_t agt_ypsnmp_setup_peeraddr (ses_cb_t *scb, netsnmp_pdu *pdu)
 Setup the scb->peeraddr for debugging and auditing. More...
 
yangapi_method_t agt_ypsnmp_get_yangapi_method (uint8 msg_code)
 Get the YANGAPI method from the SNMP method. More...
 
xmlChar * agt_ypsnmp_make_restconf_uri (obj_template_t *obj)
 Make a RESTCONF URI string from the specified OID string. More...
 
void agt_ypsnmp_log_pdu (netsnmp_pdu *pdu)
 logs the received SNMP PDU packet contents More...
 
const void * agt_ypsnmp_get_varbind_value (netsnmp_variable_list *var)
 Get the Varbind value. More...
 
const xmlChar * agt_ypsnmp_get_getnext_modename (ypsnmp_getnext_mode_t getnextmode)
 Get the getnext mode name from its enum. More...
 
obj_oid_tagt_ypsnmp_get_index_oid (obj_oid_t *full_oid, uint32 index_length)
 parse requested OID and strip out index OID More...
 
status_t agt_ypsnmp_convert_oid2chars (xmlChar *str, uint32 len, const oid_t *useoid)
 Converts an OID to its character form. More...
 
status_t agt_ypsnmp_convert_str_oid2str (xmlChar *str, uint32 len, oid_t *useoid)
 Converts a string OID to its string form. More...
 
status_t agt_ypsnmp_convert_str2oid (const xmlChar *str, oid_t *useoid, uint32 len)
 Converts a string to its OID form. More...
 
status_t agt_ypsnmp_indexoid_to_value (yangapi_cb_t *rcb, obj_template_t *obj, uint32 index_length)
 Parse requested OID and strip out index OID. More...
 
status_t agt_ypsnmp_value_to_indexoid (yangapi_cb_t *rcb, val_value_t *list)
 Converts val_value list with keys into index OID. More...
 
ypsnmp_agent_session_tagt_ypsnmp_init_agent_session (netsnmp_session *session, netsnmp_pdu *pdu)
 Allocate new ypsnmp session context. More...
 
void agt_ypsnmp_free_agent_session (ypsnmp_agent_session_t *asp)
 free the ypsnmp session and deallocate any associated memory More...
 
void free_varbind (netsnmp_variable_list *var)
 Frees the variable and any malloc'd data associated with it. More...
 
void free_varbind_yp (netsnmp_variable_list *var)
 Frees the variable and any malloc'd data associated with it. More...
 

Detailed Description

Utility functions for net-snmp agent for SNMP support.

Requires WITH_SNMP=1 in build and –with-snmp=true CLI parameter at runtime.

Function Documentation

◆ agt_ypsnmp_append_varbind_to_list()

void agt_ypsnmp_append_varbind_to_list ( netsnmp_variable_list **  list,
netsnmp_variable_list *  var 
)

Adds the given netsnmp variable binding object to the end of the list of given pdu.

Only present if WITH_SNMP=1.

Parameters
listaddress of varbind list to add to
varvariable binding object

◆ agt_ypsnmp_bestmatch_next_index()

val_value_t * agt_ypsnmp_bestmatch_next_index ( yangapi_cb_t rcb)

Find the next best matching list entry in the Queue.

Only present if WITH_SNMP=1.

Parameters
rcbrestapi request control block to use
Returns
pointer to the entry or NULL
Here is the call graph for this function:

◆ agt_ypsnmp_convert_oid2chars()

status_t agt_ypsnmp_convert_oid2chars ( xmlChar *  str,
uint32  len,
const oid_t useoid 
)

Converts an OID to its character form.

in example 5 . 1 . 2 . 3 . 4 . 5 = 12345

Only present if WITH_SNMP=1.

Parameters
[out]strbuffer to fill in
lenlength of the buffer.
useoidthe oid.
Returns
status
Here is the caller graph for this function:

◆ agt_ypsnmp_convert_physaddr()

xmlChar * agt_ypsnmp_convert_physaddr ( val_value_t val)

Converts the value of ifPhysAddress leaf element from yang syntax to SMI syntax expected by snmp client.

Only present if WITH_SNMP=1.

Parameters
valval node
Returns
smi_value converted value of ifPhysAddress
Here is the caller graph for this function:

◆ agt_ypsnmp_convert_str2oid()

status_t agt_ypsnmp_convert_str2oid ( const xmlChar *  str,
oid_t useoid,
uint32  len 
)

Converts a string to its OID form.

in example "hello" = 5 . 'h' . 'e' . 'l' . 'l' . 'o'

Only present if WITH_SNMP=1.

Parameters
[out]strbuffer to fill in
useoidthe oid.
lenthe length of the oid.
Returns
status
Here is the caller graph for this function:

◆ agt_ypsnmp_convert_str_oid2str()

status_t agt_ypsnmp_convert_str_oid2str ( xmlChar *  str,
uint32  len,
oid_t useoid 
)

Converts a string OID to its string form.

in example 5 . 'h' . 'e' . 'l' . 'l' . 'o' = "hello\0" (null terminated)

Only present if WITH_SNMP=1.

Parameters
[out]strbuffer to fill in
lenthe length of the buffer.
useoidthe oid.
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ agt_ypsnmp_convert_varbind_to_oid()

obj_oid_t * agt_ypsnmp_convert_varbind_to_oid ( netsnmp_variable_list *  var_ptr)

Converts an SNMP OID string into an internal object.

Only present if WITH_SNMP=1.

Parameters
var_ptrpointer to the varbind
Returns
pointer to new ypsnmp session context on success, NULL on error
Here is the call graph for this function:

◆ agt_ypsnmp_create_snmp_varbind_object()

netsnmp_variable_list * agt_ypsnmp_create_snmp_varbind_object ( const oid *  name,
size_t  name_length,
u_char  type,
const void *  value,
size_t  len 
)

Allocates and creates a new netsnmp variable binding object.

Add a variable with the requested name to the end of the list of variables for this pdu.

Only present if WITH_SNMP=1.

Parameters
nameoid value
name_lengthlength of above oid
typeASN type
valuevalue to be set
lenlength of the value
Returns
pointer to netsnmp_variable_list, else null
Here is the call graph for this function:

◆ agt_ypsnmp_free_agent_session()

void agt_ypsnmp_free_agent_session ( ypsnmp_agent_session_t asp)

free the ypsnmp session and deallocate any associated memory

Only present if WITH_SNMP=1.

Parameters
asphandle to ypsnmp session to free
Here is the caller graph for this function:

◆ agt_ypsnmp_get_first_getnextlist()

val_value_t * agt_ypsnmp_get_first_getnextlist ( yangapi_cb_t rcb)

Get the first list val_value structure in getnext_listQ.

Only present if WITH_SNMP=1.

Parameters
rcbrestapi request control block to use
Returns
pointer to the first entry or NULL if empty Q
Here is the caller graph for this function:

◆ agt_ypsnmp_get_getnext_modename()

const xmlChar * agt_ypsnmp_get_getnext_modename ( ypsnmp_getnext_mode_t  getnextmode)

Get the getnext mode name from its enum.

Only present if WITH_SNMP=1.

Parameters
getnextmodegetnext mode name enumeration
Returns
string for the enumeration

◆ agt_ypsnmp_get_index_oid()

obj_oid_t * agt_ypsnmp_get_index_oid ( obj_oid_t full_oid,
uint32  index_length 
)

parse requested OID and strip out index OID

Only present if WITH_SNMP=1.

Parameters
full_oidcomplete requested OID
index_lengthlength of the index, how mane .x.y.z...
Returns
Index OID appended after base OID
Here is the call graph for this function:

◆ agt_ypsnmp_get_next_getnextlist()

val_value_t * agt_ypsnmp_get_next_getnextlist ( val_value_t list)

Get the next list val_value structure in getnext_listQ.

Only present if WITH_SNMP=1.

Parameters
listcurrent list entry
Returns
pointer to the next entry or NULL
Here is the caller graph for this function:

◆ agt_ypsnmp_get_parent_obj()

obj_template_t * agt_ypsnmp_get_parent_obj ( obj_template_t obj)

Find the complex parent of the current leaf object.

Skips:

  • augments
  • choice and cases Stops only on list or container

Only present if WITH_SNMP=1.

Parameters
objleaf obj_template to use
Returns
pointer to complex parent object or NULL if none or not found
Here is the call graph for this function:
Here is the caller graph for this function:

◆ agt_ypsnmp_get_table_obj()

obj_template_t * agt_ypsnmp_get_table_obj ( obj_template_t obj)

Find the Table object of the current object.

Skips:

  • augments
  • choice and cases Stops only on container

Only present if WITH_SNMP=1.

Parameters
objcurrent obj_template to use
Returns
pointer to Table parent object or NULL if none or not found
Here is the call graph for this function:

◆ agt_ypsnmp_get_varbind_value()

const void * agt_ypsnmp_get_varbind_value ( netsnmp_variable_list *  var)

Get the Varbind value.

Only present if WITH_SNMP=1.

Parameters
varvarbind variable
Returns
variable value from varbind

◆ agt_ypsnmp_get_yangapi_method()

yangapi_method_t agt_ypsnmp_get_yangapi_method ( uint8  msg_code)

Get the YANGAPI method from the SNMP method.

Only present if WITH_SNMP=1.

Parameters
msg_codeuint8 SNMP pdu command code
Returns
YANGAPI method enum

◆ agt_ypsnmp_indexoid_to_value()

status_t agt_ypsnmp_indexoid_to_value ( yangapi_cb_t rcb,
obj_template_t obj,
uint32  index_length 
)

Parse requested OID and strip out index OID.

For tabular objects ONLY. Converts index OID into val_value, saves all key values into Q of val_values

Only present if WITH_SNMP=1.

  RFC 1902
  7.7.  Mapping of the INDEX clause

   The INDEX clause, which must be present if that object corresponds to
    a conceptual row (unless an AUGMENTS clause is present instead), and
    must be absent otherwise, defines instance identification information
    for the columnar objects subordinate to that object.

    The instance identification information in an INDEX clause must
    specify object(s) such that value(s) of those object(s) will
    unambiguously distinguish a conceptual row.  The syntax of those
    objects indicate how to form the instance-identifier:

*(1)  integer-valued:  a single sub-identifier taking the integer value
      (this works only for non-negative integers);

*(2)  string-valued, fixed-length strings (or variable-length preceded by
      the IMPLIED keyword):  `n' sub-identifiers, where `n' is the length
      of the string (each octet of the string is encoded in a separate
      sub-identifier);

*(3)  string-valued, variable-length strings (not preceded by the IMPLIED
      keyword):  `n+1' sub-identifiers, where `n' is the length of the
      string (the first sub-identifier is `n' itself, following this,
      each octet of the string is encoded in a separate sub-identifier);

*(4)  object identifier-valued (when preceded by the IMPLIED keyword):
      `n' sub-identifiers, where `n' is the number of sub-identifiers in
      the value (each sub-identifier of the value is copied into a
      separate sub-identifier);

*(5)  object identifier-valued (when not preceded by the IMPLIED
      keyword):  `n+1' sub-identifiers, where `n' is the number of sub-
      identifiers in the value (the first sub-identifier is `n' itself,
      following this, each sub-identifier in the value is copied);

*(6)  IpAddress-valued:  4 sub-identifiers, in the familiar a.b.c.d
      notation.
Parameters
[in,out]rcbrest control block
  • rcb->target_keyvalQ malloced and set
  • rcb->target_list malloced and set
objobject to use
index_lengthlength of the index
Returns
status
Here is the call graph for this function:

◆ agt_ypsnmp_init_agent_session()

ypsnmp_agent_session_t * agt_ypsnmp_init_agent_session ( netsnmp_session *  session,
netsnmp_pdu *  pdu 
)

Allocate new ypsnmp session context.

Only present if WITH_SNMP=1.

Parameters
sessionnet-snmp session to use
pduPDU for context
Returns
pointer to new ypsnmp session context on success, NULL on error
Here is the caller graph for this function:

◆ agt_ypsnmp_is_augmented_obj()

boolean agt_ypsnmp_is_augmented_obj ( obj_template_t curobj)

Check if the object is an augmented object.

That's, if the object is inside augment statement

Only present if WITH_SNMP=1.

Parameters
curobjleaf obj_template to use
Returns
TRUE if the curent object is the augmented object
Here is the call graph for this function:

◆ agt_ypsnmp_is_scalar_obj()

boolean agt_ypsnmp_is_scalar_obj ( obj_template_t curobj)

Check if the object is a scalar object.

Only present if WITH_SNMP=1.

Parameters
curobjleaf obj_template to use
Returns
TRUE if the curent object is the scalar object
FALSE if the object is tabular
Here is the call graph for this function:

◆ agt_ypsnmp_log_pdu()

void agt_ypsnmp_log_pdu ( netsnmp_pdu *  pdu)

logs the received SNMP PDU packet contents

Only present if WITH_SNMP=1.

Parameters
pdureceived SNMP protocol data unit (PDU)
Here is the caller graph for this function:

◆ agt_ypsnmp_make_restconf_uri()

xmlChar * agt_ypsnmp_make_restconf_uri ( obj_template_t obj)

Make a RESTCONF URI string from the specified OID string.

Only present if WITH_SNMP=1.

Parameters
objobject to make the URI string for
Returns
malloced uri - RESTCONF uri for given pdu, else NULL if unable to generate one
Here is the call graph for this function:

◆ agt_ypsnmp_match_index()

boolean agt_ypsnmp_match_index ( yangapi_cb_t rcb,
val_value_t keyval 
)

Checks if the current index in the walker is the target index for the request.

Only present if WITH_SNMP=1.

Parameters
rcbrestapi control block to use
keyvalkey value to match
Returns
TRUE is the curent object is the target object for the target index
Here is the call graph for this function:

◆ agt_ypsnmp_match_obj()

boolean agt_ypsnmp_match_obj ( obj_template_t targetobj,
obj_template_t curobj 
)

Checks if the current object in the walker is the target object for the request.

Only present if WITH_SNMP=1.

Parameters
targetobjfirst obj_template to use
curobjanother obj_template to use for compar
Returns
TRUE is the curent object is the target object for the target index
Here is the call graph for this function:

◆ agt_ypsnmp_set_varbind()

status_t agt_ypsnmp_set_varbind ( ses_cb_t scb,
netsnmp_pdu *  pdu,
val_value_t val,
const obj_oid_t oid_obj 
)

Set the return Varbind based on the found value.

The mapping between YANG and SMIv2 data types is defined in RFC6643

rcb->variables is updated with the final return Varbinds. Or pdu->variables is updated in case of Traps responce Only present if WITH_SNMP=1.

Parameters
scbsession control block
pduSNMP PDU->varbinds to use instead of SCB->varbinds
valfound value to use
oid_objcorresponding OID value for the val
Returns
status
Here is the call graph for this function:

◆ agt_ypsnmp_setup_peeraddr()

status_t agt_ypsnmp_setup_peeraddr ( ses_cb_t scb,
netsnmp_pdu *  pdu 
)

Setup the scb->peeraddr for debugging and auditing.

Only present if WITH_SNMP=1.

Parameters
scbsession control block to use
pduSNMP PDU to use
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ agt_ypsnmp_value_to_indexoid()

status_t agt_ypsnmp_value_to_indexoid ( yangapi_cb_t rcb,
val_value_t list 
)

Converts val_value list with keys into index OID.

Only present if WITH_SNMP=1.

Parameters
[in,out]rcbyangapi control block to use.
  • rcb->index_oid malloced and set
  • rcb->index_oid->oidc set
  • rcb->index_oid->cnt set
listlist val_value node with only keys in it
Returns
status
Here is the call graph for this function:

◆ free_varbind()

void free_varbind ( netsnmp_variable_list *  var)

Frees the variable and any malloc'd data associated with it.

Only present if WITH_SNMP=1.

Parameters
varvariable binding object
Here is the caller graph for this function:

◆ free_varbind_yp()

void free_varbind_yp ( netsnmp_variable_list *  var)

Frees the variable and any malloc'd data associated with it.

Using m__free API

Only present if WITH_SNMP=1.

Parameters
varvariable binding object