]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-isoclns.c
Add some additional bounds checking.
[tcpdump] / print-isoclns.c
index 56737044e22dbc546e7a1e51310d67c26d918f71..f134ed7ab52dcac6ae28fc688e60ab448cc66410 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.121 2004-09-15 17:54:11 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.124 2004-10-19 15:27:55 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -42,27 +42,11 @@ static const char rcsid[] _U_ =
 #include "addrtoname.h"
 #include "ethertype.h"
 #include "ether.h"
+#include "nlpid.h"
 #include "extract.h"
 #include "gmpls.h"
 #include "oui.h"
 
-#define        NLPID_CLNP      0x81 /* iso9577 */
-#define        NLPID_ESIS      0x82 /* iso9577 */
-#define        NLPID_ISIS      0x83 /* iso9577 */
-#define NLPID_IP6       0x8e
-#define NLPID_IP        0xcc
-#define        NLPID_NULLNS    0
-
-static struct tok osi_nlpid_values[] = {
-    { NLPID_NULLNS, "NULL-NS"},
-    { NLPID_CLNP,   "CLNP"},
-    { NLPID_ESIS,   "ES-IS"},
-    { NLPID_ISIS,   "IS-IS"},
-    { NLPID_IP,     "IPv4"},
-    { NLPID_IP6,    "IPv6"},
-    { 0, NULL }
-};
-
 #define IPV4            1       /* AFI value */
 #define IPV6            2       /* AFI value */
 
@@ -509,7 +493,10 @@ void isoclns_print(const u_int8_t *p, u_int length, u_int caplen)
             return;
         }
 
