blob: b03606d83242e968f0e5a22fb257f23a7db40394 [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;
310 reject;
311 '';
312 };
313 # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf).
314 "waw_dist02" = {
315 description = "AGGREGATE CUSTOMER bgpwtf/dist02";
316 table = "aggregate";
317 local = "185.236.240.14";
318 asn = 65000;
319 neighbors = [
320 { address = "185.236.240.15"; asn = 65002; }
321 ];
322 filterIn = ''
323 # dist02 customer routed
324 if net ~ [ 185.236.240.80/28+ ] then accept;
325 reject;
326 '';
327 };
Serge Bazanski520f1502021-06-06 12:51:24 +0000328 "waw_q3k" = {
329 description = "AGGREGATE CUSTOMER q3k";
330 table = "internet";
331 local = "185.236.240.64";
332 asn = 204880;
333 neighbors = [
334 { address = "185.236.240.65"; asn = 208521; }
335 ];
336 filterIn = ''
337 if net ~ [ 185.236.241.0/24 ] then accept;
338 reject;
339 '';
340 };
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200341 # backup LTE link to edge01.fra
342 "fra_edge01" = {
343 description = "IBGP edge01.fra";
344 table = "internet";
345 local = "185.236.240.74";
346 direct = true;
347 neighbors = [
348 { address = "185.236.240.75"; asn = 204880; }
349 ];
350 pref = 50;
351 filterIn = filterInUpstream;
352 filterOut = filterOutUpstream;
353 };
354 };
355 hscloud.routing.bgpSessions.v6 = let
356 filterInUpstream = ''
357 if net_martian_v6() then reject;
358 if net_as204480_waw_v6() then reject;
359 accept;
360 '';
361 filterOutUpstream = ''
362 # Accept AS204880-announced prefixes.
363 if (net ~ [ 2a0d:eb00::/29+ ]) then accept;
364 reject;
365 '';
366 in {
367 "waw_globalmix" = {
368 description = "UPSTREAM EPIX.WAR GlobalMix";
369 table = "internet";
370 local = "2001:67c:778:fd40::b9eb:462d";
371 neighbors = [
372 { address = "2001:67c:778:fd40::b9eb:462c"; asn = 62081; }
373 ];
374 prepend = 2; pref = 100;
375 filterIn = filterInUpstream;
376 filterOut = filterOutUpstream;
377 };
378 "waw_polmix" = {
379 description = "UPSTREAM EPIX.WAR PolMix";
380 table = "internet";
381 local = "2001:67c:778:fa40::5ef6:b9af";
382 neighbors = [
383 { address = "2001:67c:778:fa40::5ef6:b9ae"; asn = 201054; }
384 ];
385 prepend = 1; pref = 200;
386 filterIn = filterInUpstream;
387 filterOut = filterOutUpstream;
388 };
389 "waw_openpeering" = {
390 description = "IXP EPIX.WAR OpenPeering";
391 table = "internet";
392 local = "2001:678:3ac::313";
393 neighbors = [
394 { address = "2001:678:3ac::11"; asn = 48850; }
395 { address = "2001:678:3ac::12"; asn = 48850; }
396 ];
397 prepend = 0; pref = 300;
398 filterIn = filterInUpstream;
399 filterOut = filterOutUpstream;
400 };
401 "waw_google" = {
402 description = "PEER Google AS15169 (EPIX)";
403 table = "internet";
404 local = "2001:678:3ac::313";
405 neighbors = [
406 { address = "2001:678:3ac::185"; asn = 15169; password = passwords."edge01.waw-bgp-google"; }
407 ];
408 prepend = 0; pref = 300;
409 filterIn = filterInUpstream;
410 filterOut = filterOutUpstream;
411 };
412 # hscloud spine switch (dcsw01.hswaw.net).
413 "waw_hscloud" = {
414 description = "AGGREGATE CUSTOMER dcsw01.hswaw.net";
415 table = "aggregate";
416 local = "2a0d:eb00:2137:1::6";
417 asn = 65000;
418 neighbors = [
419 { address = "2a0d:eb00:2137:1::7"; asn = 65001; }
420 ];
421 filterIn = ''
422 # dcsw01 l2 general purpose
423 if net ~ [ 2a0d:eb00:2137::/48+ ] then accept;
424 reject;
425 '';
426 };
427 # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf).
428 "waw_dist02" = {
429 description = "AGGREGATE CUSTOMER dist02.bgp.wtf";
430 table = "aggregate";
431 local = "2a0d:eb00:2137:1::a";
432 asn = 65000;
433 neighbors = [
434 { address = "2a0d:eb00:2137:1::b"; asn = 65002; }
435 ];
436 filterIn = ''
437 # dist02 customers.
438 if net ~ [ 2a0d:eb00:8002::/48 ] then accept;
439 reject;
440 '';
441 };
442 };
443}