Commit 7074e6bc authored by Robert Lubos's avatar Robert Lubos Committed by Benjamin Cabé
Browse files

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: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
(cherry picked from commit 1c46508c)
parent fe49371b
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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;
		}

@@ -691,6 +700,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 */