Browse Source

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>
pull/89675/head
Robert Lubos 2 months ago committed by Benjamin Cabé
parent
commit
1c46508c54
  1. 13
      tests/net/dhcpv4/client/src/main.c

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

@ -234,6 +234,9 @@ struct dhcp_msg { @@ -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) @@ -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) @@ -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) @@ -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 */

Loading…
Cancel
Save