X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/571a6f33f47e7a2394fa08f925e534135c29cf1e..d7b497cac78b6e22a66a6bae9bdec60a8044f67a:/print-isoclns.c diff --git a/print-isoclns.c b/print-isoclns.c index 62855028..e4bc6941 100644 --- a/print-isoclns.c +++ b/print-isoclns.c @@ -50,8 +50,8 @@ static const char tstr[] = " [|isis]"; */ #define SYSTEM_ID_LEN ETHER_ADDR_LEN -#define NODE_ID_LEN SYSTEM_ID_LEN+1 -#define LSP_ID_LEN SYSTEM_ID_LEN+2 +#define NODE_ID_LEN (SYSTEM_ID_LEN+1) +#define LSP_ID_LEN (SYSTEM_ID_LEN+2) #define ISIS_VERSION 1 #define ESIS_VERSION 1 @@ -109,7 +109,7 @@ static const struct tok isis_pdu_values[] = { #define ISIS_TLV_POI 13 /* rfc6232 */ #define ISIS_TLV_LSP_BUFFERSIZE 14 /* iso10589 rev2 */ #define ISIS_TLV_LSP_BUFFERSIZE_MINLEN 2 -#define ISIS_TLV_EXT_IS_REACH 22 /* draft-ietf-isis-traffic-05 */ +#define ISIS_TLV_EXT_IS_REACH 22 /* rfc5305 */ #define ISIS_TLV_IS_ALIAS_ID 24 /* draft-ietf-isis-ext-lsp-frags-02 */ #define ISIS_TLV_DECNET_PHASE4 42 #define ISIS_TLV_LUCENT_PRIVATE 66 @@ -120,8 +120,8 @@ static const struct tok isis_pdu_values[] = { #define ISIS_TLV_IDRP_INFO_MINLEN 1 #define ISIS_TLV_IPADDR 132 /* rfc1195 */ #define ISIS_TLV_IPAUTH 133 /* rfc1195 */ -#define ISIS_TLV_TE_ROUTER_ID 134 /* draft-ietf-isis-traffic-05 */ -#define ISIS_TLV_EXTD_IP_REACH 135 /* draft-ietf-isis-traffic-05 */ +#define ISIS_TLV_TE_ROUTER_ID 134 /* rfc5305 */ +#define ISIS_TLV_EXTD_IP_REACH 135 /* rfc5305 */ #define ISIS_TLV_HOSTNAME 137 /* rfc2763 */ #define ISIS_TLV_SHARED_RISK_GROUP 138 /* draft-ietf-isis-gmpls-extensions */ #define ISIS_TLV_MT_PORT_CAP 143 /* rfc6165 */ @@ -338,16 +338,16 @@ static const struct tok clnp_option_qos_global_values[] = { { 0, NULL } }; -#define ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP 3 /* draft-ietf-isis-traffic-05 */ +#define ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP 3 /* rfc5305 */ #define ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID 4 /* rfc4205 */ -#define ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID 5 /* draft-ietf-isis-traffic-05 */ -#define ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR 6 /* draft-ietf-isis-traffic-05 */ -#define ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR 8 /* draft-ietf-isis-traffic-05 */ -#define ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW 9 /* draft-ietf-isis-traffic-05 */ -#define ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW 10 /* draft-ietf-isis-traffic-05 */ +#define ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID 5 /* rfc5305 */ +#define ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR 6 /* rfc5305 */ +#define ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR 8 /* rfc5305 */ +#define ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW 9 /* rfc5305 */ +#define ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW 10 /* rfc5305 */ #define ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW 11 /* rfc4124 */ #define ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD 12 /* draft-ietf-tewg-diff-te-proto-06 */ -#define ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC 18 /* draft-ietf-isis-traffic-05 */ +#define ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC 18 /* rfc5305 */ #define ISIS_SUBTLV_EXT_IS_REACH_LINK_ATTRIBUTE 19 /* draft-ietf-isis-link-attr-01 */ #define ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE 20 /* rfc4205 */ #define ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR 21 /* rfc4205 */ @@ -678,7 +678,7 @@ isoclns_print(netdissect_options *ndo, const uint8_t *p, u_int length) } if (ndo->ndo_eflag) - ND_PRINT((ndo, "OSI NLPID %s (0x%02x): ", tok2str(nlpid_values, "Unknown", *p), *p)); + ND_PRINT((ndo, "OSI NLPID %s (0x%02x): ", tok2str(nlpid_values, "Unknown", EXTRACT_U_1(p)), EXTRACT_U_1(p))); switch (*p) { @@ -718,7 +718,7 @@ isoclns_print(netdissect_options *ndo, const uint8_t *p, u_int length) default: if (!ndo->ndo_eflag) - ND_PRINT((ndo, "OSI NLPID 0x%02x unknown", *p)); + ND_PRINT((ndo, "OSI NLPID 0x%02x unknown", EXTRACT_U_1(p))); ND_PRINT((ndo, "%slength: %u", ndo->ndo_eflag ? "" : ", ", length)); if (length > 1) print_unknown_data(ndo, p, "\n\t", length); @@ -770,7 +770,7 @@ clnp_print(netdissect_options *ndo, u_int li,tlen,nsap_offset,source_address_length,dest_address_length, clnp_pdu_type, clnp_flags; const struct clnp_header_t *clnp_header; const struct clnp_segment_header_t *clnp_segment_header; - uint8_t rfd_error_major,rfd_error_minor; + uint8_t rfd_error,rfd_error_major,rfd_error_minor; clnp_header = (const struct clnp_header_t *) pptr; ND_TCHECK(*clnp_header); @@ -797,8 +797,10 @@ clnp_print(netdissect_options *ndo, if (li < sizeof(struct clnp_header_t)) { ND_PRINT((ndo, " length indicator %u < min PDU size:", li)); - while (pptr < ndo->ndo_snapend) - ND_PRINT((ndo, "%02X", *pptr++)); + while (pptr < ndo->ndo_snapend) { + ND_PRINT((ndo, "%02X", EXTRACT_U_1(pptr))); + pptr++; + } return (0); } @@ -815,7 +817,7 @@ clnp_print(netdissect_options *ndo, return (0); } ND_TCHECK(*pptr); - dest_address_length = *pptr; + dest_address_length = EXTRACT_U_1(pptr); pptr += 1; li -= 1; if (li < dest_address_length) { @@ -832,7 +834,7 @@ clnp_print(netdissect_options *ndo, return (0); } ND_TCHECK(*pptr); - source_address_length = *pptr; + source_address_length = EXTRACT_U_1(pptr); pptr += 1; li -= 1; if (li < source_address_length) { @@ -861,10 +863,10 @@ clnp_print(netdissect_options *ndo, clnp_header->version, clnp_header->lifetime/2, (clnp_header->lifetime%2)*5, - EXTRACT_16BITS(clnp_header->segment_length), - EXTRACT_16BITS(clnp_header->cksum))); + EXTRACT_BE_U_2(clnp_header->segment_length), + EXTRACT_BE_U_2(clnp_header->cksum))); - osi_print_cksum(ndo, optr, EXTRACT_16BITS(clnp_header->cksum), 7, + osi_print_cksum(ndo, optr, EXTRACT_BE_U_2(clnp_header->cksum), 7, clnp_header->length_indicator); ND_PRINT((ndo, "\n\tFlags [%s]", @@ -877,18 +879,18 @@ clnp_print(netdissect_options *ndo, isonsap_string(ndo, dest_address, dest_address_length))); if (clnp_flags & CLNP_SEGMENT_PART) { - if (li < sizeof(const struct clnp_segment_header_t)) { + if (li < sizeof(struct clnp_segment_header_t)) { ND_PRINT((ndo, "li < size of fixed part of CLNP header, addresses, and segment part")); return (0); } clnp_segment_header = (const struct clnp_segment_header_t *) pptr; ND_TCHECK(*clnp_segment_header); ND_PRINT((ndo, "\n\tData Unit ID: 0x%04x, Segment Offset: %u, Total PDU Length: %u", - EXTRACT_16BITS(clnp_segment_header->data_unit_id), - EXTRACT_16BITS(clnp_segment_header->segment_offset), - EXTRACT_16BITS(clnp_segment_header->total_length))); - pptr+=sizeof(const struct clnp_segment_header_t); - li-=sizeof(const struct clnp_segment_header_t); + EXTRACT_BE_U_2(clnp_segment_header->data_unit_id), + EXTRACT_BE_U_2(clnp_segment_header->segment_offset), + EXTRACT_BE_U_2(clnp_segment_header->total_length))); + pptr+=sizeof(struct clnp_segment_header_t); + li-=sizeof(struct clnp_segment_header_t); } /* now walk the options */ @@ -900,9 +902,10 @@ clnp_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad opts/li")); return (0); } - ND_TCHECK2(*pptr, 2); - op = *pptr++; - opli = *pptr++; + ND_TCHECK_2(pptr); + op = EXTRACT_U_1(pptr); + opli = EXTRACT_U_1(pptr + 1); + pptr += 2; li -= 2; if (opli > li) { ND_PRINT((ndo, ", opt (%d) too long", op)); @@ -936,9 +939,9 @@ clnp_print(netdissect_options *ndo, return (0); } ND_PRINT((ndo, "%s %s", - tok2str(clnp_option_sr_rr_values,"Unknown",*tptr), + tok2str(clnp_option_sr_rr_values,"Unknown",EXTRACT_U_1(tptr)), tok2str(clnp_option_sr_rr_string_values, "Unknown Option %u", op))); - nsap_offset=*(tptr+1); + nsap_offset=EXTRACT_U_1(tptr + 1); if (nsap_offset == 0) { ND_PRINT((ndo, " Bad NSAP offset (0)")); break; @@ -951,7 +954,7 @@ clnp_print(netdissect_options *ndo, tptr+=nsap_offset; tlen-=nsap_offset; while (tlen > 0) { - source_address_length=*tptr; + source_address_length=EXTRACT_U_1(tptr); if (tlen < source_address_length+1) { ND_PRINT((ndo, "\n\t NSAP address goes past end of option")); break; @@ -972,7 +975,7 @@ clnp_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad opt len")); return (0); } - ND_PRINT((ndo, "0x%1x", *tptr&0x0f)); + ND_PRINT((ndo, "0x%1x", EXTRACT_U_1(tptr)&0x0f)); break; case CLNP_OPTION_QOS_MAINTENANCE: @@ -981,13 +984,13 @@ clnp_print(netdissect_options *ndo, return (0); } ND_PRINT((ndo, "\n\t Format Code: %s", - tok2str(clnp_option_scope_values, "Reserved", *tptr&CLNP_OPTION_SCOPE_MASK))); + tok2str(clnp_option_scope_values, "Reserved", EXTRACT_U_1(tptr) & CLNP_OPTION_SCOPE_MASK))); - if ((*tptr&CLNP_OPTION_SCOPE_MASK) == CLNP_OPTION_SCOPE_GLOBAL) + if ((EXTRACT_U_1(tptr)&CLNP_OPTION_SCOPE_MASK) == CLNP_OPTION_SCOPE_GLOBAL) ND_PRINT((ndo, "\n\t QoS Flags [%s]", bittok2str(clnp_option_qos_global_values, "none", - *tptr&CLNP_OPTION_OPTION_QOS_MASK))); + EXTRACT_U_1(tptr)&CLNP_OPTION_OPTION_QOS_MASK))); break; case CLNP_OPTION_SECURITY: @@ -996,8 +999,8 @@ clnp_print(netdissect_options *ndo, return (0); } ND_PRINT((ndo, "\n\t Format Code: %s, Security-Level %u", - tok2str(clnp_option_scope_values,"Reserved",*tptr&CLNP_OPTION_SCOPE_MASK), - *(tptr+1))); + tok2str(clnp_option_scope_values,"Reserved",EXTRACT_U_1(tptr)&CLNP_OPTION_SCOPE_MASK), + EXTRACT_U_1(tptr + 1))); break; case CLNP_OPTION_DISCARD_REASON: @@ -1005,8 +1008,9 @@ clnp_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad opt len")); return (0); } - rfd_error_major = (*tptr&0xf0) >> 4; - rfd_error_minor = *tptr&0x0f; + rfd_error = EXTRACT_U_1(tptr); + rfd_error_major = (rfd_error&0xf0) >> 4; + rfd_error_minor = rfd_error&0x0f; ND_PRINT((ndo, "\n\t Class: %s Error (0x%01x), %s (0x%01x)", tok2str(clnp_option_rfd_class_values,"Unknown",rfd_error_major), rfd_error_major, @@ -1037,7 +1041,7 @@ clnp_print(netdissect_options *ndo, case CLNP_PDU_ER: /* fall through */ case CLNP_PDU_ERP: ND_TCHECK(*pptr); - if (*(pptr) == NLPID_CLNP) { + if (EXTRACT_U_1(pptr) == NLPID_CLNP) { ND_PRINT((ndo, "\n\t-----original packet-----\n\t")); /* FIXME recursion protection */ clnp_print(ndo, pptr, length - clnp_header->length_indicator); @@ -1128,8 +1132,10 @@ esis_print(netdissect_options *ndo, if (li < sizeof(struct esis_header_t) + 2) { ND_PRINT((ndo, " length indicator %u < min PDU size:", li)); - while (pptr < ndo->ndo_snapend) - ND_PRINT((ndo, "%02X", *pptr++)); + while (pptr < ndo->ndo_snapend) { + ND_PRINT((ndo, "%02X", EXTRACT_U_1(pptr))); + pptr++; + } return; } @@ -1149,12 +1155,13 @@ esis_print(netdissect_options *ndo, esis_pdu_type)); ND_PRINT((ndo, ", v: %u%s", esis_header->version, esis_header->version == ESIS_VERSION ? "" : "unsupported" )); - ND_PRINT((ndo, ", checksum: 0x%04x", EXTRACT_16BITS(esis_header->cksum))); + ND_PRINT((ndo, ", checksum: 0x%04x", EXTRACT_BE_U_2(esis_header->cksum))); - osi_print_cksum(ndo, pptr, EXTRACT_16BITS(esis_header->cksum), 7, li); + osi_print_cksum(ndo, pptr, EXTRACT_BE_U_2(esis_header->cksum), 7, + li); ND_PRINT((ndo, ", holding time: %us, length indicator: %u", - EXTRACT_16BITS(esis_header->holdtime), li)); + EXTRACT_BE_U_2(esis_header->holdtime), li)); if (ndo->ndo_vflag > 1) print_unknown_data(ndo, optr, "\n\t", sizeof(struct esis_header_t)); @@ -1172,7 +1179,7 @@ esis_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad redirect/li")); return; } - dstl = *pptr; + dstl = EXTRACT_U_1(pptr); pptr++; li--; ND_TCHECK2(*pptr, dstl); @@ -1190,7 +1197,7 @@ esis_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad redirect/li")); return; } - snpal = *pptr; + snpal = EXTRACT_U_1(pptr); pptr++; li--; ND_TCHECK2(*pptr, snpal); @@ -1206,7 +1213,7 @@ esis_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad redirect/li")); return; } - netal = *pptr; + netal = EXTRACT_U_1(pptr); pptr++; ND_TCHECK2(*pptr, netal); if (li < netal) { @@ -1238,7 +1245,7 @@ esis_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad esh/li")); return; } - source_address_number = *pptr; + source_address_number = EXTRACT_U_1(pptr); pptr++; li--; @@ -1250,7 +1257,7 @@ esis_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad esh/li")); return; } - source_address_length = *pptr; + source_address_length = EXTRACT_U_1(pptr); pptr++; li--; @@ -1275,7 +1282,7 @@ esis_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad ish/li")); return; } - source_address_length = *pptr; + source_address_length = EXTRACT_U_1(pptr); pptr++; li--; ND_TCHECK2(*pptr, source_address_length); @@ -1306,9 +1313,10 @@ esis_print(netdissect_options *ndo, ND_PRINT((ndo, ", bad opts/li")); return; } - ND_TCHECK2(*pptr, 2); - op = *pptr++; - opli = *pptr++; + ND_TCHECK_2(pptr); + op = EXTRACT_U_1(pptr); + opli = EXTRACT_U_1(pptr + 1); + pptr += 2; li -= 2; if (opli > li) { ND_PRINT((ndo, ", opt (%d) too long", op)); @@ -1326,20 +1334,20 @@ esis_print(netdissect_options *ndo, case ESIS_OPTION_ES_CONF_TIME: if (opli == 2) { - ND_TCHECK2(*pptr, 2); - ND_PRINT((ndo, "%us", EXTRACT_16BITS(tptr))); + ND_TCHECK_2(pptr); + ND_PRINT((ndo, "%us", EXTRACT_BE_U_2(tptr))); } else ND_PRINT((ndo, "(bad length)")); break; case ESIS_OPTION_PROTOCOLS: while (opli>0) { - ND_TCHECK(*pptr); + ND_TCHECK_1(tptr); ND_PRINT((ndo, "%s (0x%02x)", tok2str(nlpid_values, "unknown", - *tptr), - *tptr)); + EXTRACT_U_1(tptr)), + EXTRACT_U_1(tptr))); if (opli>1) /* further NPLIDs ? - put comma */ ND_PRINT((ndo, ", ")); tptr++; @@ -1367,7 +1375,7 @@ esis_print(netdissect_options *ndo, pptr += opli; } trunc: - return; + ND_PRINT((ndo, "[|esis]")); } static void @@ -1382,7 +1390,7 @@ isis_print_mcid(netdissect_options *ndo, if (fn_printzp(ndo, mcid->name, 32, ndo->ndo_snapend)) goto trunc; - ND_PRINT((ndo, "\n\t Lvl: %d", EXTRACT_16BITS(mcid->revision_lvl))); + ND_PRINT((ndo, "\n\t Lvl: %d", EXTRACT_BE_U_2(mcid->revision_lvl))); ND_PRINT((ndo, ", Digest: ")); @@ -1403,9 +1411,9 @@ isis_print_mt_port_cap_subtlv(netdissect_options *ndo, while (len > 2) { - ND_TCHECK2(*tptr, 2); - stlv_type = *(tptr++); - stlv_len = *(tptr++); + ND_TCHECK_2(tptr); + stlv_type = EXTRACT_U_1(tptr); + stlv_len = EXTRACT_U_1(tptr + 1); /* first lets see if we know the subTLVs name*/ ND_PRINT((ndo, "\n\t %s subTLV #%u, length: %u", @@ -1413,8 +1421,9 @@ isis_print_mt_port_cap_subtlv(netdissect_options *ndo, stlv_type, stlv_len)); + tptr = tptr + 2; /*len -= TLV_TYPE_LEN_OFFSET;*/ - len = len -2; + len = len - 2; /* Make sure the subTLV fits within the space left */ if (len < stlv_len) @@ -1455,8 +1464,10 @@ isis_print_mt_port_cap_subtlv(netdissect_options *ndo, goto trunc; ND_PRINT((ndo, "\n\t RES: %d V: %d A: %d D: %d", - (*(tptr) >> 5), (((*tptr)>> 4) & 0x01), - ((*(tptr) >> 2) & 0x03), ((*tptr) & 0x03))); + (EXTRACT_U_1(tptr) >> 5), + ((EXTRACT_U_1(tptr) >> 4) & 0x01), + ((EXTRACT_U_1(tptr) >> 2) & 0x03), + (EXTRACT_U_1(tptr) & 0x03))); tptr++; @@ -1464,7 +1475,7 @@ isis_print_mt_port_cap_subtlv(netdissect_options *ndo, for(i=1;i<=8; i++) { - ND_PRINT((ndo, "%08x ", EXTRACT_32BITS(tptr))); + ND_PRINT((ndo, "%08x ", EXTRACT_BE_U_4(tptr))); if (i%4 == 0 && i != 8) ND_PRINT((ndo, "\n\t ")); tptr = tptr + 4; @@ -1481,14 +1492,14 @@ isis_print_mt_port_cap_subtlv(netdissect_options *ndo, while (stlv_len >= ISIS_SUBTLV_SPB_BVID_MIN_LEN) { ND_PRINT((ndo, "\n\t ECT: %08x", - EXTRACT_32BITS(tptr))); + EXTRACT_BE_U_4(tptr))); tptr = tptr+4; ND_PRINT((ndo, " BVID: %d, U:%01x M:%01x ", - (EXTRACT_16BITS (tptr) >> 4) , - (EXTRACT_16BITS (tptr) >> 3) & 0x01, - (EXTRACT_16BITS (tptr) >> 2) & 0x01)); + (EXTRACT_BE_U_2(tptr) >> 4) , + (EXTRACT_BE_U_2(tptr) >> 3) & 0x01, + (EXTRACT_BE_U_2(tptr) >> 2) & 0x01)); tptr = tptr + 2; len = len - ISIS_SUBTLV_SPB_BVID_MIN_LEN; @@ -1521,9 +1532,11 @@ isis_print_mt_capability_subtlv(netdissect_options *ndo, while (len > 2) { - ND_TCHECK2(*tptr, 2); - stlv_type = *(tptr++); - stlv_len = *(tptr++); + ND_TCHECK_2(tptr); + stlv_type = EXTRACT_U_1(tptr); + stlv_len = EXTRACT_U_1(tptr + 1); + tptr = tptr + 2; + len = len - 2; /* first lets see if we know the subTLVs name*/ ND_PRINT((ndo, "\n\t %s subTLV #%u, length: %u", @@ -1531,8 +1544,6 @@ isis_print_mt_capability_subtlv(netdissect_options *ndo, stlv_type, stlv_len)); - len = len - 2; - /* Make sure the subTLV fits within the space left */ if (len < stlv_len) goto trunc; @@ -1545,24 +1556,25 @@ isis_print_mt_capability_subtlv(netdissect_options *ndo, if (stlv_len < ISIS_SUBTLV_SPB_INSTANCE_MIN_LEN) goto trunc; - ND_PRINT((ndo, "\n\t CIST Root-ID: %08x", EXTRACT_32BITS(tptr))); + ND_PRINT((ndo, "\n\t CIST Root-ID: %08x", EXTRACT_BE_U_4(tptr))); tptr = tptr+4; - ND_PRINT((ndo, " %08x", EXTRACT_32BITS(tptr))); + ND_PRINT((ndo, " %08x", EXTRACT_BE_U_4(tptr))); tptr = tptr+4; - ND_PRINT((ndo, ", Path Cost: %08x", EXTRACT_32BITS(tptr))); + ND_PRINT((ndo, ", Path Cost: %08x", EXTRACT_BE_U_4(tptr))); tptr = tptr+4; - ND_PRINT((ndo, ", Prio: %d", EXTRACT_16BITS(tptr))); + ND_PRINT((ndo, ", Prio: %d", EXTRACT_BE_U_2(tptr))); tptr = tptr + 2; ND_PRINT((ndo, "\n\t RES: %d", - EXTRACT_16BITS(tptr) >> 5)); + EXTRACT_BE_U_2(tptr) >> 5)); ND_PRINT((ndo, ", V: %d", - (EXTRACT_16BITS(tptr) >> 4) & 0x0001)); + (EXTRACT_BE_U_2(tptr) >> 4) & 0x0001)); ND_PRINT((ndo, ", SPSource-ID: %d", - (EXTRACT_32BITS(tptr) & 0x000fffff))); + (EXTRACT_BE_U_4(tptr) & 0x000fffff))); tptr = tptr+4; - ND_PRINT((ndo, ", No of Trees: %x", *(tptr))); + ND_PRINT((ndo, ", No of Trees: %x", EXTRACT_U_1(tptr))); - tmp = *(tptr++); + tmp = EXTRACT_U_1(tptr); + tptr++; len = len - ISIS_SUBTLV_SPB_INSTANCE_MIN_LEN; stlv_len = stlv_len - ISIS_SUBTLV_SPB_INSTANCE_MIN_LEN; @@ -1573,18 +1585,20 @@ isis_print_mt_capability_subtlv(netdissect_options *ndo, goto trunc; ND_PRINT((ndo, "\n\t U:%d, M:%d, A:%d, RES:%d", - *(tptr) >> 7, (*(tptr) >> 6) & 0x01, - (*(tptr) >> 5) & 0x01, (*(tptr) & 0x1f))); + EXTRACT_U_1(tptr) >> 7, + (EXTRACT_U_1(tptr) >> 6) & 0x01, + (EXTRACT_U_1(tptr) >> 5) & 0x01, + (EXTRACT_U_1(tptr) & 0x1f))); tptr++; - ND_PRINT((ndo, ", ECT: %08x", EXTRACT_32BITS(tptr))); + ND_PRINT((ndo, ", ECT: %08x", EXTRACT_BE_U_4(tptr))); tptr = tptr + 4; ND_PRINT((ndo, ", BVID: %d, SPVID: %d", - (EXTRACT_24BITS(tptr) >> 12) & 0x000fff, - EXTRACT_24BITS(tptr) & 0x000fff)); + (EXTRACT_BE_U_3(tptr) >> 12) & 0x000fff, + EXTRACT_BE_U_3(tptr) & 0x000fff)); tptr = tptr + 3; len = len - ISIS_SUBTLV_SPB_INSTANCE_VLAN_TUPLE_LEN; @@ -1598,25 +1612,25 @@ isis_print_mt_capability_subtlv(netdissect_options *ndo, if (stlv_len < 8) goto trunc; - ND_PRINT((ndo, "\n\t BMAC: %08x", EXTRACT_32BITS(tptr))); + ND_PRINT((ndo, "\n\t BMAC: %08x", EXTRACT_BE_U_4(tptr))); tptr = tptr+4; - ND_PRINT((ndo, "%04x", EXTRACT_16BITS(tptr))); + ND_PRINT((ndo, "%04x", EXTRACT_BE_U_2(tptr))); tptr = tptr+2; - ND_PRINT((ndo, ", RES: %d, VID: %d", EXTRACT_16BITS(tptr) >> 12, - (EXTRACT_16BITS(tptr)) & 0x0fff)); + ND_PRINT((ndo, ", RES: %d, VID: %d", EXTRACT_BE_U_2(tptr) >> 12, + (EXTRACT_BE_U_2(tptr)) & 0x0fff)); tptr = tptr+2; len = len - 8; stlv_len = stlv_len - 8; while (stlv_len >= 4) { - ND_TCHECK2(*tptr, 4); + ND_TCHECK_4(tptr); ND_PRINT((ndo, "\n\t T: %d, R: %d, RES: %d, ISID: %d", - (EXTRACT_32BITS(tptr) >> 31), - (EXTRACT_32BITS(tptr) >> 30) & 0x01, - (EXTRACT_32BITS(tptr) >> 24) & 0x03f, - (EXTRACT_32BITS(tptr)) & 0x0ffffff)); + (EXTRACT_BE_U_4(tptr) >> 31), + (EXTRACT_BE_U_4(tptr) >> 30) & 0x01, + (EXTRACT_BE_U_4(tptr) >> 24) & 0x03f, + (EXTRACT_BE_U_4(tptr)) & 0x0ffffff)); tptr = tptr + 4; len = len - 4; @@ -1652,17 +1666,19 @@ isis_print_id(const uint8_t *cp, int id_len) if (sysid_len > id_len) sysid_len = id_len; for (i = 1; i <= sysid_len; i++) { - snprintf(pos, sizeof(id) - (pos - id), "%02x", *cp++); + snprintf(pos, sizeof(id) - (pos - id), "%02x", EXTRACT_U_1(cp)); + cp++; pos += strlen(pos); if (i == 2 || i == 4) *pos++ = '.'; } if (id_len >= NODE_ID_LEN) { - snprintf(pos, sizeof(id) - (pos - id), ".%02x", *cp++); + snprintf(pos, sizeof(id) - (pos - id), ".%02x", EXTRACT_U_1(cp)); + cp++; pos += strlen(pos); } if (id_len == LSP_ID_LEN) - snprintf(pos, sizeof(id) - (pos - id), "-%02x", *cp); + snprintf(pos, sizeof(id) - (pos - id), "-%02x", EXTRACT_U_1(cp)); return (id); } @@ -1710,7 +1726,7 @@ isis_print_tlv_ip_reach(netdissect_options *ndo, if (!ND_TTEST(*tlv_ip_reach)) return (0); - prefix_len = mask2plen(EXTRACT_32BITS(tlv_ip_reach->mask)); + prefix_len = mask2plen(EXTRACT_BE_U_4(tlv_ip_reach->mask)); if (prefix_len == -1) ND_PRINT((ndo, "%sIPv4 prefix: %s mask %s", @@ -1774,8 +1790,8 @@ isis_print_ip_reach_subtlv(netdissect_options *ndo, case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG32: while (subl >= 4) { ND_PRINT((ndo, ", 0x%08x (=%u)", - EXTRACT_32BITS(tptr), - EXTRACT_32BITS(tptr))); + EXTRACT_BE_U_4(tptr), + EXTRACT_BE_U_4(tptr))); tptr+=4; subl-=4; } @@ -1783,8 +1799,8 @@ isis_print_ip_reach_subtlv(netdissect_options *ndo, case ISIS_SUBTLV_EXTD_IP_REACH_ADMIN_TAG64: while (subl >= 8) { ND_PRINT((ndo, ", 0x%08x%08x", - EXTRACT_32BITS(tptr), - EXTRACT_32BITS(tptr+4))); + EXTRACT_BE_U_4(tptr), + EXTRACT_BE_U_4(tptr + 4))); tptr+=8; subl-=8; } @@ -1830,9 +1846,9 @@ isis_print_is_reach_subtlv(netdissect_options *ndo, case ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID: case ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID: if (subl >= 4) { - ND_PRINT((ndo, ", 0x%08x", EXTRACT_32BITS(tptr))); + ND_PRINT((ndo, ", 0x%08x", EXTRACT_BE_U_4(tptr))); if (subl == 8) /* rfc4205 */ - ND_PRINT((ndo, ", 0x%08x", EXTRACT_32BITS(tptr+4))); + ND_PRINT((ndo, ", 0x%08x", EXTRACT_BE_U_4(tptr + 4))); } break; case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR: @@ -1843,14 +1859,14 @@ isis_print_is_reach_subtlv(netdissect_options *ndo, case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW : case ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW: if (subl >= 4) { - bw.i = EXTRACT_32BITS(tptr); + bw.i = EXTRACT_BE_U_4(tptr); ND_PRINT((ndo, ", %.3f Mbps", bw.f * 8 / 1000000)); } break; case ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW : if (subl >= 32) { for (te_class = 0; te_class < 8; te_class++) { - bw.i = EXTRACT_32BITS(tptr); + bw.i = EXTRACT_BE_U_4(tptr); ND_PRINT((ndo, "%s TE-Class %u: %.3f Mbps", ident, te_class, @@ -1861,15 +1877,16 @@ isis_print_is_reach_subtlv(netdissect_options *ndo, break; case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS: /* fall through */ case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD: + if (subl == 0) + break; ND_PRINT((ndo, "%sBandwidth Constraints Model ID: %s (%u)", ident, - tok2str(diffserv_te_bc_values, "unknown", *tptr), - *tptr)); + tok2str(diffserv_te_bc_values, "unknown", EXTRACT_U_1(tptr)), + EXTRACT_U_1(tptr))); tptr++; /* decode BCs until the subTLV ends */ for (te_class = 0; te_class < (subl-1)/4; te_class++) { - ND_TCHECK2(*tptr, 4); - bw.i = EXTRACT_32BITS(tptr); + bw.i = EXTRACT_BE_U_4(tptr); ND_PRINT((ndo, "%s Bandwidth constraint CT%u: %.3f Mbps", ident, te_class, @@ -1879,45 +1896,45 @@ isis_print_is_reach_subtlv(netdissect_options *ndo, break; case ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC: if (subl >= 3) - ND_PRINT((ndo, ", %u", EXTRACT_24BITS(tptr))); + ND_PRINT((ndo, ", %u", EXTRACT_BE_U_3(tptr))); break; case ISIS_SUBTLV_EXT_IS_REACH_LINK_ATTRIBUTE: if (subl == 2) { ND_PRINT((ndo, ", [ %s ] (0x%04x)", bittok2str(isis_subtlv_link_attribute_values, "Unknown", - EXTRACT_16BITS(tptr)), - EXTRACT_16BITS(tptr))); + EXTRACT_BE_U_2(tptr)), + EXTRACT_BE_U_2(tptr))); } break; case ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE: if (subl >= 2) { ND_PRINT((ndo, ", %s, Priority %u", - bittok2str(gmpls_link_prot_values, "none", *tptr), - *(tptr+1))); + bittok2str(gmpls_link_prot_values, "none", EXTRACT_U_1(tptr)), + EXTRACT_U_1(tptr + 1))); } break; case ISIS_SUBTLV_SPB_METRIC: if (subl >= 6) { - ND_PRINT((ndo, ", LM: %u", EXTRACT_24BITS(tptr))); + ND_PRINT((ndo, ", LM: %u", EXTRACT_BE_U_3(tptr))); tptr=tptr+3; - ND_PRINT((ndo, ", P: %u", *(tptr))); + ND_PRINT((ndo, ", P: %u", EXTRACT_U_1(tptr))); tptr++; - ND_PRINT((ndo, ", P-ID: %u", EXTRACT_16BITS(tptr))); + ND_PRINT((ndo, ", P-ID: %u", EXTRACT_BE_U_2(tptr))); } break; case ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR: if (subl >= 36) { - gmpls_switch_cap = *tptr; + gmpls_switch_cap = EXTRACT_U_1(tptr); ND_PRINT((ndo, "%s Interface Switching Capability:%s", ident, tok2str(gmpls_switch_cap_values, "Unknown", gmpls_switch_cap))); ND_PRINT((ndo, ", LSP Encoding: %s", - tok2str(gmpls_encoding_values, "Unknown", *(tptr + 1)))); + tok2str(gmpls_encoding_values, "Unknown", EXTRACT_U_1((tptr + 1))))); tptr+=4; ND_PRINT((ndo, "%s Max LSP Bandwidth:", ident)); for (priority_level = 0; priority_level < 8; priority_level++) { - bw.i = EXTRACT_32BITS(tptr); + bw.i = EXTRACT_BE_U_4(tptr); ND_PRINT((ndo, "%s priority level %d: %.3f Mbps", ident, priority_level, @@ -1930,17 +1947,19 @@ isis_print_is_reach_subtlv(netdissect_options *ndo, case GMPLS_PSC2: case GMPLS_PSC3: case GMPLS_PSC4: - ND_TCHECK2(*tptr, 6); - bw.i = EXTRACT_32BITS(tptr); + if (subl < 6) + break; + bw.i = EXTRACT_BE_U_4(tptr); ND_PRINT((ndo, "%s Min LSP Bandwidth: %.3f Mbps", ident, bw.f * 8 / 1000000)); - ND_PRINT((ndo, "%s Interface MTU: %u", ident, EXTRACT_16BITS(tptr + 4))); + ND_PRINT((ndo, "%s Interface MTU: %u", ident, EXTRACT_BE_U_2(tptr + 4))); break; case GMPLS_TSC: - ND_TCHECK2(*tptr, 8); - bw.i = EXTRACT_32BITS(tptr); + if (subl < 8) + break; + bw.i = EXTRACT_BE_U_4(tptr); ND_PRINT((ndo, "%s Min LSP Bandwidth: %.3f Mbps", ident, bw.f * 8 / 1000000)); ND_PRINT((ndo, "%s Indication %s", ident, - tok2str(gmpls_switch_cap_tsc_indication_values, "Unknown (%u)", *(tptr + 4)))); + tok2str(gmpls_switch_cap_tsc_indication_values, "Unknown (%u)", EXTRACT_U_1((tptr + 4))))); break; default: /* there is some optional stuff left to decode but this is as of yet @@ -1980,27 +1999,29 @@ isis_print_ext_is_reach(netdissect_options *ndo, return(0); ND_PRINT((ndo, "%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN))); - tptr+=(NODE_ID_LEN); + tptr+=NODE_ID_LEN; if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */ - if (!ND_TTEST2(*tptr, 3)) /* and is therefore skipped */ + if (!ND_TTEST_3(tptr)) /* and is therefore skipped */ return(0); - ND_PRINT((ndo, ", Metric: %d", EXTRACT_24BITS(tptr))); + ND_PRINT((ndo, ", Metric: %d", EXTRACT_BE_U_3(tptr))); tptr+=3; } - if (!ND_TTEST2(*tptr, 1)) + if (!ND_TTEST_1(tptr)) return(0); - subtlv_sum_len=*(tptr++); /* read out subTLV length */ + subtlv_sum_len=EXTRACT_U_1(tptr); /* read out subTLV length */ + tptr++; proc_bytes=NODE_ID_LEN+3+1; ND_PRINT((ndo, ", %ssub-TLVs present",subtlv_sum_len ? "" : "no ")); if (subtlv_sum_len) { ND_PRINT((ndo, " (%u)", subtlv_sum_len)); while (subtlv_sum_len>0) { - if (!ND_TTEST2(*tptr,2)) + if (!ND_TTEST_2(tptr)) return(0); - subtlv_type=*(tptr++); - subtlv_len=*(tptr++); + subtlv_type=EXTRACT_U_1(tptr); + subtlv_len=EXTRACT_U_1(tptr + 1); + tptr+=2; /* prepend the indent string */ snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); if (!isis_print_is_reach_subtlv(ndo, tptr, subtlv_type, subtlv_len, ident_buffer)) @@ -2022,18 +2043,18 @@ static int isis_print_mtid(netdissect_options *ndo, const uint8_t *tptr, const char *ident) { - if (!ND_TTEST2(*tptr, 2)) + if (!ND_TTEST_2(tptr)) return(0); ND_PRINT((ndo, "%s%s", ident, tok2str(isis_mt_values, "Reserved for IETF Consensus", - ISIS_MASK_MTID(EXTRACT_16BITS(tptr))))); + ISIS_MASK_MTID(EXTRACT_BE_U_2(tptr))))); ND_PRINT((ndo, " Topology (0x%03x), Flags: [%s]", - ISIS_MASK_MTID(EXTRACT_16BITS(tptr)), - bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr))))); + ISIS_MASK_MTID(EXTRACT_BE_U_2(tptr)), + bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_BE_U_2(tptr))))); return(2); } @@ -2053,16 +2074,17 @@ isis_print_extd_ip_reach(netdissect_options *ndo, uint8_t prefix[sizeof(struct in6_addr)]; /* shared copy buffer for IPv4 and IPv6 prefixes */ u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen; - if (!ND_TTEST2(*tptr, 4)) + if (!ND_TTEST_4(tptr)) return (0); - metric = EXTRACT_32BITS(tptr); + metric = EXTRACT_BE_U_4(tptr); processed=4; tptr+=4; if (afi == AF_INET) { - if (!ND_TTEST2(*tptr, 1)) /* fetch status byte */ + if (!ND_TTEST_1(tptr)) /* fetch status byte */ return (0); - status_byte=*(tptr++); + status_byte=EXTRACT_U_1(tptr); + tptr++; bit_length = status_byte&0x3f; if (bit_length > 32) { ND_PRINT((ndo, "%sIPv4 prefix: bad bit length %u", @@ -2072,16 +2094,17 @@ isis_print_extd_ip_reach(netdissect_options *ndo, } processed++; } else if (afi == AF_INET6) { - if (!ND_TTEST2(*tptr, 2)) /* fetch status & prefix_len byte */ + if (!ND_TTEST_2(tptr)) /* fetch status & prefix_len byte */ return (0); - status_byte=*(tptr++); - bit_length=*(tptr++); + status_byte=EXTRACT_U_1(tptr); + bit_length=EXTRACT_U_1(tptr + 1); if (bit_length > 128) { ND_PRINT((ndo, "%sIPv6 prefix: bad bit length %u", ident, bit_length)); return (0); } + tptr+=2; processed+=2; } else return (0); /* somebody is fooling us */ @@ -2124,17 +2147,19 @@ isis_print_extd_ip_reach(netdissect_options *ndo, than one subTLV - therefore the first byte must reflect the aggregate bytecount of the subTLVs for this prefix */ - if (!ND_TTEST2(*tptr, 1)) + if (!ND_TTEST_1(tptr)) return (0); - sublen=*(tptr++); + sublen=EXTRACT_U_1(tptr); + tptr++; processed+=sublen+1; ND_PRINT((ndo, " (%u)", sublen)); /* print out subTLV length */ while (sublen>0) { - if (!ND_TTEST2(*tptr,2)) + if (!ND_TTEST_2(tptr)) return (0); - subtlvtype=*(tptr++); - subtlvlen=*(tptr++); + subtlvtype=EXTRACT_U_1(tptr); + subtlvlen=EXTRACT_U_1(tptr + 1); + tptr+=2; /* prepend the indent string */ snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); if (!isis_print_ip_reach_subtlv(ndo, tptr, subtlvtype, subtlvlen, ident_buffer)) @@ -2184,6 +2209,7 @@ isis_print(netdissect_options *ndo, uint8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len; uint8_t ext_is_len, ext_ip_len, mt_len; + uint8_t isis_subtlv_idrp; const uint8_t *optr, *pptr, *tptr; u_short packet_len,pdu_len, key_id; u_int i,vendor_id; @@ -2326,7 +2352,7 @@ isis_print(netdissect_options *ndo, ND_PRINT((ndo, ", length %u", length)); return (1); } - pdu_len=EXTRACT_16BITS(header_iih_lan->pdu_len); + pdu_len=EXTRACT_BE_U_2(header_iih_lan->pdu_len); if (packet_len>pdu_len) { packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ length=pdu_len; @@ -2334,7 +2360,7 @@ isis_print(netdissect_options *ndo, ND_PRINT((ndo, "\n\t source-id: %s, holding time: %us, Flags: [%s]", isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN), - EXTRACT_16BITS(header_iih_lan->holding_time), + EXTRACT_BE_U_2(header_iih_lan->holding_time), tok2str(isis_iih_circuit_type_values, "unknown circuit type 0x%02x", header_iih_lan->circuit_type))); @@ -2367,7 +2393,7 @@ isis_print(netdissect_options *ndo, ND_PRINT((ndo, ", length %u", length)); return (1); } - pdu_len=EXTRACT_16BITS(header_iih_ptp->pdu_len); + pdu_len=EXTRACT_BE_U_2(header_iih_ptp->pdu_len); if (packet_len>pdu_len) { packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ length=pdu_len; @@ -2375,7 +2401,7 @@ isis_print(netdissect_options *ndo, ND_PRINT((ndo, "\n\t source-id: %s, holding time: %us, Flags: [%s]", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN), - EXTRACT_16BITS(header_iih_ptp->holding_time), + EXTRACT_BE_U_2(header_iih_ptp->holding_time), tok2str(isis_iih_circuit_type_values, "unknown circuit type 0x%02x", header_iih_ptp->circuit_type))); @@ -2406,12 +2432,12 @@ isis_print(netdissect_options *ndo, if (ndo->ndo_vflag == 0) { ND_PRINT((ndo, ", lsp-id %s, seq 0x%08x, lifetime %5us", isis_print_id(header_lsp->lsp_id, LSP_ID_LEN), - EXTRACT_32BITS(header_lsp->sequence_number), - EXTRACT_16BITS(header_lsp->remaining_lifetime))); + EXTRACT_BE_U_4(header_lsp->sequence_number), + EXTRACT_BE_U_2(header_lsp->remaining_lifetime))); ND_PRINT((ndo, ", length %u", length)); return (1); } - pdu_len=EXTRACT_16BITS(header_lsp->pdu_len); + pdu_len=EXTRACT_BE_U_2(header_lsp->pdu_len); if (packet_len>pdu_len) { packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ length=pdu_len; @@ -2419,12 +2445,12 @@ isis_print(netdissect_options *ndo, ND_PRINT((ndo, "\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t chksum: 0x%04x", isis_print_id(header_lsp->lsp_id, LSP_ID_LEN), - EXTRACT_32BITS(header_lsp->sequence_number), - EXTRACT_16BITS(header_lsp->remaining_lifetime), - EXTRACT_16BITS(header_lsp->checksum))); + EXTRACT_BE_U_4(header_lsp->sequence_number), + EXTRACT_BE_U_2(header_lsp->remaining_lifetime), + EXTRACT_BE_U_2(header_lsp->checksum))); osi_print_cksum(ndo, (const uint8_t *)header_lsp->lsp_id, - EXTRACT_16BITS(header_lsp->checksum), + EXTRACT_BE_U_2(header_lsp->checksum), 12, length-12); ND_PRINT((ndo, ", PDU length: %u, Flags: [ %s", @@ -2466,7 +2492,7 @@ isis_print(netdissect_options *ndo, ND_PRINT((ndo, ", length %u", length)); return (1); } - pdu_len=EXTRACT_16BITS(header_csnp->pdu_len); + pdu_len=EXTRACT_BE_U_2(header_csnp->pdu_len); if (packet_len>pdu_len) { packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ length=pdu_len; @@ -2504,7 +2530,7 @@ isis_print(netdissect_options *ndo, ND_PRINT((ndo, ", length %u", length)); return (1); } - pdu_len=EXTRACT_16BITS(header_psnp->pdu_len); + pdu_len=EXTRACT_BE_U_2(header_psnp->pdu_len); if (packet_len>pdu_len) { packet_len=pdu_len; /* do TLV decoding as long as it makes sense */ length=pdu_len; @@ -2537,14 +2563,15 @@ isis_print(netdissect_options *ndo, */ while (packet_len > 0) { - ND_TCHECK2(*pptr, 2); + ND_TCHECK_2(pptr); if (packet_len < 2) goto trunc; - tlv_type = *pptr++; - tlv_len = *pptr++; + tlv_type = EXTRACT_U_1(pptr); + tlv_len = EXTRACT_U_1(pptr + 1); + pptr += 2; + packet_len -= 2; tmp =tlv_len; /* copy temporary len & pointer to packet data */ tptr = pptr; - packet_len -= 2; /* first lets see if we know the TLVs name*/ ND_PRINT((ndo, "\n\t %s TLV #%u, length: %u", @@ -2563,8 +2590,9 @@ isis_print(netdissect_options *ndo, /* now check if we have a decoder otherwise do a hexdump at the end*/ switch (tlv_type) { case ISIS_TLV_AREA_ADDR: - ND_TCHECK2(*tptr, 1); - alen = *tptr++; + ND_TCHECK_1(tptr); + alen = EXTRACT_U_1(tptr); + tptr++; while (tmp && alen < tmp) { ND_TCHECK2(*tptr, alen); ND_PRINT((ndo, "\n\t Area address (length: %u): %s", @@ -2574,8 +2602,9 @@ isis_print(netdissect_options *ndo, tmp -= alen + 1; if (tmp==0) /* if this is the last area address do not attemt a boundary check */ break; - ND_TCHECK2(*tptr, 1); - alen = *tptr++; + ND_TCHECK_1(tptr); + alen = EXTRACT_U_1(tptr); + tptr++; } break; case ISIS_TLV_ISNEIGH: @@ -2588,9 +2617,10 @@ isis_print(netdissect_options *ndo, break; case ISIS_TLV_ISNEIGH_VARLEN: - if (!ND_TTEST2(*tptr, 1) || tmp < 3) /* min. TLV length */ + if (!ND_TTEST_1(tptr) || tmp < 3) /* min. TLV length */ goto trunctlv; - lan_alen = *tptr++; /* LAN address length */ + lan_alen = EXTRACT_U_1(tptr); /* LAN address length */ + tptr++; if (lan_alen == 0) { ND_PRINT((ndo, "\n\t LAN address length 0 bytes (invalid)")); break; @@ -2644,11 +2674,12 @@ isis_print(netdissect_options *ndo, } break; case ISIS_TLV_IS_REACH: - ND_TCHECK2(*tptr,1); /* check if there is one byte left to read out the virtual flag */ + ND_TCHECK_1(tptr); /* check if there is one byte left to read out the virtual flag */ ND_PRINT((ndo, "\n\t %s", tok2str(isis_is_reach_virtual_values, "bogus virtual flag 0x%02x", - *tptr++))); + EXTRACT_U_1(tptr)))); + tptr++; tlv_is_reach = (const struct isis_tlv_is_reach *)tptr; while (tmp >= sizeof(struct isis_tlv_is_reach)) { ND_TCHECK(*tlv_is_reach); @@ -2745,22 +2776,22 @@ isis_print(netdissect_options *ndo, } break; case ISIS_TLV_AUTH: - ND_TCHECK2(*tptr, 1); + ND_TCHECK_1(tptr); ND_PRINT((ndo, "\n\t %s: ", tok2str(isis_subtlv_auth_values, "unknown Authentication type 0x%02x", - *tptr))); + EXTRACT_U_1(tptr)))); - switch (*tptr) { + switch (EXTRACT_U_1(tptr)) { case ISIS_SUBTLV_AUTH_SIMPLE: if (fn_printzp(ndo, tptr + 1, tlv_len - 1, ndo->ndo_snapend)) goto trunctlv; break; case ISIS_SUBTLV_AUTH_MD5: for(i=1;i=1) { - ND_TCHECK2(*tptr, 1); + ND_TCHECK_1(tptr); ND_PRINT((ndo, "\n\t Adjacency State: %s (%u)", - tok2str(isis_ptp_adjancey_values, "unknown", *tptr), - *tptr)); + tok2str(isis_ptp_adjancey_values, "unknown", EXTRACT_U_1(tptr)), + EXTRACT_U_1(tptr))); tmp--; } if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) { ND_TCHECK(tlv_ptp_adj->extd_local_circuit_id); ND_PRINT((ndo, "\n\t Extended Local circuit-ID: 0x%08x", - EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id))); + EXTRACT_BE_U_4(tlv_ptp_adj->extd_local_circuit_id))); tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id); } if(tmp>=SYSTEM_ID_LEN) { @@ -2812,19 +2843,19 @@ isis_print(netdissect_options *ndo, if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) { ND_TCHECK(tlv_ptp_adj->neighbor_extd_local_circuit_id); ND_PRINT((ndo, "\n\t Neighbor Extended Local circuit-ID: 0x%08x", - EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id))); + EXTRACT_BE_U_4(tlv_ptp_adj->neighbor_extd_local_circuit_id))); } break; case ISIS_TLV_PROTOCOLS: ND_PRINT((ndo, "\n\t NLPID(s): ")); while (tmp>0) { - ND_TCHECK2(*(tptr), 1); + ND_TCHECK_1(tptr); ND_PRINT((ndo, "%s (0x%02x)", tok2str(nlpid_values, "unknown", - *tptr), - *tptr)); + EXTRACT_U_1(tptr)), + EXTRACT_U_1(tptr))); if (tmp>1) /* further NPLIDs ? - put comma */ ND_PRINT((ndo, ", ")); tptr++; @@ -2834,11 +2865,11 @@ isis_print(netdissect_options *ndo, case ISIS_TLV_MT_PORT_CAP: { - ND_TCHECK2(*(tptr), 2); + ND_TCHECK_2(tptr); ND_PRINT((ndo, "\n\t RES: %d, MTID(s): %d", - (EXTRACT_16BITS (tptr) >> 12), - (EXTRACT_16BITS (tptr) & 0x0fff))); + (EXTRACT_BE_U_2(tptr) >> 12), + (EXTRACT_BE_U_2(tptr) & 0x0fff))); tmp = tmp-2; tptr = tptr+2; @@ -2851,12 +2882,12 @@ isis_print(netdissect_options *ndo, case ISIS_TLV_MT_CAPABILITY: - ND_TCHECK2(*(tptr), 2); + ND_TCHECK_2(tptr); ND_PRINT((ndo, "\n\t O: %d, RES: %d, MTID(s): %d", - (EXTRACT_16BITS(tptr) >> 15) & 0x01, - (EXTRACT_16BITS(tptr) >> 12) & 0x07, - EXTRACT_16BITS(tptr) & 0x0fff)); + (EXTRACT_BE_U_2(tptr) >> 15) & 0x01, + (EXTRACT_BE_U_2(tptr) >> 12) & 0x07, + EXTRACT_BE_U_2(tptr) & 0x0fff)); tmp = tmp-2; tptr = tptr+2; @@ -2891,13 +2922,14 @@ isis_print(netdissect_options *ndo, break; ND_TCHECK2(*tptr, NODE_ID_LEN); ND_PRINT((ndo, "\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN))); - tptr+=(NODE_ID_LEN); - tmp-=(NODE_ID_LEN); + tptr+=NODE_ID_LEN; + tmp-=NODE_ID_LEN; if (tmp < 1) break; - ND_TCHECK2(*tptr, 1); - ND_PRINT((ndo, ", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered")); + ND_TCHECK_1(tptr); + ND_PRINT((ndo, ", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(EXTRACT_U_1(tptr)) ? "numbered" : "unnumbered")); + tptr++; tmp--; if (tmp < sizeof(struct in_addr)) @@ -2915,8 +2947,8 @@ isis_print(netdissect_options *ndo, tmp-=sizeof(struct in_addr); while (tmp>=4) { - ND_TCHECK2(*tptr, 4); - ND_PRINT((ndo, "\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr))); + ND_TCHECK_4(tptr); + ND_PRINT((ndo, "\n\t Link-ID: 0x%08x", EXTRACT_BE_U_4(tptr))); tptr+=4; tmp-=4; } @@ -2929,11 +2961,11 @@ isis_print(netdissect_options *ndo, ND_PRINT((ndo, "\n\t lsp-id: %s", isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN))); ND_TCHECK2(tlv_lsp->sequence_number, 4); - ND_PRINT((ndo, ", seq: 0x%08x", EXTRACT_32BITS(tlv_lsp->sequence_number))); + ND_PRINT((ndo, ", seq: 0x%08x", EXTRACT_BE_U_4(tlv_lsp->sequence_number))); ND_TCHECK2(tlv_lsp->remaining_lifetime, 2); - ND_PRINT((ndo, ", lifetime: %5ds", EXTRACT_16BITS(tlv_lsp->remaining_lifetime))); + ND_PRINT((ndo, ", lifetime: %5ds", EXTRACT_BE_U_2(tlv_lsp->remaining_lifetime))); ND_TCHECK2(tlv_lsp->checksum, 2); - ND_PRINT((ndo, ", chksum: 0x%04x", EXTRACT_16BITS(tlv_lsp->checksum))); + ND_PRINT((ndo, ", chksum: 0x%04x", EXTRACT_BE_U_2(tlv_lsp->checksum))); tmp-=sizeof(struct isis_tlv_lsp); tlv_lsp++; } @@ -2943,14 +2975,14 @@ isis_print(netdissect_options *ndo, if (tmp < ISIS_TLV_CHECKSUM_MINLEN) break; ND_TCHECK2(*tptr, ISIS_TLV_CHECKSUM_MINLEN); - ND_PRINT((ndo, "\n\t checksum: 0x%04x ", EXTRACT_16BITS(tptr))); + ND_PRINT((ndo, "\n\t checksum: 0x%04x ", EXTRACT_BE_U_2(tptr))); /* do not attempt to verify the checksum if it is zero * most likely a HMAC-MD5 TLV is also present and * to avoid conflicts the checksum TLV is zeroed. * see rfc3358 for details */ - osi_print_cksum(ndo, optr, EXTRACT_16BITS(tptr), tptr-optr, - length); + osi_print_cksum(ndo, optr, EXTRACT_BE_U_2(tptr), tptr-optr, + length); break; case ISIS_TLV_POI: @@ -2992,7 +3024,7 @@ isis_print(netdissect_options *ndo, break; ND_TCHECK2(*tptr, ISIS_TLV_RESTART_SIGNALING_FLAGLEN); ND_PRINT((ndo, "\n\t Flags [%s]", - bittok2str(isis_restart_flag_values, "none", *tptr))); + bittok2str(isis_restart_flag_values, "none", EXTRACT_U_1(tptr)))); tptr+=ISIS_TLV_RESTART_SIGNALING_FLAGLEN; tmp-=ISIS_TLV_RESTART_SIGNALING_FLAGLEN; @@ -3004,7 +3036,7 @@ isis_print(netdissect_options *ndo, break; ND_TCHECK2(*tptr, ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN); - ND_PRINT((ndo, ", Remaining holding time %us", EXTRACT_16BITS(tptr))); + ND_PRINT((ndo, ", Remaining holding time %us", EXTRACT_BE_U_2(tptr))); tptr+=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN; tmp-=ISIS_TLV_RESTART_SIGNALING_HOLDTIMELEN; @@ -3022,11 +3054,13 @@ isis_print(netdissect_options *ndo, ND_PRINT((ndo, "\n\t Inter-Domain Information Type: %s", tok2str(isis_subtlv_idrp_values, "Unknown (0x%02x)", - *tptr))); - switch (*tptr++) { + EXTRACT_U_1(tptr)))); + isis_subtlv_idrp = EXTRACT_U_1(tptr); + tptr++; + switch (isis_subtlv_idrp) { case ISIS_SUBTLV_IDRP_ASN: - ND_TCHECK2(*tptr, 2); /* fetch AS number */ - ND_PRINT((ndo, "AS Number: %u", EXTRACT_16BITS(tptr))); + ND_TCHECK_2(tptr); /* fetch AS number */ + ND_PRINT((ndo, "AS Number: %u", EXTRACT_BE_U_2(tptr))); break; case ISIS_SUBTLV_IDRP_LOCAL: case ISIS_SUBTLV_IDRP_RES: @@ -3041,7 +3075,7 @@ isis_print(netdissect_options *ndo, if (tmp < ISIS_TLV_LSP_BUFFERSIZE_MINLEN) break; ND_TCHECK2(*tptr, ISIS_TLV_LSP_BUFFERSIZE_MINLEN); - ND_PRINT((ndo, "\n\t LSP Buffersize: %u", EXTRACT_16BITS(tptr))); + ND_PRINT((ndo, "\n\t LSP Buffersize: %u", EXTRACT_BE_U_2(tptr))); break; case ISIS_TLV_PART_DIS: @@ -3063,8 +3097,9 @@ isis_print(netdissect_options *ndo, tmp-=sizeof(struct isis_metric_block); while(tmp>0) { - ND_TCHECK2(*tptr, 1); - prefix_len=*tptr++; /* read out prefix length in semioctets*/ + ND_TCHECK_1(tptr); + prefix_len=EXTRACT_U_1(tptr); /* read out prefix length in semioctets*/ + tptr++; if (prefix_len < 2) { ND_PRINT((ndo, "\n\t\tAddress: prefix length %u < 2", prefix_len)); break; @@ -3084,14 +3119,14 @@ isis_print(netdissect_options *ndo, if (tmp < ISIS_TLV_IIH_SEQNR_MINLEN) break; ND_TCHECK2(*tptr, ISIS_TLV_IIH_SEQNR_MINLEN); /* check if four bytes are on the wire */ - ND_PRINT((ndo, "\n\t Sequence number: %u", EXTRACT_32BITS(tptr))); + ND_PRINT((ndo, "\n\t Sequence number: %u", EXTRACT_BE_U_4(tptr))); break; case ISIS_TLV_VENDOR_PRIVATE: if (tmp < ISIS_TLV_VENDOR_PRIVATE_MINLEN) break; ND_TCHECK2(*tptr, ISIS_TLV_VENDOR_PRIVATE_MINLEN); /* check if enough byte for a full oui */ - vendor_id = EXTRACT_24BITS(tptr); + vendor_id = EXTRACT_BE_U_3(tptr); ND_PRINT((ndo, "\n\t Vendor: %s (%u)", tok2str(oui_values, "Unknown", vendor_id), vendor_id)); @@ -3156,7 +3191,7 @@ osi_print_cksum(netdissect_options *ndo, const uint8_t *pptr, */ if (!checksum || checksum_offset < 0 - || !ND_TTEST2(*(pptr + checksum_offset), 2) + || !ND_TTEST_2(pptr + checksum_offset) || (u_int)checksum_offset > length || !ND_TTEST2(*pptr, length)) { ND_PRINT((ndo, " (unverified)"));