]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-fr.c
bgp: Parse BGP extended message support capability
[tcpdump] / print-fr.c
index 9a9273ec02dac2922772c897e6f973979a74f857..f0d7fbeb12b38d4019a4f0bfa618e6124ec74966 100644 (file)
@@ -36,7 +36,6 @@
 #include "llc.h"
 #include "nlpid.h"
 #include "extract.h"
-#include "oui.h"
 
 static void frf15_print(netdissect_options *ndo, const u_char *, u_int);
 
@@ -148,14 +147,22 @@ q922_string(netdissect_options *ndo, const u_char *p, u_int length)
 
     static u_int dlci, addr_len;
     static uint32_t flags;
-    static char buffer[sizeof("DLCI xxxxxxxxxx")];
+    static char buffer[sizeof("parse_q922_header() returned XXXXXXXXXXX")];
+    int ret;
     memset(buffer, 0, sizeof(buffer));
 
-    if (parse_q922_header(ndo, p, &dlci, &addr_len, &flags, length) == 1){
-        nd_snprintf(buffer, sizeof(buffer), "DLCI %u", dlci);
+    ret = parse_q922_header(ndo, p, &dlci, &addr_len, &flags, length);
+    if (ret == 1) {
+        snprintf(buffer, sizeof(buffer), "DLCI %u", dlci);
+        return buffer;
+    } else if (ret == 0) {
+        return "<Invalid DLCI>";
+    } else if (ret == -1) {
+        return "<Truncated>";
+    } else {
+        snprintf(buffer, sizeof(buffer), "parse_q922_header() returned %d", ret);
+        return buffer;
     }
-
-    return buffer;
 }
 
 
@@ -213,23 +220,22 @@ fr_hdr_print(netdissect_options *ndo, int length, u_int addr_len,
     }
 }
 
-u_int
+/* Frame Relay */
+void
 fr_if_print(netdissect_options *ndo,
             const struct pcap_pkthdr *h, const u_char *p)
 {
        u_int length = h->len;
        u_int caplen = h->caplen;
 
-       ndo->ndo_protocol = "fr_if";
-        ND_TCHECK_4(p); /* minimum frame header length */
+       ndo->ndo_protocol = "fr";
+       if (caplen < 4) {       /* minimum frame header length */
+               nd_print_trunc(ndo);
+               ndo->ndo_ll_hdr_len += caplen;
+               return;
+       }
 
-        if ((length = fr_print(ndo, p, length)) == 0)
-            return (0);
-        else
-            return length;
-trunc:
-        nd_print_trunc(ndo);
-        return caplen;
+       ndo->ndo_ll_hdr_len += fr_print(ndo, p, length);
 }
 
 u_int
@@ -371,23 +377,22 @@ trunc:
 
 }
 
-u_int
+/* Multi Link Frame Relay (FRF.16) */
+void
 mfr_if_print(netdissect_options *ndo,
              const struct pcap_pkthdr *h, const u_char *p)
 {
        u_int length = h->len;
        u_int caplen = h->caplen;
 
-       ndo->ndo_protocol = "mfr_if";
-        ND_TCHECK_2(p); /* minimum frame header length */
+       ndo->ndo_protocol = "mfr";
+       if (caplen < 2) {       /* minimum frame header length */
+               nd_print_trunc(ndo);
+               ndo->ndo_ll_hdr_len += caplen;
+               return;
+       }
 
-        if ((length = mfr_print(ndo, p, length)) == 0)
-            return (0);
-        else
-            return length;
-trunc:
-        nd_print_trunc(ndo);
-        return caplen;
+       ndo->ndo_ll_hdr_len += mfr_print(ndo, p, length);
 }
 
 
@@ -458,7 +463,13 @@ mfr_print(netdissect_options *ndo,
  */
 
     ndo->ndo_protocol = "mfr";
-    ND_TCHECK_4(p); /* minimum frame header length */
+
+    if (length < 4) {  /* minimum frame header length */
+        ND_PRINT("[length %u < 4]", length);
+        nd_print_invalid(ndo);
+        return length;
+    }
+    ND_TCHECK_4(p);
 
     if ((GET_U_1(p) & MFR_BEC_MASK) == MFR_CTRL_FRAME && GET_U_1(p + 1) == 0) {
         ND_PRINT("FRF.16 Control, Flags [%s], %s, length %u",
@@ -495,6 +506,12 @@ mfr_print(netdissect_options *ndo,
             switch (ie_type) {
 
             case MFR_CTRL_IE_MAGIC_NUM:
+                /* FRF.16.1 Section 3.4.3 Magic Number Information Element */
+                if (ie_len != 4) {
+                    ND_PRINT("[IE data length %d != 4]", ie_len);
+                    nd_print_invalid(ndo);
+                    break;
+                }
                 ND_PRINT("0x%08x", GET_BE_U_4(tptr));
                 break;
 
@@ -604,7 +621,6 @@ frf15_print(netdissect_options *ndo,
 
     if (length < 2)
         goto trunc;
-    ND_TCHECK_2(p);
 
     flags = GET_U_1(p)&MFR_BEC_MASK;
     sequence_num = (GET_U_1(p)&0x1e)<<7 | GET_U_1(p + 1);
@@ -620,7 +636,7 @@ frf15_print(netdissect_options *ndo,
  * dig as deep as we can - e.g. on the first (B) fragment
  * there is enough payload to print the IP header
  * on non (B) fragments it depends if the fragmentation
- * model is end-to-end or interface based wether we want to print
+ * model is end-to-end or interface based whether we want to print
  * another Q.922 header
  */
     return;
@@ -910,7 +926,6 @@ q933_print(netdissect_options *ndo,
        ND_PRINT("%s, codeset %u", is_ansi ? "ANSI" : "CCITT", codeset);
 
        if (call_ref_length != 0) {
-               ND_TCHECK_1(p);
                if (call_ref_length > 1 || GET_U_1(p) != 0) {
                        /*
                         * Not a dummy call reference.