]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-forces.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-forces.c
index 31cd2df483a241f639e5859cfa6b6a997226250e..197d6c65354704f984b728fb93143ed05d05448d 100644 (file)
@@ -18,9 +18,7 @@
 
 /* specification: RFC 5810 */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
 #define TLV_HDRL       4
 #define ILV_HDRL       8
 
-#define TOM_RSVD       0x0
-#define TOM_ASSNSETUP  0x1
-#define TOM_ASSNTEARD  0x2
-#define TOM_CONFIG     0x3
-#define TOM_QUERY      0x4
-#define TOM_EVENTNOT   0x5
-#define TOM_PKTREDIR   0x6
-#define TOM_HEARTBT    0x0F
-#define TOM_ASSNSETREP         0x11
-#define TOM_CONFIGREP  0x13
-#define TOM_QUERYREP   0x14
+#define TOM_RSVD       0x0
+#define TOM_ASSNSETUP  0x1
+#define TOM_ASSNTEARD  0x2
+#define TOM_CONFIG     0x3
+#define TOM_QUERY      0x4
+#define TOM_EVENTNOT   0x5
+#define TOM_PKTREDIR   0x6
+#define TOM_HEARTBT    0x0F
+#define TOM_ASSNSETREP 0x11
+#define TOM_CONFIGREP  0x13
+#define TOM_QUERYREP   0x14
 
 /*
  * tom_h Flags: resv1(8b):maxtlvs(4b):resv2(2b):mintlv(2b)
@@ -250,7 +248,7 @@ struct pathdata_h {
 };
 
 #define        B_FULLD         0x1
-#define        B_SPARD         0x2
+#define        B_SPARD         0x2
 #define B_RESTV                0x4
 #define B_KEYIN                0x8
 #define B_APPND                0x10
@@ -661,7 +659,7 @@ prestlv_print(netdissect_options *ndo,
               uint16_t op_msk _U_, int indent)
 {
        const struct forces_tlv *tlv = (const struct forces_tlv *)pptr;
-       const u_char *tdp = (const u_char *) TLV_DATA(tlv);
+       const u_char *tdp = TLV_DATA(tlv);
        const struct res_val *r = (const struct res_val *)tdp;
        u_int dlen;
        uint8_t result;
@@ -701,7 +699,7 @@ fdatatlv_print(netdissect_options *ndo,
 {
        const struct forces_tlv *tlv = (const struct forces_tlv *)pptr;
        u_int rlen;
-       const u_char *tdp = (const u_char *) TLV_DATA(tlv);
+       const u_char *tdp = TLV_DATA(tlv);
        uint16_t type;
 
        /*
@@ -745,12 +743,11 @@ sdatailv_print(netdissect_options *ndo,
        indent += 1;
        while (rlen != 0) {
                char *ib = indent_pr(indent, 1);
-               const u_char *tdp = (const u_char *) ILV_DATA(ilv);
+               const u_char *tdp = ILV_DATA(ilv);
                invilv = ilv_valid(ndo, ilv, rlen);
                if (invilv) {
-                       ND_PRINT("%s[", ib + 1);
-                       hex_print(ndo, ib, tdp, rlen);
-                       ND_PRINT("\n%s]\n", ib + 1);
+                       ND_PRINT("Error: %s, rlen %u\n",
+                                tok2str(ForCES_TLV_err, NULL, invilv), rlen);
                        goto invalid;
                }
                if (ndo->ndo_vflag >= 3) {
@@ -775,7 +772,7 @@ sdatatlv_print(netdissect_options *ndo,
 {
        const struct forces_tlv *tlv = (const struct forces_tlv *)pptr;
        u_int rlen;
-       const u_char *tdp = (const u_char *) TLV_DATA(tlv);
+       const u_char *tdp = TLV_DATA(tlv);
        uint16_t type;
 
        /*
@@ -802,7 +799,7 @@ pkeyitlv_print(netdissect_options *ndo,
                uint16_t op_msk, int indent)
 {
        const struct forces_tlv *tlv = (const struct forces_tlv *)pptr;
-       const u_char *tdp = (const u_char *) TLV_DATA(tlv);
+       const u_char *tdp = TLV_DATA(tlv);
        const u_char *dp = tdp + 4;
        const struct forces_tlv *kdtlv = (const struct forces_tlv *)dp;
        uint32_t id;
@@ -828,7 +825,7 @@ pkeyitlv_print(netdissect_options *ndo,
         * go past the end of the containing TLV).
         */
        tll = GET_BE_U_2(kdtlv->length);
-       dp = (const u_char *) TLV_DATA(kdtlv);
+       dp = TLV_DATA(kdtlv);
        return fdatatlv_print(ndo, dp, tll, op_msk, indent);
 invalid:
        return -1;
