[En-Nut-Discussion] Improvement of DHCP code
bon at elektron.ikp.physik.tu-darmstadt.de
bon at elektron.ikp.physik.tu-darmstadt.de
Fri Nov 22 11:56:38 CET 2019
wiegelj writes:
> Hi folks,
>
> I don't know if attachments are working in the mailing list, but I want
> to share an improved version of the dhcp software in the attachement. It
> is derived from the ethernut-5.1.0-1 version and has an additional fix
> from Henrik (Thank you for this).
>
> I hope that someone is checking in the source. I spent a lot of time
> looking for problems in the dhcp code.
>
Hello Joerg,
as you know, I work on ethernut head and do few work on ethernet. I am
willing to apply fixes to the 5.1 branch, but a fix to the old branch
with no comment if the problem is still present on head make me
uneager.
Did you try head at all? Does it show the problem too? What is keeping
you from using head?
B.t.w, do you know the diff tool? Fixes are better distributed as
diff!
Diffing you changed file against dhcpc.c from the 5.1 branch shows:
--- dhcpc.c 2019-11-22 11:43:51.943002537 +0100
+++ /tmp/pro.c 2019-11-22 11:42:27.480599358 +0100
@@ -1631,9 +1631,7 @@
}
}
-#ifdef NUTDEBUG
-// DhcpStateDebug( 1, dhcpState, last_ip, leaseTime, retries);
-#endif
+
/*
* Broadcast discover and collect incoming offers.
*/
@@ -1703,6 +1701,8 @@
}
}
+
+
/*
* Send request and wait for an acknowledge.
*/
@@ -1789,7 +1789,7 @@
*/
else if (dhcpState == DHCPST_BOUND) {
retries = 0;
- NutEventBroadcast(&dhcpDone);
+ NutEventBroadcastAsync(&dhcpDone); // Async wg. Racecondition
if (dhcpConfig->dyn_renewalTime <= NutGetSeconds() - leaseTime) {
dhcpState = DHCPST_RENEWING;
} else {
@@ -1948,10 +1948,20 @@
ReleaseDynCfg(dhcpConfig);
dhcpConfig = 0;
retries = 0;
- NutEventBroadcast(&dhcpDone);
- NutEventWait(&dhcpWake, NUT_WAIT_INFINITE);
+ NutEventBroadcastAsync(&dhcpDone); // Async wg. Racedondition
+ // if we have a device
+ if(dhcpDev!=0)
+ {
+ NutIpRouteDelAll(dhcpDev); // delete all routes, because they are needing Heap memory and this has to bee freed.
}
+
+
+ NutEventWait(&dhcpWake, NUT_WAIT_INFINITE);
+ }
+#ifdef NUTDEBUG
+ DhcpStateDebug( 1, dhcpState, last_ip, leaseTime, retries);
+#endif
/* Release any received reply. */
if (reply) {
ReleaseDynCfg(reply);
@@ -2000,7 +2010,7 @@
dhcpThread = NutThreadCreate("dhcpc", NutDhcpClient, dev,
(NUT_THREAD_DHCPSTACK * NUT_THREAD_STACK_MULT) + NUT_THREAD_STACK_ADD);
}
- NutEventPost(&dhcpWake);
+ NutEventPostAsync(&dhcpWake); // Error race condition
NutEventWait(&dhcpDone, NUT_WAIT_INFINITE);
return 0;
As you see, there is unrelated whitespace change, a change in comment
style, change in indent style and non-english comments ("wg."). I can
adapt myself, but would like you to do that. Will you do? And please,
comment on the behaviour of head.
Thanks
--
Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
More information about the En-Nut-Discussion
mailing list