From 53c6d506cf1a3fbc8df0e298cf6b988c808fdbe5 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 31 Mar 2025 23:15:28 +0100 Subject: [PATCH] dhcp6c subscribe to ppp ifindex when the peer bounces ppp, s6 will restart the ppp process but not restart the dependent services (because the service isn't considered to have gone down) so the dependent services need to notice when the outputs from ppp have changed --- modules/dhcp6c/acquire-delegated-prefix.fnl | 1 + modules/dhcp6c/acquire-wan-address.fnl | 1 + modules/dhcp6c/client.nix | 30 ++++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/modules/dhcp6c/acquire-delegated-prefix.fnl b/modules/dhcp6c/acquire-delegated-prefix.fnl index f0744df5..8ff78926 100644 --- a/modules/dhcp6c/acquire-delegated-prefix.fnl +++ b/modules/dhcp6c/acquire-delegated-prefix.fnl @@ -25,6 +25,7 @@ (fn run [] (let [[state-directory lan-device] arg dir (svc.open state-directory)] + (update-prefixes lan-device [] (or (dir:output "prefix") []) system) (accumulate [addresses [] v (dir:events)] (update-prefixes lan-device addresses (or (v:output "prefix") []) system)))) diff --git a/modules/dhcp6c/acquire-wan-address.fnl b/modules/dhcp6c/acquire-wan-address.fnl index de6edaf6..b2c7e73d 100644 --- a/modules/dhcp6c/acquire-wan-address.fnl +++ b/modules/dhcp6c/acquire-wan-address.fnl @@ -25,6 +25,7 @@ (fn run [] (let [[state-directory wan-device] arg dir (svc.open state-directory)] + (update-addresses wan-device [] (or (dir:output "address") []) system) (accumulate [addresses [] v (dir:events)] (update-addresses wan-device addresses (or (v:output "address") []) system)))) diff --git a/modules/dhcp6c/client.nix b/modules/dhcp6c/client.nix index 77314f68..a2031f7c 100644 --- a/modules/dhcp6c/client.nix +++ b/modules/dhcp6c/client.nix @@ -2,19 +2,29 @@ liminix, odhcp6c, odhcp-script, + svc }: { interface }: let inherit (liminix.services) longrun; + inherit (liminix) outputRef; name = "dhcp6c.${interface.name}"; -in -longrun { - inherit name; - notification-fd = 10; - run = '' - export SERVICE_STATE=$SERVICE_OUTPUTS/${name} - ${odhcp6c}/bin/odhcp6c -s ${odhcp-script} -e -v -p /run/${name}.pid -P0 $(output ${interface} ifname) - ) - ''; - dependencies = [ interface ]; + service = + longrun { + inherit name; + notification-fd = 10; + run = '' + export SERVICE_STATE=$SERVICE_OUTPUTS/${name} + ifname=$(output ${interface} ifname) + test -n "$ifname" && ${odhcp6c}/bin/odhcp6c -s ${odhcp-script} -e -v -p /run/${name}.pid -P0 $ifname + ) + ''; + dependencies = [ interface ]; + }; +in svc.secrets.subscriber.build { + # if the ppp service gets restarted, the interface may be different and + # we will have to restart dhcp on the new one + watch = [ (outputRef interface "ifindex") ]; + action = "restart"; + inherit service; }