X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/99ee702977aa759ce3bd4c11b1592cae2d4e58aa..1fb50928ce27360c1c987312774f686b23c69b51:/print-forces.c diff --git a/print-forces.c b/print-forces.c index 7dbac817..de6c8264 100644 --- a/print-forces.c +++ b/print-forces.c @@ -14,21 +14,21 @@ * */ -#define NETDISSECT_REWORKED +/* \summary: Forwarding and Control Element Separation (ForCES) Protocol printer */ + +/* specification: RFC 5810 */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include -#include "interface.h" +#include "netdissect.h" #include "extract.h" static const char tstr[] = "[|forces]"; -/* - * RFC5810: Forwarding and Control Element Separation (ForCES) Protocol - */ #define ForCES_VERS 1 #define ForCES_HDRL 24 #define ForCES_ALNL 4U @@ -153,17 +153,17 @@ static const struct tok ForCES_TPs[] = { * Structure of forces header, naked of TLVs. */ struct forcesh { - uint8_t fm_vrsvd; /* version and reserved */ + nd_uint8_t fm_vrsvd; /* version and reserved */ #define ForCES_V(forcesh) ((forcesh)->fm_vrsvd >> 4) - uint8_t fm_tom; /* type of message */ - uint16_t fm_len; /* total length * 4 bytes */ + nd_uint8_t fm_tom; /* type of message */ + nd_uint16_t fm_len; /* total length * 4 bytes */ #define ForCES_BLN(forcesh) ((uint32_t)(EXTRACT_16BITS(&(forcesh)->fm_len) << 2)) - uint32_t fm_sid; /* Source ID */ + nd_uint32_t fm_sid; /* Source ID */ #define ForCES_SID(forcesh) EXTRACT_32BITS(&(forcesh)->fm_sid) - uint32_t fm_did; /* Destination ID */ + nd_uint32_t fm_did; /* Destination ID */ #define ForCES_DID(forcesh) EXTRACT_32BITS(&(forcesh)->fm_did) - uint8_t fm_cor[8]; /* correlator */ - uint32_t fm_flags; /* flags */ + nd_uint8_t fm_cor[8]; /* correlator */ + nd_uint32_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) @@ -187,26 +187,28 @@ static const struct tok ForCES_LFBs[] = { {0, NULL} }; +/* this is defined in RFC5810 section A.2 */ +/* http://www.iana.org/assignments/forces/forces.xhtml#oper-tlv-types */ enum { - F_OP_RSV, - F_OP_SET, - F_OP_SETPROP, - F_OP_SETRESP, - F_OP_SETPRESP, - F_OP_DEL, - F_OP_DELRESP, - F_OP_GET, - F_OP_GETPROP, - F_OP_GETRESP, - F_OP_GETPRESP, - F_OP_REPORT, - F_OP_COMMIT, - F_OP_RCOMMIT, - F_OP_RTRCOMP, + F_OP_RSV = 0, + F_OP_SET = 1, + F_OP_SETPROP = 2, + F_OP_SETRESP = 3, + F_OP_SETPRESP = 4, + F_OP_DEL = 5, + F_OP_DELRESP = 6, + F_OP_GET = 7, + F_OP_GETPROP = 8, + F_OP_GETRESP = 9, + F_OP_GETPRESP = 10, + F_OP_REPORT = 11, + F_OP_COMMIT = 12, + F_OP_RCOMMIT = 13, + F_OP_RTRCOMP = 14, _F_OP_MAX }; - #define F_OP_MAX (_F_OP_MAX - 1) + enum { B_OP_SET = 1 << (F_OP_SET - 1), B_OP_SETPROP = 1 << (F_OP_SETPROP - 1), @@ -221,7 +223,7 @@ enum { B_OP_REPORT = 1 << (F_OP_REPORT - 1), B_OP_COMMIT = 1 << (F_OP_COMMIT - 1), B_OP_RCOMMIT = 1 << (F_OP_RCOMMIT - 1), - B_OP_RTRCOMP = 1 << (F_OP_RTRCOMP - 1), + B_OP_RTRCOMP = 1 << (F_OP_RTRCOMP - 1) }; struct optlv_h { @@ -241,8 +243,8 @@ static int invoptlv_print(netdissect_options *, register const u_char * pptr, re #define OP_MIN_SIZ 8 struct pathdata_h { - uint16_t pflags; - uint16_t pIDcnt; + nd_uint16_t pflags; + nd_uint16_t pIDcnt; }; #define B_FULLD 0x1 @@ -286,7 +288,7 @@ static inline const struct optlv_h *get_forces_optlv_h(uint16_t opt) #define IND_CHR ' ' #define IND_PREF '\n' #define IND_SUF 0x0 -char ind_buf[IND_SIZE]; +static char ind_buf[IND_SIZE]; static inline char *indent_pr(int indent, int nlpref) { @@ -374,30 +376,30 @@ static inline int ttlv_valid(uint16_t ttlv) } struct forces_ilv { - uint32_t type; - uint32_t length; + nd_uint32_t type; + nd_uint32_t length; }; struct forces_tlv { - uint16_t type; - uint16_t length; + nd_uint16_t type; + nd_uint16_t length; }; #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 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_ALN_LEN(len) F_ALN_LEN(TLV_SET_LEN(len)) #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 TLV_DATA(tlvp) ((const void*)(((const char*)(tlvp)) + TLV_SET_LEN(0))) #define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_16BITS(&(tlv)->length)), \ - (struct forces_tlv*)(((char*)(tlv)) \ + (const struct forces_tlv*)(((const char*)(tlv)) \ + 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)(EXTRACT_32BITS(&(ilv)->length)) - ILV_SET_LEN(0)) -#define ILV_DATA(ilvp) ((void*)(((char*)(ilvp)) + ILV_SET_LEN(0))) +#define ILV_DATA(ilvp) ((const void*)(((const char*)(ilvp)) + ILV_SET_LEN(0))) #define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length)), \ - (struct forces_ilv *)(((char*)(ilv)) \ + (const struct forces_ilv *)(((const char*)(ilv)) \ + F_ALN_LEN(EXTRACT_32BITS(&(ilv)->length)))) #define INVALID_RLEN 1 #define INVALID_STLN 2 @@ -450,8 +452,8 @@ static int asttlv_print(netdissect_options *, register const u_char * pptr, regi uint16_t op_msk, int indent); struct forces_lfbsh { - uint32_t class; - uint32_t instance; + nd_uint32_t class; + nd_uint32_t instance; }; #define ASSNS_OPS (B_OP_REPORT) @@ -544,9 +546,9 @@ chk_op_type(netdissect_options *ndo, #define F_TABAPPEND 4 struct res_val { - uint8_t result; - uint8_t resv1; - uint16_t resv2; + nd_uint8_t result; + nd_uint8_t resv1; + nd_uint16_t resv2; }; static int prestlv_print(netdissect_options *, register const u_char * pptr, register u_int len, @@ -644,9 +646,9 @@ prestlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { - const struct forces_tlv *tlv = (struct forces_tlv *)pptr; - register const u_char *tdp = (u_char *) TLV_DATA(tlv); - struct res_val *r = (struct res_val *)tdp; + const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; + register const u_char *tdp = (const u_char *) TLV_DATA(tlv); + const struct res_val *r = (const struct res_val *)tdp; u_int dlen; /* @@ -682,9 +684,9 @@ fdatatlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { - const struct forces_tlv *tlv = (struct forces_tlv *)pptr; + const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; u_int rlen; - register const u_char *tdp = (u_char *) TLV_DATA(tlv); + register const u_char *tdp = (const u_char *) TLV_DATA(tlv); uint16_t type; /* @@ -718,7 +720,7 @@ sdatailv_print(netdissect_options *ndo, uint16_t op_msk _U_, int indent) { u_int rlen; - const struct forces_ilv *ilv = (struct forces_ilv *)pptr; + const struct forces_ilv *ilv = (const struct forces_ilv *)pptr; int invilv; if (len < ILV_HDRL) { @@ -732,7 +734,7 @@ sdatailv_print(netdissect_options *ndo, ND_PRINT((ndo, "Jamal - outstanding length <%d>\n", rlen)); #endif char *ib = indent_pr(indent, 1); - register const u_char *tdp = (u_char *) ILV_DATA(ilv); + register const u_char *tdp = (const u_char *) ILV_DATA(ilv); ND_TCHECK(*ilv); invilv = ilv_valid(ilv, rlen); if (invilv) { @@ -763,9 +765,9 @@ sdatatlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { - const struct forces_tlv *tlv = (struct forces_tlv *)pptr; + const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; u_int rlen; - register const u_char *tdp = (u_char *) TLV_DATA(tlv); + register const u_char *tdp = (const u_char *) TLV_DATA(tlv); uint16_t type; /* @@ -792,10 +794,10 @@ pkeyitlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { - const struct forces_tlv *tlv = (struct forces_tlv *)pptr; - register const u_char *tdp = (u_char *) TLV_DATA(tlv); + const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; + register const u_char *tdp = (const u_char *) TLV_DATA(tlv); register const u_char *dp = tdp + 4; - const struct forces_tlv *kdtlv = (struct forces_tlv *)dp; + const struct forces_tlv *kdtlv = (const struct forces_tlv *)dp; uint32_t id; char *ib = indent_pr(indent, 0); uint16_t type, tll; @@ -820,7 +822,7 @@ pkeyitlv_print(netdissect_options *ndo, * go past the end of the containing TLV). */ tll = EXTRACT_16BITS(&kdtlv->length); - dp = (u_char *) TLV_DATA(kdtlv); + dp = (const u_char *) TLV_DATA(kdtlv); return fdatatlv_print(ndo, dp, tll, op_msk, indent); trunc: @@ -879,7 +881,7 @@ pdatacnt_print(netdissect_options *ndo, } if (op_msk & B_KEYIN) { - struct forces_tlv *keytlv; + const struct forces_tlv *keytlv; uint16_t tll; if (len < PTH_DESC_SIZE) { @@ -891,7 +893,7 @@ pdatacnt_print(netdissect_options *ndo, /* skip keyid */ pptr += 4; len -= 4; - keytlv = (struct forces_tlv *)pptr; + keytlv = (const struct forces_tlv *)pptr; /* skip header */ pptr += sizeof(struct forces_tlv); len -= sizeof(struct forces_tlv); @@ -914,7 +916,7 @@ pdatacnt_print(netdissect_options *ndo, } if (len) { - const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr; + const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr; uint16_t type; uint16_t tll; int pad = 0; @@ -990,7 +992,7 @@ pdata_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { - const struct pathdata_h *pdh = (struct pathdata_h *)pptr; + const struct pathdata_h *pdh = (const struct pathdata_h *)pptr; char *ib = indent_pr(indent, 0); u_int minsize = 0; int more_pd = 0; @@ -1054,7 +1056,7 @@ genoptlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { - const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr; + const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr; uint16_t type; int tll; u_int invtlv; @@ -1072,7 +1074,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). */ - register const u_char *dp = (u_char *) TLV_DATA(pdtlv); + register const u_char *dp = (const u_char *) TLV_DATA(pdtlv); if (!ttlv_valid(type)) { ND_PRINT((ndo, "%s TLV type 0x%x len %d\n", tok2str(ForCES_TLV_err, NULL, invtlv), type, @@ -1100,7 +1102,7 @@ recpdoptlv_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk, int indent) { - const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr; + const struct forces_tlv *pdtlv = (const struct forces_tlv *)pptr; int tll; u_int invtlv; uint16_t type; @@ -1121,7 +1123,7 @@ recpdoptlv_print(netdissect_options *ndo, */ ib = indent_pr(indent, 0); type = EXTRACT_16BITS(&pdtlv->type); - dp = (u_char *) TLV_DATA(pdtlv); + dp = (const u_char *) TLV_DATA(pdtlv); tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL; if (ndo->ndo_vflag >= 3) @@ -1169,7 +1171,7 @@ otlv_print(netdissect_options *ndo, const struct forces_tlv *otlv, uint16_t op_msk _U_, int indent) { int rc = 0; - register const u_char *dp = (u_char *) TLV_DATA(otlv); + register const u_char *dp = (const u_char *) TLV_DATA(otlv); uint16_t type; int tll; char *ib = indent_pr(indent, 0); @@ -1198,7 +1200,9 @@ otlv_print(netdissect_options *ndo, } /* XXX - do anything with ops->flags? */ - rc = ops->print(ndo, dp, tll, ops->op_msk, indent + 1); + if(ops->print) { + rc = ops->print(ndo, dp, tll, ops->op_msk, indent + 1); + } return rc; trunc: @@ -1345,7 +1349,7 @@ print_metailv(netdissect_options *ndo, u_int rlen; char *ib = indent_pr(indent, 0); /* XXX: check header length */ - const struct forces_ilv *ilv = (struct forces_ilv *)pptr; + const struct forces_ilv *ilv = (const struct forces_ilv *)pptr; /* * print_metatlv() has ensured that len (what remains in the @@ -1374,7 +1378,7 @@ print_metatlv(netdissect_options *ndo, u_int dlen; char *ib = indent_pr(indent, 0); u_int rlen; - const struct forces_ilv *ilv = (struct forces_ilv *)pptr; + const struct forces_ilv *ilv = (const struct forces_ilv *)pptr; int invilv; /* @@ -1396,7 +1400,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, (u_char *) ilv, 0, indent + 1); + print_metailv(ndo, (const u_char *) ilv, 0, indent + 1); ilv = GO_NXT_ILV(ilv, rlen); } @@ -1411,7 +1415,7 @@ trunc: static int print_reddata(netdissect_options *ndo, register const u_char * pptr, register u_int len, - uint16_t op_msk _U_, int indent _U_) + uint16_t op_msk _U_, int indent) { u_int dlen; char *ib = indent_pr(indent, 0); @@ -1435,7 +1439,7 @@ redirect_print(netdissect_options *ndo, register const u_char * pptr, register u_int len, uint16_t op_msk _U_, int indent) { - const struct forces_tlv *tlv = (struct forces_tlv *)pptr; + const struct forces_tlv *tlv = (const struct forces_tlv *)pptr; u_int dlen; u_int rlen; u_int invtlv; @@ -1467,10 +1471,10 @@ redirect_print(netdissect_options *ndo, * go past the end of the containing TLV). */ if (EXTRACT_16BITS(&tlv->type) == F_TLV_METD) { - print_metatlv(ndo, (u_char *) TLV_DATA(tlv), + print_metatlv(ndo, (const u_char *) TLV_DATA(tlv), EXTRACT_16BITS(&tlv->length), 0, indent); } else if ((EXTRACT_16BITS(&tlv->type) == F_TLV_REDD)) { - print_reddata(ndo, (u_char *) TLV_DATA(tlv), + print_reddata(ndo, (const u_char *) TLV_DATA(tlv), EXTRACT_16BITS(&tlv->length), 0, indent); } else { ND_PRINT((ndo, "Unknown REDIRECT TLV 0x%x len %d\n", @@ -1537,7 +1541,7 @@ lfbselect_print(netdissect_options *ndo, EXTRACT_32BITS(&lfbs->instance))); } - otlv = (struct forces_tlv *)(lfbs + 1); + otlv = (const struct forces_tlv *)(lfbs + 1); indent += 1; while (rlen != 0) { @@ -1559,7 +1563,7 @@ lfbselect_print(netdissect_options *ndo, ND_PRINT((ndo, "\t\tINValid oper-TLV type 0x%x length %d for this ForCES message\n", EXTRACT_16BITS(&otlv->type), EXTRACT_16BITS(&otlv->length))); - invoptlv_print(ndo, (u_char *)otlv, rlen, 0, indent); + invoptlv_print(ndo, (const u_char *)otlv, rlen, 0, indent); } otlv = GO_NXT_TLV(otlv, rlen); } @@ -1641,7 +1645,7 @@ forces_type_print(netdissect_options *ndo, EXTRACT_16BITS(&tltlv->length), EXTRACT_16BITS(&tltlv->length) - TLV_HDRL)); - rc = tops->print(ndo, (u_char *) TLV_DATA(tltlv), + rc = tops->print(ndo, (const u_char *) TLV_DATA(tltlv), EXTRACT_16BITS(&tltlv->length), tops->op_msk, 9); if (rc < 0) { return -1;