#943934 ifupdown-wait-online.service is useless with dhcp and dhclient

Package:
ifupdown
Source:
ifupdown
Description:
high level tools to configure network interfaces
Submitter:
"Alexander E. Patrakov"
Date:
2025-01-23 12:15:02 UTC
Severity:
normal
#943934#5
Date:
2019-11-01 04:50:17 UTC
From:
To:
Dear Maintainer,

I was trying to configure a service that needs networking to be completely
configured when it starts, with addresses and the default route. To achieve
that, I made it depend on network-online.target, and enabled
ifupdown-wait-online.service. However, after the reboot, the service was
still started before dhclient assigned the IP address to the interface.

To debug this issue, I have modified /lib/ifupdown/wait-online.sh, added a
"set -x" at the top and "/sbin/ifquery --state" at the very bottom. Result:

(This is with the "auto" workaround applied, but still shows the underlying
issue that "ifquery" considers an interface with an incomplete DHCP
transaction to be up)

Nov 01 09:14:06 wait-online.sh[234]: + WAIT_ONLINE_METHOD=ifup
Nov 01 09:14:06 wait-online.sh[234]: + WAIT_ONLINE_IFACE=
Nov 01 09:14:06 wait-online.sh[234]: + WAIT_ONLINE_ADDRESS=
Nov 01 09:14:06 wait-online.sh[234]: + WAIT_ONLINE_TIMEOUT=300
Nov 01 09:14:06 wait-online.sh[234]: + [ -f /etc/default/networking ]
Nov 01 09:14:06 wait-online.sh[234]: + . /etc/default/networking
Nov 01 09:14:06 wait-online.sh[234]: + up=false
Nov 01 09:14:06 wait-online.sh[234]: + [ -z  ]
Nov 01 09:14:06 wait-online.sh[234]: + /sbin/ifquery -X lo --list
Nov 01 09:14:06 wait-online.sh[234]: + auto_list=enp0s3
Nov 01 09:14:06 wait-online.sh[234]: + /sbin/ifquery -X lo --allow=hotplug --list
Nov 01 09:14:06 wait-online.sh[234]: + hotplug_list=
Nov 01 09:14:06 wait-online.sh[234]: + [ -n enp0s3 ]
Nov 01 09:14:06 wait-online.sh[234]: + seq 1 300
Nov 01 09:14:06 systemd[1]: Started Create Static Device Nodes in /dev.
Nov 01 09:14:06 wait-online.sh[234]: + up=true
Nov 01 09:14:06 wait-online.sh[234]: + /sbin/ifquery --state enp0s3
Nov 01 09:14:06 wait-online.sh[234]: + up=false
Nov 01 09:14:06 wait-online.sh[234]: + break
Nov 01 09:14:06 wait-online.sh[234]: + [ false = true ]
Nov 01 09:14:06 wait-online.sh[234]: + sleep 1
.....
Nov 01 09:14:06 systemd[1]: Started Helper to synchronize boot up for ifupdown.
Nov 01 09:14:06 systemd[1]: Starting Raise network interfaces...
.....
Nov 01 09:14:06 dhclient[405]: Internet Systems Consortium DHCP Client 4.4.1
Nov 01 09:14:06 ifup[382]: Internet Systems Consortium DHCP Client 4.4.1
Nov 01 09:14:06 dhclient[405]: Copyright 2004-2018 Internet Systems Consortium.
Nov 01 09:14:06 ifup[382]: Copyright 2004-2018 Internet Systems Consortium.
Nov 01 09:14:06 dhclient[405]: All rights reserved.
Nov 01 09:14:06 ifup[382]: All rights reserved.
Nov 01 09:14:06 dhclient[405]: For info, please visit https://www.isc.org/software/dhcp/
Nov 01 09:14:06 ifup[382]: For info, please visit https://www.isc.org/software/dhcp/
Nov 01 09:14:06 dhclient[405]:
Nov 01 09:14:06 dhclient[405]: Listening on LPF/enp0s3/52:54:00:4a:f5:1f
Nov 01 09:14:06 ifup[382]: Listening on LPF/enp0s3/52:54:00:4a:f5:1f
Nov 01 09:14:06 ifup[382]: Sending on   LPF/enp0s3/52:54:00:4a:f5:1f
Nov 01 09:14:06 ifup[382]: Sending on   Socket/fallback
Nov 01 09:14:06 ifup[382]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 7
Nov 01 09:14:06 dhclient[405]: Sending on   LPF/enp0s3/52:54:00:4a:f5:1f
Nov 01 09:14:06 dhclient[405]: Sending on   Socket/fallback
Nov 01 09:14:06 dhclient[405]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 7
Nov 01 09:14:07 wait-online.sh[234]: + up=true
Nov 01 09:14:07 wait-online.sh[234]: + /sbin/ifquery --state enp0s3
Nov 01 09:14:07 wait-online.sh[234]: + [ true = true ]
Nov 01 09:14:07 wait-online.sh[234]: + break
Nov 01 09:14:07 wait-online.sh[234]: + [ true = true ]
Nov 01 09:14:07 wait-online.sh[234]: + /sbin/ifquery --state
Nov 01 09:14:07 wait-online.sh[234]: enp0s3=enp0s3
Nov 01 09:14:07 wait-online.sh[234]: lo=lo
Nov 01 09:14:07 systemd[1]: Started Wait for network to be configured by ifupdown.

