Skip to content

Commit 1c46508

Browse files
rluboskartben
authored andcommitted
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 <robert.lubos@nordicsemi.no>
1 parent eabeb84 commit 1c46508

File tree

1 file changed

+13
-0
lines changed
  • tests/net/dhcpv4/client/src

1 file changed

+13
-0
lines changed

tests/net/dhcpv4/client/src/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ struct dhcp_msg {
234234
uint8_t type;
235235
};
236236

237+
static uint32_t offer_xid;
238+
static uint32_t request_xid;
239+
237240
static struct k_sem test_lock;
238241

239242
#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)
310313

311314
net_ipv4_finalize(pkt, IPPROTO_UDP);
312315

316+
offer_xid = xid;
317+
313318
return pkt;
314319

315320
fail:
@@ -396,6 +401,10 @@ static int parse_dhcp_message(struct net_pkt *pkt, struct dhcp_msg *msg)
396401
return 0;
397402
}
398403

404+
if (msg->type == NET_DHCPV4_MSG_TYPE_REQUEST) {
405+
request_xid = msg->xid;
406+
}
407+
399408
return 1;
400409
}
401410

@@ -693,6 +702,10 @@ ZTEST(dhcpv4_tests, test_dhcp)
693702
zassert_true(false, "Timeout while waiting");
694703
}
695704
}
705+
706+
/* Verify that Request xid matched Offer xid. */
707+
zassert_equal(offer_xid, request_xid, "Offer/Request xid mismatch, "
708+
"Offer 0x%08x, Request 0x%08x", offer_xid, request_xid);
696709
}
697710

698711
/**test case main entry */

0 commit comments

Comments
 (0)