hi all,

even if i sound like a broken record;

pls disregard the last patch; [its all contained in this as well]

-pls find attached a patch to better display [hexdump]
 the content of unknown TLV and subTLV data;
-plus misc cleanups;
-bugfix for a nasty bug in the EXT_IS_REACH subTLV decoder

/hannes

Index: print-isoclns.c
===================================================================
RCS file: /tcpdump/master/tcpdump/print-isoclns.c,v
retrieving revision 1.38
diff -u -r1.38 print-isoclns.c
--- print-isoclns.c     2002/03/14 05:59:53     1.38
+++ print-isoclns.c     2002/03/20 01:01:21
@@ -620,6 +620,38 @@
        printf("-%02x", *cp);
 }
 
+/*
+ *  this is a generic routine for printing unknown data;
+ *  as it is called from various places (TLV and subTLV parsing routines)
+ *  we pass on the linefeed plus identation string to
+ *  get a proper output
+ */
+
+static int
+isis_print_unknown_data(const u_char *cp,const u_char *lf,int len)
+{
+        int i;
+       
+       printf("%s0x0000: ",lf);
+       for(i=0;i<len;i++) {
+           if (!TTEST2(*(cp+i), 1))
+             goto trunctlv;
+           printf("%02x",*(cp+i));
+           if (i%2)
+               printf(" ");
+           if (i/16!=(i+1)/16) {
+               if (i<(len-1))
+                   printf("%s0x%04x: ",lf,i);
+           }
+       }
+       return(0); /* everything is ok */
+
+trunctlv:
+    printf("%spacket exceeded snapshot",lf);
+    return(1);
+
+}
+
 static int
 isis_print_tlv_ip_reach (const u_char *cp, int length)
 {
@@ -724,7 +756,7 @@
     const struct isis_tlv_ptp_adj *tlv_ptp_adj;
     const struct isis_tlv_is_reach *tlv_is_reach;
 
-    u_char pdu_type, max_area, type, len, tmp, alen, subl, subt, tslen, ttslen;
+    u_char pdu_type, max_area, id_length, type, len, tmp, alen, subl, subt, tslen;
     const u_char *optr, *pptr, *tptr;
     u_short packet_len,pdu_len;
     u_int i,j,bit_length,byte_length,metric;
@@ -773,7 +805,7 @@
     max_area = header->max_area;
     switch(max_area) {
     case 0:
-       max_area = 3;                   /* silly shit */
+       max_area = 3;    /* silly shit */
        break;
     case 255:
        printf(", bad packet -- 255 areas");
@@ -781,10 +813,35 @@
     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:
+       printf(", bad packet -- illegal sys-ID length (%u)", id_length);      
+       return (0);
+       break;
+    }
 
-    printf(", hlen: %u, v: %u, sys-id-len: 6 (0), max-area: %u (%u)",
+    printf(", hlen: %u, v: %u, sys-id-len: %u (%u), max-area: %u (%u)",
            header->fixed_len,
-           header->pkt_version,
+           header->version,
+          id_length,
+          header->id_length,
            max_area,
            header->max_area);
            
@@ -976,6 +1033,8 @@
 
     default:
        printf(", PDU type (0x%02x) not supported", pdu_type);
+       if(isis_print_unknown_data(pptr,"\n\t\t  ",length))
+           return(1);  
        return (1);
     }
 
@@ -1087,7 +1146,13 @@
                     goto trunctlv;
                 tslen=*(tptr++);
                 printf(", %ssub-TLVs present",tslen ? "" : "no ");
-       
+               /* so far no decoding of subTLVs is supported
+                * so lets print out a hexdump of the unknown subTLV data
+                */
+               if(!tslen){
+                    if(isis_print_unknown_data(tptr,"\n\t\t\t    ",tslen))
+                         return(1);
+               }
                 tptr+=tslen;
                 tmp-=(13+tslen);
             }
