]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-isoclns.c
fix typo from previous commit
[tcpdump] / print-isoclns.c
index f4535bfcba85db19edcf989624fd98efdca5cffa..9f512b4253566adfa16310cf3ba952c9ad1ac58e 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.78 2003-03-30 01:21:13 hannes 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
@@ -696,75 +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);
-               sprintf(pos, "%02x", *cp++);
-               pos += strlen(pos);
-               if ((i==2)^(i==4)) {
-                       *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);
-               sprintf(pos, "%02x", *cp++);
-               pos += strlen(pos);
-               if ((i & 1) == 0) {
-                       *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++) {
-               sprintf(pos, "%02x", *cp++);
-               pos += strlen(pos);
-               if ((i & 1) == 0)
-                       *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++ = '.';
        }
-       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)
 {
@@ -1067,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;
@@ -1076,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);
@@ -1185,7 +1145,7 @@ isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi
                bit_length);
 #ifdef INET6
     if (afi == IPV6)
-        printf("%sIPv6 prefix: %39s/%u",
+        printf("%sIPv6 prefix: %s/%u",
                ident,
                ip6addr_string(prefix),
                bit_length);
@@ -1252,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;
@@ -1380,14 +1340,14 @@ static int isis_print (const u_int8_t *p, u_int length)
 
        TCHECK(*header_iih_lan);
        printf("\n\t  source-id: %s,  holding time: %us, Flags: [%s]",
-               isis_print_sysid(header_iih_lan->source_id,SYSTEM_ID_LEN),
+               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);
 
@@ -1415,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,
@@ -1448,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 -
@@ -1496,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))
@@ -1528,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))
@@ -1559,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;
        }
 
@@ -1572,12 +1532,12 @@ 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;
@@ -1599,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      IS 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;
            }
@@ -1614,7 +1574,7 @@ static int isis_print (const u_int8_t *p, u_int length)
            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;
             }
@@ -1631,7 +1591,7 @@ static int isis_print (const u_int8_t *p, u_int length)
                 tptr+=mt_len;
                 tmp-=mt_len;
 
-                ext_is_len = isis_print_ext_is_reach(tptr,"\n\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;
                    
@@ -1641,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      ");
-                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      ");
+                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;
@@ -1670,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      IS 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,7 +1644,7 @@ static int isis_print (const u_int8_t *p, u_int length)
                if (!TTEST(*tlv_es_reach))
                    goto trunctlv;
                printf("\n\t      ES Neighbor: %s",
-                       isis_print_sysid(tlv_es_reach->neighbor_sysid,SYSTEM_ID_LEN));
+                       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++;
@@ -1693,7 +1654,7 @@ 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, "\n\t      ", len))
+           if (!isis_print_tlv_ip_reach(pptr, "\n\t      ", tlv_len))
                return (1);
            break;
 
@@ -1774,24 +1735,24 @@ static int isis_print (const u_int8_t *p, u_int length)
 
            switch (*tptr) {
            case SUBTLV_AUTH_SIMPLE:
-               for(i=1;i<len;i++) {
+               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<len;i++) {
+               for(i=1;i<tlv_len;i++) {
                    if (!TTEST2(*(tptr+i), 1))
                        goto trunctlv;
                    printf("%02x",*(tptr+i));
                }
-               if (len != SUBTLV_AUTH_MD5_LEN+1)
+               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  ",len-1))
+               if(!print_unknown_data(tptr+1,"\n\t\t  ",tlv_len-1))
                    return(0);
                break;
            }
@@ -1818,7 +1779,7 @@ static int isis_print (const u_int8_t *p, u_int length)
                if (!TTEST2(tlv_ptp_adj->neighbor_sysid, SYSTEM_ID_LEN))
                    goto trunctlv;
                printf("\n\t      Neighbor SystemID: %s",
-                      isis_print_sysid(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN));
+                      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)) {
@@ -1874,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      IS 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      IPv4 interface address: %s", ipaddr_string(tptr));
            tptr+=4;
-           len-=4;
+           tmp-=4;
 
            if (!TTEST2(*tptr,4))
                 goto trunctlv;
            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      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      lsp-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));
@@ -1978,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      ",len-1))
+                if(!print_unknown_data(tptr,"\n\t      ",tlv_len-1))
                     return(0);
                 break;
             }
@@ -1994,7 +1954,7 @@ static int isis_print (const u_int8_t *p, u_int length)
             while (tmp >= SYSTEM_ID_LEN) {
                 if (!TTEST2(*tptr, SYSTEM_ID_LEN))
                     goto trunctlv;
-                printf("\n\t      %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;
             }
@@ -2052,19 +2012,19 @@ 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      ",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) {