]> The Tcpdump Group git mirrors - tcpdump/blobdiff - forces.h
Fix the pointer tests in the non-ndoified TTEST2() macro as well.
[tcpdump] / forces.h
index 64fc98a7dcc3e7a6d998055b16b64c00a9f76b06..b9cf072fb6113827f5834d5eb53af71be009c82d 100644 (file)
--- a/forces.h
+++ b/forces.h
@@ -39,7 +39,7 @@
 */
 #define        ForCES_VERS     1
 #define        ForCES_HDRL     24
-#define        ForCES_ALNL     4
+#define        ForCES_ALNL     4U
 #define TLV_HDRL       4
 #define ILV_HDRL       8
 
@@ -104,8 +104,14 @@ int asttlv_print(register const u_char * pptr, register u_int len,
                 u_int16_t op_msk, int indent);
 int gentltlv_print(register const u_char * pptr, register u_int len,
                   u_int16_t op_msk, int indent);
-
-static inline tom_valid(u_int8_t tom)
+int print_metailv(register const u_char * pptr, register u_int len,
+             u_int16_t op_msk, int indent);
+int print_metatlv(register const u_char * pptr, register u_int len,
+             u_int16_t op_msk, int indent);
+int print_reddata(register const u_char * pptr, register u_int len,
+             u_int16_t op_msk, int indent);
+
+static inline int tom_valid(u_int8_t tom)
 {
        if (tom > 0) {
                if (tom >= 0x7 && tom <= 0xe)
@@ -121,7 +127,7 @@ static inline tom_valid(u_int8_t tom)
 
 static inline const char *ForCES_node(u_int32_t node)
 {
-       if (node >= 0 && node <= 0x3FFFFFFF)
+       if (node <= 0x3FFFFFFF)
                return "FE";
        if (node >= 0x40000000 && node <= 0x7FFFFFFF)
                return "CE";
@@ -190,44 +196,43 @@ static inline const char *ForCES_TPp(u_int32_t flg)
  * Structure of forces header, naked of TLVs.
  */
 struct forcesh {
-#if BYTE_ORDER == LITTLE_ENDIAN
-       u_int8_t fm_rsvd:4, fm_version:4;
-#elif BYTE_ORDER == BIG_ENDIAN
-       u_int8_t fm_version:4, fm_rsvd:4;
-#endif
-
-#define ForCES_V(forcesh)      (forcesh)->fm_version
+       u_int8_t fm_vrsvd;      /* version and reserved */
+#define ForCES_V(forcesh)      ((forcesh)->fm_vrsvd >> 4)
        u_int8_t fm_tom;        /* type of message */
        u_int16_t fm_len;       /* total length * 4 bytes */
-#define ForCES_BLN(forcesh)    ntohs((forcesh)->fm_len) << 2
+#define ForCES_BLN(forcesh)    ((u_int32_t)(EXTRACT_16BITS(&(forcesh)->fm_len) << 2))
        u_int32_t fm_sid;       /* Source ID */
-#define ForCES_SID(forcesh)    ntohl((forcesh)->fm_sid)
+#define ForCES_SID(forcesh)    EXTRACT_32BITS(&(forcesh)->fm_sid)
        u_int32_t fm_did;       /* Destination ID */
-#define ForCES_DID(forcesh)    ntohl((forcesh)->fm_did)
+#define ForCES_DID(forcesh)    EXTRACT_32BITS(&(forcesh)->fm_did)
        u_int8_t fm_cor[8];     /* correlator */
-#if BYTE_ORDER == LITTLE_ENDIAN
-       u_int16_t f_rs1:3, f_pri:3, f_ack:2, f_rs2:3, f_tp:2, f_at:1, f_em:2;
-#elif BYTE_ORDER == BIG_ENDIAN
-       u_int16_t f_ack:2, f_pri:3, f_rs1:3, f_em:2, f_at:1, f_tp:2, f_rs2:3;
-#endif
-       u_int16_t f_rs3;
-
+       u_int32_t fm_flags;     /* flags */
+#define ForCES_ACK(forcesh)    ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0xC0000000) >> 30)
+#define ForCES_PRI(forcesh)    ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x38000000) >> 27)
+#define ForCES_RS1(forcesh)    ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x07000000) >> 24)
+#define ForCES_EM(forcesh)     ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00C00000) >> 22)
+#define ForCES_AT(forcesh)     ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00200000) >> 21)
+#define ForCES_TP(forcesh)     ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x00180000) >> 19)
+#define ForCES_RS2(forcesh)    ((EXTRACT_32BITS(&(forcesh)->fm_flags)&0x0007FFFF) >> 0)
 };
 
-#define ForCES_HLN_VALID(fhl,tlen) ((tlen) >= (int)sizeof(struct forcesh) && \
-                                  (fhl) >= sizeof(struct forcesh) && \
+#define ForCES_HLN_VALID(fhl,tlen) ((tlen) >= ForCES_HDRL && \
+                                  (fhl) >= ForCES_HDRL && \
                                   (fhl) == (tlen))
 
 #define F_LFB_RSVD 0x0
 #define F_LFB_FEO 0x1
 #define F_LFB_FEPO 0x2
-struct tok ForCES_LFBs[] = {
+const struct tok ForCES_LFBs[] = {
        {F_LFB_RSVD, "Invalid TLV"},
        {F_LFB_FEO, "FEObj LFB"},
        {F_LFB_FEPO, "FEProtoObj LFB"},
        {0, NULL}
 };
 
+int forces_type_print(register const u_char * pptr, const struct forcesh *fhdr,
+                 register u_int mlen, const struct tom_h *tops);
+
 enum {
        F_OP_RSV,
        F_OP_SET,
@@ -291,29 +296,29 @@ struct pathdata_h {
 #define B_RESTV                0x4
 #define B_KEYIN                0x8
 
-static struct optlv_h OPTLV_msg[F_OP_MAX + 1] = {
-       [F_OP_RSV] = {ZERO_TTLV, 0, "Invalid OPTLV", invoptlv_print},
-       [F_OP_SET] = {TTLV_T2, B_FULLD | B_SPARD, " Set", recpdoptlv_print},
-       [F_OP_SETPROP] =
+static const struct optlv_h OPTLV_msg[F_OP_MAX + 1] = {
+       /* F_OP_RSV */ {ZERO_TTLV, 0, "Invalid OPTLV", invoptlv_print},
+       /* F_OP_SET */ {TTLV_T2, B_FULLD | B_SPARD, " Set", recpdoptlv_print},
+       /* F_OP_SETPROP */
            {TTLV_T2, B_FULLD | B_SPARD, " SetProp", recpdoptlv_print},
-       [F_OP_SETRESP] = {TTLV_T2, B_RESTV, " SetResp", recpdoptlv_print},
-       [F_OP_SETPRESP] = {TTLV_T2, B_RESTV, " SetPropResp", recpdoptlv_print},
-       [F_OP_DEL] = {ZERO_TTLV, 0, " Del", recpdoptlv_print},
-       [F_OP_DELRESP] = {TTLV_T2, B_RESTV, " DelResp", recpdoptlv_print},
-       [F_OP_GET] = {ZERO_TTLV, 0, " Get", recpdoptlv_print},
-       [F_OP_GETPROP] = {ZERO_TTLV, 0, " GetProp", recpdoptlv_print},
-       [F_OP_GETRESP] =
+       /* F_OP_SETRESP */ {TTLV_T2, B_RESTV, " SetResp", recpdoptlv_print},
+       /* F_OP_SETPRESP */ {TTLV_T2, B_RESTV, " SetPropResp", recpdoptlv_print},
+       /* F_OP_DEL */ {ZERO_TTLV, 0, " Del", recpdoptlv_print},
+       /* F_OP_DELRESP */ {TTLV_T2, B_RESTV, " DelResp", recpdoptlv_print},
+       /* F_OP_GET */ {ZERO_TTLV, 0, " Get", recpdoptlv_print},
+       /* F_OP_GETPROP */ {ZERO_TTLV, 0, " GetProp", recpdoptlv_print},
+       /* F_OP_GETRESP */
            {TTLV_T2, B_FULLD | B_RESTV, " GetResp", recpdoptlv_print},
-       [F_OP_GETPRESP] =
+       /* F_OP_GETPRESP */
            {TTLV_T2, B_FULLD | B_RESTV, " GetPropResp", recpdoptlv_print},
-       [F_OP_REPORT] =
+       /* F_OP_REPORT */
            {TTLV_T2, B_FULLD | B_SPARD, " Report", recpdoptlv_print},
-       [F_OP_COMMIT] = {ZERO_TTLV, 0, " Commit", NULL},
-       [F_OP_RCOMMIT] = {TTLV_T1, B_RESTV, " RCommit", genoptlv_print},
-       [F_OP_RTRCOMP] = {ZERO_TTLV, 0, " RTRCOMP", NULL},
+       /* F_OP_COMMIT */ {ZERO_TTLV, 0, " Commit", NULL},
+       /* F_OP_RCOMMIT */ {TTLV_T1, B_RESTV, " RCommit", genoptlv_print},
+       /* F_OP_RTRCOMP */ {ZERO_TTLV, 0, " RTRCOMP", NULL},
 };
 
-static inline struct optlv_h *get_forces_optlv_h(u_int16_t opt)
+static inline const struct optlv_h *get_forces_optlv_h(u_int16_t opt)
 {
        if (opt > F_OP_MAX || opt <= F_OP_RSV)
                return &OPTLV_msg[F_OP_RSV];
@@ -348,7 +353,7 @@ static inline char *indent_pr(int indent, int nlpref)
        return r;
 }
 
-static inline op_valid(u_int16_t op, u_int16_t mask)
+static inline int op_valid(u_int16_t op, u_int16_t mask)
 {
        int opb = 1 << (op - 1);
 
@@ -356,7 +361,7 @@ static inline op_valid(u_int16_t op, u_int16_t mask)
                return 0;
        if (opb & mask)
                return 1;
-       // I guess we should allow vendor operations?
+       /* I guess we should allow vendor operations? */
        if (op >= 0x8000)
                return 1;
        return 0;
@@ -376,7 +381,7 @@ static inline op_valid(u_int16_t op, u_int16_t mask)
 #define F_TLV_REDD     0x0116
 #define F_TLV_VNST     0x8000
 
-static struct tok ForCES_TLV[] = {
+static const struct tok ForCES_TLV[] = {
        {F_TLV_RSVD, "Invalid TLV"},
        {F_TLV_REDR, "REDIRECT TLV"},
        {F_TLV_ASRS, "ASResult TLV"},
@@ -403,7 +408,7 @@ static inline int ttlv_valid(u_int16_t ttlv)
                if (ttlv >= 0x110 && ttlv <= 0x116)
                        return 1;
                if (ttlv >= 0x8000)
-                       return 0;       //XXX:
+                       return 0;       /* XXX: */
        }
 
        return 0;
@@ -419,28 +424,30 @@ struct forces_tlv {
        u_int16_t length;
 };
 
+int otlv_print(const struct forces_tlv *otlv, u_int16_t op_msk, int indent);
+
 #define F_ALN_LEN(len) ( ((len)+ForCES_ALNL-1) & ~(ForCES_ALNL-1) )
 #define        GET_TOP_TLV(fhdr) ((struct forces_tlv *)((fhdr) + sizeof (struct forcesh)))
-#define TLV_SET_LEN(len)  (F_ALN_LEN(sizeof(struct forces_tlv)) + (len))
+#define TLV_SET_LEN(len)  (F_ALN_LEN(TLV_HDRL) + (len))
 #define TLV_ALN_LEN(len)  F_ALN_LEN(TLV_SET_LEN(len))
-#define TLV_RDAT_LEN(tlv) ((int)(ntohs((tlv)->length)) - TLV_SET_LEN(0))
+#define TLV_RDAT_LEN(tlv) ((int)(EXTRACT_16BITS(&(tlv)->length) - TLV_SET_LEN(0))
 #define TLV_DATA(tlvp)   ((void*)(((char*)(tlvp)) + TLV_SET_LEN(0)))
-#define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(ntohs((tlv)->length)), \
+#define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length)), \
                              (struct forces_tlv*)(((char*)(tlv)) \
-                                     + F_ALN_LEN(ntohs((tlv)->length))))
-#define ILV_SET_LEN(len)  (F_ALN_LEN(sizeof(struct forces_ilv)) + (len))
+                                     + F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length))))
+#define ILV_SET_LEN(len)  (F_ALN_LEN(ILV_HDRL) + (len))
 #define ILV_ALN_LEN(len)  F_ALN_LEN(ILV_SET_LEN(len))
-#define ILV_RDAT_LEN(ilv) ((int)(ntohl((ilv)->length)) - ILV_SET_LEN(0))
+#define ILV_RDAT_LEN(ilv) ((int)(EXTRACT_32BITS(&(ilv)->length)) - ILV_SET_LEN(0))
 #define ILV_DATA(ilvp)   ((void*)(((char*)(ilvp)) + ILV_SET_LEN(0)))
-#define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(ntohl((ilv)->length)), \
+#define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length)), \
                              (struct forces_ilv *)(((char*)(ilv)) \
-                                     + F_ALN_LEN(ntohl((ilv)->length))))
+                                     + F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length))))
 #define INVALID_RLEN -1
 #define INVALID_STLN -2
 #define INVALID_LTLN -3
 #define INVALID_ALEN -4
 