@@ -1113,9 +1178,8 @@
                 tslen=*(tptr++);
                 printf(", %ssub-TLVs present",tslen ? "" : "no ");
                 if (tslen) {
-                    printf(" (%u)",tslen);
-                    ttslen=tslen;
-                    while (ttslen>0) {
+                    printf(" (%u)",tslen);                    
+                    while (tslen>0) {
                         if (!TTEST2(*tptr,2))
                             goto trunctlv;
                         printf("\n\t\t\t  ");
@@ -1156,15 +1220,13 @@
                         case SUBTLV_EXT_IS_REACH_UNRESERVED_BW :
                             printf("Unreserved bandwidth:");
                             for (i = 0; i < 8; i++) {
-                                if (!TTEST2(*tptr,4))
+                                if (!TTEST2(*(tptr+i*4),4))
                                     goto trunctlv;
                                 j = EXTRACT_32BITS(tptr);
                                 memcpy (&bw, &j, 4);   
                                 printf("\n\t\t\t    priority level %d: %.3f Mbps",
                                        i, bw*8/1000000 );
-                                tptr+=4;
                             }
-                            tptr-=32;
                             break;      
                         case SUBTLV_EXT_IS_REACH_TE_METRIC:
                             if (!TTEST2(*tptr,3))
@@ -1196,8 +1258,7 @@
                                    printf(", ");
                                i++;
                            }
-                           tptr++;
-                           printf(", Priority %u", *tptr);
+                           printf(", Priority %u", *(tptr+1));
                             break;
                        case SUBTLV_EXT_IS_REACH_INTF_SW_CAP_DESCR:
                            printf("Interface Switching Capability");
@@ -1205,31 +1266,31 @@
                            if (!TTEST2(*tptr,1))
                              goto trunctlv;
                            printf("\n\t\t\t  Interface Switching Capability:%s",
-                                  tok2str(isis_gmpls_sw_cap_values, "Unknown", 
*(tptr++)));
-                           tptr++;
+                                  tok2str(isis_gmpls_sw_cap_values, "Unknown", 
+*(tptr)));
 
-                           if (!TTEST2(*tptr,1))
+                           if (!TTEST2(*(tptr+1),1))
                              goto trunctlv;
                            printf(", LSP Encoding: %s",
-                                  tok2str(isis_gmpls_lsp_enc_values, "Unknown", 
*(tptr++)));
-                           tptr++;
+                                  tok2str(isis_gmpls_lsp_enc_values, "Unknown", 
+*(tptr+1)));
 
-                           if (!TTEST2(*tptr,2)) /* skip 2 res. bytes */
+                           if (!TTEST2(*(tptr+2),2)) /* skip 2 res. bytes */
                              goto trunctlv;
-                           tptr+=2;
 
                            printf("\n\t\t\t  Max LSP Bandwidth:");
                            for (i = 0; i < 8; i++) {
-                             if (!TTEST2(*tptr,4))
+                             if (!TTEST2(*(tptr+(i*4)+4),4))
                                goto trunctlv;
                              j = EXTRACT_32BITS(tptr);
                              memcpy (&bw, &j, 4);      
                              printf("\n\t\t\t    priority level %d: %.3f Mbps",
                                     i, bw*8/1000000 );
-                             tptr+=4;
                             }
                            /* there is some optional stuff left to decode but this is 
as of yet
-                              not specified */
+                              not specified so just lets hexdump what is left */
+                           if(!subl){
+                             if(isis_print_unknown_data(tptr,"\n\t\t\t    ",subl-36))
+                                 return(1);
+                           }
                            break;
                         case 250:
                         case 251:
@@ -1243,12 +1304,14 @@
                              break;                                 
                         default:
                             printf("unknown subTLV, type %d, length %d", subt, subl);
+                           if(isis_print_unknown_data(tptr,"\n\t\t\t    ",subl))
+                               return(1);
+                           break;
                         }      
                    tptr+=subl;
-                   ttslen-=(subl+2);
+                   tslen-=(subl+2);
                     }
                 }      
-                tptr+=tslen;
                 tmp-=(11+tslen);
             }
             break;
