diff --git a/include/haproxy/quic_tp-t.h b/include/haproxy/quic_tp-t.h index 8ca69c7319..cc0669b2d1 100644 --- a/include/haproxy/quic_tp-t.h +++ b/include/haproxy/quic_tp-t.h @@ -6,6 +6,7 @@ #endif #include +#include #define QUIC_STATELESS_RESET_TOKEN_LEN 16 @@ -20,8 +21,8 @@ struct tp_cid { struct tp_preferred_address { uint16_t ipv4_port; uint16_t ipv6_port; - uint8_t ipv4_addr[4]; - uint8_t ipv6_addr[16]; + struct in_addr ipv4_addr; + struct in6_addr ipv6_addr; struct tp_cid cid; uint8_t stateless_reset_token[QUIC_STATELESS_RESET_TOKEN_LEN]; }; diff --git a/include/haproxy/quic_tp.h b/include/haproxy/quic_tp.h index af822641a3..d3bdd18c9d 100644 --- a/include/haproxy/quic_tp.h +++ b/include/haproxy/quic_tp.h @@ -84,8 +84,7 @@ static inline void quic_transport_params_dump(struct buffer *b, chunk_appendf(b, " ms_bidi=%llu", (ull)p->initial_max_streams_bidi); chunk_appendf(b, " ms_uni=%llu\n", (ull)p->initial_max_streams_uni); - if (p->disable_active_migration || p->with_stateless_reset_token || - p->with_preferred_address) { + if (p->disable_active_migration || p->with_stateless_reset_token) { int prev = 0; chunk_appendf(b, " ("); @@ -101,15 +100,23 @@ static inline void quic_transport_params_dump(struct buffer *b, prev = 1; chunk_appendf(b, "stless_rst_tok"); } - if (p->with_preferred_address) { - if (prev) - chunk_appendf(b, ","); - prev = 1; - chunk_appendf(b, "pref_addr"); - } chunk_appendf(b, ")"); } + if (p->with_preferred_address) { + char bufaddr[INET6_ADDRSTRLEN]; + chunk_appendf(b, " pref_addr="); + inet_ntop(AF_INET, &p->preferred_address.ipv4_addr, + bufaddr, sizeof(bufaddr)); + chunk_appendf(b, "%s:%hu ", bufaddr, p->preferred_address.ipv4_port); + + inet_ntop(AF_INET6, &p->preferred_address.ipv6_addr, + bufaddr, sizeof(bufaddr)); + chunk_appendf(b, "[%s]:%hu ", bufaddr, p->preferred_address.ipv6_port); + quic_tp_cid_dump(b, &p->preferred_address.cid); + chunk_appendf(b, "\n"); + } + quic_tp_version_info_dump(b, &p->version_information, local); } diff --git a/src/quic_tp.c b/src/quic_tp.c index eea8a31ddc..caf48ceb94 100644 --- a/src/quic_tp.c +++ b/src/quic_tp.c @@ -80,10 +80,7 @@ void quic_transport_params_init(struct quic_transport_params *p, int server) } /* Encode preferred address transport parameter in without its - * "type+len" prefix. Note that the IP addresses must be encoded in network byte - * order. - * So ->ipv4_addr and ->ipv6_addr, which are buffers, must contained values - * already encoded in network byte order. + * "type+len" prefix. * It is the responsibility of the caller to check there is enough room in to encode * this address. * Never fails. @@ -95,14 +92,14 @@ static void quic_transport_param_enc_pref_addr_val(unsigned char **buf, write_n16(*buf, addr->ipv4_port); *buf += sizeof addr->ipv4_port; - memcpy(*buf, addr->ipv4_addr, sizeof addr->ipv4_addr); - *buf += sizeof addr->ipv4_addr; + memcpy(*buf, (uint8_t *)&addr->ipv4_addr.s_addr, sizeof(addr->ipv4_addr.s_addr)); + *buf += sizeof(addr->ipv4_addr.s_addr); write_n16(*buf, addr->ipv6_port); *buf += sizeof addr->ipv6_port; - memcpy(*buf, addr->ipv6_addr, sizeof addr->ipv6_addr); - *buf += sizeof addr->ipv6_addr; + memcpy(*buf, addr->ipv6_addr.s6_addr, sizeof(addr->ipv6_addr.s6_addr)); + *buf += sizeof(addr->ipv6_addr.s6_addr); *(*buf)++ = addr->cid.len; if (addr->cid.len) { @@ -123,21 +120,21 @@ static int quic_transport_param_dec_pref_addr(struct tp_preferred_address *addr, { ssize_t addr_len; - addr_len = sizeof addr->ipv4_port + sizeof addr->ipv4_addr; - addr_len += sizeof addr->ipv6_port + sizeof addr->ipv6_addr; - addr_len += sizeof addr->cid.len; + addr_len = sizeof(addr->ipv4_port) + sizeof(addr->ipv4_addr.s_addr); + addr_len += sizeof(addr->ipv6_port) + sizeof(addr->ipv6_addr.s6_addr); + addr_len += sizeof(addr->cid.len); if (end - *buf < addr_len) return 0; - memcpy(addr->ipv4_addr, *buf, sizeof addr->ipv4_addr); - *buf += sizeof addr->ipv4_addr; + memcpy((uint8_t *)&addr->ipv4_addr.s_addr, *buf, sizeof(addr->ipv4_addr.s_addr)); + *buf += sizeof(addr->ipv4_addr.s_addr); addr->ipv4_port = read_n16(*buf); *buf += sizeof addr->ipv4_port; - memcpy(addr->ipv6_addr, *buf, sizeof addr->ipv6_addr); - *buf += sizeof addr->ipv6_addr; + memcpy(addr->ipv6_addr.s6_addr, *buf, sizeof(addr->ipv6_addr.s6_addr)); + *buf += sizeof(addr->ipv6_addr.s6_addr); addr->ipv6_port = read_n16(*buf); *buf += sizeof addr->ipv6_port; @@ -394,9 +391,6 @@ static inline size_t sizeof_quic_cid(const struct tp_cid *cid) } /* Encode preferred address into . - * Note that the IP addresses must be encoded in network byte order. - * So ->ipv4_addr and ->ipv6_addr, which are buffers, must contained - * values already encoded in network byte order. * Returns 1 if succeeded, 0 if not. */ static int quic_transport_param_enc_pref_addr(unsigned char **buf, @@ -405,10 +399,10 @@ static int quic_transport_param_enc_pref_addr(unsigned char **buf, { uint64_t addr_len = 0; - addr_len += sizeof addr->ipv4_port + sizeof addr->ipv4_addr; - addr_len += sizeof addr->ipv6_port + sizeof addr->ipv6_addr; + addr_len += sizeof(addr->ipv4_port) + sizeof(addr->ipv4_addr.s_addr); + addr_len += sizeof(addr->ipv6_port) + sizeof(addr->ipv6_addr.s6_addr); addr_len += sizeof_quic_cid(&addr->cid); - addr_len += sizeof addr->stateless_reset_token; + addr_len += sizeof(addr->stateless_reset_token); if (!quic_transport_param_encode_type_len(buf, end, QUIC_TP_PREFERRED_ADDRESS, addr_len)) return 0;