3 ### Makefile for the DNS zones I maintain.
5 ### (c) 2011 Mark Wooding
7 ###--------------------------------------------------------------------------
8 ### Silent-rules machinery.
11 v_tag = $(call v_tag_$V,$1)
12 v_tag_0 = @printf " %-6s %s\n" "$1" "$@";
17 ###--------------------------------------------------------------------------
18 ### Programs and options.
21 CHECKZONE = named-checkzone -i full \
22 -k fail -M fail -n fail -S fail -W fail
26 inside_MASTER = precision
28 ifeq ($(MASTER),localhost)
29 ZONEINST = userv zoneconf install
31 ZONEINST = ssh zoneconf@$(MASTER)
34 ###--------------------------------------------------------------------------
35 ### Utility functions.
37 dir-nosl = $(patsubst %/,%,$(dir $1))
39 ###--------------------------------------------------------------------------
40 ### Keeping all of the files straight.
42 ## Establish a default target. We'll sort out what it does later.
49 REALCLEANFILES = $(CLEANFILES)
50 REALCLEANDIRS = $(CLEANDIRS)
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.
59 ###--------------------------------------------------------------------------
60 ### The distorted.org.uk zones.
64 distorted_VIEWS = inside outside
65 distorted_outside_NETS = dmz jump
66 distorted_inside_NETS = any unsafe colo vpn nvpn upn nupn
68 distorted_all_ZONES += distorted.org.uk
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.12.169.217.in-addr.arpa
73 distorted_all_ZONES += 64-79.198.13.212.in-addr.arpa
75 distorted_all_ZONES += 199.29.172.in-addr.arpa
77 distorted_all_ZONES += 9.d.1.0.0.0.0.0.8.a.b.0.1.0.0.2.ip6.arpa
78 distorted_all_ZONES += 2.9.c.0.0.b.8.0.1.0.0.2.ip6.arpa
79 distorted_all_ZONES += 9.d.1.0.8.a.b.0.1.0.0.2.ip6.arpa
81 distorted_outside_NSDIFF = -sradius.dmz.distorted.org.uk
83 ###--------------------------------------------------------------------------
88 binswood_VIEWS = outside
89 binswood_all_ZONES += binswood.org.uk
90 binswood_all_ZONES += 27.165.10.in-addr.arpa
94 escorted_VIEWS = outside
95 escorted_all_ZONES += escorted.org.uk
100 odin_all_ZONES = odin.gg
102 ###--------------------------------------------------------------------------
103 ### Zone construction machinery.
106 V_ZONE = $(call v_tag,ZONE)$(ZONE)
108 .SECONDEXPANSION: #sorry
110 ## For each net/zoneset pair, we make a stamp file net/zoneset.stamp to
111 ## remember that we've made the corresponding zones.
112 ALL_ZONESTAMPS = $(foreach s,$(ZONESETS), \
113 $(patsubst %,%/$s.zonestamp,$($s_VIEWS)))
114 $(ALL_ZONESTAMPS) : %.zonestamp : $$(notdir $$*).lisp hosts.lisp
115 $(V_AT)mkdir -p $(dir $*)
116 $(V_ZONE) -d$(dir $*) -fview/$(call dir-nosl,$*)$(hack \
117 hack) $(addprefix -s, \
118 $($(notdir $*)_$(call dir-nosl,$*)_NETS)) $<
120 all: $(ALL_ZONESTAMPS)
121 CLEANFILES += $(sort $(foreach s,$(ZONESETS), \
122 $(foreach v,$($s_VIEWS), \
123 $v/*.zonestamp $v/*.zone)))
124 REALCLEANFILES += $(sort $(foreach s,$(ZONESETS), \
125 $(foreach v,$($s_VIEWS), \
127 REALCLEANDIRS += $(sort $(foreach s,$(ZONESETS),$($s_VIEWS)))
129 ## Now explain that each generated zone file depends on the corresponding
130 ## zonestamp. This is where things start getting a little hairy.
131 $(foreach s,$(ZONESETS), \
132 $(foreach v,$($s_VIEWS), \
133 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
134 $(eval $v/$z.zone: $v/$s.zonestamp))))
136 ## Prepare a mapping from zone names back to their owning zonesets.
137 $(foreach s,$(ZONESETS), \
138 $(foreach z,$(sort $(foreach v,$($s_VIEWS), \
139 $($s_all_ZONES) $($s_$v_ZONES))), \
140 $(eval $z_ZONESET = $s)))
142 ## Now we have to check the individual zone files.
143 ALL_ZONECHECKS = $(foreach s,$(ZONESETS), \
144 $(foreach v,$($s_VIEWS), \
145 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
147 $(ALL_ZONECHECKS) : %.check : %.zone
149 { $(CHECKZONE) $(notdir $*) $^ || kill $$$$; } | \
150 { grep -Ev 'loaded serial|OK' || :; }
151 check: $(ALL_ZONECHECKS)
152 .PHONY: check $(ALL_ZONECHECKS)
154 ## If nsdiff(1) is available then we can show what changes we will make if
155 ## we install the new zone files.
156 ALL_ZONEDIFFS = $(foreach s,$(ZONESETS), \
157 $(foreach v,$($s_VIEWS), \
158 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
160 run-nsdiff = nsdiff -v "" $2 \
161 $($($(call notdir,$1)_ZONESET)_$(call dir-nosl,$1)_NSDIFF) \
162 $(call notdir,$1) $1.zone
163 $(ALL_ZONEDIFFS) : %.zonediff : %.zone
164 $(call v_tag,NSDIFF)$(call run-nsdiff,$*,-q); \
165 rc=$$?; case $$rc in 1) $(call run-nsdiff,$*); rc=$$? ;; esac; \
166 case $$rc in 0 | 1) : ;; *) exit $$rc ;; esac
167 diff: $(ALL_ZONEDIFFS)
169 ## Finally we have to install the zone files.
170 ALL_INSTALLS = $(foreach s,$(ZONESETS), \
171 $(foreach v,$($s_VIEWS), \
172 $(foreach z,$($s_all_ZONES) $($s_$v_ZONES), \
174 $(ALL_INSTALLS) : %.inst : %.check
175 $(call v_tag,INST)$(ZONEINST) \
176 $(call dir-nosl,$*) $(notdir $*) <$*.zone
177 install: $(ALL_INSTALLS)
178 .PHONY: install $(ALL_INSTALLS)
183 [ "$(CLEANDIRS)x" = x ] || rmdir $(CLEANDIRS) || :
185 rm -f $(REALCLEANFILES)
186 [ "$(REALCLEANDIRS)x" = x ] || rmdir $(REALCLEANDIRS) || :
187 .PHONY: clean realclean
189 ###----- That's all, folks --------------------------------------------------