SNMP frontend: special case for SnmpAdminString with not null-terminated string

This commit is contained in:
Olof hagsand 2022-05-28 15:13:53 +02:00
parent 7bcecc155a
commit 18ff854e12
2 changed files with 17 additions and 2 deletions

View file

@ -107,7 +107,9 @@ static const map_str2int snmp_type_map[] = {
{"boolean", ASN_INTEGER}, // 2 special case -> enumeration {"boolean", ASN_INTEGER}, // 2 special case -> enumeration
{NULL, -1} {NULL, -1}
}; };
#define CLIXON_ASN_PHYS_ADDR 0x4242
#define CLIXON_ASN_PHYS_ADDR 0x4242 /* Special case phy-address */
#define CLIXON_ASN_ADMIN_STRING 0x4243 /* Special case SnmpAdminString */
/* Map between SNMP message / mode str and int form /* Map between SNMP message / mode str and int form
*/ */
@ -155,6 +157,8 @@ snmp_handle_free(clixon_snmp_handle *sh)
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* @see type_yang2snmp, yang only * @see type_yang2snmp, yang only
* @note there are some special cases where extended clixon asn1-types are used to convey info
* to type_snmpstr2val, these types are prefixed with CLIXON_ASN_
*/ */
int int
type_yang2asn1(yang_stmt *ys, type_yang2asn1(yang_stmt *ys,
@ -200,6 +204,9 @@ type_yang2asn1(yang_stmt *ys,
else if (strcmp(origtype, "phys-address")==0){ else if (strcmp(origtype, "phys-address")==0){
at = CLIXON_ASN_PHYS_ADDR; /* Clixon extended string type */ at = CLIXON_ASN_PHYS_ADDR; /* Clixon extended string type */
} }
else if (strcmp(origtype, "SnmpAdminString")==0){
at = CLIXON_ASN_ADMIN_STRING; /* cf extension display-type 255T? */
}
/* translate to asn.1 */ /* translate to asn.1 */
else if ((at = clicon_str2int(snmp_type_map, restype)) < 0){ else if ((at = clicon_str2int(snmp_type_map, restype)) < 0){
@ -498,6 +505,14 @@ type_snmpstr2val(char *snmpstr,
*asn1type = ASN_OCTET_STR; *asn1type = ASN_OCTET_STR;
break; break;
} }
case CLIXON_ASN_ADMIN_STRING: /* OCTET-STRING with decrement length */
*snmplen = strlen(snmpstr);
if ((*snmpval = (u_char*)strdup((snmpstr))) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
goto done;
}
*asn1type = ASN_OCTET_STR;
break;
default: default:
assert(0); assert(0);
} }

View file

@ -150,7 +150,7 @@ VALUE="foo bar"
TYPE=STRING # SnmpAdminString TYPE=STRING # SnmpAdminString
new "Get $NAME default" new "Get $NAME default"
expectpart "$($snmpget $OID)" 0 "$OID = $TYPE: So long, and thanks for all the fish!." expectpart "$($snmpget $OID)" 0 "$OID = $TYPE: So long, and thanks for all the fish!"
new "Set $NAME $VALUE" new "Set $NAME $VALUE"
expectpart "$($snmpset $OID s "$VALUE")" 0 "$OID = $TYPE: $VALUE" expectpart "$($snmpset $OID s "$VALUE")" 0 "$OID = $TYPE: $VALUE"