From db8827f83e6fb61699a6543b7f0826f598c81dc4 Mon Sep 17 00:00:00 2001 From: 186526 Date: Tue, 27 Dec 2022 15:31:54 +0800 Subject: [PATCH] Add: complete the filter of internal network and downstream --- lib/10-community-transit.conf | 19 ++++++------------- lib/20-community-downstream.conf | 14 ++++++++++++++ lib/20-community-net186.conf | 14 ++++++++++++-- lib/20-community-peer.conf | 8 ++++---- protocol/external_network.conf | 16 +++++++--------- protocol/internal_network.conf | 29 ++++++++++------------------- readme.md | 2 +- 7 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 lib/20-community-downstream.conf diff --git a/lib/10-community-transit.conf b/lib/10-community-transit.conf index b9f2167..723f497 100644 --- a/lib/10-community-transit.conf +++ b/lib/10-community-transit.conf @@ -22,8 +22,9 @@ function pub_add_communities(int ASN; int PeerType) { if (LOCAL_ASN, 120, POP) ~ bgp_large_community then bgp_large_community.add((LOCAL_ASN, 120, POP)); if (LOCAL_ASN, 121, REGION) ~ bgp_large_community then bgp_large_community.add((LOCAL_ASN, 121, REGION)); - + # Finished (LOCAL_ASN, 120~130, *); + return true; } function pub_preprocess_communities() { @@ -41,18 +42,10 @@ function pub_preprocess_communities() { bgp_path.prepend(bgp_path.last); } # Finished (LOCAL_ASN, 115, *); + return true; } function pub_process_communities(int ASN; int PeerType) { - - if (LOCAL_ASN, 125, POP) ~ bgp_large_community then { - bgp_community.add((65535, 65282)); - } - - if (LOCAL_ASN, 126, REGION) ~ bgp_large_community then { - bgp_community.add((65535, 65283)); - } - if (65535, 65281) ~ bgp_community then return false; if (65535, 65282) ~ bgp_community then return false; if (65535, 65283) ~ bgp_community then return false; @@ -71,7 +64,7 @@ function pub_process_communities(int ASN; int PeerType) { } else if (PeerType=20) then { if (LOCAL_ASN, 1, 2) ~ bgp_large_community then return false; } - + return true; } function transit_import_filter(int ASN) { @@ -85,7 +78,7 @@ function transit_export_filter(int ASN) { # Delete Self eBGP Confed Path. bgp_path.delete([4200000000..4225479999]); if !is_valid() then return false; - pub_process_communities(ASN, 10); if bgp_path.last !~ DOWNSTREAM_ASN && source = RTS_BGP then return false; - return true; + if pub_process_communities(ASN, 10) then return true; + else return false; } \ No newline at end of file diff --git a/lib/20-community-downstream.conf b/lib/20-community-downstream.conf new file mode 100644 index 0000000..64820c2 --- /dev/null +++ b/lib/20-community-downstream.conf @@ -0,0 +1,14 @@ +function downstream_import_filter(int ASN) { + if !is_valid() then return false; + if bgp_path.last !~ DOWNSTREAM_ASN then return false; + pub_add_communities(ASN, 20); + pub_preprocess_communities(); + return true; +} + +function downstream_export_filter(int ASN) { + if !is_valid() then return false; + bgp_path.delete([4200000000..4225479999]); + if pub_process_communities(ASN, 20) then return true; + else return false; +} \ No newline at end of file diff --git a/lib/20-community-net186.conf b/lib/20-community-net186.conf index 9e86baf..34febc5 100644 --- a/lib/20-community-net186.conf +++ b/lib/20-community-net186.conf @@ -1,4 +1,4 @@ -function net186_import_filter (int POPID) +function net186_import_filter(int POPID) int viaRegion; bgppath public_bgp_path; { @@ -29,7 +29,7 @@ function net186_import_filter (int POPID) bgp_local_pref = bgp_local_pref - filter(bgp_large_community, [(LOCAL_ASN, 122, *)]).len * 10; }; -function net186_export_filter (int POPID) { +function net186_export_filter(int POPID) { if (65535, 65282) ~ bgp_community then return false; if (65535, 65283) ~ bgp_community then { @@ -37,4 +37,14 @@ function net186_export_filter (int POPID) { return false; } } + + if (LOCAL_ASN, 125, POP) ~ bgp_large_community then { + return false; + } + + if (LOCAL_ASN, 126, REGION) ~ bgp_large_community then { + return false; + } + + return true; }; \ No newline at end of file diff --git a/lib/20-community-peer.conf b/lib/20-community-peer.conf index 3b621ef..e890f44 100644 --- a/lib/20-community-peer.conf +++ b/lib/20-community-peer.conf @@ -9,17 +9,17 @@ function is_peer_route() { function direct_peer_import_filter(int ASN) { if !is_valid() then return false; + if !is_peer_route() then return false; pub_add_communities(ASN, 0); pub_preprocess_communities(); - if !is_peer_route() then return false; return true; } function direct_peer_export_filter(int ASN) { + # Delete Self eBGP Confed Path. bgp_path.delete([4200000000..4225479999]); if !is_valid() then return false; - # Delete Self eBGP Confed Path. - pub_process_communities(ASN, 10); if !is_peer_route() then return false; - return true; + if pub_process_communities(ASN, 0) then return true; + else return false; } \ No newline at end of file diff --git a/protocol/external_network.conf b/protocol/external_network.conf index 85b127f..bf084fb 100644 --- a/protocol/external_network.conf +++ b/protocol/external_network.conf @@ -16,13 +16,11 @@ template bgp pub_peer { }; } -# WIP +template bgp pub_downstream { + local as LOCAL_ASN; -# template bgp pub_downstream { -# local as LOCAL_ASN; - -# ipv6 { -# import where downstream_import_filter(6939); -# export where downstream_export_filter(6939); -# }; -# } + ipv6 { + import where downstream_import_filter(6939); + export where downstream_export_filter(6939); + }; +} diff --git a/protocol/internal_network.conf b/protocol/internal_network.conf index a07e202..3a4f7c2 100644 --- a/protocol/internal_network.conf +++ b/protocol/internal_network.conf @@ -1,23 +1,14 @@ -# WIP - -# template bgp net186 { -# local as SELFASN; +template bgp net186 { + local as SELFASN; -# interpret communities off; + interpret communities off; -# bfd on; + ipv6 { + next hop self; -# ipv6 { -# next hop self; + gateway direct; -# gateway direct; - -# import filter { - -# }; - -# export filter { - -# }; -# } -# } + import where net186_import_filter(101); + export where net186_import_filter(101); + }; +} diff --git a/readme.md b/readme.md index b524cde..39bf0f7 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # 186526 Network [![Build Status](https://ci.186526.xyz/api/badges/186526/net186-config/status.svg)](https://ci.186526.xyz/186526/net186-config) -![Bird Version Needed](https://img.shields.io/badge/bird-%3E%3D%202.0.11-blue) +![Bird Version Needed](https://img.shields.io/badge/bird-%3E%3D%202.0.8-blue) - Experimental global network - Maintained by 186526 (@real186526)