diff --git a/bird.conf b/bird.conf index e7059c4..8709981 100644 --- a/bird.conf +++ b/bird.conf @@ -4,7 +4,7 @@ protocol device { protocol static { route 172.20.0.0/14 via 172.20.170.192; - route 172.20.170.192/28 reject; + route 172.20.170.192/27 reject; import all; export none; } @@ -14,7 +14,8 @@ include "/etc/bird/local4.conf"; # filter helpers ################# -##include "/etc/bird/filter4.conf"; +#include "/etc/bird/filter4.conf"; +include "/etc/bird/community_filters.conf"; protocol kernel { scan time 20; diff --git a/bird6.conf b/bird6.conf index 667971a..b5b5d53 100644 --- a/bird6.conf +++ b/bird6.conf @@ -10,7 +10,8 @@ include "/etc/bird/local6.conf"; # filter helpers ################# -##include "/etc/bird/filter6.conf"; +#include "/etc/bird/filter6.conf"; +include "/etc/bird/community_filters.conf"; protocol kernel { metric 64; # Use explicit kernel route metric to avoid collisions diff --git a/community_filters.conf b/community_filters.conf new file mode 100644 index 0000000..8594aa7 --- /dev/null +++ b/community_filters.conf @@ -0,0 +1,67 @@ +#/etc/bird/community_filters.conf +function update_latency(int link_latency) { + bgp_community.add((64511, link_latency)); + if (64511, 9) ~ bgp_community then { bgp_community.delete([(64511, 1..8)]); return 9; } + else if (64511, 8) ~ bgp_community then { bgp_community.delete([(64511, 1..7)]); return 8; } + else if (64511, 7) ~ bgp_community then { bgp_community.delete([(64511, 1..6)]); return 7; } + else if (64511, 6) ~ bgp_community then { bgp_community.delete([(64511, 1..5)]); return 6; } + else if (64511, 5) ~ bgp_community then { bgp_community.delete([(64511, 1..4)]); return 5; } + else if (64511, 4) ~ bgp_community then { bgp_community.delete([(64511, 1..3)]); return 4; } + else if (64511, 3) ~ bgp_community then { bgp_community.delete([(64511, 1..2)]); return 3; } + else if (64511, 2) ~ bgp_community then { bgp_community.delete([(64511, 1..1)]); return 2; } + else return 1; +} + +function update_bandwidth(int link_bandwidth) { + bgp_community.add((64511, link_bandwidth)); + if (64511, 21) ~ bgp_community then { bgp_community.delete([(64511, 22..29)]); return 21; } + else if (64511, 22) ~ bgp_community then { bgp_community.delete([(64511, 23..29)]); return 22; } + else if (64511, 23) ~ bgp_community then { bgp_community.delete([(64511, 24..29)]); return 23; } + else if (64511, 24) ~ bgp_community then { bgp_community.delete([(64511, 25..29)]); return 24; } + else if (64511, 25) ~ bgp_community then { bgp_community.delete([(64511, 26..29)]); return 25; } + else if (64511, 26) ~ bgp_community then { bgp_community.delete([(64511, 27..29)]); return 26; } + else if (64511, 27) ~ bgp_community then { bgp_community.delete([(64511, 28..29)]); return 27; } + else if (64511, 28) ~ bgp_community then { bgp_community.delete([(64511, 29..29)]); return 28; } + else return 29; +} + +function update_crypto(int link_crypto) { + bgp_community.add((64511, link_crypto)); + if (64511, 31) ~ bgp_community then { bgp_community.delete([(64511, 32..34)]); return 31; } + else if (64511, 32) ~ bgp_community then { bgp_community.delete([(64511, 33..34)]); return 32; } + else if (64511, 33) ~ bgp_community then { bgp_community.delete([(64511, 34..34)]); return 33; } + else return 34; +} + +function update_flags(int link_latency; int link_bandwidth; int link_crypto) +int dn42_latency; +int dn42_bandwidth; +int dn42_crypto; +{ + dn42_latency = update_latency(link_latency); + dn42_bandwidth = update_bandwidth(link_bandwidth) - 20; + dn42_crypto = update_crypto(link_crypto) - 30; + # replace 4 with your calculated bandwidth value + if dn42_bandwidth > 4 then dn42_bandwidth = 4; + return true; +} + +# Combines filter from local4.conf/local6.conf and filter4.conf/filter6.conf, +# which means, these must included before this file + +function dn42_import_filter(int link_latency; int link_bandwidth; int link_crypto) { + if is_valid_network() && !is_self_net() then { + update_flags(link_latency, link_bandwidth, link_crypto); + accept; + } + reject; +} + +function dn42_export_filter(int link_latency; int link_bandwith; int link_crypto) { + if is_valid_network() then { + if source = RTS_STATIC then bgp_community.add((64511, DN42_REGION)); + update_flags(link_latency, link_bandwith, link_crypto); + accept; + } + reject; +} diff --git a/local4.conf b/local4.conf index c01a79d..81b1978 100644 --- a/local4.conf +++ b/local4.conf @@ -2,6 +2,7 @@ router id 172.20.170.192; define OWNAS = 4242423934; define OWNIP = 172.20.170.192; +define DN42_REGION = 41; function is_self_net() { return net ~ [172.20.170.192/27+]; diff --git a/local6.conf b/local6.conf index 01163c5..288cf6c 100644 --- a/local6.conf +++ b/local6.conf @@ -2,6 +2,7 @@ router id 172.20.170.192; define OWNAS = 4242423934; define OWNIP = fd62:77fb:94bf::; +define DN42_REGION = 41; function is_self_net() { return net ~ [fd62:77fb:94bf::/48+]; diff --git a/peers4/B_dn42_Yamakaja b/peers4/B_dn42_Yamakaja new file mode 100644 index 0000000..75a1006 --- /dev/null +++ b/peers4/B_dn42_Yamakaja @@ -0,0 +1,5 @@ +protocol bgp B_dn42_Yamakaja from dnpeers { + neighbor 172.20.20.64 as 4242421191; + import where dn42_import_filter(2,24,34); + export where dn42_export_filter(2,24,34); +}; diff --git a/peers4/filip b/peers4/B_dn42_filip similarity index 50% rename from peers4/filip rename to peers4/B_dn42_filip index 94d5ac0..93c8acc 100644 --- a/peers4/filip +++ b/peers4/B_dn42_filip @@ -1,3 +1,3 @@ -protocol bgp filip from dnpeers { +protocol bgp B_dn42_filip from dnpeers { neighbor 172.20.178.65 as 4242421404; }; diff --git a/peers4/Yamakaja b/peers4/Yamakaja deleted file mode 100644 index 8bd32d7..0000000 --- a/peers4/Yamakaja +++ /dev/null @@ -1,3 +0,0 @@ -protocol bgp Yamakaja from dnpeers { - neighbor 172.20.20.64 as 4242421191; -}; diff --git a/peers6/Yamakaja b/peers6/B_dn42_Yamakaja similarity index 57% rename from peers6/Yamakaja rename to peers6/B_dn42_Yamakaja index 9643245..18c956d 100644 --- a/peers6/Yamakaja +++ b/peers6/B_dn42_Yamakaja @@ -1,3 +1,3 @@ -protocol bgp Yamakaja from dnpeers { +protocol bgp B_dn42_Yamakaja from dnpeers { neighbor fe80::1191 % 'wg-bgp-Yamakaja' as 4242421191; }; diff --git a/peers6/filip b/peers6/B_dn42_filip similarity index 63% rename from peers6/filip rename to peers6/B_dn42_filip index 54abc94..8201b3f 100644 --- a/peers6/filip +++ b/peers6/B_dn42_filip @@ -1,3 +1,3 @@ -protocol bgp filip from dnpeers { +protocol bgp B_dn42_filip from dnpeers { neighbor fe80::feec:daff:fe46:d60e % 'wg-bgp-filip' as 4242421404; };