@@ -1359,7 +1422,14 @@
                if (ISIS_MASK_TLV_EXT_IP_SUBTLV(j)) {
                    if (!TTEST2(*tptr, 1))
                      return (1);                 
-                   printf(" (%u)",*tptr);  /* no subTLV decoder supported - just 
print out subTLV length */
+                   printf(" (%u)",*tptr);   /* print out subTLV length */          
+
+                   /* so far no decoding of subTLVs is supported
+                     * so lets print out a hexdump of the unknown subTLV data
+                    */
+                   if(isis_print_unknown_data(tptr,"\n\t\t\t    ",*tptr))
+                     return(1);
+
                    i-=*tptr;
                    tptr+=*tptr++;
                }
@@ -1406,7 +1476,14 @@
                if (ISIS_MASK_TLV_IP6_SUBTLV(j)) {
                    if (!TTEST2(*tptr, 1))
                      return (1);                 
-                   printf(" (%u)",*tptr); /* no subTLV decoder supported - just print 
out subTLV length */
+                   printf(" (%u)",*tptr);   /* print out subTLV length */          
+
+                   /* so far no decoding of subTLVs is supported
+                     * so lets print out a hexdump of the unknown subTLV data
+                    */
+                   if(isis_print_unknown_tlv(tptr,"\n\t\t\t    ",*tptr))
+                     return(1);
+
                    i-=*tptr;
                    tptr+=*tptr++;
                }
@@ -1461,22 +1538,13 @@
                break;
            case SUBTLV_AUTH_PRIVATE:
                printf("\n\t\t\tRouting Domain private password: ");
-               tptr=pptr+1;
-               len--;
-               for(i=0;i<len;i++) {
-                   if (!TTEST2(*(tptr+i), 1))
-                       goto trunctlv;
-                   printf("%02x",*(tptr+i)); /* formatted hex output of unknown data 
*/
-                   if (i%2)
-                       printf(" ");
-                   if (i/16!=(i+1)/16) {
-                      if (i<(len-1))
-                          printf("\n\t\t\t  ");
-                   }
-               }       
+               if(isis_print_unknown_data(pptr+1,"\n\t\t\t    ",len-1))
+                   return(1);  
                break;
            default:
                printf("\n\t\t\tunknown Authentication method");
+               if(isis_print_unknown_data(pptr+1,"\n\t\t\t    ",len-1))
+                   return(1);  
                break;
            }
            break;
@@ -1608,13 +1676,13 @@
                printf("-%02x",(tlv_lsp->lsp_id)[SYSTEM_ID_LEN+1]);
                if (!TTEST2(tlv_lsp->sequence_number, 4))
                    goto trunctlv;
-               printf("\n\t\t\t  sequence number: 
0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number));
+               printf(", seq: 0x%08x",EXTRACT_32BITS(tlv_lsp->sequence_number));
                if (!TTEST2(tlv_lsp->remaining_lifetime, 2))
                    goto trunctlv;
-               printf("\n\t\t\t  Remaining lifetime: 
%5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime));
+               printf(", lifetime: %5ds",EXTRACT_16BITS(tlv_lsp->remaining_lifetime));
                if (!TTEST2(tlv_lsp->checksum, 2))
                    goto trunctlv;
-               printf("\n\t\t\t  checksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum));
+               printf(", chksum: 0x%04x",EXTRACT_16BITS(tlv_lsp->checksum));
                i+=sizeof(struct isis_tlv_lsp);
                tlv_lsp++;
            }
@@ -1697,20 +1765,9 @@
            break;
 
        default:
-           printf("unknown TLV, type %d, length %d\n\t\t\t", type, len);
-           tptr=pptr;
-
-           for(i=0;i<len;i++) {
-               if (!TTEST2(*(tptr+i), 1))
-                   goto trunctlv;
-               printf("%02x",*(tptr+i)); /* formatted hex output of unknown TLV data 
*/
-               if (i%2)
-                   printf(" ");
-               if (i/16!=(i+1)/16) {
-                 if (i<(len-1))
-                   printf("\n\t\t\t");
-               }
-           }
+           printf("unknown TLV, type %d, length %d", type, len);
+           if(isis_print_unknown_data(pptr,"\n\t\t\t",len))
+               return(1);
            break;
        }
 

Reply via email to