Subject: [bug#61869] gnu: services: Add more dnsmasq options.

From: "Wicki Gabriel (wicg)" <[email-masked]>
Date: Tue, 28 Feb 2023 13:36:16 +0000

Hi y'all

I've created a patch which adds more options to the dnsmasq service.  Thanks in advance for merging,

g

From bb85650b9bac7afb4a21d483d2bb6249857a02c0 Mon Sep 17 00:00:00 2001
From: gabriel <[email-masked]>
Date: Thu, 23 Feb 2023 16:46:29 +0100
Subject: [PATCH] gnu: services: Add more dnsmasq options.

* gnu/services/dns.scm (dnsmasq-configuration, dnsmasq-shepherd-service): Add
options domain-needed?, bogus-priv?, filterwin2k?, poll?, local, interface,
bind-dynamic?, expand-hosts?, domain, dhcp-range and dhcp-option, as they are
documented in dnsmasq's manual.
* doc/guix.texi (dnsmasq-configuration): Document them.
---
 doc/guix.texi        | 38 +++++++++++++++++++++++++++
 gnu/services/dns.scm | 62 ++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 05615b9549..bab2f5491e 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -31317,6 +31317,44 @@ When false, disable negative caching.
 If set, add a CPE (Customer-Premises Equipment) identifier to DNS
 queries which are forwarded upstream.
 
+@item @code{domain-needed?} (default: @code{#f})
+Whether to forward queries with no domain part.
+
+@item @code{bogus-priv?} (default: @code{#f})
+Whether to fake reverse lookups for RFC1918 private address ranges.
+
+@item @code{filterwin2k?} (default: @code{#f})
+Whether to forward spurious DNS requests from Windows hosts.
+
+@item @code{poll?} (default: @code{#f})
+Continuously reads @file{/etc/resolv.conf} when @code{#true}, otherwise only
+does so on SIGHUP.
+
+@item @code{local} (default: @code{#f})
+A string representing domains where nothing will be forwarded to
+@code{"/domain/"}).
+
+@item @code{interface} (default: @code{#f})
+The interface(s) dnsmasq works on (like @code{"wlp3"} or @code{"lan0"}.
+Multiple names can be specified as strings separated by commas.
+
+@item @code{bind-dynamic?} (default: @code{#f})
+Bind to interfaces in use - check for new interfaces.
+
+@item @code{expand-hosts?} (default: @code{#f})
+Expand simple names in @file{/etc/hosts} with domain-suffix.
+
+@item @code{domain} (default: @code{#f})
+Specify the domain to be assigned in DHCP leases.
+
+@item @code{dhcp-range} (default: @code{#f})
+Enable DHCP in the range given with lease duration, the format is
+@code{<START-IP>,<END-IP>,<MASK>,<LEASE-TIME>}, e.g.
+@code{10.42.0.50,10.42.0.150,255.255.255.0,1h}.
+
+@item @code{dhcp-options} (default: @code{'()})
+A list of options to be passed along.
+
 @item @code{tftp-enable?} (default: @code{#f})
 Whether to enable the built-in TFTP server.
 
diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm
index 50753b7ab6..48fee15192 100644
--- a/gnu/services/dns.scm
+++ b/gnu/services/dns.scm
@@ -749,8 +749,7 @@ (define-record-type* <dnsmasq-configuration>
   (forward-private-reverse-lookup?
                     dnsmasq-configuration-forward-private-reverse-lookup?
                     (default #t))       ;boolean
-  (query-servers-in-order?
-                    dnsmasq-configuration-query-servers-in-order?
+  (query-servers-in-order? dnsmasq-configuration-query-servers-in-order?
                     (default #f))       ;boolean
   (servers          dnsmasq-configuration-servers
                     (default '()))      ;list of string
@@ -762,6 +761,28 @@ (define-record-type* <dnsmasq-configuration>
                     (default #t))       ;boolean
   (cpe-id           dnsmasq-configuration-cpe-id
                     (default #t))       ;string
+  (domain-needed?   dnsmasq-configuration-domain-needed?
+                    (default #f))       ;boolean
+  (bogus-priv?      dnsmasq-configuration-bogus-priv?
+                    (default #f))       ;boolean
+  (filterwin2k?     dnsmasq-configuration-filterwin2k?
+                    (default #f))       ;boolean
+  (poll?            dnsmasq-configuration-poll?
+                    (default #t))       ;boolean
+  (local            dnsmasq-configuration-local
+                    (default #f))       ;string
+  (interface        dnsmasq-configuration-interface
+                    (default #f))       ;string
+  (bind-dynamic?    dnsmasq-configuration-bind-dynamic?
+                    (default #f))       ;boolean
+  (expand-hosts?    dnsmasq-configuration-expand-hosts?
+                    (default #f))       ;boolean
+  (domain           dnsmasq-configuration-domain
+                    (default #f))       ;string
+  (dhcp-range       dnsmasq-configuration-dhcp-range
+                    (default #f))       ;string
+  (dhcp-options      dnsmasq-configuration-dhcp-options
+                    (default '()))      ;list of string
   (tftp-enable?     dnsmasq-configuration-tftp-enable?
                     (default #f))       ;boolean
   (tftp-no-fail?    dnsmasq-configuration-tftp-no-fail?
@@ -795,6 +816,11 @@ (define (dnsmasq-shepherd-service config)
      servers addresses
      cache-size negative-cache?
      cpe-id
+     domain-needed? bogus-priv? filterwin2k? poll?
+     local interface
+     bind-dynamic? expand-hosts?
+     domain
+     dhcp-range dhcp-options
      tftp-enable? tftp-no-fail?
      tftp-single-port? tftp-secure?
      tftp-max tftp-mtu tftp-no-blocksize?
@@ -838,6 +864,38 @@ (define (dnsmasq-shepherd-service config)
                  #$@(if cpe-id
                         (list (format #f "--add-cpe-id=~a" cpe-id))
                         '())
+                 #$@(if domain-needed?
+                        '("--domain-needed")
+                        '())
+                 #$@(if bogus-priv?
+                        '("--bogus-priv")
+                        '())
+                 #$@(if filterwin2k?
+                        '("--filterwin2k")
+                        '())
+                 #$@(if poll?
+                        '()
+                        '("--no-poll"))
+                 #$@(if local
+                        (list (format #f "--local=~a" local))
+                        '())
+                 #$@(if interface
+                        (list (format #f "--interface=~a" interface))
+                        '())
+                 #$@(if bind-dynamic?
+                        '("--bind-dynamic")
+                        '())
+                 #$@(if expand-hosts?
+                        '("--expand-hosts")
+                        '())
+                 #$@(if domain
+                        (list (format #f "--domain=~a" domain))
+                        '())
+                 #$@(if dhcp-range
+                        (list (format #f "--dhcp-range=~a" dhcp-range))
+                        '())
+                 #$@(map (cut format #f "--dhcp-option=~a" <>)
+                      dhcp-options)
                  #$@(if tftp-enable?
                         '("--enable-tftp")
                         '())
-- 
2.39.1