Work on [bug #51577] snmp/asn1: 64 bit encoding/decoding seems broken for big endian

We should support COUNTER64 data type only when we have u64_t on the system
This commit is contained in:
Dirk Ziegelmeier 2017-07-26 09:27:11 +02:00
parent 3ec8b22f14
commit f5d7535323
3 changed files with 52 additions and 12 deletions

View File

@ -122,12 +122,22 @@ tcp_get_value(struct snmp_node_instance* instance, void* value)
case 15: /* tcpOutRsts */
*uint_ptr = STATS_GET(mib2.tcpoutrsts);
return sizeof(*uint_ptr);
#if LWIP_HAVE_INT64
case 17: /* tcpHCInSegs */
memset(value, 0, 2*sizeof(u32_t)); /* not supported */
return 2*sizeof(u32_t);
{
/* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.tcpinsegs);
*((u64_t*)value) = val64;
}
return sizeof(u64_t);
case 18: /* tcpHCOutSegs */
memset(value, 0, 2*sizeof(u32_t)); /* not supported */
return 2*sizeof(u32_t);
{
/* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.tcpoutsegs);
*((u64_t*)value) = val64;
}
return sizeof(u64_t);
#endif
default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_value(): unknown id: %"S32_F"\n", instance->node->oid));
break;
@ -512,8 +522,10 @@ static const struct snmp_scalar_node tcp_OutSegs = SNMP_SCALAR_CREATE_NODE
static const struct snmp_scalar_node tcp_RetransSegs = SNMP_SCALAR_CREATE_NODE_READONLY(12, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
static const struct snmp_scalar_node tcp_InErrs = SNMP_SCALAR_CREATE_NODE_READONLY(14, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
static const struct snmp_scalar_node tcp_OutRsts = SNMP_SCALAR_CREATE_NODE_READONLY(15, SNMP_ASN1_TYPE_COUNTER, tcp_get_value);
#if LWIP_HAVE_INT64
static const struct snmp_scalar_node tcp_HCInSegs = SNMP_SCALAR_CREATE_NODE_READONLY(17, SNMP_ASN1_TYPE_COUNTER64, tcp_get_value);
static const struct snmp_scalar_node tcp_HCOutSegs = SNMP_SCALAR_CREATE_NODE_READONLY(18, SNMP_ASN1_TYPE_COUNTER64, tcp_get_value);
#endif
#if LWIP_IPV4
static const struct snmp_table_simple_col_def tcp_ConnTable_columns[] = {
@ -561,8 +573,10 @@ CREATE_LWIP_SYNC_NODE(13, tcp_ConnTable)
#endif /* LWIP_IPV4 */
CREATE_LWIP_SYNC_NODE(14, tcp_InErrs)
CREATE_LWIP_SYNC_NODE(15, tcp_OutRsts)
#if LWIP_HAVE_INT64
CREATE_LWIP_SYNC_NODE(17, tcp_HCInSegs)
CREATE_LWIP_SYNC_NODE(18, tcp_HCOutSegs)
#endif
CREATE_LWIP_SYNC_NODE(19, tcp_ConnectionTable)
CREATE_LWIP_SYNC_NODE(20, tcp_ListenerTable)
@ -585,8 +599,10 @@ static const struct snmp_node* const tcp_nodes[] = {
&SYNC_NODE_NAME(tcp_InErrs).node.node,
&SYNC_NODE_NAME(tcp_OutRsts).node.node,
&SYNC_NODE_NAME(tcp_HCInSegs).node.node,
#if LWIP_HAVE_INT64
&SYNC_NODE_NAME(tcp_HCOutSegs).node.node,
&SYNC_NODE_NAME(tcp_ConnectionTable).node.node,
#endif
&SYNC_NODE_NAME(tcp_ListenerTable).node.node
};

View File

@ -75,12 +75,22 @@ udp_get_value(struct snmp_node_instance* instance, void* value)
case 4: /* udpOutDatagrams */
*uint_ptr = STATS_GET(mib2.udpoutdatagrams);
return sizeof(*uint_ptr);
#if LWIP_HAVE_INT64
case 8: /* udpHCInDatagrams */
memset(value, 0, 2*sizeof(u32_t)); /* not supported */
return 2*sizeof(u32_t);
{
/* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.udpindatagrams);
*((u64_t*)value) = val64;
}
return sizeof(u64_t);
case 9: /* udpHCOutDatagrams */
memset(value, 0, 2*sizeof(u32_t)); /* not supported */
return 2*sizeof(u32_t);
{
/* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.udpoutdatagrams);
*((u64_t*)value) = val64;
}
return sizeof(u64_t);
#endif
default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_value(): unknown id: %"S32_F"\n", instance->node->oid));
break;
@ -310,8 +320,10 @@ static const struct snmp_scalar_node udp_inDatagrams = SNMP_SCALAR_CREATE_NOD
static const struct snmp_scalar_node udp_noPorts = SNMP_SCALAR_CREATE_NODE_READONLY(2, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
static const struct snmp_scalar_node udp_inErrors = SNMP_SCALAR_CREATE_NODE_READONLY(3, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
static const struct snmp_scalar_node udp_outDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(4, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
#if LWIP_HAVE_INT64
static const struct snmp_scalar_node udp_HCInDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(8, SNMP_ASN1_TYPE_COUNTER64, udp_get_value);
static const struct snmp_scalar_node udp_HCOutDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(9, SNMP_ASN1_TYPE_COUNTER64, udp_get_value);
#endif
#if LWIP_IPV4
static const struct snmp_table_simple_col_def udp_Table_columns[] = {
@ -337,8 +349,10 @@ CREATE_LWIP_SYNC_NODE(4, udp_outDatagrams)
CREATE_LWIP_SYNC_NODE(5, udp_Table)
#endif /* LWIP_IPV4 */
CREATE_LWIP_SYNC_NODE(7, udp_endpointTable)
#if LWIP_HAVE_INT64
CREATE_LWIP_SYNC_NODE(8, udp_HCInDatagrams)
CREATE_LWIP_SYNC_NODE(9, udp_HCOutDatagrams)
#endif
static const struct snmp_node* const udp_nodes[] = {
&SYNC_NODE_NAME(udp_inDatagrams).node.node,
@ -348,9 +362,12 @@ static const struct snmp_node* const udp_nodes[] = {
#if LWIP_IPV4
&SYNC_NODE_NAME(udp_Table).node.node,
#endif /* LWIP_IPV4 */
&SYNC_NODE_NAME(udp_endpointTable).node.node,
&SYNC_NODE_NAME(udp_endpointTable).node.node
#if LWIP_HAVE_INT64
,
&SYNC_NODE_NAME(udp_HCInDatagrams).node.node,
&SYNC_NODE_NAME(udp_HCOutDatagrams).node.node
#endif
};
const struct snmp_tree_node snmp_mib2_udp_root = SNMP_CREATE_TREE_NODE(7, udp_nodes);

View File

@ -398,10 +398,12 @@ snmp_msg_getnext_validate_node_inst(struct snmp_node_instance* node_instance, vo
return SNMP_ERR_NOSUCHINSTANCE;
}
#if LWIP_HAVE_INT64
if ((node_instance->asn1_type == SNMP_ASN1_TYPE_COUNTER64) && (((struct snmp_request*)validate_arg)->version == SNMP_VERSION_1)) {
/* according to RFC 2089 skip Counter64 objects in GetNext requests from v1 clients */
return SNMP_ERR_NOSUCHINSTANCE;
}
#endif
return SNMP_ERR_NOERROR;
}
@ -1514,12 +1516,14 @@ snmp_varbind_length(struct snmp_varbind *varbind, struct snmp_varbind_len *len)
}
snmp_asn1_enc_oid_cnt((u32_t*) varbind->value, varbind->value_len >> 2, &len->value_value_len);
break;
#if LWIP_HAVE_INT64
case SNMP_ASN1_TYPE_COUNTER64:
if (varbind->value_len != (2 * sizeof (u32_t))) {
if (varbind->value_len != sizeof(u64_t)) {
return ERR_VAL;
}
snmp_asn1_enc_u64t_cnt((u32_t*) varbind->value, &len->value_value_len);
break;
#endif
default:
/* unsupported type */
return ERR_VAL;
@ -1590,9 +1594,10 @@ snmp_append_outbound_varbind(struct snmp_pbuf_stream *pbuf_stream, struct snmp_v
case SNMP_ASN1_TYPE_OBJECT_ID:
OVB_BUILD_EXEC(snmp_asn1_enc_oid(pbuf_stream, (u32_t*) varbind->value, varbind->value_len / sizeof (u32_t)));
break;
#if LWIP_HAVE_INT64
case SNMP_ASN1_TYPE_COUNTER64:
OVB_BUILD_EXEC(snmp_asn1_enc_u64t(pbuf_stream, len.value_value_len, (u32_t*) varbind->value));
break;
#endif
default:
LWIP_ASSERT("Unknown variable type", 0);
break;
@ -1936,10 +1941,12 @@ snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct s
VB_PARSE_ASSERT(0);
}
break;
#if LWIP_HAVE_INT64
case SNMP_ASN1_TYPE_COUNTER64:
VB_PARSE_EXEC(snmp_asn1_dec_u64t(&(enumerator->pbuf_stream), tlv.value_len, (u32_t*)varbind->value));
varbind->value_len = 2 * sizeof(u32_t);
varbind->value_len = sizeof(u64_t);
break;
#endif
default:
VB_PARSE_ASSERT(0);
break;