From 6934ff024cc217dfd55aac8b21d6198d7013ed81 Mon Sep 17 00:00:00 2001 From: SherySheng Date: Thu, 7 Nov 2024 17:10:03 +0800 Subject: [PATCH] [pd] add pd daemon service to support the automation of dhcpcd PD management (#2360) The changes include: - PD daemon (dhcp6_pd_daemon.py) to monitor and react to PD state changes between running and stopped/disabled. - Creation of systemd service file (dhcp6_pd_daemon.service) for managing the daemon. - Update of _dhcpv6_pd_ref to support pd daemon installation and uninstallation This scripts essentially automate the process of setting up a machine as a dhcpcd pd reference device, handling prefix delegation. --- script/_dhcpv6_pd_ref | 104 +++++++++++++-- script/reference-device/dhcp6_pd_daemon.py | 143 +++++++++++++++++++++ script/reference-device/dhcpcd.enter-hook | 13 +- script/reference-device/dhcpcd.exit-hook | 11 +- 4 files changed, 251 insertions(+), 20 deletions(-) create mode 100755 script/reference-device/dhcp6_pd_daemon.py diff --git a/script/_dhcpv6_pd_ref b/script/_dhcpv6_pd_ref index b431ce625da..946c22c7400 100644 --- a/script/_dhcpv6_pd_ref +++ b/script/_dhcpv6_pd_ref @@ -30,15 +30,65 @@ # This script manipulates DHCPv6-PD-REF configuration. # -customise_dhcpcd_conf() +# TODO: set the upstream interface according to the environment variables of `script/setup`. +UPSTREAM_INTERFACE="eth0" + +DHCPCD_ENTER_HOOK="/etc/dhcpcd.enter-hook" +DHCPCD_EXIT_HOOK="/etc/dhcpcd.exit-hook" + +PD_DAEMON_DIR="/opt/pd-daemon" +PD_DAEMON_PATH="${PD_DAEMON_DIR}/dhcp6_pd_daemon.py" +PD_DAEMON_SERVICE_NAME="dhcp6_pd_daemon.service" +PD_DAEMON_SERVICE_PATH="/etc/systemd/system/${PD_DAEMON_SERVICE_NAME}" + +DHCP_CONFIG_PATH="/etc/dhcpcd.conf" +DHCP_CONFIG_ORIG_PATH="/etc/dhcpcd.conf.orig" +DHCP_CONFIG_PD_PATH="/etc/dhcpcd.conf.pd" +DHCP_CONFIG_NO_PD_PATH="/etc/dhcpcd.conf.no-pd" + +# Create dhcpcd configuration file with ipv6 prefix request. +create_dhcpcd_conf_pd() { - # This has to be run after script/_border_routing, and this will - # invalidate all changes to dhcpcd.conf made by script/_border_routing. - sudo tee /etc/dhcpcd.conf >/dev/null </dev/null </dev/null <