]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-icmp.c
Add changes in 4.2.1.
[tcpdump] / print-icmp.c
index a6c0811007e2b7f952ed083efe7b046a5f6902bc..03b9505b1146da6f0dc91ad38466ece3ae1ef8ab 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.84 2006-12-12 10:48:43 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.87 2007-09-13 17:42:31 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -300,9 +300,6 @@ struct icmp_ext_t {
     u_int8_t icmp_ext_data[1];
 };
 
-struct icmp_mpls_ext_common_header_t {
-};
-
 struct icmp_mpls_ext_object_header_t {
     u_int8_t length[2];
     u_int8_t class_num;
@@ -349,6 +346,7 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
        const struct icmp_mpls_ext_object_header_t *icmp_mpls_ext_object_header;
        u_int hlen, dport, mtu, obj_tlen, obj_class_num, obj_ctype;
        char buf[MAXHOSTNAMELEN + 100];
+       struct cksum_vec vec[1];
 
        dp = (struct icmp *)bp;
         ext_dp = (struct icmp_ext_t *)bp;
@@ -415,7 +413,7 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
                case ICMP_UNREACH_NEEDFRAG:
                    {
                        register const struct mtu_discovery *mp;
-                       mp = (struct mtu_discovery *)&dp->icmp_void;
+                       mp = (struct mtu_discovery *)(u_char *)&dp->icmp_void;
                        mtu = EXTRACT_16BITS(&mp->nexthopmtu);
                        if (mtu) {
                                (void)snprintf(buf, sizeof(buf),
@@ -563,8 +561,11 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
        (void)printf("ICMP %s, length %u", str, plen);
        if (vflag && !fragmented) { /* don't attempt checksumming if this is a frag */
                u_int16_t sum, icmp_sum;
+               struct cksum_vec vec[1];
                if (TTEST2(*bp, plen)) {
-                       sum = in_cksum((u_short*)dp, plen, 0);
+                       vec[0].ptr = (const u_int8_t *)(void *)dp;
+                       vec[0].len = plen;
+                       sum = in_cksum(vec, 1);
                        if (sum != 0) {
                                icmp_sum = EXTRACT_16BITS(&dp->icmp_cksum);
                                (void)printf(" (wrong icmp cksum %x (->%x)!)",
@@ -589,13 +590,26 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
        }
 
         /*
-         * Check if the extended ICMP header indicates that there is
-         * MPLS extension header present for the "interesting" ICMP types.
+         * Attempt to decode the MPLS extensions only for some ICMP types.
          */
-        if (vflag >= 1 && plen > ICMP_EXTD_MINLEN &&
-            ext_dp->icmp_length && ICMP_MPLS_EXT_TYPE(dp->icmp_type)) {
+        if (vflag >= 1 && plen > ICMP_EXTD_MINLEN && ICMP_MPLS_EXT_TYPE(dp->icmp_type)) {
 
             TCHECK(*ext_dp);
+
+            /*
+             * Check first if the mpls extension header shows a non-zero length.
+             * If the length field is not set then silently verify the checksum
+             * to check if an extension header is present. This is expedient,
+             * however not all implementations set the length field proper.
+             */
+            if (!ext_dp->icmp_length) {
+                vec[0].ptr = (const u_int8_t *)(void *)&ext_dp->icmp_ext_version_res;
+                vec[0].len = plen - ICMP_EXTD_MINLEN;
+                if (in_cksum(vec, 1)) {
+                    return;
+                }
+            }
+
             printf("\n\tMPLS extension v%u",
                    ICMP_MPLS_EXT_EXTRACT_VERSION(*(ext_dp->icmp_ext_version_res)));
             
@@ -609,8 +623,11 @@ icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
             }
 
             hlen = plen - ICMP_EXTD_MINLEN;
-            printf(", checksum 0x%04x (unverified), length %u", /* FIXME */
+            vec[0].ptr = (const u_int8_t *)(void *)&ext_dp->icmp_ext_version_res;
+            vec[0].len = hlen;
+            printf(", checksum 0x%04x (%scorrect), length %u",
                    EXTRACT_16BITS(ext_dp->icmp_ext_checksum),
+                   in_cksum(vec, 1) ? "in" : "",
                    hlen);
 
             hlen -= 4; /* subtract common header size */