-        printf("%s",tok2str(osi_nlpid_values,"Unknown NLPID (0x%02x)",*p));
+        if (eflag)
+            printf("nlpid %s (0x%02x), ",
+                   tok2str(nlpid_values,"Unknown NLPID (0x%02x)",*p),
+                   *p);
         
        switch (*p) {
 
@@ -531,6 +518,20 @@ void isoclns_print(const u_int8_t *p, u_int length, u_int caplen)
                (void)printf(", length: %u", length);
                break;
 
+        case NLPID_IP:
+                ip_print(p+1, length-1);
+                break;
+
+#ifdef INET6
+        case NLPID_IP6:
+                ip6_print(p+1, length-1);
+                break;
+#endif
+
+        case NLPID_PPP:
+                ppp_print(p+1, length-1);
+                break;
+
        default:
                (void)printf(", length: %u", length);
                if (caplen > 1)
@@ -579,6 +580,9 @@ static int clnp_print (const u_int8_t *pptr, u_int length)
         li = clnp_header->length_indicator;
         optr = pptr;
 
+        if (!eflag)
+            printf("CLNP, ");
+
         /*
          * Sanity checking of the header.
          */
@@ -598,13 +602,13 @@ static int clnp_print (const u_int8_t *pptr, u_int length)
         pptr += (1 + source_address_length);
 
         if (vflag < 1) {
-            printf("%s > %s, length %u",
+            printf("%s > %s, length %u",
                    print_nsap(source_address, source_address_length),
                    print_nsap(dest_address, dest_address_length),
                    length);
             return (1);
         }
-        printf("length %u", length);
+        printf("length %u", length);
 
     printf("\n\t%s PDU, hlen: %u, v: %u, lifetime: %u.%us, PDU length: %u, checksum: 0x%04x ",
            tok2str(clnp_pdu_values,
@@ -677,11 +681,14 @@ esis_print(const u_int8_t *pptr, u_int length)
        u_int li,esis_pdu_type,source_address_length, source_address_number;
        const struct esis_header_t *esis_header;
 
+        if (!eflag)
+            printf("ES-IS, ");
+
        if (length <= 2) {
                if (qflag)
-                       printf(" bad pkt!");
+                       printf("bad pkt!");
                else
-                       printf(" no header at all!");
+                       printf("no header at all!");
                return;
        }
 
@@ -694,22 +701,22 @@ esis_print(const u_int8_t *pptr, u_int length)
          */
 
         if (esis_header->nlpid != NLPID_ESIS) {
-            printf("nlpid 0x%02x packet not supported", esis_header->nlpid);
+            printf("nlpid 0x%02x packet not supported", esis_header->nlpid);
             return;
         }
 
         if (esis_header->version != ESIS_VERSION) {
-            printf("version %d packet not supported", esis_header->version);
+            printf("version %d packet not supported", esis_header->version);
             return;
         }
                 
        if (li > length) {
-            printf("length indicator(%d) > PDU size (%d)!", li, length);
+            printf("length indicator(%d) > PDU size (%d)!", li, length);
             return;
        }
 
        if (li < sizeof(struct esis_header_t) + 2) {
-            printf("length indicator < min PDU size %d:", li);
+            printf("length indicator < min PDU size %d:", li);
             while (--length != 0)
                 printf("%02X", *pptr++);
             return;
@@ -718,12 +725,12 @@ esis_print(const u_int8_t *pptr, u_int length)
         esis_pdu_type = esis_header->type & ESIS_PDU_TYPE_MASK;
 
         if (vflag < 1) {
-            printf("%s, length %u",
+            printf("%s, length %u",
                    tok2str(esis_pdu_values,"unknown type (%u)",esis_pdu_type),
                    length);
             return;
         } else
-            printf("length %u\n\t%s (%u)",
+            printf("length %u\n\t%s (%u)",
                    length,
                    tok2str(esis_pdu_values,"unknown type: %u", esis_pdu_type),
                    esis_pdu_type);
@@ -838,7 +845,7 @@ esis_print(const u_int8_t *pptr, u_int length)
             case ESIS_OPTION_PROTOCOLS:
                 while (opli>0) {
                     printf("%s (0x%02x)",
-                           tok2str(osi_nlpid_values,
+                           tok2str(nlpid_values,
                                    "unknown",
                                    *tptr),
                            *tptr);
@@ -1369,23 +1376,26 @@ static int isis_print (const u_int8_t *p, u_int length)
     header_csnp = (const struct isis_csnp_header *)pptr;
     header_psnp = (const struct isis_psnp_header *)pptr;
 
+    if (!eflag)
+        printf("IS-IS, ");
+
     /*
      * Sanity checking of the header.
      */
 
     if (isis_header->version != ISIS_VERSION) {
-       printf("version %d packet not supported", isis_header->version);
+       printf("version %d packet not supported", isis_header->version);
        return (0);
     }
 
     if ((isis_header->id_length != SYSTEM_ID_LEN) && (isis_header->id_length != 0)) {
-       printf("system ID length of %d is not supported",
+       printf("system ID length of %d is not supported",
               isis_header->id_length);
        return (0);
     }
 
     if (isis_header->pdu_version != ISIS_VERSION) {
-       printf("version %d packet not supported", isis_header->pdu_version);
+       printf("version %d packet not supported", isis_header->pdu_version);
        return (0);
     }
 
@@ -1395,7 +1405,7 @@ static int isis_print (const u_int8_t *p, u_int length)
        max_area = 3;    /* silly shit */
        break;
     case 255:
-       printf("bad packet -- 255 areas");
+       printf("bad packet -- 255 areas");
        return (0);
     default:
        break;
@@ -1424,7 +1434,7 @@ static int isis_print (const u_int8_t *p, u_int length)
 
     /* toss any non 6-byte sys-ID len PDUs */
     if (id_length != 6 ) { 
-       printf("bad packet -- illegal sys-ID length (%u)", id_length);
+       printf("bad packet -- illegal sys-ID length (%u)", id_length);
        return (0);
     }
 
@@ -1432,7 +1442,7 @@ static int isis_print (const u_int8_t *p, u_int length)
 
     /* in non-verbose mode print the basic PDU Type plus PDU specific brief information*/
     if (vflag < 1) {
-        printf("%s", tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type));
+        printf("%s", tok2str(isis_pdu_values,"unknown PDU-Type %u",pdu_type));
 
        switch (pdu_type) {
 
@@ -1974,7 +1984,7 @@ static int isis_print (const u_int8_t *p, u_int length)
                if (!TTEST2(*(tptr), 1))
                    goto trunctlv;
                printf("%s (0x%02x)",
-                       tok2str(osi_nlpid_values,
+                       tok2str(nlpid_values,
                                "unknown",
                                *tptr),
                        *tptr);