I’m trying to use NetworkManager-dispatcher to call ddclient on DHCP lease change.
However, when the 1st “dhcp4-change” action happens (upon activating a connection), all the DHCP environment variable are not set, despite that the lease is accepted. They are not set until the “up” action. What’s the reason for this?
Can I assume the subsequent “dhcp4-change” will have latest DHCP options unlike the 1st one? Or is this something to worry about? (Like the env vars are always lagging behind in “dhcp4-change”.)
I noticed the chrony NTP script includes “up”:
case "$action" in
up|dhcp4-change|dhcp6-change)
Below are logs:
/etc/NetworkManager/dispatcher.d/test.sh
#! /bin/bash
if [[ $2 == "up" || $2 == "dhcp4-change" ]]; then
echo "DHCP Addr: $DHCP4_IP_ADDRESS Action: $2 Addr: $IP4_ADDRESS_0"
fi
journalctl -u NetworkManager-dispatcher -f
shows address in each action:
nm-dispatcher[4477]: req:7 'dhcp4-change' [wlp1s0]: start running ordered scripts...
nm-dispatcher[7857]: DHCP Addr: Action: dhcp4-change Addr:
nm-dispatcher[4477]: req:9 'up' [wlp1s0]: start running ordered scripts...
nm-dispatcher[7875]: DHCP Addr: 111.222.333.444 Action: up Addr: 111.222.333.444/22 111.222.333.254
journalctl -u NetworkManager -f
(with logging level trace) shows that the lease has been present and accepted before “dhcp4-change” is dispatched:
NetworkManager[1692]: <info> [1734643555.1348] dhcp4 (wlp1s0): state changed new lease, address=111.222.333.444, acd pending
...
NetworkManager[1692]: <debug> [1734643555.1350] dhcp4 (wlp1s0): option ip_address => '111.222.333.444'
...
NetworkManager[1692]: <debug> [1734643555.2882] dhcp4 (wlp1s0): accept lease
NetworkManager[1692]: <trace> [1734643555.2883] dhcp4 (wlp1s0): accept
NetworkManager[1692]: <trace> [1734643555.2888] device[deef3778902ae932] (wlp1s0): ip:dhcp4: lease accepted
NetworkManager[1692]: <trace> [1734643555.2891] config: device-state: write #2 (/run/NetworkManager/devices/2); managed=managed, connection-uuid=48a58e83-b7d8-49ef-b265-0fdb8e11bd35, route-metric-default=600-600
NetworkManager[1692]: <debug> [1734643555.2891] dispatcher: (29) (wlp1s0) dispatching action 'dhcp4-change'
Yet the DHCP options environment variables are not set until the “up” action:
nm-dispatcher[4477]: req:7 'dhcp4-change' [wlp1s0]: new request (6 scripts)
nm-dispatcher[4477]: req:7 'dhcp4-change' [wlp1s0]: environment: NM_DISPATCHER_ACTION=dhcp4-change
...
nm-dispatcher[4477]: req:8 'pre-up' [wlp1s0]: new request (0 scripts)
nm-dispatcher[4477]: req:8 'pre-up' [wlp1s0]: environment: NM_DISPATCHER_ACTION=pre-up
...
nm-dispatcher[4477]: req:9 'up' [wlp1s0]: new request (6 scripts)
nm-dispatcher[4477]: req:9 'up' [wlp1s0]: environment: IP4_ADDRESS_0=111.222.333.444/22 111.222.333.254
nm-dispatcher[4477]: req:9 'up' [wlp1s0]: environment: DHCP4_IP_ADDRESS=111.222.333.444
nm-dispatcher[4477]: req:9 'up' [wlp1s0]: environment: DHCP4_NTP_SERVERS=111.222.333.254