#include "netdissect-stdinc.h"
-#include <string.h>
-
+#define ND_LONGJMP_FROM_TCHECK
#include "netdissect.h"
#include "extract.h"
#include "addrtoname.h"
/*
* Build a indentation string for a given indentation level.
- * XXX this should be really in util.c
*/
static char *
indent_string (u_int indent)
const rpki_rtr_pdu *pdu_header;
u_int pdu_type, pdu_len, hexdump;
const u_char *msg;
+ uint8_t pdu_ver;
- /* Protocol Version */
- ND_TCHECK_1(tptr);
- if (GET_U_1(tptr) != 0) {
+ if (len < sizeof(rpki_rtr_pdu)) {
+ ND_PRINT("(%u bytes is too few to decode)", len);
+ goto invalid;
+ }
+ pdu_header = (const rpki_rtr_pdu *)tptr;
+ pdu_ver = GET_U_1(pdu_header->version);
+ if (pdu_ver != 0) {
/* Skip the rest of the input buffer because even if this is
* a well-formed PDU of a future RPKI-Router protocol version
* followed by a well-formed PDU of RPKI-Router protocol
* version 0, there is no way to know exactly how to skip the
* current PDU.
*/
- ND_PRINT("%sRPKI-RTRv%u (unknown)", indent_string(8), GET_U_1(tptr));
+ ND_PRINT("%sRPKI-RTRv%u (unknown)", indent_string(8), pdu_ver);
return len;
}
- if (len < sizeof(rpki_rtr_pdu)) {
- ND_PRINT("(%u bytes is too few to decode)", len);
- goto invalid;
- }
- ND_TCHECK_LEN(tptr, sizeof(rpki_rtr_pdu));
- pdu_header = (const rpki_rtr_pdu *)tptr;
pdu_type = GET_U_1(pdu_header->pdu_type);
pdu_len = GET_BE_U_4(pdu_header->length);
/* Do not check bounds with pdu_len yet, do it in the case blocks
ND_PRINT("%sRPKI-RTRv%u, %s PDU (%u), length: %u",
indent_string(8),
- GET_U_1(pdu_header->version),
+ pdu_ver,
tok2str(rpki_rtr_pdu_values, "Unknown", pdu_type),
pdu_type, pdu_len);
if (pdu_len < sizeof(rpki_rtr_pdu) || pdu_len > len)
case RPKI_RTR_END_OF_DATA_PDU:
if (pdu_len != sizeof(rpki_rtr_pdu) + 4)
goto invalid;
- ND_TCHECK_LEN(tptr, pdu_len);
msg = (const u_char *)(pdu_header + 1);
ND_PRINT("%sSession ID: 0x%04x, Serial: %u",
indent_string(indent+2),
{
const rpki_rtr_pdu_ipv4_prefix *pdu;
- if (pdu_len != sizeof(rpki_rtr_pdu) + 12)
+ if (pdu_len != sizeof(rpki_rtr_pdu_ipv4_prefix))
goto invalid;
- ND_TCHECK_LEN(tptr, pdu_len);
pdu = (const rpki_rtr_pdu_ipv4_prefix *)tptr;
ND_PRINT("%sIPv4 Prefix %s/%u-%u, origin-as %u, flags 0x%02x",
indent_string(indent+2),
{
const rpki_rtr_pdu_ipv6_prefix *pdu;
- if (pdu_len != sizeof(rpki_rtr_pdu) + 24)
+ if (pdu_len != sizeof(rpki_rtr_pdu_ipv6_prefix))
goto invalid;
- ND_TCHECK_LEN(tptr, pdu_len);
pdu = (const rpki_rtr_pdu_ipv6_prefix *)tptr;
ND_PRINT("%sIPv6 Prefix %s/%u-%u, origin-as %u, flags 0x%02x",
indent_string(indent+2),
/* Do not test for the "Length of Error Text" data element yet. */
if (pdu_len < tlen + 4)
goto invalid;
- ND_TCHECK_LEN(tptr, tlen + 4);
- /* Safe up to and including the "Length of Encapsulated PDU"
- * data element, more data elements may be present.
- */
pdu = (const rpki_rtr_pdu_error_report *)tptr;
encapsulated_pdu_length = GET_BE_U_4(pdu->encapsulated_pdu_length);
tlen += 4;
+ /* Safe up to and including the "Length of Encapsulated PDU"
+ * data element, more data elements may be present.
+ */
error_code = GET_BE_U_2(pdu->pdu_header.u.error_code);
ND_PRINT("%sError code: %s (%u), Encapsulated PDU length: %u",
if (pdu_len < tlen + 4)
goto invalid;
- ND_TCHECK_LEN(tptr, tlen + 4);
- /* Safe up to and including the "Length of Error Text" data element,
- * one more data element may be present.
- */
-
/*
* Extract, trail-zero and print the Error message.
*/
text_length = GET_BE_U_4(tptr + tlen);
tlen += 4;
+ /* Safe up to and including the "Length of Error Text" data element,
+ * one more data element may be present.
+ */
if (text_length) {
if (pdu_len < tlen + text_length)
goto invalid;
- /* nd_printn() makes the bounds check */
ND_PRINT("%sError text: ", indent_string(indent+2));
- if (nd_printn(ndo, tptr + tlen, text_length, ndo->ndo_snapend))
- goto trunc;
+ nd_printjn(ndo, tptr + tlen, text_length);
}
}
break;
nd_print_invalid(ndo);
ND_TCHECK_LEN(tptr, len);
return len;
-trunc:
- nd_print_trunc(ndo);
- return len;
}
void