From 1c46508c54b6eb7d9ea78e5b4b4e16284cfa53bc Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Tue, 6 May 2025 12:56:20 +0200 Subject: [PATCH] tests: net: dhcpv4: client: Verify Request xid According to RFC 2131 Request message Exchange ID should be the same as the one received in the Offer message from the server. Modify test to verify that. Signed-off-by: Robert Lubos --- tests/net/dhcpv4/client/src/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/net/dhcpv4/client/src/main.c b/tests/net/dhcpv4/client/src/main.c index 04e52b26585..654a98d2cbe 100644 --- a/tests/net/dhcpv4/client/src/main.c +++ b/tests/net/dhcpv4/client/src/main.c @@ -234,6 +234,9 @@ struct dhcp_msg { uint8_t type; }; +static uint32_t offer_xid; +static uint32_t request_xid; + static struct k_sem test_lock; #define WAIT_TIME K_SECONDS(CONFIG_NET_DHCPV4_INITIAL_DELAY_MAX + 1) @@ -310,6 +313,8 @@ struct net_pkt *prepare_dhcp_offer(struct net_if *iface, uint32_t xid) net_ipv4_finalize(pkt, IPPROTO_UDP); + offer_xid = xid; + return pkt; fail: @@ -396,6 +401,10 @@ static int parse_dhcp_message(struct net_pkt *pkt, struct dhcp_msg *msg) return 0; } + if (msg->type == NET_DHCPV4_MSG_TYPE_REQUEST) { + request_xid = msg->xid; + } + return 1; } @@ -693,6 +702,10 @@ ZTEST(dhcpv4_tests, test_dhcp) zassert_true(false, "Timeout while waiting"); } } + + /* Verify that Request xid matched Offer xid. */ + zassert_equal(offer_xid, request_xid, "Offer/Request xid mismatch, " + "Offer 0x%08x, Request 0x%08x", offer_xid, request_xid); } /**test case main entry */