@@ -849,9 +846,7 @@ pdatacnt_print(netdissect_options *ndo,
                ND_PRINT("%sTABLE APPEND\n", ib);
        }
        for (i = 0; i < IDcnt; i++) {
-               ND_TCHECK_4(pptr);
-               if (len < 4)
-                       goto invalid;
+               ND_ICHECK_U(len, <, 4);
                id = GET_BE_U_4(pptr);
                if (ndo->ndo_vflag >= 3)
                        ND_PRINT("%sID#%02u: %u\n", ib, i + 1, id);
@@ -965,10 +960,9 @@ pdatacnt_print(netdissect_options *ndo,
 
                        chk_op_type(ndo, type, op_msk, ops->op_msk);
 
-                       if (ops->print(ndo, (const u_char *)pdtlv,
-                                       tll + pad + TLV_HDRL, op_msk,
-                                       indent + 2) == -1)
-                               goto invalid;
+                       ND_ICHECK_U(ops->print(ndo, (const u_char *)pdtlv,
+                                   tll + pad + TLV_HDRL, op_msk, indent + 2),
+                                   ==, -1);
                        len -= (TLV_HDRL + pad + tll);
                } else {
                        ND_PRINT("Invalid path data content type 0x%x len %u\n",
@@ -1001,8 +995,7 @@ pdata_print(netdissect_options *ndo,
        uint16_t idcnt = 0;
 
        ND_TCHECK_SIZE(pdh);
-       if (len < sizeof(struct pathdata_h))
-               goto invalid;
+       ND_ICHECK_ZU(len, <, sizeof(struct pathdata_h));
        if (ndo->ndo_vflag >= 3) {
                ND_PRINT("\n%sPathdata: Flags 0x%x ID count %u\n",
                       ib, GET_BE_U_2(pdh->pflags),
@@ -1078,7 +1071,7 @@ genoptlv_print(netdissect_options *ndo,
         * length is large enough but not too large (it doesn't
         * go past the end of the containing TLV).
         */
-       const u_char *dp = (const u_char *) TLV_DATA(pdtlv);
+       const u_char *dp = TLV_DATA(pdtlv);
 
        if (!ttlv_valid(type)) {
                ND_PRINT("%s TLV type 0x%x len %u\n",
@@ -1122,7 +1115,7 @@ recpdoptlv_print(netdissect_options *ndo,
                 */
                ib = indent_pr(indent, 0);
                type = GET_BE_U_2(pdtlv->type);
-               dp = (const u_char *) TLV_DATA(pdtlv);
+               dp = TLV_DATA(pdtlv);
 
                if (ndo->ndo_vflag >= 3)
                        ND_PRINT("%s%s, length %u (data encapsulated %u Bytes)",
@@ -1130,8 +1123,8 @@ recpdoptlv_print(netdissect_options *ndo,
                                  tlvl,
                                  tlvl - TLV_HDRL);
 
-               if (pdata_print(ndo, dp, tlvl - TLV_HDRL, op_msk, indent + 1) == -1)
-                       goto invalid;
+               ND_ICHECK_U(pdata_print(ndo, dp, tlvl - TLV_HDRL, op_msk, indent + 1),
+                           ==, -1);
                pdtlv = GO_NXT_TLV(pdtlv, len);
        }
 
@@ -1167,7 +1160,7 @@ otlv_print(netdissect_options *ndo,
            const struct forces_tlv *otlv, uint16_t op_msk _U_, int indent)
 {
        int rc = 0;
-       const u_char *dp = (const u_char *) TLV_DATA(otlv);
+       const u_char *dp = TLV_DATA(otlv);
        uint16_t type;
        u_int tll;
        char *ib = indent_pr(indent, 0);
@@ -1310,12 +1303,12 @@ gentltlv_print(netdissect_options *ndo,
 
 static int
 print_metailv(netdissect_options *ndo,
-              const u_char * pptr, uint16_t op_msk _U_, int indent)
+              const struct forces_ilv * ilv, uint16_t op_msk _U_,
+              const int indent)
 {
        u_int rlen;
        char *ib = indent_pr(indent, 0);
        /* XXX: check header length */
-       const struct forces_ilv *ilv = (const struct forces_ilv *)pptr;
 
        /*
         * print_metatlv() has ensured that len (what remains in the
@@ -1360,7 +1353,7 @@ print_metatlv(netdissect_options *ndo,
                 * length is large enough but not too large (it doesn't
                 * go past the end of the containing TLV).
                 */
-               print_metailv(ndo, (const u_char *) ilv, 0, indent + 1);
+               print_metailv(ndo, ilv, 0, indent + 1);
                ilv = GO_NXT_ILV(ilv, rlen);
        }
 
@@ -1430,11 +1423,11 @@ redirect_print(netdissect_options *ndo,
                 * go past the end of the containing TLV).
                 */
                if (type == F_TLV_METD) {
-                       print_metatlv(ndo, (const u_char *) TLV_DATA(tlv),
+                       print_metatlv(ndo, TLV_DATA(tlv),
                                      tlvl, 0,
                                      indent);
                } else if (type == F_TLV_REDD) {
-                       print_reddata(ndo, (const u_char *) TLV_DATA(tlv),
+                       print_reddata(ndo, TLV_DATA(tlv),
                                      tlvl, 0,
                                      indent);
                } else {
@@ -1608,12 +1601,10 @@ forces_type_print(netdissect_options *ndo,
                               tlvl,
                               tlvl - TLV_HDRL);
 
-               rc = tops->print(ndo, (const u_char *) TLV_DATA(tltlv),
+               rc = tops->print(ndo, TLV_DATA(tltlv),
                                 tlvl,
                                 tops->op_msk, 9);
-               if (rc < 0) {
-                       goto invalid;
-               }
+               ND_ICHECK_U(rc, <, 0);
                tltlv = GO_NXT_TLV(tltlv, rlen);
                ttlv--;
                if (ttlv <= 0)
@@ -1694,9 +1685,7 @@ forces_print(netdissect_options *ndo,
                     ForCES_RS1(fhdr), ForCES_RS2(fhdr));
        }
        rc = forces_type_print(ndo, pptr, fhdr, mlen, tops);
-       if (rc < 0) {
-               goto invalid;
-       }
+       ND_ICHECK_U(rc, <, 0);
 
        if (ndo->ndo_vflag >= 4) {
                ND_PRINT("\n\t  Raw ForCES message\n\t [");