]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-juniper.c
Backout CHANGES update - wrong branch
[tcpdump] / print-juniper.c
index 204bd7382388e62d2aa5f8af33a412882d9b3047..fde0b9350433603cf6aa3ce2b2b8d53fe43a98f7 100644 (file)
@@ -15,7 +15,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-juniper.c,v 1.8.2.15 2005-07-20 22:20:54 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-juniper.c,v 1.8.2.22 2006-05-10 22:42:46 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -40,6 +40,7 @@ static const char rcsid[] _U_ =
 #define JUNIPER_BPF_IN            1       /* Incoming packet */
 #define JUNIPER_BPF_PKT_IN        0x1     /* Incoming packet */
 #define JUNIPER_BPF_NO_L2         0x2     /* L2 header stripped */
+#define JUNIPER_BPF_EXT           0x80    /* extensions present */
 #define JUNIPER_MGC_NUMBER        0x4d4743 /* = "MGC" */
 
 #define JUNIPER_LSQ_COOKIE_RE         (1 << 3)
@@ -357,6 +358,74 @@ juniper_pppoe_print(const struct pcap_pkthdr *h, register const u_char *p)
 }
 #endif
 
+#ifdef DLT_JUNIPER_ETHER
+u_int
+juniper_ether_print(const struct pcap_pkthdr *h, register const u_char *p)
+{
+        struct juniper_l2info_t l2info;
+
+        l2info.pictype = DLT_JUNIPER_ETHER;
+        if(juniper_parse_header(p, h, &l2info) == 0)
+            return l2info.header_len;
+
+        p+=l2info.header_len;
+        /* this DLT contains nothing but raw Ethernet frames */
+        ether_print(p, l2info.length, l2info.caplen);
+        return l2info.header_len;
+}
+#endif
+
+#ifdef DLT_JUNIPER_PPP
+u_int
+juniper_ppp_print(const struct pcap_pkthdr *h, register const u_char *p)
+{
+        struct juniper_l2info_t l2info;
+
+        l2info.pictype = DLT_JUNIPER_PPP;
+        if(juniper_parse_header(p, h, &l2info) == 0)
+            return l2info.header_len;
+
+        p+=l2info.header_len;
+        /* this DLT contains nothing but raw ppp frames */
+        ppp_print(p, l2info.length);
+        return l2info.header_len;
+}
+#endif
+
+#ifdef DLT_JUNIPER_FRELAY
+u_int
+juniper_frelay_print(const struct pcap_pkthdr *h, register const u_char *p)
+{
+        struct juniper_l2info_t l2info;
+
+        l2info.pictype = DLT_JUNIPER_FRELAY;
+        if(juniper_parse_header(p, h, &l2info) == 0)
+            return l2info.header_len;
+
+        p+=l2info.header_len;
+        /* this DLT contains nothing but raw frame-relay frames */
+        fr_print(p, l2info.length);
+        return l2info.header_len;
+}
+#endif
+
+#ifdef DLT_JUNIPER_CHDLC
+u_int
+juniper_chdlc_print(const struct pcap_pkthdr *h, register const u_char *p)
+{
+        struct juniper_l2info_t l2info;
+
+        l2info.pictype = DLT_JUNIPER_CHDLC;
+        if(juniper_parse_header(p, h, &l2info) == 0)
+            return l2info.header_len;
+
+        p+=l2info.header_len;
+        /* this DLT contains nothing but raw c-hdlc frames */
+        chdlc_print(p, l2info.length);
+        return l2info.header_len;
+}
+#endif
+
 #ifdef DLT_JUNIPER_PPPOE_ATM
 u_int
 juniper_pppoe_atm_print(const struct pcap_pkthdr *h, register const u_char *p)
@@ -601,7 +670,6 @@ u_int
 juniper_atm2_print(const struct pcap_pkthdr *h, register const u_char *p)
 {
         u_int16_t extracted_ethertype;
-        u_int32_t control_word;
 
         struct juniper_l2info_t l2info;
 
@@ -612,12 +680,6 @@ juniper_atm2_print(const struct pcap_pkthdr *h, register const u_char *p)
         p+=l2info.header_len;
 
         if (l2info.cookie[7] & ATM2_PKT_TYPE_MASK) { /* OAM cell ? */
-            control_word = EXTRACT_32BITS(p);
-            if(control_word == 0 || control_word == 0x08000000) {
-                l2info.header_len += 4;
-                l2info.length -= 4;
-                p += 4;
-            }
             oam_print(p,l2info.length,ATM_OAM_NOHEC);
             return l2info.header_len;
         }
@@ -732,7 +794,10 @@ static int
 juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct juniper_l2info_t *l2info) {
 
     struct juniper_cookie_table_t *lp = juniper_cookie_table;
-    u_int idx;
+    u_int idx, offset;
+#ifdef DLT_JUNIPER_ATM2
+    u_int32_t control_word;
+#endif
 
     l2info->header_len = 0;
     l2info->cookie_len = 0;
@@ -747,12 +812,19 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip
     if (EXTRACT_24BITS(p) != JUNIPER_MGC_NUMBER) { /* magic number found ? */
         printf("no magic-number found!");
         return 0;
-    } else
-        l2info->header_len = 4;
+    } 
 
     if (eflag) /* print direction */
         printf("%3s ",tok2str(juniper_direction_values,"---",l2info->direction));
 
