示例#1
0
static int
recpdoptlv_print(netdissect_options *ndo,
                 register const u_char * pptr, register u_int len,
                 u_int16_t op_msk, int indent)
{
	const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr;
	int tll;
	u_int invtlv;
	u_int16_t type;
	register const u_char *dp;
	char *ib;

	while (len != 0) {
		ND_TCHECK(*pdtlv);
		invtlv = tlv_valid(pdtlv, len);
		if (invtlv) {
			break;
		}

		/*
		 * At this point, tlv_valid() has ensured that the TLV
		 * length is large enough but not too large (it doesn't
		 * go past the end of the containing TLV).
		 */
		ib = indent_pr(indent, 0);
		type = EXTRACT_16BITS(&pdtlv->type);
		dp = (u_char *) TLV_DATA(pdtlv);
		tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;

		if (ndo->ndo_vflag >= 3)
			ND_PRINT((ndo, "%s%s, length %d (data encapsulated %d Bytes)",
			          ib, tok2str(ForCES_TLV, NULL, type),
			          EXTRACT_16BITS(&pdtlv->length),
			          EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL));

		if (pdata_print(ndo, dp, tll, op_msk, indent + 1) == -1)
			return -1;
		pdtlv = GO_NXT_TLV(pdtlv, len);
	}

	if (len) {
		ND_PRINT((ndo,
		          "\n\t\tMessy PATHDATA TLV header, type (0x%x)\n\t\texcess of %d Bytes ",
		          EXTRACT_16BITS(&pdtlv->type), len - EXTRACT_16BITS(&pdtlv->length)));
		return -1;
	}

	return 0;

trunc:
	ND_PRINT((ndo, "%s", tstr));
	return -1;
}
示例#2
0
static int
genoptlv_print(netdissect_options *ndo,
               register const u_char * pptr, register u_int len,
               u_int16_t op_msk, int indent)
{
	const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr;
	u_int16_t type;
	int tll;
	u_int invtlv;
	char *ib = indent_pr(indent, 0);

	ND_TCHECK(*pdtlv);
	type = EXTRACT_16BITS(&pdtlv->type);
	tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
	invtlv = tlv_valid(pdtlv, len);
	ND_PRINT((ndo, "genoptlvprint - %s TLV type 0x%x len %d\n",
	       tok2str(ForCES_TLV, NULL, type), type, EXTRACT_16BITS(&pdtlv->length)));
	if (!invtlv) {
		/*
		 * At this point, tlv_valid() has ensured that the TLV
		 * 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);
		if (!ttlv_valid(type)) {
			ND_PRINT((ndo, "%s TLV type 0x%x len %d\n",
			       tok2str(ForCES_TLV_err, NULL, invtlv), type,
			       EXTRACT_16BITS(&pdtlv->length)));
			return -1;
		}
		if (ndo->ndo_vflag >= 3)
			ND_PRINT((ndo, "%s%s, length %d (data length %d Bytes)",
			       ib, tok2str(ForCES_TLV, NULL, type),
			       EXTRACT_16BITS(&pdtlv->length), tll));

		return pdata_print(ndo, dp, tll, op_msk, indent + 1);
	} else {
		ND_PRINT((ndo, "\t\t\tInvalid ForCES TLV type=%x", type));
		return -1;
	}

trunc:
	ND_PRINT((ndo, "%s", tstr));
	return -1;
}
示例#3
0
static int
pkeyitlv_print(netdissect_options *ndo,
               register const u_char * pptr, register u_int len,
               u_int16_t op_msk, int indent)
{
	const struct forces_tlv *tlv = (struct forces_tlv *)pptr;
	register const u_char *tdp = (u_char *) TLV_DATA(tlv);
	register const u_char *dp = tdp + 4;
	const struct forces_tlv *kdtlv = (struct forces_tlv *)dp;
	u_int32_t id;
	char *ib = indent_pr(indent, 0);
	u_int16_t type, tll;
	u_int invtlv;

	ND_TCHECK(*tdp);
	id = EXTRACT_32BITS(tdp);
	ND_PRINT((ndo, "%sKeyinfo: Key 0x%x\n", ib, id));
	ND_TCHECK(*kdtlv);
	type = EXTRACT_16BITS(&kdtlv->type);
	invtlv = tlv_valid(kdtlv, len);

	if (invtlv) {
		ND_PRINT((ndo, "%s TLV type 0x%x len %d\n",
		       tok2str(ForCES_TLV_err, NULL, invtlv), type,
		       EXTRACT_16BITS(&kdtlv->length)));
		return -1;
	}
	/*
	 * At this point, tlv_valid() has ensured that the TLV
	 * length is large enough but not too large (it doesn't
	 * go past the end of the containing TLV).
	 */
	tll = EXTRACT_16BITS(&kdtlv->length);
	dp = (u_char *) TLV_DATA(kdtlv);
	return fdatatlv_print(ndo, dp, tll, op_msk, indent);

trunc:
	ND_PRINT((ndo, "%s", tstr));
	return -1;
}
示例#4
0
static int
pdatacnt_print(netdissect_options *ndo,
               register const u_char * pptr, register u_int len,
               u_int16_t IDcnt, u_int16_t op_msk, int indent)
{
	u_int i;
	u_int32_t id;
	char *ib = indent_pr(indent, 0);

	if ((op_msk & B_APPND) && ndo->ndo_vflag >= 3) {
		ND_PRINT((ndo, "%sTABLE APPEND\n", ib));
	}
	for (i = 0; i < IDcnt; i++) {
		ND_TCHECK2(*pptr, 4);
		if (len < 4)
			goto trunc;
		id = EXTRACT_32BITS(pptr);
		if (ndo->ndo_vflag >= 3)
			ND_PRINT((ndo, "%sID#%02u: %d\n", ib, i + 1, id));
		len -= 4;
		pptr += 4;
	}

	if ((op_msk & B_TRNG) || (op_msk & B_KEYIN)) {
		if (op_msk & B_TRNG) {
			u_int32_t starti, endi;

			if (len < PTH_DESC_SIZE) {
				ND_PRINT((ndo, "pathlength %d with key/range too short %d\n",
				       len, PTH_DESC_SIZE));
				return -1;
			}

			pptr += sizeof(struct forces_tlv);
			len -= sizeof(struct forces_tlv);

			starti = EXTRACT_32BITS(pptr);
			pptr += 4;
			len -= 4;

			endi = EXTRACT_32BITS(pptr);
			pptr += 4;
			len -= 4;

			if (ndo->ndo_vflag >= 3)
				ND_PRINT((ndo, "%sTable range: [%d,%d]\n", ib, starti, endi));
		}

		if (op_msk & B_KEYIN) {
			struct forces_tlv *keytlv;
			u_int16_t tll;

			if (len < PTH_DESC_SIZE) {
				ND_PRINT((ndo, "pathlength %d with key/range too short %d\n",
				       len, PTH_DESC_SIZE));
				return -1;
			}

			/* skip keyid */
			pptr += 4;
			len -= 4;
			keytlv = (struct forces_tlv *)pptr;
			/* skip header */
			pptr += sizeof(struct forces_tlv);
			len -= sizeof(struct forces_tlv);
			/* skip key content */
			tll = EXTRACT_16BITS(&keytlv->length);
			if (tll < TLV_HDRL) {
				ND_PRINT((ndo, "key content length %u < %u\n",
					tll, TLV_HDRL));
				return -1;
			}
			tll -= TLV_HDRL;
			if (len < tll) {
				ND_PRINT((ndo, "key content too short\n"));
				return -1;
			}
			pptr += tll;
			len -= tll;
		}

	}

	if (len) {
		const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr;
		u_int16_t type;
		u_int16_t tll;
		int pad = 0;
		u_int aln;
		u_int invtlv;

		ND_TCHECK(*pdtlv);
		type = EXTRACT_16BITS(&pdtlv->type);
		invtlv = tlv_valid(pdtlv, len);
		if (invtlv) {
			ND_PRINT((ndo, "%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n",
			          tok2str(ForCES_TLV_err, NULL, invtlv), len, type,
			          EXTRACT_16BITS(&pdtlv->length)));
			goto pd_err;
		}
		/*
		 * At this point, tlv_valid() has ensured that the TLV
		 * length is large enough but not too large (it doesn't
		 * go past the end of the containing TLV).
		 */
		tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
		aln = F_ALN_LEN(EXTRACT_16BITS(&pdtlv->length));
		if (aln > EXTRACT_16BITS(&pdtlv->length)) {
			if (aln > len) {
				ND_PRINT((ndo,
				          "Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n",
				          type, EXTRACT_16BITS(&pdtlv->length), aln - len));
			} else {
				pad = aln - EXTRACT_16BITS(&pdtlv->length);
			}
		}
		if (pd_valid(type)) {
			const struct pdata_ops *ops = get_forces_pd(type);

			if (ndo->ndo_vflag >= 3 && ops->v != F_TLV_PDAT) {
				if (pad)
					ND_PRINT((ndo, "%s  %s (Length %d DataLen %d pad %d Bytes)\n",
					          ib, ops->s, EXTRACT_16BITS(&pdtlv->length), tll, pad));
				else
					ND_PRINT((ndo, "%s  %s (Length %d DataLen %d Bytes)\n",
					          ib, ops->s, EXTRACT_16BITS(&pdtlv->length), tll));
			}

			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)
				return -1;
			len -= (TLV_HDRL + pad + tll);
		} else {
			ND_PRINT((ndo, "Invalid path data content type 0x%x len %d\n",
			       type, EXTRACT_16BITS(&pdtlv->length)));
pd_err:
			if (EXTRACT_16BITS(&pdtlv->length)) {
                                hex_print_with_offset(ndo, "Bad Data val\n\t  [",
						      pptr, len, 0);
				ND_PRINT((ndo, "]\n"));

				return -1;
			}
		}
	}
	return len;

trunc:
	ND_PRINT((ndo, "%s", tstr));
	return -1;
}
示例#5
0
int
pdatacnt_print(register const u_char * pptr, register u_int len,
	       u_int16_t IDcnt, u_int16_t op_msk, int indent)
{
	u_int i;
	u_int32_t id;
	char *ib = indent_pr(indent, 0);

	for (i = 0; i < IDcnt; i++) {
		TCHECK2(*pptr, 4);
		if (len < 4)
			goto trunc;
		id = EXTRACT_32BITS(pptr);
		if (vflag >= 3)
			printf("%s  ID#%02u: %d\n", ib, i + 1, id);
		len -= 4;
		pptr += 4;
	}
	if (len) {
		const struct forces_tlv *pdtlv = (struct forces_tlv *)pptr;
		u_int16_t type;
		u_int16_t tll;
		int pad = 0;
		u_int aln;
		int invtlv;

		TCHECK(*pdtlv);
		type = EXTRACT_16BITS(&pdtlv->type);
		invtlv = tlv_valid(pdtlv, len);
		if (invtlv) {
			printf
			    ("%s Outstanding bytes %d for TLV type 0x%x TLV len %d\n",
			     tok2str(ForCES_TLV_err, NULL, invtlv), len, type,
			     EXTRACT_16BITS(&pdtlv->length));
			goto pd_err;
		}
		/*
		 * At this point, tlv_valid() has ensured that the TLV
		 * length is large enough but not too large (it doesn't
		 * go past the end of the containing TLV).
		 */
		tll = EXTRACT_16BITS(&pdtlv->length) - TLV_HDRL;
		aln = F_ALN_LEN(EXTRACT_16BITS(&pdtlv->length));
		if (aln > EXTRACT_16BITS(&pdtlv->length)) {
			if (aln > len) {
				printf
				    ("Invalid padded pathdata TLV type 0x%x len %d missing %d pad bytes\n",
				     type, EXTRACT_16BITS(&pdtlv->length), aln - len);
			} else {
				pad = aln - EXTRACT_16BITS(&pdtlv->length);
			}
		}
		if (pd_valid(type)) {
			const struct pdata_ops *ops = get_forces_pd(type);

			if (vflag >= 3 && ops->v != F_TLV_PDAT) {
				if (pad)
					printf
					    ("%s  %s (Length %d DataLen %d pad %d Bytes)\n",
					     ib, ops->s, EXTRACT_16BITS(&pdtlv->length),
					     tll, pad);
				else
					printf
					    ("%s  %s (Length %d DataLen %d Bytes)\n",
					     ib, ops->s, EXTRACT_16BITS(&pdtlv->length),
					     tll);
			}

			chk_op_type(type, op_msk, ops->op_msk);

			if (ops->print((const u_char *)pdtlv,
					tll + pad + TLV_HDRL, op_msk,
					indent + 2) == -1)
				return -1;
			len -= (TLV_HDRL + pad + tll);
		} else {
			printf("Invalid path data content type 0x%x len %d\n",
			       type, EXTRACT_16BITS(&pdtlv->length));
pd_err:
			if (EXTRACT_16BITS(&pdtlv->length)) {
				hex_print_with_offset("Bad Data val\n\t  [",
						      pptr, len, 0);
				printf("]\n");

				return -1;
			}
		}
	}
	return len;

trunc:
	fputs("[|forces]", stdout);
	return -1;
}