blob: ef614727bd1bc9e78f175f61ccf6162ba08e032f [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
Bartosz Stebelc7267982020-12-10 15:38:29 +010025 ./modules/anchorvm.nix
Serge Bazanski6abe4fa2020-10-03 00:18:34 +020026 # 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 };
Bartosz Stebelc7267982020-12-10 15:38:29 +0100132 # VM bridge
133 "br0" = {
134 ipv4.addresses = [ { address = "185.236.240.17"; prefixLength = 29; } ];
135 ipv6.addresses = [ { address = "2a0d:eb00:2137:3::1"; prefixLength = 64; } ];
136 };
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200137
138 # Extra interface configs contained in //bgpwtf/machines/secrets/plain/edge01.waw.bgp.wtf-private.nix
139 };
Bartosz Stebelc7267982020-12-10 15:38:29 +0100140 networking.bridges = {
141 "br0" = {
142 interfaces = [];
143 };
144 };
145 hscloud.anchorvm = {
146 bridge = "br0";
147 };
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200148
149 hscloud.routing.enable = true;
150 hscloud.routing.routerID = "185.236.240.1";
151 hscloud.routing.asn = 204880;
152 # Use default master4/master6 tables so that `birdc show route` works.
153 hscloud.routing.tables.master.program = true;
154 hscloud.routing.tables.master.programSourceV4 = "185.236.240.1";
155 hscloud.routing.tables.master.programSourceV6 = "2a0d:eb00:2137::1";
156
157 hscloud.routing.extra = ''
158 function net_martian_v4() {
159 return net ~ [ 169.254.0.0/16+, 172.16.0.0/12+, 192.168.0.0/16+, 10.0.0.0/8+,
160 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} ];
161 }
162 function net_as204480_waw_v4() {
163 return net ~ [ 185.236.240.0/23+ ];
164 }
165 function net_martian_v6() {
166 return net ~ [ fc00::/7+, fec0::/10+, ::/128-, ::/0{0,15}, ::/0{49,128} ];
167 }
168 function net_as204480_waw_v6() {
169 return net ~ [ 2a0d:eb00::/32 ];
170 }
171
172 '';
173 hscloud.routing.originate = {
174 # WAW prefixes, exposed into internet BGP table.
Serge Bazanski520f1502021-06-06 12:51:24 +0000175 v4.waw = { table = "internet"; address = "185.236.240.0"; prefixLength = 24; };
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200176 v6.waw = { table = "internet"; address = "2a0d:eb00::"; prefixLength = 32; };
177
178 # Default gateway via us, exposed into aggregated table.
179 v4.default = { table = "aggregate"; address = "0.0.0.0"; prefixLength = 0; };
180 v6.default = { table = "aggregate"; address = "::"; prefixLength = 0; };
181 };
182 hscloud.routing.pipe = let
Serge Bazanskid9a63652020-10-16 19:07:41 +0200183 copySourcesToKernel = sources: table: extra: {
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200184 table = "master";
185 peerTable = table;
186 filterIn = ''
Serge Bazanskid9a63652020-10-16 19:07:41 +0200187 ${extra}
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200188 ${concatStringsSep "\n" (map (v: "if source = RTS_${v} then accept;") sources)}
189 reject;
190 '';
191 };
192 in {
Serge Bazanskid9a63652020-10-16 19:07:41 +0200193 v4."internet_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "internet" "";
194 v4."aggregate_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "aggregate" "";
195 v6."internet_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "internet" "";
196 v6."aggregate_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "aggregate" ''
197 # Static v6 routes for customers.
198 if proto ~ "static_static_ipv6_customer_*" then accept;
199 '';
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200200 };
201
202 hscloud.routing.ospf.v6.main = {
203 area."0.0.0.0".interfaces = {
204 "e2-customs" = {
205 type = "bcast";
206 };
207 "e4-oob" = {
208 type = "bcast";
209 stub = true;
210 };
211 };
212 table = "aggregate";
213 filterIn = ''
214 # hswaw prefix from e2-customs
Serge Bazanskie9f2c9d2020-11-08 16:31:11 +0100215 if net ~ [ 2a0d:eb00:4242::/48+ ] then accept;
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200216 # e2-customs link
217 if net ~ [ 2a0d:eb00:2137:1::2/127+ ] then accept;
218 '';
219 };
220 hscloud.routing.ospf.v4.main = {
221 area."0.0.0.0".interfaces = {
222 "e4-oob" = {
223 type = "bcast";
224 stub = true;
225 };
226 };
227 table = "aggregate";
228 filterIn = ''
229 # e4-oob link
230 if net ~ [ 185.236.240.72/29+ ] then accept;
231 '';
232 };
233
234 hscloud.routing.bgpSessions.v4 = let
235 filterInUpstream = ''
236 if net_martian_v4() then reject;
237 if net_as204480_waw_v4() then reject;
238 accept;
239 '';
240 filterOutUpstream = ''
241 # Accept AS204880-announced prefixes.
242 if (net ~ [ 185.236.240.0/22+ ]) then accept;
243 reject;
244 '';
245 in {
246 "waw_globalmix" = {
247 description = "UPSTREAM EPIX.WAR GlobalMix";
248 table = "internet";
249 local = "185.235.70.45";
250 neighbors = [
251 { address = "185.235.70.44"; asn = 62081; }
252 ];
253 prepend = 2; pref = 100;
254 filterIn = filterInUpstream;
255 filterOut = filterOutUpstream;
256 };
257 "waw_polmix" = {
258 description = "UPSTREAM EPIX.WAR PolMix";
259 table = "internet";
260 local = "94.246.185.175";
261 neighbors = [
262 { address = "94.246.185.174"; asn = 201054; }
263 ];
264 prepend = 1; pref = 200;
265 filterIn = filterInUpstream;
266 filterOut = filterOutUpstream;
267 };
268 "waw_openpeering" = {
269 description = "IXP EPIX.WAR OpenPeering";
270 table = "internet";
271 local = "89.46.145.61";
272 neighbors = [
273 { address = "89.46.144.11"; asn = 48850; }
274 { address = "89.46.144.12"; asn = 48850; }
275 ];
276 prepend = 0; pref = 300;
277 filterIn = filterInUpstream;
278 filterOut = filterOutUpstream;
279 };
280 "waw_google" = {
281 description = "PEER Google AS15169 (EPIX)";
282 table = "internet";
283 local = "89.46.145.61";
284 neighbors = [
285 # TODO(q3k): secretify the password.
286 { address = "89.46.144.185"; asn = 15169; password = passwords."edge01.waw-bgp-google"; }
287 ];
288 prepend = 0; pref = 300;
289 filterIn = filterInUpstream;
290 filterOut = filterOutUpstream;
291 };
292 # hscloud spine switch (dcsw01.hswaw.net).
293 "waw_hscloud" = {
294 description = "AGGREGATE CUSTOMER hscloud/dcsw01";
295 table = "aggregate";
296 local = "185.236.240.6";
297 asn = 65000;
298 neighbors = [
299 { address = "185.236.240.7"; asn = 65001; }
300 ];
301 filterIn = ''
302 # wieloryb prefix
303 if net ~ [ 185.236.240.8/31+ ] then accept;
304 # dcsw01 l2 general purpose
305 if net ~ [ 185.236.240.24/29+ ] then accept;
306 # hscloud l2 general purpose
307 if net ~ [ 185.236.240.32/28+ ] then accept;
308 # k0 metallb pools
309 if net ~ [ 185.236.240.48/28+, 185.236.240.112/28+ ] then accept;
Serge Bazanski1c80bd72021-06-30 23:22:38 +0200310 # dcsw01.hswaw.net / dcr03sw48.hswaw.net
311 if net ~ [ 185.236.240.66/31 ] then accept;
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200312 reject;
313 '';
314 };
315 # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf).
316 "waw_dist02" = {
317 description = "AGGREGATE CUSTOMER bgpwtf/dist02";
318 table = "aggregate";
319 local = "185.236.240.14";
320 asn = 65000;
321 neighbors = [
322 { address = "185.236.240.15"; asn = 65002; }
323 ];
324 filterIn = ''
325 # dist02 customer routed
326 if net ~ [ 185.236.240.80/28+ ] then accept;
327 reject;
328 '';
329 };
Serge Bazanski520f1502021-06-06 12:51:24 +0000330 "waw_q3k" = {
331 description = "AGGREGATE CUSTOMER q3k";
332 table = "internet";
333 local = "185.236.240.64";
334 asn = 204880;
335 neighbors = [
336 { address = "185.236.240.65"; asn = 208521; }
337 ];
338 filterIn = ''
339 if net ~ [ 185.236.241.0/24 ] then accept;
340 reject;
341 '';
342 };
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200343 # backup LTE link to edge01.fra
344 "fra_edge01" = {
345 description = "IBGP edge01.fra";
346 table = "internet";
347 local = "185.236.240.74";
348 direct = true;
349 neighbors = [
350 { address = "185.236.240.75"; asn = 204880; }
351 ];
352 pref = 50;
353 filterIn = filterInUpstream;
354 filterOut = filterOutUpstream;
355 };
356 };
357 hscloud.routing.bgpSessions.v6 = let
358 filterInUpstream = ''
359 if net_martian_v6() then reject;
360 if net_as204480_waw_v6() then reject;
361 accept;
362 '';
363 filterOutUpstream = ''
364 # Accept AS204880-announced prefixes.
365 if (net ~ [ 2a0d:eb00::/29+ ]) then accept;
366 reject;
367 '';
368 in {
369 "waw_globalmix" = {
370 description = "UPSTREAM EPIX.WAR GlobalMix";
371 table = "internet";
372 local = "2001:67c:778:fd40::b9eb:462d";
373 neighbors = [
374 { address = "2001:67c:778:fd40::b9eb:462c"; asn = 62081; }
375 ];
376 prepend = 2; pref = 100;
377 filterIn = filterInUpstream;
378 filterOut = filterOutUpstream;
379 };
380 "waw_polmix" = {
381 description = "UPSTREAM EPIX.WAR PolMix";
382 table = "internet";
383 local = "2001:67c:778:fa40::5ef6:b9af";
384 neighbors = [
385 { address = "2001:67c:778:fa40::5ef6:b9ae"; asn = 201054; }
386 ];
387 prepend = 1; pref = 200;
388 filterIn = filterInUpstream;
389 filterOut = filterOutUpstream;
390 };
391 "waw_openpeering" = {
392 description = "IXP EPIX.WAR OpenPeering";
393 table = "internet";
394 local = "2001:678:3ac::313";
395 neighbors = [
396 { address = "2001:678:3ac::11"; asn = 48850; }
397 { address = "2001:678:3ac::12"; asn = 48850; }
398 ];
399 prepend = 0; pref = 300;
400 filterIn = filterInUpstream;
401 filterOut = filterOutUpstream;
402 };
403 "waw_google" = {
404 description = "PEER Google AS15169 (EPIX)";
405 table = "internet";
406 local = "2001:678:3ac::313";
407 neighbors = [
408 { address = "2001:678:3ac::185"; asn = 15169; password = passwords."edge01.waw-bgp-google"; }
409 ];
410 prepend = 0; pref = 300;
411 filterIn = filterInUpstream;
412 filterOut = filterOutUpstream;
413 };
414 # hscloud spine switch (dcsw01.hswaw.net).
415 "waw_hscloud" = {
416 description = "AGGREGATE CUSTOMER dcsw01.hswaw.net";
417 table = "aggregate";
418 local = "2a0d:eb00:2137:1::6";
419 asn = 65000;
420 neighbors = [
421 { address = "2a0d:eb00:2137:1::7"; asn = 65001; }
422 ];
423 filterIn = ''
424 # dcsw01 l2 general purpose
425 if net ~ [ 2a0d:eb00:2137::/48+ ] then accept;
426 reject;
427 '';
428 };
429 # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf).
430 "waw_dist02" = {
431 description = "AGGREGATE CUSTOMER dist02.bgp.wtf";
432 table = "aggregate";
433 local = "2a0d:eb00:2137:1::a";
434 asn = 65000;
435 neighbors = [
436 { address = "2a0d:eb00:2137:1::b"; asn = 65002; }
437 ];
438 filterIn = ''
439 # dist02 customers.
440 if net ~ [ 2a0d:eb00:8002::/48 ] then accept;
441 reject;
442 '';
443 };
444 };
445}