+    /* extensions present ?  - calculate how much bytes to skip */
+    if ((p[3] & JUNIPER_BPF_EXT ) == JUNIPER_BPF_EXT ) {
+        offset = 6 + EXTRACT_16BITS(p+4);
+        if (eflag>1)
+            printf("ext-len %u, ",EXTRACT_16BITS(p+4));
+    } else
+        offset = 4;
+
     if ((p[3] & JUNIPER_BPF_NO_L2 ) == JUNIPER_BPF_NO_L2 ) {            
         if (eflag)
             printf("no-L2-hdr, ");
@@ -761,15 +833,15 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip
          * perform the v4/v6 heuristics
          * to figure out what it is
          */
-        TCHECK2(p[8],1);
-        if(ip_heuristic_guess(p+8,l2info->length-8) == 0)
+        TCHECK2(p[offset+4],1);
+        if(ip_heuristic_guess(p+offset+4,l2info->length-(offset+4)) == 0)
             printf("no IP-hdr found!");
 
-        l2info->header_len+=4;
+        l2info->header_len=offset+4;
         return 0; /* stop parsing the output further */
         
     }
-
+    l2info->header_len = offset;
     p+=l2info->header_len;
     l2info->length -= l2info->header_len;
     l2info->caplen -= l2info->header_len;
@@ -805,6 +877,8 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip
 #endif
 
             l2info->header_len += l2info->cookie_len;
+            l2info->length -= l2info->cookie_len;
+            l2info->caplen -= l2info->cookie_len;
 
             if (eflag)
                 printf("%s-PIC, cookie-len %u",
@@ -833,6 +907,7 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip
 
     /* DLT_ specific parsing */
     switch(l2info->pictype) {
+#ifdef DLT_JUNIPER_MLPPP
     case DLT_JUNIPER_MLPPP:
         switch (l2info->cookie_type) {
         case LS_COOKIE_ID:
@@ -847,6 +922,8 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip
             break;
         }
         break;
+#endif
+#ifdef DLT_JUNIPER_MLFR
     case DLT_JUNIPER_MLFR:
         switch (l2info->cookie_type) {
         case LS_COOKIE_ID:
@@ -868,6 +945,8 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip
             break;
         }
         break;
+#endif
+#ifdef DLT_JUNIPER_MFR
     case DLT_JUNIPER_MFR:
         switch (l2info->cookie_type) {
         case LS_COOKIE_ID:
@@ -886,17 +965,52 @@ juniper_parse_header (const u_char *p, const struct pcap_pkthdr *h, struct junip
             break;
         }
         break;
+#endif
+#ifdef DLT_JUNIPER_ATM2
     case DLT_JUNIPER_ATM2:
         TCHECK2(p[0],4);
         /* ATM cell relay control word present ? */
-        if (l2info->cookie[7] & ATM2_PKT_TYPE_MASK && *p & 0x08) {
-            l2info->header_len += 4;
+        if (l2info->cookie[7] & ATM2_PKT_TYPE_MASK) {
+            control_word = EXTRACT_32BITS(p);
+            /* some control word heuristics */
+            switch(control_word) {
+            case 0: /* zero control word */
+            case 0x08000000: /* < JUNOS 7.4 control-word */
+            case 0x08380000: /* cntl word plus cell length (56) >= JUNOS 7.4*/
+                l2info->header_len += 4;
+                break;
+            default:
+                break;
+            }
+            
             if (eflag)
-                printf("control-word 0x%08x ",EXTRACT_32BITS(p));
+                printf("control-word 0x%08x ", control_word);
         }
         break;
+#endif
+#ifdef DLT_JUNIPER_ATM1
     case DLT_JUNIPER_ATM1:
+        break;
+#endif
+#ifdef DLT_JUNIPER_PPP
+    case DLT_JUNIPER_PPP:
+        break;
+#endif
+#ifdef DLT_JUNIPER_CHDLC
+    case DLT_JUNIPER_CHDLC:
+        break;
+#endif
+#ifdef DLT_JUNIPER_ETHER
+    case DLT_JUNIPER_ETHER:
+        break;
+#endif
+#ifdef DLT_JUNIPER_FRELAY
+    case DLT_JUNIPER_FRELAY:
+        break;
+#endif
+
     default:
+        printf("Unknown Juniper DLT_ type %u: ", l2info->pictype);
         break;
     }