blob: d26f2191ea9e9404fbffe716bee07890f9e8e860 [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" "";
Serge Bazanski81e7fba2021-09-08 23:29:52 +0200194 v4."aggregate_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "aggregate" ''
195 # Static v4 routes for customers.
196 if proto ~ "static_static_ipv4_customer_*" then accept;
197 '';
Serge Bazanskid9a63652020-10-16 19:07:41 +0200198 v6."internet_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "internet" "";
199 v6."aggregate_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "aggregate" ''
200 # Static v6 routes for customers.
201 if proto ~ "static_static_ipv6_customer_*" then accept;
202 '';
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200203 };
204
205 hscloud.routing.ospf.v6.main = {
206 area."0.0.0.0".interfaces = {
207 "e2-customs" = {
208 type = "bcast";
209 };
210 "e4-oob" = {
211 type = "bcast";
212 stub = true;
213 };
214 };
215 table = "aggregate";
216 filterIn = ''
217 # hswaw prefix from e2-customs
Serge Bazanskie9f2c9d2020-11-08 16:31:11 +0100218 if net ~ [ 2a0d:eb00:4242::/48+ ] then accept;
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200219 # e2-customs link
220 if net ~ [ 2a0d:eb00:2137:1::2/127+ ] then accept;
221 '';
222 };
223 hscloud.routing.ospf.v4.main = {
224 area."0.0.0.0".interfaces = {
225 "e4-oob" = {
226 type = "bcast";
227 stub = true;
228 };
229 };
230 table = "aggregate";
231 filterIn = ''
232 # e4-oob link
233 if net ~ [ 185.236.240.72/29+ ] then accept;
234 '';
235 };
236
237 hscloud.routing.bgpSessions.v4 = let
238 filterInUpstream = ''
239 if net_martian_v4() then reject;
240 if net_as204480_waw_v4() then reject;
241 accept;
242 '';
243 filterOutUpstream = ''
244 # Accept AS204880-announced prefixes.
245 if (net ~ [ 185.236.240.0/22+ ]) then accept;
246 reject;
247 '';
248 in {
249 "waw_globalmix" = {
250 description = "UPSTREAM EPIX.WAR GlobalMix";
251 table = "internet";
252 local = "185.235.70.45";
253 neighbors = [
254 { address = "185.235.70.44"; asn = 62081; }
255 ];
256 prepend = 2; pref = 100;
257 filterIn = filterInUpstream;
258 filterOut = filterOutUpstream;
259 };
260 "waw_polmix" = {
261 description = "UPSTREAM EPIX.WAR PolMix";
262 table = "internet";
263 local = "94.246.185.175";
264 neighbors = [
265 { address = "94.246.185.174"; asn = 201054; }
266 ];
267 prepend = 1; pref = 200;
268 filterIn = filterInUpstream;
269 filterOut = filterOutUpstream;
270 };
271 "waw_openpeering" = {
272 description = "IXP EPIX.WAR OpenPeering";
273 table = "internet";
274 local = "89.46.145.61";
275 neighbors = [
276 { address = "89.46.144.11"; asn = 48850; }
277 { address = "89.46.144.12"; asn = 48850; }
278 ];
279 prepend = 0; pref = 300;
280 filterIn = filterInUpstream;
281 filterOut = filterOutUpstream;
282 };
283 "waw_google" = {
284 description = "PEER Google AS15169 (EPIX)";
285 table = "internet";
286 local = "89.46.145.61";
287 neighbors = [
288 # TODO(q3k): secretify the password.
289 { address = "89.46.144.185"; asn = 15169; password = passwords."edge01.waw-bgp-google"; }
290 ];
291 prepend = 0; pref = 300;
292 filterIn = filterInUpstream;
293 filterOut = filterOutUpstream;
294 };
295 # hscloud spine switch (dcsw01.hswaw.net).
296 "waw_hscloud" = {
297 description = "AGGREGATE CUSTOMER hscloud/dcsw01";
298 table = "aggregate";
299 local = "185.236.240.6";
300 asn = 65000;
301 neighbors = [
302 { address = "185.236.240.7"; asn = 65001; }
303 ];
304 filterIn = ''
305 # wieloryb prefix
306 if net ~ [ 185.236.240.8/31+ ] then accept;
307 # dcsw01 l2 general purpose
308 if net ~ [ 185.236.240.24/29+ ] then accept;
309 # hscloud l2 general purpose
310 if net ~ [ 185.236.240.32/28+ ] then accept;
311 # k0 metallb pools
312 if net ~ [ 185.236.240.48/28+, 185.236.240.112/28+ ] then accept;
Serge Bazanski1c80bd72021-06-30 23:22:38 +0200313 # dcsw01.hswaw.net / dcr03sw48.hswaw.net
314 if net ~ [ 185.236.240.66/31 ] then accept;
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200315 reject;
316 '';
317 };
318 # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf).
319 "waw_dist02" = {
320 description = "AGGREGATE CUSTOMER bgpwtf/dist02";
321 table = "aggregate";
322 local = "185.236.240.14";
323 asn = 65000;
324 neighbors = [
325 { address = "185.236.240.15"; asn = 65002; }
326 ];
327 filterIn = ''
328 # dist02 customer routed
329 if net ~ [ 185.236.240.80/28+ ] then accept;
330 reject;
331 '';
332 };
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200333 # backup LTE link to edge01.fra
334 "fra_edge01" = {
335 description = "IBGP edge01.fra";
336 table = "internet";
337 local = "185.236.240.74";
338 direct = true;
339 neighbors = [
340 { address = "185.236.240.75"; asn = 204880; }
341 ];
342 pref = 50;
343 filterIn = filterInUpstream;
344 filterOut = filterOutUpstream;
345 };
346 };
347 hscloud.routing.bgpSessions.v6 = let
348 filterInUpstream = ''
349 if net_martian_v6() then reject;
350 if net_as204480_waw_v6() then reject;
351 accept;
352 '';
353 filterOutUpstream = ''
354 # Accept AS204880-announced prefixes.
355 if (net ~ [ 2a0d:eb00::/29+ ]) then accept;
356 reject;
357 '';
358 in {
359 "waw_globalmix" = {
360 description = "UPSTREAM EPIX.WAR GlobalMix";
361 table = "internet";
362 local = "2001:67c:778:fd40::b9eb:462d";
363 neighbors = [
364 { address = "2001:67c:778:fd40::b9eb:462c"; asn = 62081; }
365 ];
366 prepend = 2; pref = 100;
367 filterIn = filterInUpstream;
368 filterOut = filterOutUpstream;
369 };
370 "waw_polmix" = {
371 description = "UPSTREAM EPIX.WAR PolMix";
372 table = "internet";
373 local = "2001:67c:778:fa40::5ef6:b9af";
374 neighbors = [
375 { address = "2001:67c:778:fa40::5ef6:b9ae"; asn = 201054; }
376 ];
377 prepend = 1; pref = 200;
378 filterIn = filterInUpstream;
379 filterOut = filterOutUpstream;
380 };
381 "waw_openpeering" = {
382 description = "IXP EPIX.WAR OpenPeering";
383 table = "internet";
384 local = "2001:678:3ac::313";
385 neighbors = [
386 { address = "2001:678:3ac::11"; asn = 48850; }
387 { address = "2001:678:3ac::12"; asn = 48850; }
388 ];
389 prepend = 0; pref = 300;
390 filterIn = filterInUpstream;
391 filterOut = filterOutUpstream;
392 };
393 "waw_google" = {
394 description = "PEER Google AS15169 (EPIX)";
395 table = "internet";
396 local = "2001:678:3ac::313";
397 neighbors = [
398 { address = "2001:678:3ac::185"; asn = 15169; password = passwords."edge01.waw-bgp-google"; }
399 ];
400 prepend = 0; pref = 300;
401 filterIn = filterInUpstream;
402 filterOut = filterOutUpstream;
403 };
404 # hscloud spine switch (dcsw01.hswaw.net).
405 "waw_hscloud" = {
406 description = "AGGREGATE CUSTOMER dcsw01.hswaw.net";
407 table = "aggregate";
408 local = "2a0d:eb00:2137:1::6";
409 asn = 65000;
410 neighbors = [
411 { address = "2a0d:eb00:2137:1::7"; asn = 65001; }
412 ];
413 filterIn = ''
414 # dcsw01 l2 general purpose
415 if net ~ [ 2a0d:eb00:2137::/48+ ] then accept;
Serge Bazanski400e03f2021-07-20 17:57:49 +0200416 # customer
417 if net ~ [ 2a0d:eb00:8004::/48+ ] then accept;
Serge Bazanski6abe4fa2020-10-03 00:18:34 +0200418 reject;
419 '';
420 };
421 # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf).
422 "waw_dist02" = {
423 description = "AGGREGATE CUSTOMER dist02.bgp.wtf";
424 table = "aggregate";
425 local = "2a0d:eb00:2137:1::a";
426 asn = 65000;
427 neighbors = [
428 { address = "2a0d:eb00:2137:1::b"; asn = 65002; }
429 ];
430 filterIn = ''
431 # dist02 customers.
432 if net ~ [ 2a0d:eb00:8002::/48 ] then accept;
433 reject;
434 '';
435 };
436 };
437}