From: Pavel TvrdĂ­k Date: Tue, 22 Dec 2015 15:51:21 +0000 (+0100) Subject: RPKI: refactore X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03f7edbd83b69aa2b2c0c008843499648e03f483;p=thirdparty%2Fbird.git RPKI: refactore Move out the translation a PDU header to host byte order to outside of PDU header correctness checking. --- diff --git a/proto/rpki/packets.c b/proto/rpki/packets.c index 9f00ee5fd..12785e331 100644 --- a/proto/rpki/packets.c +++ b/proto/rpki/packets.c @@ -486,9 +486,15 @@ static int rtr_send_pdu(struct rpki_cache *cache, const void *pdu, const unsigne return RTR_SUCCESS; } -/* +/** + * rtr_check_receive_packet - Make a basic validation of received RPKI PDU header: + * - check protocol version + * - check pdu type + * - check size + * + * @cache cache connection * @param len must <= RTR_MAX_PDU_LEN bytes - * @return RTR_SUCCESS, pdu is converted to host order byte + * @return RTR_SUCCESS * @return RTR_ERROR, error pdu was sent */ static int @@ -496,13 +502,6 @@ rtr_check_receive_packet(struct rpki_cache *cache, void *pdu, const size_t len) { struct rtr_socket *rtr_socket = cache->rtr_socket; struct rpki_proto *p = cache->p; - //error values: - // 0 = no_err - // 1 = internal error - // 2 = unknown pdu type - // 4 = pdu to big - // 8 = corrupt data - // 16 = unknown pdu version int error = RTR_SUCCESS; // header in hostbyte order, retain original received pdu, in case we need to detach it to an error pdu @@ -557,15 +556,11 @@ rtr_check_receive_packet(struct rpki_cache *cache, void *pdu, const size_t len) goto error; } - memcpy(pdu, &header, sizeof(header)); //copy header in host_byte_order to pdu - rtr_pdu_footer_to_host_byte_order(pdu); - if (header.type == IPV4_PREFIX || header.type == IPV6_PREFIX) { if (((struct pdu_ipv4 *) pdu)->zero != 0) CACHE_TRACE(D_PACKETS, cache, "Warning: Zero field of received Prefix PDU doesn't contain 0"); } - rpki_log_packet(cache, pdu, len, RPKI_RECV); return RTR_SUCCESS; error: @@ -834,6 +829,13 @@ rtr_handle_end_of_data_pdu(struct rpki_cache *cache, void *pdu) rtr_schedule_next_expire_check(cache); } +static void +rtr_transform_pdu_to_host_byte_order(byte *pdu) +{ + rtr_pdu_header_to_host_byte_order(pdu); + rtr_pdu_footer_to_host_byte_order(pdu); +} + static void rpki_rx_packet(struct rpki_cache *cache, byte *pdu, uint len) { @@ -847,7 +849,8 @@ rpki_rx_packet(struct rpki_cache *cache, byte *pdu, uint len) return; } - /* the pdu is in host order already */ + rtr_transform_pdu_to_host_byte_order(pdu); + rpki_log_packet(cache, pdu, len, RPKI_RECV); switch (type) {