Reformat SNMP code using astylerc

This commit is contained in:
Dirk Ziegelmeier 2017-09-17 20:29:18 +02:00
parent 6e7fe4520a
commit 3ed24085fa
27 changed files with 1291 additions and 1325 deletions

View File

@ -71,8 +71,7 @@ extern "C" {
#define SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_OBJECT 0
#define SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW 2
struct snmp_asn1_tlv
{
struct snmp_asn1_tlv {
u8_t type; /* only U8 because extended types are not specified by SNMP */
u8_t type_len; /* encoded length of 'type' field (normally 1) */
u8_t length_len; /* indicates how many bytes are required to encode the 'value_len' field */

View File

@ -1230,8 +1230,7 @@ snmp_decode_bits(const u8_t *buf, u32_t buf_len, u32_t *bit_value)
}
bits_processed++;
b <<= 1;
}
while ((bits_processed & 0x07) != 0); /* &0x07 -> % 8 */
} while ((bits_processed & 0x07) != 0); /* &0x07 -> % 8 */
} else {
bits_processed += 8;
}

View File

@ -161,8 +161,7 @@ interfaces_Table_get_value(struct snmp_node_instance* instance, void* value)
s32_t *value_s32 = (s32_t *)value;
u16_t value_len;
switch (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id))
{
switch (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id)) {
case 1: /* ifIndex */
*value_s32 = netif_to_num(netif);
value_len = sizeof(*value_s32);

View File

@ -238,8 +238,7 @@ system_get_value(const struct snmp_scalar_array_node_def *node, void *value)
var = sysdescr;
var_len = (const s16_t *)sysdescr_len;
break;
case 2: /* sysObjectID */
{
case 2: { /* sysObjectID */
const struct snmp_obj_id *dev_enterprise_oid = snmp_get_device_enterprise_oid();
MEMCPY(value, dev_enterprise_oid->id, dev_enterprise_oid->len * sizeof(u32_t));
return dev_enterprise_oid->len * sizeof(u32_t);

View File

@ -93,8 +93,7 @@ tcp_get_value(struct snmp_node_instance* instance, void* value)
case 8: /* tcpEstabResets */
*uint_ptr = STATS_GET(mib2.tcpestabresets);
return sizeof(*uint_ptr);
case 9: /* tcpCurrEstab */
{
case 9: { /* tcpCurrEstab */
u16_t tcpcurrestab = 0;
struct tcp_pcb *pcb = tcp_active_pcbs;
while (pcb != NULL) {
@ -123,15 +122,13 @@ tcp_get_value(struct snmp_node_instance* instance, void* value)
*uint_ptr = STATS_GET(mib2.tcpoutrsts);
return sizeof(*uint_ptr);
#if LWIP_HAVE_INT64
case 17: /* tcpHCInSegs */
{
case 17: { /* tcpHCInSegs */
/* 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 */
{
case 18: { /* tcpHCOutSegs */
/* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.tcpoutsegs);
*((u64_t *)value) = val64;

View File

@ -76,15 +76,13 @@ udp_get_value(struct snmp_node_instance* instance, void* value)
*uint_ptr = STATS_GET(mib2.udpoutdatagrams);
return sizeof(*uint_ptr);
#if LWIP_HAVE_INT64
case 8: /* udpHCInDatagrams */
{
case 8: { /* udpHCInDatagrams */
/* 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 */
{
case 9: { /* udpHCOutDatagrams */
/* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.udpoutdatagrams);
*((u64_t *)value) = val64;

View File

@ -91,8 +91,7 @@ snmp_version_enabled(u8_t version)
if (version == SNMP_VERSION_1) {
return v1_enabled;
}
else if (version == SNMP_VERSION_2c) {
} else if (version == SNMP_VERSION_2c) {
return v2c_enabled;
}
#if LWIP_SNMP_V3
@ -131,8 +130,7 @@ snmp_version_enable(u8_t version, u8_t enable)
if (version == SNMP_VERSION_1) {
v1_enabled = enable;
}
else if (version == SNMP_VERSION_2c) {
} else if (version == SNMP_VERSION_2c) {
v2c_enabled = enable;
}
#if LWIP_SNMP_V3
@ -312,43 +310,37 @@ snmp_receive(void *handle, struct pbuf *p, const ip_addr_t *source_ip, u16_t por
vb.value_len = sizeof(u32_t);
switch (request.error_status) {
case SNMP_ERR_AUTHORIZATIONERROR:
{
case SNMP_ERR_AUTHORIZATIONERROR: {
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 5, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.wrongdigests;
}
break;
case SNMP_ERR_UNKNOWN_ENGINEID:
{
case SNMP_ERR_UNKNOWN_ENGINEID: {
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 4, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.unknownengineids;
}
break;
case SNMP_ERR_UNKNOWN_SECURITYNAME:
{
case SNMP_ERR_UNKNOWN_SECURITYNAME: {
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 3, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.unknownusernames;
}
break;
case SNMP_ERR_UNSUPPORTED_SECLEVEL:
{
case SNMP_ERR_UNSUPPORTED_SECLEVEL: {
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 1, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.unsupportedseclevels;
}
break;
case SNMP_ERR_NOTINTIMEWINDOW:
{
case SNMP_ERR_NOTINTIMEWINDOW: {
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 2, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.notintimewindows;
}
break;
case SNMP_ERR_DECRYIPTION_ERROR:
{
case SNMP_ERR_DECRYIPTION_ERROR: {
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 6, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.decryptionerrors;
@ -808,8 +800,7 @@ snmp_parse_inbound_frame(struct snmp_request *request)
#if LWIP_SNMP_CONFIGURE_VERSIONS
|| (!snmp_version_enabled(s32_value))
#endif
)
{
) {
/* unsupported SNMP version */
snmp_stats.inbadversions++;
return ERR_ARG;
@ -1066,8 +1057,7 @@ snmp_parse_inbound_frame(struct snmp_request *request)
request->msg_flags = SNMP_V3_AUTHNOPRIV;
request->error_status = SNMP_ERR_NOTINTIMEWINDOW;
return ERR_OK;
}
else if (time > 150) {
} else if (time > 150) {
if (request->msg_authoritative_engine_time < time - 150) {
snmp_stats.notintimewindows++;
request->msg_flags = SNMP_V3_AUTHNOPRIV;
@ -1878,8 +1868,7 @@ snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct s
u16_t varbind_len;
err_t err;
if (enumerator->pbuf_stream.length == 0)
{
if (enumerator->pbuf_stream.length == 0) {
return SNMP_VB_ENUMERATOR_ERR_EOVB;
}
enumerator->varbind_count++;

View File

@ -62,8 +62,7 @@ extern "C" {
#define SNMP_VERSION_2c 1
#define SNMP_VERSION_3 3
struct snmp_varbind_enumerator
{
struct snmp_varbind_enumerator {
struct snmp_pbuf_stream pbuf_stream;
u16_t varbind_count;
};
@ -78,8 +77,7 @@ typedef enum {
void snmp_vb_enumerator_init(struct snmp_varbind_enumerator *enumerator, struct pbuf *p, u16_t offset, u16_t length);
snmp_vb_enumerator_err_t snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator *enumerator, struct snmp_varbind *varbind);
struct snmp_request
{
struct snmp_request {
/* Communication handle */
void *handle;
/* source IP address */
@ -156,8 +154,7 @@ struct snmp_request
};
/** A helper struct keeping length information about varbinds */
struct snmp_varbind_len
{
struct snmp_varbind_len {
u8_t vb_len_len;
u16_t vb_value_len;
u8_t oid_len_len;

View File

@ -49,8 +49,7 @@
extern "C" {
#endif
struct snmp_pbuf_stream
{
struct snmp_pbuf_stream {
struct pbuf *pbuf;
u16_t offset;
u16_t length;

View File

@ -61,8 +61,7 @@ static const struct snmp_obj_id *snmp_auth_algo_to_oid(snmpv3_auth_algo_t algo)
{
if (algo == SNMP_V3_AUTH_ALGO_MD5) {
return &usmHMACMD5AuthProtocol;
}
else if (algo == SNMP_V3_AUTH_ALGO_SHA) {
} else if (algo == SNMP_V3_AUTH_ALGO_SHA) {
return &usmHMACMD5AuthProtocol;
}
@ -73,8 +72,7 @@ static const struct snmp_obj_id *snmp_priv_algo_to_oid(snmpv3_priv_algo_t algo)
{
if (algo == SNMP_V3_PRIV_ALGO_DES) {
return &usmDESPrivProtocol;
}
else if (algo == SNMP_V3_PRIV_ALGO_AES) {
} else if (algo == SNMP_V3_PRIV_ALGO_AES) {
return &usmAESPrivProtocol;
}
@ -207,8 +205,7 @@ static snmp_err_t usmusertable_get_next_instance(const u32_t *column, struct snm
if (!snmp_oid_equal(&row_oid->id[engineid_start], row_oid->len - 1, engineid_oid, row_oid->len - 1)) {
return SNMP_ERR_NOSUCHINSTANCE;
}
}
else {
} else {
/* Verify complete EngineID */
snmp_engineid_to_oid(engineid, engineid_oid, engineid_len);
if (!snmp_oid_equal(&row_oid->id[engineid_start], engineid_len, engineid_oid, engineid_len)) {
@ -234,8 +231,7 @@ static snmp_err_t usmusertable_get_next_instance(const u32_t *column, struct snm
if (!snmp_oid_in_range(&row_oid->id[name_start], tmplen, usmUserTable_oid_ranges, tmplen)) {
return SNMP_ERR_NOSUCHINSTANCE;
}
}
else {
} else {
/* Full name given according to oid. Also test for too much data.*/
u8_t tmplen = row_oid->len - engineid_len - 2;
if (!snmp_oid_in_range(&row_oid->id[name_start], name_len, usmUserTable_oid_ranges, tmplen)) {
@ -291,8 +287,7 @@ static s16_t usmusertable_get_value(struct snmp_node_instance *cell_instance, vo
case 4: /* usmUserCloneFrom */
MEMCPY(value, snmp_zero_dot_zero.id, snmp_zero_dot_zero.len * sizeof(u32_t));
return snmp_zero_dot_zero.len * sizeof(u32_t);
case 5: /* usmUserAuthProtocol */
{
case 5: { /* usmUserAuthProtocol */
const struct snmp_obj_id *auth_algo;
snmpv3_auth_algo_t auth_algo_val;
snmpv3_get_user((const char *)cell_instance->reference.ptr, &auth_algo_val, NULL, NULL, NULL);
@ -304,8 +299,7 @@ static s16_t usmusertable_get_value(struct snmp_node_instance *cell_instance, vo
return 0;
case 7: /* usmUserOwnAuthKeyChange */
return 0;
case 8: /* usmUserPrivProtocol */
{
case 8: { /* usmUserPrivProtocol */
const struct snmp_obj_id *priv_algo;
snmpv3_priv_algo_t priv_algo_val;
snmpv3_get_user((const char *)cell_instance->reference.ptr, NULL, NULL, &priv_algo_val, NULL);

View File

@ -283,8 +283,7 @@ snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_
row_oid.len = 0; /* reset row_oid because we switch to next column and start with the first entry there */
column = next_col_def->index + 1;
}
while (1);
} while (1);
instance->asn1_type = col_def->asn1_type;
instance->access = SNMP_NODE_INSTANCE_READ_ONLY;

View File

@ -51,8 +51,7 @@
#include "snmp_asn1.h"
#include "snmp_core_priv.h"
struct snmp_msg_trap
{
struct snmp_msg_trap {
/* source enterprise ID (sysObjectID) */
const struct snmp_obj_id *enterprise;
/* source IP address, raw network order format */
@ -93,8 +92,7 @@ extern const char *snmp_community_trap;
void *snmp_traps_handle;
struct snmp_trap_dst
{
struct snmp_trap_dst {
/* destination IP address in network order */
ip_addr_t dip;
/* set to 0 when disabled, >0 when enabled */

View File

@ -52,8 +52,7 @@
#define SNMP_V3_MD5_LEN 16
#define SNMP_V3_SHA_LEN 20
typedef enum
{
typedef enum {
SNMP_V3_PRIV_MODE_DECRYPT = 0,
SNMP_V3_PRIV_MODE_ENCRYPT = 1
} snmpv3_priv_mode_t;