chiark / gitweb /
distorted.lisp: Include the correct TLSA record details for SMTP.
[zones] / Makefile
1 ### -*-makefile-*-
2 ###
3 ### Makefile for the DNS zones I maintain.
4 ###
5 ### (c) 2011 Mark Wooding
6
7 ###--------------------------------------------------------------------------
8 ### Silent-rules machinery.
9
10 V                        = 0
11 v_tag                    = $(call v_tag_$V,$1)
12 v_tag_0                  = @printf "  %-6s %s\n" "$1" "$@";
13
14 V_AT                     = $(V_AT_$V)
15 V_AT_0                   = @
16
17 ###--------------------------------------------------------------------------
18 ### Programs and options.
19
20 ## Zone checking.
21 CHECKZONE                = named-checkzone -i full \
22                                 -k fail -M fail -n fail -S fail -W fail
23
24 ## Zone installation.
25 MASTER                   = localhost
26 inside_MASTER            = precision
27
28 ifeq ($(MASTER),localhost)
29 ZONEINST                 = userv zoneconf install
30 else
31 ZONEINST                 = ssh zoneconf@$(MASTER)
32 endif
33
34 ###--------------------------------------------------------------------------
35 ### Utility functions.
36
37 dir-nosl = $(patsubst %/,%,$(dir $1))
38
39 ###--------------------------------------------------------------------------
40 ### Keeping all of the files straight.
41
42 ## Establish a default target.  We'll sort out what it does later.
43 all:
44 .PHONY: all
45
46 ## Things to clean.
47 CLEANFILES               =
48 CLEANDIRS                =
49 REALCLEANFILES           = $(CLEANFILES)
50 REALCLEANDIRS            = $(CLEANDIRS)
51
52 ## We work in terms of `zonesets'.  Each one corresponds to a Lisp source
53 ## file to be passed to `zone'.  A zoneset has a number of different nets
54 ## associated with it, in the variable zoneset_NETS, and we must run it
55 ## through `zone' once for each net.  The zoneset will make a number of
56 ## zones, listed in zoneset_ZONES.
57 ZONESETS                 =
58
59 ###--------------------------------------------------------------------------
60 ### The distorted.org.uk zones.
61
62 ZONESETS                += distorted
63
64 distorted_VIEWS          = inside outside
65 distorted_outside_NETS   = dmz jump
66 distorted_inside_NETS    = any unsafe colo vpn upn
67
68 distorted_all_ZONES     += distorted.org.uk
69
70 distorted_all_ZONES     += 195.113.2.81.in-addr.arpa
71 distorted_all_ZONES     += 128-143.238.187.81.in-addr.arpa
72 distorted_all_ZONES     += 64-79.198.13.212.in-addr.arpa
73
74 distorted_all_ZONES     += 199.29.172.in-addr.arpa
75
76 distorted_all_ZONES     += 9.d.1.0.0.0.0.0.8.a.b.0.1.0.0.2.ip6.arpa
77 distorted_all_ZONES     += 2.9.c.0.0.b.8.0.1.0.0.2.ip6.arpa
78 distorted_all_ZONES     += 9.d.1.0.8.a.b.0.1.0.0.2.ip6.arpa
79
80 distorted_outside_NSDIFF = -sradius.dmz.distorted.org.uk
81
82 ###--------------------------------------------------------------------------
83 ### Other zones.
84
85 ## binswood.org.uk
86 ZONESETS                += binswood
87 binswood_VIEWS           = outside
88 binswood_all_ZONES      += binswood.org.uk
89 binswood_all_ZONES      += 27.165.10.in-addr.arpa
90
91 ## escorted.org.uk
92 ZONESETS                += escorted
93 escorted_VIEWS           = outside
94 escorted_all_ZONES      += escorted.org.uk
95
96 ## odin.gg
97 ZONESETS                += odin
98 odin_VIEWS               = outside
99 odin_all_ZONES           = odin.gg
100
101 ###--------------------------------------------------------------------------
102 ### Zone construction machinery.
103
104 ZONE                     = zone
105 V_ZONE                   = $(call v_tag,ZONE)$(ZONE)
106
107 .SECONDEXPANSION: #sorry
108
109 ## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
110 ## remember that we've made the corresponding zones.
111 ALL_ZONESTAMPS = $(foreach s,$(ZONESETS), \
112         $(patsubst %,%/$s.zonestamp,$($s_VIEWS)))
113 $(ALL_ZONESTAMPS) : %.zonestamp : $$(notdir $$*).lisp hosts.lisp
114         $(V_AT)mkdir -p $(dir $*)
115         $(V_ZONE) -d$(dir $*) -fview/$(call dir-nosl,$*)$(hack \
116                 hack) $(addprefix -s, \
117                 $($(notdir $*)_$(call dir-nosl,$*)_NETS)) $<
118         $(V_AT)touch $@
119 all: $(ALL_ZONESTAMPS)
120 CLEANFILES += $(sort $(foreach s,$(ZONESETS), \
121                        $(foreach v,$($s_VIEWS), \
122                          $v/*.zonestamp $v/*.zone)))
123 REALCLEANFILES += $(sort $(foreach s,$(ZONESETS), \
124                            $(foreach v,$($s_VIEWS), \
125                              $v/*.serial)))
126 REALCLEANDIRS += $(sort $(foreach s,$(ZONESETS),$($s_VIEWS)))
127
128 ## Now explain that each generated zone file depends on the corresponding
129 ## zonestamp.  This is where things start getting a little hairy.
130 $(foreach s,$(ZONESETS), \
131   $(foreach v,$($s_VIEWS), \
132     $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
133       $(eval $v/$z.zone: $v/$s.zonestamp))))
134
135 ## Prepare a mapping from zone names back to their owning zonesets.
136 $(foreach s,$(ZONESETS), \
137   $(foreach z,$(sort $(foreach v,$($s_VIEWS), \
138         $($s_all_ZONES) $($s_$v_ZONES))), \
139     $(eval $z_ZONESET = $s)))
140
141 ## Now we have to check the individual zone files.
142 ALL_ZONECHECKS = $(foreach s,$(ZONESETS), \
143         $(foreach v,$($s_VIEWS), \
144           $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
145             $v/$z.check)))
146 $(ALL_ZONECHECKS) : %.check : %.zone
147         $(call v_tag,CHECK)\
148                 { $(CHECKZONE) $(notdir $*) $^ || kill $$$$; } | \
149                 { grep -Ev 'loaded serial|OK' || :; }
150 check: $(ALL_ZONECHECKS)
151 .PHONY: check $(ALL_ZONECHECKS)
152
153 ## If nsdiff(1) is available then we can show what changes we will make if
154 ## we install the new zone files.
155 ALL_ZONEDIFFS = $(foreach s,$(ZONESETS), \
156         $(foreach v,$($s_VIEWS), \
157           $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
158             $v/$z.zonediff)))
159 run-nsdiff = nsdiff -v "" $2 \
160         $($($(call notdir,$1)_ZONESET)_$(call dir-nosl,$1)_NSDIFF) \
161         $(call notdir,$1) $1.zone
162 $(ALL_ZONEDIFFS) : %.zonediff : %.zone
163         $(call v_tag,NSDIFF)$(call run-nsdiff,$*,-q); \
164         rc=$$?; case $$rc in 1) $(call run-nsdiff,$*); rc=$$? ;; esac; \
165         case $$rc in 0 | 1) : ;; *) exit $$rc ;; esac
166 diff: $(ALL_ZONEDIFFS)
167
168 ## Finally we have to install the zone files.
169 ALL_INSTALLS = $(foreach s,$(ZONESETS), \
170         $(foreach v,$($s_VIEWS), \
171           $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
172             $v/$z.inst)))
173 $(ALL_INSTALLS) : %.inst : %.check
174         $(call v_tag,INST)$(ZONEINST) \
175                 $(call dir-nosl,$*) $(notdir $*) <$*.zone
176 install: $(ALL_INSTALLS)
177 .PHONY: install $(ALL_INSTALLS)
178
179 ## Files to clean.
180 clean:
181         rm -f $(CLEANFILES)
182         [ "$(CLEANDIRS)x" = x ] || rmdir $(CLEANDIRS) || :
183 realclean:
184         rm -f $(REALCLEANFILES)
185         [ "$(REALCLEANDIRS)x" = x ] || rmdir $(REALCLEANDIRS) || :
186 .PHONY: clean realclean
187
188 ###----- That's all, folks --------------------------------------------------