Add support decimal64 for snmp

Signed-off-by: Dmitry Grinberg <dima.g@siklu.com>
This commit is contained in:
stass 2023-02-14 11:56:37 +02:00 committed by Dmitry Grinberg
parent 411a67f9d6
commit 980c7d082f

View file

@ -108,6 +108,7 @@ static const map_str2int snmp_type_map[] = {
{"uint64", ASN_COUNTER64}, // 0x46 / 70 {"uint64", ASN_COUNTER64}, // 0x46 / 70
{"boolean", ASN_INTEGER}, // 2 special case -> enumeration {"boolean", ASN_INTEGER}, // 2 special case -> enumeration
{"string", ASN_IPADDRESS}, // 64 {"string", ASN_IPADDRESS}, // 64
{"decimal64", ASN_OCTET_STR},
{NULL, -1} {NULL, -1}
}; };
@ -127,6 +128,7 @@ static const map_str2int snmp_orig_map[] = {
{"ipv4-address", ASN_IPADDRESS}, // 0x40 / 64 (This is used instead) {"ipv4-address", ASN_IPADDRESS}, // 0x40 / 64 (This is used instead)
{"RowStatus", CLIXON_ASN_ROWSTATUS}, // 0x40 / 64 (This is used instead) {"RowStatus", CLIXON_ASN_ROWSTATUS}, // 0x40 / 64 (This is used instead)
{"phys-address", CLIXON_ASN_PHYS_ADDR}, /* Clixon extended string type */ {"phys-address", CLIXON_ASN_PHYS_ADDR}, /* Clixon extended string type */
{"decimal64", ASN_OCTET_STR},
{NULL, -1} {NULL, -1}
}; };
@ -750,6 +752,21 @@ type_xml2snmp_pre(char *xmlstr0,
else else
str = "1"; str = "1";
} }
else if( strcmp(restype, "decimal64") == 0 ) {
char **reason;
cbuf *cb = cbuf_new();
cg_var* cv = yang_cv_get(ys);
int64_t num;
if( (ret = parse_dec64(xmlstr0, cv_dec64_n_get(cv), &num, reason)) < 0)
goto done;
if (ret == 0){
clicon_debug(1, "Invalid decimal64 valstr %s", xmlstr0);
goto fail;
}
cv_dec64_i_set(cv, num);
cv2cbuf(cv, cb);
str = cbuf_get(cb);
}
else{ else{
str = xmlstr0; str = xmlstr0;
} }