net: lib: zperf: warning on bad response flags

Output a warning if the server response does not have the expected
header flag set.

Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
Jordan Yates 2025-04-17 14:39:22 +10:00 committed by Benjamin Cabé
commit 4582c64816
2 changed files with 10 additions and 0 deletions

View file

@ -64,6 +64,11 @@ struct zperf_udp_datagram {
BUILD_ASSERT(sizeof(struct zperf_udp_datagram) <= PACKET_SIZE_MAX, "Invalid PACKET_SIZE_MAX"); BUILD_ASSERT(sizeof(struct zperf_udp_datagram) <= PACKET_SIZE_MAX, "Invalid PACKET_SIZE_MAX");
#define ZPERF_FLAGS_VERSION1 0x80000000
#define ZPERF_FLAGS_EXTEND 0x40000000
#define ZPERF_FLAGS_UDPTESTS 0x20000000
#define ZPERF_FLAGS_SEQNO64B 0x08000000
struct zperf_client_hdr_v1 { struct zperf_client_hdr_v1 {
int32_t flags; int32_t flags;
int32_t num_of_threads; int32_t num_of_threads;

View file

@ -25,6 +25,7 @@ static inline void zperf_upload_decode_stat(const uint8_t *data,
struct zperf_results *results) struct zperf_results *results)
{ {
struct zperf_server_hdr *stat; struct zperf_server_hdr *stat;
uint32_t flags;
if (datalen < sizeof(struct zperf_udp_datagram) + if (datalen < sizeof(struct zperf_udp_datagram) +
sizeof(struct zperf_server_hdr)) { sizeof(struct zperf_server_hdr)) {
@ -33,6 +34,10 @@ static inline void zperf_upload_decode_stat(const uint8_t *data,
stat = (struct zperf_server_hdr *) stat = (struct zperf_server_hdr *)
(data + sizeof(struct zperf_udp_datagram)); (data + sizeof(struct zperf_udp_datagram));
flags = ntohl(UNALIGNED_GET(&stat->flags));
if (!(flags & ZPERF_FLAGS_VERSION1)) {
NET_WARN("Unexpected response flags");
}
results->nb_packets_rcvd = ntohl(UNALIGNED_GET(&stat->datagrams)); results->nb_packets_rcvd = ntohl(UNALIGNED_GET(&stat->datagrams));
results->nb_packets_lost = ntohl(UNALIGNED_GET(&stat->error_cnt)); results->nb_packets_lost = ntohl(UNALIGNED_GET(&stat->error_cnt));