Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 1 | # 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 | |
| 14 | with builtins; |
| 15 | |
| 16 | let |
| 17 | passwords = import ./secrets/plain/passwords.nix; |
| 18 | |
| 19 | in 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 |
Serge Bazanski | d9a6365 | 2020-10-16 19:07:41 +0200 | [diff] [blame] | 170 | copySourcesToKernel = sources: table: extra: { |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 171 | table = "master"; |
| 172 | peerTable = table; |
| 173 | filterIn = '' |
Serge Bazanski | d9a6365 | 2020-10-16 19:07:41 +0200 | [diff] [blame] | 174 | ${extra} |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 175 | ${concatStringsSep "\n" (map (v: "if source = RTS_${v} then accept;") sources)} |
| 176 | reject; |
| 177 | ''; |
| 178 | }; |
| 179 | in { |
Serge Bazanski | d9a6365 | 2020-10-16 19:07:41 +0200 | [diff] [blame] | 180 | v4."internet_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "internet" ""; |
| 181 | v4."aggregate_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "aggregate" ""; |
| 182 | v6."internet_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "internet" ""; |
| 183 | v6."aggregate_to_kernel" = copySourcesToKernel ["BGP" "OSPF"] "aggregate" '' |
| 184 | # Static v6 routes for customers. |
| 185 | if proto ~ "static_static_ipv6_customer_*" then accept; |
| 186 | ''; |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | hscloud.routing.ospf.v6.main = { |
| 190 | area."0.0.0.0".interfaces = { |
| 191 | "e2-customs" = { |
| 192 | type = "bcast"; |
| 193 | }; |
| 194 | "e4-oob" = { |
| 195 | type = "bcast"; |
| 196 | stub = true; |
| 197 | }; |
| 198 | }; |
| 199 | table = "aggregate"; |
| 200 | filterIn = '' |
| 201 | # hswaw prefix from e2-customs |
Serge Bazanski | e9f2c9d | 2020-11-08 16:31:11 +0100 | [diff] [blame] | 202 | if net ~ [ 2a0d:eb00:4242::/48+ ] then accept; |
Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 203 | # e2-customs link |
| 204 | if net ~ [ 2a0d:eb00:2137:1::2/127+ ] then accept; |
| 205 | ''; |
| 206 | }; |
| 207 | hscloud.routing.ospf.v4.main = { |
| 208 | area."0.0.0.0".interfaces = { |
| 209 | "e4-oob" = { |
| 210 | type = "bcast"; |
| 211 | stub = true; |
| 212 | }; |
| 213 | }; |
| 214 | table = "aggregate"; |
| 215 | filterIn = '' |
| 216 | # e4-oob link |
| 217 | if net ~ [ 185.236.240.72/29+ ] then accept; |
| 218 | ''; |
| 219 | }; |
| 220 | |
| 221 | hscloud.routing.bgpSessions.v4 = let |
| 222 | filterInUpstream = '' |
| 223 | if net_martian_v4() then reject; |
| 224 | if net_as204480_waw_v4() then reject; |
| 225 | accept; |
| 226 | ''; |
| 227 | filterOutUpstream = '' |
| 228 | # Accept AS204880-announced prefixes. |
| 229 | if (net ~ [ 185.236.240.0/22+ ]) then accept; |
| 230 | reject; |
| 231 | ''; |
| 232 | in { |
| 233 | "waw_globalmix" = { |
| 234 | description = "UPSTREAM EPIX.WAR GlobalMix"; |
| 235 | table = "internet"; |
| 236 | local = "185.235.70.45"; |
| 237 | neighbors = [ |
| 238 | { address = "185.235.70.44"; asn = 62081; } |
| 239 | ]; |
| 240 | prepend = 2; pref = 100; |
| 241 | filterIn = filterInUpstream; |
| 242 | filterOut = filterOutUpstream; |
| 243 | }; |
| 244 | "waw_polmix" = { |
| 245 | description = "UPSTREAM EPIX.WAR PolMix"; |
| 246 | table = "internet"; |
| 247 | local = "94.246.185.175"; |
| 248 | neighbors = [ |
| 249 | { address = "94.246.185.174"; asn = 201054; } |
| 250 | ]; |
| 251 | prepend = 1; pref = 200; |
| 252 | filterIn = filterInUpstream; |
| 253 | filterOut = filterOutUpstream; |
| 254 | }; |
| 255 | "waw_openpeering" = { |
| 256 | description = "IXP EPIX.WAR OpenPeering"; |
| 257 | table = "internet"; |
| 258 | local = "89.46.145.61"; |
| 259 | neighbors = [ |
| 260 | { address = "89.46.144.11"; asn = 48850; } |
| 261 | { address = "89.46.144.12"; asn = 48850; } |
| 262 | ]; |
| 263 | prepend = 0; pref = 300; |
| 264 | filterIn = filterInUpstream; |
| 265 | filterOut = filterOutUpstream; |
| 266 | }; |
| 267 | "waw_google" = { |
| 268 | description = "PEER Google AS15169 (EPIX)"; |
| 269 | table = "internet"; |
| 270 | local = "89.46.145.61"; |
| 271 | neighbors = [ |
| 272 | # TODO(q3k): secretify the password. |
| 273 | { address = "89.46.144.185"; asn = 15169; password = passwords."edge01.waw-bgp-google"; } |
| 274 | ]; |
| 275 | prepend = 0; pref = 300; |
| 276 | filterIn = filterInUpstream; |
| 277 | filterOut = filterOutUpstream; |
| 278 | }; |
| 279 | # hscloud spine switch (dcsw01.hswaw.net). |
| 280 | "waw_hscloud" = { |
| 281 | description = "AGGREGATE CUSTOMER hscloud/dcsw01"; |
| 282 | table = "aggregate"; |
| 283 | local = "185.236.240.6"; |
| 284 | asn = 65000; |
| 285 | neighbors = [ |
| 286 | { address = "185.236.240.7"; asn = 65001; } |
| 287 | ]; |
| 288 | filterIn = '' |
| 289 | # wieloryb prefix |
| 290 | if net ~ [ 185.236.240.8/31+ ] then accept; |
| 291 | # dcsw01 l2 general purpose |
| 292 | if net ~ [ 185.236.240.24/29+ ] then accept; |
| 293 | # hscloud l2 general purpose |
| 294 | if net ~ [ 185.236.240.32/28+ ] then accept; |
| 295 | # k0 metallb pools |
| 296 | if net ~ [ 185.236.240.48/28+, 185.236.240.112/28+ ] then accept; |
| 297 | reject; |
| 298 | ''; |
| 299 | }; |
| 300 | # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf). |
| 301 | "waw_dist02" = { |
| 302 | description = "AGGREGATE CUSTOMER bgpwtf/dist02"; |
| 303 | table = "aggregate"; |
| 304 | local = "185.236.240.14"; |
| 305 | asn = 65000; |
| 306 | neighbors = [ |
| 307 | { address = "185.236.240.15"; asn = 65002; } |
| 308 | ]; |
| 309 | filterIn = '' |
| 310 | # dist02 customer routed |
| 311 | if net ~ [ 185.236.240.80/28+ ] then accept; |
| 312 | reject; |
| 313 | ''; |
| 314 | }; |
| 315 | # backup LTE link to edge01.fra |
| 316 | "fra_edge01" = { |
| 317 | description = "IBGP edge01.fra"; |
| 318 | table = "internet"; |
| 319 | local = "185.236.240.74"; |
| 320 | direct = true; |
| 321 | neighbors = [ |
| 322 | { address = "185.236.240.75"; asn = 204880; } |
| 323 | ]; |
| 324 | pref = 50; |
| 325 | filterIn = filterInUpstream; |
| 326 | filterOut = filterOutUpstream; |
| 327 | }; |
| 328 | }; |
| 329 | hscloud.routing.bgpSessions.v6 = let |
| 330 | filterInUpstream = '' |
| 331 | if net_martian_v6() then reject; |
| 332 | if net_as204480_waw_v6() then reject; |
| 333 | accept; |
| 334 | ''; |
| 335 | filterOutUpstream = '' |
| 336 | # Accept AS204880-announced prefixes. |
| 337 | if (net ~ [ 2a0d:eb00::/29+ ]) then accept; |
| 338 | reject; |
| 339 | ''; |
| 340 | in { |
| 341 | "waw_globalmix" = { |
| 342 | description = "UPSTREAM EPIX.WAR GlobalMix"; |
| 343 | table = "internet"; |
| 344 | local = "2001:67c:778:fd40::b9eb:462d"; |
| 345 | neighbors = [ |
| 346 | { address = "2001:67c:778:fd40::b9eb:462c"; asn = 62081; } |
| 347 | ]; |
| 348 | prepend = 2; pref = 100; |
| 349 | filterIn = filterInUpstream; |
| 350 | filterOut = filterOutUpstream; |
| 351 | }; |
| 352 | "waw_polmix" = { |
| 353 | description = "UPSTREAM EPIX.WAR PolMix"; |
| 354 | table = "internet"; |
| 355 | local = "2001:67c:778:fa40::5ef6:b9af"; |
| 356 | neighbors = [ |
| 357 | { address = "2001:67c:778:fa40::5ef6:b9ae"; asn = 201054; } |
| 358 | ]; |
| 359 | prepend = 1; pref = 200; |
| 360 | filterIn = filterInUpstream; |
| 361 | filterOut = filterOutUpstream; |
| 362 | }; |
| 363 | "waw_openpeering" = { |
| 364 | description = "IXP EPIX.WAR OpenPeering"; |
| 365 | table = "internet"; |
| 366 | local = "2001:678:3ac::313"; |
| 367 | neighbors = [ |
| 368 | { address = "2001:678:3ac::11"; asn = 48850; } |
| 369 | { address = "2001:678:3ac::12"; asn = 48850; } |
| 370 | ]; |
| 371 | prepend = 0; pref = 300; |
| 372 | filterIn = filterInUpstream; |
| 373 | filterOut = filterOutUpstream; |
| 374 | }; |
| 375 | "waw_google" = { |
| 376 | description = "PEER Google AS15169 (EPIX)"; |
| 377 | table = "internet"; |
| 378 | local = "2001:678:3ac::313"; |
| 379 | neighbors = [ |
| 380 | { address = "2001:678:3ac::185"; asn = 15169; password = passwords."edge01.waw-bgp-google"; } |
| 381 | ]; |
| 382 | prepend = 0; pref = 300; |
| 383 | filterIn = filterInUpstream; |
| 384 | filterOut = filterOutUpstream; |
| 385 | }; |
| 386 | # hscloud spine switch (dcsw01.hswaw.net). |
| 387 | "waw_hscloud" = { |
| 388 | description = "AGGREGATE CUSTOMER dcsw01.hswaw.net"; |
| 389 | table = "aggregate"; |
| 390 | local = "2a0d:eb00:2137:1::6"; |
| 391 | asn = 65000; |
| 392 | neighbors = [ |
| 393 | { address = "2a0d:eb00:2137:1::7"; asn = 65001; } |
| 394 | ]; |
| 395 | filterIn = '' |
| 396 | # dcsw01 l2 general purpose |
| 397 | if net ~ [ 2a0d:eb00:2137::/48+ ] then accept; |
| 398 | reject; |
| 399 | ''; |
| 400 | }; |
| 401 | # bgp.wtf internet customer router on W2A, floor 3 (dist02.bgp.wtf). |
| 402 | "waw_dist02" = { |
| 403 | description = "AGGREGATE CUSTOMER dist02.bgp.wtf"; |
| 404 | table = "aggregate"; |
| 405 | local = "2a0d:eb00:2137:1::a"; |
| 406 | asn = 65000; |
| 407 | neighbors = [ |
| 408 | { address = "2a0d:eb00:2137:1::b"; asn = 65002; } |
| 409 | ]; |
| 410 | filterIn = '' |
| 411 | # dist02 customers. |
| 412 | if net ~ [ 2a0d:eb00:8002::/48 ] then accept; |
| 413 | reject; |
| 414 | ''; |
| 415 | }; |
| 416 | }; |
| 417 | } |