]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-isoclns.c
Fix a signed-vs-unsigned comparison warning.
[tcpdump] / print-isoclns.c
index d13329567ececcf910f0ae93a41c7b305102797b..16cedfc4996848ebd7d744471ead5f083ad18f61 100644 (file)
@@ -25,8 +25,8 @@
  */
 
 #ifndef lint
-static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.98 2003-10-21 23:04:23 hannes Exp $ (LBL)";
+static const char rcsid[] _U_ =
+    "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.108 2003-11-16 09:36:25 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -114,14 +114,14 @@ static struct tok isis_pdu_values[] = {
 #define TLV_IS_ALIAS_ID         24  /* draft-ietf-isis-ext-lsp-frags-02 */
 #define TLV_DECNET_PHASE4       42
 #define TLV_LUCENT_PRIVATE      66
-#define TLV_IP_REACH            128 /* rfc1195, rfc2966 */
+#define TLV_INT_IP_REACH        128 /* rfc1195, rfc2966 */
 #define TLV_PROTOCOLS           129 /* rfc1195 */
-#define TLV_IP_REACH_EXT        130 /* rfc1195, rfc2966 */
+#define TLV_EXT_IP_REACH        130 /* rfc1195, rfc2966 */
 #define TLV_IDRP_INFO           131 /* rfc1195 */
 #define TLV_IPADDR              132 /* rfc1195 */
 #define TLV_IPAUTH              133 /* rfc1195 */
 #define TLV_TE_ROUTER_ID        134 /* draft-ietf-isis-traffic-05 */
-#define TLV_EXT_IP_REACH        135 /* draft-ietf-isis-traffic-05 */
+#define TLV_EXTD_IP_REACH       135 /* draft-ietf-isis-traffic-05 */
 #define TLV_HOSTNAME            137 /* rfc2763 */
 #define TLV_SHARED_RISK_GROUP   138 /* draft-ietf-isis-gmpls-extensions */
 #define TLV_NORTEL_PRIVATE1     176
