From ac94edd8992987270ab0ecf1019dd2452d4b0e8b Mon Sep 17 00:00:00 2001
From: Gabriel Wicki <gabriel@erlikon.ch>
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        | 39 +++++++++++++++++++++++++++
 gnu/services/dns.scm | 63 ++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 05615b9549..d7f63e711b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -114,6 +114,7 @@ Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@*
 Copyright @copyright{} 2023 Giacomo Leidi@*
 Copyright @copyright{} 2022 Antero Mejr@*
 Copyright @copyright{} 2023 Bruno Victal@*
+Copyright @copyright{} 2023 Gabriel Wicki@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -31317,6 +31318,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{#t})
+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{192.0.2.50,192.0.2.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..d4b9a78c7a 100644
--- a/gnu/services/dns.scm
+++ b/gnu/services/dns.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2020 Pierre Langlois <pierre.langlois@gmx.com>
 ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
 ;;; Copyright © 2022 Remco van 't Veer <remco@remworks.net>
+;;; Copyright © 2023 Gabriel Wicki <gabriel@erlikon.ch>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -749,8 +750,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 +762,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 +817,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 +865,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

