From patchwork Thu May 8 17:47:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Abramov X-Patchwork-Id: 42467 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 0B51127BC4A; Thu, 8 May 2025 18:51:52 +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=-7.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable 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 70FA027BC49 for ; Thu, 8 May 2025 18:51:50 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uD5P5-0005Xb-PY; Thu, 08 May 2025 13:51:28 -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 1uD5Ok-0005E3-Cy for guix-patches@gnu.org; Thu, 08 May 2025 13:51:17 -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 1uD5Oi-0001ut-86; Thu, 08 May 2025 13:51:04 -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:References:In-Reply-To:Date:From:To:Subject; bh=olJTwpuIoqvBCXGacS7xTtQlCYsWtGsVStHUCbbt/HU=; b=QLkHfDDY7uQt843cz6vyQEb7OK2YR0gxNbUpWcVIQDX9r5VR8md6zNKbZqDFBOQhryqPnTJSLnGuy3LbCJFyflx8lJznDPX124pCOUpzsOs+X7NlwjvSujlXf4rU6+EMgJNcLlmxD8FZ1Pb/dGXRq4Vlq8Ig/gqFu2ZQWt06hSMEin/OSSj7R9luUaW0FEko0BBa8YH0qXVaTcGFx/72ueFgMyebsNcm21UG67IIg1zU5ntL0pamgclmNHR0hF5onzNBkIzSIzGzAmtQwMSpGWsrArTg1IZpQod+u2gByQv6Wx/NGjQVqF4+8xZfNG6B0S2d3c8jYXtUiFxXAOM0sw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uD5Og-0007gB-QB; Thu, 08 May 2025 13:51:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77204] [PATCH v4 1/3] services: dnsmasq: Add shepherd-provision and shepherd-requirement fields. Resent-From: Alexey Abramov Original-Sender: "Debbugs-submit" Resent-CC: gabriel@erlikon.ch, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Thu, 08 May 2025 17:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77204 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77204@debbugs.gnu.org Cc: Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 77204-submit@debbugs.gnu.org id=B77204.174672663529426 (code B ref 77204); Thu, 08 May 2025 17:51:02 +0000 Received: (at 77204) by debbugs.gnu.org; 8 May 2025 17:50:35 +0000 Received: from localhost ([127.0.0.1]:59717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uD5OE-0007eT-OX for submit@debbugs.gnu.org; Thu, 08 May 2025 13:50:35 -0400 Received: from mail.mmer.org ([178.22.65.174]:51192) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uD5OC-0007dp-26 for 77204@debbugs.gnu.org; Thu, 08 May 2025 13:50:32 -0400 Received: from mail.mmer.org (localhost [127.0.0.1]) by mail.mmer.org (OpenSMTPD) with ESMTP id aca7030e for <77204@debbugs.gnu.org>; Thu, 8 May 2025 17:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=mmer.org; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=dkim; bh=Wo5E4PKD4t3Oa4TmO6Z44T+Gz Zo2RnDxzewPwgY7rN0=; b=7ci0lpq3khBVGqSrXy1VFiibaytDT5FATZcffJI7T /dPydygRpfeaaDOSnqCY8u33gTUGG6sIzm1ASQMDnby3p3YCEJKFu/o7qUKEVEL1 g8nBokzyQIfBIM4jYxxHvrfX9SNFTjRJU/8B9TfqjOxZAQcz4/2nps8bsee8i28e hk= Received: from delta (208-91-20-31.ftth.glasoperator.nl [31.20.91.208]) by mail.mmer.org (OpenSMTPD) with ESMTPSA id b352b3c6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <77204@debbugs.gnu.org>; Thu, 8 May 2025 17:50:22 +0000 (UTC) Date: Thu, 8 May 2025 19:47:41 +0200 Message-ID: <50e5cf5522a10bc4f438d33847d01b5e6adfe676.1746726463.git.levenson@mmer.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 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: , Reply-to: Alexey Abramov X-ACL-Warn: , Alexey Abramov via Guix-patches X-Patchwork-Original-From: Alexey Abramov via Guix-patches via From: Alexey Abramov 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/dns.scm ()[provision]: Mark filed as deprecated with a warning. Set default to #f. [shepherd-provision]: Add new field for consistency with other services. [shepherd-requirement]: Add new field. (dnsmasq-shepherd-service): Use them * doc/guix.texi: Document these changes. * doc/guix-cookbook.texi (Custom NAT-based network for libvirt): Update example to use 'shepherd-provision' instead of 'provision'. --- doc/guix-cookbook.texi | 4 ++-- doc/guix.texi | 11 ++++++++--- gnu/services/dns.scm | 24 ++++++++++++++++++++---- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi index fb58866d404..3ebe661a078 100644 --- a/doc/guix-cookbook.texi +++ b/doc/guix-cookbook.texi @@ -4018,8 +4018,8 @@ Custom NAT-based network for libvirt (service dnsmasq-service-type (dnsmasq-configuration ;; You can have multiple instances of `dnsmasq-service-type` as long - ;; as each one has a different provision. - (provision '(dnsmasq-virbr0)) + ;; as each one has a different shepherd-provision. + (shepherd-provision '(dnsmasq-virbr0)) (extra-options (list ;; Only bind to the virtual bridge. This ;; avoids conflicts with other running diff --git a/doc/guix.texi b/doc/guix.texi index 889eab2ab35..279bbda9ac4 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36086,9 +36086,14 @@ DNS Services @item @code{package} (default: @var{dnsmasq}) Package object of the dnsmasq server. -@item @code{provision} (default: @code{'(dnsmasq)}) -A list of symbols for the Shepherd service corresponding to this dnsmasq -configuration. +@item @code{shepherd-provision} (default: @code{'(dnsmasq)}) +@itemx @code{shepherd-requirement} (default: @code{'(user-processes networking)}) +This option can be used to provide a list of Shepherd service names +(symbols) provided by this service. You might want to change the default +value if you intend to run several @command{dnsmasq} instances. + +Likewise, @code{shepherd-requirement} is a list of Shepherd service names +(symbols) that this service will depend on. @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index 05291eb65d9..fd849d08e89 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -27,6 +27,7 @@ (define-module (gnu services dns) #:use-module (gnu system shadow) #:use-module (gnu packages admin) #:use-module (gnu packages dns) + #:use-module (guix deprecation) #:use-module (guix packages) #:use-module (guix records) #:use-module (guix gexp) @@ -742,8 +743,13 @@ (define-record-type* dnsmasq-configuration? (package dnsmasq-configuration-package (default dnsmasq)) ;file-like - (provision dnsmasq-provision - (default '(dnsmasq))) + (provision dnsmasq-configuration-provision ; deprecated + (default #f) + (sanitize warn-deprecated-dnsmasq-configuration-provision)) + (shepherd-provision dnsmasq-configuration-shepherd-provision + (default '(dnsmasq))) + (shepherd-requirement dnsmasq-configuration-shepherd-requirement + (default '(user-processes networking))) (no-hosts? dnsmasq-configuration-no-hosts? (default #f)) ;boolean (port dnsmasq-configuration-port @@ -799,9 +805,19 @@ (define-record-type* (tftp-unique-root dnsmasq-tftp-unique-root (default #f))) ;"" or "ip" or "mac" +(define (warn-deprecated-dnsmasq-configuration-provision value) + (when (pair? value) + (warn-about-deprecation + 'provision #f + #:replacement 'shepherd-provision)) + value) + (define (dnsmasq-shepherd-service config) (match-record config (package + provision + shepherd-provision + shepherd-requirement no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -815,8 +831,8 @@ (define (dnsmasq-shepherd-service config) tftp-lowercase? tftp-port-range tftp-root tftp-unique-root extra-options) (shepherd-service - (provision (dnsmasq-provision config)) - (requirement '(user-processes networking)) + (provision (or provision shepherd-provision)) + (requirement shepherd-requirement) (documentation "Run the dnsmasq DNS server.") (start #~(make-forkexec-constructor (list From patchwork Thu May 8 17:47:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Abramov X-Patchwork-Id: 42468 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 A9DB427BC4B; Thu, 8 May 2025 18:51:57 +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=-7.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED 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 05A7F27BC49 for ; Thu, 8 May 2025 18:51:57 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uD5P4-0005V5-Fw; Thu, 08 May 2025 13:51:26 -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 1uD5Ok-0005EE-Ro for guix-patches@gnu.org; Thu, 08 May 2025 13:51:17 -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 1uD5Oi-0001uy-Hp; Thu, 08 May 2025 13:51:06 -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:References:In-Reply-To:Date:From:To:Subject; bh=wtXMBfN89GcdD1Or4Krpe1WprmvjScZ+ZrlKeZywpi0=; b=oxk5lIXv/a32Fb14Zo3nRhDxIO6dkN5z65te2Ud+q7/86CN8V+7sfSWw4YY2GwNPO5mfQRhno1xhXtKn7yp5RqU4KX2xMzgsultVL1q+s6hDwcU/mOii/+TDyf6dyvl8E2VLFPA++mLEAt+kUKDsDQxZFzae6fNFgGCEUOrZcv/kAJwB5H9Y5oFViU+V1B02r19HZzahxD+nAAhwehEB6c8JDwohv7JvL8YTI2N+mYUuHjAtQUpbRw7nWqNZ17IvM434GZ56DkxlDqA0GWv5wHUeZapqIGKkYosDmVRlg+KVB2E1sdXr7jDU87+0FQf888d3Q/5MPYADgxFRS/mFxg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uD5Oh-0007gJ-8j; Thu, 08 May 2025 13:51:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77204] [PATCH v4 2/3] services: dnsmasq: Add pid-file, conf-file and conf-dir configuration fields. Resent-From: Alexey Abramov Original-Sender: "Debbugs-submit" Resent-CC: gabriel@erlikon.ch, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Thu, 08 May 2025 17:51:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77204 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77204@debbugs.gnu.org Cc: Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 77204-submit@debbugs.gnu.org id=B77204.174672663829439 (code B ref 77204); Thu, 08 May 2025 17:51:03 +0000 Received: (at 77204) by debbugs.gnu.org; 8 May 2025 17:50:38 +0000 Received: from localhost ([127.0.0.1]:59719 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uD5OH-0007ei-8C for submit@debbugs.gnu.org; Thu, 08 May 2025 13:50:37 -0400 Received: from mail.mmer.org ([178.22.65.174]:51192) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uD5OD-0007dp-4w for 77204@debbugs.gnu.org; Thu, 08 May 2025 13:50:34 -0400 Received: from mail.mmer.org (localhost [127.0.0.1]) by mail.mmer.org (OpenSMTPD) with ESMTP id 17053eea for <77204@debbugs.gnu.org>; Thu, 8 May 2025 17:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=mmer.org; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=dkim; bh=mqVb+k7Gc2KNY5iCWfTvZI8Qf cm/xmU4sjQE7+WttJQ=; b=rFAwixrnzabSslFJ4X3TYXLVMSdsM6rjH3dJ1HqhU o8Kq3YZ3Qku1SNnHaWnLFEGLw0Zk5ITHJd03s4s41HWdWiaZEnpw2JpnDH66oBH9 6Ak19OufFSKoU8I+kRA+ek9NCASOXjTGAg3/RNCsUUNN7NN57bp+UQ49iF6Nc+bt AA= Received: from delta (208-91-20-31.ftth.glasoperator.nl [31.20.91.208]) by mail.mmer.org (OpenSMTPD) with ESMTPSA id 217c7244 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <77204@debbugs.gnu.org>; Thu, 8 May 2025 17:50:23 +0000 (UTC) Date: Thu, 8 May 2025 19:47:42 +0200 Message-ID: <7546c2197d7d36a1a8682823cd5c6224e475addc.1746726463.git.levenson@mmer.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 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: , Reply-to: Alexey Abramov X-ACL-Warn: , Alexey Abramov via Guix-patches X-Patchwork-Original-From: Alexey Abramov via Guix-patches via From: Alexey Abramov 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/dns.scm ()[pid-file]: New field to specify alternate path for dnsmasq PID. [conf-file]: New field to specify one or more configuration files. [conf-dir]: New field to read configuration files from a directory. [extra-options]: Move to the end of the definition as a last resort option. (dnsmasq-shepherd-service): Use new fields instead of hardcoded values. * gnu/services/dns.scm: Export all record accessors. * doc/guix.texi: Document new configuration options. --- doc/guix.texi | 15 ++++++++++++ gnu/services/dns.scm | 58 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 279bbda9ac4..ec096643eaa 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36095,6 +36095,9 @@ DNS Services Likewise, @code{shepherd-requirement} is a list of Shepherd service names (symbols) that this service will depend on. +@item @code{pid-file} (default: @code{"/run/dnsmasq.pid"}) +Specify an alternate path for dnsmasq to record its process-id in. + @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. @@ -36215,6 +36218,18 @@ DNS Services resolving MAC addresses is only possible if the client is in the local network or obtained a DHCP lease from dnsmasq. +@item @code{conf-file} (default: @code{'()}) +Specify a configuration file or multiple. The given value should be a +list of string paths to the configuration files. File-like objects are +also supported. + +@item @code{conf-dir} (default: @code{#f}) +Read all the files in the given directory as configuration files. +@command{dnsmasq} also supports extensions for the field, but here it is +not implemented. It is more convenient to make @code{computed-file} +directory in the store and use that. Files are loaded in alphabetical +order of filename. + @item @code{extra-options} (default: @code{'()}) This option provides an ``escape hatch'' for the user to provide arbitrary command-line arguments to @command{dnsmasq} as a list of strings. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index fd849d08e89..d55ee3e4fcb 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -55,6 +55,38 @@ (define-module (gnu services dns) dnsmasq-service-type dnsmasq-configuration + dnsmasq-configuration-package + dnsmasq-configuration-shepherd-provision + dnsmasq-configuration-shepherd-requirement + dnsmasq-configuration-pid-file + dnsmasq-configuration-no-hosts? + dnsmasq-configuration-port + dnsmasq-configuration-local-service? + dnsmasq-configuration-listen-address + dnsmasq-configuration-resolv-file + dnsmasq-configuration-no-resolv? + dnsmasq-configuration-forward-private-reverse-lookup? + dnsmasq-configuration-query-servers-in-order? + dnsmasq-configuration-servers + dnsmasq-configuration-servers-file + dnsmasq-configuration-addresses + dnsmasq-configuration-cache-size + dnsmasq-configuration-negative-cache? + dnsmasq-configuration-cpe-id + dnsmasq-configuration-tftp-enable? + dnsmasq-configuration-tftp-no-fail? + dnsmasq-configuration-tftp-single-port? + dnsmasq-tftp-secure? + dnsmasq-tftp-max + dnsmasq-tftp-mtu + dnsmasq-tftp-no-blocksize? + dnsmasq-tftp-lowercase? + dnsmasq-tftp-port-range + dnsmasq-tftp-root + dnsmasq-tftp-unique-root + dnsmasq-configuration-conf-file + dnsmasq-configuration-conf-dir + dnsmasq-configuration-extra-options unbound-service-type unbound-configuration @@ -752,14 +784,14 @@ (define-record-type* (default '(user-processes networking))) (no-hosts? dnsmasq-configuration-no-hosts? (default #f)) ;boolean + (pid-file dnsmasq-configuration-pid-file + (default "/run/dnsmasq.pid")) ;string (port dnsmasq-configuration-port (default 53)) ;integer (local-service? dnsmasq-configuration-local-service? (default #t)) ;boolean (listen-addresses dnsmasq-configuration-listen-address (default '())) ;list of string - (extra-options dnsmasq-configuration-extra-options - (default '())) ;list of string (resolv-file dnsmasq-configuration-resolv-file (default "/etc/resolv.conf")) ;string (no-resolv? dnsmasq-configuration-no-resolv? @@ -803,7 +835,13 @@ (define-record-type* (tftp-root dnsmasq-tftp-root (default "/var/empty,lo")) ;string (tftp-unique-root dnsmasq-tftp-unique-root - (default #f))) ;"" or "ip" or "mac" + (default #f)) ;"" or "ip" or "mac" + (conf-file dnsmasq-configuration-conf-file + (default '())) ;list of string|file-like + (conf-dir dnsmasq-configuration-conf-dir + (default #f)) ;string|file-like + (extra-options dnsmasq-configuration-extra-options + (default '()))) ;list of string (define (warn-deprecated-dnsmasq-configuration-provision value) (when (pair? value) @@ -818,6 +856,7 @@ (define (dnsmasq-shepherd-service config) provision shepherd-provision shepherd-requirement + pid-file no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -829,7 +868,8 @@ (define (dnsmasq-shepherd-service config) tftp-single-port? tftp-secure? tftp-max tftp-mtu tftp-no-blocksize? tftp-lowercase? tftp-port-range - tftp-root tftp-unique-root extra-options) + tftp-root tftp-unique-root + conf-file conf-dir extra-options) (shepherd-service (provision (or provision shepherd-provision)) (requirement shepherd-requirement) @@ -838,7 +878,7 @@ (define (dnsmasq-shepherd-service config) (list #$(file-append package "/sbin/dnsmasq") "--keep-in-foreground" - "--pid-file=/run/dnsmasq.pid" + (string-append "--pid-file=" #$pid-file) #$@(if no-hosts? '("--no-hosts") '()) @@ -909,8 +949,14 @@ (define (dnsmasq-shepherd-service config) (format #f "--tftp-unique-root=~a" tftp-unique-root) (format #f "--tftp-unique-root"))) '()) + #$@(map (lambda (conf-file) + #~(string-append "--conf-file=" #$conf-file)) + conf-file) + #$@(if conf-dir + (list #~(string-append "--conf-dir=" #$conf-dir)) + '()) #$@extra-options) - #:pid-file "/run/dnsmasq.pid")) + #:pid-file #$pid-file)) (stop #~(make-kill-destructor))))) (define (dnsmasq-activation config) From patchwork Thu May 8 17:47:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Abramov X-Patchwork-Id: 42466 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 2866627BC4D; Thu, 8 May 2025 18:51:40 +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=-7.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED 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 3312627BC49 for ; Thu, 8 May 2025 18:51:36 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uD5P2-0005QZ-Ov; Thu, 08 May 2025 13:51:25 -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 1uD5Oj-0005Di-Il for guix-patches@gnu.org; Thu, 08 May 2025 13:51:12 -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 1uD5Oh-0001ur-Uo; Thu, 08 May 2025 13:51:04 -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:References:In-Reply-To:Date:From:To:Subject; bh=YbrxUh/HT77zH5g0OEdWMWI+E/t1u8bYxuTaI2+WAkw=; b=uWvVlgScWH70Xyo+2IE6bNNqd6H8RDQQVpFeHkW9tISMwhyzWZX12SMxi0i1XGb5XP54bQSqQVPP+oRSTI2tYds2Pvkigv/+MGG9ldqiX5Eht0NWBNGaaRWpYczW6ixEdrd3nsV+3Cj8zFjPeAJ9By59Sszkt7fn5iiIhnmpfLr6KgLx3yLs7MSwoucJ+JGiC+iGkALyDMTiti2AtxE17WNNc2pqIZCRMkT5mrtvb2Mu/DJ20G6hZpK4nOrfCQr9gUrtRZQUdAa/cT4x3QEHb3tQH/GpnS2p9NdVUnUNo6WUMgJzeKikrpBrTQhiDfz9be4ioHLO1HjVBgg92EP59w==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uD5Oh-0007gU-NH; Thu, 08 May 2025 13:51:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77204] [PATCH v4 3/3] services: dnsmasq: Add stats and reload shepherd actions. Resent-From: Alexey Abramov Original-Sender: "Debbugs-submit" Resent-CC: gabriel@erlikon.ch, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Thu, 08 May 2025 17:51:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77204 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77204@debbugs.gnu.org Cc: Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 77204-submit@debbugs.gnu.org id=B77204.174672663829445 (code B ref 77204); Thu, 08 May 2025 17:51:03 +0000 Received: (at 77204) by debbugs.gnu.org; 8 May 2025 17:50:38 +0000 Received: from localhost ([127.0.0.1]:59721 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uD5OH-0007em-RI for submit@debbugs.gnu.org; Thu, 08 May 2025 13:50:38 -0400 Received: from mail.mmer.org ([178.22.65.174]:51192) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uD5OE-0007dp-CL for 77204@debbugs.gnu.org; Thu, 08 May 2025 13:50:35 -0400 Received: from mail.mmer.org (localhost [127.0.0.1]) by mail.mmer.org (OpenSMTPD) with ESMTP id 56ba2924 for <77204@debbugs.gnu.org>; Thu, 8 May 2025 17:50:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=mmer.org; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=dkim; bh=hjkpYhLz3nO4nCid3HAjVGLsZ I5kVK+2gr7GZ/FyksU=; b=Jv1fHwvTf+0hjqTvN+vxdszLixw8GKlOQNQPOMBo6 PvwR3QcbhNv7D5yS+X81IYLjI4FYt+8CrjRko3YH3CC+5lA3Zot1uqjpqQV3afmH Rwul1pd8BXMpm7UVza2EXHIsxxHtsWiq2o7z97TKGWnkxYfFjDU/DFu83DxufIFB Qs= Received: from delta (208-91-20-31.ftth.glasoperator.nl [31.20.91.208]) by mail.mmer.org (OpenSMTPD) with ESMTPSA id fc22e554 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <77204@debbugs.gnu.org>; Thu, 8 May 2025 17:50:23 +0000 (UTC) Date: Thu, 8 May 2025 19:47:43 +0200 Message-ID: <0780b834d037ca669f1f6edfb67b4b671aac8d58.1746726463.git.levenson@mmer.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 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: , Reply-to: Alexey Abramov X-ACL-Warn: , Alexey Abramov via Guix-patches X-Patchwork-Original-From: Alexey Abramov via Guix-patches via From: Alexey Abramov 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/dns.scm (dnsmasq-service-reload-action): New function. Implements SIGHUP handling for reloading configurations. (dnsmasq-service-stats-action): New function. Implements SIGUSR1 handling for dumping statistics. (dnsmasq-shepherd-service): Use new actions. * doc/guix.texi: Document new actions with examples. * gnu/tests/networking.scm (%test-dnsmasq): Add tests to verify the functionality of new actions. --- doc/guix.texi | 52 +++++++++++++++++++++ gnu/services/dns.scm | 22 +++++++++ gnu/tests/networking.scm | 98 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index ec096643eaa..fa34eb4a8bc 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36077,6 +36077,58 @@ DNS Services (no-resolv? #t) (servers '("192.168.1.1")))) @end lisp + +@code{dnsmasq-service-type} provides two actions: + +@table @code +@item reload +Send a @code{SIGHUP} signal to @command{dnsmasq} to clear cache and +reload hosts files which triggers the following actions: + +@itemize @bullet +@item +Clears the DNS cache +@item +Reloads @file{/etc/hosts} and @file{/etc/ethers} +@item +Reloads files specified by @option{--dhcp-hostsfile}, @option{--dhcp-hostsdir}, +@option{--dhcp-optsfile}, @option{--dhcp-optsdir}, @option{--addn-hosts}, +or @option{--hostsdir} +@item +Executes DHCP lease change scripts for all existing leases +@item +Rereads @file{/etc/resolv.conf} (only if @option{--no-poll} is configured) +@end itemize + +@emph{Note:} The @code{SIGHUP} signal does not trigger a reread of the main +configuration file. + +Example usage: +@example +herd reload dnsmasq +@end example + +@item stats +When @command{dnsmasq} receives a @code{SIGUSR1} signal, it writes +statistics to the system log including: + +@itemize @bullet +@item +Cache size and number of evicted entries +@item +Cache hits, misses, and authoritative queries answered +@item +For each upstream server: queries sent and errors received +@item +TCP connection fork statistics +@end itemize + +Example usage: +@example +herd stats dnsmasq +@end example +@end table + @end defvar @deftp {Data Type} dnsmasq-configuration diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index d55ee3e4fcb..9a9b78d877b 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -874,6 +874,8 @@ (define (dnsmasq-shepherd-service config) (provision (or provision shepherd-provision)) (requirement shepherd-requirement) (documentation "Run the dnsmasq DNS server.") + (actions (list (dnsmasq-service-reload-action config) + (dnsmasq-service-stats-action config))) (start #~(make-forkexec-constructor (list #$(file-append package "/sbin/dnsmasq") @@ -965,6 +967,26 @@ (define (dnsmasq-activation config) ;; create directory to store dnsmasq lease file (mkdir-p "/var/lib/misc"))) +(define (dnsmasq-service-reload-action config) + (match-record config () + (shepherd-action + (name 'reload) + (documentation "Send a @code{SIGHUP} signal to @command{dnsmasq} to clear +cache and reload hosts files.") + (procedure #~(lambda (running) + (let ((pid (process-id running))) + (kill pid SIGHUP))))))) + +(define (dnsmasq-service-stats-action config) + (match-record config () + (shepherd-action + (name 'stats) + (documentation "Send a @code{SIGUSR1} to write statistics to the system +log.") + (procedure #~(lambda (running) + (let ((pid (process-id running))) + (kill pid SIGUSR1))))))) + (define dnsmasq-service-type (service-type (name 'dnsmasq) diff --git a/gnu/tests/networking.scm b/gnu/tests/networking.scm index 7d54ebba50e..fdc515ceb04 100644 --- a/gnu/tests/networking.scm +++ b/gnu/tests/networking.scm @@ -27,6 +27,7 @@ (define-module (gnu tests networking) #:use-module (gnu system vm) #:use-module (gnu services) #:use-module (gnu services base) + #:use-module (gnu services dns) #:use-module (gnu services networking) #:use-module (guix gexp) #:use-module (guix store) @@ -46,6 +47,7 @@ (define-module (gnu tests networking) %test-openvswitch %test-dhcpd %test-dhcpcd + %test-dnsmasq %test-tor %test-iptables %test-ipfs)) @@ -675,6 +677,102 @@ (define %test-dhcpd (description "Test a running DHCP daemon configuration.") (value (run-dhcpd-test)))) + + +;;; +;;; dnsmasq tests +;;; + + +(define dnsmasq-os-configuration + (dnsmasq-configuration)) + +(define %dnsmasq-os + (simple-operating-system + (service dhcp-client-service-type) + (service dnsmasq-service-type + (dnsmasq-configuration + (extra-options + (list "--log-facility=/tmp/dnsmasq.log")))))) + + +(define (run-dnsmasq-test) + (define os + (marionette-operating-system %dnsmasq-os + #:imported-modules '((gnu services herd)))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-64)) + + (define marionette + (make-marionette (list #$(virtual-machine os)))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "dnsmasq") + + (test-assert "dnsmasq is alive" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (wait-for-service 'dnsmasq)) + marionette)) + + (test-assert "pid file exists" + (wait-for-file + '#$(dnsmasq-configuration-pid-file dnsmasq-os-configuration) + marionette)) + + (test-assert "send SIGHUP" + (positive? + (marionette-eval + '(begin + (use-modules (ice-9 rdelim)) + (system* "sync") + (let* ((port (open-input-file "/tmp/dnsmasq.log"))) + (seek port 0 SEEK_END) + (system* "herd" "reload" "dnsmasq") + (system* "sync") + (let ((line (read-line port))) + (close-port port) + (string-contains line "read /etc/hosts")))) + marionette))) + + (test-assert "send SIGUSR1" + (positive? + (marionette-eval + '(begin + (use-modules (ice-9 rdelim)) + (system* "sync") + (let* ((port (open-input-file "/tmp/dnsmasq.log"))) + (seek port 0 SEEK_END) + (system* "herd" "stats" "dnsmasq") + (system* "sync") + (let ((line (read-line port))) + (close-port port) + (string-contains-ci line "time")))) + marionette))) + + (test-assert "dnsmasq is alive" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (wait-for-service 'dnsmasq)) + marionette)) + + (test-end)))) + + (gexp->derivation "dnsmasq-test" test)) + +(define %test-dnsmasq + (system-test + (name "dnsmasq") + (description "Test a running dnsmasq daemon configuration.") + (value (run-dnsmasq-test)))) + + ;;; ;;; DHCPCD Daemon