From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqcYI-0002r0-M8 for guix-patches@gnu.org; Tue, 27 Feb 2018 05:32:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqcYE-0005kk-L6 for guix-patches@gnu.org; Tue, 27 Feb 2018 05:32:06 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:54730) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eqcYE-0005kd-GY for guix-patches@gnu.org; Tue, 27 Feb 2018 05:32:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eqcYD-00043p-W9 for guix-patches@gnu.org; Tue, 27 Feb 2018 05:32:02 -0500 Subject: [bug#29732] [PATCH 1/1] services: Add dhcpd-service-type and . Resent-Message-ID: References: <20171216083528.2081-1-cmmarusich@gmail.com> <20171216085242.2309-1-cmmarusich@gmail.com> From: =?UTF-8?Q?Cl=C3=A9ment?= Lassieur In-reply-to: <20171216085242.2309-1-cmmarusich@gmail.com> Date: Tue, 27 Feb 2018 11:31:10 +0100 Message-ID: <871sh6rafl.fsf@lassieur.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Chris Marusich Cc: 29732@debbugs.gnu.org Hi Chris, thank you for this service! A few comments: Chris Marusich writes: > * doc/guix.texi (Networking Services): Document it. > * gnu/services/networking.scm (dhcpd-service-type): Add it. > (dhcpd-configuration, dhcpd-configuration?): Add it. > (dhcpd-configuration-package): Add it. > (dhcpd-configuration-config-file): Add it. > (dhcpd-configuration-ip-version): Add it. > (dhcpd-configuration-run-directory): Add it. > (dhcpd-configuration-lease-file): Add it. > (dhcpd-configuration-pid-file): Add it. > (dhcpd-configuration-interfaces): Add it. > --- > doc/guix.texi | 17 +++++++++++ > gnu/services/networking.scm | 72 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 89 insertions(+) > > diff --git a/doc/guix.texi b/doc/guix.texi > index 64f73b38a..3b62a0578 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -10357,6 +10357,23 @@ Return a service that runs @var{dhcp}, a Dynamic Host Configuration > Protocol (DHCP) client, on all the non-loopback network interfaces. > @end deffn > > +@deffn {Scheme Procedure} dhcpd-service-type > +This type defines a DHCP daemon. To create a service of this type, you > +must supply a @code{}. For example: > + > +@example > +(service dhcpd-service-type > + (dhcpd-configuration (config-file (local-file "my-dhcpd.conf")) > + (interfaces '("enp2s0f0")))) > +@end example > + > +Here, @file{my-dhcpd.conf} is a local file that defines a valid > +@command{dhcpd} configuration. Any ``file-like'' object will do here. > +For example, you could use @code{plain-file} instead of > +@code{local-file} if you prefer to embed the @code{dhcpd} configuration > +file in your scheme code. > +@end deffn > + > @defvr {Scheme Variable} static-networking-service-type > This is the type for statically-configured network interfaces. > @c TODO Document data structures. > diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm > index b0c23aafc..d562b7011 100644 > --- a/gnu/services/networking.scm > +++ b/gnu/services/networking.scm > @@ -55,6 +55,18 @@ > static-networking-service > static-networking-service-type > dhcp-client-service > + > + dhcpd-service-type > + dhcpd-configuration > + dhcpd-configuration? > + dhcpd-configuration-package > + dhcpd-configuration-config-file > + dhcpd-configuration-ip-version > + dhcpd-configuration-run-directory > + dhcpd-configuration-lease-file > + dhcpd-configuration-pid-file > + dhcpd-configuration-interfaces > + > %ntp-servers > > ntp-configuration > @@ -338,6 +350,66 @@ to handle." > Protocol (DHCP) client, on all the non-loopback network interfaces." > (service dhcp-client-service-type dhcp)) > > +(define-record-type* dhcpd-configuration > + make-dhcpd-configuration > + dhcpd-configuration? > + (package dhcpd-configuration-package ; > + (default isc-dhcp)) > + (config-file dhcpd-configuration-config-file ;file-like > + (default #f)) > + (ip-version dhcpd-ip-version ; either "4" or "6" > + (default "4")) Upstream defaults to "6". I guess it's because they want to encourage people to use IPv6. Maybe we should respect their choice and default to "6" as well? > + (run-directory dhcpd-run-directory > + (default "/run/dhcpd")) > + (lease-file dhcpd-lease-file > + (default "/var/db/dhcpd.leases")) > + (pid-file dhcpd-pid-file > + (default "/run/dhcpd/dhcpd.pid")) I wonder, does it make sense to run two instances of the daemon, one for IPv4 and another for IPv6? Would having the IP version included in the pid file name make it possible? (dhcpd-4.pid and dhcp-6.pid) > + (interfaces dhcpd-interfaces ; list of strings, e.g. (list "enp0s25") > + (default '()))) I don't really understand the logic of the indentation and alignment of this whole block :-). > +(define dhcpd-shepherd-service > + (match-lambda > + (($ package config-file ip-version _ lease-file pid-file interfaces) > + (when (null-list? interfaces) > + (error "Must specify at least one interface for DHCP daemon to use")) > + (unless config-file > + (error "Must supply a config-file")) > + (list (shepherd-service > + (provision '(dhcp-daemon)) > + (documentation "Run the DHCP daemon.") > + (requirement '(networking)) > + (start #~(make-forkexec-constructor > + '(#$(file-append package "/sbin/dhcpd") > + #$(string-append "-" ip-version) > + "-lf" #$lease-file > + "-pf" #$pid-file > + "-cf" #$config-file > + #$@interfaces) > + #:pid-file #$pid-file)) > + (stop #~(make-kill-destructor))))))) > + > +(define dhcpd-activation > + (match-lambda > + (($ package config-file _ run-directory lease-file _ _) > + #~(begin > + (unless (file-exists? #$run-directory) > + (mkdir #$run-directory)) mkdir-p I guess > + ;; According to the DHCP manual (man dhcpd.leases), the lease > + ;; database must be present for dhcpd to start successfully. > + (unless (file-exists? #$lease-file) > + (with-output-to-file #$lease-file > + (lambda _ (display "")))) > + ;; Validate the config. > + (zero? (system* #$(file-append package "/sbin/dhcpd") "-t" "-cf" #$config-file)))))) > + > +(define dhcpd-service-type > + (service-type > + (name 'dhcpd) > + (extensions > + (list (service-extension shepherd-root-service-type dhcpd-shepherd-service) > + (service-extension activation-service-type dhcpd-activation))))) > + > (define %ntp-servers > ;; Default set of NTP servers. These URLs are managed by the NTP Pool project. > ;; Within Guix, Leo Famulari is the administrative contact Also, could you stick to 80 columns? Thank you! Clément