0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-04-20 22:14:38 +00:00

RPKI: refactored pdu to host byte order conversion

We shouldn't convert bytes 2 and 3 of the PDU blindly, there are several
cases where these are used by bytes. Instead, the conversion is done
only where needed.

This fixes misinterpretation bug of ASPA PDU flags on little endian
architectures.
This commit is contained in:
Maria Matejka 2024-11-28 14:10:40 +01:00
parent 54499f8850
commit 3ca6e03db7

@ -306,26 +306,22 @@ rpki_pdu_to_network_byte_order(struct pdu_header *pdu)
static void
rpki_pdu_to_host_byte_order(struct pdu_header *pdu)
{
/* The Router Key PDU has two one-byte fields instead of one two-bytes field. */
if (pdu->type != ROUTER_KEY)
pdu->reserved = ntohs(pdu->reserved);
pdu->len = ntohl(pdu->len);
switch (pdu->type)
{
case SERIAL_NOTIFY:
{
/* Note that a session_id is converted using converting header->reserved */
struct pdu_serial_notify *sn_pdu = (void *) pdu;
sn_pdu->session_id = ntohs(sn_pdu->session_id);
sn_pdu->serial_num = ntohl(sn_pdu->serial_num);
break;
}
case END_OF_DATA:
{
/* Note that a session_id is converted using converting header->reserved */
struct pdu_end_of_data_v0 *eod0 = (void *) pdu;
eod0->session_id = ntohs(eod0->session_id);
eod0->serial_num = ntohl(eod0->serial_num); /* Same either for version 1 */
if (pdu->ver > RPKI_VERSION_0)
@ -356,8 +352,8 @@ rpki_pdu_to_host_byte_order(struct pdu_header *pdu)
case ERROR:
{
/* Note that a error_code is converted using converting header->reserved */
struct pdu_error *err = (void *) pdu;
err->error_code = ntohs(err->error_code);
err->len_enc_pdu = ntohl(err->len_enc_pdu);
u32 *err_text_len = (u32 *)(err->rest + err->len_enc_pdu);
*err_text_len = htonl(*err_text_len);
@ -388,8 +384,14 @@ rpki_pdu_to_host_byte_order(struct pdu_header *pdu)
* We don't care here. */
case CACHE_RESPONSE:
{
struct pdu_cache_response *cr = (void *) pdu;
cr->session_id = ntohs(cr->session_id);
break;
}
case CACHE_RESET:
/* Converted with pdu->reserved */
/* Nothing to convert */
break;
}
}