-static struct tok ForCES_TLV_err[] = {
+static const struct tok ForCES_TLV_err[] = {
        {INVALID_RLEN, "Invalid total length"},
        {INVALID_STLN, "xLV too short"},
        {INVALID_LTLN, "xLV too long"},
@@ -448,29 +455,29 @@ static struct tok ForCES_TLV_err[] = {
        {0, NULL}
 };
 
-static inline int tlv_valid(struct forces_tlv *tlv, int rlen)
+static inline int tlv_valid(const struct forces_tlv *tlv, u_int rlen)
 {
-       if (rlen < sizeof(struct forces_tlv))
+       if (rlen < TLV_HDRL)
                return INVALID_RLEN;
-       if (ntohs(tlv->length) < sizeof(struct forces_tlv))
+       if (EXTRACT_16BITS(&tlv->length) < TLV_HDRL)
                return INVALID_STLN;
-       if (ntohs(tlv->length) > rlen)
+       if (EXTRACT_16BITS(&tlv->length) > rlen)
                return INVALID_LTLN;
-       if (rlen < F_ALN_LEN(ntohs(tlv->length)))
+       if (rlen < F_ALN_LEN(EXTRACT_16BITS(&tlv->length)))
                return INVALID_ALEN;
 
        return 0;
 }
 
-static inline int ilv_valid(struct forces_ilv *ilv, int rlen)
+static inline int ilv_valid(const struct forces_ilv *ilv, u_int rlen)
 {
-       if (rlen < sizeof(struct forces_ilv))
+       if (rlen < ILV_HDRL)
                return INVALID_RLEN;
-       if (ntohl(ilv->length) < sizeof(struct forces_ilv))
+       if (EXTRACT_32BITS(&ilv->length) < ILV_HDRL)
                return INVALID_STLN;
-       if (ntohl(ilv->length) > rlen)
+       if (EXTRACT_32BITS(&ilv->length) > rlen)
                return INVALID_LTLN;
-       if (rlen < F_ALN_LEN(ntohl(ilv->length)))
+       if (rlen < F_ALN_LEN(EXTRACT_32BITS(&ilv->length)))
                return INVALID_ALEN;
 
        return 0;
@@ -488,32 +495,32 @@ struct forces_lfbsh {
 #define CFG_QYR (B_OP_GETRESP|B_OP_GETPRESP)
 #define CFG_EVN (B_OP_REPORT)
 
-static struct tom_h ForCES_msg[TOM_MAX_IND + 1] = {
-       [TOM_RSV_I] = {TOM_RSVD, ZERO_TTLV, 0, "Invalid message", NULL},
-       [TOM_ASS_I] = {TOM_ASSNSETUP, ZERO_MORE_TTLV | TWO_TLV, ASSNS_OPS,
+static const struct tom_h ForCES_msg[TOM_MAX_IND + 1] = {
+       /* TOM_RSV_I */ {TOM_RSVD, ZERO_TTLV, 0, "Invalid message", NULL},
+       /* TOM_ASS_I */ {TOM_ASSNSETUP, ZERO_MORE_TTLV | TWO_TLV, ASSNS_OPS,
                       "Association Setup", lfbselect_print},
-       [TOM_AST_I] =
+       /* TOM_AST_I */
            {TOM_ASSNTEARD, TTLV_T1, 0, "Association TearDown", asttlv_print},
-       [TOM_CFG_I] = {TOM_CONFIG, TTLV_T2, CFG_OPS, "Config", lfbselect_print},
-       [TOM_QRY_I] = {TOM_QUERY, TTLV_T2, CFG_QY, "Query", lfbselect_print},
-       [TOM_EVN_I] = {TOM_EVENTNOT, TTLV_T1, CFG_EVN, "Event Notification",
+       /* TOM_CFG_I */ {TOM_CONFIG, TTLV_T2, CFG_OPS, "Config", lfbselect_print},
+       /* TOM_QRY_I */ {TOM_QUERY, TTLV_T2, CFG_QY, "Query", lfbselect_print},
+       /* TOM_EVN_I */ {TOM_EVENTNOT, TTLV_T1, CFG_EVN, "Event Notification",
                       lfbselect_print},
-       [TOM_RED_I] =
+       /* TOM_RED_I */
            {TOM_PKTREDIR, TTLV_T2, 0, "Packet Redirect", redirect_print},
-       [TOM_HBT_I] = {TOM_HEARTBT, ZERO_TTLV, 0, "HeartBeat", NULL},
-       [TOM_ASR_I] =
+       /* TOM_HBT_I */ {TOM_HEARTBT, ZERO_TTLV, 0, "HeartBeat", NULL},
+       /* TOM_ASR_I */
            {TOM_ASSNSETREP, TTLV_T1, 0, "Association Response", asrtlv_print},
-       [TOM_CNR_I] = {TOM_CONFIGREP, TTLV_T2, CFG_ROPS, "Config Response",
+       /* TOM_CNR_I */ {TOM_CONFIGREP, TTLV_T2, CFG_ROPS, "Config Response",
                       lfbselect_print},
-       [TOM_QRR_I] =
+       /* TOM_QRR_I */
            {TOM_QUERYREP, TTLV_T2, CFG_QYR, "Query Response", lfbselect_print},
 };
 
-static inline struct tom_h *get_forces_tom(u_int8_t tom)
+static inline const struct tom_h *get_forces_tom(u_int8_t tom)
 {
        int i;
        for (i = TOM_RSV_I; i <= TOM_MAX_IND; i++) {
-               struct tom_h *th = &ForCES_msg[i];
+               const struct tom_h *th = &ForCES_msg[i];
                if (th->v == tom)
                        return th;
        }
@@ -542,14 +549,12 @@ enum {
 
 static inline int pd_valid(u_int16_t pd)
 {
-       if (pd > 0) {
-               if (pd >= F_TLV_PDAT && pd <= F_TLV_REST)
-                       return 1;
-       } else
-               return 0;
+       if (pd >= F_TLV_PDAT && pd <= F_TLV_REST)
+               return 1;
+       return 0;
 }
 
-static inline int chk_op_type(u_int16_t type, u_int16_t msk, u_int16_t omsk)
+static inline void chk_op_type(u_int16_t type, u_int16_t msk, u_int16_t omsk)
 {
        if (type != F_TLV_PDAT) {
                if (msk & B_KEYIN) {
@@ -570,6 +575,8 @@ static inline int chk_op_type(u_int16_t type, u_int16_t msk, u_int16_t omsk)
 
 int fdatatlv_print(register const u_char * pptr, register u_int len,
                   u_int16_t op_msk, int indent);
+int sdatailv_print(register const u_char * pptr, register u_int len,
+              u_int16_t op_msk, int indent);
 int sdatatlv_print(register const u_char * pptr, register u_int len,
                   u_int16_t op_msk, int indent);
 int pdatatlv_print(register const u_char * pptr, register u_int len,
@@ -577,6 +584,11 @@ int pdatatlv_print(register const u_char * pptr, register u_int len,
 int pkeyitlv_print(register const u_char * pptr, register u_int len,
                   u_int16_t op_msk, int indent);
 
+int pdatacnt_print(register const u_char * pptr, register u_int len,
+              u_int32_t IDcnt, u_int16_t op_msk, int indent);
+int pdata_print(register const u_char * pptr, register u_int len,
+           u_int16_t op_msk, int indent);
+
 int prestlv_print(register const u_char * pptr, register u_int len,
                  u_int16_t op_msk, int indent);
 #define F_SELKEY 1
@@ -587,21 +599,21 @@ struct res_val {
        u_int16_t resv2;
 };
 
-static struct pdata_ops ForCES_pdata[PD_MAX_IND + 1] = {
-       [PD_RSV_I] = {0, 0, 0, "Invalid message", NULL},
-       [PD_SEL_I] = {F_TLV_KEYI, 0, 0, "KEYINFO TLV", pkeyitlv_print},
-       [PD_FDT_I] = {F_TLV_FULD, 0, B_FULLD, "FULLDATA TLV", fdatatlv_print},
-       [PD_SDT_I] = {F_TLV_SPAD, 0, B_SPARD, "SPARSEDATA TLV", sdatatlv_print},
-       [PD_RES_I] = {F_TLV_REST, 0, B_RESTV, "RESULT TLV", prestlv_print},
-       [PD_PDT_I] =
+static const struct pdata_ops ForCES_pdata[PD_MAX_IND + 1] = {
+       /* PD_RSV_I */ {0, 0, 0, "Invalid message", NULL},
+       /* PD_SEL_I */ {F_TLV_KEYI, 0, 0, "KEYINFO TLV", pkeyitlv_print},
+       /* PD_FDT_I */ {F_TLV_FULD, 0, B_FULLD, "FULLDATA TLV", fdatatlv_print},
+       /* PD_SDT_I */ {F_TLV_SPAD, 0, B_SPARD, "SPARSEDATA TLV", sdatatlv_print},
+       /* PD_RES_I */ {F_TLV_REST, 0, B_RESTV, "RESULT TLV", prestlv_print},
+       /* PD_PDT_I */
            {F_TLV_PDAT, 0, 0, "Inner PATH-DATA TLV", recpdoptlv_print},
 };
 
-static inline struct pdata_ops *get_forces_pd(u_int16_t pd)
+static inline const struct pdata_ops *get_forces_pd(u_int16_t pd)
 {
        int i;
        for (i = PD_RSV_I + 1; i <= PD_MAX_IND; i++) {
-               struct pdata_ops *pdo = &ForCES_pdata[i];
+               const struct pdata_ops *pdo = &ForCES_pdata[i];
                if (pdo->v == pd)
                        return pdo;
        }
@@ -633,11 +645,11 @@ enum {
        E_NOT_SUPPORTED,
        E_MEMORY_ERROR,
        E_INTERNAL_ERROR,
-       // 0x18-0xFE are reserved ..
+       /* 0x18-0xFE are reserved .. */
        E_UNSPECIFIED_ERROR = 0XFF
 };
 
-struct tok ForCES_errs[] = {
+const struct tok ForCES_errs[] = {
        {E_SUCCESS, "SUCCESS"},
        {E_INVALID_HEADER, "INVALID HEADER"},
        {E_LENGTH_MISMATCH, "LENGTH MISMATCH"},