]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-icmp6.c
icmp: clean up the extension code and comments.
[tcpdump] / print-icmp6.c
index a1289e1cc43ce1f15aec9a4ab196edde326e760a..4a335270e5f53b99a8de20005e82682e5a7c65d9 100644 (file)
@@ -490,10 +490,6 @@ static void dnsname_print(netdissect_options *ndo, const u_char *, const u_char
 static void icmp6_nodeinfo_print(netdissect_options *ndo, u_int, const u_char *, const u_char *);
 static void icmp6_rrenum_print(netdissect_options *ndo, const u_char *, const u_char *);
 
-#ifndef abs
-#define abs(a) ((0 < (a)) ? (a) : -(a))
-#endif
-
 /*
  * DIO: Updated to RFC6550, as published in 2012: section 6. (page 30)
  */
@@ -711,7 +707,6 @@ static const struct tok icmp6_nd_na_flag_values[] = {
     { 0,       NULL }
 };
 
-
 static const struct tok icmp6_opt_values[] = {
    { ND_OPT_SOURCE_LINKADDR, "source link-address"},
    { ND_OPT_TARGET_LINKADDR, "destination link-address"},
@@ -879,23 +874,19 @@ rpl_dao_print(netdissect_options *ndo,
         const char *dagid_str = "<elided>";
         uint8_t rpl_flags;
 
-        ND_TCHECK_SIZE(dao);
-        if (length < ND_RPL_DAO_MIN_LEN)
-               goto tooshort;
+        ND_ICHECK_U(length, <, ND_RPL_DAO_MIN_LEN);
 
         bp += ND_RPL_DAO_MIN_LEN;
         length -= ND_RPL_DAO_MIN_LEN;
         rpl_flags = GET_U_1(dao->rpl_flags);
         if(RPL_DAO_D(rpl_flags)) {
-                ND_TCHECK_LEN(dao->rpl_dagid, DAGID_LEN);
-                if (length < DAGID_LEN)
-                       goto tooshort;
-                dagid_str = ip6addr_string (ndo, dao->rpl_dagid);
+                ND_ICHECK_U(length, <, DAGID_LEN);
+                dagid_str = GET_IP6ADDR_STRING(dao->rpl_dagid);
                 bp += DAGID_LEN;
                 length -= DAGID_LEN;
         }
 
-        ND_PRINT(" [dagid:%s,seq:%u,instance:%u%s%s,%02x]",
+        ND_PRINT(" [dagid:%s,seq:%u,instance:%u%s%s,flags:%02x]",
                   dagid_str,
                   GET_U_1(dao->rpl_daoseq),
                   GET_U_1(dao->rpl_instanceid),
@@ -906,14 +897,9 @@ rpl_dao_print(netdissect_options *ndo,
         if(ndo->ndo_vflag > 1) {
                 rpl_printopts(ndo, bp, length);
         }
-       return;
-
-trunc:
-       nd_print_trunc(ndo);
-       return;
-
-tooshort:
-       ND_PRINT(" [|length too short]");
+        return;
+invalid:
+        nd_print_invalid(ndo);
 }
 
 static void
@@ -923,17 +909,13 @@ rpl_daoack_print(netdissect_options *ndo,
         const struct nd_rpl_daoack *daoack = (const struct nd_rpl_daoack *)bp;
         const char *dagid_str = "<elided>";
 
-        ND_TCHECK_LEN(daoack, ND_RPL_DAOACK_MIN_LEN);
-        if (length < ND_RPL_DAOACK_MIN_LEN)
-               goto tooshort;
+        ND_ICHECK_U(length, <, ND_RPL_DAOACK_MIN_LEN);
 
         bp += ND_RPL_DAOACK_MIN_LEN;
         length -= ND_RPL_DAOACK_MIN_LEN;
         if(RPL_DAOACK_D(GET_U_1(daoack->rpl_flags))) {
-                ND_TCHECK_LEN(daoack->rpl_dagid, DAGID_LEN);
-                if (length < DAGID_LEN)
-                       goto tooshort;
-                dagid_str = ip6addr_string (ndo, daoack->rpl_dagid);
+                ND_ICHECK_U(length, <, DAGID_LEN);
+                dagid_str = GET_IP6ADDR_STRING(daoack->rpl_dagid);
                 bp += DAGID_LEN;
                 length -= DAGID_LEN;
         }
@@ -948,14 +930,9 @@ rpl_daoack_print(netdissect_options *ndo,
         if(ndo->ndo_vflag > 1) {
                 rpl_printopts(ndo, bp, length);
         }
-       return;
-
-trunc:
-       nd_print_trunc(ndo);
-       return;
-
-tooshort:
-       ND_PRINT(" [|dao-length too short]");
+        return;
+invalid:
+        nd_print_invalid(ndo);
 }
 
 static void
@@ -1015,7 +992,6 @@ trunc:
 
 }
 
-
 void
 icmp6_print(netdissect_options *ndo,
             const u_char *bp, u_int length, const u_char *bp2, int fragmented)
@@ -1520,7 +1496,7 @@ icmp6_opt_print(netdissect_options *ndo, const u_char *bp, int resid)
                        default:
                                goto trunc;
                        }
-                       ND_PRINT(" %s/%u", ip6addr_string(ndo, (const u_char *)&in6),
+                       ND_PRINT(" %s/%u", ip6addr_string(ndo, (const u_char *)&in6), /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */
                                   GET_U_1(opri->nd_opt_rti_prefixlen));
                        ND_PRINT(", pref=%s",
                                 get_rtpref(GET_U_1(opri->nd_opt_rti_flags)));
@@ -1776,7 +1752,6 @@ icmp6_nodeinfo_print(netdissect_options *ndo, u_int icmp6len, const u_char *bp,
                        break;
                }
 
-
                /* XXX backward compat, icmp-name-lookup-03 */
                if (siz == sizeof(*ni6)) {
                        ND_PRINT(", 03 draft");