^^^^^ see this? At this point ifquery thinks that the interface is up,
vvvvv but it will actually be configured only 2 seconds later!

Nov 01 09:14:09 dhclient[405]: DHCPOFFER of 192.168.0.241 from 192.168.0.1
Nov 01 09:14:09 ifup[382]: DHCPOFFER of 192.168.0.241 from 192.168.0.1
Nov 01 09:14:09 ifup[382]: DHCPREQUEST for 192.168.0.241 on enp0s3 to 255.255.255.255 port 67
Nov 01 09:14:09 dhclient[405]: DHCPREQUEST for 192.168.0.241 on enp0s3 to 255.255.255.255 port 67
Nov 01 09:14:09 dhclient[405]: DHCPACK of 192.168.0.241 from 192.168.0.1
Nov 01 09:14:09 ifup[382]: DHCPACK of 192.168.0.241 from 192.168.0.1
Nov 01 09:14:09 dhclient[405]: bound to 192.168.0.241 -- renewal in 18440 seconds.
Nov 01 09:14:09 ifup[382]: bound to 192.168.0.241 -- renewal in 18440 seconds.
Nov 01 09:14:09 systemd[1]: Started Raise network interfaces.

I have changed "allow-hotplug" to "auto" in /etc/network/interfaces as a
workaround, so that ifup itself waits, as evidenced by the last line in the
log. But then, what's the point of the wait-online.sh script with the default
settings in /etc/default/networking?

It may be relevant that in my network IPv6 with SLAAC also exists, maybe
that's why ifquery sees the interface as up even though the DHCP transaction
is not yet complete.
--- /etc/network/interfaces.d/*:
cat: '/etc/network/interfaces.d/*': No such file or directory
--- up and down scripts installed: /etc/network/if-down.d: total 4 -rwxr-xr-x 1 root root 289 Jun 21 14:24 bind9 /etc/network/if-post-down.d: total 0 /etc/network/if-pre-up.d: total 0 /etc/network/if-up.d: total 4 -rwxr-xr-x 1 root root 289 Jun 21 14:24 bind9
#943934#10
Date:
2019-11-01 07:11:33 UTC
From:
To:
[...]

Indeed, that sounds like a bug. It should have waited for ifup to finish
bringing the interface up.

As a workaround, you can tell wait-online.sh to wait for a route to a
given address to become available. Edit /etc/default/networking, set
WAIT_ONLINE_METHOD to route, and WAIT_ONLINE_ADDRESS to the address you
want to wait for to become reachable.

#943934#15
Date:
2025-01-23 12:10:00 UTC
From:
To:
0.8.41 still seems to have this issue.

Additionally /lib/ifupdown/wait-online.sh should differentiate
route/route6 like it does with ping/ping6. The generic
WAIT_ONLINE_METHOD route now stalls if ipv6 is not configured because it
calls both "ip -4 r s" and "ip -6 r s".

On an ipv4 only network WAIT_ONLINE_METHOD ping currently seems the only
working option to have the ifupdown-wait-online service do what it
should do.