blob: ec45938925a52261b43330e6e6ddd7bc3639f3be [file] [log] [blame]
Serge Bazanski6abe4fa2020-10-03 00:18:34 +02001# Main configuration file for edge01.waw.bgp.wtf.
2# This includes everything needed to run the machine, except for hardware
3# configuration, which is defined in //bgpwtf/machines/
4# edge01.waw.bgp.wtf-hardware.nix.
5#
6# Any changes here can be tested in a local NixOS test by running the following:
7#
8# nix-build -A bgpwtf.machines.tests.edge01-waw
9#
10# To deploy changes, see //ops:machines.nix.
11
12{ config, pkgs, ... }:
13
14with builtins;
15
16let
17 passwords = import ./secrets/plain/passwords.nix;
18
19in rec {
20 networking.hostName = "edge01";
21 networking.domain = "waw.bgp.wtf";
22
23 imports = [
24 ./modules/router.nix
25
26 # Private configuration data - notably, customer data.
27 ./secrets/plain/edge01.waw.bgp.wtf-private.nix
28 ];
29
30 # TODO(q3k): make this generic, move to modules/router.nix.
31 services.unbound = {
32 enable = true;
33 interfaces = [
34 "185.236.240.1"
35 "2a0d:eb00:2137::1"
36 "127.0.0.1"
37 ];
38 allowedAccess = [
39 "185.236.240.0/22"
40 "2a0d:eb00::0/29"
41 "127.0.0.0/8"
42 ];
43 extraConfig = ''
44 outgoing-interface: 185.236.240.1
45 outgoing-interface: 2a0d:eb00:2137::1
46 cache-max-negative-ttl: 30
47
48 # Disable DoH in Firefox
49 local-zone: "use-application-dns.net" static
50
51 # Rejestr Stron Hazardowych.
52 # Populated by the rsh-unbound daemon.
53 include: "/var/lib/unbound/rsh.conf"
54 '';
55 };
56 hscloud.rsh = {
57 enable = true;
58 out = "/var/lib/unbound/rsh.conf";
59 };
60
61 hscloud.renameInterfaces = {
62 # Link to Nitronet CPE.
63 e1-nnet.mac = "ac:1f:6b:1c:d7:ae";
64 # Link to HSWAW Customs.
65 e2-customs.mac = "ac:1f:6b:1c:d7:af";
66 # Link to management switch.
67 e3-mgmt.mac = "ac:1f:6b:1c:d7:b0";
68 # Link to oob1.
69 e4-oob.mac = "ac:1f:6b:1c:d7:b1";
70 e5.mac = "ac:1f:6b:1c:d7:b2";
71 e6.mac = "ac:1f:6b:1c:d7:b3";
72 # Link to dcsw01.hswaw.net
73 e7-dcsw.mac = "ac:1f:6b:1c:db:06";
74 e8.mac = "ac:1f:6b:1c:db:07";
75 };
76 networking.interfaces.e7-dcsw.mtu = 9000;
77
78 networking.vlans = {
79 "vl-globalmix" = { interface = "e1-nnet"; id = 466; };
80 "vl-polmix" = { interface = "e1-nnet"; id = 2486; };
81 "vl-openpeering" = { interface = "e1-nnet"; id = 992; };
82
83 "vl-dcsw-l3" = { interface = "e7-dcsw"; id = 4001; };
84 "vl-dist-l3" = { interface = "e7-dcsw"; id = 3006; };
85
86 # Extra vlans contained in //bgpwtf/machines/secrets/plain/edge01.waw.bgp.wtf-private.nix
87 };
88 networking.interfaces = {
89 lo = {
90 ipv4.addresses = [ { address = "185.236.240.1"; prefixLength = 32; } ];
91 ipv6.addresses = [ { address = "2a0d:eb00:2137::1"; prefixLength = 64; } ];
92 };
93 ## EPIX links via Nitronet.
94 "vl-globalmix" = {
95 ipv4.addresses = [ { address = "185.235.70.45"; prefixLength = 31; } ];
96 ipv6.addresses = [ { address = "2001:67c:778:fd40::b9eb:462d"; prefixLength = 127; } ];
97 };
98 "vl-polmix" = {
99 ipv4.addresses = [ { address = "94.246.185.175"; prefixLength = 31; } ];
100 ipv6.addresses = [ { address = "2001:67c:778:fa40::5ef6:b9af"; prefixLength = 127; } ];
101 };
102 "vl-openpeering" = {
103 ipv4.addresses = [ { address = "89.46.145.61"; prefixLength = 21; } ];
104 ipv6.addresses = [ { address = "2001:678:3ac::313"; prefixLength = 48; } ];
105 };
106
107 ## L3/mgmt links..
108 # To customs.hackerspace.pl.
109 "e2-customs" = {
110 ipv4.addresses = [ { address = "185.236.240.4"; prefixLength = 31; } ];
111 ipv6.addresses = [ { address = "2a0d:eb00:2137:1::2"; prefixLength = 127; } ];
112 };
113 # To mgmt.
114 "e3-mgmt" = {
115 ipv4.addresses = [ { address = "10.10.10.1"; prefixLength = 24; } ];
116 };
117 # To obb1.
118 "e4-oob" = {
119 ipv4.addresses = [ { address = "185.236.240.74"; prefixLength = 29; } ];
120 };
121 # To dcsw01, L3 (BGP).
122 "vl-dcsw-l3" = {
123 mtu = 9000;
124 ipv4.addresses = [ { address = "185.236.240.6"; prefixLength = 31; } ];
125 ipv6.addresses = [ { address = "2a0d:eb00:2137:1::6"; prefixLength = 127; } ];
126 };
127 # To dist02, L3 (BGP).
128 "vl-dist-l3" = {
129 ipv4.addresses = [ { address = "185.236.240.14"; prefixLength = 31; } ];
130 ipv6.addresses = [ { address = "2a0d:eb00:2137:1::a"; prefixLength = 127; } ];
131 };
132
133 # Extra interface configs contained in //bgpwtf/machines/secrets/plain/edge01.waw.bgp.wtf-private.nix
134 };
135
136 hscloud.routing.enable = true;
137 hscloud.routing.routerID = "185.236.240.1";
138 hscloud.routing.asn = 204880;
139 # Use default master4/master6 tables so that `birdc show route` works.
140 hscloud.routing.tables.master.program = true;
141 hscloud.routing.tables.master.programSourceV4 = "185.236.240.1";
142 hscloud.routing.tables.master.programSourceV6 = "2a0d:eb00:2137::1";
143
144 hscloud.routing.extra = ''
145 function net_martian_v4() {
146 return net ~ [ 169.254.0.0/16+, 172.16.0.0/12+, 192.168.0.0/16+, 10.0.0.0/8+,
147 127.0.0.0/8+, 224.0.0.0/4+, 240.0.0.0/4+, 0.0.0.0/32-, 0.0.0.0/0{25,32}, 0.0.0.0/0{0,7} ];
148 }
149 function net_as204480_waw_v4() {
150 return net ~ [ 185.236.240.0/23+ ];
151 }
152 function net_martian_v6() {
153 return net ~ [ fc00::/7+, fec0::/10+, ::/128-, ::/0{0,15}, ::/0{49,128} ];
154 }
155 function net_as204480_waw_v6() {
156 return net ~ [ 2a0d:eb00::/32 ];
157 }
158
159 '';
160 hscloud.routing.originate = {
161 # WAW prefixes, exposed into internet BGP table.
162 v4.waw = { table = "internet"; address = "185.236.240.0"; prefixLength = 23; };
163 v6.waw = { table = "internet"; address = "2a0d:eb00::"; prefixLength = 32; };
164
165 # Default gateway via us, exposed into aggregated table.
166 v4.default = { table = "aggregate"; address = "0.0.0.0"; prefixLength = 0; };
167 v6.default = { table = "aggregate"; address = "::"; prefixLength = 0; };
168 };
169 hscloud.routing.pipe = let
170 copySourcesToKernel = sources: table: {
171 table = "master";
172 peerTable = table;
173 filterIn = ''
174 ${concatStringsSep "\n" (map (v: "if source = RTS_${v} then accept;") sources)}
175 reject;
176 '';
177 };
178 in {
179 v4."internet_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "internet";
180 v4."aggregate_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "aggregate";
181 v6."internet_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "internet";
182 v6."aggregate_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "aggregate";
183 };
184
185 hscloud.routing.ospf.v6.main = {
186 area."0.0.0.0".interfaces = {
187 "e2-customs" = {
188 type = "bcast";
189 };
190 "e4-oob" = {
191 type = "bcast";
192 stub = true;
193 };
194 };
195 table = "aggregate";
196 filterIn = ''
197 # hswaw prefix from e2-customs
198 if net ~ [ 2a0d:eb00:4242::/64+ ] then accept;
199 # e2-customs link
200 if net ~ [ 2a0d:eb00:2137:1::2/127+ ] then accept;
201 '';
202 };
203 hscloud.routing.ospf.v4.main = {
204 area."0.0.0.0".interfaces = {
205 "e4-oob" = {
206 type = "bcast";
207 stub = true;
208 };
209 };
210 table = "aggregate";
211 filterIn = ''
212 # e4-oob link
213 if net ~ [ 185.236.240.72/29+ ] then accept;
214 '';
215 };
216
217 hscloud.routing.bgpSessions.v4 = let
218 filterInUpstream = ''
219 if net_martian_v4() then reject;
220 if net_as204480_waw_v4() then reject;
221 accept;
222 '';
223 filterOutUpstream = ''
224 # Accept AS204880-announced prefixes.
225 if (net ~ [ 185.236.240.0/22+ ]) then accept;
226 reject;
227 '';
228 in {
229 "waw_globalmix" = {
230 description = "UPSTREAM EPIX.WAR GlobalMix";
231 table = "internet";
232 local = "185.235.70.45";
233 neighbors = [
234 { address = "185.235.70.44"; asn = 62081; }
235 ];
236 prepend = 2; pref = 100;
237 filterIn = filterInUpstream;
238 filterOut = filterOutUpstream;
239 };
240 "waw_polmix" = {
241 description = "UPSTREAM EPIX.WAR PolMix";
242 table = "internet";
243 local = "94.246.185.175";
244 neighbors = [
245 { address = "94.246.185.174"; asn = 201054; }
246 ];
247 prepend = 1; pref = 200;
248 filterIn = filterInUpstream;
249 filterOut = filterOutUpstream;
250 };
251 "waw_openpeering" = {
252 description = "IXP EPIX.WAR OpenPeering";
253 table = "internet";
254 local = "89.46.145.61";
255 neighbors = [
256 { address = "89.46.144.11"; asn = 48850; }
257 { address = "89.46.144.12"; asn = 48850; }
258 ];
259 prepend = 0; pref = 300;
260 filterIn = filterInUpstream;
261 filterOut = filterOutUpstream;
262 };
263 "waw_google" = {
264 description = "PEER Google AS15169 (EPIX)";
265 table = "internet";
266 local = "89.46.145.61";
267 neighbors = [
268 # TODO(q3k): secretify the password.
269 { address = "89.46.144.185"; asn = 15169; password = passwords."edge01.waw-bgp-google"; }
270 ];
271 prepend = 0; pref = 300;
272 filterIn = filterInUpstream;
273 filterOut = filterOutUpstream;
274 };
275 # hscloud spine switch (dcsw01.hswaw.net).
276 "waw_hscloud" = {
277 description = "AGGREGATE CUSTOMER hscloud/dcsw01";
278 table = "aggregate";
279 local = "185.236.240.6";
280 asn = 65000;
281 neighbors = [
282 { address = "185.236.240.7"; asn = 65001; }
283 ];
284 filterIn = ''
285 # wieloryb prefix
286 if net ~ [ 185.236.240.8/31+ ] then accept;
287 # dcsw01 l2 general purpose
288 if net ~ [ 185.236.240.24/29+ ] then accept;
289 # hscloud l2 general purpose
290 if net ~ [ 185.236.240.32/28+ ] then accept;
291 # k0 metallb pools
292 if net ~ [ 185.236.240.48/28+, 185.236.240.112/28+ ] then accept;
293 reject;
294 '';
295 };
296 # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf).
297 "waw_dist02" = {
298 description = "AGGREGATE CUSTOMER bgpwtf/dist02";
299 table = "aggregate";
300 local = "185.236.240.14";
301 asn = 65000;
302 neighbors = [
303 { address = "185.236.240.15"; asn = 65002; }
304 ];
305 filterIn = ''
306 # dist02 customer routed
307 if net ~ [ 185.236.240.80/28+ ] then accept;
308 reject;
309 '';
310 };
311 # backup LTE link to edge01.fra
312 "fra_edge01" = {
313 description = "IBGP edge01.fra";
314 table = "internet";
315 local = "185.236.240.74";
316 direct = true;
317 neighbors = [
318 { address = "185.236.240.75"; asn = 204880; }
319 ];
320 pref = 50;
321 filterIn = filterInUpstream;
322 filterOut = filterOutUpstream;
323 };
324 };
325 hscloud.routing.bgpSessions.v6 = let
326 filterInUpstream = ''
327 if net_martian_v6() then reject;
328 if net_as204480_waw_v6() then reject;
329 accept;
330 '';
331 filterOutUpstream = ''
332 # Accept AS204880-announced prefixes.
333 if (net ~ [ 2a0d:eb00::/29+ ]) then accept;
334 reject;
335 '';
336 in {
337 "waw_globalmix" = {
338 description = "UPSTREAM EPIX.WAR GlobalMix";
339 table = "internet";
340 local = "2001:67c:778:fd40::b9eb:462d";
341 neighbors = [
342 { address = "2001:67c:778:fd40::b9eb:462c"; asn = 62081; }
343 ];
344 prepend = 2; pref = 100;
345 filterIn = filterInUpstream;
346 filterOut = filterOutUpstream;
347 };
348 "waw_polmix" = {
349 description = "UPSTREAM EPIX.WAR PolMix";
350 table = "internet";
351 local = "2001:67c:778:fa40::5ef6:b9af";
352 neighbors = [
353 { address = "2001:67c:778:fa40::5ef6:b9ae"; asn = 201054; }
354 ];
355 prepend = 1; pref = 200;
356 filterIn = filterInUpstream;
357 filterOut = filterOutUpstream;
358 };
359 "waw_openpeering" = {
360 description = "IXP EPIX.WAR OpenPeering";
361 table = "internet";
362 local = "2001:678:3ac::313";
363 neighbors = [
364 { address = "2001:678:3ac::11"; asn = 48850; }
365 { address = "2001:678:3ac::12"; asn = 48850; }
366 ];
367 prepend = 0; pref = 300;
368 filterIn = filterInUpstream;
369 filterOut = filterOutUpstream;
370 };
371 "waw_google" = {
372 description = "PEER Google AS15169 (EPIX)";
373 table = "internet";
374 local = "2001:678:3ac::313";
375 neighbors = [
376 { address = "2001:678:3ac::185"; asn = 15169; password = passwords."edge01.waw-bgp-google"; }
377 ];
378 prepend = 0; pref = 300;
379 filterIn = filterInUpstream;
380 filterOut = filterOutUpstream;
381 };
382 # hscloud spine switch (dcsw01.hswaw.net).
383 "waw_hscloud" = {
384 description = "AGGREGATE CUSTOMER dcsw01.hswaw.net";
385 table = "aggregate";
386 local = "2a0d:eb00:2137:1::6";
387 asn = 65000;
388 neighbors = [
389 { address = "2a0d:eb00:2137:1::7"; asn = 65001; }
390 ];
391 filterIn = ''
392 # dcsw01 l2 general purpose
393 if net ~ [ 2a0d:eb00:2137::/48+ ] then accept;
394 reject;
395 '';
396 };
397 # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf).
398 "waw_dist02" = {
399 description = "AGGREGATE CUSTOMER dist02.bgp.wtf";
400 table = "aggregate";
401 local = "2a0d:eb00:2137:1::a";
402 asn = 65000;
403 neighbors = [
404 { address = "2a0d:eb00:2137:1::b"; asn = 65002; }
405 ];
406 filterIn = ''
407 # dist02 customers.
408 if net ~ [ 2a0d:eb00:8002::/48 ] then accept;
409 reject;
410 '';
411 };
412 };
413}