system-configuration/modules/config/dns.scm

dns.scm

1
;;; Tyreunom's system administration and configuration tools.
2
;;;
3
;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
4
;;;
5
;;; This program is free software: you can redistribute it and/or modify
6
;;; it under the terms of the GNU General Public License as published by
7
;;; the Free Software Foundation, either version 3 of the License, or
8
;;; (at your option) any later version.
9
;;;
10
;;; This program is distributed in the hope that it will be useful,
11
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
;;; GNU General Public License for more details.
14
;;;
15
;;; You should have received a copy of the GNU General Public License
16
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
;;
19
;; DNS services
20
;;
21
22
(define-module (config dns)
23
  #:use-module (data dns)
24
  #:use-module (gnu services)
25
  #:use-module (gnu services dns)
26
  #:use-module (srfi srfi-1)
27
  #:export (ipv4-reverse-master-zone
28
            ipv6-reverse-master-zone
29
            lepiller-master-zone
30
	    master-acl
31
	    slave-acl
32
	    hermes
33
	    ene))
34
35
(define-zone-entries lepiller.eu.zone
36
;; Name         TTL Class Type Data
37
  ("ene"        ""  "IN"  "A"     ene-ip4)
38
  ("hermes"     ""  "IN"  "A"     hermes-ip4)
39
  ("hermes"     ""  "IN"  "AAAA"  hermes-ip6)
40
  ("xana"       ""  "IN"  "A"     xana-ip4)
41
  ("@"          ""  "IN"  "A"     hermes-ip4)
42
  ("@"          ""  "IN"  "AAAA"  hermes-ip6)
43
  ("www"        ""  "IN"  "CNAME" "lepiller.eu.")
44
45
  ("avatar"     ""  "IN"  "CNAME" "ene")
46
  ("rennes"     ""  "IN"  "CNAME" "ene")
47
  ("nani"       ""  "IN"  "CNAME" "xana")
48
  ("i18n"       ""  "IN"  "CNAME" "xana")
49
50
  ("@"          ""  "IN"  "NS"    "ns")
51
  ("@"          ""  "IN"  "NS"    "ns2")
52
  ("ns"         ""  "IN"  "A"     hermes-ip4)
53
  ("ns"         ""  "IN"  "AAAA"  hermes-ip6)
54
  ("ns2"        ""  "IN"  "A"     ene-ip4)
55
56
  ("@"          ""  "IN"  "MX"    "10 courriel")
57
  ("@"          ""  "IN"  "MX"    "50 b.courriel")
58
  ("b.courriel" ""  "IN"  "A"     hermes-ip4)
59
  ("b.courriel" ""  "IN"  "AAAA"  hermes-ip6)
60
  ("courriel"   ""  "IN"  "A"     ene-ip4)
61
  ("imap"       ""  "IN"  "CNAME" "courriel")
62
  ("smtp"       ""  "IN"  "CNAME" "b.courriel")
63
  ("@"          ""  "IN"  "TXT"   "v=spf1 mx a ~all")
64
  ("@"          ""  "IN"  "SPF"   "v=spf1 mx a ~all"))
65
66
(define-zone-entries ipv4-reverse.zone
67
  ("@" "" "IN" "PTR" "lepiller.eu.")
68
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
69
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
70
71
(define-zone-entries ipv6-reverse.zone
72
  ("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" "" "IN" "PTR" "lepiller.eu.")
73
  ("@"          ""  "IN"  "NS"    "ns.lepiller.eu.")
74
  ("@"          ""  "IN"  "NS"    "ns2.lepiller.eu."))
75
76
(define ene
77
  (knot-remote-configuration
78
    (id "ene")
79
    (address (list ene-ip4))
80
    (key "lepiller-key")))
81
82
(define hermes
83
  (knot-remote-configuration
84
    (id "hermes")
85
    (address (list hermes-ip4))
86
    (key "lepiller-key")))
87
88
(define master-acl
89
  (knot-acl-configuration
90
    (id "master-acl")
91
    (address (list hermes-ip4))
92
    (key '("lepiller-key"))
93
    (action '(transfer))))
94
95
(define slave-acl
96
  (knot-acl-configuration
97
    (id "master-acl")
98
    (address (list ene-ip4))
99
    (key '("lepiller-key"))
100
    (action '(notify))))
101
102
(define lepiller-master-zone
103
  (knot-zone-configuration
104
    (domain "lepiller.eu")
105
    (notify '("hermes"))
106
    (dnssec-policy "default")
107
    (acl '("master-acl"))
108
    (zonefile-load 'difference)
109
    (zone (zone-file
110
            (origin "lepiller.eu")
111
            (entries lepiller.eu.zone)
112
            (serial 2019041202)))))
113
114
(define lepiller-slave-zone
115
  (knot-zone-configuration
116
    (domain "lepiller.eu")
117
    (acl '("slave-acl"))
118
    (master '("ene"))))
119
120
(define ipv6-reverse-master-zone
121
  (let* ((ip6 (string->list (substring (string-delete hermes-ip6 #\:) 0 12)))
122
         (rev-ip6-lst (fold (lambda (elem acc)
123
                          (cons* #\. elem acc))
124
                        '()
125
                        ip6))
126
         (rev-ip6 (list->string (cdr rev-ip6-lst)))
127
         (domain (string-append rev-ip6 ".ip6.arpa")))
128
    (knot-zone-configuration
129
      (domain domain)
130
      (zone (zone-file
131
              (origin domain)
132
              (entries ipv6-reverse.zone)
133
              (ns "ns.lepiller.eu.")
134
              (mail "hostmaster.lepiller.eu.")
135
              (serial 1))))))
136
137
(define ipv4-reverse-master-zone
138
  (let ((domain (string-append
139
                  (string-join (reverse (string-split hermes-ip4 #\.)) ".")
140
                  ".in-addr.arpa")))
141
    (knot-zone-configuration
142
      (domain domain)
143
      (zone (zone-file
144
              (origin domain)
145
              (entries ipv4-reverse.zone)
146
              (ns "ns.lepiller.eu.")
147
              (mail "hostmaster.lepiller.eu.")
148
              (serial 1))))))
149