From e27d34d1186c47ebabfa04c0cd45536e2a8bc873 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Sat, 3 Sep 2011 22:27:06 +0200 Subject: [PATCH] DHCP uses LWIP_RAND() for xid's (bug #30302) --- CHANGELOG | 3 +++ src/core/dhcp.c | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 8af059e9..5c6875dd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,9 @@ HISTORY ++ New features: + 2011-09-03: Simon Goldschmidt + * dhcp.c: DHCP uses LWIP_RAND() for xid's (bug #30302) + 2011-08-24: Simon Goldschmidt * opt.h, netif.h/.c: added netif remove callback (bug #32397) diff --git a/src/core/dhcp.c b/src/core/dhcp.c index 644290b9..f224587b 100644 --- a/src/core/dhcp.c +++ b/src/core/dhcp.c @@ -83,6 +83,13 @@ #include +/** DHCP_CREATE_RAND_XID: if this is set to 1, the xid is created using + * LWIP_RAND() (this overrides DHCP_GLOBAL_XID) + */ +#ifndef DHCP_CREATE_RAND_XID +#define DHCP_CREATE_RAND_XID 1 +#endif + /** Default for DHCP_GLOBAL_XID is 0xABCD0000 * This can be changed by defining DHCP_GLOBAL_XID and DHCP_GLOBAL_XID_HEADER, e.g. * #define DHCP_GLOBAL_XID_HEADER "stdlib.h" @@ -1623,7 +1630,11 @@ dhcp_create_msg(struct netif *netif, struct dhcp *dhcp, u8_t message_type) * with a packet analyser). We simply increment for each new request. * Predefine DHCP_GLOBAL_XID to a better value or a function call to generate one * at runtime, any supporting function prototypes can be defined in DHCP_GLOBAL_XID_HEADER */ +#if DHCP_CREATE_RAND_XID && defined(LWIP_RAND) + static u32_t xid; +#else /* DHCP_CREATE_RAND_XID && defined(LWIP_RAND) */ static u32_t xid = 0xABCD0000; +#endif /* DHCP_CREATE_RAND_XID && defined(LWIP_RAND) */ #else if (!xid_initialised) { xid = DHCP_GLOBAL_XID; @@ -1645,7 +1656,11 @@ dhcp_create_msg(struct netif *netif, struct dhcp *dhcp, u8_t message_type) /* reuse transaction identifier in retransmissions */ if (dhcp->tries == 0) { - xid++; +#if DHCP_CREATE_RAND_XID && defined(LWIP_RAND) + xid = LWIP_RAND(); +#else /* DHCP_CREATE_RAND_XID && defined(LWIP_RAND) */ + xid++; +#endif /* DHCP_CREATE_RAND_XID && defined(LWIP_RAND) */ } dhcp->xid = xid; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,