Package: guix-patches;
Reported by: Alexey Abramov <levenson <at> mmer.org>
Date: Sat, 1 Oct 2022 13:12:02 UTC
Severity: normal
Tags: patch
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 58223 in the body.
You can then email your comments to 58223 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
guix-patches <at> gnu.org
:bug#58223
; Package guix-patches
.
(Sat, 01 Oct 2022 13:12:02 GMT) Full text and rfc822 format available.Alexey Abramov <levenson <at> mmer.org>
:guix-patches <at> gnu.org
.
(Sat, 01 Oct 2022 13:12:02 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: guix-patches <at> gnu.org Subject: [PATCH 0/1] dhclient record configuration Date: Sat, 1 Oct 2022 15:11:12 +0200
With this patch, dhclient will get its configuration record. The main reason for this is to be able to define a list of interfaces dhclient should be listening to. Such cases are common for routers and other network devices. This patch provides a deprecation message in case someone uses a custom dhclient package for this service, and recommends switching to a proper configuration. However, there is one thing that is not clear to me. I am configuring my router, where I have to have dhclient service which has to get an IP from the upstream, and also have dhcpd configuration for my private internal networks. Both services provision '(networking), which is not allowed right now. Alexey Abramov (1): services: dhcp-client: Implement and use a configuration record doc/guix.texi | 18 +++++- gnu/services/networking.scm | 114 ++++++++++++++++++++++-------------- 2 files changed, 85 insertions(+), 47 deletions(-) -- 2.36.1
guix-patches <at> gnu.org
:bug#58223
; Package guix-patches
.
(Sat, 01 Oct 2022 13:14:02 GMT) Full text and rfc822 format available.Message #8 received at 58223 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 58223 <at> debbugs.gnu.org Subject: [PATCH 1/1] services: dhcp-client: Implement and use a configuration record Date: Sat, 1 Oct 2022 15:12:57 +0200
* gnu/services/networking.scm (dhcp-client-configuration): New record configuration. (dhcp-client-shepherd-service): Implement a shepher service. Provide a deprication message for legacy configurations. (dhcp-client-service-type): Use dhcp-client-shepherd-service. * doc/guix.texi: Update documentation --- doc/guix.texi | 18 +++++- gnu/services/networking.scm | 114 ++++++++++++++++++++++-------------- 2 files changed, 85 insertions(+), 47 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 30eb7f4cbf..e425d98d26 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -19227,10 +19227,24 @@ the user mode network stack,,, QEMU, QEMU Documentation}). @cindex DHCP, networking service @defvr {Scheme Variable} dhcp-client-service-type This is the type of services that run @var{dhcp}, a Dynamic Host Configuration -Protocol (DHCP) client, on all the non-loopback network interfaces. Its value -is the DHCP client package to use, @code{isc-dhcp} by default. +Protocol (DHCP) client. @end defvr +@deftp {Data Type} dhcp-client-configuration +Data type representing the configuration of dhcp client network service. + +@table @asis +@item @code{package} (default: @code{isc-dhcp}) +DHCP client package to use. + +@item @code{interfaces} (default: @code{'()}) +List of strings of interface names that dhcp client should listen on. By +default dhcp client will listen on all available non-loopback interfaces +that can be activated (meaning, to set them up). (default: @code{'()}) + +@end table +@end deftp + @cindex NetworkManager @defvr {Scheme Variable} network-manager-service-type diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 9d85728371..1185f7e57d 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -77,6 +77,10 @@ (define-module (gnu services networking) static-networking-service-type) #:export (%facebook-host-aliases dhcp-client-service-type + dhcp-client-configuration + dhcp-client-configuration? + dhcp-client-configuration-package + dhcp-client-configuration-interfaces dhcpd-service-type dhcpd-configuration @@ -259,52 +263,72 @@ (define %facebook-host-aliases fe80::1%lo0 www.connect.facebook.net fe80::1%lo0 apps.facebook.com\n") + +(define-record-type* <dhcp-client-configuration> + dhcp-client-configuration make-dhcp-client-configuration + dhcp-client-configuration? + (package dhcp-client-configuration-package ;file-like + (default isc-dhcp)) + ;; Empty list (means any) or a list of valid interfaces + (interfaces dhcp-client-configuration-interfaces + (default '()))) + +(define dhcp-client-shepherd-service + (match-lambda + (($ <dhcp-client-configuration> package interfaces) + (let ((pid-file "/var/run/dhclient.pid")) + (list (shepherd-service + (documentation "Set up networking via DHCP.") + (requirement '(user-processes udev)) + + ;; 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. + (provision '(networking)) + + (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? (or '#$interfaces + (all-network-interface-names)))) + + (false-if-exception (delete-file #$pid-file)) + (let ((pid (fork+exec-command + (cons* dhclient "-nw" + "-pf" #$pid-file ifaces)))) + (and (zero? (cdr (waitpid pid))) + (read-pid-file #$pid-file))))) + (stop #~(make-kill-destructor)))))) + (anything + (format (current-error-port) "warning: Defining dhcp-client service with +a single argument value being a client package to use, is deprecated. Please +use <dhcp-client-configuration> record instead.\n") + (dhcp-client-shepherd-service + (dhcp-client-configuration + (package anything)))))) + (define dhcp-client-service-type - (shepherd-service-type - 'dhcp-client - (lambda (dhcp) - (define dhclient - (file-append dhcp "/sbin/dhclient")) - - (define pid-file - "/var/run/dhclient.pid") - - (shepherd-service - (documentation "Set up networking via DHCP.") - (requirement '(user-processes udev)) - - ;; 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. - (provision '(networking)) - - (start #~(lambda _ - ;; 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? (all-network-interface-names))) - - (false-if-exception (delete-file #$pid-file)) - (let ((pid (fork+exec-command - (cons* #$dhclient "-nw" - "-pf" #$pid-file ifaces)))) - (and (zero? (cdr (waitpid pid))) - (read-pid-file #$pid-file))))) - (stop #~(make-kill-destructor)))) - isc-dhcp - (description "Run @command{dhcp}, a Dynamic Host Configuration + (service-type (name 'dhcp-client) + (extensions + (list (service-extension shepherd-root-service-type dhcp-client-shepherd-service))) + (default-value (dhcp-client-configuration)) + (description "Run @command{dhcp}, a Dynamic Host Configuration Protocol (DHCP) client, on all the non-loopback network interfaces."))) (define-record-type* <dhcpd-configuration> -- 2.36.1
Ludovic Courtès <ludo <at> gnu.org>
:Alexey Abramov <levenson <at> mmer.org>
:Message #13 received at 58223-done <at> debbugs.gnu.org (full text, mbox):
From: Ludovic Courtès <ludo <at> gnu.org> To: Alexey Abramov <levenson <at> mmer.org> Cc: 58223-done <at> debbugs.gnu.org Subject: Re: bug#58223: [PATCH 0/1] dhclient record configuration Date: Thu, 06 Oct 2022 00:04:53 +0200
[Message part 1 (text/plain, inline)]
Hi, Alexey Abramov <levenson <at> mmer.org> skribis: > * gnu/services/networking.scm (dhcp-client-configuration): New record > configuration. > (dhcp-client-shepherd-service): Implement a shepher service. Provide a > deprication message for legacy configurations. > (dhcp-client-service-type): Use dhcp-client-shepherd-service. > * doc/guix.texi: Update documentation [...] > + ;; Empty list (means any) or a list of valid interfaces > + (interfaces dhcp-client-configuration-interfaces > + (default '()))) [...] > + (define ifaces > + (filter valid? (or '#$interfaces > + (all-network-interface-names)))) This isn’t quite right since '() is always true. For this and for aesthetic reasons, I changed ‘interfaces’ such that it must be either 'all or a list. Applied with the changes below, thanks! Ludo’.
[Message part 2 (text/x-patch, inline)]
diff --git a/doc/guix.texi b/doc/guix.texi index afc18239d4..6691ae5844 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -19234,17 +19234,19 @@ Protocol (DHCP) client. @end defvr @deftp {Data Type} dhcp-client-configuration -Data type representing the configuration of dhcp client network service. +Data type representing the configuration of the DHCP client service. @table @asis @item @code{package} (default: @code{isc-dhcp}) DHCP client package to use. -@item @code{interfaces} (default: @code{'()}) -List of strings of interface names that dhcp client should listen on. By -default dhcp client will listen on all available non-loopback interfaces -that can be activated (meaning, to set them up). (default: @code{'()}) +@item @code{interfaces} (default: @code{'all}) +Either @code{'all} or the list of interface names that the DHCP client +should listen on---e.g., @code{'("eno1")}. +When set to @code{'all}, the DHCP client listens on all the available +non-loopback interfaces that can be activated. Otherwise the DHCP +client listens only on the specified interfaces. @end table @end deftp diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm index 1185f7e57d..19aba8c266 100644 --- a/gnu/services/networking.scm +++ b/gnu/services/networking.scm @@ -66,6 +66,9 @@ (define-module (gnu services networking) #:use-module (guix modules) #:use-module (guix packages) #:use-module (guix deprecation) + #:use-module (guix diagnostics) + #:autoload (guix ui) (display-hint) + #:use-module (guix i18n) #:use-module (rnrs enums) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) @@ -269,9 +272,8 @@ (define-record-type* <dhcp-client-configuration> dhcp-client-configuration? (package dhcp-client-configuration-package ;file-like (default isc-dhcp)) - ;; Empty list (means any) or a list of valid interfaces (interfaces dhcp-client-configuration-interfaces - (default '()))) + (default 'all))) ;'all | list of strings (define dhcp-client-shepherd-service (match-lambda @@ -305,8 +307,12 @@ (define valid? (false-if-exception (set-network-interface-up interface))))) (define ifaces - (filter valid? (or '#$interfaces - (all-network-interface-names)))) + (filter valid? + #$(match interfaces + ('all + #~(all-network-interface-names)) + (_ + #~'#$interfaces)))) (false-if-exception (delete-file #$pid-file)) (let ((pid (fork+exec-command @@ -315,18 +321,21 @@ (define ifaces (and (zero? (cdr (waitpid pid))) (read-pid-file #$pid-file))))) (stop #~(make-kill-destructor)))))) - (anything - (format (current-error-port) "warning: Defining dhcp-client service with -a single argument value being a client package to use, is deprecated. Please -use <dhcp-client-configuration> record instead.\n") + (package + (warning (G_ "'dhcp-client' service now expects a \ +'dhcp-client-configuration' record~%")) + (display-hint (G_ "The value associated with instances of +@code{dhcp-client-service-type} must now be a @code{dhcp-client-configuration} +record instead of a package. Please adjust your configuration accordingly.")) (dhcp-client-shepherd-service (dhcp-client-configuration - (package anything)))))) + (package package)))))) (define dhcp-client-service-type (service-type (name 'dhcp-client) (extensions - (list (service-extension shepherd-root-service-type dhcp-client-shepherd-service))) + (list (service-extension shepherd-root-service-type + dhcp-client-shepherd-service))) (default-value (dhcp-client-configuration)) (description "Run @command{dhcp}, a Dynamic Host Configuration Protocol (DHCP) client, on all the non-loopback network interfaces."))) diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in index 4050a4c7ae..ed3fdb6be0 100644 --- a/po/guix/POTFILES.in +++ b/po/guix/POTFILES.in @@ -5,6 +5,7 @@ gnu/packages.scm gnu/services.scm gnu/system.scm gnu/services/configuration.scm +gnu/services/networking.scm gnu/services/shepherd.scm gnu/services/samba.scm gnu/home/services.scm
Debbugs Internal Request <help-debbugs <at> gnu.org>
to internal_control <at> debbugs.gnu.org
.
(Thu, 03 Nov 2022 11:24:06 GMT) Full text and rfc822 format available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.