From patchwork Sun Sep 8 12:06:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 30803 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6F16727BBEA; Sun, 8 Sep 2024 13:08:28 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4EE0527BBE2 for ; Sun, 8 Sep 2024 13:08:27 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snGi4-0002kw-7D; Sun, 08 Sep 2024 08:08:04 -0400 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 1snGi1-0002kn-UN for guix-patches@gnu.org; Sun, 08 Sep 2024 08:08:01 -0400 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 1snGi1-0002C8-AE; Sun, 08 Sep 2024 08:08:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=jEm5QJhQImRZzg2yZvW/FOX5KG1PEinUogh8q+/KDEQ=; b=VCm98qb6CVoo3uylcVyHa/L8k7eaNZB0aKZkFt8F2BRIkXLRYA0I3/evixcaKMFiP3W5vxV3n+yJRZ+CQF6LD0cVhqw6MKPdQs9Sp7brs+XDEK0U8E20bWgEWkiC+G+AEeUE6x1pHXnWnPD5gAIK0hePTDo1y5STenTNQYNg2koXrvuxfi5f3bgbb0BZxgNUGcJP1GOBc++W2Qdn8IUmEJnGoh994oN1ycFe2lPNrWSKwWs1b1EC9I3gi8BVvG0aNt5jsoYY7kRZIqHo4JQ41ysRwRj5nbKMVWDlPwsIEoFieixOIKAtRlEYHFeOB9dsT6mHxg/rLYQQdw6sVyIzAA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1snGi2-0000Pn-DE; Sun, 08 Sep 2024 08:08:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73120] [PATCH] services: networking: Add 'version' field to dhcp-client-configuration. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 08 Sep 2024 12:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73120 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73120@debbugs.gnu.org Cc: Maxim Cournoyer , Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by submit@debbugs.gnu.org id=B.17257972331519 (code B ref -1); Sun, 08 Sep 2024 12:08:02 +0000 Received: (at submit) by debbugs.gnu.org; 8 Sep 2024 12:07:13 +0000 Received: from localhost ([127.0.0.1]:58113 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snGhE-0000OQ-Kk for submit@debbugs.gnu.org; Sun, 08 Sep 2024 08:07:13 -0400 Received: from lists.gnu.org ([209.51.188.17]:51200) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snGhB-0000OI-Jm for submit@debbugs.gnu.org; Sun, 08 Sep 2024 08:07:10 -0400 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 1snGh9-0002i2-7v for guix-patches@gnu.org; Sun, 08 Sep 2024 08:07:07 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1snGh6-00029s-8q for guix-patches@gnu.org; Sun, 08 Sep 2024 08:07:06 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-718d606726cso1579365b3a.3 for ; Sun, 08 Sep 2024 05:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725797219; x=1726402019; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jEm5QJhQImRZzg2yZvW/FOX5KG1PEinUogh8q+/KDEQ=; b=YI8z/ql2KOazOGixvoUTMxCHT2HwQTiKXWnN0Egx0++9CFf694pnZh+9MVZhI9jZsO B4Sfmc8gotTgy7RTMlqWsv9pwR4XBdc0+xtYsAzt0KHpns/ejIeqvuz2gidyZQlGIMxR 03RpBOMFQumnx346JSj71ejwsHgaseAq6K8Cyg/K6EYGzRHzzScSXPkcDIpmy3CoGKOm XwuZfPA1DDDpARm7CYoWcGZO3j2V/qIrneXQpskEl4y1T9YywfOaVIXhrVZXkrelXQ3O te35p4PlsmHAJq5n2pqCTGzRlI6fFdc22/MfUg8c4yX/Li7JbRFjUW0bn+L4pajlICZc LbTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725797219; x=1726402019; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jEm5QJhQImRZzg2yZvW/FOX5KG1PEinUogh8q+/KDEQ=; b=qGytKIlzkBmlKdhCCCEbtlgF7NDwlHgsG3XUsh7OGe4pLp3v8nGxkkS60xG1yjtHcV 6uwIyyCcQLp3fq1J4BbYoNNX+wt1R7EVx7ItcagFLhajAgzrZ/gFpvA7R+ihgbxfSoVy 5FLARORNZ5LSzFzDtidDatPbhiCC3LIodjDYPHZkDzNxheoOjHSeLJgCtjIiap58Kd0Q /z7FkQkdjv7YV16JuZgbHshkqWCW3lC4VwwvXvXRsQukW1XDZOATEVMmg+XwW+t1svCn IwOukHBqS12Pxu+AQ4oRjPG4F+wamF16dhgytArIxey2btcX5Nj8h8Cl5IDgm+7O9Fe5 cpzw== X-Gm-Message-State: AOJu0Yyj4hzdK6Tsk9TZMF2eZR/F2s1KFHXkkTtDCqDANky9uEa5qcyx R992hz8RIJyNboYbRIwrgRaqFf6rBY3J7V+DtwxsJo3rfLTZ6QxVv3a2GnwC X-Google-Smtp-Source: AGHT+IHwclOSblOHOznsgUh4gioJnGmMvYc6TMcd9L0A8u6RdZHTjKfERdAq9kRPa8UkPUZRexdZgg== X-Received: by 2002:a05:6a21:a24c:b0:1cf:339e:a8d1 with SMTP id adf61e73a8af0-1cf339eabb3mr5114193637.10.1725797219049; Sun, 08 Sep 2024 05:06:59 -0700 (PDT) Received: from hurd.lan (vps-6234970c.vps.ovh.ca. [51.222.13.224]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-718e5896712sm1994241b3a.2.2024.09.08.05.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Sep 2024 05:06:58 -0700 (PDT) From: Maxim Cournoyer Date: Sun, 8 Sep 2024 21:06:44 +0900 Message-ID: <84f485d05604a93a5563d77f418c2a4981f21bba.1725797204.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=maxim.cournoyer@gmail.com; helo=mail-pf1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/networking.scm () [version]: New field. (dhcp-client-shepherd-service): Use 'match-record' instead of various accessors. Honor the new 'version field'. Include the version the PID file name when a non-default version is used. * doc/guix.texi (Networking Setup) [version]: Document it. Change-Id: I6236ae160967c95fe7a2c1785821cc9b0c183e77 --- doc/guix.texi | 7 +- gnu/services/networking.scm | 131 +++++++++++++++++++----------------- 2 files changed, 76 insertions(+), 62 deletions(-) base-commit: d0e361f50d927910c722cddda67b5a98168de36e diff --git a/doc/guix.texi b/doc/guix.texi index 981ffb8c58..fe3f03e9da 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -49,7 +49,7 @@ Copyright @copyright{} 2017, 2021 Christine Lemmer-Webber@* Copyright @copyright{} 2017, 2018, 2019, 2020, 2021, 2022 Marius Bakke@* Copyright @copyright{} 2017, 2019, 2020, 2022 Hartmut Goebel@* -Copyright @copyright{} 2017, 2019, 2020, 2021, 2022, 2023 Maxim Cournoyer@* +Copyright @copyright{} 2017, 2019, 2020, 2021, 2022, 2023, 2024 Maxim Cournoyer@* Copyright @copyright{} 2017–2022 Tobias Geerinckx-Rice@* Copyright @copyright{} 2017 George Clemmer@* Copyright @copyright{} 2017 Andy Wingo@* @@ -21085,6 +21085,11 @@ Networking Setup @item @code{config-file} (default: @code{#f}) The configuration file for the ISC DHCP client. +@item @code{version} (default: @code{"4"}) +The DHCP protocol version to use, as a string. Accepted values are +@code{"4"} or @code{"6"} for DHCPv4 or DHCPv6, respectively, as well as +@code{"4o6"}, for DHCPv4 over DHCPv6 (as specified by RFC 7341). + @item @code{shepherd-requirement} (default: @code{'()}) @itemx @code{shepherd-provision} (default: @code{'(networking)}) This option can be used to provide a list of symbols naming Shepherd services diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 12d8934e43..a1f5f37564 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -10,7 +10,7 @@ ;;; Copyright © 2018 Chris Marusich ;;; Copyright © 2018 Arun Isaac ;;; Copyright © 2019 Florian Pelz -;;; Copyright © 2019, 2021 Maxim Cournoyer +;;; Copyright © 2019, 2021, 2024 Maxim Cournoyer ;;; Copyright © 2019 Sou Bunnbu ;;; Copyright © 2019 Alex Griffin ;;; Copyright © 2020 Brice Waegeneire @@ -94,6 +94,7 @@ (define-module (gnu services networking) dhcp-client-configuration-config-file dhcp-client-configuration-shepherd-provision dhcp-client-configuration-shepherd-requirement + dhcp-client-configuration-version dhcpd-service-type dhcpd-configuration @@ -323,70 +324,78 @@ (define-record-type* (config-file dhcp-client-configuration-config-file (default #f)) (interfaces dhcp-client-configuration-interfaces - (default 'all))) ;'all | list of strings + (default 'all)) ;'all | list of strings + (version dhcp-client-configuration-version ;"4", "6", or "4o6" + (default "4"))) (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)) - (config-file (dhcp-client-configuration-config-file config)) - (pid-file "/var/run/dhclient.pid")) - (list (shepherd-service - (documentation "Set up networking via DHCP.") - (requirement `(user-processes udev ,@requirement)) - (provision provision) - - ;; 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 - ;; non-loopback interfaces *that are up*. However, the relevant - ;; interfaces are typically down at this point. Thus we perform - ;; our own interface discovery here. - (define valid? - (lambda (interface) - (and (arp-network-interface? interface) - (not (loopback-network-interface? interface)) - ;; XXX: Make sure the interfaces are up so that - ;; 'dhclient' can actually send/receive over them. - ;; Ignore those that cannot be activated. - (false-if-exception - (set-network-interface-up interface))))) - (define ifaces - (filter valid? - #$(match interfaces - ('all - #~(all-network-interface-names)) - (_ - #~'#$interfaces)))) - - (define config-file-args - (if #$config-file - (list "-cf" #$config-file) - '())) - - (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'. - ;; . - `(,dhclient "-nw" "-I" - "-pf" ,#$pid-file - ,@config-file-args - ,@ifaces)))) - (and (zero? (cdr (waitpid pid))) - (read-pid-file #$pid-file))))) - (stop #~(make-kill-destructor)))))) + (match-record config + (package shepherd-requirement shepherd-provision + interfaces config-file version) + ;; Version the PID file to avoid conflicts in case multiple DHCP + ;; clients are run concurrently. + (let ((pid-file (if (string=? "4" version) + "/var/run/dhclient.pid" + (string-append "/var/run/dhclient-" version ".pid")))) + (list (shepherd-service + (documentation "Set up networking via DHCP.") + (requirement `(user-processes udev ,@shepherd-requirement)) + (provision shepherd-provision) + + ;; 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 non-loopback interfaces *that are + ;; up*. However, the relevant interfaces are + ;; typically down at this point. Thus we perform + ;; our own interface discovery here. + (define valid? + (lambda (interface) + (and (arp-network-interface? interface) + (not (loopback-network-interface? interface)) + ;; XXX: Make sure the interfaces are up so + ;; that 'dhclient' can actually + ;; send/receive over them. Ignore those + ;; that cannot be activated. + (false-if-exception + (set-network-interface-up interface))))) + (define ifaces + (filter valid? + #$(match interfaces + ('all + #~(all-network-interface-names)) + (_ + #~'#$interfaces)))) + + (define config-file-args + (if #$config-file + (list "-cf" #$config-file) + '())) + + (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'. + ;; . + `(,dhclient "-nw" "-I" + #$(string-append "-" version) + "-pf" ,#$pid-file + ,@config-file-args + ,@ifaces)))) + (and (zero? (cdr (waitpid pid))) + (read-pid-file #$pid-file))))) + (stop #~(make-kill-destructor))))))) (package (warning (G_ "'dhcp-client' service now expects a \ 'dhcp-client-configuration' record~%"))