From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.haj.ipfire.org (localhost [IPv6:::1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4j6QJD4cPSz2ymW for ; Sat, 17 Oct 2026 15:11:40 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [IPv6:2001:678:b28::25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1 raw public key) server-digest SHA384 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mail01.haj.ipfire.org", Issuer "YR1" (not verified)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4j6QJ90vM2z2yBs for ; Sat, 17 Oct 2026 15:11:37 +0000 (UTC) Received: from smtp.smtpout.orange.fr (smtp-21.smtpout.orange.fr [80.12.242.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "*.smtpout.orange.fr", Issuer "DigiCert Global G2 TLS RSA SHA256 2020 CA1" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4j6QJ74tjXz2VP for ; Sat, 17 Oct 2026 15:11:35 +0000 (UTC) Authentication-Results: mail01.ipfire.org; dkim=pass header.d=orange.fr header.s=t20230301 header.b=sSIzeZBx; dmarc=pass (policy=quarantine) header.from=orange.fr; spf=pass (mail01.ipfire.org: domain of p27m@orange.fr designates 80.12.242.21 as permitted sender) smtp.mailfrom=p27m@orange.fr ARC-Seal: i=1; a=rsa-sha256; d=lists.ipfire.org; s=202003rsa; cv=none; t=1792249895; b=GWo6gvd7B9WeIAR8pPfVMmdHa27JtScgNMy3SvnYWKJwoFaIKR/whrEW/PBFypckQeemI9 7d8sKd+IfgQ0F3lzt8la+cnEcH0UhMrDDoM2sxiYL571lzqjoLPU0VIRA9fTiWRFyf8biv MTrGP7mQaV0BUgavxqRxVe/BIPCOsjzVpGk5SeVf2U+6MEt3iEDXlGWp3umdqQRBUdtsIY 4s3fCpEIpqdwRWwBNiFwj6IxmLCGJYlPIFy8bcysbZvam2Q30RQfuaJUVbUGkbIh3WZSGe EkSgKv9HusG1yi1YJlAa/3VSrcPX0jrAlcmCsCbfFhDFDWwmXETpNm4s3/KKXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1792249895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:dkim-signature; bh=6lwuipAD1abJsE/vY1jcI4DBPK8sxbJ1ZSnK9+9InO0=; b=UsY3HqU2VdDWw9s2Kd5gVRxw1dNt9wSorkBLSubkE0qIJe1YANPY2tYH6LIQzUsNn3vuB/ eGYdgAp2ERruGH4s86TYsBu5FhdEp4JnKVn6ZRzvP7ZnpH7Aqd08ITnePCCh5jG7tbb6M6 5WIrnnAT07MlG2awWKp4SA/n4896U2YOyVTeE9nhwc8eLhmr3z79eJBwen8Zs17cNND3Ry 4J9ht1dyPB5ONNzGGo0O2Z/tjwFWE1b2xH75VRtTBwYuewbK8FEt/AB0Fkst7JAQ/E9M8Y qnTFXqSPvBYi0sjDnfLe7U7wcjp5wIIg7xKFjJ7kKEN2YLcT39u7brY/i+8iYg== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=orange.fr header.s=t20230301 header.b=sSIzeZBx; dmarc=pass (policy=quarantine) header.from=orange.fr; spf=pass (mail01.ipfire.org: domain of p27m@orange.fr designates 80.12.242.21 as permitted sender) smtp.mailfrom=p27m@orange.fr Received: from PCBUREAU.pshome ([176.146.212.228]) by smtp.orange.fr with ESMTPSA id I64BxHTSlRdnDI64Mxhmmr; Sat, 17 Oct 2026 17:11:34 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1792249894; bh=6lwuipAD1abJsE/vY1jcI4DBPK8sxbJ1ZSnK9+9InO0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=sSIzeZBxsKJXUWqSgF1qZBHM8ysj1Im689H1GpIKSJJ2ZeBrDs/Miwh9t1ZAzopOo vc17mfQ0cywkspyQerxNmSQjsZclpoPgWCkMNhfZWyN06Ebl3nOAMJjD72aaXU+fPq 9SB7Nlg3JUs8bRJoofsH8UGuFWsrCMXCdL09/8claIw8UvERHJD5uerdCBqL2gxEyy sPCI2YqwYvuZqB751R4LjUvWMVWtUM7hoWLtcGs3JEFI5wEqrU9KyFV01yfcVhygHg 70ry2L/LsnZgqwrpCHPpxht9tmZuITl396OIqb0IpFMgaKEMTxgx+5PYYVIuCjOz7s B+70riU3LIFWQ== X-ME-Helo: PCBUREAU.pshome X-ME-Auth: cDI3bUBvcmFuZ2UuZnI= X-ME-Date: Sat, 17 Oct 2026 17:11:34 +0200 X-ME-IP: 176.146.212.228 From: Philippe SCARSELLI To: development@lists.ipfire.org Cc: Philippe SCARSELLI Subject: [PATCH] dhcp: convert dhcpd.conf from CU202 to CU203 format Date: Sat, 17 Oct 2026 17:11:03 +0200 Message-ID: <20261017151103.1218-1-p27m@orange.fr> X-Mailer: git-send-email 2.47.3 Precedence: list List-Id: List-Subscribe: , List-Unsubscribe: , List-Post: List-Help: Sender: Mail-Followup-To: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4j6QJ74tjXz2VP X-Spamd-Result: default: False [-2.80 / 11.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[orange.fr,quarantine]; R_MISSING_CHARSET(0.50)[]; RWL_MAILSPIKE_EXCELLENT(-0.40)[80.12.242.21:from]; ONCE_RECEIVED(0.20)[]; R_SPF_ALLOW(-0.20)[+ip4:80.12.242.0/25]; R_DKIM_ALIGNED(-0.10)[strict]; MX_GOOD(-0.10)[smtp-in2.orange.fr]; R_DKIM_ALLOW(-0.10)[orange.fr:s=t20230301]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RECEIVED_SPAMHAUS_PBL(0.00)[176.146.212.228:received]; RCPT_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVFROM(0.00)[orange.fr]; FREEMAIL_FROM(0.00)[orange.fr]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; DKIM_TRACE(0.00)[orange.fr:+]; FROM_EQ_ENVFROM(0.00)[]; DWL_DNSWL_NONE(0.00)[orange.fr:dkim]; RCVD_COUNT_ONE(0.00)[1]; ASN(0.00)[asn:3215, ipnet:80.12.240.0/20, country:FR]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_REPUTATION(0.00)[0]; RCVD_IN_DNSWL_NONE(0.00)[80.12.242.21:from]; IP_REPUTATION_SPAM(0.00)[asn: 3215(0.00), country: FR(0.00), ip: 80.12.242.21(0.00)]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FREEMAIL_CC(0.00)[orange.fr]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Action: no action X-Rspamd-Server: mail01.haj.ipfire.org Related to bug Bug 14320 - DHCP configuration is not correctly migrated from CU202 to CU203 and more. here is a proposed fix This patch enables the automatic migration of the `/var/ipfire/dhcp/dhcpd.conf` file during an upgrade from CU202 to CU203, as well as when restoring a backup from CU202 or earlier onto a CU203 system. This ensures compliance with the `on commit`, `on release`, and `on expiry` commands required for local DNS management by `knot-resolver`. This patch was created on the core203 branch to regenerate the core-upgrade-2.29-203.ipfire package and the test CU203 ISO file. I am not familiar with the integration method for subsequent versions, but it will be useful for backup/restore operations when moving from versions prior to CU203 to CU203 or later. Tested on x86_64 platform (VMware). Upgrade from CU202 to CU203 tested. Restore test of a CU202 backup file onto a fresh CU203 installation on an x86_64 test platform (VMware). - The /var/ipfire/dhcp/dhcpd.conf file is in the expected format. - DNS management for DHCP leases is functioning correctly. Signed-off-by: Philippe SCARSELLI --- config/backup/backup.pl | 4 + config/rootfiles/common/aarch64/stage2 | 1 + config/rootfiles/common/riscv64/stage2 | 1 + config/rootfiles/common/x86_64/stage2 | 1 + config/rootfiles/core/203/filelists/files | 1 + config/rootfiles/core/203/update.sh | 4 +- src/scripts/convert-dhcp-conf | 165 ++++++++++++++++++++++ 7 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 src/scripts/convert-dhcp-conf diff --git a/config/backup/backup.pl b/config/backup/backup.pl index f948c4d21..7ac385ad9 100644 --- a/config/backup/backup.pl +++ b/config/backup/backup.pl @@ -213,6 +213,10 @@ restore_backup() { # Convert DNS settings convert-dns-settings + # Convert DHCP conf + convert-dhcp-conf + /etc/init.d/dhcp restart + # move nobeeps if exist [ -e "/var/ipfire/ppp/nobeeps" ] && mv /var/ipfire/ppp/nobeeps /var/ipfire/red/nobeeps diff --git a/config/rootfiles/common/aarch64/stage2 b/config/rootfiles/common/aarch64/stage2 index 4b79d96f6..a02c91c1d 100644 --- a/config/rootfiles/common/aarch64/stage2 +++ b/config/rootfiles/common/aarch64/stage2 @@ -92,6 +92,7 @@ usr/local/bin/backupiso usr/local/bin/connscheduler usr/local/bin/consort.sh usr/local/bin/convert-dns-settings +usr/local/bin/convert-dhcp-conf usr/local/bin/convert-to-location usr/local/bin/filesystem-cleanup usr/local/bin/hddshutdown diff --git a/config/rootfiles/common/riscv64/stage2 b/config/rootfiles/common/riscv64/stage2 index 9c3621f62..2d27af818 100644 --- a/config/rootfiles/common/riscv64/stage2 +++ b/config/rootfiles/common/riscv64/stage2 @@ -93,6 +93,7 @@ usr/local/bin/backupiso usr/local/bin/connscheduler usr/local/bin/consort.sh usr/local/bin/convert-dns-settings +usr/local/bin/convert-dhcp-conf usr/local/bin/convert-to-location usr/local/bin/filesystem-cleanup usr/local/bin/hddshutdown diff --git a/config/rootfiles/common/x86_64/stage2 b/config/rootfiles/common/x86_64/stage2 index e50df0494..b35aa15d0 100644 --- a/config/rootfiles/common/x86_64/stage2 +++ b/config/rootfiles/common/x86_64/stage2 @@ -92,6 +92,7 @@ usr/local/bin/backupiso usr/local/bin/connscheduler usr/local/bin/consort.sh usr/local/bin/convert-dns-settings +usr/local/bin/convert-dhcp-conf usr/local/bin/convert-to-location usr/local/bin/filesystem-cleanup usr/local/bin/hddshutdown diff --git a/config/rootfiles/core/203/filelists/files b/config/rootfiles/core/203/filelists/files index dd3435411..56dbf818f 100644 --- a/config/rootfiles/core/203/filelists/files +++ b/config/rootfiles/core/203/filelists/files @@ -16,6 +16,7 @@ etc/rc.d/rc0.d/K86knot-resolver etc/rc.d/rc3.d/S11knot-resolver etc/rc.d/rc3.d/S17waitfordns etc/rc.d/rc6.d/K86knot-resolver +usr/local/bin/convert-dhcp-conf usr/local/bin/settime usr/local/bin/update-rpzs usr/local/bin/waitfordns diff --git a/config/rootfiles/core/203/update.sh b/config/rootfiles/core/203/update.sh index 5b314664f..7447bef98 100644 --- a/config/rootfiles/core/203/update.sh +++ b/config/rootfiles/core/203/update.sh @@ -135,9 +135,7 @@ fi # Migrate DHCP configuration if [ -e "/var/ipfire/dhcp/dhcpd.conf" ]; then - sed -e "s/unbound-dhcp-leases-client/dhcp-lease/g" \ - -i /var/ipfire/dhcp/dhcpd.conf - + /usr/local/bin/convert-dhcp-conf # Restart DHCP /etc/init.d/dhcp restart fi diff --git a/src/scripts/convert-dhcp-conf b/src/scripts/convert-dhcp-conf new file mode 100644 index 000000000..6215f8315 --- /dev/null +++ b/src/scripts/convert-dhcp-conf @@ -0,0 +1,165 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2026 IPFire Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### +# +# Convert the DHCP configuration from version 202 to version 203. +# +# Replace the block from "on commit {" through the closing brace +# of the "on expiry" block with the version 203 configuration. +# +# If DOMAINNAME= is already present, the configuration is +# considered to be in the new format and no changes are made. +# +# All other content in dhcpd.conf must remain unchanged. +# + +set -euo pipefail + +DHCP_DIR="/var/ipfire/dhcp" +TARGET="${DHCP_DIR}/dhcpd.conf" + +# Check that the script is running as root. +if [[ $EUID -ne 0 ]]; then + echo "Error: This script must be run as root." >&2 + exit 1 +fi + +# Check that the target configuration file exists. +if [[ ! -f "$TARGET" ]]; then + echo "Error: DHCP configuration file not found: $TARGET" >&2 + exit 1 +fi + +# Skip conversion if the configuration is already in the new format. +if grep -q 'DOMAINNAME=' "$TARGET"; then + echo "DHCP configuration already uses the new format. No changes required." + exit 0 +fi + +# Define the version 203 hooks. +read -r -d '' NEW_BLOCK <<'EOF' || true +on commit { + set ClientAddress = concat( + "ADDRESS=", + binary-to-ascii(10, 8, ".", leased-address) + ); + set ClientHostName = concat( + "HOSTNAME=", + pick-first-value(option host-name, config-option-host-name, client-name, "") + ); + set ClientDomainName = concat( + "DOMAINNAME=", + pick-first-value(config-option domain-name, "") + ); + + if (ClientHostName != "") { + execute("/usr/sbin/dhcp-lease", "commit", ClientAddress, ClientHostName, ClientDomainName); + } +} + +on release { + set ClientAddress = concat( + "ADDRESS=", + binary-to-ascii(10, 8, ".", leased-address) + ); + set ClientHostName = concat( + "HOSTNAME=", + pick-first-value(option host-name, config-option-host-name, client-name, "") + ); + set ClientDomainName = concat( + "DOMAINNAME=", + pick-first-value(config-option domain-name, "") + ); + + if (ClientHostName != "") { + execute("/usr/sbin/dhcp-lease", "release", ClientAddress, ClientHostName, ClientDomainName); + } +} + +on expiry { + set ClientAddress = concat( + "ADDRESS=", + binary-to-ascii(10, 8, ".", leased-address) + ); + + execute("/usr/sbin/dhcp-lease", "expiry", ClientAddress); +} +EOF + +# Ensure the expected hooks exist in the original configuration. +if ! grep -q '^on commit[[:space:]]*{' "$TARGET" || + ! grep -q '^on expiry[[:space:]]*{' "$TARGET"; then + echo "Error: Expected DHCP hooks were not found in $TARGET." >&2 + exit 1 +fi + +# Create a temporary file in the same directory. +TMP=$(mktemp "${DHCP_DIR}/dhcpd.conf.XXXXXX") +trap 'rm -f "$TMP"' EXIT + +# Replace only the block from "on commit" to the end of "on expiry". +awk -v replacement="$NEW_BLOCK" ' + /^on commit[[:space:]]*\{/ && !done { + print replacement + done = 1 + skipping = 1 + next + } + + skipping && /^on expiry[[:space:]]*\{/ { + expiry = 1 + next + } + + skipping && expiry && /^}/ { + skipping = 0 + expiry = 0 + next + } + + !skipping { + print + } + + END { + if (!done || skipping) { + exit 1 + } + } +' "$TARGET" > "$TMP" || { + echo "Error: Failed to replace the DHCP hooks." >&2 + exit 1 +} + +# Validate the configuration before installing it. +if ! dhcpd -t -cf "$TMP"; then + echo "Error: Invalid DHCP configuration. The original file is unchanged." >&2 + exit 1 +fi + +# Preserve the original permissions and ownership. +chmod --reference="$TARGET" "$TMP" +chown --reference="$TARGET" "$TMP" + +# Install the updated configuration. +mv "$TMP" "$TARGET" +trap - EXIT + +echo "DHCP configuration successfully updated to version 203." -- 2.47.3