Implement SNMP bits data type support
This commit is contained in:
parent
dcfa367b3d
commit
5c05748cfe
6 changed files with 138 additions and 37 deletions
|
|
@ -178,7 +178,7 @@ snmp_scalar_return(cxobj *xs,
|
|||
}
|
||||
if (type_yang2asn1(ys, &asn1type, 1) < 0)
|
||||
goto done;
|
||||
if ((ret = type_xml2snmp(xmlstr, &asn1type, &snmpval, &snmplen, &reason)) < 0)
|
||||
if ((ret = type_xml2snmp(xmlstr, ys, &asn1type, &snmpval, &snmplen, &reason)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clixon_debug(CLIXON_DBG_SNMP, "%s", reason);
|
||||
|
|
@ -298,7 +298,7 @@ snmp_scalar_get(clixon_handle h,
|
|||
}
|
||||
goto ok;
|
||||
}
|
||||
if ((ret = type_xml2snmp(xmlstr, &asn1type, &snmpval, &snmplen, &reason)) < 0)
|
||||
if ((ret = type_xml2snmp(xmlstr, ys, &asn1type, &snmpval, &snmplen, &reason)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clixon_debug(CLIXON_DBG_SNMP, "%s", reason);
|
||||
|
|
|
|||
|
|
@ -611,6 +611,12 @@ type_yang2asn1(yang_stmt *ys,
|
|||
(strcmp(display_hint, "255a")==0 ||
|
||||
strcmp(display_hint, "255t")==0))
|
||||
at = CLIXON_ASN_FIXED_STRING;
|
||||
|
||||
/* Special case for bits type because netsnmp lib returns ASN_OCTET_STRING. In this case
|
||||
we have to define an extended type to be able to handle bits type correctly later on. */
|
||||
if (strcmp(restype, "bits") == 0){
|
||||
at = CLIXON_ASN_BIT_STRING;
|
||||
}
|
||||
}
|
||||
if (asn1_type)
|
||||
*asn1_type = at;
|
||||
|
|
@ -648,6 +654,7 @@ type_snmp2xml(yang_stmt *ys,
|
|||
char *restype = NULL; /* resolved type */
|
||||
char *origtype = NULL; /* original type */
|
||||
yang_stmt *yrestype = NULL;
|
||||
cbuf *cb = NULL;
|
||||
int ret;
|
||||
|
||||
clixon_debug(CLIXON_DBG_SNMP, "");
|
||||
|
|
@ -706,6 +713,20 @@ type_snmp2xml(yang_stmt *ys,
|
|||
case ASN_GAUGE: // 0x42
|
||||
cv_uint32_set(cv, *requestvb->val.integer);
|
||||
break;
|
||||
case CLIXON_ASN_BIT_STRING:{ /* special case for bit string */
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clixon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = yang_val2bitsstr(yrestype, requestvb->val.bitstring, requestvb->val_len, cb)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "Invalid bits value");
|
||||
goto fail;
|
||||
}
|
||||
cv_strncpy(cv, cbuf_get(cb), cbuf_len(cb));
|
||||
break;
|
||||
}
|
||||
case ASN_IPADDRESS:{
|
||||
struct in_addr addr;
|
||||
memcpy(&addr.s_addr, requestvb->val.string, 4);
|
||||
|
|
@ -753,6 +774,8 @@ type_snmp2xml(yang_stmt *ys,
|
|||
free(origtype);
|
||||
if (cv)
|
||||
cv_free(cv);
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
return retval;
|
||||
fail:
|
||||
retval = 0;
|
||||
|
|
@ -849,6 +872,7 @@ type_xml2snmp_pre(char *xmlstr0,
|
|||
/*! Given snmp string value (as translated from XML) parse into snmp value
|
||||
*
|
||||
* @param[in] snmpstr SNMP type string
|
||||
* @param[in] ys YANG node
|
||||
* @param[in,out] asn1type ASN.1 type id
|
||||
* @param[out] snmpval Malloc:ed snmp type
|
||||
* @param[out] snmplen Length of snmp type
|
||||
|
|
@ -861,18 +885,24 @@ type_xml2snmp_pre(char *xmlstr0,
|
|||
*/
|
||||
int
|
||||
type_xml2snmp(char *snmpstr,
|
||||
yang_stmt *ys,
|
||||
int *asn1type,
|
||||
u_char **snmpval,
|
||||
size_t *snmplen,
|
||||
char **reason)
|
||||
{
|
||||
int retval = -1;
|
||||
int ret;
|
||||
int retval = -1;
|
||||
int ret;
|
||||
yang_stmt *yrestype; /* resolved type */
|
||||
|
||||
if (snmpval == NULL || snmplen == NULL){
|
||||
clixon_err(OE_UNIX, EINVAL, "snmpval or snmplen is NULL");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (snmp_yang_type_get(ys, NULL, NULL, &yrestype, NULL)) // XXX yrestype
|
||||
goto done;
|
||||
|
||||
switch (*asn1type){
|
||||
case CLIXON_ASN_ROWSTATUS:
|
||||
*asn1type = ASN_INTEGER;
|
||||
|
|
@ -978,6 +1008,15 @@ type_xml2snmp(char *snmpstr,
|
|||
}
|
||||
*asn1type = ASN_OCTET_STR;
|
||||
break;
|
||||
case CLIXON_ASN_BIT_STRING:
|
||||
if ((ret = yang_bitsstr2val(yrestype, snmpstr, snmpval, snmplen)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "Invalid bits valstr %s", snmpstr);
|
||||
goto fail;
|
||||
}
|
||||
*asn1type = ASN_OCTET_STR;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ extern "C" {
|
|||
* Must be back to proper net-snmp ASN_ types in type_snmp2xml and type_xml2snmp
|
||||
* before calling netsnmp API
|
||||
*/
|
||||
#define CLIXON_ASN_BIT_STRING 252 /* Special case used to identify a bit string data type */
|
||||
#define CLIXON_ASN_EXTRAS 253 /* Special case clixon address >= this */
|
||||
#define CLIXON_ASN_PHYS_ADDR 253 /* Special case phy-address */
|
||||
#define CLIXON_ASN_FIXED_STRING 254 /* RFC2578 Sec 7.7: String-valued, fixed-length */
|
||||
|
|
@ -101,7 +102,7 @@ int type_snmp2xml(yang_stmt *ys,
|
|||
netsnmp_request_info *requests,
|
||||
char **valstr);
|
||||
int type_xml2snmp_pre(char *xmlstr, yang_stmt *ys, char **snmpstr);
|
||||
int type_xml2snmp(char *snmpstr, int *asn1type, u_char **snmpval, size_t *snmplen, char **reason);
|
||||
int type_xml2snmp(char *snmpstr, yang_stmt *ys, int *asn1type, u_char **snmpval, size_t *snmplen, char **reason);
|
||||
int snmp_yang2xpath(yang_stmt *ys, cvec *keyvec, char **xpath);
|
||||
int snmp_str2oid(char *str, yang_stmt *yi, oid *objid, size_t *objidlen);
|
||||
int snmp_oid2str(oid **oidi, size_t *oidilen, yang_stmt *yi, cg_var *cv);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue