2020-06-07 14:03:12 +00:00
|
|
|
# SPDX-FileCopyrightText: 2020 Luke Granger-Brown <depot@lukegb.com>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2023-04-15 14:47:37 +00:00
|
|
|
{ depot, lib, config, ... }:
|
2020-05-08 22:26:21 +00:00
|
|
|
let
|
|
|
|
generateSnippet = base: args: lib.concatStringsSep "\n" (lib.mapAttrsToList ( ixName: ix: generateSnippetForIX (args // { ixName = ixName; ix = ix; }) ) base );
|
|
|
|
generateSnippetForIX = { ixName, ix, ... }@args: ''
|
2023-01-18 23:41:42 +00:00
|
|
|
${lib.optionalString (doesIPv4 ix) ''
|
2020-05-08 22:26:21 +00:00
|
|
|
ipv4 table ${ixName}4;
|
2021-08-19 00:23:09 +00:00
|
|
|
filter bgp_in_${ixName}4
|
|
|
|
prefix set allnet;
|
|
|
|
int set allas;
|
|
|
|
{
|
|
|
|
if ! (avoid_martians4()) then reject;
|
|
|
|
${if ix.remote.must_be_next_hop then "if (bgp_path.first != ${toString ix.remote.asn}) then reject;" else "# no next-hop requirement"}
|
2024-06-28 07:21:05 +00:00
|
|
|
${if ix.remote.set_imported_next_hop_to != null then "bgp_next_hop = ${ix.remote.set_imported_next_hop_to};" else "# no imported bgp_next_hop override"}
|
2022-01-01 03:02:55 +00:00
|
|
|
${lib.concatMapStringsSep "\n" (asn: "if (bgp_path ~ [= * ${toString asn} * =]) then reject;") ix.remote.drop_asns}
|
2023-09-30 01:14:36 +00:00
|
|
|
${lib.optionalString (ixName == "quadv") ''
|
|
|
|
bgp_ext_community.add((ro, 205479, 1000));
|
|
|
|
bgp_ext_community.add((ro, 205479, 4000)); # etheroute
|
2024-06-28 07:21:05 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 6000)); # cofractal-ams01
|
2023-09-30 01:14:36 +00:00
|
|
|
#bgp_ext_community.add((ro, 205479, 4002)); # gsl
|
|
|
|
|
|
|
|
# Etheroute communities
|
|
|
|
bgp_community.add((3170, 63257)); # GTT Corero
|
|
|
|
bgp_community.add((64600, 3356)); # no Lumen
|
|
|
|
bgp_community.add((64600, 5459)); # no LINX peers (inc. RS)
|
|
|
|
''}
|
2024-03-28 00:45:06 +00:00
|
|
|
${if ix.remote.pref_src.v4 != null then "krt_prefsrc = ${ix.remote.pref_src.v4};" else "# no krt_prefsrc"}
|
2021-09-10 20:46:05 +00:00
|
|
|
bgp_local_pref = ${toString ix.remote.bgp_local_pref};
|
2021-08-19 00:23:09 +00:00
|
|
|
accept;
|
|
|
|
}
|
2023-01-18 23:41:42 +00:00
|
|
|
filter bgp_export_${ixName}4
|
|
|
|
{
|
2024-07-13 16:57:05 +00:00
|
|
|
${if ix.remote.export_internal then "if ((ro, ${toString ix.local.asn}, 10) ~ bgp_ext_community) then accept;" else ""}
|
2023-01-18 23:41:42 +00:00
|
|
|
if ! ((ro, ${toString ix.local.asn}, 1000) ~ bgp_ext_community) then reject;
|
|
|
|
bgp_ext_community.delete([(ro, ${toString ix.local.asn}, *)]);
|
|
|
|
accept;
|
|
|
|
}
|
|
|
|
protocol pipe ${ixName}pipe_4 {
|
|
|
|
table ${ixName}4;
|
|
|
|
peer table master4;
|
|
|
|
import ${if ix.remote.is_route_collector then "all" else "where ((ro, ${toString ix.local.asn}, ${toString ix.remote.export_community}) ~ bgp_ext_community)"};
|
|
|
|
export filter bgp_in_${ixName}4;
|
|
|
|
};
|
|
|
|
''}
|
|
|
|
|
2023-09-30 01:14:36 +00:00
|
|
|
${lib.optionalString (doesIPv6 ix) ''
|
2023-01-18 23:41:42 +00:00
|
|
|
ipv6 table ${ixName}6;
|
2021-08-19 00:23:09 +00:00
|
|
|
filter bgp_in_${ixName}6
|
|
|
|
prefix set allnet;
|
|
|
|
int set allas;
|
|
|
|
{
|
|
|
|
if ! (avoid_martians6()) then reject;
|
|
|
|
${if ix.remote.must_be_next_hop then "if (bgp_path.first != ${toString ix.remote.asn}) then reject;" else "# no next-hop requirement"}
|
2022-01-01 03:02:55 +00:00
|
|
|
${lib.concatMapStringsSep "\n" (asn: "if (bgp_path ~ [= * ${toString asn} * =]) then reject;") ix.remote.drop_asns}
|
2024-03-28 00:45:06 +00:00
|
|
|
${if ix.remote.pref_src.v6 != null then "krt_prefsrc = ${ix.remote.pref_src.v6};" else "# no krt_prefsrc"}
|
2021-09-10 20:46:05 +00:00
|
|
|
bgp_local_pref = ${toString ix.remote.bgp_local_pref};
|
2021-08-19 00:23:09 +00:00
|
|
|
accept;
|
|
|
|
}
|
2022-08-17 01:30:09 +00:00
|
|
|
filter bgp_export_${ixName}6
|
|
|
|
{
|
2024-07-13 16:57:05 +00:00
|
|
|
${if ix.remote.export_internal then "if ((ro, ${toString ix.local.asn}, 10) ~ bgp_ext_community) then accept;" else ""}
|
2022-08-17 01:30:09 +00:00
|
|
|
if ! ((ro, ${toString ix.local.asn}, 1000) ~ bgp_ext_community) then reject;
|
|
|
|
bgp_ext_community.delete([(ro, ${toString ix.local.asn}, *)]);
|
|
|
|
accept;
|
|
|
|
}
|
2020-05-08 22:26:21 +00:00
|
|
|
protocol pipe ${ixName}pipe_6 {
|
|
|
|
table ${ixName}6;
|
|
|
|
peer table master6;
|
2022-04-30 15:47:35 +00:00
|
|
|
import ${if ix.remote.is_route_collector then "all" else "where ((ro, ${toString ix.local.asn}, ${toString ix.remote.export_community}) ~ bgp_ext_community)"};
|
2021-08-19 00:23:09 +00:00
|
|
|
export filter bgp_in_${ixName}6;
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
2023-09-30 01:14:36 +00:00
|
|
|
''}
|
2020-05-08 22:26:21 +00:00
|
|
|
'' + lib.concatImapStringsSep "\n" ( i: v: generateSnippetForRouter (args // { routerNum = i; router = v; }) ) ix.remote.routers;
|
2023-01-18 23:41:42 +00:00
|
|
|
doesIPv4 = ix: (ix.local.v4 != null) || ix.v4onv6;
|
2023-09-30 01:14:36 +00:00
|
|
|
doesIPv6 = ix: (ix.local.v6 != null);
|
2021-07-01 01:48:12 +00:00
|
|
|
enabledSnippet = { enabled ? true, ... }: "disabled ${if enabled then "off" else "on"};";
|
|
|
|
passwordSnippet = { password ? null, ... }: if password == null then "# no password" else "password \"${password}\";";
|
|
|
|
multihopSnippet = { multihop ? null, ... }: if multihop == null then "# not multihop" else "multihop ${toString multihop};";
|
2024-06-28 07:21:05 +00:00
|
|
|
nexthopSnippet = { next_hop ? null, ... }: if next_hop == null then "# no next hop override" else "next hop ${toString next_hop};";
|
2021-08-17 01:30:33 +00:00
|
|
|
passiveSnippet = { passive, ... }: "passive ${if passive then "on" else "off"};";
|
2024-07-13 16:57:05 +00:00
|
|
|
bfdSnippet = { bfd, ... }: "bfd ${if bfd then "on" else "off"};";
|
2021-08-19 00:23:09 +00:00
|
|
|
prefixLimitSnippet = limit: if limit == null then "# no import limit" else "import limit ${toString limit} action restart;";
|
2020-05-08 22:26:21 +00:00
|
|
|
generateSnippetForRouter = { ixName, ix, routerNum, router, ... }: ''
|
2023-01-18 23:41:42 +00:00
|
|
|
${lib.optionalString (ix.local.v4 != null) ''
|
2020-05-08 22:26:21 +00:00
|
|
|
protocol bgp ${ixName}${toString routerNum}_4 {
|
2021-07-01 01:48:12 +00:00
|
|
|
${enabledSnippet router}
|
|
|
|
${passwordSnippet router}
|
|
|
|
${multihopSnippet router}
|
2024-06-28 07:21:05 +00:00
|
|
|
${nexthopSnippet router}
|
2021-08-17 01:30:33 +00:00
|
|
|
${passiveSnippet ix.remote}
|
2024-07-13 16:57:05 +00:00
|
|
|
${bfdSnippet ix.remote}
|
2020-05-08 22:26:21 +00:00
|
|
|
local ${ix.local.v4} as ${toString ix.local.asn};
|
|
|
|
neighbor ${router.v4} as ${toString ix.remote.asn};
|
2021-07-01 01:48:12 +00:00
|
|
|
graceful restart on;
|
|
|
|
long lived graceful restart on;
|
2020-05-08 22:26:21 +00:00
|
|
|
ipv4 {
|
|
|
|
table ${ixName}4;
|
|
|
|
import all;
|
2022-08-17 01:30:09 +00:00
|
|
|
export ${if ix.remote.is_route_collector then "all" else "filter bgp_export_${ixName}4"};
|
2021-08-19 00:23:09 +00:00
|
|
|
${prefixLimitSnippet ix.remote.prefix_limit.v4}
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
|
|
|
};
|
2023-01-18 23:41:42 +00:00
|
|
|
''}
|
2023-09-30 01:14:36 +00:00
|
|
|
${lib.optionalString (ix.local.v6 != null) ''
|
2020-05-08 22:26:21 +00:00
|
|
|
protocol bgp ${ixName}${toString routerNum}_6 {
|
2021-07-01 01:48:12 +00:00
|
|
|
${enabledSnippet router}
|
|
|
|
${passwordSnippet router}
|
|
|
|
${multihopSnippet router}
|
2021-08-17 01:30:33 +00:00
|
|
|
${passiveSnippet ix.remote}
|
2024-07-13 16:57:05 +00:00
|
|
|
${bfdSnippet ix.remote}
|
2020-05-08 22:26:21 +00:00
|
|
|
local ${ix.local.v6} as ${toString ix.local.asn};
|
|
|
|
neighbor ${router.v6} as ${toString ix.remote.asn};
|
2021-07-01 01:48:12 +00:00
|
|
|
graceful restart on;
|
|
|
|
long lived graceful restart on;
|
2023-01-18 23:41:42 +00:00
|
|
|
${lib.optionalString (ix.v4onv6) ''
|
|
|
|
ipv4 {
|
|
|
|
table ${ixName}4;
|
|
|
|
import all;
|
|
|
|
export ${if ix.remote.is_route_collector then "all" else "filter bgp_export_${ixName}4"};
|
|
|
|
${prefixLimitSnippet ix.remote.prefix_limit.v4}
|
2023-01-19 09:29:37 +00:00
|
|
|
extended next hop;
|
2023-01-18 23:41:42 +00:00
|
|
|
};
|
|
|
|
''}
|
2020-05-08 22:26:21 +00:00
|
|
|
ipv6 {
|
|
|
|
table ${ixName}6;
|
|
|
|
import all;
|
2022-08-17 01:30:09 +00:00
|
|
|
export ${if ix.remote.is_route_collector then "all" else "filter bgp_export_${ixName}6"};
|
2021-08-19 00:23:09 +00:00
|
|
|
${prefixLimitSnippet ix.remote.prefix_limit.v6}
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
|
|
|
};
|
2023-09-30 01:14:36 +00:00
|
|
|
''}
|
2020-05-08 22:26:21 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
inherit (lib) mkOption mkAfter types;
|
|
|
|
in {
|
|
|
|
options.services.lukegbgp = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
config = mkOption { # lukegbgp.config
|
|
|
|
type = with types; submodule {
|
|
|
|
options = {
|
|
|
|
local = mkOption { # lukegbgp.config.local
|
|
|
|
type = submodule {
|
|
|
|
options = {
|
|
|
|
routerID = mkOption { # lukegbgp.config.local.routerID
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
peering = mkOption { # lukegbgp.config.peering
|
|
|
|
type = attrsOf (submodule {
|
|
|
|
options = {
|
|
|
|
local = mkOption { # lukegbgp.config.peering.<foo>.local
|
|
|
|
type = submodule {
|
|
|
|
options = {
|
|
|
|
asn = mkOption { # lukegbgp.config.peering.<foo>.local.asn
|
|
|
|
type = int;
|
|
|
|
};
|
|
|
|
v4 = mkOption { # lukegbgp.config.peering.<foo>.local.v4
|
2023-01-18 23:41:42 +00:00
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
|
|
|
v6 = mkOption { # lukegbgp.config.peering.<foo>.local.v6
|
2023-09-30 01:14:36 +00:00
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2023-01-18 23:41:42 +00:00
|
|
|
v4onv6 = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2020-05-08 22:26:21 +00:00
|
|
|
remote = mkOption { # lukegbgp.config.peering.<foo>.remote
|
|
|
|
type = submodule {
|
|
|
|
options = {
|
|
|
|
asn = mkOption { # lukegbgp.config.peering.<foo>.remote.asn
|
|
|
|
type = int;
|
|
|
|
};
|
2021-08-17 01:30:33 +00:00
|
|
|
passive = mkOption { # lukegbgp.config.peering.<foo>.remote.passive
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2020-05-08 22:26:21 +00:00
|
|
|
export_community = mkOption { # lukegbgp.config.peering.<foo>.remote.export_community
|
|
|
|
type = int;
|
|
|
|
};
|
2021-08-19 00:23:09 +00:00
|
|
|
prefix_limit.v4 = mkOption { # lukegbgp.config.peering.<foo>.remote.prefix_limit.v4
|
|
|
|
type = nullOr int;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
prefix_limit.v6 = mkOption { # lukegbgp.config.peering.<foo>.remote.prefix_limit.v6
|
|
|
|
type = nullOr int;
|
|
|
|
default = null;
|
|
|
|
};
|
2024-03-28 00:45:06 +00:00
|
|
|
pref_src.v4 = mkOption { # lukegbgp.config.peering.<foo>.pref_src.v4
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
pref_src.v6 = mkOption { # lukegbgp.config.peering.<foo>.pref_src.v6
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
};
|
2021-08-19 00:23:09 +00:00
|
|
|
must_be_next_hop = mkOption { # lukegbgp.config.peering.<foo>.remote.must_be_next_hop
|
|
|
|
type = bool;
|
|
|
|
default = true;
|
|
|
|
};
|
2024-06-28 07:21:05 +00:00
|
|
|
set_imported_next_hop_to = mkOption { # lukegbgp.config.peering.<foo>.remote.set_imported_next_hop_to
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
};
|
2022-01-01 03:02:55 +00:00
|
|
|
drop_asns = mkOption { # lukegbgp.config.peering.<foo>.remote.drop_asns
|
|
|
|
type = listOf int;
|
|
|
|
default = [];
|
|
|
|
};
|
2021-09-10 20:46:05 +00:00
|
|
|
bgp_local_pref = mkOption { # lukegbgp.config.peering.<foo>.remote.bgp_local_pref
|
|
|
|
type = int;
|
|
|
|
default = 100;
|
|
|
|
};
|
2022-04-30 15:47:35 +00:00
|
|
|
is_route_collector = mkOption { # lukegbgp.config.peering.<foo>.remote.is_route_collector
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2024-07-13 16:57:05 +00:00
|
|
|
bfd = mkOption { # lukegbgp.config.peering.<foo>.remote.bfd
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
export_internal = mkOption { # lukegbgp.config.peering.<foo>.remote.export_internal
|
|
|
|
type = bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2020-05-08 22:26:21 +00:00
|
|
|
routers = mkOption { # lukegbgp.config.peering.<foo>.remote.routers
|
|
|
|
type = listOf (submodule {
|
|
|
|
options = {
|
|
|
|
enabled = mkOption { # lukegbgp.config.peering.<foo>.remote.routers.<n>.enabled
|
|
|
|
type = bool;
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
v4 = mkOption { # lukegbgp.config.peering.<foo>.remote.routers.<n>.v4
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
v6 = mkOption { # lukegbgp.config.peering.<foo>.remote.routers.<n>.v6
|
|
|
|
type = str;
|
|
|
|
};
|
2021-07-01 01:48:12 +00:00
|
|
|
multihop = mkOption { # lukegbgp.config.peering.<foo>.remote.routers.<n>.multihop
|
|
|
|
type = nullOr int;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
password = mkOption { # lukegbgp.config.peering.<foo>.remote.routers.<n>.password
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
};
|
2024-06-28 07:21:05 +00:00
|
|
|
next_hop = mkOption { # lukegbgp.config.peering.<foo>.remote.routers.<n>.next_hop
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
};
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
2020-11-04 16:41:15 +00:00
|
|
|
export = mkOption { # lukegbgp.config.export
|
2021-12-07 15:19:45 +00:00
|
|
|
default = { v4 = []; v6 = ["2a09:a440::/48"]; };
|
2020-11-04 16:41:15 +00:00
|
|
|
type = submodule {
|
|
|
|
options = {
|
|
|
|
v4 = mkOption { # lukegbgp.config.export.v4
|
|
|
|
type = listOf str;
|
2021-12-07 15:19:45 +00:00
|
|
|
default = [];
|
2020-11-04 16:41:15 +00:00
|
|
|
};
|
2021-08-30 18:58:21 +00:00
|
|
|
v4Extra = mkOption { #lukegbgp.config.export.v4Extra
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
|
|
|
};
|
2020-11-04 16:41:15 +00:00
|
|
|
v6 = mkOption { # lukegbgp.config.export.v6
|
|
|
|
type = listOf str;
|
|
|
|
default = ["2a09:a440::/48"];
|
|
|
|
};
|
2021-08-30 18:58:21 +00:00
|
|
|
v6Extra = mkOption { #lukegbgp.config.export.v6Extra
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
|
|
|
};
|
2020-11-04 16:41:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-04-04 22:51:40 +00:00
|
|
|
internal.export = mkOption {
|
|
|
|
default = { v4 = []; v6 = []; };
|
|
|
|
type = submodule {
|
|
|
|
options = {
|
|
|
|
v4 = mkOption { # lukegbgp.config.internal.export.v4
|
|
|
|
type = listOf str;
|
|
|
|
default = [];
|
|
|
|
};
|
|
|
|
v4Extra = mkOption { #lukegbgp.config.internal.export.v4Extra
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
v6 = mkOption { # lukegbgp.config.internal.export.v6
|
|
|
|
type = listOf str;
|
|
|
|
default = [];
|
|
|
|
};
|
|
|
|
v6Extra = mkOption { #lukegbgp.config.internal.export.v6Extra
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-07-13 16:57:05 +00:00
|
|
|
internal.local = mkOption {
|
|
|
|
default = { v4 = []; v6 = []; };
|
|
|
|
type = submodule {
|
|
|
|
options = {
|
|
|
|
v4 = mkOption { # lukegbgp.config.internal.local.v4
|
|
|
|
type = listOf str;
|
|
|
|
default = [];
|
|
|
|
};
|
|
|
|
v4Extra = mkOption { #lukegbgp.config.internal.local.v4Extra
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
v6 = mkOption { # lukegbgp.config.internal.local.v6
|
|
|
|
type = listOf str;
|
|
|
|
default = [];
|
|
|
|
};
|
|
|
|
v6Extra = mkOption { #lukegbgp.config.internal.local.v6Extra
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-08-30 18:58:21 +00:00
|
|
|
bfd = mkOption { # lukegbgp.config.bfd
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
|
|
|
};
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
services.bird2 = lib.mkIf config.services.lukegbgp.enable {
|
|
|
|
enable = true;
|
|
|
|
config = ''
|
|
|
|
router id ${config.services.lukegbgp.config.local.routerID};
|
|
|
|
|
2021-08-19 00:23:09 +00:00
|
|
|
function avoid_martians4()
|
|
|
|
prefix set martians;
|
|
|
|
{
|
|
|
|
martians = [
|
|
|
|
169.254.0.0/16+,
|
|
|
|
172.16.0.0/12+,
|
|
|
|
192.168.0.0/16+,
|
|
|
|
192.0.0.0/24+,
|
|
|
|
192.0.2.0/24+,
|
|
|
|
192.88.99.0/24+,
|
|
|
|
198.18.0.0/15+,
|
|
|
|
198.51.100.0/24+,
|
|
|
|
203.0.113.0/24+,
|
|
|
|
10.0.0.0/8+,
|
|
|
|
100.64.0.0/10+,
|
|
|
|
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} ];
|
|
|
|
|
|
|
|
if net ~ martians then return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function avoid_martians6()
|
|
|
|
prefix set martians;
|
|
|
|
{
|
|
|
|
martians = [
|
|
|
|
::/128-,
|
|
|
|
::1/128-,
|
|
|
|
::ffff:0:0/96+,
|
|
|
|
::ffff:0:0:0/96+,
|
|
|
|
64:ff9b::/96+,
|
|
|
|
100::/64+,
|
|
|
|
::/0{64,128},
|
|
|
|
::/0{0,15},
|
|
|
|
2001:db8::/32+,
|
|
|
|
fc00::/7+,
|
|
|
|
fe80::/10+,
|
|
|
|
ff00::/8+ ];
|
|
|
|
|
|
|
|
if net ~ martians then return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-08 22:26:21 +00:00
|
|
|
${generateSnippet config.services.lukegbgp.config.peering {}}
|
|
|
|
|
|
|
|
protocol kernel {
|
|
|
|
persist;
|
|
|
|
ipv4 {
|
|
|
|
import none;
|
|
|
|
export all;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
protocol kernel {
|
|
|
|
persist;
|
|
|
|
ipv6 {
|
|
|
|
import none;
|
|
|
|
export all;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
protocol device {
|
|
|
|
};
|
|
|
|
|
|
|
|
protocol static export4 {
|
|
|
|
ipv4 {
|
|
|
|
import filter {
|
2024-07-13 16:57:05 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 10));
|
2020-05-08 22:26:21 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 1000));
|
|
|
|
bgp_ext_community.add((ro, 205479, 2000));
|
|
|
|
bgp_ext_community.add((ro, 205479, 2001));
|
|
|
|
bgp_ext_community.add((ro, 205479, 2002));
|
|
|
|
bgp_ext_community.add((ro, 205479, 2003));
|
2020-11-04 16:41:15 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 3000));
|
2021-03-29 11:47:44 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 4000));
|
|
|
|
bgp_ext_community.add((ro, 205479, 4001));
|
|
|
|
bgp_ext_community.add((ro, 205479, 4002));
|
2021-08-17 01:30:33 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 5000));
|
|
|
|
bgp_ext_community.add((ro, 205479, 5001));
|
|
|
|
bgp_ext_community.add((ro, 205479, 5002));
|
|
|
|
bgp_ext_community.add((ro, 205479, 5003));
|
|
|
|
bgp_ext_community.add((ro, 205479, 5004));
|
|
|
|
bgp_ext_community.add((ro, 205479, 5005));
|
|
|
|
bgp_ext_community.add((ro, 205479, 5006));
|
2021-08-31 20:36:26 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 5007));
|
2021-09-10 20:23:24 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 5008));
|
2024-03-27 00:37:57 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 5009)); # fastly from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5010)); # ovh from rexxar
|
2022-06-04 11:15:43 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 6000)); # EMF: EMF-IX Route Server
|
2024-07-13 16:57:05 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 7000)); # 1299 from rexxar
|
2021-08-20 23:34:43 +00:00
|
|
|
|
2022-01-30 15:57:35 +00:00
|
|
|
# do not export to clouvider; they do... strange things.
|
|
|
|
bgp_ext_community.add((rt, 0, 62240));
|
|
|
|
|
2020-05-08 22:26:21 +00:00
|
|
|
accept;
|
|
|
|
};
|
|
|
|
};
|
2020-11-04 16:41:15 +00:00
|
|
|
${lib.concatMapStrings (ip: "route ${ip} blackhole;") config.services.lukegbgp.config.export.v4}
|
2021-08-30 18:58:21 +00:00
|
|
|
${config.services.lukegbgp.config.export.v4Extra}
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
2024-04-04 22:51:40 +00:00
|
|
|
protocol static exportinternal4 {
|
|
|
|
ipv4 {
|
|
|
|
import filter {
|
|
|
|
bgp_ext_community.add((ro, 205479, 10)); # internal only
|
|
|
|
accept;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
${lib.concatMapStrings (ip: "route ${ip} blackhole;") config.services.lukegbgp.config.internal.export.v4}
|
|
|
|
${config.services.lukegbgp.config.internal.export.v4Extra}
|
|
|
|
};
|
2024-07-13 16:57:05 +00:00
|
|
|
protocol static localinternal4 {
|
|
|
|
ipv4 { import all; };
|
|
|
|
${lib.concatMapStrings (ip: "route ${ip} blackhole;") config.services.lukegbgp.config.internal.local.v4}
|
|
|
|
${config.services.lukegbgp.config.internal.local.v4Extra}
|
|
|
|
};
|
2020-05-08 22:26:21 +00:00
|
|
|
protocol static export6 {
|
|
|
|
ipv6 {
|
|
|
|
import filter {
|
2024-07-13 16:57:05 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 10));
|
2021-08-31 16:39:23 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 1000)); # export
|
|
|
|
bgp_ext_community.add((ro, 205479, 2000)); #
|
|
|
|
bgp_ext_community.add((ro, 205479, 2001)); #
|
|
|
|
bgp_ext_community.add((ro, 205479, 2002)); #
|
|
|
|
bgp_ext_community.add((ro, 205479, 2003)); #
|
|
|
|
bgp_ext_community.add((ro, 205479, 3000)); # clouvider from clouvider-lon01
|
|
|
|
bgp_ext_community.add((ro, 205479, 4000)); # frantech from frantech-nyc01/veloxserv from etheroute-lon01
|
2024-03-27 00:37:57 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 4001)); # veloxserv from rexxar
|
2023-07-28 21:13:35 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 4002)); # mercury from etheroute-lon01
|
2024-03-27 00:37:57 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 5000)); # linx route collector from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5001)); # linx route server from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5002)); # facebook from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5003)); # openpeering from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5004)); # freetransitnet from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5005)); # he from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5006)); # clouvider from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5007)); # google from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5008)); # cloudflare from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5009)); # fastly from rexxar
|
|
|
|
bgp_ext_community.add((ro, 205479, 5010)); # ovh from rexxar
|
2022-06-04 11:15:43 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 6000)); # EMF: EMF-IX Route Server
|
2024-07-13 16:57:05 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 7000)); # 1299 from rexxar
|
2021-08-20 23:34:43 +00:00
|
|
|
|
2022-01-30 15:57:35 +00:00
|
|
|
# do not export to clouvider; they do... strange things.
|
|
|
|
bgp_ext_community.add((rt, 0, 62240));
|
|
|
|
|
2020-05-08 22:26:21 +00:00
|
|
|
accept;
|
|
|
|
};
|
|
|
|
};
|
2020-11-04 16:41:15 +00:00
|
|
|
${lib.concatMapStrings (ip: "route ${ip} blackhole;") config.services.lukegbgp.config.export.v6}
|
2021-08-30 18:58:21 +00:00
|
|
|
${config.services.lukegbgp.config.export.v6Extra}
|
|
|
|
};
|
2024-04-04 22:51:40 +00:00
|
|
|
protocol static exportinternal6 {
|
|
|
|
ipv6 {
|
|
|
|
import filter {
|
2024-07-13 16:57:05 +00:00
|
|
|
bgp_ext_community.add((ro, 205479, 10)); # internal only
|
2024-04-04 22:51:40 +00:00
|
|
|
accept;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
${lib.concatMapStrings (ip: "route ${ip} blackhole;") config.services.lukegbgp.config.internal.export.v6}
|
|
|
|
${config.services.lukegbgp.config.internal.export.v6Extra}
|
|
|
|
};
|
2024-07-13 16:57:05 +00:00
|
|
|
protocol static localinternal6 {
|
|
|
|
ipv6 { import all; };
|
|
|
|
${lib.concatMapStrings (ip: "route ${ip} blackhole;") config.services.lukegbgp.config.internal.local.v6}
|
|
|
|
${config.services.lukegbgp.config.internal.local.v6Extra}
|
|
|
|
};
|
2021-08-30 18:58:21 +00:00
|
|
|
|
|
|
|
protocol bfd {
|
|
|
|
${config.services.lukegbgp.config.bfd}
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
2021-08-31 02:01:38 +00:00
|
|
|
services.prometheus.exporters.bird.enable = config.services.bird2.enable;
|
2020-05-08 22:26:21 +00:00
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = lib.mkIf config.services.lukegbgp.enable (lib.mkAfter [ 179 ]);
|
2021-07-17 14:29:04 +00:00
|
|
|
networking.firewall.checkReversePath = false;
|
2020-05-08 22:26:21 +00:00
|
|
|
|
|
|
|
boot.kernel.sysctl = {
|
|
|
|
"net.ipv6.conf.default.accept_ra" = 0;
|
|
|
|
"net.ipv6.conf.all.accept_ra" = 0;
|
|
|
|
"net.ipv6.conf.default.autoconf" = 0;
|
|
|
|
"net.ipv6.conf.all.autoconf" = 0;
|
|
|
|
};
|
2023-04-15 14:36:22 +00:00
|
|
|
|
|
|
|
services.tailscale.package = depot.nix.pkgs.tailscale;
|
|
|
|
systemd.network.config.networkConfig.ManageForeignRoutes = "no";
|
2023-08-06 17:02:28 +00:00
|
|
|
|
|
|
|
systemd.services."systemd-resolved".environment.SYSTEMD_RESOLVED_SYNTHESIZE_HOSTNAME = "false";
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
2020-11-04 16:41:15 +00:00
|
|
|
}
|