Commit ea08ad2f authored by Adam Wujek's avatar Adam Wujek 💬

lib/snmp: don't respond to SNMPv1 requests for counter64 OIDs

SNMPv1 does not support counter64.
Add tests for that too.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 6a46311f
......@@ -517,6 +517,8 @@ static int func_group(uint8_t *buf, uint8_t in_oid_limb_matched_len,
return_len = oid->get(in_oid_limb_end + oid->oid_len,
oid);
/* add the length of twig part of the OID */
if (!return_len)
continue;
return_len += oid->oid_len;
return return_len;
}
......@@ -744,6 +746,10 @@ static int get_value(uint8_t *buf, uint8_t asn, void *p)
snmp_verbose("%s: 0x%x\n", __func__, *(uint32_t *)p);
break;
case ASN_COUNTER64:
if (snmp_version == SNMP_V1) {
/* There is no support for 64bit counters in SNMPv1 */
return 0;
}
tmp_uint64 = *(uint64_t *)p;
memcpy(oid_data, &tmp_uint64, sizeof(tmp_uint64));
*len = sizeof(tmp_uint64);
......
load snmp_test_config
@test "Get Counter64 OID (WR-WRPC-MIB::wrpcPtpAsymmetry.0) with SNMPv2" {
result="$(snmpget $SNMP_OPTIONS -Os $TARGET_IP wrpcPtpAsymmetry.0 | grep "wrpcPtpAsymmetry.0" | wc -l)"
[ "$result" -eq 1 ]
}
@test "Get Counter64 OID (WR-WRPC-MIB::wrpcPtpAsymmetry.0) with SNMPv1 (not supported)" {
# SNMP v1 does not support counter64, so it should return oid not found
result="$(snmpget $SNMP_OPTIONS -Os -v 1 $TARGET_IP wrpcPtpAsymmetry.0 | grep "wrpcPtpAsymmetry.0" | wc -l)"
[ "$result" -eq 0 ]
}
@test "Getnext OID before Counter64 WR-WRPC-MIB::wrpcPtpAsymmetry.0 with SNMPv1" {
# should point after the Counter64 (wrpcPtpRTTErrCnt.0) to the wrpcPtpTx.0
result="$(snmpgetnext $SNMP_OPTIONS -Os -v 1 $TARGET_IP wrpcPtpRTTErrCnt.0 | grep "wrpcPtpTx.0" | wc -l)"
[ "$result" -eq 1 ]
}
@test "Getnext Counter64 OID WR-WRPC-MIB::wrpcPtpAsymmetry.0 with SNMPv1" {
# should point after Counter64 (wrpcPtpAsymmetry.0) to the wrpcPtpTx.0
result="$(snmpgetnext $SNMP_OPTIONS -Os -v 1 $TARGET_IP wrpcPtpAsymmetry.0 | grep "wrpcPtpTx.0" | wc -l)"
[ "$result" -eq 1 ]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment