+/*
+ * 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 (const u_int8_t *tptr,const char *ident, int tlv) {
+
+ char ident_buffer[20];
+ int subt,subl,tslen;
+ int proc_bytes = 0; /* how many bytes did we process ? */
+
+ if (!TTEST2(*tptr, NODE_ID_LEN))
+ return(0);
+
+ printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN));
+ tptr+=(NODE_ID_LEN);
+
+ if (tlv != TLV_IS_ALIAS_ID) {
+ if (!TTEST2(*tptr, 3))
+ return(0);
+ printf(", Metric: %d",EXTRACT_24BITS(tptr));
+ tptr+=3;
+ }
+
+ if (!TTEST2(*tptr, 1))
+ return(0);
+ tslen=*(tptr++); /* read out subTLV length */
+ proc_bytes=NODE_ID_LEN+3+1;
+ printf(", %ssub-TLVs present",tslen ? "" : "no ");
+ if (tslen) {
+ printf(" (%u)",tslen);
+ while (tslen>0) {
+ if (!TTEST2(*tptr,2))
+ return(0);
+ subt=*(tptr++);
+ subl=*(tptr++);
+ /* prepend the ident string */
+ snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
+ if(!isis_print_is_reach_subtlv(tptr,subt,subl,ident_buffer))
+ return(0);
+ tptr+=subl;
+ tslen-=(subl+2);
+ proc_bytes+=(subl+2);
+ }
+ }
+ return(proc_bytes);
+}
+
+/*
+ * this is the common Multi Topology ID decoder
+ * it is called from various MT-TLVs (222,229,235,237)
+ */
+
+static int
+isis_print_mtid (const u_int8_t *tptr,const char *ident) {
+
+ if (!TTEST2(*tptr, 2))
+ return(0);
+
+ printf("%s%s",
+ ident,
+ tok2str(isis_mt_values,
+ "Reserved for IETF Consensus",
+ ISIS_MASK_MTID(EXTRACT_16BITS(tptr))));
+
+ printf(" Topology (0x%03x), Flags: [%s]",
+ ISIS_MASK_MTID(EXTRACT_16BITS(tptr)),
+ bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr))));
+
+ return(2);
+}
+
+/*
+ * 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 int
+isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) {
+
+ char ident_buffer[20];
+ u_int8_t prefix[16]; /* shared copy buffer for IPv4 and IPv6 prefixes */
+ u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
+
+ if (!TTEST2(*tptr, 4))
+ return (0);
+ metric = EXTRACT_32BITS(tptr);
+ processed=4;
+ tptr+=4;
+
+ if (afi == IPV4) {
+ if (!TTEST2(*tptr, 1)) /* fetch status byte */
+ return (0);
+ status_byte=*(tptr++);
+ bit_length = status_byte&0x3f;
+ processed++;
+#ifdef INET6
+ } else if (afi == IPV6) {
+ if (!TTEST2(*tptr, 1)) /* fetch status & prefix_len byte */
+ return (0);
+ status_byte=*(tptr++);
+ bit_length=*(tptr++);
+ processed+=2;
+#endif
+ } else
+ return (0); /* somebody is fooling us */
+
+ byte_length = (bit_length + 7) / 8; /* prefix has variable length encoding */
+
+ if (!TTEST2(*tptr, byte_length))
+ return (0);
+ memset(prefix, 0, 16); /* clear the copy buffer */
+ memcpy(prefix,tptr,byte_length); /* copy as much as is stored in the TLV */
+ tptr+=byte_length;
+ processed+=byte_length;
+
+ if (afi == IPV4)
+ printf("%sIPv4 prefix: %15s/%u",
+ ident,
+ ipaddr_string(prefix),
+ bit_length);
+#ifdef INET6
+ if (afi == IPV6)
+ printf("%sIPv6 prefix: %s/%u",
+ ident,
+ ip6addr_string(prefix),
+ bit_length);
+#endif
+
+ printf(", Distribution: %s, Metric: %u",
+ ISIS_MASK_TLV_EXT_IP_UPDOWN(status_byte) ? "down" : "up",
+ metric);
+
+ if (afi == IPV4 && ISIS_MASK_TLV_EXT_IP_SUBTLV(status_byte))
+ printf(", sub-TLVs present");
+#ifdef INET6
+ if (afi == IPV6)
+ printf(", %s%s",
+ ISIS_MASK_TLV_EXT_IP6_IE(status_byte) ? "External" : "Internal",
+ ISIS_MASK_TLV_EXT_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : "");
+#endif
+
+ if ((ISIS_MASK_TLV_EXT_IP_SUBTLV(status_byte) && afi == IPV4) ||
+ (ISIS_MASK_TLV_EXT_IP6_SUBTLV(status_byte) && afi == IPV6)) {
+ /* 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
+ */
+ if (!TTEST2(*tptr, 1))
+ return (0);
+ sublen=*(tptr++);
+ processed+=sublen+1;
+ printf(" (%u)",sublen); /* print out subTLV length */
+
+ while (sublen>0) {
+ if (!TTEST2(*tptr,2))
+ return (0);
+ subtlvtype=*(tptr++);
+ subtlvlen=*(tptr++);
+ /* prepend the ident string */
+ snprintf(ident_buffer, sizeof(ident_buffer), "%s ",ident);
+ if(!isis_print_ip_reach_subtlv(tptr,subtlvtype,subtlvlen,ident_buffer))
+ return(0);
+ tptr+=subtlvlen;
+ sublen-=(subtlvlen+2);
+ }
+ }
+ return (processed);
+}
+
+/*
+ * isis_print
+ * Decode IS-IS packets. Return 0 on error.
+ */
+
+static int isis_print (const u_int8_t *p, u_int length)
+{
+ const struct isis_common_header *header;
+
+ const struct isis_iih_lan_header *header_iih_lan;
+ const struct isis_iih_ptp_header *header_iih_ptp;
+ const struct isis_lsp_header *header_lsp;
+ const struct isis_csnp_header *header_csnp;
+ const struct isis_psnp_header *header_psnp;
+
+ const struct isis_tlv_lsp *tlv_lsp;
+ const struct isis_tlv_ptp_adj *tlv_ptp_adj;
+ const struct isis_tlv_is_reach *tlv_is_reach;
+ const struct isis_tlv_es_reach *tlv_es_reach;
+
+ u_int8_t pdu_type, max_area, id_length, tlv_type, tlv_len, tmp, alen, lan_alen, prefix_len;
+ u_int8_t ext_is_len, ext_ip_len, mt_len;
+ const u_int8_t *optr, *pptr, *tptr;
+ u_short packet_len,pdu_len,time_remain;
+ u_int i,ra,rr;
+
+ packet_len=length;
+ optr = p; /* initialize the _o_riginal pointer to the packet start -
+ need it for parsing the checksum TLV */
+ header = (const struct isis_common_header *)p;
+ TCHECK(*header);
+ pptr = p+(ISIS_COMMON_HEADER_SIZE);
+ header_iih_lan = (const struct isis_iih_lan_header *)pptr;
+ header_iih_ptp = (const struct isis_iih_ptp_header *)pptr;
+ header_lsp = (const struct isis_lsp_header *)pptr;
+ header_csnp = (const struct isis_csnp_header *)pptr;
+ header_psnp = (const struct isis_psnp_header *)pptr;
+
+ /*
+ * Sanity checking of the header.
+ */
+
+ if (header->version != ISIS_VERSION) {
+ printf(", version %d packet not supported", header->version);
+ return (0);
+ }
+
+ if ((header->id_length != SYSTEM_ID_LEN) && (header->id_length != 0)) {
+ printf(", system ID length of %d is not supported",
+ header->id_length);
+ return (0);
+ }
+
+ if (header->pdu_version != ISIS_VERSION) {
+ printf(", version %d packet not supported", header->pdu_version);
+ return (0);
+ }
+
+ max_area = header->max_area;
+ switch(max_area) {
+ case 0:
+ max_area = 3; /* silly shit */
+ break;
+ case 255:
+ printf(", bad packet -- 255 areas");
+ return (0);
+ default:
+ break;
+ }
+
+ id_length = header->id_length;
+ switch(id_length) {
+ case 0:
+ id_length = 6; /* silly shit again */
+ break;
+ case 1: /* 1-8 are valid sys-ID lenghts */
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ break;
+ case 255:
+ id_length = 0; /* entirely useless */
+ break;
+ default:
+ break;
+ }
+
+ /* toss any non 6-byte sys-ID len PDUs */
+ if (id_length != 6 ) {
+ printf(", bad packet -- illegal sys-ID length (%u)", id_length);
+ return (0);
+ }
+
+ pdu_type=header->pdu_type;
+
+ /* in non-verbose mode just lets print the basic PDU Type*/
+ if (vflag < 1) {
+ printf("IS-IS, %s, length: %u",
+ tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type),
+ length);
+ return(1);
+ }
+
+ /* ok they seem to want to know everything - lets fully decode it */
+ printf("IS-IS, length: %u",length);
+
+ printf("\n\thlen: %u, v: %u, pdu-v: %u, sys-id-len: %u (%u), max-area: %u (%u)",
+ header->fixed_len,
+ header->version,
+ header->pdu_version,
+ id_length,
+ header->id_length,
+ max_area,
+ header->max_area);
+
+ /* first lets see if we know the PDU name*/
+ printf(", pdu-type: %s",
+ tok2str(isis_pdu_values,
+ "unknown, type %u",
+ pdu_type));
+
+ if (vflag > 1) {
+ if(!print_unknown_data(optr,"\n\t",8)) /* provide the _o_riginal pointer */
+ return(0); /* for optionally debugging the common header */
+ }
+
+ switch (pdu_type) {
+
+ case L1_LAN_IIH:
+ case L2_LAN_IIH:
+ if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE)) {
+ printf(", bogus fixed header length %u should be %lu",
+ header->fixed_len, (unsigned long)ISIS_IIH_LAN_HEADER_SIZE);
+ return (0);
+ }
+
+ pdu_len=EXTRACT_16BITS(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;
+ }
+
+ TCHECK(*header_iih_lan);
+ printf("\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),
+ tok2str(isis_iih_circuit_type_values,
+ "unknown circuit type 0x%02x",
+ header_iih_lan->circuit_type));
+
+ printf("\n\t lan-id: %s, Priority: %u, PDU length: %u",
+ isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN),
+ (header_iih_lan->priority) & PRIORITY_MASK,
+ pdu_len);
+
+ if (vflag > 1) {
+ if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_LAN_HEADER_SIZE))
+ return(0);
+ }
+
+ packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
+ pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_LAN_HEADER_SIZE);
+ break;
+
+ case PTP_IIH:
+ if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE)) {
+ printf(", bogus fixed header length %u should be %lu",
+ header->fixed_len, (unsigned long)ISIS_IIH_PTP_HEADER_SIZE);
+ return (0);
+ }
+
+ pdu_len=EXTRACT_16BITS(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;
+ }
+
+ TCHECK(*header_iih_ptp);
+ printf("\n\t source-id: %s, holding time: %us, circuit-id: 0x%02x, %s, PDU length: %u",
+ isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN),
+ EXTRACT_16BITS(header_iih_ptp->holding_time),
+ header_iih_ptp->circuit_id,
+ tok2str(isis_iih_circuit_type_values,
+ "unknown circuit type 0x%02x",
+ header_iih_ptp->circuit_type),
+ pdu_len);
+
+ if (vflag > 1) {
+ if(!print_unknown_data(pptr,"\n\t ",ISIS_IIH_PTP_HEADER_SIZE))
+ return(0);
+ }
+
+ packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
+ pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_IIH_PTP_HEADER_SIZE);
+ break;
+
+ case L1_LSP:
+ case L2_LSP:
+ if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE)) {
+ printf(", bogus fixed header length %u should be %lu",
+ header->fixed_len, (unsigned long)ISIS_LSP_HEADER_SIZE);
+ return (0);
+ }
+
+ pdu_len=EXTRACT_16BITS(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;
+ }
+
+ TCHECK(*header_lsp);
+ printf("\n\t 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));
+ /* verify the checksum -
+ * checking starts at the lsp-id field
+ * which is 12 bytes after the packet start*/
+ printf("\n\t chksum: 0x%04x (%s), PDU length: %u",
+ EXTRACT_16BITS(header_lsp->checksum),
+ (osi_cksum(optr+12, length-12)) ? "incorrect" : "correct",
+ pdu_len);
+
+ printf(", %s", ISIS_MASK_LSP_OL_BIT(header_lsp->typeblock) ? "Overload bit set, " : "");
+
+ if (ISIS_MASK_LSP_ATT_BITS(header_lsp->typeblock)) {
+ printf("%s", ISIS_MASK_LSP_ATT_DEFAULT_BIT(header_lsp->typeblock) ? "default " : "");
+ printf("%s", ISIS_MASK_LSP_ATT_DELAY_BIT(header_lsp->typeblock) ? "delay " : "");
+ printf("%s", ISIS_MASK_LSP_ATT_EXPENSE_BIT(header_lsp->typeblock) ? "expense " : "");
+ printf("%s", ISIS_MASK_LSP_ATT_ERROR_BIT(header_lsp->typeblock) ? "error " : "");
+ printf("ATT bit set, ");
+ }
+ printf("%s", ISIS_MASK_LSP_PARTITION_BIT(header_lsp->typeblock) ? "P bit set, " : "");
+ printf("%s", tok2str(isis_lsp_istype_values,"Unknown(0x%x)",ISIS_MASK_LSP_ISTYPE_BITS(header_lsp->typeblock)));
+
+ if (vflag > 1) {
+ if(!print_unknown_data(pptr,"\n\t ",ISIS_LSP_HEADER_SIZE))
+ return(0);
+ }
+
+ packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
+ pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_LSP_HEADER_SIZE);
+ break;
+
+ case L1_CSNP:
+ case L2_CSNP:
+ if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE)) {
+ printf(", bogus fixed header length %u should be %lu",
+ header->fixed_len, (unsigned long)ISIS_CSNP_HEADER_SIZE);
+ return (0);
+ }
+
+ pdu_len=EXTRACT_16BITS(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;
+ }
+
+ TCHECK(*header_csnp);
+ printf("\n\t source-id: %s, PDU length: %u",
+ isis_print_id(header_csnp->source_id, NODE_ID_LEN),
+ pdu_len);
+ printf("\n\t start lsp-id: %s",
+ isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN));
+ printf("\n\t end lsp-id: %s",
+ isis_print_id(header_csnp->end_lsp_id, LSP_ID_LEN));
+
+ if (vflag > 1) {
+ if(!print_unknown_data(pptr,"\n\t ",ISIS_CSNP_HEADER_SIZE))
+ return(0);
+ }
+
+ packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
+ pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_CSNP_HEADER_SIZE);
+ break;
+
+ case L1_PSNP:
+ case L2_PSNP:
+ if (header->fixed_len != (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE)) {
+ printf("- bogus fixed header length %u should be %lu",
+ header->fixed_len, (unsigned long)ISIS_PSNP_HEADER_SIZE);
+ return (0);
+ }
+
+ pdu_len=EXTRACT_16BITS(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;
+ }
+
+ TCHECK(*header_psnp);
+ printf("\n\t source-id: %s",
+ isis_print_id(header_psnp->source_id, NODE_ID_LEN));
+
+ if (vflag > 1) {
+ if(!print_unknown_data(pptr,"\n\t ",ISIS_PSNP_HEADER_SIZE))
+ return(0);
+ }
+
+ packet_len -= (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
+ pptr = p + (ISIS_COMMON_HEADER_SIZE+ISIS_PSNP_HEADER_SIZE);
+ break;
+
+ default:
+ if(!print_unknown_data(pptr,"\n\t ",length))
+ return(0);
+ return (0);
+ }
+
+ /*
+ * Now print the TLV's.
+ */
+
+ while (packet_len >= 2) {
+ if (pptr == snapend) {
+ return (1);
+ }
+
+ if (!TTEST2(*pptr, 2)) {
+ printf("\n\t\t packet exceeded snapshot (%ld) bytes",
+ (long)(pptr-snapend));
+ return (1);
+ }
+ tlv_type = *pptr++;
+ tlv_len = *pptr++;
+ tmp =tlv_len; /* copy temporary len & pointer to packet data */
+ tptr = pptr;
+ packet_len -= 2;
+ if (tlv_len > packet_len) {
+ break;
+ }
+
+ /* first lets see if we know the TLVs name*/
+ printf("\n\t %s TLV #%u, length: %u",
+ tok2str(isis_tlv_values,
+ "unknown",
+ tlv_type),
+ tlv_type,
+ tlv_len);
+
+ /* now check if we have a decoder otherwise do a hexdump at the end*/
+ switch (tlv_type) {
+ case TLV_AREA_ADDR:
+ if (!TTEST2(*tptr, 1))
+ goto trunctlv;
+ alen = *tptr++;
+ while (tmp && alen < tmp) {
+ printf("\n\t Area address (length: %u): %s",
+ alen,
+ print_nsap(tptr, alen));
+ tptr += alen;
+ tmp -= alen + 1;
+ if (tmp==0) /* if this is the last area address do not attemt a boundary check */
+ break;
+ if (!TTEST2(*tptr, 1))
+ goto trunctlv;
+ alen = *tptr++;
+ }
+ break;
+ case TLV_ISNEIGH:
+ while (tmp >= ETHER_ADDR_LEN) {
+ if (!TTEST2(*tptr, ETHER_ADDR_LEN))
+ goto trunctlv;
+ printf("\n\t IS Neighbor: %s",isis_print_id(tptr,ETHER_ADDR_LEN));
+ tmp -= ETHER_ADDR_LEN;
+ tptr += ETHER_ADDR_LEN;
+ }
+ break;
+
+ case TLV_ISNEIGH_VARLEN:
+ if (!TTEST2(*tptr, 1))
+ goto trunctlv;
+ lan_alen = *tptr++; /* LAN adress length */
+ tmp --;
+ printf("\n\t LAN address length %u bytes ",lan_alen);
+ while (tmp >= lan_alen) {
+ if (!TTEST2(*tptr, lan_alen))
+ goto trunctlv;
+ printf("\n\t\tIS Neighbor: %s",isis_print_id(tptr,lan_alen));
+ tmp -= lan_alen;
+ tptr +=lan_alen;
+ }
+ break;
+
+ case TLV_PADDING:
+ break;
+
+ case TLV_MT_IS_REACH:
+ while (tmp >= 2+NODE_ID_LEN+3+1) {
+ mt_len = isis_print_mtid(tptr, "\n\t ");
+ if (mt_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tptr+=mt_len;
+ tmp-=mt_len;
+
+ ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
+ if (ext_is_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+
+ tmp-=ext_is_len;
+ tptr+=ext_is_len;
+ }
+ break;
+
+ case TLV_IS_ALIAS_ID:
+ while (tmp >= NODE_ID_LEN+1) { /* is it worth attempting a decode ? */
+ ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
+ if (ext_is_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tmp-=ext_is_len;
+ tptr+=ext_is_len;
+ }
+ break;
+
+ case TLV_EXT_IS_REACH:
+ while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */
+ ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type);
+ if (ext_is_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tmp-=ext_is_len;
+ tptr+=ext_is_len;
+ }
+ break;
+ case TLV_IS_REACH:
+ if (!TTEST2(*tptr,1)) /* check if there is one byte left to read out the virtual flag */
+ goto trunctlv;
+ printf("\n\t %s",
+ tok2str(isis_is_reach_virtual_values,
+ "bogus virtual flag 0x%02x",
+ *tptr++));
+ tlv_is_reach = (const struct isis_tlv_is_reach *)tptr;
+ while (tmp >= sizeof(struct isis_tlv_is_reach)) {
+ if (!TTEST(*tlv_is_reach))
+ goto trunctlv;
+ printf("\n\t IS Neighbor: %s",
+ isis_print_id(tlv_is_reach->neighbor_nodeid, NODE_ID_LEN));
+ isis_print_metric_block(&tlv_is_reach->isis_metric_block);
+ tmp -= sizeof(struct isis_tlv_is_reach);
+ tlv_is_reach++;
+ }
+ break;
+
+ case TLV_ESNEIGH:
+ tlv_es_reach = (const struct isis_tlv_es_reach *)tptr;
+ while (tmp >= sizeof(struct isis_tlv_es_reach)) {
+ if (!TTEST(*tlv_es_reach))
+ goto trunctlv;
+ printf("\n\t ES Neighbor: %s",
+ isis_print_id(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN));
+ isis_print_metric_block(&tlv_es_reach->isis_metric_block);
+ tmp -= sizeof(struct isis_tlv_es_reach);
+ tlv_es_reach++;
+ }
+ break;
+
+ /* those two TLVs share the same format */
+ case TLV_IP_REACH:
+ case TLV_IP_REACH_EXT:
+ if (!isis_print_tlv_ip_reach(pptr, "\n\t ", tlv_len))
+ return (1);
+ break;
+
+ case TLV_EXT_IP_REACH:
+ while (tmp>0) {
+ ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
+ if (ext_ip_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tptr+=ext_ip_len;
+ tmp-=ext_ip_len;
+ }
+ break;
+
+ case TLV_MT_IP_REACH:
+ while (tmp>0) {
+ mt_len = isis_print_mtid(tptr, "\n\t ");
+ if (mt_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tptr+=mt_len;
+ tmp-=mt_len;
+
+ ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV4);
+ if (ext_ip_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tptr+=ext_ip_len;
+ tmp-=ext_ip_len;
+ }
+ break;
+
+#ifdef INET6
+ case TLV_IP6_REACH:
+ while (tmp>0) {
+ ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
+ if (ext_ip_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tptr+=ext_ip_len;
+ tmp-=ext_ip_len;
+ }
+ break;
+
+ case TLV_MT_IP6_REACH:
+ while (tmp>0) {
+ mt_len = isis_print_mtid(tptr, "\n\t ");
+ if (mt_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tptr+=mt_len;
+ tmp-=mt_len;
+
+ ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t ", IPV6);
+ if (ext_ip_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tptr+=ext_ip_len;
+ tmp-=ext_ip_len;
+ }
+ break;
+
+ case TLV_IP6ADDR:
+ while (tmp>0) {
+ if (!TTEST2(*tptr, 16))
+ goto trunctlv;
+
+ printf("\n\t IPv6 interface address: %s",
+ ip6addr_string(tptr));
+
+ tptr += 16;
+ tmp -= 16;
+ }
+ break;
+#endif
+ case TLV_AUTH:
+ if (!TTEST2(*tptr, 1))
+ goto trunctlv;
+
+ printf("\n\t %s: ",
+ tok2str(isis_subtlv_auth_values,
+ "unknown Authentication type 0x%02x",
+ *tptr));
+
+ switch (*tptr) {
+ case SUBTLV_AUTH_SIMPLE:
+ for(i=1;i<tlv_len;i++) {
+ if (!TTEST2(*(tptr+i), 1))
+ goto trunctlv;
+ printf("%c",*(tptr+i));
+ }
+ break;
+ case SUBTLV_AUTH_MD5:
+ for(i=1;i<tlv_len;i++) {
+ if (!TTEST2(*(tptr+i), 1))
+ goto trunctlv;
+ printf("%02x",*(tptr+i));
+ }
+ if (tlv_len != SUBTLV_AUTH_MD5_LEN+1)
+ printf(", (malformed subTLV) ");
+ break;
+ case SUBTLV_AUTH_PRIVATE:
+ default:
+ if(!print_unknown_data(tptr+1,"\n\t\t ",tlv_len-1))
+ return(0);
+ break;
+ }
+ break;
+
+ case TLV_PTP_ADJ:
+ tlv_ptp_adj = (const struct isis_tlv_ptp_adj *)tptr;
+ if(tmp>=1) {
+ if (!TTEST2(*tptr, 1))
+ goto trunctlv;
+ printf("\n\t Adjacency State: %s",
+ tok2str(isis_ptp_adjancey_values, "0x%02x", *tptr));
+ tmp--;
+ }
+ if(tmp>sizeof(tlv_ptp_adj->extd_local_circuit_id)) {
+ if (!TTEST2(tlv_ptp_adj->extd_local_circuit_id,
+ sizeof(tlv_ptp_adj->extd_local_circuit_id)))
+ goto trunctlv;
+ printf("\n\t Extended Local circuit ID: 0x%08x",
+ EXTRACT_32BITS(tlv_ptp_adj->extd_local_circuit_id));
+ tmp-=sizeof(tlv_ptp_adj->extd_local_circuit_id);
+ }
+ if(tmp>=SYSTEM_ID_LEN) {
+ if (!TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN))
+ goto trunctlv;
+ printf("\n\t Neighbor SystemID: %s",
+ isis_print_id(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN));
+ tmp-=SYSTEM_ID_LEN;
+ }
+ if(tmp>=sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)) {
+ if (!TTEST2(tlv_ptp_adj->neighbor_extd_local_circuit_id,
+ sizeof(tlv_ptp_adj->neighbor_extd_local_circuit_id)))
+ goto trunctlv;
+ printf("\n\t Neighbor Extended Local circuit ID: 0x%08x",
+ EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id));
+ }
+ break;
+
+ case TLV_PROTOCOLS:
+ printf("\n\t NLPID(s): ");
+ while (tmp>0) {
+ if (!TTEST2(*(tptr), 1))
+ goto trunctlv;
+ printf("%s",
+ tok2str(osi_nlpid_values,
+ "Unknown 0x%02x",
+ *tptr++));
+ if (tmp>1) /* further NPLIDs ? - put comma */
+ printf(", ");
+ tmp--;
+ }
+ break;
+
+ case TLV_TE_ROUTER_ID:
+ if (!TTEST2(*pptr, 4))
+ goto trunctlv;
+ printf("\n\t Traffic Engineering Router ID: %s", ipaddr_string(pptr));
+ break;
+
+ case TLV_IPADDR:
+ while (tmp>0) {
+ if (!TTEST2(*tptr, 4))
+ goto trunctlv;
+ printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
+ tptr += 4;
+ tmp -= 4;
+ }
+ break;
+
+ case TLV_HOSTNAME:
+ printf("\n\t Hostname: ");
+ while (tmp>0) {
+ if (!TTEST2(*tptr, 1))
+ goto trunctlv;
+ printf("%c",*tptr++);
+ tmp--;
+ }
+ break;
+
+ case TLV_SHARED_RISK_GROUP:
+ if (!TTEST2(*tptr, NODE_ID_LEN))
+ goto trunctlv;
+ printf("\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN));
+ tptr+=(NODE_ID_LEN);
+ tmp-=(NODE_ID_LEN);
+
+ if (!TTEST2(*tptr, 1))
+ goto trunctlv;
+ printf(", %s", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered");
+ tmp--;
+
+ if (!TTEST2(*tptr,4))
+ goto trunctlv;
+ printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr));
+ tptr+=4;
+ tmp-=4;
+
+ if (!TTEST2(*tptr,4))
+ goto trunctlv;
+ printf("\n\t IPv4 neighbor address: %s", ipaddr_string(tptr));
+ tptr+=4;
+ tmp-=4;
+
+ while (tmp>0) {
+ if (!TTEST2(*tptr, 4))
+ goto trunctlv;
+ printf("\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr));
+ tptr+=4;
+ tmp-=4;
+ }
+ break;
+
+ case TLV_LSP:
+ tlv_lsp = (const struct isis_tlv_lsp *)tptr;
+ while(tmp>0) {
+ if (!TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN]))
+ goto trunctlv;
+ printf("\n\t lsp-id: %s",
+ isis_print_id(tlv_lsp->lsp_id, LSP_ID_LEN));
+ if (!TTEST2(tlv_lsp->sequence_number, 4))
+ goto trunctlv;
+ printf(", seq: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number));
+ if (!TTEST2(tlv_lsp->remaining_lifetime, 2))
+ goto trunctlv;
+ printf(", lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime));
+ if (!TTEST2(tlv_lsp->checksum, 2))
+ goto trunctlv;
+ printf(", chksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum));
+ tmp-=sizeof(struct isis_tlv_lsp);
+ tlv_lsp++;
+ }
+ break;
+
+ case TLV_CHECKSUM:
+ if (!TTEST2(*tptr, 2))
+ goto trunctlv;
+ printf("\n\t checksum: 0x%04x (%s)",
+ EXTRACT_16BITS(tptr),
+ (osi_cksum(optr, length)) ? "incorrect" : "correct");
+ break;
+
+ case TLV_MT_SUPPORTED:
+ while (tmp>1) {
+ /* length can only be a multiple of 2, otherwise there is
+ something broken -> so decode down until length is 1 */
+ if (tmp!=1) {
+ mt_len = isis_print_mtid(tptr, "\n\t ");
+ if (mt_len == 0) /* did something go wrong ? */
+ goto trunctlv;
+ tptr+=mt_len;
+ tmp-=mt_len;
+ } else {
+ printf("\n\t malformed MT-ID");
+ break;
+ }
+ }
+ break;
+
+ case TLV_RESTART_SIGNALING:
+ if (!TTEST2(*tptr, 3))
+ goto trunctlv;
+ rr = ISIS_MASK_TLV_RESTART_RR(*tptr);
+ ra = ISIS_MASK_TLV_RESTART_RA(*tptr);
+ tptr++;
+ time_remain = EXTRACT_16BITS(tptr);
+ printf("\n\t Restart Request bit %s, Restart Acknowledgement bit %s\n\t Remaining holding time: %us",
+ rr ? "set" : "clear", ra ? "set" : "clear", time_remain);
+ break;
+
+ case TLV_IDRP_INFO:
+ if (!TTEST2(*tptr, 1))
+ goto trunctlv;
+ printf("\n\t Inter-Domain Information Type: %s",
+ tok2str(isis_subtlv_idrp_values,
+ "Unknown (0x%02x)",
+ *tptr));
+ switch (*tptr++) {
+ case SUBTLV_IDRP_ASN:
+ if (!TTEST2(*tptr, 2)) /* fetch AS number */
+ goto trunctlv;
+ printf("AS Number: %u",EXTRACT_16BITS(tptr));
+ break;
+ case SUBTLV_IDRP_LOCAL:
+ case SUBTLV_IDRP_RES:
+ default:
+ if(!print_unknown_data(tptr,"\n\t ",tlv_len-1))
+ return(0);
+ break;
+ }
+ break;
+
+ case TLV_LSP_BUFFERSIZE:
+ if (!TTEST2(*tptr, 2))
+ goto trunctlv;
+ printf("\n\t LSP Buffersize: %u",EXTRACT_16BITS(tptr));
+ break;
+
+ case TLV_PART_DIS:
+ while (tmp >= SYSTEM_ID_LEN) {
+ if (!TTEST2(*tptr, SYSTEM_ID_LEN))
+ goto trunctlv;
+ printf("\n\t %s",isis_print_id(tptr,SYSTEM_ID_LEN));
+ tptr+=SYSTEM_ID_LEN;
+ tmp-=SYSTEM_ID_LEN;
+ }
+ break;
+
+ case TLV_PREFIX_NEIGH:
+ if (!TTEST2(*tptr, sizeof(struct isis_metric_block)))
+ goto trunctlv;
+ printf("\n\t Metric Block");
+ isis_print_metric_block((const struct isis_metric_block *)tptr);
+ tptr+=sizeof(struct isis_metric_block);
+ tmp-=sizeof(struct isis_metric_block);
+
+ while(tmp>0) {
+ if (!TTEST2(*tptr, 1))
+ goto trunctlv;
+ prefix_len=*tptr++; /* read out prefix length in semioctets*/
+ tmp--;
+ if (!TTEST2(*tptr, prefix_len/2))
+ goto trunctlv;
+ printf("\n\t\tAddress: %s/%u",
+ print_nsap(tptr,prefix_len/2),
+ prefix_len*4);
+ tptr+=prefix_len/2;
+ tmp-=prefix_len/2;
+ }
+ break;
+
+ case TLV_IIH_SEQNR:
+ if (!TTEST2(*tptr, 4)) /* check if four bytes are on the wire */
+ goto trunctlv;
+ printf("\n\t Sequence number: %u", EXTRACT_32BITS(tptr) );
+ break;
+
+ case TLV_VENDOR_PRIVATE:
+ if (!TTEST2(*tptr, 3)) /* check if enough byte for a full oui */
+ goto trunctlv;
+ printf("\n\t Vendor OUI Code: 0x%06x", EXTRACT_24BITS(tptr) );
+ tptr+=3;
+ tmp-=3;
+ if (tmp > 0) /* hexdump the rest */
+ if(!print_unknown_data(tptr,"\n\t\t",tmp))
+ return(0);
+ break;
+ /*
+ * FIXME those are the defined TLVs that lack a decoder
+ * you are welcome to contribute code ;-)
+ */
+
+ case TLV_DECNET_PHASE4:
+ case TLV_LUCENT_PRIVATE:
+ case TLV_IPAUTH:
+ case TLV_NORTEL_PRIVATE1:
+ case TLV_NORTEL_PRIVATE2:
+
+ default:
+ if (vflag <= 1) {
+ if(!print_unknown_data(pptr,"\n\t\t",tlv_len))
+ return(0);
+ }
+ break;
+ }
+ /* do we want to see an additionally hexdump ? */
+ if (vflag> 1) {
+ if(!print_unknown_data(pptr,"\n\t ",tlv_len))
+ return(0);
+ }
+
+ pptr += tlv_len;
+ packet_len -= tlv_len;
+ }
+
+ if (packet_len != 0) {
+ printf("\n\t %u straggler bytes", packet_len);
+ }
+ return (1);
+
+ trunc:
+ fputs("[|isis]", stdout);
+ return (1);
+
+ trunctlv:
+ printf("\n\t\t packet exceeded snapshot");
+ return(1);
+}
+
+/*
+ * Verify the checksum. See 8473-1, Appendix C, section C.4.
+ */
+
+static int
+osi_cksum(const u_int8_t *tptr, u_int len)
+{
+ int32_t c0 = 0, c1 = 0;
+