From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id COSgBPZly2UEIAEA62LTzQ:P1 (envelope-from ) for ; Tue, 13 Feb 2024 13:52:06 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id COSgBPZly2UEIAEA62LTzQ (envelope-from ) for ; Tue, 13 Feb 2024 13:52:06 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=soeren-tempel.net header.s=opensmtpd header.b=WJ6bLMKd; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=soeren-tempel.net (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1707828726; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=gG9o4TPmwd7MXSdl+xWB0+4zsMiUJYXGB5pY1D3Rfhk=; b=nw4iuDD56QAjoBHYg19PHymgaBzlvgIbdOQi++zQc7LLl6SHv0Bo2F30eXm910YO3IyvH6 wf5Ql97CbksBtCEec6wPmQf3+9QsbazSEK1AG4FpWd6LVI0yA7ecZ6dFgpQpE8ypBbtUwF EJgPARVlnh3bVahmGj3vV+oW9fv55ZoutPMG1No4sZUStmgHKhgVeM71wGx+Xah5Xbp1wp Ksnz8z5HX8MDv7dpBgfh+jSrU+F/EdynvOaoBqiENIYm4431LtoWKz1yaXPBfds3yIXuoP pf40MLc9obm8AmfgfvYCUm1pmsHfOhoj8bc7qyBH6jvHUulcUGJNvkeIJSzc5Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=soeren-tempel.net header.s=opensmtpd header.b=WJ6bLMKd; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=soeren-tempel.net (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1707828726; a=rsa-sha256; cv=none; b=bj3L/u3r3AB4CLLA28fdNVsJxwLeqYFA7Wf5Qvdkzeft7DSTUzZqDPjlLf7UmrdrdeUytX i/1GPizZrwb1oI93GxcAfVziMs7MAos7X4c7Xy2HEt5BSLr1CA45ErWSTXRRRKxGKj1LhE KLzcUcCr2yOg9VQfU1uX/s4njIzRMriuVi1vU8HmC7pLZmu/ofizCEgr5wTBJFW9AN1VVi 259HRfS9nvvUKcDUh4RqZI/w8+fBgUycGsdYTqwnFbJx5/dzqouFrBmHqOgDEXQMk9MehE /S5lkSqtKT4ZvLQhOI4DMNo3PKU0yE3hMKMBaodMLxVFrM7qNMO3e04iBSH6tw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D89924785B for ; Tue, 13 Feb 2024 13:52:05 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZsGO-0005Bl-1z; Tue, 13 Feb 2024 07:51:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rZsGI-00059M-Sh for guix-patches@gnu.org; Tue, 13 Feb 2024 07:51:46 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZsGI-0003cE-0H for guix-patches@gnu.org; Tue, 13 Feb 2024 07:51:46 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rZsGY-000529-Ry for guix-patches@gnu.org; Tue, 13 Feb 2024 07:52:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68675] [PATCH v3 2/2] services: dhcp: Support the dhcpcd implementation. Resent-From: soeren@soeren-tempel.net Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 13 Feb 2024 12:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68675 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68675@debbugs.gnu.org Received: via spool by 68675-submit@debbugs.gnu.org id=B68675.170782868019275 (code B ref 68675); Tue, 13 Feb 2024 12:52:02 +0000 Received: (at 68675) by debbugs.gnu.org; 13 Feb 2024 12:51:20 +0000 Received: from localhost ([127.0.0.1]:42886 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZsFr-00050p-K7 for submit@debbugs.gnu.org; Tue, 13 Feb 2024 07:51:20 -0500 Received: from magnesium.8pit.net ([45.76.88.171]:28727) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZsFo-00050J-6l; Tue, 13 Feb 2024 07:51:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=+CVPgXe9o3 3xj789ikQ62mSqjI1GBUVMXSMvJHRWfNQ=; h=references:in-reply-to:date: subject:to:from; d=soeren-tempel.net; b=WJ6bLMKdgz5blMy6PdW3/N3MLHc6w9 lnDlXVoZ0Ios74NH78wOeCRkSrziBx2FMQTC3T9ZUq1sJoXxzbzj9EiWI3GHk4SdNXNaKT UATMXNu18SMIIJDxYIqG7QFw4ijfLMNlujEXJ5CjKONk/WFXneYV77Y2vWkXp6fl9GV0KD E= Received: from localhost (dynamic-2a02-3102-49da-001b-df49-33b7-2af2-ff52.310.pool.telefonica.de [2a02:3102:49da:1b:df49:33b7:2af2:ff52]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 43820bef (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Tue, 13 Feb 2024 13:50:55 +0100 (CET) From: soeren@soeren-tempel.net Date: Tue, 13 Feb 2024 13:50:43 +0100 Message-ID: X-Mailer: git-send-email 2.43.1 In-Reply-To: <5c6f714f4802ec17bc247e701bcee82d54733005.1707828643.git.soeren@soeren-tempel.net> References: <5c6f714f4802ec17bc247e701bcee82d54733005.1707828643.git.soeren@soeren-tempel.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: 5.03 X-Migadu-Queue-Id: D89924785B X-Spam-Score: 5.03 X-Migadu-Scanner: mx11.migadu.com X-TUID: f68pd5n1iJ05 From: Sören Tempel Prior to this commit, the isc-dhcp implementation was the only DHCP implementation supported by dhcp-client-shepherd-service. This is problematic as the ISC implementation has reached end-of-life in 2022(!). As a first step to migrate away from isc-dhcp, this commit adds support for dhcpcd to dhcp-client-shepherd-service. Currently, it has to be enabled explicitly via the package field of the dhcp-client-configuration. In the future, it is intended to become the default to migrate away from isc-dhcp. While at it, also remove isc-dhcp from %base-packages as it is no longer necessarily needed and it will be pulled in by the DHCP client service if required. See also: https://issues.guix.gnu.org/68619 * gnu/services/networking.scm (dhcp-client-shepherd-service): Add support for the dhcpcd client implementation. * gnu/services/networking.scm (dhcp-client-account-service): New procedure. * gnu/services/networking.scm (dhcp-client-service-type): Add optional account-service-type extensions (needed for dhcpcd). * gnu/system.scm (%base-packages-networking): Remove isc-dhcp from %base-packages (will be pulled in by dhcp-client-shepherd-service). Signed-off-by: Sören Tempel --- gnu/services/networking.scm | 92 +++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 495d049728..4e058e1880 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -316,25 +316,21 @@ (define-record-type* (define dhcp-client-shepherd-service (match-lambda ((? dhcp-client-configuration? config) - (let ((package (dhcp-client-configuration-package config)) - (requirement (dhcp-client-configuration-shepherd-requirement config)) - (provision (dhcp-client-configuration-shepherd-provision config)) - (interfaces (dhcp-client-configuration-interfaces config)) - (pid-file "/var/run/dhclient.pid")) + (let* ((package (dhcp-client-configuration-package config)) + (client-name (package-name package)) + (requirement (dhcp-client-configuration-shepherd-requirement config)) + (provision (dhcp-client-configuration-shepherd-provision config)) + (interfaces (dhcp-client-configuration-interfaces config))) (list (shepherd-service (documentation "Set up networking via DHCP.") (requirement `(user-processes udev ,@requirement)) (provision provision) + (modules `((ice-9 popen) + (ice-9 rdelim) + ,@%default-modules)) - ;; XXX: Running with '-nw' ("no wait") avoids blocking for a minute when - ;; networking is unavailable, but also means that the interface is not up - ;; yet when 'start' completes. To wait for the interface to be ready, one - ;; should instead monitor udev events. (start #~(lambda _ - (define dhclient - (string-append #$package "/sbin/dhclient")) - - ;; When invoked without any arguments, 'dhclient' discovers all + ;; When invoked without any arguments, the client discovers all ;; non-loopback interfaces *that are up*. However, the relevant ;; interfaces are typically down at this point. Thus we perform ;; our own interface discovery here. @@ -355,17 +351,46 @@ (define dhcp-client-shepherd-service (_ #~'#$interfaces)))) - (false-if-exception (delete-file #$pid-file)) - (let ((pid (fork+exec-command - ;; By default dhclient uses a - ;; pre-standardization implementation of - ;; DDNS, which is incompatable with - ;; non-ISC DHCP servers; thus, pass '-I'. - ;; . - (cons* dhclient "-nw" "-I" - "-pf" #$pid-file ifaces)))) - (and (zero? (cdr (waitpid pid))) - (read-pid-file #$pid-file))))) + ;; Returns the execution configuration for the DHCP client + ;; selected by the package field of dhcp-client-configuration. + ;; The configuration is a pair of pidfile and execution command + ;; where the latter is a list. + (define exec-config + (case (string->symbol #$client-name) + ((isc-dhcp) + (let ((pid-file "/var/run/dhclient.pid")) + (cons + (cons* (string-append #$package "/sbin/dhclient") + "-nw" "-I" "-pf" pid-file ifaces) + pid-file))) + ((dhcpcd) + ;; For dhcpcd, the utilized pid-file depends on the + ;; command-line arguments. If multiple interfaces are + ;; given, a different pid-file is returned. Hence, we + ;; consult dhcpcd itself to determine the pid-file. + (let* ((cmd (string-append #$package "/sbin/dhcpcd")) + (arg (cons* cmd "-b" ifaces))) + (cons arg + (let* ((pipe (string-join (append arg '("-P")) " ")) + (port (open-input-pipe pipe)) + (path (read-line port))) + (close-pipe port) + path)))) + (else + (display + "unknown 'package' value in dhcp-client-configuration" + (current-error-port)) + (newline (current-error-port)) + #f))) + + (and + exec-config + (let ((pid-file (cdr exec-config)) + (exec-cmd (car exec-config))) + (false-if-exception (delete-file pid-file)) + (let ((pid (fork+exec-command exec-cmd))) + (and (zero? (cdr (waitpid pid))) + (read-pid-file pid-file))))))) (stop #~(make-kill-destructor)))))) (package (warning (G_ "'dhcp-client' service now expects a \ @@ -377,10 +402,27 @@ (define dhcp-client-shepherd-service (dhcp-client-configuration (package package)))))) +(define (dhcp-client-account-service config) + (let ((package (dhcp-client-configuration-package config))) + ;; Contrary to other DHCP clients (e.g. dhclient), dhcpcd supports + ;; privilege separation. Hence, we need to create an account here. + (if (string=? "dhcpcd" (package-name package)) + (list (user-group (name "dhcpcd") (system? #t)) + (user-account + (name "dhcpcd") + (group "dhcpcd") + (system? #t) + (comment "dhcpcd daemon user") + (home-directory "/var/empty") + (shell "/run/current-system/profile/sbin/nologin"))) + '()))) + (define dhcp-client-service-type (service-type (name 'dhcp-client) (extensions - (list (service-extension shepherd-root-service-type + (list (service-extension account-service-type + dhcp-client-account-service) + (service-extension shepherd-root-service-type dhcp-client-shepherd-service))) (default-value (dhcp-client-configuration)) (description "Run @command{dhcp}, a Dynamic Host Configuration