@@ -155,14 +155,14 @@ static struct tok isis_tlv_values[] = {
     { TLV_IS_ALIAS_ID,       "IS Alias ID"},
     { TLV_DECNET_PHASE4,     "DECnet Phase IV"},
     { TLV_LUCENT_PRIVATE,    "Lucent Proprietary"},
-    { TLV_IP_REACH,          "IPv4 Internal Reachability"},
+    { TLV_INT_IP_REACH,      "IPv4 Internal Reachability"},
     { TLV_PROTOCOLS,         "Protocols supported"},
-    { TLV_IP_REACH_EXT,      "IPv4 External Reachability"},
+    { TLV_EXT_IP_REACH,      "IPv4 External Reachability"},
     { TLV_IDRP_INFO,         "Inter-Domain Information Type"},
     { TLV_IPADDR,            "IPv4 Interface address(es)"},
     { TLV_IPAUTH,            "IPv4 authentication (deprecated)"},
     { TLV_TE_ROUTER_ID,      "Traffic Engineering Router ID"},
-    { TLV_EXT_IP_REACH,      "Extended IPv4 Reachability"},
+    { TLV_EXTD_IP_REACH,      "Extended IPv4 Reachability"},
     { TLV_HOSTNAME,          "Hostname"},
     { TLV_SHARED_RISK_GROUP, "Shared Risk Link Group"},
     { TLV_NORTEL_PRIVATE1,   "Nortel Proprietary"},
@@ -214,12 +214,12 @@ static struct tok isis_ext_is_reach_subtlv_values[] = {
     { 0, NULL }
 };
 
-#define SUBTLV_IP_REACH_ADMIN_TAG32               1
-#define SUBTLV_IP_REACH_ADMIN_TAG64               2
+#define SUBTLV_EXTD_IP_REACH_ADMIN_TAG32          1
+#define SUBTLV_EXTD_IP_REACH_ADMIN_TAG64          2
 
 static struct tok isis_ext_ip_reach_subtlv_values[] = {
-    { SUBTLV_IP_REACH_ADMIN_TAG32,                "32-Bit Administrative tag" },
-    { SUBTLV_IP_REACH_ADMIN_TAG64,                "64-Bit Administrative tag" },
+    { SUBTLV_EXTD_IP_REACH_ADMIN_TAG32,           "32-Bit Administrative tag" },
+    { SUBTLV_EXTD_IP_REACH_ADMIN_TAG64,           "64-Bit Administrative tag" },
     { 0, NULL }
 };
 
@@ -266,11 +266,11 @@ static struct tok isis_mt_flag_values[] = {
     { 0, NULL}
 };
 
-#define ISIS_MASK_TLV_EXT_IP_UPDOWN(x)     ((x)&0x80)
-#define ISIS_MASK_TLV_EXT_IP_SUBTLV(x)     ((x)&0x40)
+#define ISIS_MASK_TLV_EXTD_IP_UPDOWN(x)     ((x)&0x80)
+#define ISIS_MASK_TLV_EXTD_IP_SUBTLV(x)     ((x)&0x40)
 
-#define ISIS_MASK_TLV_EXT_IP6_IE(x)        ((x)&0x40)
-#define ISIS_MASK_TLV_EXT_IP6_SUBTLV(x)    ((x)&0x20)
+#define ISIS_MASK_TLV_EXTD_IP6_IE(x)        ((x)&0x40)
+#define ISIS_MASK_TLV_EXTD_IP6_SUBTLV(x)    ((x)&0x20)
 
 #define ISIS_LSP_TLV_METRIC_SUPPORTED(x)   ((x)&0x80)
 #define ISIS_LSP_TLV_METRIC_IE(x)          ((x)&0x40)
@@ -434,15 +434,11 @@ struct isis_tlv_lsp {
     u_int8_t checksum[2];
 };
 
-
-/* allocate space for the following string
- * xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx
- * 50 bytes plus one termination byte */
 static char *
 print_nsap(register const u_int8_t *pptr, register int nsap_length)
 {
        int nsap_idx;
-       static char nsap_ascii_output[51];
+       static char nsap_ascii_output[sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx")];
         char *junk_buf = nsap_ascii_output;
 
         if (nsap_length < 1 || nsap_length > 20) {
@@ -686,15 +682,12 @@ esis_print(const u_int8_t *p, u_int length)
                }
 }
 
-/* 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 */
+/* shared routine for printing system, node and lsp-ids */
 static char *
 isis_print_id(const u_int8_t *cp, int id_len)
 {
     int i;
-    static char id[21];
+    static char id[sizeof("xxxx.xxxx.xxxx.yy-zz")];
     char *pos = id;
 
     for (i = 1; i <= SYSTEM_ID_LEN; i++) {
@@ -817,7 +810,7 @@ isis_print_ip_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *i
            goto trunctlv;
 
     switch(subt) {
-    case SUBTLV_IP_REACH_ADMIN_TAG32:
+    case SUBTLV_EXTD_IP_REACH_ADMIN_TAG32:
         while (subl >= 4) {
            printf(", 0x%08x (=%u)",
                   EXTRACT_32BITS(tptr),
@@ -826,7 +819,7 @@ isis_print_ip_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *i
            subl-=4;
        }
        break;
-    case SUBTLV_IP_REACH_ADMIN_TAG64:
+    case SUBTLV_EXTD_IP_REACH_ADMIN_TAG64:
         while (subl >= 8) {
            printf(", 0x%08x%08x",
                   EXTRACT_32BITS(tptr),
@@ -954,10 +947,10 @@ trunctlv:
  */
 
 static int
-isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv) {
+isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv_type) {
 
     char ident_buffer[20];
-    int subt,subl,tslen;
+    int subtlv_type,subtlv_len,subtlv_sum_len;
     int proc_bytes = 0; /* how many bytes did we process ? */
     
     if (!TTEST2(*tptr, NODE_ID_LEN))
@@ -966,8 +959,8 @@ isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv) {
     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))
+    if (tlv_type != TLV_IS_ALIAS_ID) { /* the Alias TLV Metric field is implicit 0 */
+        if (!TTEST2(*tptr, 3))    /* and is therefore skipped */
            return(0);
        printf(", Metric: %d",EXTRACT_24BITS(tptr));
        tptr+=3;
@@ -975,23 +968,23 @@ isis_print_ext_is_reach (const u_int8_t *tptr,const char *ident, int tlv) {
         
     if (!TTEST2(*tptr, 1))
         return(0);
-    tslen=*(tptr++); /* read out subTLV length */
+    subtlv_sum_len=*(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) {
+    printf(", %ssub-TLVs present",subtlv_sum_len ? "" : "no ");
+    if (subtlv_sum_len) {
+        printf(" (%u)",subtlv_sum_len);
+        while (subtlv_sum_len>0) {
             if (!TTEST2(*tptr,2))
                 return(0);
-            subt=*(tptr++);
-            subl=*(tptr++);
+            subtlv_type=*(tptr++);
+            subtlv_len=*(tptr++);
             /* prepend the ident string */
             snprintf(ident_buffer, sizeof(ident_buffer), "%s  ",ident);
-            if(!isis_print_is_reach_subtlv(tptr,subt,subl,ident_buffer))
+            if(!isis_print_is_reach_subtlv(tptr,subtlv_type,subtlv_len,ident_buffer))
                 return(0);
-            tptr+=subl;
-            tslen-=(subl+2);
-            proc_bytes+=(subl+2);
+            tptr+=subtlv_len;
+            subtlv_sum_len-=(subtlv_len+2);
+            proc_bytes+=(subtlv_len+2);
         }
     }
     return(proc_bytes);
@@ -1081,20 +1074,20 @@ isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi
 #endif 
    
     printf(", Distribution: %s, Metric: %u",
-           ISIS_MASK_TLV_EXT_IP_UPDOWN(status_byte) ? "down" : "up",
+           ISIS_MASK_TLV_EXTD_IP_UPDOWN(status_byte) ? "down" : "up",
            metric);
 
-    if (afi == IPV4 && ISIS_MASK_TLV_EXT_IP_SUBTLV(status_byte))
+    if (afi == IPV4 && ISIS_MASK_TLV_EXTD_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" : "");
+               ISIS_MASK_TLV_EXTD_IP6_IE(status_byte) ? "External" : "Internal",
+               ISIS_MASK_TLV_EXTD_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)) {
+    if ((ISIS_MASK_TLV_EXTD_IP_SUBTLV(status_byte)  && afi == IPV4) ||
+        (ISIS_MASK_TLV_EXTD_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
@@ -1229,10 +1222,14 @@ static int isis_print (const u_int8_t *p, u_int length)
 
        case L1_LAN_IIH:
        case L2_LAN_IIH:
-           printf(", source-id %s", isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN));
+           printf(", src-id %s",
+                   isis_print_id(header_iih_lan->source_id,SYSTEM_ID_LEN));
+           printf(", lan-id %s, prio %u",
+                   isis_print_id(header_iih_lan->lan_id,NODE_ID_LEN),
+                   header_iih_lan->priority);
            break;
        case PTP_IIH:
-           printf(", source-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN));
+           printf(", src-id %s", isis_print_id(header_iih_ptp->source_id,SYSTEM_ID_LEN));
            break;
        case L1_LSP:
        case L2_LSP:
@@ -1243,11 +1240,11 @@ static int isis_print (const u_int8_t *p, u_int length)
            break;
        case L1_CSNP:
        case L2_CSNP:
-           printf(", source-id %s", isis_print_id(header_csnp->source_id,SYSTEM_ID_LEN));
+           printf(", src-id %s", isis_print_id(header_csnp->source_id,SYSTEM_ID_LEN));
            break;
        case L1_PSNP:
        case L2_PSNP:
-           printf(", source-id %s", isis_print_id(header_psnp->source_id,SYSTEM_ID_LEN));
+           printf(", src-id %s", isis_print_id(header_psnp->source_id,SYSTEM_ID_LEN));
            break;
 
        }
@@ -1328,13 +1325,15 @@ 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",
+       printf("\n\t  source-id: %s, holding time: %us, Flags: [%s]",
                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),
+                       header_iih_ptp->circuit_type));
+
+       printf("\n\t  circuit-id: 0x%02x, PDU length: %u",
+               header_iih_ptp->circuit_id,
                pdu_len);
 
         if (vflag > 1) {
@@ -1361,19 +1360,25 @@ 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",
+       printf("\n\t  lsp-id: %s, seq: 0x%08x, lifetime: %5us\n\t  chksum: 0x%04x",
                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, " : "");
+               EXTRACT_16BITS(header_lsp->remaining_lifetime),
+               EXTRACT_16BITS(header_lsp->checksum));
+
+        /* if this is a purge do not attempt to verify the checksum */
+        if ( EXTRACT_16BITS(header_lsp->remaining_lifetime) == 0 &&
+             EXTRACT_16BITS(header_lsp->checksum) == 0)
+            printf(" (purged)");
+        else
+            /* verify the checksum -
+             * checking starts at the lsp-id field at byte position [12]
+             * hence the length needs to be reduced by 12 bytes */
+            printf(" (%s)", (osi_cksum((u_int8_t *)header_lsp->lsp_id, length-12)) ? "incorrect" : "correct");
+
+       printf(", PDU length: %u, Flags: [ %s",
+               pdu_len,
+               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 " : "");
@@ -1383,7 +1388,7 @@ static int isis_print (const u_int8_t *p, u_int length)
            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)));
+       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))
@@ -1441,8 +1446,9 @@ static int isis_print (const u_int8_t *p, u_int length)
        }
 
        TCHECK(*header_psnp);
-       printf("\n\t  source-id:    %s",
-               isis_print_id(header_psnp->source_id, NODE_ID_LEN));
+       printf("\n\t  source-id:    %s, PDU length: %u",
+               isis_print_id(header_psnp->source_id, NODE_ID_LEN),
+               pdu_len);
 
         if (vflag > 1) {
             if(!print_unknown_data(pptr,"\n\t  ",ISIS_PSNP_HEADER_SIZE))
@@ -1513,7 +1519,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_id(tptr,ETHER_ADDR_LEN));
+                printf("\n\t      SNPA: %s",isis_print_id(tptr,ETHER_ADDR_LEN));
                 tmp -= ETHER_ADDR_LEN;
                 tptr += ETHER_ADDR_LEN;
            }
@@ -1606,13 +1612,13 @@ static int isis_print (const u_int8_t *p, u_int length)
             break;
 
             /* those two TLVs share the same format */
-       case TLV_IP_REACH:
-       case TLV_IP_REACH_EXT:
+       case TLV_INT_IP_REACH:
+       case TLV_EXT_IP_REACH:
            if (!isis_print_tlv_ip_reach(pptr, "\n\t      ", tlv_len))
                return (1);
            break;
 
-       case TLV_EXT_IP_REACH:
+       case TLV_EXTD_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 ? */
@@ -1717,22 +1723,23 @@ static int isis_print (const u_int8_t *p, u_int length)
            if(tmp>=1) {
                if (!TTEST2(*tptr, 1))
                    goto trunctlv;
-               printf("\n\t      Adjacency State: %s",
-                      tok2str(isis_ptp_adjancey_values, "0x%02x", *tptr));
+               printf("\n\t      Adjacency State: %s (%u)",
+                      tok2str(isis_ptp_adjancey_values, "unknown", *tptr),
+                        *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",
+               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",
+               printf("\n\t      Neighbor System-ID: %s",
                       isis_print_id(tlv_ptp_adj->neighbor_sysid,SYSTEM_ID_LEN));
                tmp-=SYSTEM_ID_LEN;
            }
@@ -1740,7 +1747,7 @@ static int isis_print (const u_int8_t *p, u_int length)
                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",
+               printf("\n\t      Neighbor Extended Local circuit-ID: 0x%08x",
                       EXTRACT_32BITS(tlv_ptp_adj->neighbor_extd_local_circuit_id));
            }
            break;
@@ -1750,12 +1757,14 @@ static int isis_print (const u_int8_t *p, u_int length)
            while (tmp>0) {
                if (!TTEST2(*(tptr), 1))
                    goto trunctlv;
-               printf("%s",
+               printf("%s (0x%02x)",
                        tok2str(osi_nlpid_values,
-                               "Unknown 0x%02x",
-                               *tptr++));
+                               "unknown",
+                               *tptr),
+                       *tptr);
                if (tmp>1) /* further NPLIDs ? - put comma */
                    printf(", ");
+                tptr++;
                 tmp--;
            }
            break;
@@ -1795,7 +1804,7 @@ static int isis_print (const u_int8_t *p, u_int length)
 
            if (!TTEST2(*tptr, 1))
                 goto trunctlv;
-           printf(", %s", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered");
+           printf(", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered");
            tmp--;
 
            if (!TTEST2(*tptr,4))
@@ -1843,9 +1852,15 @@ static int isis_print (const u_int8_t *p, u_int length)
        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");
+           printf("\n\t      checksum: 0x%04x ", EXTRACT_16BITS(tptr));
+            /* do not attempt to verify the checksum if it is zero
+             * most likely a HMAC-MD5 TLV is also present and
+             * to avoid conflicts the checksum TLV is zeroed.
+             * see rfc3358 for details
+             */
+            if (EXTRACT_16BITS(tptr) == 0)
+                printf("(unverified)");
+            else printf("(%s)", osi_cksum(optr, length) ? "incorrect" : "correct");
            break;
 
        case TLV_MT_SUPPORTED: