[En-Nut-Discussion] Possible race condition in DHCP and DHCPKick
Ole Reinhardt
ole.reinhardt at embedded-it.de
Sat Feb 11 17:20:50 CET 2012
Hi Henrik,
I just looked into the code and for me it seems very likely that this
race condition can occur. The problem can occur, as the dhcp code often
first signals dhcpDone and waits then for a wake which might result in a
race condition.
But shouldn't we change the other places as well:
multiple times in NutDhcpClient()
...
NutEventBroadcast(&dhcpDone);
NutEventWait(&dhcpWake, NUT_WAIT_INFINITE);
...
To
... mutiple time:
NutEventBroadcastAsync(&dhcpDone);
NutEventWait(&dhcpWake, NUT_WAIT_INFINITE);
...
And another more complex situation:
else if (dhcpState == DHCPST_BOUND) {
retries = 0;
NutEventBroadcast(&dhcpDone);
if (dhcpConfig->dyn_renewalTime <= NutGetSeconds() -
leaseTime) {
dhcpState = DHCPST_RENEWING;
} else {
/* Calculate the remaining lease time and take a nap. */
napTime = dhcpConfig->dyn_renewalTime - (NutGetSeconds()
- leaseTime);
if (napTime > MAX_DHCP_NAPTIME) {
napTime = MAX_DHCP_NAPTIME;
}
NutEventWait(&dhcpWake, napTime * 1000UL);
}
}
to
else if (dhcpState == DHCPST_BOUND) {
uint32_t now = NutGetSeconds();
retries = 0;
NutEventBroadcastAsync(&dhcpDone);
if (dhcpConfig->dyn_renewalTime <= now - leaseTime) {
dhcpState = DHCPST_RENEWING;
} else {
/* Calculate the remaining lease time and take a nap. */
napTime = dhcpConfig->dyn_renewalTime - (now -
leaseTime);
if (napTime > MAX_DHCP_NAPTIME) {
napTime = MAX_DHCP_NAPTIME;
}
NutEventWait(&dhcpWake, napTime * 1000UL);
}
}
The above is more complex as NutGetSeconds also could result in a
context switch.
Regards,
Ole
--
Thermotemp GmbH, Embedded-IT
Embedded Hard-/ Software and Open Source Development,
Integration and Consulting
http://www.embedded-it.de
Geschäftsstelle Siegen - Steinstraße 67 - D-57072 Siegen -
tel +49 (0)271 5513597, +49 (0)271-73681 - fax +49 (0)271 736 97
Hauptsitz - Hademarscher Weg 7 - 13503 Berlin
Tel +49 (0)30 4315205 - Fax +49 (0)30 43665002
Geschäftsführer: Jörg Friedrichs, Ole Reinhardt
Handelsregister Berlin Charlottenburg HRB 45978 UstID DE 156329280
More information about the En-Nut-Discussion
mailing list