diff --git a/src/core/snmp/asn1_dec.c b/src/core/snmp/asn1_dec.c index f87f578e..bb42aef8 100644 --- a/src/core/snmp/asn1_dec.c +++ b/src/core/snmp/asn1_dec.c @@ -55,12 +55,10 @@ snmp_asn1_dec_type(struct pbuf *p, u16_t ofs, u8_t *type) u8_t *msg_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; *type = *msg_ptr; @@ -88,128 +86,104 @@ snmp_asn1_dec_length(struct pbuf *p, u16_t ofs, u8_t *octets_used, u16_t *length u8_t *msg_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; - if (*msg_ptr < 0x80) - { + if (*msg_ptr < 0x80) { /* primitive definite length format */ *octets_used = 1; *length = *msg_ptr; return ERR_OK; - } - else if (*msg_ptr == 0x80) - { + } else if (*msg_ptr == 0x80) { /* constructed indefinite length format, termination with two zero octets */ u8_t zeros; u8_t i; *length = 0; zeros = 0; - while (zeros != 2) - { + while (zeros != 2) { i = 2; - while (i > 0) - { + while (i > 0) { i--; (*length) += 1; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } - if (*msg_ptr == 0) - { + if (*msg_ptr == 0) { zeros++; - if (zeros == 2) - { + if (zeros == 2) { /* stop while (i > 0) */ i = 0; } - } - else - { + } else { zeros = 0; } } } *octets_used = 1; return ERR_OK; - } - else if (*msg_ptr == 0x81) - { + } else if (*msg_ptr == 0x81) { /* constructed definite length format, one octet */ ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } *length = *msg_ptr; *octets_used = 2; return ERR_OK; - } - else if (*msg_ptr == 0x82) - { + } else if (*msg_ptr == 0x82) { u8_t i; /* constructed definite length format, two octets */ i = 2; - while (i > 0) - { + while (i > 0) { i--; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } - if (i == 0) - { + if (i == 0) { /* least significant length octet */ *length |= *msg_ptr; - } - else - { + } else { /* most significant length octet */ *length = (*msg_ptr) << 8; } } *octets_used = 3; return ERR_OK; - } - else - { + } else { /* constructed definite length format 3..127 octets, this is too big (>64k) */ /** @todo: do we need to accept inefficient codings with many leading zero's? */ *octets_used = 1 + ((*msg_ptr) & 0x7f); @@ -243,72 +217,60 @@ snmp_asn1_dec_u32t(struct pbuf *p, u16_t ofs, u16_t len, u32_t *value) u8_t *msg_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; - if ((len > 0) && (len < 6)) - { + if ((len > 0) && (len < 6)) { /* start from zero */ *value = 0; - if (*msg_ptr & 0x80) - { + if (*msg_ptr & 0x80) { /* negative, expecting zero sign bit! */ return ERR_ARG; - } - else - { + } else { /* positive */ - if ((len > 1) && (*msg_ptr == 0)) - { + if ((len > 1) && (*msg_ptr == 0)) { /* skip leading "sign byte" octet 0x00 */ len--; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } } } /* OR octets with value */ - while (len > 1) - { + while (len > 1) { len--; *value |= *msg_ptr; *value <<= 8; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } } *value |= *msg_ptr; return ERR_OK; - } - else - { + } else { return ERR_ARG; } } @@ -343,70 +305,54 @@ snmp_asn1_dec_s32t(struct pbuf *p, u16_t ofs, u16_t len, s32_t *value) u8_t sign; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; - if ((len > 0) && (len < 5)) - { - if (*msg_ptr & 0x80) - { + if ((len > 0) && (len < 5)) { + if (*msg_ptr & 0x80) { /* negative, start from -1 */ *value = -1; sign = 1; - } - else - { + } else { /* positive, start from 0 */ *value = 0; sign = 0; } /* OR/AND octets with value */ - while (len > 1) - { + while (len > 1) { len--; - if (sign) - { + if (sign) { *lsb_ptr &= *msg_ptr; *value <<= 8; *lsb_ptr |= 255; - } - else - { + } else { *lsb_ptr |= *msg_ptr; *value <<= 8; } ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } } - if (sign) - { + if (sign) { *lsb_ptr &= *msg_ptr; - } - else - { + } else { *lsb_ptr |= *msg_ptr; } return ERR_OK; - } - else - { + } else { return ERR_ARG; } } @@ -433,129 +379,106 @@ snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid) s32_t *oid_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; oid->len = 0; oid_ptr = &oid->id[0]; - if (len > 0) - { + if (len > 0) { /* first compressed octet */ - if (*msg_ptr == 0x2B) - { + if (*msg_ptr == 0x2B) { /* (most) common case 1.3 (iso.org) */ *oid_ptr = 1; oid_ptr++; *oid_ptr = 3; oid_ptr++; - } - else if (*msg_ptr < 40) - { + } else if (*msg_ptr < 40) { *oid_ptr = 0; oid_ptr++; *oid_ptr = *msg_ptr; oid_ptr++; - } - else if (*msg_ptr < 80) - { + } else if (*msg_ptr < 80) { *oid_ptr = 1; oid_ptr++; *oid_ptr = (*msg_ptr) - 40; oid_ptr++; - } - else - { + } else { *oid_ptr = 2; oid_ptr++; *oid_ptr = (*msg_ptr) - 80; oid_ptr++; } oid->len = 2; - } - else - { + } else { /* accepting zero length identifiers e.g. for getnext operation. uncommon but valid */ return ERR_OK; } len--; - if (len > 0) - { + if (len > 0) { ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } } - while ((len > 0) && (oid->len < LWIP_SNMP_OBJ_ID_LEN)) - { + while ((len > 0) && (oid->len < LWIP_SNMP_OBJ_ID_LEN)) { /* sub-identifier uses multiple octets */ - if (*msg_ptr & 0x80) - { + if (*msg_ptr & 0x80) { s32_t sub_id = 0; - while ((*msg_ptr & 0x80) && (len > 1)) - { + while ((*msg_ptr & 0x80) && (len > 1)) { len--; sub_id = (sub_id << 7) + (*msg_ptr & ~0x80); ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } } - if (!(*msg_ptr & 0x80) && (len > 0)) - { + if (!(*msg_ptr & 0x80) && (len > 0)) { /* last octet sub-identifier */ len--; sub_id = (sub_id << 7) + *msg_ptr; *oid_ptr = sub_id; } - } - else - { + } else { /* !(*msg_ptr & 0x80) sub-identifier uses single octet */ len--; *oid_ptr = *msg_ptr; } - if (len > 0) - { + if (len > 0) { /* remaining oid bytes available ... */ ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } @@ -563,13 +486,10 @@ snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid) oid_ptr++; oid->len++; } - if (len == 0) - { + if (len == 0) { /* len == 0, end of oid */ return ERR_OK; - } - else - { + } else { /* len > 0, oid->len == LWIP_SNMP_OBJ_ID_LEN or malformed encoding */ return ERR_ARG; } @@ -598,36 +518,30 @@ snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw u16_t plen, base; u8_t *msg_ptr; - if (len > 0) - { + if (len > 0) { plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; - if (raw_len >= len) - { - while (len > 1) - { + if (raw_len >= len) { + while (len > 1) { /* copy len - 1 octets */ len--; *raw = *msg_ptr; raw++; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } @@ -635,9 +549,7 @@ snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw /* copy last octet */ *raw = *msg_ptr; return ERR_OK; - } - else - { + } else { /* raw_len < len, not enough dst space */ return ERR_ARG; } @@ -646,9 +558,7 @@ snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw } /* p == NULL, ofs >= plen */ return ERR_ARG; - } - else - { + } else { /* len == 0, empty string */ return ERR_OK; } diff --git a/src/core/snmp/asn1_enc.c b/src/core/snmp/asn1_enc.c index aa5e8aee..57bb6a1e 100644 --- a/src/core/snmp/asn1_enc.c +++ b/src/core/snmp/asn1_enc.c @@ -49,16 +49,11 @@ void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed) { - if (length < 0x80U) - { + if (length < 0x80U) { *octets_needed = 1; - } - else if (length < 0x100U) - { + } else if (length < 0x100U) { *octets_needed = 2; - } - else - { + } else { *octets_needed = 3; } } @@ -76,24 +71,15 @@ snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed) void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed) { - if (value < 0x80UL) - { + if (value < 0x80UL) { *octets_needed = 1; - } - else if (value < 0x8000UL) - { + } else if (value < 0x8000UL) { *octets_needed = 2; - } - else if (value < 0x800000UL) - { + } else if (value < 0x800000UL) { *octets_needed = 3; - } - else if (value < 0x80000000UL) - { + } else if (value < 0x80000000UL) { *octets_needed = 4; - } - else - { + } else { *octets_needed = 5; } } @@ -109,24 +95,15 @@ snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed) void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed) { - if (value < 0) - { + if (value < 0) { value = ~value; - } - if (value < 0x80L) - { + } if (value < 0x80L) { *octets_needed = 1; - } - else if (value < 0x8000L) - { + } else if (value < 0x8000L) { *octets_needed = 2; - } - else if (value < 0x800000L) - { + } else if (value < 0x800000L) { *octets_needed = 3; - } - else - { + } else { *octets_needed = 4; } } @@ -145,22 +122,19 @@ snmp_asn1_enc_oid_cnt(u16_t ident_len, const s32_t *ident, u16_t *octets_needed) u8_t cnt; cnt = 0; - if (ident_len > 1) - { + if (ident_len > 1) { /* compressed prefix in one octet */ cnt++; ident_len -= 2; ident += 2; } - while(ident_len > 0) - { + while (ident_len > 0) { ident_len--; sub_id = *ident; sub_id >>= 7; cnt++; - while(sub_id > 0) - { + while (sub_id > 0) { sub_id >>= 7; cnt++; } @@ -184,12 +158,10 @@ snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type) u8_t *msg_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; *msg_ptr = type; @@ -216,70 +188,57 @@ snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length) u8_t *msg_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; - if (length < 0x80) - { + if (length < 0x80) { *msg_ptr = (u8_t)length; return ERR_OK; - } - else if (length < 0x100) - { + } else if (length < 0x100) { *msg_ptr = 0x81; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } *msg_ptr = (u8_t)length; return ERR_OK; - } - else - { + } else { u8_t i; /* length >= 0x100 && length <= 0xFFFF */ *msg_ptr = 0x82; i = 2; - while (i > 0) - { + while (i > 0) { i--; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } - if (i == 0) - { + if (i == 0) { /* least significant length octet */ *msg_ptr = (u8_t)length; - } - else - { + } else { /* most significant length octet */ *msg_ptr = (u8_t)(length >> 8); } @@ -311,50 +270,44 @@ snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, u32_t value) u8_t *msg_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; - if (octets_needed == 5) - { + if (octets_needed == 5) { /* not enough bits in 'value' add leading 0x00 */ octets_needed--; *msg_ptr = 0x00; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } } - while (octets_needed > 1) - { + while (octets_needed > 1) { octets_needed--; *msg_ptr = (u8_t)(value >> (octets_needed << 3)); ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } @@ -387,30 +340,26 @@ snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, s32_t value) u8_t *msg_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; - while (octets_needed > 1) - { + while (octets_needed > 1) { octets_needed--; *msg_ptr = (u8_t)(value >> (octets_needed << 3)); ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } @@ -441,52 +390,42 @@ snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u16_t ident_len, const s32_t *ident u8_t *msg_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; - if (ident_len > 1) - { - if ((ident[0] == 1) && (ident[1] == 3)) - { + if (ident_len > 1) { + if ((ident[0] == 1) && (ident[1] == 3)) { /* compressed (most common) prefix .iso.org */ *msg_ptr = 0x2b; - } - else - { + } else { /* calculate prefix */ *msg_ptr = (u8_t)((ident[0] * 40) + ident[1]); } ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } ident_len -= 2; ident += 2; - } - else - { -/* @bug: allow empty varbinds for symmetry (we must decode them for getnext), allow partial compression?? */ + } else { + /* @bug: allow empty varbinds for symmetry (we must decode them for getnext), allow partial compression?? */ /* ident_len <= 1, at least we need zeroDotZero (0.0) (ident_len == 2) */ return ERR_ARG; } - while (ident_len > 0) - { + while (ident_len > 0) { s32_t sub_id; u8_t shift, tail; @@ -494,26 +433,23 @@ snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u16_t ident_len, const s32_t *ident sub_id = *ident; tail = 0; shift = 28; - while(shift > 0) - { + while (shift > 0) { u8_t code; code = (u8_t)(sub_id >> shift); - if ((code != 0) || (tail != 0)) - { + if ((code != 0) || (tail != 0)) { tail = 1; *msg_ptr = code | 0x80; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } @@ -521,19 +457,17 @@ snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u16_t ident_len, const s32_t *ident shift -= 7; } *msg_ptr = (u8_t)sub_id & 0x7F; - if (ident_len > 0) - { + if (ident_len > 0) { ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } @@ -565,38 +499,33 @@ snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u16_t raw_len, const u8_t *raw) u8_t *msg_ptr; plen = 0; - while (p != NULL) - { + while (p != NULL) { base = plen; plen += p->len; - if (ofs < plen) - { + if (ofs < plen) { msg_ptr = (u8_t*)p->payload; msg_ptr += ofs - base; - while (raw_len > 1) - { + while (raw_len > 1) { /* copy raw_len - 1 octets */ raw_len--; *msg_ptr = *raw; raw++; ofs += 1; - if (ofs >= plen) - { + if (ofs >= plen) { /* next octet in next pbuf */ p = p->next; - if (p == NULL) { return ERR_ARG; } + if (p == NULL) { + return ERR_ARG; + } msg_ptr = (u8_t*)p->payload; plen += p->len; - } - else - { + } else { /* next octet in same pbuf */ msg_ptr++; } } - if (raw_len > 0) - { + if (raw_len > 0) { /* copy last or single octet */ *msg_ptr = *raw; } diff --git a/src/core/snmp/mib2.c b/src/core/snmp/mib2.c index 85d411cd..d4c8cb72 100644 --- a/src/core/snmp/mib2.c +++ b/src/core/snmp/mib2.c @@ -672,8 +672,7 @@ static u32_t snmpinpkts = 0, */ void snmp_set_sysdescr(const u8_t *str, const u8_t *len) { - if (str != NULL) - { + if (str != NULL) { sysdescr_ptr = str; sysdescr_len_ptr = len; } @@ -705,8 +704,7 @@ void snmp_set_sysobjid(const struct snmp_obj_id *oid) */ void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen, u8_t bufsize) { - if (ocstr != NULL) - { + if (ocstr != NULL) { syscontact_ptr = ocstr; syscontact_len_ptr = ocstrlen; syscontact_size = bufsize; @@ -724,8 +722,7 @@ void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen, u8_t bufsize) */ void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen, u8_t bufsize) { - if (ocstr != NULL) - { + if (ocstr != NULL) { sysname_ptr = ocstr; sysname_len_ptr = ocstrlen; sysname_size = bufsize; @@ -743,8 +740,7 @@ void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen, u8_t bufsize) */ void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen, u8_t bufsize) { - if (ocstr != NULL) - { + if (ocstr != NULL) { syslocation_ptr = ocstr; syslocation_len_ptr = ocstrlen; syslocation_size = bufsize; @@ -768,7 +764,9 @@ void mib2_netif_removed(struct netif *ni) snmp_mib_node_delete(&iflist_root, iflist_root.tail); /* disable getnext traversal on empty table */ - if(iflist_root.count == 0) iftable.maxlength = 0; + if(iflist_root.count == 0) { + iftable.maxlength = 0; + } } /** @@ -786,53 +784,37 @@ void mib2_add_arp_entry(struct netif *ni, ip4_addr_t *ip) snmp_netiftoifindex(ni, &arpidx[0]); snmp_iptooid(ip, &arpidx[1]); - for (tree = 0; tree < 2; tree++) - { - if (tree == 0) - { + for (tree = 0; tree < 2; tree++) { + if (tree == 0) { at_rn = &arptree_root; - } - else - { + } else { at_rn = &ipntomtree_root; } - for (level = 0; level < 5; level++) - { + for (level = 0; level < 5; level++) { at_node = NULL; snmp_mib_node_insert(at_rn, arpidx[level], &at_node); - if ((level != 4) && (at_node != NULL)) - { - if (at_node->nptr == NULL) - { + if ((level != 4) && (at_node != NULL)) { + if (at_node->nptr == NULL) { at_rn = snmp_mib_lrn_alloc(); at_node->nptr = &at_rn->scalar.node; - if (at_rn != NULL) - { - if (level == 3) - { - if (tree == 0) - { + if (at_rn != NULL) { + if (level == 3) { + if (tree == 0) { at_rn->scalar.get_object_def = atentry_get_object_def; at_rn->scalar.get_value = atentry_get_value; - } - else - { + } else { at_rn->scalar.get_object_def = ip_ntomentry_get_object_def; at_rn->scalar.get_value = ip_ntomentry_get_value; } at_rn->scalar.set_test = noleafs_set_test; at_rn->scalar.set_value = noleafs_set_value; } - } - else - { + } else { /* at_rn == NULL, malloc failure */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_arpidx_tree() insert failed, mem full")); break; } - } - else - { + } else { at_rn = (struct mib_list_rootnode*)(void*)at_node->nptr; } } @@ -857,37 +839,27 @@ void mib2_remove_arp_entry(struct netif *ni, ip4_addr_t *ip) snmp_netiftoifindex(ni, &arpidx[0]); snmp_iptooid(ip, &arpidx[1]); - for (tree = 0; tree < 2; tree++) - { + for (tree = 0; tree < 2; tree++) { /* mark nodes for deletion */ - if (tree == 0) - { + if (tree == 0) { at_rn = &arptree_root; - } - else - { + } else { at_rn = &ipntomtree_root; } level = 0; del_cnt = 0; - while ((level < 5) && (at_rn != NULL)) - { + while ((level < 5) && (at_rn != NULL)) { fc = snmp_mib_node_find(at_rn, arpidx[level], &at_n); - if (fc == 0) - { + if (fc == 0) { /* arpidx[level] does not exist */ del_cnt = 0; at_rn = NULL; - } - else if (fc == 1) - { + } else if (fc == 1) { del_rn[del_cnt] = at_rn; del_n[del_cnt] = at_n; del_cnt++; at_rn = (struct mib_list_rootnode*)(void*)at_n->nptr; - } - else if (fc == 2) - { + } else if (fc == 2) { /* reset delete (2 or more childs) */ del_cnt = 0; at_rn = (struct mib_list_rootnode*)(void*)at_n->nptr; @@ -895,24 +867,26 @@ void mib2_remove_arp_entry(struct netif *ni, ip4_addr_t *ip) level++; } /* delete marked index nodes */ - while (del_cnt > 0) - { + while (del_cnt > 0) { del_cnt--; at_rn = del_rn[del_cnt]; at_n = del_n[del_cnt]; next = snmp_mib_node_delete(at_rn, at_n); - if (next != NULL) - { + if (next != NULL) { LWIP_ASSERT("next_count == 0",next->count == 0); snmp_mib_lrn_free(next); } } } /* disable getnext traversal on empty tables */ - if(arptree_root.count == 0) at.maxlength = 0; - if(ipntomtree_root.count == 0) ipntomtable.maxlength = 0; + if(arptree_root.count == 0) { + at.maxlength = 0; + } + if(ipntomtree_root.count == 0) { + ipntomtable.maxlength = 0; + } } /** @@ -931,35 +905,26 @@ void mib2_add_ip4(struct netif *ni) level = 0; ipa_rn = &ipaddrtree_root; - while (level < 4) - { + while (level < 4) { ipa_node = NULL; snmp_mib_node_insert(ipa_rn, ipaddridx[level], &ipa_node); - if ((level != 3) && (ipa_node != NULL)) - { - if (ipa_node->nptr == NULL) - { + if ((level != 3) && (ipa_node != NULL)) { + if (ipa_node->nptr == NULL) { ipa_rn = snmp_mib_lrn_alloc(); ipa_node->nptr = &ipa_rn->scalar.node; - if (ipa_rn != NULL) - { - if (level == 2) - { + if (ipa_rn != NULL) { + if (level == 2) { ipa_rn->scalar.get_object_def = ip_addrentry_get_object_def; ipa_rn->scalar.get_value = ip_addrentry_get_value; ipa_rn->scalar.set_test = noleafs_set_test; ipa_rn->scalar.set_value = noleafs_set_value; } - } - else - { + } else { /* ipa_rn == NULL, malloc failure */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_ipaddridx_tree() insert failed, mem full")); break; } - } - else - { + } else { ipa_rn = (struct mib_list_rootnode*)(void*)ipa_node->nptr; } } @@ -987,24 +952,18 @@ void mib2_remove_ip4(struct netif *ni) level = 0; del_cnt = 0; ipa_rn = &ipaddrtree_root; - while ((level < 4) && (ipa_rn != NULL)) - { + while ((level < 4) && (ipa_rn != NULL)) { fc = snmp_mib_node_find(ipa_rn, ipaddridx[level], &ipa_n); - if (fc == 0) - { + if (fc == 0) { /* ipaddridx[level] does not exist */ del_cnt = 0; ipa_rn = NULL; - } - else if (fc == 1) - { + } else if (fc == 1) { del_rn[del_cnt] = ipa_rn; del_n[del_cnt] = ipa_n; del_cnt++; ipa_rn = (struct mib_list_rootnode*)(void*)ipa_n->nptr; - } - else if (fc == 2) - { + } else if (fc == 2) { /* reset delete (2 or more childs) */ del_cnt = 0; ipa_rn = (struct mib_list_rootnode*)(void*)ipa_n->nptr; @@ -1012,22 +971,22 @@ void mib2_remove_ip4(struct netif *ni) level++; } /* delete marked index nodes */ - while (del_cnt > 0) - { + while (del_cnt > 0) { del_cnt--; ipa_rn = del_rn[del_cnt]; ipa_n = del_n[del_cnt]; next = snmp_mib_node_delete(ipa_rn, ipa_n); - if (next != NULL) - { + if (next != NULL) { LWIP_ASSERT("next_count == 0",next->count == 0); snmp_mib_lrn_free(next); } } /* disable getnext traversal on empty table */ - if (ipaddrtree_root.count == 0) ipaddrtable.maxlength = 0; + if (ipaddrtree_root.count == 0) { + ipaddrtable.maxlength = 0; + } } /** @@ -1045,14 +1004,11 @@ void mib2_add_route_ip4(u8_t dflt, struct netif *ni) u8_t insert = 0; ip4_addr_t dst; - if (dflt != 0) - { + if (dflt != 0) { /* the default route 0.0.0.0 */ ip4_addr_set_any(&dst); insert = 1; - } - else - { + } else { /* route to the network address */ ip4_addr_get_network(&dst, netif_ip4_addr(ni), netif_ip4_netmask(ni)); /* exclude 0.0.0.0 network (reserved for default rte) */ @@ -1060,8 +1016,7 @@ void mib2_add_route_ip4(u8_t dflt, struct netif *ni) insert = 1; } } - if (insert) - { + if (insert) { struct mib_list_rootnode *iprte_rn; struct mib_list_node *iprte_node; s32_t iprteidx[4]; @@ -1070,35 +1025,27 @@ void mib2_add_route_ip4(u8_t dflt, struct netif *ni) snmp_iptooid(&dst, &iprteidx[0]); level = 0; iprte_rn = &iprtetree_root; - while (level < 4) - { + while (level < 4) { iprte_node = NULL; snmp_mib_node_insert(iprte_rn, iprteidx[level], &iprte_node); if ((level != 3) && (iprte_node != NULL)) { - if (iprte_node->nptr == NULL) - { + if (iprte_node->nptr == NULL) { iprte_rn = snmp_mib_lrn_alloc(); iprte_node->nptr = &iprte_rn->scalar.node; - if (iprte_rn != NULL) - { - if (level == 2) - { + if (iprte_rn != NULL) { + if (level == 2) { iprte_rn->scalar.get_object_def = ip_rteentry_get_object_def; iprte_rn->scalar.get_value = ip_rteentry_get_value; iprte_rn->scalar.set_test = noleafs_set_test; iprte_rn->scalar.set_value = noleafs_set_value; } - } - else - { + } else { /* iprte_rn == NULL, malloc failure */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_iprteidx_tree() insert failed, mem full")); break; } - } - else - { + } else { iprte_rn = (struct mib_list_rootnode*)(void*)iprte_node->nptr; } } @@ -1122,14 +1069,11 @@ void mib2_remove_route_ip4(u8_t dflt, struct netif *ni) u8_t del = 0; ip4_addr_t dst; - if (dflt != 0) - { + if (dflt != 0) { /* the default route 0.0.0.0 */ ip4_addr_set_any(&dst); del = 1; - } - else - { + } else { /* route to the network address */ ip4_addr_get_network(&dst, netif_ip4_addr(ni), netif_ip4_netmask(ni)); /* exclude 0.0.0.0 network (reserved for default rte) */ @@ -1137,8 +1081,7 @@ void mib2_remove_route_ip4(u8_t dflt, struct netif *ni) del = 1; } } - if (del) - { + if (del) { struct mib_list_rootnode *iprte_rn, *next, *del_rn[4]; struct mib_list_node *iprte_n, *del_n[4]; s32_t iprteidx[4]; @@ -1149,24 +1092,18 @@ void mib2_remove_route_ip4(u8_t dflt, struct netif *ni) level = 0; del_cnt = 0; iprte_rn = &iprtetree_root; - while ((level < 4) && (iprte_rn != NULL)) - { + while ((level < 4) && (iprte_rn != NULL)) { fc = snmp_mib_node_find(iprte_rn, iprteidx[level], &iprte_n); - if (fc == 0) - { + if (fc == 0) { /* iprteidx[level] does not exist */ del_cnt = 0; iprte_rn = NULL; - } - else if (fc == 1) - { + } else if (fc == 1) { del_rn[del_cnt] = iprte_rn; del_n[del_cnt] = iprte_n; del_cnt++; iprte_rn = (struct mib_list_rootnode*)(void*)iprte_n->nptr; - } - else if (fc == 2) - { + } else if (fc == 2) { /* reset delete (2 or more childs) */ del_cnt = 0; iprte_rn = (struct mib_list_rootnode*)(void*)iprte_n->nptr; @@ -1174,23 +1111,23 @@ void mib2_remove_route_ip4(u8_t dflt, struct netif *ni) level++; } /* delete marked index nodes */ - while (del_cnt > 0) - { + while (del_cnt > 0) { del_cnt--; iprte_rn = del_rn[del_cnt]; iprte_n = del_n[del_cnt]; next = snmp_mib_node_delete(iprte_rn, iprte_n); - if (next != NULL) - { + if (next != NULL) { LWIP_ASSERT("next_count == 0",next->count == 0); snmp_mib_lrn_free(next); } } } /* disable getnext traversal on empty table */ - if (iprtetree_root.count == 0) iprtetable.maxlength = 0; + if (iprtetree_root.count == 0) { + iprtetable.maxlength = 0; + } } @@ -1214,35 +1151,26 @@ void mib2_udp_bind(struct udp_pcb *pcb) udpidx[4] = pcb->local_port; udp_rn = &udp_root; - for (level = 0; level < 5; level++) - { + for (level = 0; level < 5; level++) { udp_node = NULL; snmp_mib_node_insert(udp_rn, udpidx[level], &udp_node); - if ((level != 4) && (udp_node != NULL)) - { - if (udp_node->nptr == NULL) - { + if ((level != 4) && (udp_node != NULL)) { + if (udp_node->nptr == NULL) { udp_rn = snmp_mib_lrn_alloc(); udp_node->nptr = &udp_rn->scalar.node; - if (udp_rn != NULL) - { - if (level == 3) - { + if (udp_rn != NULL) { + if (level == 3) { udp_rn->scalar.get_object_def = udpentry_get_object_def; udp_rn->scalar.get_value = udpentry_get_value; udp_rn->scalar.set_test = noleafs_set_test; udp_rn->scalar.set_value = noleafs_set_value; } - } - else - { + } else { /* udp_rn == NULL, malloc failure */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_udpidx_tree() insert failed, mem full")); break; } - } - else - { + } else { udp_rn = (struct mib_list_rootnode*)(void*)udp_node->nptr; } } @@ -1274,40 +1202,31 @@ void mib2_udp_unbind(struct udp_pcb *pcb) (e.g. when reusing ports or for temp output PCBs) */ bindings = 0; npcb = udp_pcbs; - while ((npcb != NULL)) - { + while ((npcb != NULL)) { if (ip_addr_cmp(&npcb->local_ip, &pcb->local_ip) && - (npcb->local_port == udpidx[4])) - { + (npcb->local_port == udpidx[4])) { bindings++; } npcb = npcb->next; } - if (bindings == 1) - { + if (bindings == 1) { /* selectively remove */ /* mark nodes for deletion */ level = 0; del_cnt = 0; udp_rn = &udp_root; - while ((level < 5) && (udp_rn != NULL)) - { + while ((level < 5) && (udp_rn != NULL)) { fc = snmp_mib_node_find(udp_rn, udpidx[level], &udp_n); - if (fc == 0) - { + if (fc == 0) { /* udpidx[level] does not exist */ del_cnt = 0; udp_rn = NULL; - } - else if (fc == 1) - { + } else if (fc == 1) { del_rn[del_cnt] = udp_rn; del_n[del_cnt] = udp_n; del_cnt++; udp_rn = (struct mib_list_rootnode*)(void*)udp_n->nptr; - } - else if (fc == 2) - { + } else if (fc == 2) { /* reset delete (2 or more childs) */ del_cnt = 0; udp_rn = (struct mib_list_rootnode*)(void*)udp_n->nptr; @@ -1315,23 +1234,23 @@ void mib2_udp_unbind(struct udp_pcb *pcb) level++; } /* delete marked index nodes */ - while (del_cnt > 0) - { + while (del_cnt > 0) { del_cnt--; udp_rn = del_rn[del_cnt]; udp_n = del_n[del_cnt]; next = snmp_mib_node_delete(udp_rn, udp_n); - if (next != NULL) - { + if (next != NULL) { LWIP_ASSERT("next_count == 0",next->count == 0); snmp_mib_lrn_free(next); } } } /* disable getnext traversal on empty table */ - if (udp_root.count == 0) udptable.maxlength = 0; + if (udp_root.count == 0) { + udptable.maxlength = 0; + } } @@ -1477,8 +1396,7 @@ void mib2_get_snmpgrpid_ptr(const struct snmp_obj_id **oid) void snmp_set_snmpenableauthentraps(u8_t *value) { - if (value != NULL) - { + if (value != NULL) { snmpenableauthentraps_ptr = value; } } @@ -1503,59 +1421,55 @@ system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) /* return to object name, adding index depth (1) */ ident_len += 1; ident -= 1; - if (ident_len == 2) - { + if (ident_len == 2) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def system.%"U16_F".0\n",(u16_t)id)); - switch (id) - { - case 1: /* sysDescr */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); - break; - case 2: /* sysObjectID */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); - break; - case 3: /* sysUpTime */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS); - break; - case 4: /* sysContact */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); - break; - case 5: /* sysName */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); - break; - case 6: /* sysLocation */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); - break; - case 7: /* sysServices */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (id) { + case 1: /* sysDescr */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); + break; + case 2: /* sysObjectID */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); + break; + case 3: /* sysUpTime */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS); + break; + case 4: /* sysContact */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); + break; + case 5: /* sysName */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); + break; + case 6: /* sysLocation */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); + break; + case 7: /* sysServices */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -1571,35 +1485,34 @@ system_get_value(struct obj_def *od, void *value) LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* sysDescr */ - MEMCPY(value, sysdescr_ptr, *sysdescr_len_ptr); - return *sysdescr_len_ptr; - case 2: /* sysObjectID */ - MEMCPY(value, sysobjid_ptr->id, sysobjid_ptr->len * sizeof(s32_t)); - return sysobjid_ptr->len * sizeof(s32_t); - case 3: /* sysUpTime */ - MIB2_COPY_SYSUPTIME_TO((u32_t*)value); - return sizeof(u32_t); - case 4: /* sysContact */ - MEMCPY(value, syscontact_ptr, *syscontact_len_ptr); - return *syscontact_len_ptr; - case 5: /* sysName */ - MEMCPY(value, sysname_ptr, *sysname_len_ptr); - return *sysname_len_ptr; - case 6: /* sysLocation */ - MEMCPY(value, syslocation_ptr, *syslocation_len_ptr); - return *syslocation_len_ptr; - case 7: /* sysServices */ - { - s32_t *sint_ptr = (s32_t*)value; - *sint_ptr = sysservices; - return sizeof(s32_t); - } - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_value(): unknown id: %d\n", id)); - break; + switch (id) { + case 1: /* sysDescr */ + MEMCPY(value, sysdescr_ptr, *sysdescr_len_ptr); + return *sysdescr_len_ptr; + case 2: /* sysObjectID */ + MEMCPY(value, sysobjid_ptr->id, sysobjid_ptr->len * sizeof(s32_t)); + return sysobjid_ptr->len * sizeof(s32_t); + case 3: /* sysUpTime */ + MIB2_COPY_SYSUPTIME_TO((u32_t*)value); + return sizeof(u32_t); + case 4: /* sysContact */ + MEMCPY(value, syscontact_ptr, *syscontact_len_ptr); + return *syscontact_len_ptr; + case 5: /* sysName */ + MEMCPY(value, sysname_ptr, *sysname_len_ptr); + return *sysname_len_ptr; + case 6: /* sysLocation */ + MEMCPY(value, syslocation_ptr, *syslocation_len_ptr); + return *syslocation_len_ptr; + case 7: /* sysServices */ + { + s32_t *sint_ptr = (s32_t*)value; + *sint_ptr = sysservices; + return sizeof(s32_t); + } + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_value(): unknown id: %d\n", id)); + break; } return 0; @@ -1614,29 +1527,25 @@ system_set_test(struct obj_def *od, u16_t len, void *value) set_ok = 0; LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 4: /* sysContact */ - if (len < syscontact_size) - { - set_ok = 1; - } - break; - case 5: /* sysName */ - if (len < sysname_size) - { - set_ok = 1; - } - break; - case 6: /* sysLocation */ - if (len < syslocation_size) - { - set_ok = 1; - } - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_set_test(): unknown id: %d\n", id)); - break; + switch (id) { + case 4: /* sysContact */ + if (len < syscontact_size) { + set_ok = 1; + } + break; + case 5: /* sysName */ + if (len < sysname_size) { + set_ok = 1; + } + break; + case 6: /* sysLocation */ + if (len < syslocation_size) { + set_ok = 1; + } + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_set_test(): unknown id: %d\n", id)); + break; } return set_ok; } @@ -1649,23 +1558,22 @@ system_set_value(struct obj_def *od, u16_t len, void *value) LWIP_ASSERT("invalid len", len <= 0xff); LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 4: /* sysContact (size already checked in system_set_test) */ - MEMCPY(syscontact_ptr, value, len); - *syscontact_len_ptr = (u8_t)len; - break; - case 5: /* sysName (size already checked in system_set_test) */ - MEMCPY(sysname_ptr, value, len); - *sysname_len_ptr = (u8_t)len; - break; - case 6: /* sysLocation (size already checked in system_set_test) */ - MEMCPY(syslocation_ptr, value, len); - *syslocation_len_ptr = (u8_t)len; - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_set_value(): unknown id: %d\n", id)); - break; + switch (id) { + case 4: /* sysContact (size already checked in system_set_test) */ + MEMCPY(syscontact_ptr, value, len); + *syscontact_len_ptr = (u8_t)len; + break; + case 5: /* sysName (size already checked in system_set_test) */ + MEMCPY(sysname_ptr, value, len); + *sysname_len_ptr = (u8_t)len; + break; + case 6: /* sysLocation (size already checked in system_set_test) */ + MEMCPY(syslocation_ptr, value, len); + *syslocation_len_ptr = (u8_t)len; + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_set_value(): unknown id: %d\n", id)); + break; } } @@ -1682,17 +1590,14 @@ interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) /* return to object name, adding index depth (1) */ ident_len += 1; ident -= 1; - if (ident_len == 2) - { + if (ident_len == 2) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("interfaces_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -1704,8 +1609,7 @@ interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) static u16_t interfaces_get_value(struct obj_def *od, void *value) { - if (od->id_inst_ptr[0] == 1) - { + if (od->id_inst_ptr[0] == 1) { s32_t *sint_ptr = (s32_t*)value; *sint_ptr = iflist_root.count; return sizeof(*sint_ptr); @@ -1729,84 +1633,80 @@ ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) /* return to object name, adding index depth (1) */ ident_len += 1; ident -= 1; - if (ident_len == 2) - { + if (ident_len == 2) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ifentry.%"U16_F"\n",(u16_t)id)); - switch (id) - { - case 1: /* ifIndex */ - case 3: /* ifType */ - case 4: /* ifMtu */ - case 8: /* ifOperStatus */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - case 2: /* ifDescr */ + switch (id) { + case 1: /* ifIndex */ + case 3: /* ifType */ + case 4: /* ifMtu */ + case 8: /* ifOperStatus */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + case 2: /* ifDescr */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); + break; + case 5: /* ifSpeed */ + case 21: /* ifOutQLen */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE); + break; + case 6: /* ifPhysAddress */ + { + struct netif *netif; + + snmp_ifindextonetif(ident[1], &netif); od->instance = MIB_OBJECT_TAB; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); - break; - case 5: /* ifSpeed */ - case 21: /* ifOutQLen */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE); - break; - case 6: /* ifPhysAddress */ - { - struct netif *netif; - - snmp_ifindextonetif(ident[1], &netif); - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); - } - break; - case 7: /* ifAdminStatus */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - case 9: /* ifLastChange */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS); - break; - case 10: /* ifInOctets */ - case 11: /* ifInUcastPkts */ - case 12: /* ifInNUcastPkts */ - case 13: /* ifInDiscarts */ - case 14: /* ifInErrors */ - case 15: /* ifInUnkownProtos */ - case 16: /* ifOutOctets */ - case 17: /* ifOutUcastPkts */ - case 18: /* ifOutNUcastPkts */ - case 19: /* ifOutDiscarts */ - case 20: /* ifOutErrors */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); - break; - case 22: /* ifSpecific */ - /** @note returning zeroDotZero (0.0) no media specific MIB support */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + } + break; + case 7: /* ifAdminStatus */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + case 9: /* ifLastChange */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS); + break; + case 10: /* ifInOctets */ + case 11: /* ifInUcastPkts */ + case 12: /* ifInNUcastPkts */ + case 13: /* ifInDiscarts */ + case 14: /* ifInErrors */ + case 15: /* ifInUnkownProtos */ + case 16: /* ifOutOctets */ + case 17: /* ifOutUcastPkts */ + case 18: /* ifOutNUcastPkts */ + case 19: /* ifOutDiscarts */ + case 20: /* ifOutErrors */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); + break; + case 22: /* ifSpecific */ + /** @note returning zeroDotZero (0.0) no media specific MIB support */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -1824,157 +1724,156 @@ ifentry_get_value(struct obj_def *od, void *value) snmp_ifindextonetif(od->id_inst_ptr[1], &netif); LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* ifIndex */ + switch (id) { + case 1: /* ifIndex */ + { + s32_t *sint_ptr = (s32_t*)value; + *sint_ptr = od->id_inst_ptr[1]; + return sizeof(*sint_ptr); + } + case 2: /* ifDescr */ + MEMCPY(value, netif->name, 2); + /** @todo this should be some sort of sizeof(struct netif.name) */ + return 2; + case 3: /* ifType */ + { + s32_t *sint_ptr = (s32_t*)value; + *sint_ptr = netif->link_type; + return sizeof(*sint_ptr); + } + case 4: /* ifMtu */ + { + s32_t *sint_ptr = (s32_t*)value; + *sint_ptr = netif->mtu; + return sizeof(*sint_ptr); + } + case 5: /* ifSpeed */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->link_speed; + return sizeof(*uint_ptr); + } + case 6: /* ifPhysAddress */ + MEMCPY(value, netif->hwaddr, netif->hwaddr_len); + return netif->hwaddr_len; + case 7: /* ifAdminStatus */ + { + s32_t *sint_ptr = (s32_t*)value; + if (netif_is_up(netif)) { - s32_t *sint_ptr = (s32_t*)value; - *sint_ptr = od->id_inst_ptr[1]; - return sizeof(*sint_ptr); - } - case 2: /* ifDescr */ - MEMCPY(value, netif->name, 2); - /** @todo this should be some sort of sizeof(struct netif.name) */ - return 2; - case 3: /* ifType */ - { - s32_t *sint_ptr = (s32_t*)value; - *sint_ptr = netif->link_type; - return sizeof(*sint_ptr); - } - case 4: /* ifMtu */ - { - s32_t *sint_ptr = (s32_t*)value; - *sint_ptr = netif->mtu; - return sizeof(*sint_ptr); - } - case 5: /* ifSpeed */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->link_speed; - return sizeof(*uint_ptr); - } - case 6: /* ifPhysAddress */ - MEMCPY(value, netif->hwaddr, netif->hwaddr_len); - return netif->hwaddr_len; - case 7: /* ifAdminStatus */ - { - s32_t *sint_ptr = (s32_t*)value; - if (netif_is_up(netif)) + if (netif_is_link_up(netif)) { - if (netif_is_link_up(netif)) - { - *sint_ptr = 1; /* up */ - } - else - { - *sint_ptr = 7; /* lowerLayerDown */ - } + *sint_ptr = 1; /* up */ } else { - *sint_ptr = 2; /* down */ + *sint_ptr = 7; /* lowerLayerDown */ } - return sizeof(*sint_ptr); } - case 8: /* ifOperStatus */ + else { - s32_t *sint_ptr = (s32_t*)value; - if (netif_is_up(netif)) - { - *sint_ptr = 1; - } - else - { - *sint_ptr = 2; - } - return sizeof(*sint_ptr); + *sint_ptr = 2; /* down */ } - case 9: /* ifLastChange */ + return sizeof(*sint_ptr); + } + case 8: /* ifOperStatus */ + { + s32_t *sint_ptr = (s32_t*)value; + if (netif_is_up(netif)) { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->ts; - return sizeof(*uint_ptr); + *sint_ptr = 1; } - case 10: /* ifInOctets */ + else { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifinoctets; - return sizeof(*uint_ptr); + *sint_ptr = 2; } - case 11: /* ifInUcastPkts */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifinucastpkts; - return sizeof(*uint_ptr); - } - case 12: /* ifInNUcastPkts */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifinnucastpkts; - return sizeof(*uint_ptr); - } - case 13: /* ifInDiscards */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifindiscards; - return sizeof(*uint_ptr); - } - case 14: /* ifInErrors */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifinerrors; - return sizeof(*uint_ptr); - } - case 15: /* ifInUnkownProtos */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifinunknownprotos; - return sizeof(*uint_ptr); - } - case 16: /* ifOutOctets */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifoutoctets; - return sizeof(*uint_ptr); - } - case 17: /* ifOutUcastPkts */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifoutucastpkts; - return sizeof(*uint_ptr); - } - case 18: /* ifOutNUcastPkts */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifoutnucastpkts; - return sizeof(*uint_ptr); - } - case 19: /* ifOutDiscarts */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifoutdiscards; - return sizeof(*uint_ptr); - } - case 20: /* ifOutErrors */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = netif->mib2_counters.ifouterrors; - return sizeof(*uint_ptr); - } - case 21: /* ifOutQLen */ - /** @todo figure out if this must be 0 (no queue) or 1? */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = 0; - return sizeof(*uint_ptr); - } - case 22: /* ifSpecific */ - MEMCPY(value, ifspecific.id, ifspecific.len * sizeof(s32_t)); - return ifspecific.len * sizeof(s32_t); - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_value(): unknown id: %d\n", id)); - break; + return sizeof(*sint_ptr); + } + case 9: /* ifLastChange */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->ts; + return sizeof(*uint_ptr); + } + case 10: /* ifInOctets */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifinoctets; + return sizeof(*uint_ptr); + } + case 11: /* ifInUcastPkts */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifinucastpkts; + return sizeof(*uint_ptr); + } + case 12: /* ifInNUcastPkts */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifinnucastpkts; + return sizeof(*uint_ptr); + } + case 13: /* ifInDiscards */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifindiscards; + return sizeof(*uint_ptr); + } + case 14: /* ifInErrors */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifinerrors; + return sizeof(*uint_ptr); + } + case 15: /* ifInUnkownProtos */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifinunknownprotos; + return sizeof(*uint_ptr); + } + case 16: /* ifOutOctets */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifoutoctets; + return sizeof(*uint_ptr); + } + case 17: /* ifOutUcastPkts */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifoutucastpkts; + return sizeof(*uint_ptr); + } + case 18: /* ifOutNUcastPkts */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifoutnucastpkts; + return sizeof(*uint_ptr); + } + case 19: /* ifOutDiscarts */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifoutdiscards; + return sizeof(*uint_ptr); + } + case 20: /* ifOutErrors */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = netif->mib2_counters.ifouterrors; + return sizeof(*uint_ptr); + } + case 21: /* ifOutQLen */ + /** @todo figure out if this must be 0 (no queue) or 1? */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = 0; + return sizeof(*uint_ptr); + } + case 22: /* ifSpecific */ + MEMCPY(value, ifspecific.id, ifspecific.len * sizeof(s32_t)); + return ifspecific.len * sizeof(s32_t); + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_value(): unknown id: %d\n", id)); + break; } return 0; @@ -1991,15 +1890,14 @@ ifentry_set_test(struct obj_def *od, u16_t len, void *value) set_ok = 0; snmp_ifindextonetif(od->id_inst_ptr[1], &netif); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 7: /* ifAdminStatus */ - { - s32_t *sint_ptr = (s32_t*)value; - if (*sint_ptr == 1 || *sint_ptr == 2) - set_ok = 1; - } - break; + switch (id) { + case 7: /* ifAdminStatus */ + { + s32_t *sint_ptr = (s32_t*)value; + if (*sint_ptr == 1 || *sint_ptr == 2) + set_ok = 1; + } + break; } return set_ok; } @@ -2013,21 +1911,17 @@ ifentry_set_value(struct obj_def *od, u16_t len, void *value) snmp_ifindextonetif(od->id_inst_ptr[1], &netif); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 7: /* ifAdminStatus */ - { - s32_t *sint_ptr = (s32_t*)value; - if (*sint_ptr == 1) - { - netif_set_up(netif); - } - else if (*sint_ptr == 2) - { - netif_set_down(netif); - } + switch (id) { + case 7: /* ifAdminStatus */ + { + s32_t *sint_ptr = (s32_t*)value; + if (*sint_ptr == 1) { + netif_set_up(netif); + } else if (*sint_ptr == 2) { + netif_set_down(netif); } - break; + } + break; } } #endif /* SNMP_SAFE_REQUESTS */ @@ -2046,36 +1940,32 @@ atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) ident_len += 5; ident -= 5; - if (ident_len == 6) - { + if (ident_len == 6) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; - switch (ident[0]) - { - case 1: /* atIfIndex */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - case 2: /* atPhysAddress */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); - break; - case 3: /* atNetAddress */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (ident[0]) { + case 1: /* atIfIndex */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + case 2: /* atPhysAddress */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); + break; + case 3: /* atNetAddress */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -2098,33 +1988,31 @@ atentry_get_value(struct obj_def *od, void *value) snmp_ifindextonetif(od->id_inst_ptr[1], &netif); snmp_oidtoip(&od->id_inst_ptr[2], &ip); - if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1) - { + if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1) { LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* atIfIndex */ - { - s32_t *sint_ptr = (s32_t*)value; - *sint_ptr = od->id_inst_ptr[1]; - return sizeof(*sint_ptr); - } - case 2: /* atPhysAddress */ - { - struct eth_addr *dst = (struct eth_addr*)value; - *dst = *ethaddr_ret; - return sizeof(*dst); /** @todo try to use netif::hwaddr_len */ - } - case 3: /* atNetAddress */ - { - ip4_addr_t *dst = (ip4_addr_t*)value; - *dst = *ipaddr_ret; - return sizeof(*dst); - } - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_value(): unknown id: %d\n", id)); - break; + switch (id) { + case 1: /* atIfIndex */ + { + s32_t *sint_ptr = (s32_t*)value; + *sint_ptr = od->id_inst_ptr[1]; + return sizeof(*sint_ptr); + } + case 2: /* atPhysAddress */ + { + struct eth_addr *dst = (struct eth_addr*)value; + *dst = *ethaddr_ret; + return sizeof(*dst); /** @todo try to use netif::hwaddr_len */ + } + case 3: /* atNetAddress */ + { + ip4_addr_t *dst = (ip4_addr_t*)value; + *dst = *ipaddr_ret; + return sizeof(*dst); + } + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_value(): unknown id: %d\n", id)); + break; } } @@ -2140,56 +2028,52 @@ ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) /* return to object name, adding index depth (1) */ ident_len += 1; ident -= 1; - if (ident_len == 2) - { + if (ident_len == 2) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ip.%"U16_F".0\n",(u16_t)id)); - switch (id) - { - case 1: /* ipForwarding */ - case 2: /* ipDefaultTTL */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - case 3: /* ipInReceives */ - case 4: /* ipInHdrErrors */ - case 5: /* ipInAddrErrors */ - case 6: /* ipForwDatagrams */ - case 7: /* ipInUnknownProtos */ - case 8: /* ipInDiscards */ - case 9: /* ipInDelivers */ - case 10: /* ipOutRequests */ - case 11: /* ipOutDiscards */ - case 12: /* ipOutNoRoutes */ - case 14: /* ipReasmReqds */ - case 15: /* ipReasmOKs */ - case 16: /* ipReasmFails */ - case 17: /* ipFragOKs */ - case 18: /* ipFragFails */ - case 19: /* ipFragCreates */ - case 23: /* ipRoutingDiscards */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); - break; - case 13: /* ipReasmTimeout */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (id) { + case 1: /* ipForwarding */ + case 2: /* ipDefaultTTL */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + case 3: /* ipInReceives */ + case 4: /* ipInHdrErrors */ + case 5: /* ipInAddrErrors */ + case 6: /* ipForwDatagrams */ + case 7: /* ipInUnknownProtos */ + case 8: /* ipInDiscards */ + case 9: /* ipInDelivers */ + case 10: /* ipOutRequests */ + case 11: /* ipOutDiscards */ + case 12: /* ipOutNoRoutes */ + case 14: /* ipReasmReqds */ + case 15: /* ipReasmOKs */ + case 16: /* ipReasmFails */ + case 17: /* ipFragOKs */ + case 18: /* ipFragFails */ + case 19: /* ipFragCreates */ + case 23: /* ipRoutingDiscards */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); + break; + case 13: /* ipReasmTimeout */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -2202,141 +2086,140 @@ ip_get_value(struct obj_def *od, void *value) LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* ipForwarding */ - { - s32_t *sint_ptr = (s32_t*)value; + switch (id) { + case 1: /* ipForwarding */ + { + s32_t *sint_ptr = (s32_t*)value; #if IP_FORWARD - /* forwarding */ - *sint_ptr = 1; + /* forwarding */ + *sint_ptr = 1; #else - /* not-forwarding */ - *sint_ptr = 2; + /* not-forwarding */ + *sint_ptr = 2; #endif - return sizeof(*sint_ptr); - } - case 2: /* ipDefaultTTL */ - { - s32_t *sint_ptr = (s32_t*)value; - *sint_ptr = IP_DEFAULT_TTL; - return sizeof(*sint_ptr); - } - case 3: /* ipInReceives */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipinreceives); - return sizeof(*uint_ptr); - } - case 4: /* ipInHdrErrors */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipinhdrerrors); - return sizeof(*uint_ptr); - } - case 5: /* ipInAddrErrors */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipinaddrerrors); - return sizeof(*uint_ptr); - } - case 6: /* ipForwDatagrams */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipforwdatagrams); - return sizeof(*uint_ptr); - } - case 7: /* ipInUnknownProtos */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipinunknownprotos); - return sizeof(*uint_ptr); - } - case 8: /* ipInDiscards */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipindiscards); - return sizeof(*uint_ptr); - } - case 9: /* ipInDelivers */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipindelivers); - return sizeof(*uint_ptr); - } - case 10: /* ipOutRequests */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipoutrequests); - return sizeof(*uint_ptr); - } - case 11: /* ipOutDiscards */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipoutdiscards); - return sizeof(*uint_ptr); - } - case 12: /* ipOutNoRoutes */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipoutnoroutes); - return sizeof(*uint_ptr); - } - case 13: /* ipReasmTimeout */ - { - s32_t *sint_ptr = (s32_t*)value; + return sizeof(*sint_ptr); + } + case 2: /* ipDefaultTTL */ + { + s32_t *sint_ptr = (s32_t*)value; + *sint_ptr = IP_DEFAULT_TTL; + return sizeof(*sint_ptr); + } + case 3: /* ipInReceives */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipinreceives); + return sizeof(*uint_ptr); + } + case 4: /* ipInHdrErrors */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipinhdrerrors); + return sizeof(*uint_ptr); + } + case 5: /* ipInAddrErrors */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipinaddrerrors); + return sizeof(*uint_ptr); + } + case 6: /* ipForwDatagrams */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipforwdatagrams); + return sizeof(*uint_ptr); + } + case 7: /* ipInUnknownProtos */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipinunknownprotos); + return sizeof(*uint_ptr); + } + case 8: /* ipInDiscards */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipindiscards); + return sizeof(*uint_ptr); + } + case 9: /* ipInDelivers */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipindelivers); + return sizeof(*uint_ptr); + } + case 10: /* ipOutRequests */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipoutrequests); + return sizeof(*uint_ptr); + } + case 11: /* ipOutDiscards */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipoutdiscards); + return sizeof(*uint_ptr); + } + case 12: /* ipOutNoRoutes */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipoutnoroutes); + return sizeof(*uint_ptr); + } + case 13: /* ipReasmTimeout */ + { + s32_t *sint_ptr = (s32_t*)value; #if IP_REASSEMBLY - *sint_ptr = IP_REASS_MAXAGE; + *sint_ptr = IP_REASS_MAXAGE; #else - *sint_ptr = 0; + *sint_ptr = 0; #endif - return sizeof(*sint_ptr); - } - case 14: /* ipReasmReqds */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipreasmreqds); - return sizeof(*uint_ptr); - } - case 15: /* ipReasmOKs */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipreasmoks); - return sizeof(*uint_ptr); - } - case 16: /* ipReasmFails */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipreasmfails); - return sizeof(*uint_ptr); - } - case 17: /* ipFragOKs */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipfragoks); - return sizeof(*uint_ptr); - } - case 18: /* ipFragFails */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipfragfails); - return sizeof(*uint_ptr); - } - case 19: /* ipFragCreates */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = STATS_GET(mib2.ipfragcreates); - return sizeof(*uint_ptr); - } - case 23: /* ipRoutingDiscards: not supported -> always 0 */ - { - u32_t *uint_ptr = (u32_t*)value; - *uint_ptr = 0; - return sizeof(*uint_ptr); - } - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_value(): unknown id: %d\n", id)); - break; + return sizeof(*sint_ptr); + } + case 14: /* ipReasmReqds */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipreasmreqds); + return sizeof(*uint_ptr); + } + case 15: /* ipReasmOKs */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipreasmoks); + return sizeof(*uint_ptr); + } + case 16: /* ipReasmFails */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipreasmfails); + return sizeof(*uint_ptr); + } + case 17: /* ipFragOKs */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipfragoks); + return sizeof(*uint_ptr); + } + case 18: /* ipFragFails */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipfragfails); + return sizeof(*uint_ptr); + } + case 19: /* ipFragCreates */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = STATS_GET(mib2.ipfragcreates); + return sizeof(*uint_ptr); + } + case 23: /* ipRoutingDiscards: not supported -> always 0 */ + { + u32_t *uint_ptr = (u32_t*)value; + *uint_ptr = 0; + return sizeof(*uint_ptr); + } + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_value(): unknown id: %d\n", id)); + break; } return 0; @@ -2362,29 +2245,28 @@ ip_set_test(struct obj_def *od, u16_t len, void *value) set_ok = 0; LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* ipForwarding */ + switch (id) { + case 1: /* ipForwarding */ #if IP_FORWARD - /* forwarding */ - if (*sint_ptr == 1) + /* forwarding */ + if (*sint_ptr == 1) #else - /* not-forwarding */ - if (*sint_ptr == 2) + /* not-forwarding */ + if (*sint_ptr == 2) #endif - { - set_ok = 1; - } - break; - case 2: /* ipDefaultTTL */ - if (*sint_ptr == IP_DEFAULT_TTL) - { - set_ok = 1; - } - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_set_test(): unknown id: %d\n", id)); - break; + { + set_ok = 1; + } + break; + case 2: /* ipDefaultTTL */ + if (*sint_ptr == IP_DEFAULT_TTL) + { + set_ok = 1; + } + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_set_test(): unknown id: %d\n", id)); + break; } return set_ok; } @@ -2396,8 +2278,7 @@ ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) ident_len += 4; ident -= 4; - if (ident_len == 5) - { + if (ident_len == 5) { u8_t id; od->id_inst_len = ident_len; @@ -2405,29 +2286,26 @@ ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; - switch (id) - { - case 1: /* ipAdEntAddr */ - case 3: /* ipAdEntNetMask */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); - break; - case 2: /* ipAdEntIfIndex */ - case 4: /* ipAdEntBcastAddr */ - case 5: /* ipAdEntReasmMaxSize */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (id) { + case 1: /* ipAdEntAddr */ + case 3: /* ipAdEntNetMask */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); + break; + case 2: /* ipAdEntIfIndex */ + case 4: /* ipAdEntBcastAddr */ + case 5: /* ipAdEntReasmMaxSize */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -2443,65 +2321,62 @@ ip_addrentry_get_value(struct obj_def *od, void *value) snmp_oidtoip(&od->id_inst_ptr[1], &ip); ifidx = 0; - while ((netif != NULL) && !ip4_addr_cmp(&ip, netif_ip4_addr(netif))) - { + while ((netif != NULL) && !ip4_addr_cmp(&ip, netif_ip4_addr(netif))) { netif = netif->next; ifidx++; } - if (netif != NULL) - { + if (netif != NULL) { LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* ipAdEntAddr */ - { - ip4_addr_t *dst = (ip4_addr_t*)value; - *dst = *netif_ip4_addr(netif); - return sizeof(dst->addr); - } - case 2: /* ipAdEntIfIndex */ - { - s32_t *sint_ptr = (s32_t*)value; - *sint_ptr = ifidx + 1; - return sizeof(*sint_ptr); - } - case 3: /* ipAdEntNetMask */ - { - ip4_addr_t *dst = (ip4_addr_t*)value; - *dst = *netif_ip4_netmask(netif); - return sizeof(*dst); - } - case 4: /* ipAdEntBcastAddr */ - { - s32_t *sint_ptr = (s32_t*)value; + switch (id) { + case 1: /* ipAdEntAddr */ + { + ip4_addr_t *dst = (ip4_addr_t*)value; + *dst = *netif_ip4_addr(netif); + return sizeof(dst->addr); + } + case 2: /* ipAdEntIfIndex */ + { + s32_t *sint_ptr = (s32_t*)value; + *sint_ptr = ifidx + 1; + return sizeof(*sint_ptr); + } + case 3: /* ipAdEntNetMask */ + { + ip4_addr_t *dst = (ip4_addr_t*)value; + *dst = *netif_ip4_netmask(netif); + return sizeof(*dst); + } + case 4: /* ipAdEntBcastAddr */ + { + s32_t *sint_ptr = (s32_t*)value; - /* lwIP oddity, there's no broadcast - address in the netif we can rely on */ - *sint_ptr = IPADDR_BROADCAST & 1; - return sizeof(*sint_ptr); - } - case 5: /* ipAdEntReasmMaxSize */ - { - s32_t *sint_ptr = (s32_t*)value; + /* lwIP oddity, there's no broadcast + address in the netif we can rely on */ + *sint_ptr = IPADDR_BROADCAST & 1; + return sizeof(*sint_ptr); + } + case 5: /* ipAdEntReasmMaxSize */ + { + s32_t *sint_ptr = (s32_t*)value; #if IP_REASSEMBLY - /* @todo The theoretical maximum is IP_REASS_MAX_PBUFS * size of the pbufs, - * but only if receiving one fragmented packet at a time. - * The current solution is to calculate for 2 simultaneous packets... - */ - *sint_ptr = (IP_HLEN + ((IP_REASS_MAX_PBUFS/2) * - (PBUF_POOL_BUFSIZE - PBUF_LINK_ENCAPSULATION_HLEN - PBUF_LINK_HLEN - IP_HLEN))); + /* @todo The theoretical maximum is IP_REASS_MAX_PBUFS * size of the pbufs, + * but only if receiving one fragmented packet at a time. + * The current solution is to calculate for 2 simultaneous packets... + */ + *sint_ptr = (IP_HLEN + ((IP_REASS_MAX_PBUFS/2) * + (PBUF_POOL_BUFSIZE - PBUF_LINK_ENCAPSULATION_HLEN - PBUF_LINK_HLEN - IP_HLEN))); #else - /** @todo returning MTU would be a bad thing and - returning a wild guess like '576' isn't good either */ - *sint_ptr = 0; + /** @todo returning MTU would be a bad thing and + returning a wild guess like '576' isn't good either */ + *sint_ptr = 0; #endif - return sizeof(*sint_ptr); - } - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_value(): unknown id: %d\n", id)); - break; + return sizeof(*sint_ptr); + } + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_value(): unknown id: %d\n", id)); + break; } } @@ -2522,53 +2397,49 @@ ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) ident_len += 4; ident -= 4; - if (ident_len == 5) - { + if (ident_len == 5) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; - switch (id) - { - case 1: /* ipRouteDest */ - case 7: /* ipRouteNextHop */ - case 11: /* ipRouteMask */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); - break; - case 2: /* ipRouteIfIndex */ - case 3: /* ipRouteMetric1 */ - case 4: /* ipRouteMetric2 */ - case 5: /* ipRouteMetric3 */ - case 6: /* ipRouteMetric4 */ - case 8: /* ipRouteType */ - case 10: /* ipRouteAge */ - case 12: /* ipRouteMetric5 */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - case 9: /* ipRouteProto */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - case 13: /* ipRouteInfo */ - /** @note returning zeroDotZero (0.0) no routing protocol specific MIB */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (id) { + case 1: /* ipRouteDest */ + case 7: /* ipRouteNextHop */ + case 11: /* ipRouteMask */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); + break; + case 2: /* ipRouteIfIndex */ + case 3: /* ipRouteMetric1 */ + case 4: /* ipRouteMetric2 */ + case 5: /* ipRouteMetric3 */ + case 6: /* ipRouteMetric4 */ + case 8: /* ipRouteType */ + case 10: /* ipRouteAge */ + case 12: /* ipRouteMetric5 */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + case 9: /* ipRouteProto */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + case 13: /* ipRouteInfo */ + /** @note returning zeroDotZero (0.0) no routing protocol specific MIB */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -2585,148 +2456,127 @@ ip_rteentry_get_value(struct obj_def *od, void *value) ident = od->id_inst_ptr; snmp_oidtoip(&ident[1], &dest); - if (ip4_addr_isany_val(dest)) - { + if (ip4_addr_isany_val(dest)) { /* ip_route() uses default netif for default route */ netif = netif_default; - } - else - { + } else { /* not using ip_route(), need exact match! */ netif = netif_list; while ((netif != NULL) && - !ip4_addr_netcmp(&dest, netif_ip4_addr(netif), netif_ip4_netmask(netif)) ) - { + !ip4_addr_netcmp(&dest, netif_ip4_addr(netif), netif_ip4_netmask(netif))) { netif = netif->next; } } - if (netif != NULL) - { + if (netif != NULL) { LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; - switch (id) - { - case 1: /* ipRouteDest */ - { - ip4_addr_t *dst = (ip4_addr_t*)value; + switch (id) { + case 1: /* ipRouteDest */ + { + ip4_addr_t *dst = (ip4_addr_t*)value; - if (ip4_addr_isany_val(dest)) - { - /* default rte has 0.0.0.0 dest */ - ip4_addr_set_zero(dst); - } - else - { - /* netifs have netaddress dest */ - ip4_addr_get_network(dst, netif_ip4_addr(netif), netif_ip4_netmask(netif)); - } + if (ip4_addr_isany_val(dest)) { + /* default rte has 0.0.0.0 dest */ + ip4_addr_set_zero(dst); + } else { + /* netifs have netaddress dest */ + ip4_addr_get_network(dst, netif_ip4_addr(netif), netif_ip4_netmask(netif)); + } - return sizeof(*dst); - } - case 2: /* ipRouteIfIndex */ - { - s32_t *sint_ptr = (s32_t*)value; + return sizeof(*dst); + } + case 2: /* ipRouteIfIndex */ + { + s32_t *sint_ptr = (s32_t*)value; - snmp_netiftoifindex(netif, sint_ptr); - return sizeof(*sint_ptr); - } - case 3: /* ipRouteMetric1 */ - { - s32_t *sint_ptr = (s32_t*)value; + snmp_netiftoifindex(netif, sint_ptr); + return sizeof(*sint_ptr); + } + case 3: /* ipRouteMetric1 */ + { + s32_t *sint_ptr = (s32_t*)value; - if (ip4_addr_isany_val(dest)) - { - /* default rte has metric 1 */ - *sint_ptr = 1; - } - else - { - /* other rtes have metric 0 */ - *sint_ptr = 0; - } - return sizeof(*sint_ptr); - } - case 4: /* ipRouteMetric2 */ - case 5: /* ipRouteMetric3 */ - case 6: /* ipRouteMetric4 */ - case 12: /* ipRouteMetric5 */ - { - s32_t *sint_ptr = (s32_t*)value; - /* not used */ - *sint_ptr = -1; - return sizeof(*sint_ptr); - } - case 7: /* ipRouteNextHop */ - { - ip4_addr_t *dst = (ip4_addr_t*)value; - - if (ip4_addr_isany_val(dest)) - { - /* default rte: gateway */ - *dst = *netif_ip4_gw(netif); - } - else - { - /* other rtes: netif ip_addr */ - *dst = *netif_ip4_addr(netif); - } - - return sizeof(*dst); - } - case 8: /* ipRouteType */ - { - s32_t *sint_ptr = (s32_t*)value; - - if (ip4_addr_isany_val(dest)) - { - /* default rte is indirect */ - *sint_ptr = 4; - } - else - { - /* other rtes are direct */ - *sint_ptr = 3; - } - return sizeof(*sint_ptr); - } - case 9: /* ipRouteProto */ - { - s32_t *sint_ptr = (s32_t*)value; - /* locally defined routes */ - *sint_ptr = 2; - return sizeof(*sint_ptr); - } - case 10: /* ipRouteAge */ - { - s32_t *sint_ptr = (s32_t*)value; - /** @todo (sysuptime - timestamp last change) / 100 - @see snmp_insert_iprteidx_tree() */ + if (ip4_addr_isany_val(dest)) { + /* default rte has metric 1 */ + *sint_ptr = 1; + } else { + /* other rtes have metric 0 */ *sint_ptr = 0; - return sizeof(*sint_ptr); } - case 11: /* ipRouteMask */ - { - ip4_addr_t *dst = (ip4_addr_t*)value; + return sizeof(*sint_ptr); + } + case 4: /* ipRouteMetric2 */ + case 5: /* ipRouteMetric3 */ + case 6: /* ipRouteMetric4 */ + case 12: /* ipRouteMetric5 */ + { + s32_t *sint_ptr = (s32_t*)value; + /* not used */ + *sint_ptr = -1; + return sizeof(*sint_ptr); + } + case 7: /* ipRouteNextHop */ + { + ip4_addr_t *dst = (ip4_addr_t*)value; - if (ip4_addr_isany_val(dest)) - { - /* default rte use 0.0.0.0 mask */ - ip4_addr_set_zero(dst); - } - else - { - /* other rtes use netmask */ - *dst = *netif_ip4_netmask(netif); - } - - return sizeof(*dst); + if (ip4_addr_isany_val(dest)) { + /* default rte: gateway */ + *dst = *netif_ip4_gw(netif); + } else { + /* other rtes: netif ip_addr */ + *dst = *netif_ip4_addr(netif); } - case 13: /* ipRouteInfo */ - MEMCPY(value, iprouteinfo.id, iprouteinfo.len * sizeof(s32_t)); - return iprouteinfo.len * sizeof(s32_t); - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_value(): unknown id: %d\n", id)); - break; + + return sizeof(*dst); + } + case 8: /* ipRouteType */ + { + s32_t *sint_ptr = (s32_t*)value; + + if (ip4_addr_isany_val(dest)) { + /* default rte is indirect */ + *sint_ptr = 4; + } else { + /* other rtes are direct */ + *sint_ptr = 3; + } + return sizeof(*sint_ptr); + } + case 9: /* ipRouteProto */ + { + s32_t *sint_ptr = (s32_t*)value; + /* locally defined routes */ + *sint_ptr = 2; + return sizeof(*sint_ptr); + } + case 10: /* ipRouteAge */ + { + s32_t *sint_ptr = (s32_t*)value; + /** @todo (sysuptime - timestamp last change) / 100 + @see snmp_insert_iprteidx_tree() */ + *sint_ptr = 0; + return sizeof(*sint_ptr); + } + case 11: /* ipRouteMask */ + { + ip4_addr_t *dst = (ip4_addr_t*)value; + + if (ip4_addr_isany_val(dest)) { + /* default rte use 0.0.0.0 mask */ + ip4_addr_set_zero(dst); + } else { + /* other rtes use netmask */ + *dst = *netif_ip4_netmask(netif); + } + + return sizeof(*dst); + } + case 13: /* ipRouteInfo */ + MEMCPY(value, iprouteinfo.id, iprouteinfo.len * sizeof(s32_t)); + return iprouteinfo.len * sizeof(s32_t); + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_value(): unknown id: %d\n", id)); + break; } } @@ -2740,8 +2590,7 @@ ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) ident_len += 5; ident -= 5; - if (ident_len == 6) - { + if (ident_len == 6) { u8_t id; od->id_inst_len = ident_len; @@ -2749,32 +2598,29 @@ ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; - switch (id) - { - case 1: /* ipNetToMediaIfIndex */ - case 4: /* ipNetToMediaType */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - case 2: /* ipNetToMediaPhysAddress */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); - break; - case 3: /* ipNetToMediaNetAddress */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (id) { + case 1: /* ipNetToMediaIfIndex */ + case 4: /* ipNetToMediaType */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + case 2: /* ipNetToMediaPhysAddress */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR); + break; + case 3: /* ipNetToMediaNetAddress */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -2797,39 +2643,37 @@ ip_ntomentry_get_value(struct obj_def *od, void *value) snmp_oidtoip(&od->id_inst_ptr[2], &ip); #if LWIP_ARP /** @todo implement a netif_find_addr */ - if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1) - { + if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1) { LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* ipNetToMediaIfIndex */ - { - s32_t *sint_ptr = (s32_t*)value; - *sint_ptr = od->id_inst_ptr[1]; - return sizeof(*sint_ptr); - } - case 2: /* ipNetToMediaPhysAddress */ - { - struct eth_addr *dst = (struct eth_addr*)value; + switch (id) { + case 1: /* ipNetToMediaIfIndex */ + { + s32_t *sint_ptr = (s32_t*)value; + *sint_ptr = od->id_inst_ptr[1]; + return sizeof(*sint_ptr); + } + case 2: /* ipNetToMediaPhysAddress */ + { + struct eth_addr *dst = (struct eth_addr*)value; - *dst = *ethaddr_ret; - return sizeof(*dst); /** @todo try to use netif::hwaddr_len */ - } - case 3: /* ipNetToMediaNetAddress */ - { - ip4_addr_t *dst = (ip4_addr_t*)value; + *dst = *ethaddr_ret; + return sizeof(*dst); /** @todo try to use netif::hwaddr_len */ + } + case 3: /* ipNetToMediaNetAddress */ + { + ip4_addr_t *dst = (ip4_addr_t*)value; - *dst = *ipaddr_ret; - return sizeof(*dst); - } - case 4: /* ipNetToMediaType */ - { - s32_t *sint_ptr = (s32_t*)value; - /* dynamic (?) */ - *sint_ptr = 3; - return sizeof(*sint_ptr); - } + *dst = *ipaddr_ret; + return sizeof(*dst); + } + case 4: /* ipNetToMediaType */ + { + s32_t *sint_ptr = (s32_t*)value; + /* dynamic (?) */ + *sint_ptr = 3; + return sizeof(*sint_ptr); + } default: LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_value(): unknown id: %d\n", id)); break; @@ -2847,17 +2691,14 @@ icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) ident_len += 1; ident -= 1; if ((ident_len == 2) && - (ident[0] > 0) && (ident[0] < 27)) - { + (ident[0] > 0) && (ident[0] < 27)) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -2871,89 +2712,88 @@ icmp_get_value(struct obj_def *od, void *value) LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* icmpInMsgs */ - *uint_ptr = STATS_GET(mib2.icmpinmsgs); - return sizeof(*uint_ptr); - case 2: /* icmpInErrors */ - *uint_ptr = STATS_GET(mib2.icmpinerrors); - return sizeof(*uint_ptr); - case 3: /* icmpInDestUnreachs */ - *uint_ptr = STATS_GET(mib2.icmpindestunreachs); - return sizeof(*uint_ptr); - case 4: /* icmpInTimeExcds */ - *uint_ptr = STATS_GET(mib2.icmpintimeexcds); - return sizeof(*uint_ptr); - case 5: /* icmpInParmProbs */ - *uint_ptr = STATS_GET(mib2.icmpinparmprobs); - return sizeof(*uint_ptr); - case 6: /* icmpInSrcQuenchs */ - *uint_ptr = STATS_GET(mib2.icmpinsrcquenchs); - return sizeof(*uint_ptr); - case 7: /* icmpInRedirects */ - *uint_ptr = STATS_GET(mib2.icmpinredirects); - return sizeof(*uint_ptr); - case 8: /* icmpInEchos */ - *uint_ptr = STATS_GET(mib2.icmpinechos); - return sizeof(*uint_ptr); - case 9: /* icmpInEchoReps */ - *uint_ptr = STATS_GET(mib2.icmpinechoreps); - return sizeof(*uint_ptr); - case 10: /* icmpInTimestamps */ - *uint_ptr = STATS_GET(mib2.icmpintimestamps); - return sizeof(*uint_ptr); - case 11: /* icmpInTimestampReps */ - *uint_ptr = STATS_GET(mib2.icmpintimestampreps); - return sizeof(*uint_ptr); - case 12: /* icmpInAddrMasks */ - *uint_ptr = STATS_GET(mib2.icmpinaddrmasks); - return sizeof(*uint_ptr); - case 13: /* icmpInAddrMaskReps */ - *uint_ptr = STATS_GET(mib2.icmpinaddrmaskreps); - return sizeof(*uint_ptr); - case 14: /* icmpOutMsgs */ - *uint_ptr = STATS_GET(mib2.icmpoutmsgs); - return sizeof(*uint_ptr); - case 15: /* icmpOutErrors */ - *uint_ptr = STATS_GET(mib2.icmpouterrors); - return sizeof(*uint_ptr); - case 16: /* icmpOutDestUnreachs */ - *uint_ptr = STATS_GET(mib2.icmpoutdestunreachs); - return sizeof(*uint_ptr); - case 17: /* icmpOutTimeExcds */ - *uint_ptr = STATS_GET(mib2.icmpouttimeexcds); - return sizeof(*uint_ptr); - case 18: /* icmpOutParmProbs: not supported -> always 0 */ - *uint_ptr = 0; - return sizeof(*uint_ptr); - case 19: /* icmpOutSrcQuenchs: not supported -> always 0 */ - *uint_ptr = 0; - return sizeof(*uint_ptr); - case 20: /* icmpOutRedirects: not supported -> always 0 */ - *uint_ptr = 0; - return sizeof(*uint_ptr); - case 21: /* icmpOutEchos */ - *uint_ptr = STATS_GET(mib2.icmpoutechos); - return sizeof(*uint_ptr); - case 22: /* icmpOutEchoReps */ - *uint_ptr = STATS_GET(mib2.icmpoutechoreps); - return sizeof(*uint_ptr); - case 23: /* icmpOutTimestamps: not supported -> always 0 */ - *uint_ptr = 0; - return sizeof(*uint_ptr); - case 24: /* icmpOutTimestampReps: not supported -> always 0 */ - *uint_ptr = 0; - return sizeof(*uint_ptr); - case 25: /* icmpOutAddrMasks: not supported -> always 0 */ - *uint_ptr = 0; - return sizeof(*uint_ptr); - case 26: /* icmpOutAddrMaskReps: not supported -> always 0 */ - *uint_ptr = 0; - return sizeof(*uint_ptr); - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_value(): unknown id: %d\n", id)); - break; + switch (id) { + case 1: /* icmpInMsgs */ + *uint_ptr = STATS_GET(mib2.icmpinmsgs); + return sizeof(*uint_ptr); + case 2: /* icmpInErrors */ + *uint_ptr = STATS_GET(mib2.icmpinerrors); + return sizeof(*uint_ptr); + case 3: /* icmpInDestUnreachs */ + *uint_ptr = STATS_GET(mib2.icmpindestunreachs); + return sizeof(*uint_ptr); + case 4: /* icmpInTimeExcds */ + *uint_ptr = STATS_GET(mib2.icmpintimeexcds); + return sizeof(*uint_ptr); + case 5: /* icmpInParmProbs */ + *uint_ptr = STATS_GET(mib2.icmpinparmprobs); + return sizeof(*uint_ptr); + case 6: /* icmpInSrcQuenchs */ + *uint_ptr = STATS_GET(mib2.icmpinsrcquenchs); + return sizeof(*uint_ptr); + case 7: /* icmpInRedirects */ + *uint_ptr = STATS_GET(mib2.icmpinredirects); + return sizeof(*uint_ptr); + case 8: /* icmpInEchos */ + *uint_ptr = STATS_GET(mib2.icmpinechos); + return sizeof(*uint_ptr); + case 9: /* icmpInEchoReps */ + *uint_ptr = STATS_GET(mib2.icmpinechoreps); + return sizeof(*uint_ptr); + case 10: /* icmpInTimestamps */ + *uint_ptr = STATS_GET(mib2.icmpintimestamps); + return sizeof(*uint_ptr); + case 11: /* icmpInTimestampReps */ + *uint_ptr = STATS_GET(mib2.icmpintimestampreps); + return sizeof(*uint_ptr); + case 12: /* icmpInAddrMasks */ + *uint_ptr = STATS_GET(mib2.icmpinaddrmasks); + return sizeof(*uint_ptr); + case 13: /* icmpInAddrMaskReps */ + *uint_ptr = STATS_GET(mib2.icmpinaddrmaskreps); + return sizeof(*uint_ptr); + case 14: /* icmpOutMsgs */ + *uint_ptr = STATS_GET(mib2.icmpoutmsgs); + return sizeof(*uint_ptr); + case 15: /* icmpOutErrors */ + *uint_ptr = STATS_GET(mib2.icmpouterrors); + return sizeof(*uint_ptr); + case 16: /* icmpOutDestUnreachs */ + *uint_ptr = STATS_GET(mib2.icmpoutdestunreachs); + return sizeof(*uint_ptr); + case 17: /* icmpOutTimeExcds */ + *uint_ptr = STATS_GET(mib2.icmpouttimeexcds); + return sizeof(*uint_ptr); + case 18: /* icmpOutParmProbs: not supported -> always 0 */ + *uint_ptr = 0; + return sizeof(*uint_ptr); + case 19: /* icmpOutSrcQuenchs: not supported -> always 0 */ + *uint_ptr = 0; + return sizeof(*uint_ptr); + case 20: /* icmpOutRedirects: not supported -> always 0 */ + *uint_ptr = 0; + return sizeof(*uint_ptr); + case 21: /* icmpOutEchos */ + *uint_ptr = STATS_GET(mib2.icmpoutechos); + return sizeof(*uint_ptr); + case 22: /* icmpOutEchoReps */ + *uint_ptr = STATS_GET(mib2.icmpoutechoreps); + return sizeof(*uint_ptr); + case 23: /* icmpOutTimestamps: not supported -> always 0 */ + *uint_ptr = 0; + return sizeof(*uint_ptr); + case 24: /* icmpOutTimestampReps: not supported -> always 0 */ + *uint_ptr = 0; + return sizeof(*uint_ptr); + case 25: /* icmpOutAddrMasks: not supported -> always 0 */ + *uint_ptr = 0; + return sizeof(*uint_ptr); + case 26: /* icmpOutAddrMaskReps: not supported -> always 0 */ + *uint_ptr = 0; + return sizeof(*uint_ptr); + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_value(): unknown id: %d\n", id)); + break; } return 0; @@ -2969,8 +2809,7 @@ tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) /* return to object name, adding index depth (1) */ ident_len += 1; ident -= 1; - if (ident_len == 2) - { + if (ident_len == 2) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; @@ -2978,42 +2817,39 @@ tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) id = (u8_t)ident[0]; LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id)); - switch (id) - { - case 1: /* tcpRtoAlgorithm */ - case 2: /* tcpRtoMin */ - case 3: /* tcpRtoMax */ - case 4: /* tcpMaxConn */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - case 5: /* tcpActiveOpens */ - case 6: /* tcpPassiveOpens */ - case 7: /* tcpAttemptFails */ - case 8: /* tcpEstabResets */ - case 10: /* tcpInSegs */ - case 11: /* tcpOutSegs */ - case 12: /* tcpRetransSegs */ - case 14: /* tcpInErrs */ - case 15: /* tcpOutRsts */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); - break; - case 9: /* tcpCurrEstab */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (id) { + case 1: /* tcpRtoAlgorithm */ + case 2: /* tcpRtoMin */ + case 3: /* tcpRtoMax */ + case 4: /* tcpMaxConn */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + case 5: /* tcpActiveOpens */ + case 6: /* tcpPassiveOpens */ + case 7: /* tcpAttemptFails */ + case 8: /* tcpEstabResets */ + case 10: /* tcpInSegs */ + case 11: /* tcpOutSegs */ + case 12: /* tcpRetransSegs */ + case 14: /* tcpInErrs */ + case 15: /* tcpOutRsts */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); + break; + case 9: /* tcpCurrEstab */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -3028,70 +2864,67 @@ tcp_get_value(struct obj_def *od, void *value) LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* tcpRtoAlgorithm, vanj(4) */ - *sint_ptr = 4; - return sizeof(*sint_ptr); - case 2: /* tcpRtoMin */ - /* @todo not the actual value, a guess, - needs to be calculated */ - *sint_ptr = 1000; - return sizeof(*sint_ptr); - case 3: /* tcpRtoMax */ - /* @todo not the actual value, a guess, - needs to be calculated */ - *sint_ptr = 60000; - return sizeof(*sint_ptr); - case 4: /* tcpMaxConn */ - *sint_ptr = MEMP_NUM_TCP_PCB; - return sizeof(*sint_ptr); - case 5: /* tcpActiveOpens */ - *uint_ptr = STATS_GET(mib2.tcpactiveopens); - return sizeof(*uint_ptr); - case 6: /* tcpPassiveOpens */ - *uint_ptr = STATS_GET(mib2.tcppassiveopens); - return sizeof(*uint_ptr); - case 7: /* tcpAttemptFails */ - *uint_ptr = STATS_GET(mib2.tcpattemptfails); - return sizeof(*uint_ptr); - case 8: /* tcpEstabResets */ - *uint_ptr = STATS_GET(mib2.tcpestabresets); - return sizeof(*uint_ptr); - case 9: /* tcpCurrEstab */ - { - u16_t tcpcurrestab = 0; - struct tcp_pcb *pcb = tcp_active_pcbs; - while (pcb != NULL) - { - if ((pcb->state == ESTABLISHED) || - (pcb->state == CLOSE_WAIT)) - { - tcpcurrestab++; - } - pcb = pcb->next; + switch (id) { + case 1: /* tcpRtoAlgorithm, vanj(4) */ + *sint_ptr = 4; + return sizeof(*sint_ptr); + case 2: /* tcpRtoMin */ + /* @todo not the actual value, a guess, + needs to be calculated */ + *sint_ptr = 1000; + return sizeof(*sint_ptr); + case 3: /* tcpRtoMax */ + /* @todo not the actual value, a guess, + needs to be calculated */ + *sint_ptr = 60000; + return sizeof(*sint_ptr); + case 4: /* tcpMaxConn */ + *sint_ptr = MEMP_NUM_TCP_PCB; + return sizeof(*sint_ptr); + case 5: /* tcpActiveOpens */ + *uint_ptr = STATS_GET(mib2.tcpactiveopens); + return sizeof(*uint_ptr); + case 6: /* tcpPassiveOpens */ + *uint_ptr = STATS_GET(mib2.tcppassiveopens); + return sizeof(*uint_ptr); + case 7: /* tcpAttemptFails */ + *uint_ptr = STATS_GET(mib2.tcpattemptfails); + return sizeof(*uint_ptr); + case 8: /* tcpEstabResets */ + *uint_ptr = STATS_GET(mib2.tcpestabresets); + return sizeof(*uint_ptr); + case 9: /* tcpCurrEstab */ + { + u16_t tcpcurrestab = 0; + struct tcp_pcb *pcb = tcp_active_pcbs; + while (pcb != NULL) { + if ((pcb->state == ESTABLISHED) || + (pcb->state == CLOSE_WAIT)) { + tcpcurrestab++; } - *uint_ptr = tcpcurrestab; + pcb = pcb->next; } - return sizeof(*uint_ptr); - case 10: /* tcpInSegs */ - *uint_ptr = STATS_GET(mib2.tcpinsegs); - return sizeof(*uint_ptr); - case 11: /* tcpOutSegs */ - *uint_ptr = STATS_GET(mib2.tcpoutsegs); - return sizeof(*uint_ptr); - case 12: /* tcpRetransSegs */ - *uint_ptr = STATS_GET(mib2.tcpretranssegs); - return sizeof(*uint_ptr); - case 14: /* tcpInErrs */ - *uint_ptr = STATS_GET(mib2.tcpinerrs); - return sizeof(*uint_ptr); - case 15: /* tcpOutRsts */ - *uint_ptr = STATS_GET(mib2.tcpoutrsts); - return sizeof(*uint_ptr); - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_value(): unknown id: %d\n", id)); - break; + *uint_ptr = tcpcurrestab; + } + return sizeof(*uint_ptr); + case 10: /* tcpInSegs */ + *uint_ptr = STATS_GET(mib2.tcpinsegs); + return sizeof(*uint_ptr); + case 11: /* tcpOutSegs */ + *uint_ptr = STATS_GET(mib2.tcpoutsegs); + return sizeof(*uint_ptr); + case 12: /* tcpRetransSegs */ + *uint_ptr = STATS_GET(mib2.tcpretranssegs); + return sizeof(*uint_ptr); + case 14: /* tcpInErrs */ + *uint_ptr = STATS_GET(mib2.tcpinerrs); + return sizeof(*uint_ptr); + case 15: /* tcpOutRsts */ + *uint_ptr = STATS_GET(mib2.tcpoutrsts); + return sizeof(*uint_ptr); + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_value(): unknown id: %d\n", id)); + break; } return 0; @@ -3104,8 +2937,7 @@ tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) ident_len += 10; ident -= 10; - if (ident_len == 11) - { + if (ident_len == 11) { u8_t id; od->id_inst_len = ident_len; @@ -3114,36 +2946,33 @@ tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) id = ident[0]; LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id)); - switch (id) - { - case 1: /* tcpConnState */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - od->v_len = sizeof(s32_t); - break; - case 2: /* tcpConnLocalAddress */ - case 4: /* tcpConnRemAddress */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); - od->v_len = 4; - break; - case 3: /* tcpConnLocalPort */ - case 5: /* tcpConnRemPort */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - od->v_len = sizeof(s32_t); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (id) { + case 1: /* tcpConnState */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + od->v_len = sizeof(s32_t); + break; + case 2: /* tcpConnLocalAddress */ + case 4: /* tcpConnRemAddress */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); + od->v_len = 4; + break; + case 3: /* tcpConnLocalPort */ + case 5: /* tcpConnRemPort */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + od->v_len = sizeof(s32_t); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n")); od->instance = MIB_OBJECT_NONE; } @@ -3174,17 +3003,14 @@ udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) ident_len += 1; ident -= 1; if ((ident_len == 2) && - (ident[0] > 0) && (ident[0] < 6)) - { + (ident[0] > 0) && (ident[0] < 6)) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; od->instance = MIB_OBJECT_SCALAR; od->access = MIB_OBJECT_READ_ONLY; od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -3198,23 +3024,22 @@ udp_get_value(struct obj_def *od, void *value) LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* udpInDatagrams */ - *uint_ptr = STATS_GET(mib2.udpindatagrams); - return sizeof(*uint_ptr); - case 2: /* udpNoPorts */ - *uint_ptr = STATS_GET(mib2.udpnoports); - return sizeof(*uint_ptr); - case 3: /* udpInErrors */ - *uint_ptr = STATS_GET(mib2.udpinerrors); - return sizeof(*uint_ptr); - case 4: /* udpOutDatagrams */ - *uint_ptr = STATS_GET(mib2.udpoutdatagrams); - return sizeof(*uint_ptr); - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_value(): unknown id: %d\n", id)); - break; + switch (id) { + case 1: /* udpInDatagrams */ + *uint_ptr = STATS_GET(mib2.udpindatagrams); + return sizeof(*uint_ptr); + case 2: /* udpNoPorts */ + *uint_ptr = STATS_GET(mib2.udpnoports); + return sizeof(*uint_ptr); + case 3: /* udpInErrors */ + *uint_ptr = STATS_GET(mib2.udpinerrors); + return sizeof(*uint_ptr); + case 4: /* udpOutDatagrams */ + *uint_ptr = STATS_GET(mib2.udpoutdatagrams); + return sizeof(*uint_ptr); + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_value(): unknown id: %d\n", id)); + break; } return 0; @@ -3227,31 +3052,27 @@ udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) ident_len += 5; ident -= 5; - if (ident_len == 6) - { + if (ident_len == 6) { od->id_inst_len = ident_len; od->id_inst_ptr = ident; - switch (ident[0]) - { - case 1: /* udpLocalAddress */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); - break; - case 2: /* udpLocalPort */ - od->instance = MIB_OBJECT_TAB; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (ident[0]) { + case 1: /* udpLocalAddress */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR); + break; + case 2: /* udpLocalPort */ + od->instance = MIB_OBJECT_TAB; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -3273,34 +3094,31 @@ udpentry_get_value(struct obj_def *od, void *value) pcb = udp_pcbs; while ((pcb != NULL) && !(ip_addr_cmp(&pcb->local_ip, &ip) && - (pcb->local_port == port))) - { + (pcb->local_port == port))) { pcb = pcb->next; } - if (pcb != NULL) - { + if (pcb != NULL) { LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* udpLocalAddress */ - { - ip4_addr_t *dst = (ip4_addr_t*)value; - ip4_addr_copy(*dst, *(ip_2_ip4(&pcb->local_ip))); - return sizeof(*dst); - } - break; - case 2: /* udpLocalPort */ - { - s32_t *sint_ptr = (s32_t*)value; - *sint_ptr = pcb->local_port; - return sizeof(*sint_ptr); - } - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_value(): unknown id: %d\n", id)); - break; + switch (id) { + case 1: /* udpLocalAddress */ + { + ip4_addr_t *dst = (ip4_addr_t*)value; + ip4_addr_copy(*dst, *(ip_2_ip4(&pcb->local_ip))); + return sizeof(*dst); + } + break; + case 2: /* udpLocalPort */ + { + s32_t *sint_ptr = (s32_t*)value; + *sint_ptr = pcb->local_port; + return sizeof(*sint_ptr); + } + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_value(): unknown id: %d\n", id)); + break; } } @@ -3313,8 +3131,7 @@ snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) /* return to object name, adding index depth (1) */ ident_len += 1; ident -= 1; - if (ident_len == 2) - { + if (ident_len == 2) { u8_t id; od->id_inst_len = ident_len; @@ -3322,52 +3139,49 @@ snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od) LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff)); id = (u8_t)ident[0]; - switch (id) - { - case 1: /* snmpInPkts */ - case 2: /* snmpOutPkts */ - case 3: /* snmpInBadVersions */ - case 4: /* snmpInBadCommunityNames */ - case 5: /* snmpInBadCommunityUses */ - case 6: /* snmpInASNParseErrs */ - case 8: /* snmpInTooBigs */ - case 9: /* snmpInNoSuchNames */ - case 10: /* snmpInBadValues */ - case 11: /* snmpInReadOnlys */ - case 12: /* snmpInGenErrs */ - case 13: /* snmpInTotalReqVars */ - case 14: /* snmpInTotalSetVars */ - case 15: /* snmpInGetRequests */ - case 16: /* snmpInGetNexts */ - case 17: /* snmpInSetRequests */ - case 18: /* snmpInGetResponses */ - case 19: /* snmpInTraps */ - case 20: /* snmpOutTooBigs */ - case 21: /* snmpOutNoSuchNames */ - case 22: /* snmpOutBadValues */ - case 24: /* snmpOutGenErrs */ - case 25: /* snmpOutGetRequests */ - case 26: /* snmpOutGetNexts */ - case 27: /* snmpOutSetRequests */ - case 28: /* snmpOutGetResponses */ - case 29: /* snmpOutTraps */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_ONLY; - od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); - break; - case 30: /* snmpEnableAuthenTraps */ - od->instance = MIB_OBJECT_SCALAR; - od->access = MIB_OBJECT_READ_WRITE; - od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); - break; - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no such object\n")); - od->instance = MIB_OBJECT_NONE; - break; + switch (id) { + case 1: /* snmpInPkts */ + case 2: /* snmpOutPkts */ + case 3: /* snmpInBadVersions */ + case 4: /* snmpInBadCommunityNames */ + case 5: /* snmpInBadCommunityUses */ + case 6: /* snmpInASNParseErrs */ + case 8: /* snmpInTooBigs */ + case 9: /* snmpInNoSuchNames */ + case 10: /* snmpInBadValues */ + case 11: /* snmpInReadOnlys */ + case 12: /* snmpInGenErrs */ + case 13: /* snmpInTotalReqVars */ + case 14: /* snmpInTotalSetVars */ + case 15: /* snmpInGetRequests */ + case 16: /* snmpInGetNexts */ + case 17: /* snmpInSetRequests */ + case 18: /* snmpInGetResponses */ + case 19: /* snmpInTraps */ + case 20: /* snmpOutTooBigs */ + case 21: /* snmpOutNoSuchNames */ + case 22: /* snmpOutBadValues */ + case 24: /* snmpOutGenErrs */ + case 25: /* snmpOutGetRequests */ + case 26: /* snmpOutGetNexts */ + case 27: /* snmpOutSetRequests */ + case 28: /* snmpOutGetResponses */ + case 29: /* snmpOutTraps */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_ONLY; + od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER); + break; + case 30: /* snmpEnableAuthenTraps */ + od->instance = MIB_OBJECT_SCALAR; + od->access = MIB_OBJECT_READ_WRITE; + od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG); + break; + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no such object\n")); + od->instance = MIB_OBJECT_NONE; + break; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no scalar\n")); od->instance = MIB_OBJECT_NONE; } @@ -3381,95 +3195,94 @@ snmp_get_value(struct obj_def *od, void *value) LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - switch (id) - { - case 1: /* snmpInPkts */ - *uint_ptr = snmpinpkts; - return sizeof(*uint_ptr); - case 2: /* snmpOutPkts */ - *uint_ptr = snmpoutpkts; - return sizeof(*uint_ptr); - case 3: /* snmpInBadVersions */ - *uint_ptr = snmpinbadversions; - return sizeof(*uint_ptr); - case 4: /* snmpInBadCommunityNames */ - *uint_ptr = snmpinbadcommunitynames; - return sizeof(*uint_ptr); - case 5: /* snmpInBadCommunityUses */ - *uint_ptr = snmpinbadcommunityuses; - return sizeof(*uint_ptr); - case 6: /* snmpInASNParseErrs */ - *uint_ptr = snmpinasnparseerrs; - return sizeof(*uint_ptr); - case 8: /* snmpInTooBigs */ - *uint_ptr = snmpintoobigs; - return sizeof(*uint_ptr); - case 9: /* snmpInNoSuchNames */ - *uint_ptr = snmpinnosuchnames; - return sizeof(*uint_ptr); - case 10: /* snmpInBadValues */ - *uint_ptr = snmpinbadvalues; - return sizeof(*uint_ptr); - case 11: /* snmpInReadOnlys */ - *uint_ptr = snmpinreadonlys; - return sizeof(*uint_ptr); - case 12: /* snmpInGenErrs */ - *uint_ptr = snmpingenerrs; - return sizeof(*uint_ptr); - case 13: /* snmpInTotalReqVars */ - *uint_ptr = snmpintotalreqvars; - return sizeof(*uint_ptr); - case 14: /* snmpInTotalSetVars */ - *uint_ptr = snmpintotalsetvars; - return sizeof(*uint_ptr); - case 15: /* snmpInGetRequests */ - *uint_ptr = snmpingetrequests; - return sizeof(*uint_ptr); - case 16: /* snmpInGetNexts */ - *uint_ptr = snmpingetnexts; - return sizeof(*uint_ptr); - case 17: /* snmpInSetRequests */ - *uint_ptr = snmpinsetrequests; - return sizeof(*uint_ptr); - case 18: /* snmpInGetResponses */ - *uint_ptr = snmpingetresponses; - return sizeof(*uint_ptr); - case 19: /* snmpInTraps */ - *uint_ptr = snmpintraps; - return sizeof(*uint_ptr); - case 20: /* snmpOutTooBigs */ - *uint_ptr = snmpouttoobigs; - return sizeof(*uint_ptr); - case 21: /* snmpOutNoSuchNames */ - *uint_ptr = snmpoutnosuchnames; - return sizeof(*uint_ptr); - case 22: /* snmpOutBadValues */ - *uint_ptr = snmpoutbadvalues; - return sizeof(*uint_ptr); - case 24: /* snmpOutGenErrs */ - *uint_ptr = snmpoutgenerrs; - return sizeof(*uint_ptr); - case 25: /* snmpOutGetRequests */ - *uint_ptr = snmpoutgetrequests; - return sizeof(*uint_ptr); - case 26: /* snmpOutGetNexts */ - *uint_ptr = snmpoutgetnexts; - return sizeof(*uint_ptr); - case 27: /* snmpOutSetRequests */ - *uint_ptr = snmpoutsetrequests; - return sizeof(*uint_ptr); - case 28: /* snmpOutGetResponses */ - *uint_ptr = snmpoutgetresponses; - return sizeof(*uint_ptr); - case 29: /* snmpOutTraps */ - *uint_ptr = snmpouttraps; - return sizeof(*uint_ptr); - case 30: /* snmpEnableAuthenTraps */ - *uint_ptr = *snmpenableauthentraps_ptr; - return sizeof(*uint_ptr); - default: - LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_value(): unknown id: %d\n", id)); - break; + switch (id) { + case 1: /* snmpInPkts */ + *uint_ptr = snmpinpkts; + return sizeof(*uint_ptr); + case 2: /* snmpOutPkts */ + *uint_ptr = snmpoutpkts; + return sizeof(*uint_ptr); + case 3: /* snmpInBadVersions */ + *uint_ptr = snmpinbadversions; + return sizeof(*uint_ptr); + case 4: /* snmpInBadCommunityNames */ + *uint_ptr = snmpinbadcommunitynames; + return sizeof(*uint_ptr); + case 5: /* snmpInBadCommunityUses */ + *uint_ptr = snmpinbadcommunityuses; + return sizeof(*uint_ptr); + case 6: /* snmpInASNParseErrs */ + *uint_ptr = snmpinasnparseerrs; + return sizeof(*uint_ptr); + case 8: /* snmpInTooBigs */ + *uint_ptr = snmpintoobigs; + return sizeof(*uint_ptr); + case 9: /* snmpInNoSuchNames */ + *uint_ptr = snmpinnosuchnames; + return sizeof(*uint_ptr); + case 10: /* snmpInBadValues */ + *uint_ptr = snmpinbadvalues; + return sizeof(*uint_ptr); + case 11: /* snmpInReadOnlys */ + *uint_ptr = snmpinreadonlys; + return sizeof(*uint_ptr); + case 12: /* snmpInGenErrs */ + *uint_ptr = snmpingenerrs; + return sizeof(*uint_ptr); + case 13: /* snmpInTotalReqVars */ + *uint_ptr = snmpintotalreqvars; + return sizeof(*uint_ptr); + case 14: /* snmpInTotalSetVars */ + *uint_ptr = snmpintotalsetvars; + return sizeof(*uint_ptr); + case 15: /* snmpInGetRequests */ + *uint_ptr = snmpingetrequests; + return sizeof(*uint_ptr); + case 16: /* snmpInGetNexts */ + *uint_ptr = snmpingetnexts; + return sizeof(*uint_ptr); + case 17: /* snmpInSetRequests */ + *uint_ptr = snmpinsetrequests; + return sizeof(*uint_ptr); + case 18: /* snmpInGetResponses */ + *uint_ptr = snmpingetresponses; + return sizeof(*uint_ptr); + case 19: /* snmpInTraps */ + *uint_ptr = snmpintraps; + return sizeof(*uint_ptr); + case 20: /* snmpOutTooBigs */ + *uint_ptr = snmpouttoobigs; + return sizeof(*uint_ptr); + case 21: /* snmpOutNoSuchNames */ + *uint_ptr = snmpoutnosuchnames; + return sizeof(*uint_ptr); + case 22: /* snmpOutBadValues */ + *uint_ptr = snmpoutbadvalues; + return sizeof(*uint_ptr); + case 24: /* snmpOutGenErrs */ + *uint_ptr = snmpoutgenerrs; + return sizeof(*uint_ptr); + case 25: /* snmpOutGetRequests */ + *uint_ptr = snmpoutgetrequests; + return sizeof(*uint_ptr); + case 26: /* snmpOutGetNexts */ + *uint_ptr = snmpoutgetnexts; + return sizeof(*uint_ptr); + case 27: /* snmpOutSetRequests */ + *uint_ptr = snmpoutsetrequests; + return sizeof(*uint_ptr); + case 28: /* snmpOutGetResponses */ + *uint_ptr = snmpoutgetresponses; + return sizeof(*uint_ptr); + case 29: /* snmpOutTraps */ + *uint_ptr = snmpouttraps; + return sizeof(*uint_ptr); + case 30: /* snmpEnableAuthenTraps */ + *uint_ptr = *snmpenableauthentraps_ptr; + return sizeof(*uint_ptr); + default: + LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_value(): unknown id: %d\n", id)); + break; } return 0; @@ -3491,14 +3304,12 @@ snmp_set_test(struct obj_def *od, u16_t len, void *value) set_ok = 0; LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - if (id == 30) - { + if (id == 30) { /* snmpEnableAuthenTraps */ s32_t *sint_ptr = (s32_t*)value; /* we should have writable non-volatile mem here */ - if ((*sint_ptr == 1) || (*sint_ptr == 2)) - { + if ((*sint_ptr == 1) || (*sint_ptr == 2)) { set_ok = 1; } } @@ -3513,8 +3324,7 @@ snmp_set_value(struct obj_def *od, u16_t len, void *value) LWIP_UNUSED_ARG(len); LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff)); id = (u8_t)od->id_inst_ptr[0]; - if (id == 30) - { + if (id == 30) { /* snmpEnableAuthenTraps */ s32_t *ptr = (s32_t*)value; *snmpenableauthentraps_ptr = (u8_t)*ptr; diff --git a/src/core/snmp/mib_structs.c b/src/core/snmp/mib_structs.c index 7048418b..7fa39319 100644 --- a/src/core/snmp/mib_structs.c +++ b/src/core/snmp/mib_structs.c @@ -66,8 +66,7 @@ push_node(const struct nse* node) { LWIP_ASSERT("node_stack_cnt < NODE_STACK_SIZE",node_stack_cnt < NODE_STACK_SIZE); LWIP_DEBUGF(SNMP_MIB_DEBUG,("push_node() node=%p id=%"S32_F"\n",(const void*)(node->r_ptr),node->r_id)); - if (node_stack_cnt < NODE_STACK_SIZE) - { + if (node_stack_cnt < NODE_STACK_SIZE) { node_stack[node_stack_cnt] = *node; node_stack_cnt++; } @@ -79,8 +78,7 @@ push_node(const struct nse* node) static void pop_node(struct nse* node) { - if (node_stack_cnt > 0) - { + if (node_stack_cnt > 0) { node_stack_cnt--; *node = node_stack[node_stack_cnt]; } @@ -100,8 +98,7 @@ snmp_ifindextonetif(s32_t ifindex, struct netif **netif) ifidx = ifindex - 1; i = 0; - while ((nif != NULL) && (i < ifidx)) - { + while ((nif != NULL) && (i < ifidx)) { nif = nif->next; i++; } @@ -120,8 +117,7 @@ snmp_netiftoifindex(struct netif *netif, s32_t *ifidx) u16_t i; i = 0; - while ((nif != NULL) && (nif != netif)) - { + while ((nif != NULL) && (nif != netif)) { nif = nif->next; i++; } @@ -159,8 +155,7 @@ snmp_mib_ln_alloc(s32_t id) struct mib_list_node *ln; ln = (struct mib_list_node *)memp_malloc(MEMP_SNMP_NODE); - if (ln != NULL) - { + if (ln != NULL) { ln->prev = NULL; ln->next = NULL; ln->objid = id; @@ -181,8 +176,7 @@ snmp_mib_lrn_alloc(void) struct mib_list_rootnode *lrn; lrn = (struct mib_list_rootnode*)memp_malloc(MEMP_SNMP_ROOTNODE); - if (lrn != NULL) - { + if (lrn != NULL) { lrn->scalar.get_object_def = noleafs_get_object_def; lrn->scalar.get_value = noleafs_get_value; lrn->scalar.set_test = noleafs_set_test; @@ -222,84 +216,62 @@ snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_ /* -1 = malloc failure, 0 = not inserted, 1 = inserted, 2 = was present */ insert = 0; - if (rn->head == NULL) - { + if (rn->head == NULL) { /* empty list, add first node */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("alloc empty list objid==%"S32_F"\n",objid)); nn = snmp_mib_ln_alloc(objid); - if (nn != NULL) - { + if (nn != NULL) { rn->head = nn; rn->tail = nn; *insn = nn; insert = 1; - } - else - { + } else { insert = -1; } - } - else - { + } else { struct mib_list_node *n; /* at least one node is present */ n = rn->head; - while ((n != NULL) && (insert == 0)) - { - if (n->objid == objid) - { + while ((n != NULL) && (insert == 0)) { + if (n->objid == objid) { /* node is already there */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("node already there objid==%"S32_F"\n",objid)); *insn = n; insert = 2; - } - else if (n->objid < objid) - { - if (n->next == NULL) - { + } else if (n->objid < objid) { + if (n->next == NULL) { /* alloc and insert at the tail */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("alloc ins tail objid==%"S32_F"\n",objid)); nn = snmp_mib_ln_alloc(objid); - if (nn != NULL) - { + if (nn != NULL) { nn->next = NULL; nn->prev = n; n->next = nn; rn->tail = nn; *insn = nn; insert = 1; - } - else - { + } else { /* insertion failure */ insert = -1; } - } - else - { + } else { /* there's more to explore: traverse list */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("traverse list\n")); n = n->next; } - } - else - { + } else { /* n->objid > objid */ /* alloc and insert between n->prev and n */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("alloc ins n->prev, objid==%"S32_F", n\n",objid)); nn = snmp_mib_ln_alloc(objid); - if (nn != NULL) - { - if (n->prev == NULL) - { + if (nn != NULL) { + if (n->prev == NULL) { /* insert at the head */ nn->next = n; nn->prev = NULL; rn->head = nn; n->prev = nn; - } - else - { + } else { /* insert in the middle */ nn->next = n; nn->prev = n->prev; @@ -308,17 +280,14 @@ snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_ } *insn = nn; insert = 1; - } - else - { + } else { /* insertion failure */ insert = -1; } } } } - if (insert == 1) - { + if (insert == 1) { rn->count += 1; } LWIP_ASSERT("insert != 0",insert != 0); @@ -342,39 +311,27 @@ snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_no LWIP_ASSERT("rn != NULL",rn != NULL); n = rn->head; - while ((n != NULL) && (n->objid != objid)) - { + while ((n != NULL) && (n->objid != objid)) { n = n->next; } - if (n == NULL) - { + if (n == NULL) { fc = 0; - } - else if (n->nptr == NULL) - { + } else if (n->nptr == NULL) { /* leaf, can delete node */ fc = 1; - } - else - { + } else { struct mib_list_rootnode *r; - if (n->nptr->node_type == MIB_NODE_LR) - { + if (n->nptr->node_type == MIB_NODE_LR) { r = (struct mib_list_rootnode*)(void*)n->nptr; - if (r->count > 1) - { + if (r->count > 1) { /* can't delete node */ fc = 2; - } - else - { + } else { /* count <= 1, can delete node */ fc = 1; } - } - else - { + } else { /* other node type */ fc = 3; } @@ -403,34 +360,26 @@ snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n) next = (struct mib_list_rootnode*)(void*)n->nptr; rn->count -= 1; - if (n == rn->head) - { + if (n == rn->head) { rn->head = n->next; - if (n->next != NULL) - { + if (n->next != NULL) { /* not last node, new list begin */ n->next->prev = NULL; } - } - else if (n == rn->tail) - { + } else if (n == rn->tail) { rn->tail = n->prev; - if (n->prev != NULL) - { + if (n->prev != NULL) { /* not last node, new list end */ n->prev->next = NULL; } - } - else - { + } else { /* node must be in the middle */ n->prev->next = n->next; n->next->prev = n->prev; } LWIP_DEBUGF(SNMP_MIB_DEBUG,("free list objid==%"S32_F"\n",n->objid)); snmp_mib_ln_free(n); - if (rn->count == 0) - { + if (rn->count == 0) { rn->head = NULL; rn->tail = NULL; } @@ -455,172 +404,129 @@ snmp_search_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru ext_level = 0; LWIP_DEBUGF(SNMP_MIB_DEBUG,("node==%p *ident==%"S32_F"\n",(const void*)node,*ident)); - while (node != NULL) - { + while (node != NULL) { node_type = node->node_type; - if (node_type == MIB_NODE_AR) - { + if (node_type == MIB_NODE_AR) { const struct mib_array_node *an; u16_t i; - if (ident_len > 0) - { + if (ident_len > 0) { /* array node (internal ROM or RAM, fixed length) */ an = (const struct mib_array_node*)(const void*)node; i = 0; - while ((i < an->maxlength) && (an->entries[i].objid != *ident)) - { + while ((i < an->maxlength) && (an->entries[i].objid != *ident)) { i++; } - if (i < an->maxlength) - { + if (i < an->maxlength) { /* found it, if available proceed to child, otherwise inspect leaf */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("an->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,an->entries[i].objid,*ident)); - if (an->entries[i].nptr == NULL) - { + if (an->entries[i].nptr == NULL) { /* a scalar leaf OR table, inspect remaining instance number / table index */ np->ident_len = ident_len; np->ident = ident; return &an->node; - } - else - { + } else { /* follow next child pointer */ ident++; ident_len--; node = an->entries[i].nptr; } - } - else - { + } else { /* search failed, identifier mismatch (nosuchname) */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("an search failed *ident==%"S32_F"\n",*ident)); return NULL; } - } - else - { + } else { /* search failed, short object identifier (nosuchname) */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("an search failed, short object identifier\n")); return NULL; } - } - else if(node_type == MIB_NODE_LR) - { + } else if(node_type == MIB_NODE_LR) { const struct mib_list_rootnode *lrn; struct mib_list_node *ln; - if (ident_len > 0) - { + if (ident_len > 0) { /* list root node (internal 'RAM', variable length) */ lrn = (const struct mib_list_rootnode*)(const void*)node; ln = lrn->head; /* iterate over list, head to tail */ - while ((ln != NULL) && (ln->objid != *ident)) - { + while ((ln != NULL) && (ln->objid != *ident)) { ln = ln->next; } - if (ln != NULL) - { + if (ln != NULL) { /* found it, proceed to child */; LWIP_DEBUGF(SNMP_MIB_DEBUG,("ln->objid==%"S32_F" *ident==%"S32_F"\n",ln->objid,*ident)); - if (ln->nptr == NULL) - { + if (ln->nptr == NULL) { np->ident_len = ident_len; np->ident = ident; return &lrn->scalar.node; - } - else - { + } else { /* follow next child pointer */ ident_len--; ident++; node = ln->nptr; } - } - else - { + } else { /* search failed */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ln search failed *ident==%"S32_F"\n",*ident)); return NULL; } - } - else - { + } else { /* search failed, short object identifier (nosuchname) */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ln search failed, short object identifier\n")); return NULL; } - } - else if(node_type == MIB_NODE_EX) - { + } else if(node_type == MIB_NODE_EX) { const struct mib_external_node *en; u16_t i, len; - if (ident_len > 0) - { + if (ident_len > 0) { /* external node (addressing and access via functions) */ en = (const struct mib_external_node*)(const void*)node; i = 0; len = en->level_length(en->addr_inf,ext_level); - while ((i < len) && (en->ident_cmp(en->addr_inf,ext_level,i,*ident) != 0)) - { + while ((i < len) && (en->ident_cmp(en->addr_inf,ext_level,i,*ident) != 0)) { i++; } - if (i < len) - { + if (i < len) { s32_t debug_id; en->get_objid(en->addr_inf,ext_level,i,&debug_id); LWIP_DEBUGF(SNMP_MIB_DEBUG,("en->objid==%"S32_F" *ident==%"S32_F"\n",debug_id,*ident)); - if ((ext_level + 1) == en->tree_levels) - { + if ((ext_level + 1) == en->tree_levels) { np->ident_len = ident_len; np->ident = ident; return &en->node; - } - else - { + } else { /* found it, proceed to child */ ident_len--; ident++; ext_level++; } - } - else - { + } else { /* search failed */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("en search failed *ident==%"S32_F"\n",*ident)); return NULL; } - } - else - { + } else { /* search failed, short object identifier (nosuchname) */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("en search failed, short object identifier\n")); return NULL; } - } - else if (node_type == MIB_NODE_SC) - { + } else if (node_type == MIB_NODE_SC) { /* scalar node */ - if ((ident_len == 1) && (*ident == 0)) - { + if ((ident_len == 1) && (*ident == 0)) { np->ident_len = ident_len; np->ident = ident; return node; - } - else - { + } else { /* search failed, short object identifier (nosuchname) */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed, invalid object identifier length\n")); return NULL; } - } - else - { + } else { /* unknown node_type */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed node_type %"U16_F" unkown\n",(u16_t)node_type)); return NULL; @@ -640,33 +546,24 @@ empty_table(const struct mib_node *node) u8_t node_type; u8_t empty = 0; - if (node != NULL) - { + if (node != NULL) { node_type = node->node_type; - if (node_type == MIB_NODE_LR) - { + if (node_type == MIB_NODE_LR) { const struct mib_list_rootnode *lrn; lrn = (const struct mib_list_rootnode*)(const void*)node; - if ((lrn->count == 0) || (lrn->head == NULL)) - { + if ((lrn->count == 0) || (lrn->head == NULL)) { empty = 1; } - } - else if (node_type == MIB_NODE_AR) - { + } else if (node_type == MIB_NODE_AR) { const struct mib_array_node *an; an = (const struct mib_array_node*)(const void*)node; - if ((an->maxlength == 0) || (an->entries == NULL)) - { + if ((an->maxlength == 0) || (an->entries == NULL)) { empty = 1; } - } - else if (node_type == MIB_NODE_EX) - { + } else if (node_type == MIB_NODE_EX) { const struct mib_external_node *en; en = (const struct mib_external_node*)(const void*)node; - if (en->tree_levels == 0) - { + if (en->tree_levels == 0) { empty = 1; } } @@ -685,368 +582,274 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru ext_level = 0; /* reset node stack */ node_stack_cnt = 0; - while (node != NULL) - { + while (node != NULL) { climb_tree = 0; node_type = node->node_type; - if (node_type == MIB_NODE_AR) - { + if (node_type == MIB_NODE_AR) { const struct mib_array_node *an; u16_t i; /* array node (internal ROM or RAM, fixed length) */ an = (const struct mib_array_node*)(const void*)node; - if (ident_len > 0) - { + if (ident_len > 0) { i = 0; - while ((i < an->maxlength) && (an->entries[i].objid < *ident)) - { + while ((i < an->maxlength) && (an->entries[i].objid < *ident)) { i++; } - if (i < an->maxlength) - { + if (i < an->maxlength) { LWIP_DEBUGF(SNMP_MIB_DEBUG,("an->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,an->entries[i].objid,*ident)); /* add identifier to oidret */ oidret->id[oidret->len] = an->entries[i].objid; (oidret->len)++; - if (an->entries[i].nptr == NULL) - { + if (an->entries[i].nptr == NULL) { LWIP_DEBUGF(SNMP_MIB_DEBUG,("leaf node\n")); /* leaf node (e.g. in a fixed size table) */ - if (an->entries[i].objid > *ident) - { + if (an->entries[i].objid > *ident) { return &an->node; - } - else if ((i + 1) < an->maxlength) - { + } else if ((i + 1) < an->maxlength) { /* an->entries[i].objid == *ident */ (oidret->len)--; oidret->id[oidret->len] = an->entries[i + 1].objid; (oidret->len)++; return &an->node; - } - else - { + } else { /* (i + 1) == an->maxlength */ (oidret->len)--; climb_tree = 1; } - } - else - { + } else { u16_t j; LWIP_DEBUGF(SNMP_MIB_DEBUG,("non-leaf node\n")); /* non-leaf, store right child ptr and id */ LWIP_ASSERT("i < 0xff", i < 0xff); j = i + 1; - while ((j < an->maxlength) && (empty_table(an->entries[j].nptr))) - { + while ((j < an->maxlength) && (empty_table(an->entries[j].nptr))) { j++; } - if (j < an->maxlength) - { + if (j < an->maxlength) { struct nse cur_node; cur_node.r_ptr = an->entries[j].nptr; cur_node.r_id = an->entries[j].objid; cur_node.r_nl = 0; push_node(&cur_node); - } - else - { + } else { push_node(&node_null); } - if (an->entries[i].objid == *ident) - { + if (an->entries[i].objid == *ident) { ident_len--; ident++; - } - else - { + } else { /* an->entries[i].objid < *ident */ ident_len = 0; } /* follow next child pointer */ node = an->entries[i].nptr; } - } - else - { + } else { /* i == an->maxlength */ climb_tree = 1; } - } - else - { + } else { u16_t j; /* ident_len == 0, complete with leftmost '.thing' */ j = 0; - while ((j < an->maxlength) && empty_table(an->entries[j].nptr)) - { + while ((j < an->maxlength) && empty_table(an->entries[j].nptr)) { j++; } - if (j < an->maxlength) - { + if (j < an->maxlength) { LWIP_DEBUGF(SNMP_MIB_DEBUG,("left an->entries[j].objid==%"S32_F"\n",an->entries[j].objid)); oidret->id[oidret->len] = an->entries[j].objid; (oidret->len)++; - if (an->entries[j].nptr == NULL) - { + if (an->entries[j].nptr == NULL) { /* leaf node */ return &an->node; - } - else - { + } else { /* no leaf, continue */ node = an->entries[j].nptr; } - } - else - { + } else { /* j == an->maxlength */ climb_tree = 1; } } - } - else if(node_type == MIB_NODE_LR) - { + } else if(node_type == MIB_NODE_LR) { const struct mib_list_rootnode *lrn; struct mib_list_node *ln; /* list root node (internal 'RAM', variable length) */ lrn = (const struct mib_list_rootnode*)(const void*)node; - if (ident_len > 0) - { + if (ident_len > 0) { ln = lrn->head; /* iterate over list, head to tail */ - while ((ln != NULL) && (ln->objid < *ident)) - { + while ((ln != NULL) && (ln->objid < *ident)) { ln = ln->next; } - if (ln != NULL) - { + if (ln != NULL) { LWIP_DEBUGF(SNMP_MIB_DEBUG,("ln->objid==%"S32_F" *ident==%"S32_F"\n",ln->objid,*ident)); oidret->id[oidret->len] = ln->objid; (oidret->len)++; - if (ln->nptr == NULL) - { + if (ln->nptr == NULL) { /* leaf node */ - if (ln->objid > *ident) - { + if (ln->objid > *ident) { return &lrn->scalar.node; - } - else if (ln->next != NULL) - { + } else if (ln->next != NULL) { /* ln->objid == *ident */ (oidret->len)--; oidret->id[oidret->len] = ln->next->objid; (oidret->len)++; return &lrn->scalar.node; - } - else - { + } else { /* ln->next == NULL */ (oidret->len)--; climb_tree = 1; } - } - else - { + } else { struct mib_list_node *jn; /* non-leaf, store right child ptr and id */ jn = ln->next; - while ((jn != NULL) && empty_table(jn->nptr)) - { + while ((jn != NULL) && empty_table(jn->nptr)) { jn = jn->next; } - if (jn != NULL) - { + if (jn != NULL) { struct nse cur_node; cur_node.r_ptr = jn->nptr; cur_node.r_id = jn->objid; cur_node.r_nl = 0; push_node(&cur_node); - } - else - { + } else { push_node(&node_null); } - if (ln->objid == *ident) - { + if (ln->objid == *ident) { ident_len--; ident++; - } - else - { + } else { /* ln->objid < *ident */ ident_len = 0; } /* follow next child pointer */ node = ln->nptr; } - - } - else - { + } else { /* ln == NULL */ climb_tree = 1; } - } - else - { + } else { struct mib_list_node *jn; /* ident_len == 0, complete with leftmost '.thing' */ jn = lrn->head; - while ((jn != NULL) && empty_table(jn->nptr)) - { + while ((jn != NULL) && empty_table(jn->nptr)) { jn = jn->next; } - if (jn != NULL) - { + if (jn != NULL) { LWIP_DEBUGF(SNMP_MIB_DEBUG,("left jn->objid==%"S32_F"\n",jn->objid)); oidret->id[oidret->len] = jn->objid; (oidret->len)++; - if (jn->nptr == NULL) - { + if (jn->nptr == NULL) { /* leaf node */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("jn->nptr == NULL\n")); return &lrn->scalar.node; - } - else - { + } else { /* no leaf, continue */ node = jn->nptr; } - } - else - { + } else { /* jn == NULL */ climb_tree = 1; } } - } - else if(node_type == MIB_NODE_EX) - { + } else if(node_type == MIB_NODE_EX) { const struct mib_external_node *en; s32_t ex_id; /* external node (addressing and access via functions) */ en = (const struct mib_external_node*)(const void*)node; - if (ident_len > 0) - { + if (ident_len > 0) { u16_t i, len; i = 0; len = en->level_length(en->addr_inf,ext_level); - while ((i < len) && (en->ident_cmp(en->addr_inf,ext_level,i,*ident) < 0)) - { + while ((i < len) && (en->ident_cmp(en->addr_inf,ext_level,i,*ident) < 0)) { i++; } - if (i < len) - { + if (i < len) { /* add identifier to oidret */ en->get_objid(en->addr_inf,ext_level,i,&ex_id); LWIP_DEBUGF(SNMP_MIB_DEBUG,("en->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,ex_id,*ident)); oidret->id[oidret->len] = ex_id; (oidret->len)++; - if ((ext_level + 1) == en->tree_levels) - { + if ((ext_level + 1) == en->tree_levels) { LWIP_DEBUGF(SNMP_MIB_DEBUG,("leaf node\n")); /* leaf node */ - if (ex_id > *ident) - { + if (ex_id > *ident) { return &en->node; - } - else if ((i + 1) < len) - { + } else if ((i + 1) < len) { /* ex_id == *ident */ en->get_objid(en->addr_inf,ext_level,i + 1,&ex_id); (oidret->len)--; oidret->id[oidret->len] = ex_id; (oidret->len)++; return &en->node; - } - else - { + } else { /* (i + 1) == len */ (oidret->len)--; climb_tree = 1; } - } - else - { + } else { u16_t j; LWIP_DEBUGF(SNMP_MIB_DEBUG,("non-leaf node\n")); /* non-leaf, store right child ptr and id */ LWIP_ASSERT("i < 0xff", i < 0xff); j = i + 1; - if (j < len) - { + if (j < len) { struct nse cur_node; /* right node is the current external node */ cur_node.r_ptr = node; en->get_objid(en->addr_inf,ext_level,j,&cur_node.r_id); cur_node.r_nl = ext_level + 1; push_node(&cur_node); - } - else - { + } else { push_node(&node_null); } - if (en->ident_cmp(en->addr_inf,ext_level,i,*ident) == 0) - { + if (en->ident_cmp(en->addr_inf,ext_level,i,*ident) == 0) { ident_len--; ident++; - } - else - { + } else { /* external id < *ident */ ident_len = 0; } /* proceed to child */ ext_level++; } - } - else - { + } else { /* i == len (en->level_len()) */ climb_tree = 1; } - } - else - { + } else { /* ident_len == 0, complete with leftmost '.thing' */ en->get_objid(en->addr_inf,ext_level,0,&ex_id); LWIP_DEBUGF(SNMP_MIB_DEBUG,("left en->objid==%"S32_F"\n",ex_id)); oidret->id[oidret->len] = ex_id; (oidret->len)++; - if ((ext_level + 1) == en->tree_levels) - { + if ((ext_level + 1) == en->tree_levels) { /* leaf node */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("(ext_level + 1) == en->tree_levels\n")); return &en->node; - } - else - { + } else { /* no leaf, proceed to child */ ext_level++; } } - } - else if(node_type == MIB_NODE_SC) - { + } else if(node_type == MIB_NODE_SC) { /* scalar node */ - if (ident_len > 0) - { + if (ident_len > 0) { /* at .0 */ climb_tree = 1; - } - else - { + } else { /* ident_len == 0, complete object identifier */ oidret->id[oidret->len] = 0; (oidret->len)++; @@ -1054,39 +857,32 @@ snmp_expand_tree(const struct mib_node *node, u8_t ident_len, s32_t *ident, stru LWIP_DEBUGF(SNMP_MIB_DEBUG,("completed scalar leaf\n")); return node; } - } - else - { + } else { /* unknown/unhandled node_type */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("expand failed node_type %"U16_F" unkown\n",(u16_t)node_type)); return NULL; } - if (climb_tree) - { + if (climb_tree) { struct nse child; /* find right child ptr */ child.r_ptr = NULL; child.r_id = 0; child.r_nl = 0; - while ((node_stack_cnt > 0) && (child.r_ptr == NULL)) - { + while ((node_stack_cnt > 0) && (child.r_ptr == NULL)) { pop_node(&child); /* trim returned oid */ (oidret->len)--; } - if (child.r_ptr != NULL) - { + if (child.r_ptr != NULL) { /* incoming ident is useless beyond this point */ ident_len = 0; oidret->id[oidret->len] = child.r_id; oidret->len++; node = child.r_ptr; ext_level = child.r_nl; - } - else - { + } else { /* tree ends here ... */ LWIP_DEBUGF(SNMP_MIB_DEBUG,("expand failed, tree ends here\n")); return NULL; @@ -1110,12 +906,9 @@ snmp_iso_prefix_tst(u8_t ident_len, s32_t *ident) { if ((ident_len > 3) && (ident[0] == 1) && (ident[1] == 3) && - (ident[2] == 6) && (ident[3] == 1)) - { + (ident[2] == 6) && (ident[3] == 1)) { return 1; - } - else - { + } else { return 0; } } @@ -1142,25 +935,20 @@ snmp_iso_prefix_expand(u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret) prefix_ptr = &prefix[0]; ret_ptr = &oidret->id[0]; ident_len = ((ident_len < 4)?ident_len:4); - while ((i < ident_len) && ((*ident) <= (*prefix_ptr))) - { + while ((i < ident_len) && ((*ident) <= (*prefix_ptr))) { *ret_ptr++ = *prefix_ptr++; ident++; i++; } - if (i == ident_len) - { + if (i == ident_len) { /* match, complete missing bits */ - while (i < 4) - { + while (i < 4) { *ret_ptr++ = *prefix_ptr++; i++; } oidret->len = i; return 1; - } - else - { + } else { /* i != ident_len */ return 0; } diff --git a/src/core/snmp/msg_in.c b/src/core/snmp/msg_in.c index cb29e8d0..38606652 100644 --- a/src/core/snmp/msg_in.c +++ b/src/core/snmp/msg_in.c @@ -80,14 +80,12 @@ snmp_init(void) u8_t i; snmp1_pcb = udp_new(); - if (snmp1_pcb != NULL) - { + if (snmp1_pcb != NULL) { udp_recv(snmp1_pcb, snmp_recv, (void *)SNMP_IN_PORT); udp_bind(snmp1_pcb, IP_ADDR_ANY, SNMP_IN_PORT); } msg_ps = &msg_input_list[0]; - for (i=0; istate = SNMP_MSG_EMPTY; msg_ps->error_index = 0; msg_ps->error_status = SNMP_ES_NOERROR; @@ -189,7 +187,7 @@ snmp_error_response(struct snmp_msg_pstat *msg_ps, u8_t error) int v; struct snmp_varbind *vbi = msg_ps->invb.head; struct snmp_varbind *vbo = msg_ps->outvb.head; - for (v=0; vvb_idx; v++) { + for (v = 0; v < msg_ps->vb_idx; v++) { if (vbi->ident != NULL) { /* free previously allocated value before overwriting the pointer */ memp_free(MEMP_SNMP_VALUE, vbi->ident); @@ -222,12 +220,9 @@ snmp_ok_response(struct snmp_msg_pstat *msg_ps) err_t err_ret; err_ret = snmp_send_response(msg_ps); - if (err_ret == ERR_MEM) - { + if (err_ret == ERR_MEM) { /* serious memory problem, can't return tooBig */ - } - else - { + } else { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_msg_event = %"S32_F"\n",msg_ps->error_status)); } /* free varbinds (if available) */ @@ -247,8 +242,7 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_msg_get_event: msg_ps->state==%"U16_F"\n",(u16_t)msg_ps->state)); - if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF) - { + if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF) { const struct mib_external_node *en; struct snmp_name_ptr np; @@ -258,20 +252,15 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) /* translate answer into a known lifeform */ en->get_object_def_a(request_id, np.ident_len, np.ident, &msg_ps->ext_object_def); - if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE) - { + if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE) { msg_ps->state = SNMP_MSG_EXTERNAL_GET_VALUE; en->get_value_q(request_id, &msg_ps->ext_object_def); - } - else - { + } else { en->get_object_def_pc(request_id, np.ident_len, np.ident); /* search failed, object id points to unknown object (nosuchname) */ snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME); } - } - else if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_VALUE) - { + } else if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_VALUE) { const struct mib_external_node *en; struct snmp_varbind *vb; @@ -280,8 +269,7 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) /* allocate output varbind */ vb = (struct snmp_varbind *)memp_malloc(MEMP_SNMP_VARBIND); - if (vb != NULL) - { + if (vb != NULL) { vb->next = NULL; vb->prev = NULL; @@ -295,8 +283,7 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) vb->value_type = msg_ps->ext_object_def.asn_type; vb->value = memp_malloc(MEMP_SNMP_VALUE); - if (vb->value != NULL) - { + if (vb->value != NULL) { vb->value_len = en->get_value_a(request_id, &msg_ps->ext_object_def, vb->value); LWIP_ASSERT("SNMP_MAX_VALUE_SIZE is configured too low", vb->value_len <= SNMP_MAX_VALUE_SIZE); if(vb->value_len == 0) @@ -308,9 +295,7 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) /* search again (if vb_idx < msg_ps->invb.count) */ msg_ps->state = SNMP_MSG_SEARCH_OBJ; msg_ps->vb_idx += 1; - } - else - { + } else { en->get_value_pc(request_id, &msg_ps->ext_object_def); LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_msg_event: no variable space\n")); msg_ps->vb_ptr->ident = vb->ident; @@ -318,9 +303,7 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) memp_free(MEMP_SNMP_VARBIND, vb); snmp_error_response(msg_ps,SNMP_ES_TOOBIG); } - } - else - { + } else { en->get_value_pc(request_id, &msg_ps->ext_object_def); LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_msg_event: no outvb space\n")); snmp_error_response(msg_ps,SNMP_ES_TOOBIG); @@ -328,28 +311,21 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) } while ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) && - (msg_ps->vb_idx < msg_ps->invb.count)) - { + (msg_ps->vb_idx < msg_ps->invb.count)) { const struct mib_node *mn; struct snmp_name_ptr np; - if (msg_ps->vb_idx == 0) - { + if (msg_ps->vb_idx == 0) { msg_ps->vb_ptr = msg_ps->invb.head; - } - else - { + } else { msg_ps->vb_ptr = msg_ps->vb_ptr->next; } /** test object identifier for .iso.org.dod.internet prefix */ - if (snmp_iso_prefix_tst(msg_ps->vb_ptr->ident_len, msg_ps->vb_ptr->ident)) - { + if (snmp_iso_prefix_tst(msg_ps->vb_ptr->ident_len, msg_ps->vb_ptr->ident)) { mn = snmp_search_tree(&internet.node, msg_ps->vb_ptr->ident_len - 4, msg_ps->vb_ptr->ident + 4, &np); - if (mn != NULL) - { - if (mn->node_type == MIB_NODE_EX) - { + if (mn != NULL) { + if (mn->node_type == MIB_NODE_EX) { /* external object */ const struct mib_external_node *en = (const struct mib_external_node*)(const void*)mn; @@ -359,29 +335,23 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) msg_ps->ext_name_ptr = np; en->get_object_def_q(en->addr_inf, request_id, np.ident_len, np.ident); - } - else if((mn->node_type == MIB_NODE_SC) || (mn->node_type == MIB_NODE_LR)) - { + } else if((mn->node_type == MIB_NODE_SC) || (mn->node_type == MIB_NODE_LR)) { /* internal object */ struct obj_def object_def; const struct mib_scalar_node *msn = (const struct mib_scalar_node*)(const void*)mn; msg_ps->state = SNMP_MSG_INTERNAL_GET_OBJDEF; msn->get_object_def(np.ident_len, np.ident, &object_def); - if (object_def.instance == MIB_OBJECT_NONE) - { + if (object_def.instance == MIB_OBJECT_NONE) { /* search failed, object id points to unknown object (nosuchname) */ mn = NULL; - } - else - { + } else { struct snmp_varbind *vb; msg_ps->state = SNMP_MSG_INTERNAL_GET_VALUE; /* allocate output varbind */ vb = (struct snmp_varbind *)memp_malloc(MEMP_SNMP_VARBIND); - if (vb != NULL) - { + if (vb != NULL) { vb->next = NULL; vb->prev = NULL; @@ -395,21 +365,17 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) vb->value_type = object_def.asn_type; vb->value = memp_malloc(MEMP_SNMP_VALUE); - if (vb->value != NULL) - { + if (vb->value != NULL) { vb->value_len = msn->get_value(&object_def, vb->value); LWIP_ASSERT("SNMP_MAX_OCTET_STRING_LEN is configured too low", vb->value_len <= SNMP_MAX_VALUE_SIZE); - if(vb->value_len == 0) - { + if(vb->value_len == 0) { memp_free(MEMP_SNMP_VALUE, vb->value); vb->value = NULL; } snmp_varbind_tail_add(&msg_ps->outvb, vb); msg_ps->state = SNMP_MSG_SEARCH_OBJ; msg_ps->vb_idx += 1; - } - else - { + } else { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_msg_event: couldn't allocate variable space\n")); msg_ps->vb_ptr->ident = vb->ident; msg_ps->vb_ptr->ident_len = vb->ident_len; @@ -418,29 +384,23 @@ snmp_msg_get_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) memp_free(MEMP_SNMP_VARBIND, vb); snmp_error_response(msg_ps,SNMP_ES_TOOBIG); } - } - else - { + } else { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_msg_event: couldn't allocate outvb space\n")); snmp_error_response(msg_ps,SNMP_ES_TOOBIG); } } } } - } - else - { + } else { mn = NULL; } - if (mn == NULL) - { + if (mn == NULL) { /* mn == NULL, noSuchName */ snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME); } } if ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) && - (msg_ps->vb_idx == msg_ps->invb.count)) - { + (msg_ps->vb_idx == msg_ps->invb.count)) { snmp_ok_response(msg_ps); } } @@ -456,8 +416,7 @@ snmp_msg_getnext_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_msg_getnext_event: msg_ps->state==%"U16_F"\n",(u16_t)msg_ps->state)); - if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF) - { + if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF) { const struct mib_external_node *en; /* get_object_def() answer*/ @@ -465,20 +424,15 @@ snmp_msg_getnext_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) /* translate answer into a known lifeform */ en->get_object_def_a(request_id, 1, &msg_ps->ext_oid.id[msg_ps->ext_oid.len - 1], &msg_ps->ext_object_def); - if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE) - { + if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE) { msg_ps->state = SNMP_MSG_EXTERNAL_GET_VALUE; en->get_value_q(request_id, &msg_ps->ext_object_def); - } - else - { + } else { en->get_object_def_pc(request_id, 1, &msg_ps->ext_oid.id[msg_ps->ext_oid.len - 1]); /* search failed, object id points to unknown object (nosuchname) */ snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME); } - } - else if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_VALUE) - { + } else if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_VALUE) { const struct mib_external_node *en; struct snmp_varbind *vb; @@ -488,15 +442,12 @@ snmp_msg_getnext_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) vb = snmp_varbind_alloc(&msg_ps->ext_oid, msg_ps->ext_object_def.asn_type, SNMP_MAX_VALUE_SIZE); - if (vb != NULL) - { + if (vb != NULL) { vb->value_len = en->get_value_a(request_id, &msg_ps->ext_object_def, vb->value); snmp_varbind_tail_add(&msg_ps->outvb, vb); msg_ps->state = SNMP_MSG_SEARCH_OBJ; msg_ps->vb_idx += 1; - } - else - { + } else { en->get_value_pc(request_id, &msg_ps->ext_object_def); LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_msg_getnext_event: couldn't allocate outvb space\n")); snmp_error_response(msg_ps,SNMP_ES_TOOBIG); @@ -504,42 +455,30 @@ snmp_msg_getnext_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) } while ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) && - (msg_ps->vb_idx < msg_ps->invb.count)) - { + (msg_ps->vb_idx < msg_ps->invb.count)) { const struct mib_node *mn; struct snmp_obj_id oid; - if (msg_ps->vb_idx == 0) - { + if (msg_ps->vb_idx == 0) { msg_ps->vb_ptr = msg_ps->invb.head; - } - else - { + } else { msg_ps->vb_ptr = msg_ps->vb_ptr->next; } - if (snmp_iso_prefix_expand(msg_ps->vb_ptr->ident_len, msg_ps->vb_ptr->ident, &oid)) - { - if (msg_ps->vb_ptr->ident_len > 3) - { + if (snmp_iso_prefix_expand(msg_ps->vb_ptr->ident_len, msg_ps->vb_ptr->ident, &oid)) { + if (msg_ps->vb_ptr->ident_len > 3) { /* can offset ident_len and ident */ mn = snmp_expand_tree((const struct mib_node*)&internet, msg_ps->vb_ptr->ident_len - 4, msg_ps->vb_ptr->ident + 4, &oid); - } - else - { + } else { /* can't offset ident_len -4, ident + 4 */ mn = snmp_expand_tree((const struct mib_node*)&internet, 0, NULL, &oid); } - } - else - { + } else { mn = NULL; } - if (mn != NULL) - { - if (mn->node_type == MIB_NODE_EX) - { + if (mn != NULL) { + if (mn->node_type == MIB_NODE_EX) { /* external object */ const struct mib_external_node *en = (const struct mib_external_node*)(const void*)mn; @@ -549,9 +488,7 @@ snmp_msg_getnext_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) msg_ps->ext_oid = oid; en->get_object_def_q(en->addr_inf, request_id, 1, &oid.id[oid.len - 1]); - } - else if((mn->node_type == MIB_NODE_SC) || (mn->node_type == MIB_NODE_LR)) - { + } else if((mn->node_type == MIB_NODE_SC) || (mn->node_type == MIB_NODE_LR)) { /* internal object */ struct obj_def object_def; struct snmp_varbind *vb; @@ -561,34 +498,27 @@ snmp_msg_getnext_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) msn->get_object_def(1, &oid.id[oid.len - 1], &object_def); vb = snmp_varbind_alloc(&oid, object_def.asn_type, SNMP_MAX_VALUE_SIZE); - if (vb != NULL) - { + if (vb != NULL) { msg_ps->state = SNMP_MSG_INTERNAL_GET_VALUE; vb->value_len = msn->get_value(&object_def, vb->value); snmp_varbind_tail_add(&msg_ps->outvb, vb); msg_ps->state = SNMP_MSG_SEARCH_OBJ; msg_ps->vb_idx += 1; - } - else - { + } else { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_recv couldn't allocate outvb space\n")); snmp_error_response(msg_ps,SNMP_ES_TOOBIG); } - } - else - { + } else { mn = NULL; } } - if (mn == NULL) - { + if (mn == NULL) { /* mn == NULL, noSuchName */ snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME); } } if ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) && - (msg_ps->vb_idx == msg_ps->invb.count)) - { + (msg_ps->vb_idx == msg_ps->invb.count)) { snmp_ok_response(msg_ps); } } @@ -604,8 +534,7 @@ snmp_msg_set_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_msg_set_event: msg_ps->state==%"U16_F"\n",(u16_t)msg_ps->state)); - if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF) - { + if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF) { const struct mib_external_node *en; struct snmp_name_ptr np; @@ -615,50 +544,37 @@ snmp_msg_set_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) /* translate answer into a known lifeform */ en->get_object_def_a(request_id, np.ident_len, np.ident, &msg_ps->ext_object_def); - if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE) - { + if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE) { msg_ps->state = SNMP_MSG_EXTERNAL_SET_TEST; en->set_test_q(request_id, &msg_ps->ext_object_def); - } - else - { + } else { en->get_object_def_pc(request_id, np.ident_len, np.ident); /* search failed, object id points to unknown object (nosuchname) */ snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME); } - } - else if (msg_ps->state == SNMP_MSG_EXTERNAL_SET_TEST) - { + } else if (msg_ps->state == SNMP_MSG_EXTERNAL_SET_TEST) { const struct mib_external_node *en; /* set_test() answer*/ en = msg_ps->ext_mib_node; - if (msg_ps->ext_object_def.access & MIB_ACCESS_WRITE) - { + if (msg_ps->ext_object_def.access & MIB_ACCESS_WRITE) { if ((msg_ps->ext_object_def.asn_type == msg_ps->vb_ptr->value_type) && (en->set_test_a(request_id,&msg_ps->ext_object_def, - msg_ps->vb_ptr->value_len,msg_ps->vb_ptr->value) != 0)) - { + msg_ps->vb_ptr->value_len,msg_ps->vb_ptr->value) != 0)) { msg_ps->state = SNMP_MSG_SEARCH_OBJ; msg_ps->vb_idx += 1; - } - else - { + } else { en->set_test_pc(request_id,&msg_ps->ext_object_def); /* bad value */ snmp_error_response(msg_ps,SNMP_ES_BADVALUE); } - } - else - { + } else { en->set_test_pc(request_id,&msg_ps->ext_object_def); /* object not available for set */ snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME); } - } - else if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF_S) - { + } else if (msg_ps->state == SNMP_MSG_EXTERNAL_GET_OBJDEF_S) { const struct mib_external_node *en; struct snmp_name_ptr np; @@ -668,21 +584,16 @@ snmp_msg_set_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) /* translate answer into a known lifeform */ en->get_object_def_a(request_id, np.ident_len, np.ident, &msg_ps->ext_object_def); - if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE) - { + if (msg_ps->ext_object_def.instance != MIB_OBJECT_NONE) { msg_ps->state = SNMP_MSG_EXTERNAL_SET_VALUE; en->set_value_q(request_id, &msg_ps->ext_object_def, msg_ps->vb_ptr->value_len,msg_ps->vb_ptr->value); - } - else - { + } else { en->get_object_def_pc(request_id, np.ident_len, np.ident); /* set_value failed, object has disappeared for some odd reason?? */ snmp_error_response(msg_ps,SNMP_ES_GENERROR); } - } - else if (msg_ps->state == SNMP_MSG_EXTERNAL_SET_VALUE) - { + } else if (msg_ps->state == SNMP_MSG_EXTERNAL_SET_VALUE) { const struct mib_external_node *en; /** set_value_a() */ @@ -697,28 +608,21 @@ snmp_msg_set_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) /* test all values before setting */ while ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) && - (msg_ps->vb_idx < msg_ps->invb.count)) - { + (msg_ps->vb_idx < msg_ps->invb.count)) { const struct mib_node *mn; struct snmp_name_ptr np; - if (msg_ps->vb_idx == 0) - { + if (msg_ps->vb_idx == 0) { msg_ps->vb_ptr = msg_ps->invb.head; - } - else - { + } else { msg_ps->vb_ptr = msg_ps->vb_ptr->next; } /** test object identifier for .iso.org.dod.internet prefix */ - if (snmp_iso_prefix_tst(msg_ps->vb_ptr->ident_len, msg_ps->vb_ptr->ident)) - { + if (snmp_iso_prefix_tst(msg_ps->vb_ptr->ident_len, msg_ps->vb_ptr->ident)) { mn = snmp_search_tree((const struct mib_node*)&internet, msg_ps->vb_ptr->ident_len - 4, msg_ps->vb_ptr->ident + 4, &np); - if (mn != NULL) - { - if (mn->node_type == MIB_NODE_EX) - { + if (mn != NULL) { + if (mn->node_type == MIB_NODE_EX) { /* external object */ const struct mib_external_node *en = (const struct mib_external_node*)(const void*)mn; @@ -728,82 +632,61 @@ snmp_msg_set_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) msg_ps->ext_name_ptr = np; en->get_object_def_q(en->addr_inf, request_id, np.ident_len, np.ident); - } - else if((mn->node_type == MIB_NODE_SC) || (mn->node_type == MIB_NODE_LR)) - { + } else if((mn->node_type == MIB_NODE_SC) || (mn->node_type == MIB_NODE_LR)) { /* internal object */ struct obj_def object_def; const struct mib_scalar_node *msn = (const struct mib_scalar_node*)(const void*)mn; msg_ps->state = SNMP_MSG_INTERNAL_GET_OBJDEF; msn->get_object_def(np.ident_len, np.ident, &object_def); - if (object_def.instance == MIB_OBJECT_NONE) - { + if (object_def.instance == MIB_OBJECT_NONE) { /* search failed, object id points to unknown object (nosuchname) */ mn = NULL; - } - else - { + } else { msg_ps->state = SNMP_MSG_INTERNAL_SET_TEST; - if (object_def.access & MIB_ACCESS_WRITE) - { + if (object_def.access & MIB_ACCESS_WRITE) { if ((object_def.asn_type == msg_ps->vb_ptr->value_type) && - (msn->set_test(&object_def,msg_ps->vb_ptr->value_len,msg_ps->vb_ptr->value) != 0)) - { + (msn->set_test(&object_def,msg_ps->vb_ptr->value_len,msg_ps->vb_ptr->value) != 0)) { msg_ps->state = SNMP_MSG_SEARCH_OBJ; msg_ps->vb_idx += 1; - } - else - { + } else { /* bad value */ snmp_error_response(msg_ps,SNMP_ES_BADVALUE); } - } - else - { + } else { /* object not available for set */ snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME); } } - } - else - { + } else { mn = NULL; } } - } - else - { + } else { mn = NULL; } - if (mn == NULL) - { + if (mn == NULL) { /* mn == NULL, noSuchName */ snmp_error_response(msg_ps,SNMP_ES_NOSUCHNAME); } } if ((msg_ps->state == SNMP_MSG_SEARCH_OBJ) && - (msg_ps->vb_idx == msg_ps->invb.count)) - { + (msg_ps->vb_idx == msg_ps->invb.count)) { msg_ps->vb_idx = 0; msg_ps->state = SNMP_MSG_INTERNAL_SET_VALUE; } /* set all values "atomically" (be as "atomic" as possible) */ while ((msg_ps->state == SNMP_MSG_INTERNAL_SET_VALUE) && - (msg_ps->vb_idx < msg_ps->invb.count)) - { + (msg_ps->vb_idx < msg_ps->invb.count)) { const struct mib_node *mn; struct snmp_name_ptr np; - if (msg_ps->vb_idx == 0) - { + if (msg_ps->vb_idx == 0) { msg_ps->vb_ptr = msg_ps->invb.head; - } - else - { + } else { msg_ps->vb_ptr = msg_ps->vb_ptr->next; } /* skip iso prefix test, was done previously while settesting() */ @@ -811,10 +694,8 @@ snmp_msg_set_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) msg_ps->vb_ptr->ident + 4, &np); /* check if object is still available (e.g. external hot-plug thingy present?) */ - if (mn != NULL) - { - if (mn->node_type == MIB_NODE_EX) - { + if (mn != NULL) { + if (mn->node_type == MIB_NODE_EX) { /* external object */ const struct mib_external_node *en = (const struct mib_external_node*)(const void*)mn; @@ -824,9 +705,7 @@ snmp_msg_set_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) msg_ps->ext_name_ptr = np; en->get_object_def_q(en->addr_inf, request_id, np.ident_len, np.ident); - } - else if((mn->node_type == MIB_NODE_SC) || (mn->node_type == MIB_NODE_LR)) - { + } else if((mn->node_type == MIB_NODE_SC) || (mn->node_type == MIB_NODE_LR)) { /* internal object */ struct obj_def object_def; const struct mib_scalar_node *msn = (const struct mib_scalar_node*)(const void*)mn; @@ -840,8 +719,7 @@ snmp_msg_set_event(u8_t request_id, struct snmp_msg_pstat *msg_ps) } } if ((msg_ps->state == SNMP_MSG_INTERNAL_SET_VALUE) && - (msg_ps->vb_idx == msg_ps->invb.count)) - { + (msg_ps->vb_idx == msg_ps->invb.count)) { /* simply echo the input if we can set it @todo do we need to return the actual value? e.g. if value is silently modified or behaves sticky? */ @@ -865,19 +743,13 @@ snmp_msg_event(u8_t request_id) { struct snmp_msg_pstat *msg_ps; - if (request_id < SNMP_CONCURRENT_REQUESTS) - { + if (request_id < SNMP_CONCURRENT_REQUESTS) { msg_ps = &msg_input_list[request_id]; - if (msg_ps->rt == SNMP_ASN1_PDU_GET_NEXT_REQ) - { + if (msg_ps->rt == SNMP_ASN1_PDU_GET_NEXT_REQ) { snmp_msg_getnext_event(request_id, msg_ps); - } - else if (msg_ps->rt == SNMP_ASN1_PDU_GET_REQ) - { + } else if (msg_ps->rt == SNMP_ASN1_PDU_GET_REQ) { snmp_msg_get_event(request_id, msg_ps); - } - else if(msg_ps->rt == SNMP_ASN1_PDU_SET_REQ) - { + } else if(msg_ps->rt == SNMP_ASN1_PDU_SET_REQ) { snmp_msg_set_event(request_id, msg_ps); } } @@ -901,13 +773,11 @@ snmp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, /* traverse input message process list, look for SNMP_MSG_EMPTY */ msg_ps = &msg_input_list[0]; req_idx = 0; - while ((req_idx < SNMP_CONCURRENT_REQUESTS) && (msg_ps->state != SNMP_MSG_EMPTY)) - { + while ((req_idx < SNMP_CONCURRENT_REQUESTS) && (msg_ps->state != SNMP_MSG_EMPTY)) { req_idx++; msg_ps++; } - if (req_idx == SNMP_CONCURRENT_REQUESTS) - { + if (req_idx == SNMP_CONCURRENT_REQUESTS) { /* exceeding number of concurrent requests */ pbuf_free(p); return; @@ -931,8 +801,7 @@ snmp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, (msg_ps->rt != SNMP_ASN1_PDU_GET_NEXT_REQ) && (msg_ps->rt != SNMP_ASN1_PDU_SET_REQ)) || ((msg_ps->error_status != SNMP_ES_NOERROR) || - (msg_ps->error_index != 0)) ) - { + (msg_ps->error_index != 0))) { /* header check failed drop request silently, do not return error! */ pbuf_free(p); LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_pdu_header_check() failed\n")); @@ -945,8 +814,7 @@ snmp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, err_ret = snmp_pdu_dec_varbindlist(p, varbind_ofs, &varbind_ofs, msg_ps); /* we've decoded the incoming message, release input msg now */ pbuf_free(p); - if ((err_ret != ERR_OK) || (msg_ps->invb.count == 0)) - { + if ((err_ret != ERR_OK) || (msg_ps->invb.count == 0)) { /* varbind-list decode failed, or varbind list empty. drop request silently, do not return error! (errors are only returned for a specific varbind failure) */ @@ -993,29 +861,25 @@ snmp_pdu_header_check(struct pbuf *p, u16_t ofs, u16_t pdu_len, u16_t *ofs_ret, derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); if ((derr != ERR_OK) || (pdu_len != (1 + len_octets + len)) || - (type != (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ))) - { + (type != (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ))) { mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } ofs += (1 + len_octets); snmp_asn1_dec_type(p, ofs, &type); derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); - if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG))) - { + if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG))) { /* can't decode or no integer (version) */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } derr = snmp_asn1_dec_s32t(p, ofs + 1 + len_octets, len, &version); - if (derr != ERR_OK) - { + if (derr != ERR_OK) { /* can't decode */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } - if (version != 0) - { + if (version != 0) { /* not version 1 */ mib2_inc_snmpinbadversions(); return ERR_ARG; @@ -1024,15 +888,13 @@ snmp_pdu_header_check(struct pbuf *p, u16_t ofs, u16_t pdu_len, u16_t *ofs_ret, ofs += (1 + len_octets + len); snmp_asn1_dec_type(p, ofs, &type); derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); - if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR))) - { + if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR))) { /* can't decode or no octet string (community) */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } derr = snmp_asn1_dec_raw(p, ofs + 1 + len_octets, len, SNMP_COMMUNITY_STR_LEN, m_stat->community); - if (derr != ERR_OK) - { + if (derr != ERR_OK) { mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } @@ -1043,11 +905,9 @@ snmp_pdu_header_check(struct pbuf *p, u16_t ofs, u16_t pdu_len, u16_t *ofs_ret, ofs += (1 + len_octets + len); snmp_asn1_dec_type(p, ofs, &type); #if SNMP_COMMUNITY_EXT - if (strncmp(snmp_community_write, (const char*)m_stat->community, SNMP_COMMUNITY_STR_LEN) != 0) - { + if (strncmp(snmp_community_write, (const char*)m_stat->community, SNMP_COMMUNITY_STR_LEN) != 0) { /* community does not match the write-access community, check if this is a SetRequest */ - if (type == (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_SET_REQ)) - { + if (type == (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_SET_REQ)) { /* wrong community for SetRequest PDU */ mib2_inc_snmpinbadcommunitynames(); snmp_authfail_trap(); @@ -1056,75 +916,68 @@ snmp_pdu_header_check(struct pbuf *p, u16_t ofs, u16_t pdu_len, u16_t *ofs_ret, #else /* SNMP_COMMUNITY_EXT */ { #endif /* SNMP_COMMUNITY_EXT */ - if (strncmp(snmp_community, (const char*)m_stat->community, SNMP_COMMUNITY_STR_LEN) != 0) - { + if (strncmp(snmp_community, (const char*)m_stat->community, SNMP_COMMUNITY_STR_LEN) != 0) { mib2_inc_snmpinbadcommunitynames(); snmp_authfail_trap(); return ERR_ARG; } } derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); - if (derr != ERR_OK) - { + if (derr != ERR_OK) { mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } - switch(type) - { - case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_REQ): - /* GetRequest PDU */ - mib2_inc_snmpingetrequests(); - derr = ERR_OK; - break; - case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_NEXT_REQ): - /* GetNextRequest PDU */ - mib2_inc_snmpingetnexts(); - derr = ERR_OK; - break; - case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_RESP): - /* GetResponse PDU */ - mib2_inc_snmpingetresponses(); - derr = ERR_ARG; - break; - case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_SET_REQ): - /* SetRequest PDU */ - mib2_inc_snmpinsetrequests(); - derr = ERR_OK; - break; - case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_TRAP): - /* Trap PDU */ - mib2_inc_snmpintraps(); - derr = ERR_ARG; - break; - default: - mib2_inc_snmpinasnparseerrs(); - derr = ERR_ARG; - break; + switch(type) { + case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_REQ): + /* GetRequest PDU */ + mib2_inc_snmpingetrequests(); + derr = ERR_OK; + break; + case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_NEXT_REQ): + /* GetNextRequest PDU */ + mib2_inc_snmpingetnexts(); + derr = ERR_OK; + break; + case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_GET_RESP): + /* GetResponse PDU */ + mib2_inc_snmpingetresponses(); + derr = ERR_ARG; + break; + case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_SET_REQ): + /* SetRequest PDU */ + mib2_inc_snmpinsetrequests(); + derr = ERR_OK; + break; + case (SNMP_ASN1_CONTXT | SNMP_ASN1_CONSTR | SNMP_ASN1_PDU_TRAP): + /* Trap PDU */ + mib2_inc_snmpintraps(); + derr = ERR_ARG; + break; + default: + mib2_inc_snmpinasnparseerrs(); + derr = ERR_ARG; + break; } - if (derr != ERR_OK) - { + if (derr != ERR_OK) { /* unsupported input PDU for this agent (no parse error) */ return ERR_ARG; } m_stat->rt = type & 0x1F; ofs += (1 + len_octets); - if (len != (pdu_len - (ofs - ofs_base))) - { + if (len != (pdu_len - (ofs - ofs_base))) { /* decoded PDU length does not equal actual payload length */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } snmp_asn1_dec_type(p, ofs, &type); derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); - if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG))) - { + if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG))) { /* can't decode or no integer (request ID) */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } derr = snmp_asn1_dec_s32t(p, ofs + 1 + len_octets, len, &m_stat->rid); - if (derr != ERR_OK) - { + if (derr != ERR_OK) { /* can't decode */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; @@ -1132,8 +985,7 @@ snmp_pdu_header_check(struct pbuf *p, u16_t ofs, u16_t pdu_len, u16_t *ofs_ret, ofs += (1 + len_octets + len); snmp_asn1_dec_type(p, ofs, &type); derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); - if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG))) - { + if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG))) { /* can't decode or no integer (error-status) */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; @@ -1141,41 +993,38 @@ snmp_pdu_header_check(struct pbuf *p, u16_t ofs, u16_t pdu_len, u16_t *ofs_ret, /* must be noError (0) for incoming requests. log errors for mib-2 completeness and for debug purposes */ derr = snmp_asn1_dec_s32t(p, ofs + 1 + len_octets, len, &m_stat->error_status); - if (derr != ERR_OK) - { + if (derr != ERR_OK) { /* can't decode */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } - switch (m_stat->error_status) - { - case SNMP_ES_NOERROR: - /* nothing to do */ - break; - case SNMP_ES_TOOBIG: - mib2_inc_snmpintoobigs(); - break; - case SNMP_ES_NOSUCHNAME: - mib2_inc_snmpinnosuchnames(); - break; - case SNMP_ES_BADVALUE: - mib2_inc_snmpinbadvalues(); - break; - case SNMP_ES_READONLY: - mib2_inc_snmpinreadonlys(); - break; - case SNMP_ES_GENERROR: - mib2_inc_snmpingenerrs(); - break; - default: - LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_pdu_header_check(): unknown error_status: %d\n", (int)m_stat->error_status)); - break; + switch (m_stat->error_status) { + case SNMP_ES_NOERROR: + /* nothing to do */ + break; + case SNMP_ES_TOOBIG: + mib2_inc_snmpintoobigs(); + break; + case SNMP_ES_NOSUCHNAME: + mib2_inc_snmpinnosuchnames(); + break; + case SNMP_ES_BADVALUE: + mib2_inc_snmpinbadvalues(); + break; + case SNMP_ES_READONLY: + mib2_inc_snmpinreadonlys(); + break; + case SNMP_ES_GENERROR: + mib2_inc_snmpingenerrs(); + break; + default: + LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_pdu_header_check(): unknown error_status: %d\n", (int)m_stat->error_status)); + break; } ofs += (1 + len_octets + len); snmp_asn1_dec_type(p, ofs, &type); derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); - if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG))) - { + if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG))) { /* can't decode or no integer (error-index) */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; @@ -1183,8 +1032,7 @@ snmp_pdu_header_check(struct pbuf *p, u16_t ofs, u16_t pdu_len, u16_t *ofs_ret, /* must be 0 for incoming requests. decode anyway to catch bad integers (and dirty tricks) */ derr = snmp_asn1_dec_s32t(p, ofs + 1 + len_octets, len, &m_stat->error_index); - if (derr != ERR_OK) - { + if (derr != ERR_OK) { /* can't decode */ mib2_inc_snmpinasnparseerrs(); return ERR_ARG; @@ -1206,8 +1054,7 @@ snmp_pdu_dec_varbindlist(struct pbuf *p, u16_t ofs, u16_t *ofs_ret, struct snmp_ snmp_asn1_dec_type(p, ofs, &type); derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &vb_len); if ((derr != ERR_OK) || - (type != (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ))) - { + (type != (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ))) { mib2_inc_snmpinasnparseerrs(); return ERR_ARG; } @@ -1218,8 +1065,7 @@ snmp_pdu_dec_varbindlist(struct pbuf *p, u16_t ofs, u16_t *ofs_ret, struct snmp_ m_stat->invb.head = NULL; m_stat->invb.tail = NULL; - while (vb_len > 0) - { + while (vb_len > 0) { struct snmp_obj_id oid, oid_value; struct snmp_varbind *vb; @@ -1227,8 +1073,7 @@ snmp_pdu_dec_varbindlist(struct pbuf *p, u16_t ofs, u16_t *ofs_ret, struct snmp_ derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ)) || - (len == 0) || (len > vb_len)) - { + (len == 0) || (len > vb_len)) { mib2_inc_snmpinasnparseerrs(); /* free varbinds (if available) */ snmp_varbind_list_free(&m_stat->invb); @@ -1239,8 +1084,7 @@ snmp_pdu_dec_varbindlist(struct pbuf *p, u16_t ofs, u16_t *ofs_ret, struct snmp_ snmp_asn1_dec_type(p, ofs, &type); derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); - if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID))) - { + if ((derr != ERR_OK) || (type != (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID))) { /* can't decode object name length */ mib2_inc_snmpinasnparseerrs(); /* free varbinds (if available) */ @@ -1248,8 +1092,7 @@ snmp_pdu_dec_varbindlist(struct pbuf *p, u16_t ofs, u16_t *ofs_ret, struct snmp_ return ERR_ARG; } derr = snmp_asn1_dec_oid(p, ofs + 1 + len_octets, len, &oid); - if (derr != ERR_OK) - { + if (derr != ERR_OK) { /* can't decode object name */ mib2_inc_snmpinasnparseerrs(); /* free varbinds (if available) */ @@ -1261,8 +1104,7 @@ snmp_pdu_dec_varbindlist(struct pbuf *p, u16_t ofs, u16_t *ofs_ret, struct snmp_ snmp_asn1_dec_type(p, ofs, &type); derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); - if (derr != ERR_OK) - { + if (derr != ERR_OK) { /* can't decode object value length */ mib2_inc_snmpinasnparseerrs(); /* free varbinds (if available) */ @@ -1270,113 +1112,86 @@ snmp_pdu_dec_varbindlist(struct pbuf *p, u16_t ofs, u16_t *ofs_ret, struct snmp_ return ERR_ARG; } - switch (type) - { - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG): - vb = snmp_varbind_alloc(&oid, type, sizeof(s32_t)); - if (vb != NULL) - { + switch (type) { + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG): + vb = snmp_varbind_alloc(&oid, type, sizeof(s32_t)); + if (vb != NULL) { + s32_t *vptr = (s32_t*)vb->value; + derr = snmp_asn1_dec_s32t(p, ofs + 1 + len_octets, len, vptr); + snmp_varbind_tail_add(&m_stat->invb, vb); + } else { + derr = ERR_ARG; + } + break; + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS): + vb = snmp_varbind_alloc(&oid, type, sizeof(u32_t)); + if (vb != NULL) { + u32_t *vptr = (u32_t*)vb->value; + derr = snmp_asn1_dec_u32t(p, ofs + 1 + len_octets, len, vptr); + snmp_varbind_tail_add(&m_stat->invb, vb); + } else { + derr = ERR_ARG; + } + break; + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE): + vb = snmp_varbind_alloc(&oid, type, len); + if (vb != NULL) { + derr = snmp_asn1_dec_raw(p, ofs + 1 + len_octets, len, vb->value_len, (u8_t*)vb->value); + snmp_varbind_tail_add(&m_stat->invb, vb); + } else { + derr = ERR_ARG; + } + break; + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL): + vb = snmp_varbind_alloc(&oid, type, 0); + if (vb != NULL) { + snmp_varbind_tail_add(&m_stat->invb, vb); + derr = ERR_OK; + } else { + derr = ERR_ARG; + } + break; + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID): + derr = snmp_asn1_dec_oid(p, ofs + 1 + len_octets, len, &oid_value); + if (derr == ERR_OK) { + vb = snmp_varbind_alloc(&oid, type, oid_value.len * sizeof(s32_t)); + if (vb != NULL) { + u8_t i = oid_value.len; s32_t *vptr = (s32_t*)vb->value; - derr = snmp_asn1_dec_s32t(p, ofs + 1 + len_octets, len, vptr); - snmp_varbind_tail_add(&m_stat->invb, vb); - } - else - { - derr = ERR_ARG; - } - break; - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS): - vb = snmp_varbind_alloc(&oid, type, sizeof(u32_t)); - if (vb != NULL) - { - u32_t *vptr = (u32_t*)vb->value; - - derr = snmp_asn1_dec_u32t(p, ofs + 1 + len_octets, len, vptr); - snmp_varbind_tail_add(&m_stat->invb, vb); - } - else - { - derr = ERR_ARG; - } - break; - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE): - vb = snmp_varbind_alloc(&oid, type, len); - if (vb != NULL) - { - derr = snmp_asn1_dec_raw(p, ofs + 1 + len_octets, len, vb->value_len, (u8_t*)vb->value); - snmp_varbind_tail_add(&m_stat->invb, vb); - } - else - { - derr = ERR_ARG; - } - break; - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL): - vb = snmp_varbind_alloc(&oid, type, 0); - if (vb != NULL) - { + while (i > 0) { + i--; + vptr[i] = oid_value.id[i]; + } snmp_varbind_tail_add(&m_stat->invb, vb); derr = ERR_OK; - } - else - { + } else { derr = ERR_ARG; } - break; - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID): - derr = snmp_asn1_dec_oid(p, ofs + 1 + len_octets, len, &oid_value); - if (derr == ERR_OK) - { - vb = snmp_varbind_alloc(&oid, type, oid_value.len * sizeof(s32_t)); - if (vb != NULL) - { - u8_t i = oid_value.len; - s32_t *vptr = (s32_t*)vb->value; - - while(i > 0) - { - i--; - vptr[i] = oid_value.id[i]; - } - snmp_varbind_tail_add(&m_stat->invb, vb); - derr = ERR_OK; - } - else - { - derr = ERR_ARG; - } - } - break; - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR): - if (len == 4) - { - /* must be exactly 4 octets! */ - vb = snmp_varbind_alloc(&oid, type, 4); - if (vb != NULL) - { - derr = snmp_asn1_dec_raw(p, ofs + 1 + len_octets, len, vb->value_len, (u8_t*)vb->value); - snmp_varbind_tail_add(&m_stat->invb, vb); - } - else - { - derr = ERR_ARG; - } - } - else - { + } + break; + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR): + if (len == 4) { + /* must be exactly 4 octets! */ + vb = snmp_varbind_alloc(&oid, type, 4); + if (vb != NULL) { + derr = snmp_asn1_dec_raw(p, ofs + 1 + len_octets, len, vb->value_len, (u8_t*)vb->value); + snmp_varbind_tail_add(&m_stat->invb, vb); + } else { derr = ERR_ARG; } - break; - default: + } else { derr = ERR_ARG; - break; + } + break; + default: + derr = ERR_ARG; + break; } - if (derr != ERR_OK) - { + if (derr != ERR_OK) { mib2_inc_snmpinasnparseerrs(); /* free varbinds (if available) */ snmp_varbind_list_free(&m_stat->invb); @@ -1386,12 +1201,9 @@ snmp_pdu_dec_varbindlist(struct pbuf *p, u16_t ofs, u16_t *ofs_ret, struct snmp_ vb_len -= (1 + len_octets + len); } - if (m_stat->rt == SNMP_ASN1_PDU_SET_REQ) - { + if (m_stat->rt == SNMP_ASN1_PDU_SET_REQ) { mib2_add_snmpintotalsetvars(m_stat->invb.count); - } - else - { + } else { mib2_add_snmpintotalreqvars(m_stat->invb.count); } @@ -1405,82 +1217,61 @@ snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u16_t len) struct snmp_varbind *vb; vb = (struct snmp_varbind *)memp_malloc(MEMP_SNMP_VARBIND); - if (vb != NULL) - { + if (vb != NULL) { u8_t i; vb->next = NULL; vb->prev = NULL; i = oid->len; vb->ident_len = i; - if (i > 0) - { - if (i <= SNMP_MAX_TREE_DEPTH) - { + if (i > 0) { + if (i <= SNMP_MAX_TREE_DEPTH) { /* allocate array of s32_t for our object identifier */ vb->ident = (s32_t*)memp_malloc(MEMP_SNMP_VALUE); - if (vb->ident == NULL) - { + if (vb->ident == NULL) { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_varbind_alloc: couldn't allocate ident value space\n")); } - } - else - { + } else { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_varbind_alloc: SNMP_MAX_TREE_DEPTH is configured too low\n")); vb->ident = NULL; } - if (vb->ident == NULL) - { + if (vb->ident == NULL) { memp_free(MEMP_SNMP_VARBIND, vb); return NULL; } - while(i > 0) - { + while (i > 0) { i--; vb->ident[i] = oid->id[i]; } - } - else - { + } else { /* i == 0, pass zero length object identifier */ vb->ident = NULL; } vb->value_type = type; vb->value_len = len; - if (len > 0) - { - if (vb->value_len <= SNMP_MAX_VALUE_SIZE) - { + if (len > 0) { + if (vb->value_len <= SNMP_MAX_VALUE_SIZE) { /* allocate raw bytes for our object value */ vb->value = memp_malloc(MEMP_SNMP_VALUE); - if (vb->value == NULL) - { + if (vb->value == NULL) { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_varbind_alloc: couldn't allocate value space\n")); } - } - else - { + } else { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_varbind_alloc: SNMP_MAX_OCTET_STRING_LEN is configured too low\n")); vb->value = NULL; } - if (vb->value == NULL) - { - if (vb->ident != NULL) - { + if (vb->value == NULL) { + if (vb->ident != NULL) { memp_free(MEMP_SNMP_VALUE, vb->ident); } memp_free(MEMP_SNMP_VARBIND, vb); return NULL; } - } - else - { + } else { /* ASN1_NUL type, or zero length ASN1_OC_STR */ vb->value = NULL; } - } - else - { + } else { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_varbind_alloc: couldn't allocate varbind space\n")); } return vb; @@ -1489,12 +1280,10 @@ snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u16_t len) void snmp_varbind_free(struct snmp_varbind *vb) { - if (vb->value != NULL ) - { + if (vb->value != NULL) { memp_free(MEMP_SNMP_VALUE, vb->value); } - if (vb->ident != NULL ) - { + if (vb->ident != NULL) { memp_free(MEMP_SNMP_VALUE, vb->ident); } memp_free(MEMP_SNMP_VARBIND, vb); @@ -1506,8 +1295,7 @@ snmp_varbind_list_free(struct snmp_varbind_root *root) struct snmp_varbind *vb, *prev; vb = root->tail; - while ( vb != NULL ) - { + while (vb != NULL) { prev = vb->prev; snmp_varbind_free(vb); vb = prev; @@ -1520,14 +1308,11 @@ snmp_varbind_list_free(struct snmp_varbind_root *root) void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb) { - if (root->count == 0) - { + if (root->count == 0) { /* add first varbind to list */ root->head = vb; root->tail = vb; - } - else - { + } else { /* add nth varbind to list tail */ root->tail->next = vb; vb->prev = root->tail; @@ -1541,16 +1326,13 @@ snmp_varbind_tail_remove(struct snmp_varbind_root *root) { struct snmp_varbind* vb; - if (root->count > 0) - { + if (root->count > 0) { /* remove tail varbind */ vb = root->tail; root->tail = vb->prev; vb->prev->next = NULL; root->count -= 1; - } - else - { + } else { /* nothing to remove */ vb = NULL; } diff --git a/src/core/snmp/msg_out.c b/src/core/snmp/msg_out.c index 54cf8ac1..4b621c7e 100644 --- a/src/core/snmp/msg_out.c +++ b/src/core/snmp/msg_out.c @@ -88,8 +88,7 @@ static u16_t snmp_varbind_list_enc(struct snmp_varbind_root *root, struct pbuf * void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable) { - if (dst_idx < SNMP_TRAP_DESTINATIONS) - { + if (dst_idx < SNMP_TRAP_DESTINATIONS) { trap_dst[dst_idx].enable = enable; } } @@ -102,8 +101,7 @@ snmp_trap_dst_enable(u8_t dst_idx, u8_t enable) void snmp_trap_dst_ip_set(u8_t dst_idx, const ip_addr_t *dst) { - if (dst_idx < SNMP_TRAP_DESTINATIONS) - { + if (dst_idx < SNMP_TRAP_DESTINATIONS) { ip_addr_set(&trap_dst[dst_idx].dip, dst); } } @@ -131,8 +129,7 @@ snmp_send_response(struct snmp_msg_pstat *m_stat) /* try allocating pbuf(s) for complete response */ p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL); - if (p == NULL) - { + if (p == NULL) { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() tooBig\n")); /* can't construct reply, return error-status tooBig */ @@ -144,8 +141,7 @@ snmp_send_response(struct snmp_msg_pstat *m_stat) /* retry allocation once for header and empty varbind-list */ p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL); } - if (p != NULL) - { + if (p != NULL) { /* first pbuf alloc try or retry alloc success */ u16_t ofs; @@ -155,26 +151,25 @@ snmp_send_response(struct snmp_msg_pstat *m_stat) ofs = snmp_resp_header_enc(m_stat, p); snmp_varbind_list_enc(&m_stat->outvb, p, ofs); - switch (m_stat->error_status) - { - case SNMP_ES_NOERROR: - /* nothing to do */ - break; - case SNMP_ES_TOOBIG: - mib2_inc_snmpouttoobigs(); - break; - case SNMP_ES_NOSUCHNAME: - mib2_inc_snmpoutnosuchnames(); - break; - case SNMP_ES_BADVALUE: - mib2_inc_snmpoutbadvalues(); - break; - case SNMP_ES_GENERROR: - mib2_inc_snmpoutgenerrs(); - break; - default: - LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_send_response(): unknown error_status: %d\n", (int)m_stat->error_status)); - break; + switch (m_stat->error_status) { + case SNMP_ES_NOERROR: + /* nothing to do */ + break; + case SNMP_ES_TOOBIG: + mib2_inc_snmpouttoobigs(); + break; + case SNMP_ES_NOSUCHNAME: + mib2_inc_snmpoutnosuchnames(); + break; + case SNMP_ES_BADVALUE: + mib2_inc_snmpoutbadvalues(); + break; + case SNMP_ES_GENERROR: + mib2_inc_snmpoutgenerrs(); + break; + default: + LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_send_response(): unknown error_status: %d\n", (int)m_stat->error_status)); + break; } mib2_inc_snmpoutgetresponses(); mib2_inc_snmpoutpkts(); @@ -183,13 +178,10 @@ snmp_send_response(struct snmp_msg_pstat *m_stat) /** connect to the originating source */ udp_connect(m_stat->pcb, &m_stat->sip, m_stat->sp); err = udp_send(m_stat->pcb, p); - if (err == ERR_MEM) - { + if (err == ERR_MEM) { /** @todo release some memory, retry and return tooBig? tooMuchHassle? */ err = ERR_MEM; - } - else - { + } else { err = ERR_OK; } /** disassociate remote address and port with this pcb */ @@ -198,9 +190,7 @@ snmp_send_response(struct snmp_msg_pstat *m_stat) pbuf_free(p); LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() done\n")); return err; - } - else - { + } else { /* first pbuf alloc try or retry alloc failed very low on memory, couldn't return tooBig */ return ERR_MEM; @@ -233,10 +223,8 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific u16_t i,tot_len; err_t err = ERR_OK; - for (i=0, td = &trap_dst[0]; ienable != 0) && !ip_addr_isany(&td->dip)) - { + for (i = 0, td = &trap_dst[0]; i < SNMP_TRAP_DESTINATIONS; i++, td++) { + if ((td->enable != 0) && !ip_addr_isany(&td->dip)) { /* network order trap destination */ ip_addr_copy(trap_msg.dip, td->dip); /* lookup current source address for this dst */ @@ -247,13 +235,10 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific memcpy(trap_msg.sip_raw, dst_ip, trap_msg.sip_raw_len); trap_msg.gen_trap = generic_trap; trap_msg.spc_trap = specific_trap; - if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC) - { + if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC) { /* enterprise-Specific trap */ trap_msg.enterprise = eoid; - } - else - { + } else { /* generic (MIB-II) trap */ mib2_get_snmpgrpid_ptr(&trap_msg.enterprise); } @@ -266,8 +251,7 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific /* allocate pbuf(s) */ p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL); - if (p != NULL) - { + if (p != NULL) { u16_t ofs; /* pass 1, encode packet ino the pbuf(s) */ @@ -307,8 +291,7 @@ snmp_authfail_trap(void) { u8_t enable; mib2_get_snmpenableauthentraps(&enable); - if (enable == 1) - { + if (enable == 1) { trap_msg.outvb.head = NULL; trap_msg.outvb.tail = NULL; trap_msg.outvb.count = 0; @@ -438,35 +421,33 @@ snmp_varbind_list_sum(struct snmp_varbind_root *root) tot_len = 0; vb = root->tail; - while ( vb != NULL ) - { + while (vb != NULL) { /* encoded value lenght depends on type */ - switch (vb->value_type) - { - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG): - sint_ptr = (s32_t*)vb->value; - snmp_asn1_enc_s32t_cnt(*sint_ptr, &vb->vlen); - break; - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS): - uint_ptr = (u32_t*)vb->value; - snmp_asn1_enc_u32t_cnt(*uint_ptr, &vb->vlen); - break; - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR): - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE): - vb->vlen = vb->value_len; - break; - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID): - sint_ptr = (s32_t*)vb->value; - snmp_asn1_enc_oid_cnt(vb->value_len / sizeof(s32_t), sint_ptr, &vb->vlen); - break; - default: - /* unsupported type */ - vb->vlen = 0; - break; + switch (vb->value_type) { + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG): + sint_ptr = (s32_t*)vb->value; + snmp_asn1_enc_s32t_cnt(*sint_ptr, &vb->vlen); + break; + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS): + uint_ptr = (u32_t*)vb->value; + snmp_asn1_enc_u32t_cnt(*uint_ptr, &vb->vlen); + break; + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR): + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE): + vb->vlen = vb->value_len; + break; + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID): + sint_ptr = (s32_t*)vb->value; + snmp_asn1_enc_oid_cnt(vb->value_len / sizeof(s32_t), sint_ptr, &vb->vlen); + break; + default: + /* unsupported type */ + vb->vlen = 0; + break; } /* encoding length of value length field */ snmp_asn1_enc_length_cnt(vb->vlen, &vb->vlenlen); @@ -638,8 +619,7 @@ snmp_varbind_list_enc(struct snmp_varbind_root *root, struct pbuf *p, u16_t ofs) ofs += root->seqlenlen; vb = root->head; - while ( vb != NULL ) - { + while (vb != NULL) { snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ)); ofs += 1; snmp_asn1_enc_length(p, ofs, vb->seqlen); @@ -657,33 +637,32 @@ snmp_varbind_list_enc(struct snmp_varbind_root *root, struct pbuf *p, u16_t ofs) snmp_asn1_enc_length(p, ofs, vb->vlen); ofs += vb->vlenlen; - switch (vb->value_type) - { - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG): - sint_ptr = (s32_t*)vb->value; - snmp_asn1_enc_s32t(p, ofs, vb->vlen, *sint_ptr); - break; - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS): - uint_ptr = (u32_t*)vb->value; - snmp_asn1_enc_u32t(p, ofs, vb->vlen, *uint_ptr); - break; - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR): - case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE): - raw_ptr = (u8_t*)vb->value; - snmp_asn1_enc_raw(p, ofs, vb->vlen, raw_ptr); - break; - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL): - break; - case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID): - sint_ptr = (s32_t*)vb->value; - snmp_asn1_enc_oid(p, ofs, vb->value_len / sizeof(s32_t), sint_ptr); - break; - default: - /* unsupported type */ - break; + switch (vb->value_type) { + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG): + sint_ptr = (s32_t*)vb->value; + snmp_asn1_enc_s32t(p, ofs, vb->vlen, *sint_ptr); + break; + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS): + uint_ptr = (u32_t*)vb->value; + snmp_asn1_enc_u32t(p, ofs, vb->vlen, *uint_ptr); + break; + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR): + case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE): + raw_ptr = (u8_t*)vb->value; + snmp_asn1_enc_raw(p, ofs, vb->vlen, raw_ptr); + break; + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL): + break; + case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID): + sint_ptr = (s32_t*)vb->value; + snmp_asn1_enc_oid(p, ofs, vb->value_len / sizeof(s32_t), sint_ptr); + break; + default: + /* unsupported type */ + break; } ofs += vb->vlen; vb = vb->next;