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