+ break;
+ default:
+ if (!print_unknown_data(ndo, tptr, "\n\t\t ", subl))
+ return(0);
+ break;
+ }
+ return(1);
+
+trunc:
+ nd_print_trunc(ndo);
+ return(0);
+}
+
+/*
+ * this is the common IS-REACH decoder it is called
+ * from various EXTD-IS REACH style TLVs (22,24,222)
+ */
+
+static int
+isis_print_ext_is_reach(netdissect_options *ndo,
+ const uint8_t *tptr, const char *ident, u_int tlv_type,
+ u_int tlv_remaining)
+{
+ char ident_buffer[20];
+ u_int subtlv_type,subtlv_len,subtlv_sum_len;
+ int proc_bytes = 0; /* how many bytes did we process ? */
+ u_int te_class,priority_level,gmpls_switch_cap;
+ union { /* int to float conversion buffer for several subTLVs */
+ float f;
+ uint32_t i;
+ } bw;
+
+ ND_TCHECK_LEN(tptr, NODE_ID_LEN);
+ if (tlv_remaining < NODE_ID_LEN)
+ return(0);
+
+ ND_PRINT("%sIS Neighbor: %s", ident, isis_print_id(ndo, tptr, NODE_ID_LEN));
+ tptr+=NODE_ID_LEN;
+ tlv_remaining-=NODE_ID_LEN;
+ proc_bytes+=NODE_ID_LEN;
+
+ if (tlv_type != ISIS_TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */
+ ND_TCHECK_3(tptr);
+ if (tlv_remaining < 3)
+ return(0);
+ ND_PRINT(", Metric: %u", GET_BE_U_3(tptr));
+ tptr+=3;
+ tlv_remaining-=3;
+ proc_bytes+=3;
+ }
+
+ ND_TCHECK_1(tptr);
+ if (tlv_remaining < 1)
+ return(0);
+ subtlv_sum_len=GET_U_1(tptr); /* read out subTLV length */
+ tptr++;
+ tlv_remaining--;
+ proc_bytes++;
+ ND_PRINT(", %ssub-TLVs present",subtlv_sum_len ? "" : "no ");
+ if (subtlv_sum_len) {
+ ND_PRINT(" (%u)", subtlv_sum_len);
+ /* prepend the indent string */
+ snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
+ ident = ident_buffer;
+ while (subtlv_sum_len != 0) {
+ ND_TCHECK_2(tptr);
+ if (tlv_remaining < 2) {
+ ND_PRINT("%sRemaining data in TLV shorter than a subTLV header",ident);
+ proc_bytes += tlv_remaining;
+ break;
+ }
+ if (subtlv_sum_len < 2) {
+ ND_PRINT("%sRemaining data in subTLVs shorter than a subTLV header",ident);
+ proc_bytes += subtlv_sum_len;
+ break;
+ }
+ subtlv_type=GET_U_1(tptr);
+ subtlv_len=GET_U_1(tptr + 1);
+ tptr += 2;
+ tlv_remaining -= 2;
+ subtlv_sum_len -= 2;
+ proc_bytes += 2;
+ ND_PRINT("%s%s subTLV #%u, length: %u",
+ ident, tok2str(isis_ext_is_reach_subtlv_values, "unknown", subtlv_type),
+ subtlv_type, subtlv_len);
+
+ if (subtlv_sum_len < subtlv_len) {
+ ND_PRINT(" (remaining data in subTLVs shorter than the current subTLV)");
+ proc_bytes += subtlv_sum_len;
+ break;
+ }
+
+ if (tlv_remaining < subtlv_len) {
+ ND_PRINT(" (> remaining tlv length)");
+ proc_bytes += tlv_remaining;
+ break;
+ }
+
+ ND_TCHECK_LEN(tptr, subtlv_len);
+
+ switch(subtlv_type) {
+ case ISIS_SUBTLV_EXT_IS_REACH_ADMIN_GROUP:
+ case ISIS_SUBTLV_EXT_IS_REACH_LINK_LOCAL_REMOTE_ID:
+ case ISIS_SUBTLV_EXT_IS_REACH_LINK_REMOTE_ID:
+ if (subtlv_len >= 4) {
+ ND_PRINT(", 0x%08x", GET_BE_U_4(tptr));
+ if (subtlv_len == 8) /* rfc4205 */
+ ND_PRINT(", 0x%08x", GET_BE_U_4(tptr + 4));
+ }
+ break;
+ case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR:
+ case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR:
+ if (subtlv_len >= sizeof(nd_ipv4))
+ ND_PRINT(", %s", GET_IPADDR_STRING(tptr));
+ break;
+ case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW :
+ case ISIS_SUBTLV_EXT_IS_REACH_RESERVABLE_BW:
+ if (subtlv_len >= 4) {
+ bw.i = GET_BE_U_4(tptr);
+ ND_PRINT(", %.3f Mbps", bw.f * 8 / 1000000);
+ }
+ break;
+ case ISIS_SUBTLV_EXT_IS_REACH_UNRESERVED_BW :
+ if (subtlv_len >= 32) {
+ for (te_class = 0; te_class < 8; te_class++) {
+ bw.i = GET_BE_U_4(tptr);
+ ND_PRINT("%s TE-Class %u: %.3f Mbps",
+ ident,
+ te_class,
+ bw.f * 8 / 1000000);
+ tptr += 4;
+ subtlv_len -= 4;
+ subtlv_sum_len -= 4;
+ proc_bytes += 4;
+ }
+ }
+ break;
+ case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS: /* fall through */
+ case ISIS_SUBTLV_EXT_IS_REACH_BW_CONSTRAINTS_OLD:
+ if (subtlv_len == 0)
+ break;
+ ND_PRINT("%sBandwidth Constraints Model ID: %s (%u)",
+ ident,
+ tok2str(diffserv_te_bc_values, "unknown", GET_U_1(tptr)),
+ GET_U_1(tptr));
+ tptr++;
+ subtlv_len--;
+ subtlv_sum_len--;
+ proc_bytes++;
+ /* decode BCs until the subTLV ends */
+ for (te_class = 0; subtlv_len != 0; te_class++) {
+ if (subtlv_len < 4)
+ break;
+ bw.i = GET_BE_U_4(tptr);
+ ND_PRINT("%s Bandwidth constraint CT%u: %.3f Mbps",
+ ident,
+ te_class,
+ bw.f * 8 / 1000000);
+ tptr += 4;
+ subtlv_len -= 4;
+ subtlv_sum_len -= 4;
+ proc_bytes += 4;
+ }
+ break;
+ case ISIS_SUBTLV_EXT_IS_REACH_TE_METRIC:
+ if (subtlv_len >= 3)
+ ND_PRINT(", %u", GET_BE_U_3(tptr));
+ break;
+ case ISIS_SUBTLV_EXT_IS_REACH_LINK_ATTRIBUTE:
+ if (subtlv_len == 2) {
+ ND_PRINT(", [ %s ] (0x%04x)",
+ bittok2str(isis_subtlv_link_attribute_values,
+ "Unknown",
+ GET_BE_U_2(tptr)),
+ GET_BE_U_2(tptr));
+ }
+ break;
+ case ISIS_SUBTLV_EXT_IS_REACH_LINK_PROTECTION_TYPE:
+ if (subtlv_len >= 2) {
+ ND_PRINT(", %s, Priority %u",
+ bittok2str(gmpls_link_prot_values, "none", GET_U_1(tptr)),
+ GET_U_1(tptr + 1));
+ }
+ break;
+ case ISIS_SUBTLV_SPB_METRIC:
+ if (subtlv_len >= 6) {
+ ND_PRINT(", LM: %u", GET_BE_U_3(tptr));
+ tptr += 3;
+ subtlv_len -= 3;
+ subtlv_sum_len -= 3;
+ proc_bytes += 3;
+ ND_PRINT(", P: %u", GET_U_1(tptr));
+ tptr++;
+ subtlv_len--;
+ subtlv_sum_len--;
+ proc_bytes++;
+ ND_PRINT(", P-ID: %u", GET_BE_U_2(tptr));
+ }
+ break;
+ case ISIS_SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR:
+ if (subtlv_len >= 36) {
+ gmpls_switch_cap = GET_U_1(tptr);
+ ND_PRINT("%s Interface Switching Capability:%s",
+ ident,
+ tok2str(gmpls_switch_cap_values, "Unknown", gmpls_switch_cap));
+ ND_PRINT(", LSP Encoding: %s",
+ tok2str(gmpls_encoding_values, "Unknown", GET_U_1((tptr + 1))));
+ tptr += 4;
+ subtlv_len -= 4;
+ subtlv_sum_len -= 4;
+ proc_bytes += 4;
+ ND_PRINT("%s Max LSP Bandwidth:", ident);
+ for (priority_level = 0; priority_level < 8; priority_level++) {
+ bw.i = GET_BE_U_4(tptr);
+ ND_PRINT("%s priority level %u: %.3f Mbps",
+ ident,
+ priority_level,
+ bw.f * 8 / 1000000);
+ tptr += 4;
+ subtlv_len -= 4;
+ subtlv_sum_len -= 4;
+ proc_bytes += 4;
+ }
+ switch (gmpls_switch_cap) {
+ case GMPLS_PSC1:
+ case GMPLS_PSC2:
+ case GMPLS_PSC3:
+ case GMPLS_PSC4:
+ if (subtlv_len < 6)
+ break;
+ bw.i = GET_BE_U_4(tptr);
+ ND_PRINT("%s Min LSP Bandwidth: %.3f Mbps", ident, bw.f * 8 / 1000000);
+ ND_PRINT("%s Interface MTU: %u", ident,
+ GET_BE_U_2(tptr + 4));
+ break;
+ case GMPLS_TSC:
+ if (subtlv_len < 8)
+ break;
+ bw.i = GET_BE_U_4(tptr);
+ ND_PRINT("%s Min LSP Bandwidth: %.3f Mbps", ident, bw.f * 8 / 1000000);
+ ND_PRINT("%s Indication %s", ident,
+ tok2str(gmpls_switch_cap_tsc_indication_values, "Unknown (%u)", GET_U_1((tptr + 4))));
+ break;
+ default:
+ /* there is some optional stuff left to decode but this is as of yet
+ not specified so just lets hexdump what is left */
+ if (subtlv_len != 0) {
+ if (!print_unknown_data(ndo, tptr, "\n\t\t ", subtlv_len))
+ return(0);
+ }
+ }
+ }
+ break;
+ case ISIS_SUBTLV_EXT_IS_REACH_LAN_ADJ_SEGMENT_ID:
+ if (subtlv_len >= 8) {
+ ND_PRINT("%s Flags: [%s]", ident,
+ bittok2str(isis_lan_adj_sid_flag_values,
+ "none",
+ GET_U_1(tptr)));
+ int vflag = (GET_U_1(tptr) & 0x20) ? 1:0;
+ int lflag = (GET_U_1(tptr) & 0x10) ? 1:0;
+ tptr++;
+ subtlv_len--;
+ subtlv_sum_len--;
+ proc_bytes++;
+ ND_PRINT("%s Weight: %u", ident, GET_U_1(tptr));
+ tptr++;
+ subtlv_len--;
+ subtlv_sum_len--;
+ proc_bytes++;
+ if(subtlv_len>=SYSTEM_ID_LEN) {
+ ND_TCHECK_LEN(tptr, SYSTEM_ID_LEN);
+ ND_PRINT("%s Neighbor System-ID: %s", ident,
+ isis_print_id(ndo, tptr, SYSTEM_ID_LEN));
+ }
+ /* RFC 8667 section 2.2.2 */
+ /* if V-flag is set to 1 and L-flag is set to 1 ==> 3 octet label */
+ /* if V-flag is set to 0 and L-flag is set to 0 ==> 4 octet index */
+ if (vflag && lflag) {
+ ND_PRINT("%s Label: %u",
+ ident, GET_BE_U_3(tptr+SYSTEM_ID_LEN));
+ } else if ((!vflag) && (!lflag)) {
+ ND_PRINT("%s Index: %u",
+ ident, GET_BE_U_4(tptr+SYSTEM_ID_LEN));
+ } else
+ nd_print_invalid(ndo);
+ }
+ break;
+ default:
+ if (!print_unknown_data(ndo, tptr, "\n\t\t ", subtlv_len))
+ return(0);
+ break;
+ }
+
+ tptr += subtlv_len;
+ tlv_remaining -= subtlv_len;
+ subtlv_sum_len -= subtlv_len;
+ proc_bytes += subtlv_len;
+ }
+ }
+ return(proc_bytes);
+
+trunc:
+ return(0);
+}
+
+/*
+ * this is the common Multi Topology ID decoder
+ * it is called from various MT-TLVs (222,229,235,237)
+ */
+
+static uint8_t
+isis_print_mtid(netdissect_options *ndo,
+ const uint8_t *tptr, const char *ident, u_int tlv_remaining)
+{
+ if (tlv_remaining < 2)
+ goto trunc;
+
+ ND_PRINT("%s%s",
+ ident,
+ tok2str(isis_mt_values,
+ "Reserved for IETF Consensus",
+ ISIS_MASK_MTID(GET_BE_U_2(tptr))));
+
+ ND_PRINT(" Topology (0x%03x), Flags: [%s]",
+ ISIS_MASK_MTID(GET_BE_U_2(tptr)),
+ bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(GET_BE_U_2(tptr))));
+
+ return(2);
+trunc:
+ return 0;
+}
+
+/*
+ * this is the common extended IP reach decoder
+ * it is called from TLVs (135,235,236,237)
+ * we process the TLV and optional subTLVs and return
+ * the amount of processed bytes
+ */
+
+static u_int
+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(nd_ipv6)]; /* shared copy buffer for IPv4 and IPv6 prefixes */
+ u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
+
+ metric = GET_BE_U_4(tptr);
+ processed=4;
+ tptr+=4;
+
+ if (afi == AF_INET) {
+ status_byte=GET_U_1(tptr);
+ tptr++;
+ bit_length = status_byte&0x3f;
+ if (bit_length > 32) {
+ ND_PRINT("%sIPv4 prefix: bad bit length %u",
+ ident,
+ bit_length);
+ return (0);
+ }
+ processed++;
+ } else if (afi == AF_INET6) {
+ status_byte=GET_U_1(tptr);
+ bit_length=GET_U_1(tptr + 1);
+ if (bit_length > 128) {
+ ND_PRINT("%sIPv6 prefix: bad bit length %u",
+ ident,
+ bit_length);
+ return (0);
+ }
+ tptr+=2;
+ processed+=2;
+ } else
+ return (0); /* somebody is fooling us */
+
+ byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */
+
+ memset(prefix, 0, sizeof(prefix)); /* clear the copy buffer */
+ GET_CPY_BYTES(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */
+ tptr+=byte_length;
+ processed+=byte_length;
+
+ if (afi == AF_INET)
+ ND_PRINT("%sIPv4 prefix: %15s/%u",
+ ident,
+ ipaddr_string(ndo, prefix), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
+ bit_length);
+ else if (afi == AF_INET6)
+ ND_PRINT("%sIPv6 prefix: %s/%u",
+ ident,
+ ip6addr_string(ndo, prefix), /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */
+ bit_length);
+
+ ND_PRINT(", Distribution: %s, Metric: %u",
+ ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",
+ metric);
+
+ if (afi == AF_INET && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
+ ND_PRINT(", sub-TLVs present");
+ else if (afi == AF_INET6)
+ ND_PRINT(", %s%s",
+ ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",
+ ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : "");
+
+ if ((afi == AF_INET && ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte))
+ || (afi == AF_INET6 && ISIS_MASK_TLV_EXTD_IP6_SUBTLV(status_byte))
+ ) {
+ /* assume that one prefix can hold more
+ than one subTLV - therefore the first byte must reflect
+ the aggregate bytecount of the subTLVs for this prefix
+ */
+ sublen=GET_U_1(tptr);
+ tptr++;
+ processed+=sublen+1;
+ ND_PRINT(" (%u)", sublen); /* print out subTLV length */
+
+ while (sublen>0) {
+ subtlvtype=GET_U_1(tptr);
+ subtlvlen=GET_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))
+ return(0);
+ tptr+=subtlvlen;
+ sublen-=(subtlvlen+2);
+ }
+ }
+ return (processed);