X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/d32eeddb466520b2c9ac9ff4bb6c60fcc6188e47..a8abce5c5e2dce2ba6dbccd5d3829da104b80f9c:/print-forces.c diff --git a/print-forces.c b/print-forces.c index 37336078..072c9389 100644 --- a/print-forces.c +++ b/print-forces.c @@ -19,15 +19,14 @@ /* specification: RFC 5810 */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif -#include +#include "netdissect-stdinc.h" #include "netdissect.h" #include "extract.h" -static const char tstr[] = "[|forces]"; #define ForCES_VERS 1 #define ForCES_HDRL 24 @@ -86,7 +85,8 @@ enum { }; #define TOM_MAX_IND (_TOM_RSV_MAX - 1) -static inline int tom_valid(uint8_t tom) +static int +tom_valid(uint8_t tom) { if (tom > 0) { if (tom >= 0x7 && tom <= 0xe) @@ -100,7 +100,8 @@ static inline int tom_valid(uint8_t tom) return 0; } -static inline const char *ForCES_node(uint32_t node) +static const char * +ForCES_node(uint32_t node) { if (node <= 0x3FFFFFFF) return "FE"; @@ -276,7 +277,8 @@ static const struct optlv_h OPTLV_msg[F_OP_MAX + 1] = { /* F_OP_RTRCOMP */ {ZERO_TTLV, 0, " RTRCOMP", NULL}, }; -static inline const struct optlv_h *get_forces_optlv_h(uint16_t opt) +static const struct optlv_h * +get_forces_optlv_h(uint16_t opt) { if (opt > F_OP_MAX || opt == F_OP_RSV) return &OPTLV_msg[F_OP_RSV]; @@ -290,7 +292,8 @@ static inline const struct optlv_h *get_forces_optlv_h(uint16_t opt) #define IND_SUF 0x0 static char ind_buf[IND_SIZE]; -static inline char *indent_pr(int indent, int nlpref) +static char * +indent_pr(int indent, int nlpref) { int i = 0; char *r = ind_buf; @@ -311,7 +314,8 @@ static inline char *indent_pr(int indent, int nlpref) return r; } -static inline int op_valid(uint16_t op, uint16_t mask) +static int +op_valid(uint16_t op, uint16_t mask) { if (op == 0) return 0; @@ -357,7 +361,8 @@ static const struct tok ForCES_TLV[] = { }; #define TLV_HLN 4 -static inline int ttlv_valid(uint16_t ttlv) +static int +ttlv_valid(uint16_t ttlv) { if (ttlv > 0) { if (ttlv == 1 || ttlv == 0x1000) @@ -387,14 +392,14 @@ struct forces_tlv { #define GET_TOP_TLV(fhdr) ((const struct forces_tlv *)((fhdr) + sizeof (struct forcesh))) #define TLV_SET_LEN(len) (F_ALN_LEN(TLV_HDRL) + (len)) #define TLV_DATA(tlvp) ((const void*)(((const char*)(tlvp)) + TLV_SET_LEN(0))) -#define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_BE_U_2(&(tlv)->length)), \ +#define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_BE_U_2((tlv)->length)), \ (const struct forces_tlv*)(((const char*)(tlv)) \ - + F_ALN_LEN(EXTRACT_BE_U_2(&(tlv)->length)))) + + F_ALN_LEN(EXTRACT_BE_U_2((tlv)->length)))) #define ILV_SET_LEN(len) (F_ALN_LEN(ILV_HDRL) + (len)) #define ILV_DATA(ilvp) ((const void*)(((const char*)(ilvp)) + ILV_SET_LEN(0))) -#define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_BE_U_4(&(ilv)->length)), \ +#define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_BE_U_4((ilv)->length)), \ (const struct forces_ilv *)(((const char*)(ilv)) \ - + F_ALN_LEN(EXTRACT_BE_U_4(&(ilv)->length)))) + + F_ALN_LEN(EXTRACT_BE_U_4((ilv)->length)))) #define INVALID_RLEN 1 #define INVALID_STLN 2 #define INVALID_LTLN 3 @@ -408,29 +413,31 @@ static const struct tok ForCES_TLV_err[] = { {0, NULL} }; -static inline u_int tlv_valid(const struct forces_tlv *tlv, u_int rlen) +static u_int +tlv_valid(u_int tlvl, u_int rlen) { if (rlen < TLV_HDRL) return INVALID_RLEN; - if (EXTRACT_BE_U_2(&tlv->length) < TLV_HDRL) + if (tlvl < TLV_HDRL) return INVALID_STLN; - if (EXTRACT_BE_U_2(&tlv->length) > rlen) + if (tlvl > rlen) return INVALID_LTLN; - if (rlen < F_ALN_LEN(EXTRACT_BE_U_2(&tlv->length))) + if (rlen < F_ALN_LEN(tlvl)) return INVALID_ALEN; return 0; } -static inline int ilv_valid(const struct forces_ilv *ilv, u_int rlen) +static int +ilv_valid(const struct forces_ilv *ilv, u_int rlen) { if (rlen < ILV_HDRL) return INVALID_RLEN; - if (EXTRACT_BE_U_4(&ilv->length) < ILV_HDRL) + if (EXTRACT_BE_U_4(ilv->length) < ILV_HDRL) return INVALID_STLN; - if (EXTRACT_BE_U_4(&ilv->length) > rlen) + if (EXTRACT_BE_U_4(ilv->length) > rlen) return INVALID_LTLN; - if (rlen < F_ALN_LEN(EXTRACT_BE_U_4(&ilv->length))) + if (rlen < F_ALN_LEN(EXTRACT_BE_U_4(ilv->length))) return INVALID_ALEN; return 0; @@ -478,7 +485,8 @@ static const struct tom_h ForCES_msg[TOM_MAX_IND + 1] = { {TOM_QUERYREP, TTLV_T2, CFG_QYR, "Query Response", lfbselect_print}, }; -static inline const struct tom_h *get_forces_tom(uint8_t tom) +static const struct tom_h * +get_forces_tom(uint8_t tom) { int i; for (i = TOM_RSV_I; i <= TOM_MAX_IND; i++) { @@ -509,14 +517,15 @@ enum { }; #define PD_MAX_IND (_TOM_RSV_MAX - 1) -static inline int pd_valid(uint16_t pd) +static int +pd_valid(uint16_t pd) { if (pd >= F_TLV_PDAT && pd <= F_TLV_REST) return 1; return 0; } -static inline void +static void chk_op_type(netdissect_options *ndo, uint16_t type, uint16_t msk, uint16_t omsk) { @@ -564,7 +573,8 @@ static const struct pdata_ops ForCES_pdata[PD_MAX_IND + 1] = { {F_TLV_PDAT, 0, 0, "Inner PATH-DATA TLV", recpdoptlv_print}, }; -static inline const struct pdata_ops *get_forces_pd(uint16_t pd) +static const struct pdata_ops * +get_forces_pd(uint16_t pd) { int i; for (i = PD_RSV_I + 1; i <= PD_MAX_IND; i++) { @@ -652,7 +662,7 @@ prestlv_print(netdissect_options *ndo, */ dlen = len - TLV_HDRL; if (dlen != RESLEN) { - ND_PRINT("illegal RESULT-TLV: %d bytes!\n", dlen); + ND_PRINT("illegal RESULT-TLV: %u bytes!\n", dlen); return -1; } @@ -671,7 +681,7 @@ prestlv_print(netdissect_options *ndo, return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -691,7 +701,7 @@ fdatatlv_print(netdissect_options *ndo, */ rlen = len - TLV_HDRL; ND_TCHECK_SIZE(tlv); - type = EXTRACT_BE_U_2(&tlv->type); + type = EXTRACT_BE_U_2(tlv->type); if (type != F_TLV_FULD) { ND_PRINT("Error: expecting FULLDATA!\n"); return -1; @@ -706,7 +716,7 @@ fdatatlv_print(netdissect_options *ndo, return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -727,7 +737,7 @@ sdatailv_print(netdissect_options *ndo, indent += 1; while (rlen != 0) { #if 0 - ND_PRINT("Jamal - outstanding length <%d>\n", rlen); + ND_PRINT("Jamal - outstanding length <%u>\n", rlen); #endif char *ib = indent_pr(indent, 1); const u_char *tdp = (const u_char *) ILV_DATA(ilv); @@ -740,9 +750,9 @@ sdatailv_print(netdissect_options *ndo, return -1; } if (ndo->ndo_vflag >= 3) { - int ilvl = EXTRACT_BE_U_4(&ilv->length); - ND_PRINT("\n%s ILV: type %x length %d\n", ib + 1, - EXTRACT_BE_U_4(&ilv->type), ilvl); + u_int ilvl = EXTRACT_BE_U_4(ilv->length); + ND_PRINT("\n%s ILV: type %x length %u\n", ib + 1, + EXTRACT_BE_U_4(ilv->type), ilvl); hex_print_with_offset(ndo, "\t\t[", tdp, ilvl-ILV_HDRL, 0); } @@ -752,7 +762,7 @@ sdatailv_print(netdissect_options *ndo, return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -772,7 +782,7 @@ sdatatlv_print(netdissect_options *ndo, */ rlen = len - TLV_HDRL; ND_TCHECK_SIZE(tlv); - type = EXTRACT_BE_U_2(&tlv->type); + type = EXTRACT_BE_U_2(tlv->type); if (type != F_TLV_SPAD) { ND_PRINT("Error: expecting SPARSEDATA!\n"); return -1; @@ -781,7 +791,7 @@ sdatatlv_print(netdissect_options *ndo, return sdatailv_print(ndo, tdp, rlen, op_msk, indent); trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -803,13 +813,14 @@ pkeyitlv_print(netdissect_options *ndo, id = EXTRACT_BE_U_4(tdp); ND_PRINT("%sKeyinfo: Key 0x%x\n", ib, id); ND_TCHECK_SIZE(kdtlv); - type = EXTRACT_BE_U_2(&kdtlv->type); - invtlv = tlv_valid(kdtlv, len); + type = EXTRACT_BE_U_2(kdtlv->type); + tll = EXTRACT_BE_U_2(kdtlv->length); + invtlv = tlv_valid(tll, len); if (invtlv) { - ND_PRINT("%s TLV type 0x%x len %d\n", + ND_PRINT("%s TLV type 0x%x len %u\n", tok2str(ForCES_TLV_err, NULL, invtlv), type, - EXTRACT_BE_U_2(&kdtlv->length)); + tll); return -1; } /* @@ -817,12 +828,12 @@ pkeyitlv_print(netdissect_options *ndo, * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ - tll = EXTRACT_BE_U_2(&kdtlv->length); + tll = EXTRACT_BE_U_2(kdtlv->length); dp = (const u_char *) TLV_DATA(kdtlv); return fdatatlv_print(ndo, dp, tll, op_msk, indent); trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -846,7 +857,7 @@ pdatacnt_print(netdissect_options *ndo, goto trunc; id = EXTRACT_BE_U_4(pptr); if (ndo->ndo_vflag >= 3) - ND_PRINT("%sID#%02u: %d\n", ib, i + 1, id); + ND_PRINT("%sID#%02u: %u\n", ib, i + 1, id); len -= 4; pptr += 4; } @@ -856,7 +867,7 @@ pdatacnt_print(netdissect_options *ndo, uint32_t starti, endi; if (len < PTH_DESC_SIZE) { - ND_PRINT("pathlength %d with key/range too short %d\n", + ND_PRINT("pathlength %u with key/range too short %u\n", len, PTH_DESC_SIZE); return -1; } @@ -873,7 +884,7 @@ pdatacnt_print(netdissect_options *ndo, len -= 4; if (ndo->ndo_vflag >= 3) - ND_PRINT("%sTable range: [%d,%d]\n", ib, starti, endi); + ND_PRINT("%sTable range: [%u,%u]\n", ib, starti, endi); } if (op_msk & B_KEYIN) { @@ -881,7 +892,7 @@ pdatacnt_print(netdissect_options *ndo, uint16_t tll; if (len < PTH_DESC_SIZE) { - ND_PRINT("pathlength %d with key/range too short %d\n", + ND_PRINT("pathlength %u with key/range too short %u\n", len, PTH_DESC_SIZE); return -1; } @@ -894,7 +905,7 @@ pdatacnt_print(netdissect_options *ndo, pptr += sizeof(struct forces_tlv); len -= sizeof(struct forces_tlv); /* skip key content */ - tll = EXTRACT_BE_U_2(&keytlv->length); + tll = EXTRACT_BE_U_2(keytlv->length); if (tll < TLV_HDRL) { ND_PRINT("key content length %u < %u\n", tll, TLV_HDRL); @@ -914,18 +925,19 @@ pdatacnt_print(netdissect_options *ndo, if (len) { const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr; uint16_t type; - uint16_t tll; - int pad = 0; + uint16_t tlvl, tll; + u_int pad = 0; u_int aln; u_int invtlv; ND_TCHECK_SIZE(pdtlv); - type = EXTRACT_BE_U_2(&pdtlv->type); - invtlv = tlv_valid(pdtlv, len); + type = EXTRACT_BE_U_2(pdtlv->type); + tlvl = EXTRACT_BE_U_2(pdtlv->length); + invtlv = tlv_valid(tlvl, len); if (invtlv) { - ND_PRINT("%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n", + ND_PRINT("%s Outstanding bytes %u for TLV type 0x%x TLV len %u\n", tok2str(ForCES_TLV_err, NULL, invtlv), len, type, - EXTRACT_BE_U_2(&pdtlv->length)); + tlvl); goto pd_err; } /* @@ -933,14 +945,14 @@ pdatacnt_print(netdissect_options *ndo, * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ - tll = EXTRACT_BE_U_2(&pdtlv->length) - TLV_HDRL; - aln = F_ALN_LEN(EXTRACT_BE_U_2(&pdtlv->length)); - if (aln > EXTRACT_BE_U_2(&pdtlv->length)) { + tll = tlvl - TLV_HDRL; + aln = F_ALN_LEN(tlvl); + if (aln > tlvl) { if (aln > len) { - ND_PRINT("Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n", - type, EXTRACT_BE_U_2(&pdtlv->length), aln - len); + ND_PRINT("Invalid padded pathdata TLV type 0x%x len %u missing %u pad bytes\n", + type, tlvl, aln - len); } else { - pad = aln - EXTRACT_BE_U_2(&pdtlv->length); + pad = aln - tlvl; } } if (pd_valid(type)) { @@ -948,11 +960,11 @@ pdatacnt_print(netdissect_options *ndo, if (ndo->ndo_vflag >= 3 && ops->v != F_TLV_PDAT) { if (pad) - ND_PRINT("%s %s (Length %d DataLen %d pad %d Bytes)\n", - ib, ops->s, EXTRACT_BE_U_2(&pdtlv->length), tll, pad); + ND_PRINT("%s %s (Length %u DataLen %u pad %u Bytes)\n", + ib, ops->s, tlvl, tll, pad); else - ND_PRINT("%s %s (Length %d DataLen %d Bytes)\n", - ib, ops->s, EXTRACT_BE_U_2(&pdtlv->length), tll); + ND_PRINT("%s %s (Length %u DataLen %u Bytes)\n", + ib, ops->s, tlvl, tll); } chk_op_type(ndo, type, op_msk, ops->op_msk); @@ -963,10 +975,10 @@ pdatacnt_print(netdissect_options *ndo, return -1; len -= (TLV_HDRL + pad + tll); } else { - ND_PRINT("Invalid path data content type 0x%x len %d\n", - type, EXTRACT_BE_U_2(&pdtlv->length)); + ND_PRINT("Invalid path data content type 0x%x len %u\n", + type, tlvl); pd_err: - if (EXTRACT_BE_U_2(&pdtlv->length)) { + if (tlvl) { hex_print_with_offset(ndo, "Bad Data val\n\t [", pptr, len, 0); ND_PRINT("]\n"); @@ -978,7 +990,7 @@ pd_err: return len; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -997,26 +1009,27 @@ pdata_print(netdissect_options *ndo, if (len < sizeof(struct pathdata_h)) goto trunc; if (ndo->ndo_vflag >= 3) { - ND_PRINT("\n%sPathdata: Flags 0x%x ID count %d\n", - ib, EXTRACT_BE_U_2(&pdh->pflags), EXTRACT_BE_U_2(&pdh->pIDcnt)); + ND_PRINT("\n%sPathdata: Flags 0x%x ID count %u\n", + ib, EXTRACT_BE_U_2(pdh->pflags), + EXTRACT_BE_U_2(pdh->pIDcnt)); } - if (EXTRACT_BE_U_2(&pdh->pflags) & F_SELKEY) { + if (EXTRACT_BE_U_2(pdh->pflags) & F_SELKEY) { op_msk |= B_KEYIN; } /* Table GET Range operation */ - if (EXTRACT_BE_U_2(&pdh->pflags) & F_SELTABRANGE) { + if (EXTRACT_BE_U_2(pdh->pflags) & F_SELTABRANGE) { op_msk |= B_TRNG; } /* Table SET append operation */ - if (EXTRACT_BE_U_2(&pdh->pflags) & F_TABAPPEND) { + if (EXTRACT_BE_U_2(pdh->pflags) & F_TABAPPEND) { op_msk |= B_APPND; } pptr += sizeof(struct pathdata_h); len -= sizeof(struct pathdata_h); - idcnt = EXTRACT_BE_U_2(&pdh->pIDcnt); + idcnt = EXTRACT_BE_U_2(pdh->pIDcnt); minsize = idcnt * 4; if (len < minsize) { ND_PRINT("\t\t\ttruncated IDs expected %uB got %uB\n", minsize, @@ -1042,7 +1055,7 @@ pdata_print(netdissect_options *ndo, return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1053,16 +1066,16 @@ genoptlv_print(netdissect_options *ndo, { const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr; uint16_t type; - int tll; + u_int tlvl; u_int invtlv; char *ib = indent_pr(indent, 0); ND_TCHECK_SIZE(pdtlv); - type = EXTRACT_BE_U_2(&pdtlv->type); - tll = EXTRACT_BE_U_2(&pdtlv->length) - TLV_HDRL; - invtlv = tlv_valid(pdtlv, len); - ND_PRINT("genoptlvprint - %s TLV type 0x%x len %d\n", - tok2str(ForCES_TLV, NULL, type), type, EXTRACT_BE_U_2(&pdtlv->length)); + type = EXTRACT_BE_U_2(pdtlv->type); + tlvl = EXTRACT_BE_U_2(pdtlv->length); + invtlv = tlv_valid(tlvl, len); + ND_PRINT("genoptlvprint - %s TLV type 0x%x len %u\n", + tok2str(ForCES_TLV, NULL, type), type, tlvl); if (!invtlv) { /* * At this point, tlv_valid() has ensured that the TLV @@ -1070,25 +1083,26 @@ genoptlv_print(netdissect_options *ndo, * go past the end of the containing TLV). */ const u_char *dp = (const u_char *) TLV_DATA(pdtlv); + if (!ttlv_valid(type)) { - ND_PRINT("%s TLV type 0x%x len %d\n", + ND_PRINT("%s TLV type 0x%x len %u\n", tok2str(ForCES_TLV_err, NULL, invtlv), type, - EXTRACT_BE_U_2(&pdtlv->length)); + tlvl); return -1; } if (ndo->ndo_vflag >= 3) - ND_PRINT("%s%s, length %d (data length %d Bytes)", + ND_PRINT("%s%s, length %u (data length %u Bytes)", ib, tok2str(ForCES_TLV, NULL, type), - EXTRACT_BE_U_2(&pdtlv->length), tll); + tlvl, tlvl - TLV_HDRL); - return pdata_print(ndo, dp, tll, op_msk, indent + 1); + return pdata_print(ndo, dp, tlvl - TLV_HDRL, op_msk, indent + 1); } else { ND_PRINT("\t\t\tInvalid ForCES TLV type=%x", type); return -1; } trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1098,15 +1112,16 @@ recpdoptlv_print(netdissect_options *ndo, uint16_t op_msk, int indent) { const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr; - int tll; - u_int invtlv; - uint16_t type; - const u_char *dp; - char *ib; while (len != 0) { + uint16_t type, tlvl; + u_int invtlv; + char *ib; + const u_char *dp; + ND_TCHECK_SIZE(pdtlv); - invtlv = tlv_valid(pdtlv, len); + tlvl = EXTRACT_BE_U_2(pdtlv->length); + invtlv = tlv_valid(tlvl, len); if (invtlv) { break; } @@ -1117,31 +1132,31 @@ recpdoptlv_print(netdissect_options *ndo, * go past the end of the containing TLV). */ ib = indent_pr(indent, 0); - type = EXTRACT_BE_U_2(&pdtlv->type); + type = EXTRACT_BE_U_2(pdtlv->type); dp = (const u_char *) TLV_DATA(pdtlv); - tll = EXTRACT_BE_U_2(&pdtlv->length) - TLV_HDRL; if (ndo->ndo_vflag >= 3) - ND_PRINT("%s%s, length %d (data encapsulated %d Bytes)", + ND_PRINT("%s%s, length %u (data encapsulated %u Bytes)", ib, tok2str(ForCES_TLV, NULL, type), - EXTRACT_BE_U_2(&pdtlv->length), - EXTRACT_BE_U_2(&pdtlv->length) - TLV_HDRL); + tlvl, + tlvl - TLV_HDRL); - if (pdata_print(ndo, dp, tll, op_msk, indent + 1) == -1) + if (pdata_print(ndo, dp, tlvl - TLV_HDRL, op_msk, indent + 1) == -1) return -1; pdtlv = GO_NXT_TLV(pdtlv, len); } if (len) { - ND_PRINT("\n\t\tMessy PATHDATA TLV header, type (0x%x)\n\t\texcess of %d Bytes ", - EXTRACT_BE_U_2(&pdtlv->type), len - EXTRACT_BE_U_2(&pdtlv->length)); + ND_PRINT("\n\t\tMessy PATHDATA TLV header, type (0x%x)\n\t\texcess of %u Bytes ", + EXTRACT_BE_U_2(pdtlv->type), + len - EXTRACT_BE_U_2(pdtlv->length)); return -1; } return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1167,27 +1182,27 @@ otlv_print(netdissect_options *ndo, int rc = 0; const u_char *dp = (const u_char *) TLV_DATA(otlv); uint16_t type; - int tll; + u_int tll; char *ib = indent_pr(indent, 0); const struct optlv_h *ops; /* - * lfbselect_print() has ensured that EXTRACT_BE_U_2(&otlv->length) + * lfbselect_print() has ensured that EXTRACT_BE_U_2(otlv->length) * >= TLV_HDRL. */ ND_TCHECK_SIZE(otlv); - type = EXTRACT_BE_U_2(&otlv->type); - tll = EXTRACT_BE_U_2(&otlv->length) - TLV_HDRL; + type = EXTRACT_BE_U_2(otlv->type); + tll = EXTRACT_BE_U_2(otlv->length) - TLV_HDRL; ops = get_forces_optlv_h(type); if (ndo->ndo_vflag >= 3) { - ND_PRINT("%sOper TLV %s(0x%x) length %d\n", ib, ops->s, type, - EXTRACT_BE_U_2(&otlv->length)); + ND_PRINT("%sOper TLV %s(0x%x) length %u\n", ib, ops->s, type, + EXTRACT_BE_U_2(otlv->length)); } /* rest of ops must at least have 12B {pathinfo} */ if (tll < OP_MIN_SIZ) { - ND_PRINT("\t\tOper TLV %s(0x%x) length %d\n", ops->s, type, - EXTRACT_BE_U_2(&otlv->length)); - ND_PRINT("\t\tTruncated data size %d minimum required %d\n", tll, + ND_PRINT("\t\tOper TLV %s(0x%x) length %u\n", ops->s, type, + EXTRACT_BE_U_2(otlv->length)); + ND_PRINT("\t\tTruncated data size %u minimum required %u\n", tll, OP_MIN_SIZ); return invoptlv_print(ndo, dp, tll, ops->op_msk, indent); @@ -1200,7 +1215,7 @@ otlv_print(netdissect_options *ndo, return rc; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1221,13 +1236,13 @@ asttlv_print(netdissect_options *ndo, */ dlen = len - TLV_HDRL; if (dlen != ASTDLN) { - ND_PRINT("illegal ASTresult-TLV: %d bytes!\n", dlen); + ND_PRINT("illegal ASTresult-TLV: %u bytes!\n", dlen); return -1; } ND_TCHECK_4(pptr); rescode = EXTRACT_BE_U_4(pptr); if (rescode > ASTMCD) { - ND_PRINT("illegal ASTresult result code: %d!\n", rescode); + ND_PRINT("illegal ASTresult result code: %u!\n", rescode); return -1; } @@ -1258,7 +1273,7 @@ asttlv_print(netdissect_options *ndo, return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1279,14 +1294,14 @@ asrtlv_print(netdissect_options *ndo, */ dlen = len - TLV_HDRL; if (dlen != ASRDLN) { /* id, instance, oper tlv */ - ND_PRINT("illegal ASRresult-TLV: %d bytes!\n", dlen); + ND_PRINT("illegal ASRresult-TLV: %u bytes!\n", dlen); return -1; } ND_TCHECK_4(pptr); rescode = EXTRACT_BE_U_4(pptr); if (rescode > ASRMCD) { - ND_PRINT("illegal ASRresult result code: %d!\n", rescode); + ND_PRINT("illegal ASRresult result code: %u!\n", rescode); return -1; } @@ -1311,7 +1326,7 @@ asrtlv_print(netdissect_options *ndo, return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1327,7 +1342,7 @@ gentltlv_print(netdissect_options *ndo, u_int dlen = len - TLV_HDRL; if (dlen < 4) { /* at least 32 bits must exist */ - ND_PRINT("truncated TLV: %d bytes missing! ", 4 - dlen); + ND_PRINT("truncated TLV: %u bytes missing! ", 4 - dlen); return -1; } return 0; @@ -1349,10 +1364,10 @@ print_metailv(netdissect_options *ndo, * print_metatlv() has ensured that len (what remains in the * ILV) >= ILV_HDRL. */ - rlen = EXTRACT_BE_U_4(&ilv->length) - ILV_HDRL; + rlen = EXTRACT_BE_U_4(ilv->length) - ILV_HDRL; ND_TCHECK_SIZE(ilv); - ND_PRINT("%sMetaID 0x%x length %d\n", ib, EXTRACT_BE_U_4(&ilv->type), - EXTRACT_BE_U_4(&ilv->length)); + ND_PRINT("%sMetaID 0x%x length %u\n", ib, EXTRACT_BE_U_4(ilv->type), + EXTRACT_BE_U_4(ilv->length)); if (ndo->ndo_vflag >= 3) { hex_print_with_offset(ndo, "\t\t[", ILV_DATA(ilv), rlen, 0); ND_PRINT(" ]\n"); @@ -1360,7 +1375,7 @@ print_metailv(netdissect_options *ndo, return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1381,7 +1396,7 @@ print_metatlv(netdissect_options *ndo, */ dlen = len - TLV_HDRL; rlen = dlen; - ND_PRINT("\n%s METADATA length %d \n", ib, rlen); + ND_PRINT("\n%s METADATA length %u\n", ib, rlen); while (rlen != 0) { ND_TCHECK_SIZE(ilv); invilv = ilv_valid(ilv, rlen); @@ -1401,7 +1416,7 @@ print_metatlv(netdissect_options *ndo, return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1417,7 +1432,7 @@ print_reddata(netdissect_options *ndo, dlen = len - TLV_HDRL; rlen = dlen; - ND_PRINT("\n%s Redirect Data length %d \n", ib, rlen); + ND_PRINT("\n%s Redirect Data length %u\n", ib, rlen); if (ndo->ndo_vflag >= 3) { ND_PRINT("\t\t["); @@ -1444,7 +1459,7 @@ redirect_print(netdissect_options *ndo, */ dlen = len - TLV_HDRL; if (dlen <= RD_MIN) { - ND_PRINT("\n\t\ttruncated Redirect TLV: %d bytes missing! ", + ND_PRINT("\n\t\ttruncated Redirect TLV: %u bytes missing! ", RD_MIN - dlen); return -1; } @@ -1452,8 +1467,12 @@ redirect_print(netdissect_options *ndo, rlen = dlen; indent += 1; while (rlen != 0) { + uint16_t type, tlvl; + ND_TCHECK_SIZE(tlv); - invtlv = tlv_valid(tlv, rlen); + type = EXTRACT_BE_U_2(tlv->type); + tlvl = EXTRACT_BE_U_2(tlv->length); + invtlv = tlv_valid(tlvl, rlen); if (invtlv) { ND_PRINT("Bad Redirect data\n"); break; @@ -1464,34 +1483,34 @@ redirect_print(netdissect_options *ndo, * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ - if (EXTRACT_BE_U_2(&tlv->type) == F_TLV_METD) { + if (type == F_TLV_METD) { print_metatlv(ndo, (const u_char *) TLV_DATA(tlv), - EXTRACT_BE_U_2(&tlv->length), 0, + tlvl, 0, indent); - } else if ((EXTRACT_BE_U_2(&tlv->type) == F_TLV_REDD)) { + } else if (type == F_TLV_REDD) { print_reddata(ndo, (const u_char *) TLV_DATA(tlv), - EXTRACT_BE_U_2(&tlv->length), 0, + tlvl, 0, indent); } else { - ND_PRINT("Unknown REDIRECT TLV 0x%x len %d\n", - EXTRACT_BE_U_2(&tlv->type), - EXTRACT_BE_U_2(&tlv->length)); + ND_PRINT("Unknown REDIRECT TLV 0x%x len %u\n", + type, + tlvl); } tlv = GO_NXT_TLV(tlv, rlen); } if (rlen) { - ND_PRINT("\n\t\tMessy Redirect TLV header, type (0x%x)\n\t\texcess of %d Bytes ", - EXTRACT_BE_U_2(&tlv->type), - rlen - EXTRACT_BE_U_2(&tlv->length)); + ND_PRINT("\n\t\tMessy Redirect TLV header, type (0x%x)\n\t\texcess of %u Bytes ", + EXTRACT_BE_U_2(tlv->type), + rlen - EXTRACT_BE_U_2(tlv->length)); return -1; } return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1516,7 +1535,7 @@ lfbselect_print(netdissect_options *ndo, */ dlen = len - TLV_HDRL; if (dlen <= OP_MIN) { /* id, instance, oper tlv header .. */ - ND_PRINT("\n\t\ttruncated lfb selector: %d bytes missing! ", + ND_PRINT("\n\t\ttruncated lfb selector: %u bytes missing! ", OP_MIN - dlen); return -1; } @@ -1531,17 +1550,22 @@ lfbselect_print(netdissect_options *ndo, ND_TCHECK_SIZE(lfbs); if (ndo->ndo_vflag >= 3) { ND_PRINT("\n%s%s(Classid %x) instance %x\n", - ib, tok2str(ForCES_LFBs, NULL, EXTRACT_BE_U_4(&lfbs->class)), - EXTRACT_BE_U_4(&lfbs->class), - EXTRACT_BE_U_4(&lfbs->instance)); + ib, + tok2str(ForCES_LFBs, NULL, EXTRACT_BE_U_4(lfbs->class)), + EXTRACT_BE_U_4(lfbs->class), + EXTRACT_BE_U_4(lfbs->instance)); } otlv = (const struct forces_tlv *)(lfbs + 1); indent += 1; while (rlen != 0) { + uint16_t type, tlvl; + ND_TCHECK_SIZE(otlv); - invtlv = tlv_valid(otlv, rlen); + type = EXTRACT_BE_U_2(otlv->type); + tlvl = EXTRACT_BE_U_2(otlv->length); + invtlv = tlv_valid(tlvl, rlen); if (invtlv) break; @@ -1550,28 +1574,29 @@ lfbselect_print(netdissect_options *ndo, * length is large enough but not too large (it doesn't * go past the end of the containing TLV). */ - if (op_valid(EXTRACT_BE_U_2(&otlv->type), op_msk)) { + if (op_valid(type, op_msk)) { otlv_print(ndo, otlv, 0, indent); } else { if (ndo->ndo_vflag < 3) ND_PRINT("\n"); - ND_PRINT("\t\tINValid oper-TLV type 0x%x length %d for this ForCES message\n", - EXTRACT_BE_U_2(&otlv->type), EXTRACT_BE_U_2(&otlv->length)); + ND_PRINT("\t\tINValid oper-TLV type 0x%x length %u for this ForCES message\n", + type, tlvl); invoptlv_print(ndo, (const u_char *)otlv, rlen, 0, indent); } otlv = GO_NXT_TLV(otlv, rlen); } if (rlen) { - ND_PRINT("\n\t\tMessy oper TLV header, type (0x%x)\n\t\texcess of %d Bytes ", - EXTRACT_BE_U_2(&otlv->type), rlen - EXTRACT_BE_U_2(&otlv->length)); + ND_PRINT("\n\t\tMessy oper TLV header, type (0x%x)\n\t\texcess of %u Bytes ", + EXTRACT_BE_U_2(otlv->type), + rlen - EXTRACT_BE_U_2(otlv->length)); return -1; } return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1584,7 +1609,7 @@ forces_type_print(netdissect_options *ndo, u_int rlen; u_int invtlv; int rc = 0; - int ttlv = 0; + u_int ttlv = 0; /* * forces_print() has already checked that mlen >= ForCES_HDRL @@ -1616,8 +1641,12 @@ forces_type_print(netdissect_options *ndo, /*XXX: 15 top level tlvs will probably be fine You are nuts if you send more ;-> */ while (rlen != 0) { + u_int type, tlvl; + ND_TCHECK_SIZE(tltlv); - invtlv = tlv_valid(tltlv, rlen); + type = EXTRACT_BE_U_2(tltlv->type); + tlvl = EXTRACT_BE_U_2(tltlv->length); + invtlv = tlv_valid(tlvl, rlen); if (invtlv) break; @@ -1626,20 +1655,20 @@ forces_type_print(netdissect_options *ndo, * length is large enough but not too large (it doesn't * go past the end of the packet). */ - if (!ttlv_valid(EXTRACT_BE_U_2(&tltlv->type))) { + if (!ttlv_valid(type)) { ND_PRINT("\n\tInvalid ForCES Top TLV type=0x%x", - EXTRACT_BE_U_2(&tltlv->type)); + type); return -1; } if (ndo->ndo_vflag >= 3) - ND_PRINT("\t%s, length %d (data length %d Bytes)", - tok2str(ForCES_TLV, NULL, EXTRACT_BE_U_2(&tltlv->type)), - EXTRACT_BE_U_2(&tltlv->length), - EXTRACT_BE_U_2(&tltlv->length) - TLV_HDRL); + ND_PRINT("\t%s, length %u (data length %u Bytes)", + tok2str(ForCES_TLV, NULL, type), + tlvl, + tlvl - TLV_HDRL); rc = tops->print(ndo, (const u_char *) TLV_DATA(tltlv), - EXTRACT_BE_U_2(&tltlv->length), + tlvl, tops->op_msk, 9); if (rc < 0) { return -1; @@ -1654,15 +1683,15 @@ forces_type_print(netdissect_options *ndo, * short, and didn't have *enough* TLVs in it? */ if (rlen) { - ND_PRINT("\tMess TopTLV header: min %u, total %d advertised %d ", - TLV_HDRL, rlen, EXTRACT_BE_U_2(&tltlv->length)); + ND_PRINT("\tMess TopTLV header: min %u, total %u advertised %u ", + TLV_HDRL, rlen, EXTRACT_BE_U_2(tltlv->length)); return -1; } return 0; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); return -1; } @@ -1677,11 +1706,12 @@ forces_print(netdissect_options *ndo, const struct tom_h *tops; int rc = 0; + ndo->ndo_protocol = "forces"; fhdr = (const struct forcesh *)pptr; ND_TCHECK_SIZE(fhdr); tom = EXTRACT_U_1(fhdr->fm_tom); if (!tom_valid(tom)) { - ND_PRINT("Invalid ForCES message type %d\n", tom); + ND_PRINT("Invalid ForCES message type %u\n", tom); goto error; } @@ -1695,7 +1725,7 @@ forces_print(netdissect_options *ndo, ND_PRINT("\n\tForCES %s ", tops->s); if (!ForCES_HLN_VALID(mlen, len)) { - ND_PRINT("Illegal ForCES pkt len - min %u, total recvd %d, advertised %d ", + ND_PRINT("Illegal ForCES pkt len - min %u, total recvd %u, advertised %u ", ForCES_HDRL, len, ForCES_BLN(fhdr)); goto error; } @@ -1703,7 +1733,7 @@ forces_print(netdissect_options *ndo, ND_TCHECK_4(pptr + 20); flg_raw = EXTRACT_BE_U_4(pptr + 20); if (ndo->ndo_vflag >= 1) { - ND_PRINT("\n\tForCES Version %d len %uB flags 0x%08x ", + ND_PRINT("\n\tForCES Version %u len %uB flags 0x%08x ", ForCES_V(fhdr), mlen, flg_raw); ND_PRINT("\n\tSrcID 0x%x(%s) DstID 0x%x(%s) Correlator 0x%" PRIx64, ForCES_SID(fhdr), ForCES_node(ForCES_SID(fhdr)), @@ -1712,7 +1742,7 @@ forces_print(netdissect_options *ndo, } if (ndo->ndo_vflag >= 2) { - ND_PRINT("\n\tForCES flags:\n\t %s(0x%x), prio=%d, %s(0x%x),\n\t %s(0x%x), %s(0x%x)\n", + ND_PRINT("\n\tForCES flags:\n\t %s(0x%x), prio=%u, %s(0x%x),\n\t %s(0x%x), %s(0x%x)\n", tok2str(ForCES_ACKs, "ACKUnknown", ForCES_ACK(fhdr)), ForCES_ACK(fhdr), ForCES_PRI(fhdr), @@ -1742,11 +1772,5 @@ error: return; trunc: - ND_PRINT("%s", tstr); + nd_print_trunc(ndo); } -/* - * Local Variables: - * c-style: whitesmith - * c-basic-offset: 8 - * End: - */