X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/4081766c05975203d9c43f7fea5aed8f7ce32c87..381b94ccaff9dd04f21cdbb4bf8ddeb8b72d8688:/print-isoclns.c diff --git a/print-isoclns.c b/print-isoclns.c index eff45e3a..9f512b42 100644 --- a/print-isoclns.c +++ b/print-isoclns.c @@ -26,7 +26,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.72 2002-12-11 06:00:41 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.82 2003-05-01 18:04:41 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -229,9 +229,14 @@ static struct tok isis_subtlv_idrp_values[] = { #define ISIS_MASK_LSP_ATT_DELAY_BIT(x) ((x)&0x10) #define ISIS_MASK_LSP_ATT_DEFAULT_BIT(x) ((x)&0x8) -#define ISIS_MASK_MTID(x) ((x)&0xfff) -#define ISIS_MASK_MTSUB(x) ((x)&0x8000) -#define ISIS_MASK_MTATT(x) ((x)&0x4000) +#define ISIS_MASK_MTID(x) ((x)&0x0fff) +#define ISIS_MASK_MTFLAGS(x) ((x)&0xf000) + +static struct tok isis_mt_flag_values[] = { + { 0x4000, "sub-TLVs present"}, + { 0x8000, "ATT bit set"}, + { 0, NULL} +}; #define ISIS_MASK_TLV_EXT_IP_UPDOWN(x) ((x)&0x80) #define ISIS_MASK_TLV_EXT_IP_SUBTLV(x) ((x)&0x40) @@ -346,7 +351,7 @@ struct isis_tlv_ptp_adj { u_int8_t extd_local_circuit_id[4]; u_int8_t neighbor_sysid[SYSTEM_ID_LEN]; u_int8_t neighbor_extd_local_circuit_id[4]; -} __attribute__((packed)); +}; static int osi_cksum(const u_int8_t *, u_int); static void esis_print(const u_int8_t *, u_int); @@ -357,23 +362,23 @@ struct isis_metric_block { u_int8_t metric_delay; u_int8_t metric_expense; u_int8_t metric_error; -} __attribute__((packed)); +}; struct isis_tlv_is_reach { struct isis_metric_block isis_metric_block; u_int8_t neighbor_nodeid[NODE_ID_LEN]; -} __attribute__((packed)); +}; struct isis_tlv_es_reach { struct isis_metric_block isis_metric_block; u_int8_t neighbor_sysid[SYSTEM_ID_LEN]; -} __attribute__((packed)); +}; struct isis_tlv_ip_reach { struct isis_metric_block isis_metric_block; u_int8_t prefix[4]; u_int8_t mask[4]; -} __attribute__((packed)); +}; static struct tok isis_is_reach_virtual_values[] = { { 0, "IsNotVirtual"}, @@ -384,13 +389,13 @@ static struct tok isis_is_reach_virtual_values[] = { struct isis_common_header { u_int8_t nlpid; u_int8_t fixed_len; - u_int8_t version; /* Protocol version? */ + u_int8_t version; /* Protocol version */ u_int8_t id_length; - u_int8_t pdu_type; /* 3 MSbs are reserved */ - u_int8_t pdu_version; /* Packet format version? */ + u_int8_t pdu_type; /* 3 MSbits are reserved */ + u_int8_t pdu_version; /* Packet format version */ u_int8_t reserved; u_int8_t max_area; -} __attribute__((packed)); +}; struct isis_iih_lan_header { u_int8_t circuit_type; @@ -399,7 +404,7 @@ struct isis_iih_lan_header { u_int8_t pdu_len[2]; u_int8_t priority; u_int8_t lan_id[NODE_ID_LEN]; -} __attribute__((packed)); +}; struct isis_iih_ptp_header { u_int8_t circuit_type; @@ -407,7 +412,7 @@ struct isis_iih_ptp_header { u_int8_t holding_time[2]; u_int8_t pdu_len[2]; u_int8_t circuit_id; -} __attribute__((packed)); +}; struct isis_lsp_header { u_int8_t pdu_len[2]; @@ -416,26 +421,26 @@ struct isis_lsp_header { u_int8_t sequence_number[4]; u_int8_t checksum[2]; u_int8_t typeblock; -} __attribute__((packed)); +}; struct isis_csnp_header { u_int8_t pdu_len[2]; u_int8_t source_id[NODE_ID_LEN]; u_int8_t start_lsp_id[LSP_ID_LEN]; u_int8_t end_lsp_id[LSP_ID_LEN]; -} __attribute__((packed)); +}; struct isis_psnp_header { u_int8_t pdu_len[2]; u_int8_t source_id[NODE_ID_LEN]; -} __attribute__((packed)); +}; struct isis_tlv_lsp { u_int8_t remaining_lifetime[2]; u_int8_t lsp_id[LSP_ID_LEN]; u_int8_t sequence_number[4]; u_int8_t checksum[2]; -} __attribute__((packed)); +}; /* allocate space for the following string @@ -449,18 +454,18 @@ print_nsap(register const u_int8_t *pptr, register int nsap_length) char *junk_buf = nsap_ascii_output; if (nsap_length < 1 || nsap_length > 13) { - junk_buf+=sprintf(junk_buf, "illegal length"); - *(junk_buf) = '\0'; + sprintf(junk_buf, "illegal length"); return (nsap_ascii_output); } for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) { if (!TTEST2(*pptr, 1)) return (0); - junk_buf+=sprintf(junk_buf, "%02x", *pptr++); + sprintf(junk_buf, "%02x", *pptr++); + junk_buf += strlen(junk_buf); if (((nsap_idx & 1) == 0) && (nsap_idx + 1 < nsap_length)) { - junk_buf+=sprintf(junk_buf, "."); + *junk_buf++ = '.'; } } *(junk_buf) = '\0'; @@ -691,72 +696,33 @@ esis_print(const u_int8_t *p, u_int length) } } -/* allocate space for the following string - * xxxx.xxxx.xxxx - * 14 bytes plus one termination byte */ -static char * -isis_print_sysid(const u_int8_t *cp, int sysid_len) -{ - int i; - static char sysid[15]; - char *pos = sysid; - - for (i = 1; i <= sysid_len; i++) { - if (!TTEST2(*cp, 1)) - return (0); - pos+=sprintf(pos, "%02x", *cp++); - if ((i==2)^(i==4)) { - pos+=sprintf(pos, "."); - } - } - *(pos) = '\0'; - return (sysid); -} - - -/* allocate space for the following string - * xxxx.xxxx.xxxx.yy - * 17 bytes plus one termination byte */ -static char * -isis_print_nodeid(const u_int8_t *cp) -{ - int i; - static char nodeid[18]; - char *pos = nodeid; - - for (i = 1; i <= 7; i++) { - if (!TTEST2(*cp, 1)) - return (0); - pos+=sprintf(pos, "%02x", *cp++); - if ((i & 1) == 0) { - pos+=sprintf(pos, "."); - } - } - *(pos) = '\0'; - return (nodeid); -} - -/* allocate space for the following string +/* shared routine for printing system, node and lsp-ids + * allocate space for the worst-case string * xxxx.xxxx.xxxx.yy-zz * 20 bytes plus one termination byte */ static char * -isis_print_lspid(const u_int8_t *cp) +isis_print_id(const u_int8_t *cp, int id_len) { - int i; - static char lspid[21]; - char *pos = lspid; - - for (i = 1; i <= 7; i++) { - pos+=sprintf(pos, "%02x", *cp++); - if ((i & 1) == 0) - pos+=sprintf(pos, "."); + int i; + static char id[21]; + char *pos = id; + + for (i = 1; i <= SYSTEM_ID_LEN; i++) { + sprintf(pos, "%02x", *cp++); + pos += strlen(pos); + if (i == 2 || i == 4) + *pos++ = '.'; } - pos+=sprintf(pos, "-%02x", *cp); - return (lspid); + if (id_len == NODE_ID_LEN) { + sprintf(pos, ".%02x", *cp++); + pos += strlen(pos); + } + if (id_len == LSP_ID_LEN) + sprintf(pos, "-%02x", *cp); + return (id); } /* print the 4-byte metric block which is common found in the old-style TLVs */ - static int isis_print_metric_block (const struct isis_metric_block *isis_metric_block) { @@ -780,20 +746,8 @@ isis_print_metric_block (const struct isis_metric_block *isis_metric_block) } static int -isis_print_tlv_ip_reach (const u_int8_t *cp, int length) +isis_print_tlv_ip_reach (const u_int8_t *cp, const char *ident, int length) { - u_int bitmasks[33] = { - 0x00000000, - 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, - 0xf8000000, 0xfc000000, 0xfe000000, 0xff000000, - 0xff800000, 0xffc00000, 0xffe00000, 0xfff00000, - 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, - 0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000, - 0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00, - 0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0, - 0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff - }; - u_int mask; int prefix_len; const struct isis_tlv_ip_reach *tlv_ip_reach; @@ -801,57 +755,50 @@ isis_print_tlv_ip_reach (const u_int8_t *cp, int length) while (length > 0) { if ((size_t)length < sizeof(*tlv_ip_reach)) { - printf("short IPv4 reachability (%d vs %lu)", length, - (unsigned long)sizeof(*tlv_ip_reach)); + printf("short IPv4 reachability (%d vs %lu)", + length, + (unsigned long)sizeof(*tlv_ip_reach)); return (0); } if (!TTEST(*tlv_ip_reach)) return (0); - mask = EXTRACT_32BITS(tlv_ip_reach->mask); - prefix_len = 0; - - /* lets see if we can transform the mask into a prefixlen */ - while (prefix_len <= 33) { - if (bitmasks[prefix_len++] == mask) { - prefix_len--; - break; - } - } + prefix_len = mask2plen(EXTRACT_32BITS(tlv_ip_reach->mask)); - /* - * 34 indicates no match -> must be a discontiguous netmask - * lets dump the mask, otherwise print the prefix_len - */ - if (prefix_len == 34) - printf("\n\t\tIPv4 prefix: %s mask %s", + if (prefix_len == -1) + printf("%sIPv4 prefix: %s mask %s", + ident, ipaddr_string((tlv_ip_reach->prefix)), ipaddr_string((tlv_ip_reach->mask))); else - printf("\n\t\tIPv4 prefix: %s/%u", + printf("%sIPv4 prefix: %15s/%u", + ident, ipaddr_string((tlv_ip_reach->prefix)), prefix_len); - printf("\n\t\t Default Metric: %02d, %s, Distribution: %s", - ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default), - ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal", - ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up"); + printf(", Distribution: %s, Metric: %u, %s", + ISIS_LSP_TLV_METRIC_UPDOWN(tlv_ip_reach->isis_metric_block.metric_default) ? "down" : "up", + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_default), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_default) ? "External" : "Internal"); if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_delay)) - printf("\n\t\t Delay Metric: %02d, %s", - ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay), - ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal"); - + printf("%s Delay Metric: %u, %s", + ident, + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_delay), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_delay) ? "External" : "Internal"); + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_expense)) - printf("\n\t\t Expense Metric: %02d, %s", - ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense), - ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal"); - + printf("%s Expense Metric: %u, %s", + ident, + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_expense), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_expense) ? "External" : "Internal"); + if (!ISIS_LSP_TLV_METRIC_SUPPORTED(tlv_ip_reach->isis_metric_block.metric_error)) - printf("\n\t\t Error Metric: %02d, %s", - ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error), - ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal"); + printf("%s Error Metric: %u, %s", + ident, + ISIS_LSP_TLV_METRIC_VALUE(tlv_ip_reach->isis_metric_block.metric_error), + ISIS_LSP_TLV_METRIC_IE(tlv_ip_reach->isis_metric_block.metric_error) ? "External" : "Internal"); length -= sizeof(struct isis_tlv_ip_reach); tlv_ip_reach++; @@ -867,34 +814,43 @@ isis_print_tlv_ip_reach (const u_int8_t *cp, int length) static int isis_print_ip_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) { - switch(subt) { - case SUBTLV_IP_REACH_ADMIN_TAG32: - if (!TTEST2(*tptr,4)) - goto trunctlv; - printf("%s32-Bit Administrative tag: 0x%08x", - ident, - EXTRACT_32BITS(tptr)); - break; - case SUBTLV_IP_REACH_ADMIN_TAG64: - if (!TTEST2(*tptr,8)) - goto trunctlv; - printf("%s64-Bit Administrative tag: 0x%08x%08x", - ident, - EXTRACT_32BITS(tptr), - EXTRACT_32BITS(tptr+4)); - break; - default: - printf("%sunknown subTLV, type %d, length %d", - ident, - subt, - subl); - if(!print_unknown_data(tptr,"\n\t\t ", - subl)) - return(0); - break; - } - return(1); - + switch(subt) { + case SUBTLV_IP_REACH_ADMIN_TAG32: + while (subl >= 4) { + if (!TTEST2(*tptr,4)) + goto trunctlv; + printf("%s32-Bit Administrative tag: 0x%08x (=%u)", + ident, + EXTRACT_32BITS(tptr), + EXTRACT_32BITS(tptr)); + tptr+=4; + subl-=4; + } + break; + case SUBTLV_IP_REACH_ADMIN_TAG64: + while (subl >= 8) { + if (!TTEST2(*tptr,8)) + goto trunctlv; + printf("%s64-Bit Administrative tag: 0x%08x%08x", + ident, + EXTRACT_32BITS(tptr), + EXTRACT_32BITS(tptr+4)); + tptr+=8; + subl-=8; + } + break; + default: + printf("%sunknown subTLV, type %d, length %d", + ident, + subt, + subl); + if(!print_unknown_data(tptr,"\n\t\t ", + subl)) + return(0); + break; + } + return(1); + trunctlv: printf("%spacket exceeded snapshot",ident); return(0); @@ -1069,7 +1025,7 @@ trunctlv: */ static int -isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident) { +isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv) { char ident_buffer[20]; int subt,subl,tslen; @@ -1078,13 +1034,15 @@ isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident) { if (!TTEST2(*tptr, NODE_ID_LEN)) return(0); - printf("%sIS Neighbor: %s", ident, isis_print_nodeid(tptr)); + printf("%sIS Neighbor: %s", ident, isis_print_id(tptr, NODE_ID_LEN)); tptr+=(NODE_ID_LEN); - - if (!TTEST2(*tptr, 3)) - return(0); - printf(", Metric: %d",EXTRACT_24BITS(tptr)); - tptr+=3; + + 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); @@ -1127,10 +1085,9 @@ isis_print_mtid (const u_int8_t *tptr,const char *ident) { "Reserved for IETF Consensus", ISIS_MASK_MTID(EXTRACT_16BITS(tptr)))); - printf(" Topology (0x%03x)%s%s", + printf(" Topology (0x%03x), Flags: [%s]", ISIS_MASK_MTID(EXTRACT_16BITS(tptr)), - ISIS_MASK_MTSUB(EXTRACT_16BITS(tptr)) ? "" : ", no sub-TLVs present", - ISIS_MASK_MTATT(EXTRACT_16BITS(tptr)) ? ", ATT bit set" : "" ); + bittok2str(isis_mt_flag_values, "none",ISIS_MASK_MTFLAGS(EXTRACT_16BITS(tptr)))); return(2); } @@ -1146,7 +1103,7 @@ 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[14]; /* shared copy buffer for IPv4 and IPv6 prefixes */ + 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)) @@ -1182,31 +1139,29 @@ isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi processed+=byte_length; if (afi == IPV4) - printf("%sIPv4 prefix: %s/%d", + printf("%sIPv4 prefix: %15s/%u", ident, ipaddr_string(prefix), bit_length); #ifdef INET6 if (afi == IPV6) - printf("%sIPv6 prefix: %s/%d", + printf("%sIPv6 prefix: %s/%u", ident, ip6addr_string(prefix), bit_length); #endif - printf("%s Metric: %u, Distribution: %s", - ident, - metric, - ISIS_MASK_TLV_EXT_IP_UPDOWN(status_byte) ? "down" : "up"); + printf(", Distribution: %s, Metric: %u", + ISIS_MASK_TLV_EXT_IP_UPDOWN(status_byte) ? "down" : "up", + metric); - if (afi == IPV4) - printf(", %ssub-TLVs present", - ISIS_MASK_TLV_EXT_IP_SUBTLV(status_byte) ? "" : "no "); + if (afi == IPV4 && ISIS_MASK_TLV_EXT_IP_SUBTLV(status_byte)) + printf(", sub-TLVs present"); #ifdef INET6 if (afi == IPV6) - printf(", %s, %ssub-TLVs present", + printf(", %s%s", ISIS_MASK_TLV_EXT_IP6_IE(status_byte) ? "External" : "Internal", - ISIS_MASK_TLV_EXT_IP6_SUBTLV(status_byte) ? "" : "no "); + ISIS_MASK_TLV_EXT_IP6_SUBTLV(status_byte) ? ", sub-TLVs present" : ""); #endif if ((ISIS_MASK_TLV_EXT_IP_SUBTLV(status_byte) && afi == IPV4) || @@ -1218,7 +1173,7 @@ isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi if (!TTEST2(*tptr, 1)) return (0); sublen=*(tptr++); - processed+=sublen; + processed+=sublen+1; printf(" (%u)",sublen); /* print out subTLV length */ while (sublen>0) { @@ -1257,7 +1212,7 @@ static int isis_print (const u_int8_t *p, u_int length) 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, type, len, tmp, alen, lan_alen, prefix_len; + 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; @@ -1325,9 +1280,13 @@ static int isis_print (const u_int8_t *p, u_int length) 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); - break; } pdu_type=header->pdu_type; @@ -1380,15 +1339,15 @@ static int isis_print (const u_int8_t *p, u_int length) } TCHECK(*header_iih_lan); - printf("\n\t source-id: %s, holding time: %u, %s", - isis_print_sysid(header_iih_lan->source_id,SYSTEM_ID_LEN), + 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_nodeid(header_iih_lan->lan_id), + isis_print_id(header_iih_lan->lan_id, NODE_ID_LEN), (header_iih_lan->priority) & PRIORITY_MASK, pdu_len); @@ -1416,7 +1375,7 @@ static int isis_print (const u_int8_t *p, u_int length) TCHECK(*header_iih_ptp); printf("\n\t source-id: %s, holding time: %us, circuit-id: 0x%02x, %s, PDU length: %u", - isis_print_sysid(header_iih_ptp->source_id,SYSTEM_ID_LEN), + 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, @@ -1449,7 +1408,7 @@ static int isis_print (const u_int8_t *p, u_int length) TCHECK(*header_lsp); printf("\n\t lsp-id: %s, seq: 0x%08x, lifetime: %5us", - isis_print_lspid(header_lsp->lsp_id), + 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 - @@ -1497,12 +1456,12 @@ static int isis_print (const u_int8_t *p, u_int length) TCHECK(*header_csnp); printf("\n\t source-id: %s, PDU length: %u", - isis_print_nodeid(header_csnp->source_id), + isis_print_id(header_csnp->source_id, NODE_ID_LEN), pdu_len); printf("\n\t start lsp-id: %s", - isis_print_lspid(header_csnp->start_lsp_id)); + isis_print_id(header_csnp->start_lsp_id, LSP_ID_LEN)); printf("\n\t end lsp-id: %s", - isis_print_lspid(header_csnp->end_lsp_id)); + 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)) @@ -1529,7 +1488,7 @@ static int isis_print (const u_int8_t *p, u_int length) TCHECK(*header_psnp); printf("\n\t source-id: %s", - isis_print_nodeid(header_psnp->source_id)); + isis_print_id(header_psnp->source_id, NODE_ID_LEN)); if (vflag > 1) { if(!print_unknown_data(pptr,"\n\t ",ISIS_PSNP_HEADER_SIZE)) @@ -1560,12 +1519,12 @@ static int isis_print (const u_int8_t *p, u_int length) (long)(pptr-snapend)); return (1); } - type = *pptr++; - len = *pptr++; - tmp =len; /* copy temporary len & pointer to packet data */ + tlv_type = *pptr++; + tlv_len = *pptr++; + tmp =tlv_len; /* copy temporary len & pointer to packet data */ tptr = pptr; packet_len -= 2; - if (len > packet_len) { + if (tlv_len > packet_len) { break; } @@ -1573,18 +1532,18 @@ static int isis_print (const u_int8_t *p, u_int length) printf("\n\t %s TLV #%u, length: %u", tok2str(isis_tlv_values, "unknown", - type), - type, - len); + tlv_type), + tlv_type, + tlv_len); /* now check if we have a decoder otherwise do a hexdump at the end*/ - switch (type) { + switch (tlv_type) { case TLV_AREA_ADDR: if (!TTEST2(*tptr, 1)) goto trunctlv; alen = *tptr++; while (tmp && alen < tmp) { - printf("\n\t\tArea address (length: %u): %s", + printf("\n\t Area address (length: %u): %s", alen, print_nsap(tptr, alen)); tptr += alen; @@ -1600,7 +1559,7 @@ static int isis_print (const u_int8_t *p, u_int length) while (tmp >= ETHER_ADDR_LEN) { if (!TTEST2(*tptr, ETHER_ADDR_LEN)) goto trunctlv; - printf("\n\t\tIS Neighbor: %s",isis_print_sysid(tptr,ETHER_ADDR_LEN)); + printf("\n\t IS Neighbor: %s",isis_print_id(tptr,ETHER_ADDR_LEN)); tmp -= ETHER_ADDR_LEN; tptr += ETHER_ADDR_LEN; } @@ -1611,11 +1570,11 @@ static int isis_print (const u_int8_t *p, u_int length) goto trunctlv; lan_alen = *tptr++; /* LAN adress length */ tmp --; - printf("\n\t\tLAN address length %u bytes ",lan_alen); + 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_sysid(tptr,lan_alen)); + printf("\n\t\tIS Neighbor: %s",isis_print_id(tptr,lan_alen)); tmp -= lan_alen; tptr +=lan_alen; } @@ -1626,13 +1585,13 @@ static int isis_print (const u_int8_t *p, u_int length) case TLV_MT_IS_REACH: while (tmp >= 2+NODE_ID_LEN+3+1) { - mt_len = isis_print_mtid(tptr, "\n\t\t"); + 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\t"); + ext_is_len = isis_print_ext_is_reach(tptr,"\n\t ",tlv_type); if (ext_is_len == 0) /* did something go wrong ? */ goto trunctlv; @@ -1642,18 +1601,18 @@ static int isis_print (const u_int8_t *p, u_int length) break; case TLV_IS_ALIAS_ID: - while (tmp >= NODE_ID_LEN+3+1) { /* is it worth attempting a decode ? */ - ext_is_len = isis_print_ext_is_reach(tptr,"\n\t\t"); - if (ext_is_len == 0) /* did something go wrong ? */ - goto trunctlv; - tmp-=ext_is_len; - tptr+=ext_is_len; - } - break; + 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\t"); + 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; @@ -1663,7 +1622,7 @@ static int isis_print (const u_int8_t *p, u_int length) 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\t%s", + printf("\n\t %s", tok2str(isis_is_reach_virtual_values, "bogus virtual flag 0x%02x", *tptr++)); @@ -1671,7 +1630,8 @@ static int isis_print (const u_int8_t *p, u_int length) while (tmp >= sizeof(struct isis_tlv_is_reach)) { if (!TTEST(*tlv_is_reach)) goto trunctlv; - printf("\n\t\tIS Neighbor: %s", isis_print_nodeid(tlv_is_reach->neighbor_nodeid)); + 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++; @@ -1683,8 +1643,8 @@ static int isis_print (const u_int8_t *p, u_int length) while (tmp >= sizeof(struct isis_tlv_es_reach)) { if (!TTEST(*tlv_es_reach)) goto trunctlv; - printf("\n\t\tES Neighbor: %s", - isis_print_sysid(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN)); + 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++; @@ -1694,13 +1654,13 @@ static int isis_print (const u_int8_t *p, u_int length) /* those two TLVs share the same format */ case TLV_IP_REACH: case TLV_IP_REACH_EXT: - if (!isis_print_tlv_ip_reach(pptr, len)) + 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\t", IPV4); + 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; @@ -1710,13 +1670,13 @@ static int isis_print (const u_int8_t *p, u_int length) case TLV_MT_IP_REACH: while (tmp>0) { - mt_len = isis_print_mtid(tptr, "\n\t\t"); + 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\t", IPV4); + 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; @@ -1727,7 +1687,7 @@ static int isis_print (const u_int8_t *p, u_int length) #ifdef INET6 case TLV_IP6_REACH: while (tmp>0) { - ext_ip_len = isis_print_extd_ip_reach(tptr, "\n\t\t", IPV6); + 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; @@ -1737,13 +1697,13 @@ static int isis_print (const u_int8_t *p, u_int length) case TLV_MT_IP6_REACH: while (tmp>0) { - mt_len = isis_print_mtid(tptr, "\n\t\t"); + 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\t", IPV6); + 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; @@ -1756,7 +1716,7 @@ static int isis_print (const u_int8_t *p, u_int length) if (!TTEST2(*tptr, 16)) goto trunctlv; - printf("\n\t\tIPv6 interface address: %s", + printf("\n\t IPv6 interface address: %s", ip6addr_string(tptr)); tptr += 16; @@ -1768,31 +1728,31 @@ static int isis_print (const u_int8_t *p, u_int length) if (!TTEST2(*tptr, 1)) goto trunctlv; - printf("\n\t\t%s: ", + 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=1) { if (!TTEST2(*tptr, 1)) goto trunctlv; - printf("\n\t\tAdjacency State: %s", + printf("\n\t Adjacency State: %s", tok2str(isis_ptp_adjancey_values, "0x%02x", *tptr)); tmp--; } @@ -1811,28 +1771,28 @@ static int isis_print (const u_int8_t *p, u_int length) if (!TTEST2(tlv_ptp_adj->extd_local_circuit_id, sizeof(tlv_ptp_adj->extd_local_circuit_id))) goto trunctlv; - printf("\n\t\tExtended Local circuit ID: 0x%08x", + 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\tNeighbor SystemID: %s", - isis_print_sysid(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN)); + 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\tNeighbor Extended Local circuit ID: 0x%08x", + 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\tNLPID(s): "); + printf("\n\t NLPID(s): "); while (tmp>0) { if (!TTEST2(*(tptr), 1)) goto trunctlv; @@ -1849,21 +1809,21 @@ static int isis_print (const u_int8_t *p, u_int length) case TLV_TE_ROUTER_ID: if (!TTEST2(*pptr, 4)) goto trunctlv; - printf("\n\t\tTraffic Engineering Router ID: %s", ipaddr_string(pptr)); + 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\tIPv4 interface address: %s", ipaddr_string(tptr)); + printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr)); tptr += 4; tmp -= 4; } break; case TLV_HOSTNAME: - printf("\n\t\tHostname: "); + printf("\n\t Hostname: "); while (tmp>0) { if (!TTEST2(*tptr, 1)) goto trunctlv; @@ -1875,44 +1835,43 @@ static int isis_print (const u_int8_t *p, u_int length) case TLV_SHARED_RISK_GROUP: if (!TTEST2(*tptr, NODE_ID_LEN)) goto trunctlv; - printf("\n\t\tIS Neighbor: %s", isis_print_nodeid(tptr)); + printf("\n\t IS Neighbor: %s", isis_print_id(tptr, NODE_ID_LEN)); tptr+=(NODE_ID_LEN); - len-=(NODE_ID_LEN); + tmp-=(NODE_ID_LEN); if (!TTEST2(*tptr, 1)) goto trunctlv; printf(", %s", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered"); - len--; + tmp--; if (!TTEST2(*tptr,4)) goto trunctlv; - printf("\n\t\tIPv4 interface address: %s", ipaddr_string(tptr)); + printf("\n\t IPv4 interface address: %s", ipaddr_string(tptr)); tptr+=4; - len-=4; + tmp-=4; if (!TTEST2(*tptr,4)) goto trunctlv; - printf("\n\t\tIPv4 neighbor address: %s", ipaddr_string(tptr)); + printf("\n\t IPv4 neighbor address: %s", ipaddr_string(tptr)); tptr+=4; - len-=4; + tmp-=4; while (tmp>0) { if (!TTEST2(*tptr, 4)) goto trunctlv; - printf("\n\t\tLink-ID: 0x%08x", EXTRACT_32BITS(tptr)); + printf("\n\t Link-ID: 0x%08x", EXTRACT_32BITS(tptr)); tptr+=4; - len-=4; + tmp-=4; } break; case TLV_LSP: tlv_lsp = (const struct isis_tlv_lsp *)tptr; while(tmp>0) { - printf("\n\t\tlsp-id: %s", - isis_print_nodeid(tlv_lsp->lsp_id)); - if (!TTEST((tlv_lsp->lsp_id)[NODE_ID_LEN])) + if (!TTEST((tlv_lsp->lsp_id)[LSP_ID_LEN])) goto trunctlv; - printf("-%02x",(tlv_lsp->lsp_id)[NODE_ID_LEN]); + 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)); @@ -1930,7 +1889,7 @@ static int isis_print (const u_int8_t *p, u_int length) case TLV_CHECKSUM: if (!TTEST2(*tptr, 2)) goto trunctlv; - printf("\n\t\tchecksum: 0x%04x (%s)", + printf("\n\t checksum: 0x%04x (%s)", EXTRACT_16BITS(tptr), (osi_cksum(optr, length)) ? "incorrect" : "correct"); break; @@ -1940,13 +1899,13 @@ static int isis_print (const u_int8_t *p, u_int length) /* 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\t"); + 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\tmalformed MT-ID"); + printf("\n\t malformed MT-ID"); break; } } @@ -1959,14 +1918,14 @@ static int isis_print (const u_int8_t *p, u_int length) ra = ISIS_MASK_TLV_RESTART_RA(*tptr); tptr++; time_remain = EXTRACT_16BITS(tptr); - printf("\n\t\tRestart Request bit %s, Restart Acknowledgement bit %s\n\t\tRemaining holding time: %us", + 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\tInter-Domain Information Type: %s", + printf("\n\t Inter-Domain Information Type: %s", tok2str(isis_subtlv_idrp_values, "Unknown (0x%02x)", *tptr)); @@ -1979,7 +1938,7 @@ static int isis_print (const u_int8_t *p, u_int length) case SUBTLV_IDRP_LOCAL: case SUBTLV_IDRP_RES: default: - if(!print_unknown_data(tptr,"\n\t\t",len-1)) + if(!print_unknown_data(tptr,"\n\t ",tlv_len-1)) return(0); break; } @@ -1988,14 +1947,14 @@ static int isis_print (const u_int8_t *p, u_int length) case TLV_LSP_BUFFERSIZE: if (!TTEST2(*tptr, 2)) goto trunctlv; - printf("LSP Buffersize: %u",EXTRACT_16BITS(tptr)); + 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("%s",isis_print_sysid(tptr,SYSTEM_ID_LEN)); + printf("\n\t %s",isis_print_id(tptr,SYSTEM_ID_LEN)); tptr+=SYSTEM_ID_LEN; tmp-=SYSTEM_ID_LEN; } @@ -2004,7 +1963,7 @@ static int isis_print (const u_int8_t *p, u_int length) case TLV_PREFIX_NEIGH: if (!TTEST2(*tptr, sizeof(struct isis_metric_block))) goto trunctlv; - printf("Metric Block"); + 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); @@ -2027,13 +1986,13 @@ static int isis_print (const u_int8_t *p, u_int length) case TLV_IIH_SEQNR: if (!TTEST2(*tptr, 4)) /* check if four bytes are on the wire */ goto trunctlv; - printf("\n\t\tSequence number: %u", EXTRACT_32BITS(tptr) ); + 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\tVendor OUI Code: 0x%06x", EXTRACT_24BITS(tptr) ); + printf("\n\t Vendor OUI Code: 0x%06x", EXTRACT_24BITS(tptr) ); tptr+=3; tmp-=3; if (tmp > 0) /* hexdump the rest */ @@ -2053,23 +2012,23 @@ static int isis_print (const u_int8_t *p, u_int length) default: if (vflag <= 1) { - if(!print_unknown_data(pptr,"\n\t\t",len)) + 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\t",len)) + if(!print_unknown_data(pptr,"\n\t ",tlv_len)) return(0); } - pptr += len; - packet_len -= len; + pptr += tlv_len; + packet_len -= tlv_len; } if (packet_len != 0) { - printf("\n\t\t %d straggler bytes", packet_len); + printf("\n\t %u straggler bytes", packet_len); } return (1);