diff options
Diffstat (limited to 'print-rpki-rtr.c')
-rw-r--r-- | print-rpki-rtr.c | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/print-rpki-rtr.c b/print-rpki-rtr.c index 34e2057b..77e29c78 100644 --- a/print-rpki-rtr.c +++ b/print-rpki-rtr.c @@ -12,24 +12,27 @@ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * - * support for the The RPKI/Router Protocol as RFC6810 - * * Original code by Hannes Gredler (hannes@juniper.net) */ -#define NETDISSECT_REWORKED +/* \summary: Resource Public Key Infrastructure (RPKI) to Router Protocol printer */ + +/* specification: RFC 6810 */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include <tcpdump-stdinc.h> +#include <netdissect-stdinc.h> #include <string.h> -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "addrtoname.h" +static const char tstr[] = "[|RPKI-RTR]"; + /* * RPKI/Router PDU header * @@ -168,14 +171,14 @@ indent_string (u_int indent) /* * Print a single PDU. */ -static void +static int rpki_rtr_pdu_print (netdissect_options *ndo, const u_char *tptr, u_int indent) { const rpki_rtr_pdu *pdu_header; u_int pdu_type, pdu_len, hexdump; const u_char *msg; - pdu_header = (rpki_rtr_pdu *)tptr; + pdu_header = (const rpki_rtr_pdu *)tptr; pdu_type = pdu_header->pdu_type; pdu_len = EXTRACT_32BITS(pdu_header->length); ND_TCHECK2(*tptr, pdu_len); @@ -221,9 +224,9 @@ rpki_rtr_pdu_print (netdissect_options *ndo, const u_char *tptr, u_int indent) case RPKI_RTR_IPV4_PREFIX_PDU: { - rpki_rtr_pdu_ipv4_prefix *pdu; + const rpki_rtr_pdu_ipv4_prefix *pdu; - pdu = (rpki_rtr_pdu_ipv4_prefix *)tptr; + pdu = (const rpki_rtr_pdu_ipv4_prefix *)tptr; ND_PRINT((ndo, "%sIPv4 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", indent_string(indent+2), ipaddr_string(ndo, pdu->prefix), @@ -232,12 +235,11 @@ rpki_rtr_pdu_print (netdissect_options *ndo, const u_char *tptr, u_int indent) } break; -#ifdef INET6 case RPKI_RTR_IPV6_PREFIX_PDU: { - rpki_rtr_pdu_ipv6_prefix *pdu; + const rpki_rtr_pdu_ipv6_prefix *pdu; - pdu = (rpki_rtr_pdu_ipv6_prefix *)tptr; + pdu = (const rpki_rtr_pdu_ipv6_prefix *)tptr; ND_PRINT((ndo, "%sIPv6 Prefix %s/%u-%u, origin-as %u, flags 0x%02x", indent_string(indent+2), ip6addr_string(ndo, pdu->prefix), @@ -245,14 +247,13 @@ rpki_rtr_pdu_print (netdissect_options *ndo, const u_char *tptr, u_int indent) EXTRACT_32BITS(pdu->as), pdu->flags)); } break; -#endif case RPKI_RTR_ERROR_REPORT_PDU: { - rpki_rtr_pdu_error_report *pdu; + const rpki_rtr_pdu_error_report *pdu; u_int encapsulated_pdu_length, text_length, tlen, error_code; - pdu = (rpki_rtr_pdu_error_report *)tptr; + pdu = (const rpki_rtr_pdu_error_report *)tptr; encapsulated_pdu_length = EXTRACT_32BITS(pdu->encapsulated_pdu_length); ND_TCHECK2(*tptr, encapsulated_pdu_length); tlen = pdu_len; @@ -272,7 +273,8 @@ rpki_rtr_pdu_print (netdissect_options *ndo, const u_char *tptr, u_int indent) if (encapsulated_pdu_length && (encapsulated_pdu_length <= tlen)) { ND_PRINT((ndo, "%s-----encapsulated PDU-----", indent_string(indent+4))); - rpki_rtr_pdu_print(ndo, tptr, indent+2); + if (rpki_rtr_pdu_print(ndo, tptr, indent+2)) + goto trunc; } tptr += encapsulated_pdu_length; @@ -290,7 +292,8 @@ rpki_rtr_pdu_print (netdissect_options *ndo, const u_char *tptr, u_int indent) ND_TCHECK2(*tptr, text_length); if (text_length && (text_length <= tlen )) { ND_PRINT((ndo, "%sError text: ", indent_string(indent+2))); - fn_printn(ndo, tptr, text_length, ndo->ndo_snapend); + if (fn_printn(ndo, tptr, text_length, ndo->ndo_snapend)) + goto trunc; } } break; @@ -307,11 +310,10 @@ rpki_rtr_pdu_print (netdissect_options *ndo, const u_char *tptr, u_int indent) if (ndo->ndo_vflag > 1 || (ndo->ndo_vflag && hexdump)) { print_unknown_data(ndo,tptr,"\n\t ", pdu_len); } - return; + return 0; - trunc: - ND_PRINT((ndo, "|trunc")); - return; +trunc: + return 1; } void @@ -333,7 +335,7 @@ rpki_rtr_print(netdissect_options *ndo, register const u_char *pptr, register u_ ND_TCHECK2(*tptr, sizeof(rpki_rtr_pdu)); - pdu_header = (rpki_rtr_pdu *)tptr; + pdu_header = (const rpki_rtr_pdu *)tptr; pdu_type = pdu_header->pdu_type; pdu_len = EXTRACT_32BITS(pdu_header->length); ND_TCHECK2(*tptr, pdu_len); @@ -350,14 +352,15 @@ rpki_rtr_print(netdissect_options *ndo, register const u_char *pptr, register u_ /* * Print the PDU. */ - rpki_rtr_pdu_print(ndo, tptr, 8); + if (rpki_rtr_pdu_print(ndo, tptr, 8)) + goto trunc; tlen -= pdu_len; tptr += pdu_len; } return; - trunc: - ND_PRINT((ndo, "\n\t[|RPKI-RTR]")); +trunc: + ND_PRINT((ndo, "\n\t%s", tstr)); } /* |