X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/6e15ad4b99382ef8223d8262abeb5c28b235d790..a8abce5c5e2dce2ba6dbccd5d3829da104b80f9c:/print-isoclns.c?ds=sidebyside diff --git a/print-isoclns.c b/print-isoclns.c index 5b1f9a4e..b9935ebd 100644 --- a/print-isoclns.c +++ b/print-isoclns.c @@ -29,7 +29,7 @@ /* * specification: * - * CLNP: ISO 8473 + * CLNP: ISO 8473 (respective ITU version is at http://www.itu.int/rec/T-REC-X.233/en/) * ES-IS: ISO 9542 * IS-IS: ISO 10589 */ @@ -50,7 +50,6 @@ #include "oui.h" #include "signature.h" -static const char tstr[] = " [|isis]"; /* * IS-IS is defined in ISO 10589. Look there for protocol definitions. @@ -677,12 +676,10 @@ struct isis_tlv_lsp { #define ISIS_PSNP_HEADER_SIZE (sizeof(struct isis_psnp_header)) void -isoclns_print(netdissect_options *ndo, const uint8_t *p, u_int length) +isoclns_print(netdissect_options *ndo, const u_char *p, u_int length) { - if (!ND_TTEST_1(p)) { /* enough bytes on the wire ? */ - ND_PRINT("|OSI"); - return; - } + ndo->ndo_protocol = "isoclns"; + ND_TCHECK_1(p); /* enough bytes on the wire ? */ if (ndo->ndo_eflag) ND_PRINT("OSI NLPID %s (0x%02x): ", tok2str(nlpid_values, "Unknown", EXTRACT_U_1(p)), EXTRACT_U_1(p)); @@ -731,6 +728,9 @@ isoclns_print(netdissect_options *ndo, const uint8_t *p, u_int length) print_unknown_data(ndo, p, "\n\t", length); break; } + return; +trunc: + nd_print_trunc(ndo); } #define CLNP_PDU_ER 1 @@ -779,6 +779,7 @@ clnp_print(netdissect_options *ndo, const struct clnp_segment_header_t *clnp_segment_header; uint8_t rfd_error,rfd_error_major,rfd_error_minor; + ndo->ndo_protocol = "clnp"; clnp_header = (const struct clnp_header_t *) pptr; ND_TCHECK_SIZE(clnp_header); @@ -902,7 +903,7 @@ clnp_print(netdissect_options *ndo, } /* now walk the options */ - while (li_remaining >= 2) { + while (li_remaining != 0) { u_int op, opli; const uint8_t *tptr; @@ -1057,6 +1058,18 @@ clnp_print(netdissect_options *ndo, break; } + /* The cases above break from the switch block if they see and print + * a CLNP header in the Data part. For an Error Report PDU this is + * described in Section 7.9.6 of ITU X.233 (1997 E), also known as + * ISO/IEC 8473-1:1998(E). It is not clear why in this code the same + * applies to an Echo Response PDU, as the standard does not specify + * the contents -- could be a proprietary extension or a bug. In either + * case, if the Data part does not contain a CLNP header, its structure + * is considered unknown and the decoding falls through to print the + * contents as-is. + */ + ND_FALL_THROUGH; + case CLNP_PDU_DT: case CLNP_PDU_MD: case CLNP_PDU_ERQ: @@ -1072,7 +1085,7 @@ clnp_print(netdissect_options *ndo, return (1); trunc: - ND_PRINT("[|clnp]"); + nd_print_trunc(ndo); return (1); } @@ -1107,6 +1120,7 @@ esis_print(netdissect_options *ndo, u_int li, version, esis_pdu_type, source_address_length, source_address_number; const struct esis_header_t *esis_header; + ndo->ndo_protocol = "esis"; if (!ndo->ndo_eflag) ND_PRINT("ES-IS"); @@ -1384,8 +1398,10 @@ esis_print(netdissect_options *ndo, print_unknown_data(ndo, pptr, "\n\t ", opli); pptr += opli; } + return; + trunc: - ND_PRINT("[|esis]"); + nd_print_trunc(ndo); } static void @@ -1397,7 +1413,7 @@ isis_print_mcid(netdissect_options *ndo, ND_TCHECK_SIZE(mcid); ND_PRINT("ID: %u, Name: ", EXTRACT_U_1(mcid->format_id)); - if (fn_printzp(ndo, mcid->name, 32, ndo->ndo_snapend)) + if (nd_printzp(ndo, mcid->name, 32, ndo->ndo_snapend)) goto trunc; ND_PRINT("\n\t Lvl: %u", EXTRACT_BE_U_2(mcid->revision_lvl)); @@ -1406,9 +1422,10 @@ isis_print_mcid(netdissect_options *ndo, for(i=0;i<16;i++) ND_PRINT("%.2x ", mcid->digest[i]); + return; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); } static int @@ -1529,8 +1546,7 @@ isis_print_mt_port_cap_subtlv(netdissect_options *ndo, return 0; trunc: - ND_PRINT("\n\t\t"); - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return(1); } @@ -1658,8 +1674,7 @@ isis_print_mt_capability_subtlv(netdissect_options *ndo, return 0; trunc: - ND_PRINT("\n\t\t"); - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return(1); } @@ -1676,19 +1691,19 @@ isis_print_id(const uint8_t *cp, u_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", EXTRACT_U_1(cp)); + nd_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", EXTRACT_U_1(cp)); + nd_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", EXTRACT_U_1(cp)); + nd_snprintf(pos, sizeof(id) - (pos - id), "-%02x", EXTRACT_U_1(cp)); return (id); } @@ -1823,8 +1838,7 @@ isis_print_ip_reach_subtlv(netdissect_options *ndo, return(1); trunc: - ND_PRINT("%s", ident); - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return(0); } @@ -1878,7 +1892,7 @@ isis_print_ext_is_reach(netdissect_options *ndo, if (subtlv_sum_len) { ND_PRINT(" (%u)", subtlv_sum_len); /* prepend the indent string */ - snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); + nd_snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); ident = ident_buffer; while (subtlv_sum_len != 0) { if (!ND_TTEST_2(tptr)) @@ -1929,7 +1943,7 @@ isis_print_ext_is_reach(netdissect_options *ndo, break; case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR: case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR: - if (subtlv_len >= sizeof(struct in_addr)) + if (subtlv_len >= sizeof(nd_ipv4)) ND_PRINT(", %s", ipaddr_string(ndo, tptr)); break; case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW : @@ -2124,7 +2138,7 @@ isis_print_extd_ip_reach(netdissect_options *ndo, const uint8_t *tptr, const char *ident, uint16_t afi) { char ident_buffer[20]; - uint8_t prefix[sizeof(struct in6_addr)]; /* shared copy buffer for IPv4 and IPv6 prefixes */ + uint8_t prefix[sizeof(nd_ipv6)]; /* shared copy buffer for IPv4 and IPv6 prefixes */ u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen; if (!ND_TTEST_4(tptr)) @@ -2166,7 +2180,7 @@ isis_print_extd_ip_reach(netdissect_options *ndo, if (!ND_TTEST_LEN(tptr, byte_length)) return (0); - memset(prefix, 0, sizeof prefix); /* clear the copy buffer */ + memset(prefix, 0, sizeof(prefix)); /* clear the copy buffer */ memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */ tptr+=byte_length; processed+=byte_length; @@ -2214,7 +2228,7 @@ isis_print_extd_ip_reach(netdissect_options *ndo, subtlvlen=EXTRACT_U_1(tptr + 1); tptr+=2; /* prepend the indent string */ - snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); + nd_snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident); if (!isis_print_ip_reach_subtlv(ndo, tptr, subtlvtype, subtlvlen, ident_buffer)) return(0); tptr+=subtlvlen; @@ -2269,6 +2283,7 @@ isis_print(netdissect_options *ndo, u_int i,vendor_id; int sigcheck; + ndo->ndo_protocol = "isis"; packet_len=length; optr = p; /* initialize the _o_riginal pointer to the packet start - need it for parsing the checksum TLV and authentication @@ -2678,7 +2693,7 @@ isis_print(netdissect_options *ndo, case ISIS_TLV_ISNEIGH_VARLEN: if (!ND_TTEST_1(tptr) || tmp < 3) /* min. TLV length */ - goto trunctlv; + goto trunc; lan_alen = EXTRACT_U_1(tptr); /* LAN address length */ tptr++; if (lan_alen == 0) { @@ -2701,13 +2716,13 @@ isis_print(netdissect_options *ndo, case ISIS_TLV_MT_IS_REACH: mt_len = isis_print_mtid(ndo, tptr, "\n\t "); if (mt_len == 0) /* did something go wrong ? */ - goto trunctlv; + goto trunc; tptr+=mt_len; tmp-=mt_len; while (tmp >= 2+NODE_ID_LEN+3+1) { ext_is_len = isis_print_ext_is_reach(ndo, tptr, "\n\t ", tlv_type, tmp); if (ext_is_len == 0) /* did something go wrong ? */ - goto trunctlv; + goto trunc; tmp-=ext_is_len; tptr+=ext_is_len; @@ -2718,7 +2733,7 @@ isis_print(netdissect_options *ndo, while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */ ext_is_len = isis_print_ext_is_reach(ndo, tptr, "\n\t ", tlv_type, tmp); if (ext_is_len == 0) /* did something go wrong ? */ - goto trunctlv; + goto trunc; tmp-=ext_is_len; tptr+=ext_is_len; } @@ -2728,7 +2743,7 @@ isis_print(netdissect_options *ndo, while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */ ext_is_len = isis_print_ext_is_reach(ndo, tptr, "\n\t ", tlv_type, tmp); if (ext_is_len == 0) /* did something go wrong ? */ - goto trunctlv; + goto trunc; tmp-=ext_is_len; tptr+=ext_is_len; } @@ -2774,7 +2789,7 @@ isis_print(netdissect_options *ndo, while (tmp>0) { ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t ", AF_INET); if (ext_ip_len == 0) /* did something go wrong ? */ - goto trunctlv; + goto trunc; tptr+=ext_ip_len; tmp-=ext_ip_len; } @@ -2783,7 +2798,7 @@ isis_print(netdissect_options *ndo, case ISIS_TLV_MT_IP_REACH: mt_len = isis_print_mtid(ndo, tptr, "\n\t "); if (mt_len == 0) { /* did something go wrong ? */ - goto trunctlv; + goto trunc; } tptr+=mt_len; tmp-=mt_len; @@ -2791,7 +2806,7 @@ isis_print(netdissect_options *ndo, while (tmp>0) { ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t ", AF_INET); if (ext_ip_len == 0) /* did something go wrong ? */ - goto trunctlv; + goto trunc; tptr+=ext_ip_len; tmp-=ext_ip_len; } @@ -2801,7 +2816,7 @@ isis_print(netdissect_options *ndo, while (tmp>0) { ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t ", AF_INET6); if (ext_ip_len == 0) /* did something go wrong ? */ - goto trunctlv; + goto trunc; tptr+=ext_ip_len; tmp-=ext_ip_len; } @@ -2810,7 +2825,7 @@ isis_print(netdissect_options *ndo, case ISIS_TLV_MT_IP6_REACH: mt_len = isis_print_mtid(ndo, tptr, "\n\t "); if (mt_len == 0) { /* did something go wrong ? */ - goto trunctlv; + goto trunc; } tptr+=mt_len; tmp-=mt_len; @@ -2818,21 +2833,21 @@ isis_print(netdissect_options *ndo, while (tmp>0) { ext_ip_len = isis_print_extd_ip_reach(ndo, tptr, "\n\t ", AF_INET6); if (ext_ip_len == 0) /* did something go wrong ? */ - goto trunctlv; + goto trunc; tptr+=ext_ip_len; tmp-=ext_ip_len; } break; case ISIS_TLV_IP6ADDR: - while (tmp>=sizeof(struct in6_addr)) { - ND_TCHECK_LEN(tptr, sizeof(struct in6_addr)); + while (tmp>=sizeof(nd_ipv6)) { + ND_TCHECK_LEN(tptr, sizeof(nd_ipv6)); ND_PRINT("\n\t IPv6 interface address: %s", ip6addr_string(ndo, tptr)); - tptr += sizeof(struct in6_addr); - tmp -= sizeof(struct in6_addr); + tptr += sizeof(nd_ipv6); + tmp -= sizeof(nd_ipv6); } break; case ISIS_TLV_AUTH: @@ -2845,8 +2860,8 @@ isis_print(netdissect_options *ndo, switch (EXTRACT_U_1(tptr)) { case ISIS_SUBTLV_AUTH_SIMPLE: - if (fn_printzp(ndo, tptr + 1, tlv_len - 1, ndo->ndo_snapend)) - goto trunctlv; + if (nd_printzp(ndo, tptr + 1, tlv_len - 1, ndo->ndo_snapend)) + goto trunc; break; case ISIS_SUBTLV_AUTH_MD5: for(i=1;i=sizeof(struct in_addr)) { - ND_TCHECK_LEN(tptr, sizeof(struct in_addr)); + while (tmp>=sizeof(nd_ipv4)) { + ND_TCHECK_LEN(tptr, sizeof(nd_ipv4)); ND_PRINT("\n\t IPv4 interface address: %s", ipaddr_string(ndo, tptr)); - tptr += sizeof(struct in_addr); - tmp -= sizeof(struct in_addr); + tptr += sizeof(nd_ipv4); + tmp -= sizeof(nd_ipv4); } break; case ISIS_TLV_HOSTNAME: ND_PRINT("\n\t Hostname: "); - if (fn_printzp(ndo, tptr, tmp, ndo->ndo_snapend)) - goto trunctlv; + if (nd_printzp(ndo, tptr, tmp, ndo->ndo_snapend)) + goto trunc; break; case ISIS_TLV_SHARED_RISK_GROUP: @@ -2992,19 +3007,19 @@ isis_print(netdissect_options *ndo, tptr++; tmp--; - if (tmp < sizeof(struct in_addr)) + if (tmp < sizeof(nd_ipv4)) break; - ND_TCHECK_LEN(tptr, sizeof(struct in_addr)); + ND_TCHECK_LEN(tptr, sizeof(nd_ipv4)); ND_PRINT("\n\t IPv4 interface address: %s", ipaddr_string(ndo, tptr)); - tptr+=sizeof(struct in_addr); - tmp-=sizeof(struct in_addr); + tptr+=sizeof(nd_ipv4); + tmp-=sizeof(nd_ipv4); - if (tmp < sizeof(struct in_addr)) + if (tmp < sizeof(nd_ipv4)) break; - ND_TCHECK_LEN(tptr, sizeof(struct in_addr)); + ND_TCHECK_LEN(tptr, sizeof(nd_ipv4)); ND_PRINT("\n\t IPv4 neighbor address: %s", ipaddr_string(ndo, tptr)); - tptr+=sizeof(struct in_addr); - tmp-=sizeof(struct in_addr); + tptr+=sizeof(nd_ipv4); + tmp-=sizeof(nd_ipv4); while (tmp>=4) { ND_TCHECK_4(tptr); @@ -3017,14 +3032,14 @@ isis_print(netdissect_options *ndo, case ISIS_TLV_LSP: tlv_lsp = (const struct isis_tlv_lsp *)tptr; while(tmp>=sizeof(struct isis_tlv_lsp)) { - ND_TCHECK((tlv_lsp->lsp_id)[LSP_ID_LEN-1]); + ND_TCHECK_1(tlv_lsp->lsp_id + LSP_ID_LEN - 1); ND_PRINT("\n\t lsp-id: %s", isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN)); - ND_TCHECK_LEN(tlv_lsp->sequence_number, 4); + ND_TCHECK_4(tlv_lsp->sequence_number); ND_PRINT(", seq: 0x%08x", EXTRACT_BE_U_4(tlv_lsp->sequence_number)); - ND_TCHECK_LEN(tlv_lsp->remaining_lifetime, 2); + ND_TCHECK_2(tlv_lsp->remaining_lifetime); ND_PRINT(", lifetime: %5ds", EXTRACT_BE_U_2(tlv_lsp->remaining_lifetime)); - ND_TCHECK_LEN(tlv_lsp->checksum, 2); + ND_TCHECK_2(tlv_lsp->checksum); ND_PRINT(", chksum: 0x%04x", EXTRACT_BE_U_2(tlv_lsp->checksum)); tmp-=sizeof(struct isis_tlv_lsp); tlv_lsp++; @@ -3068,7 +3083,7 @@ isis_print(netdissect_options *ndo, if (tmp!=1) { mt_len = isis_print_mtid(ndo, tptr, "\n\t "); if (mt_len == 0) /* did something go wrong ? */ - goto trunctlv; + goto trunc; tptr+=mt_len; tmp-=mt_len; } else { @@ -3229,14 +3244,9 @@ isis_print(netdissect_options *ndo, } return (1); - trunc: - ND_PRINT("%s", tstr); +trunc: + nd_print_trunc(ndo); return (1); - - trunctlv: - ND_PRINT("\n\t\t"); - ND_PRINT("%s", tstr); - return(1); } static void @@ -3267,10 +3277,3 @@ osi_print_cksum(netdissect_options *ndo, const uint8_t *pptr, } } } - -/* - * Local Variables: - * c-style: whitesmith - * c-basic-offset: 8 - * End: - */