diff --git a/CHANGELOG b/CHANGELOG index 2d4e32af..4ea5aa75 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -238,6 +238,12 @@ HISTORY ++ Bug fixes: + 2007-06-28 Frédéric Bernon + * autoip.c: replace most of rand() calls by a macro LWIP_AUTOIP_RAND which compute + a "pseudo-random" value based on netif's MAC and some autoip fields. It's always + possible to define this macro in your own lwipopts.h to always use C library's + rand(). Note that autoip_create_rand_addr doesn't use this macro. + 2007-06-28 Frédéric Bernon * netifapi.h, netifapi.c, tcpip.h, tcpip.c: Update code to handle the option LWIP_TCPIP_CORE_LOCKING, and do some changes to be coherent with last modifications diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index c5aa5038..6aecc6ff 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -78,6 +78,11 @@ #error LWIP_ARP is need for LWIP_AUTOIP. Set it from your lwipopts.h. #endif /* !LWIP_ARP */ +/* pseudo random macro based on netif informations. You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h */ +#ifndef LWIP_AUTOIP_RAND +#define LWIP_AUTOIP_RAND(netif) ( (((u32_t)((netif->hwaddr[5]) & 0xff) << 24) | ((u32_t)((netif->hwaddr[3]) & 0xff) << 16) | ((u32_t)((netif->hwaddr[2]) & 0xff) << 8) | ((u32_t)((netif->hwaddr[4]) & 0xff))) + (netif->autoip?netif->autoip->tried_llipaddr:0)) +#endif /* LWIP_AUTOIP_RAND */ + /* static functions */ static void autoip_handle_arp_conflict(struct netif *netif); @@ -257,7 +262,7 @@ autoip_start(struct netif *netif) * choosen out of 0 to PROBE_WAIT seconds. * compliant to RFC 3927 Section 2.2.1 */ - autoip->ttw = (rand() % (PROBE_WAIT * AUTOIP_TICKS_PER_SECOND)); + autoip->ttw = (LWIP_AUTOIP_RAND(netif) % (PROBE_WAIT * AUTOIP_TICKS_PER_SECOND)); /* * if we tried more then MAX_CONFLICTS we must limit our rate for @@ -316,7 +321,7 @@ autoip_tmr() LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | 3, ("autoip_tmr() PROBING Sent Probe\n")); netif->autoip->sent_num++; /* calculate time to wait to next probe */ - netif->autoip->ttw = (rand() % ((PROBE_MAX - PROBE_MIN) * AUTOIP_TICKS_PER_SECOND) ) + PROBE_MIN * AUTOIP_TICKS_PER_SECOND; + netif->autoip->ttw = (LWIP_AUTOIP_RAND(netif) % ((PROBE_MAX - PROBE_MIN) * AUTOIP_TICKS_PER_SECOND) ) + PROBE_MIN * AUTOIP_TICKS_PER_SECOND; } } break;