[klibc] Timeout values (-t) not always guaranteed

Khaled Elmously khalid.elmously at canonical.com
Thu Dec 2 11:49:13 PST 2021


Hello,

I have encountered situations where ipconfig takes longer than the user-specified timeout.

The following is an easy way to reproduce the issue:

# ip link add eth3 type dummy
# date; /usr/lib/klibc/bin/ipconfig -t 2 eth3; date
Thu Dec  2 14:26:15 EST 2021
IP-Config: eth3 hardware address aa:8f:6f:bf:35:96 mtu 1500 DHCP RARP
IP-Config: no response after 2 secs - giving up
Thu Dec  2 14:26:25 EST 2021



Notice that 'ipconfig' thinks it waited 2 seconds (which is the timeout value I specified), but in reality it waited 10 seconds as the
'date' values show.

This seems to happen because of the "try again in 10 seconds" that happens when ipconfig encounters an error on send.

I believe that a fix such as the following is needed to avoid this issue:

diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index 5472d0f0..0969e9cb 100644
--- a/usr/kinit/ipconfig/main.c
+++ b/usr/kinit/ipconfig/main.c
@@ -477,6 +477,14 @@ static int loop(void)
                if (pending == 0 || (bringup_first && done))
                        break;

+               /* Compensate for already-lost time */
+               /* Make sure to never exceed user-specified timeouts */
+               gettimeofday(&now, NULL);
+               if (now.tv_sec + timeout > start + loop_timeout) {
+                       timeout = loop_timeout - (now.tv_sec - start);
+                       printf("Lowered timeout to match user request = (%d s) \n", timeout);
+               }
+
                timeout_ms = timeout * 1000;

                for (x = 0; x < 2; x++) {





Does that make sense? Any problems with this?
Thanks
Khaled


More information about the klibc mailing list