This commit is contained in:
2022-12-26 23:41:18 +08:00
commit eb6f5dabcf
12 changed files with 443 additions and 0 deletions

45
lib/community-net186.conf Normal file
View File

@ -0,0 +1,45 @@
filter net186_import_filter(int POPID)
int viaRegion;
bgppath public_bgp_path;
{
public_bgp_path = delete(bgp_path, [4200000000..4225479999]);
if filter(bgp_large_community, [(LOCAL_ASN, 120, *)]).len != 0 then bgp_large_community.add((LOCAL_ASN, 120, POP));
if filter(bgp_large_community, [(LOCAL_ASN, 121, *)]).len != 0 then bgp_large_community.add((LOCAL_ASN, 121, REGION));
if (LOCAL_ASN, 122, REGION) ~ bgp_large_community then bgp_large_community.add((LOCAL_ASN, 122, REGION));
# ROUTE_DECIDER Start
if (LOCAL_ASN, 110, 2) ~ bgp_large_community then bgp_local_pref = 500;
else if (LOCAL_ASN, 110, 1) ~ bgp_large_community then bgp_local_pref = 400;
else bgp_local_pref = 300;
viaRegion = 0;
# Route is via Europe & Africa & Middle East
if bgp_large_community ~ [(LOCAL_ASN, 122, 100), (LOCAL_ASN, 122, 300..310), (LOCAL_ASN, 122, 600)] then viaRegion = viaRegion + 1;
# Route is via America
if bgp_large_community ~ [(LOCAL_ASN, 122, 200..299)] then viaRegion = viaRegion + 1;
# Route is via East Asia & Oceania
if bgp_large_community ~ [(LOCAL_ASN, 122, 400..500)] then viaRegion = viaRegion + 1;
if viaRegion > 2 then reject;
else if viaRegion = 2 then bgp_local_pref = bgp_local_pref - 50;
else if viaRegion then bgp_local_pref = 0;
# Route is via China mainland but not advertise in China mainland.
if (LOCAL_ASN, 122, 430) ~ bgp_large_community && REGION != 430 && (LOCAL_ASN, 120, 430) ~ bgp_large_community then {
reject;
}
bgp_local_pref = bgp_local_pref - filter(bgp_large_community, [(LOCAL_ASN, 122, *)]).len * 10;
};
filtet net186_export_filter(int POPID) {
if (65535, 65282) ~ bgp_community then {
reject;
}
if (65535, 65283) ~ bgp_community then {
if (POPID % 10) != (POP % 10) then {
reject;
}
}
};

25
lib/community-peer.conf Normal file
View File

@ -0,0 +1,25 @@
function is_peer_route() {
if (LOCAL_ASN, 110, 0) ~ bgp_large_community then return false;
if (LOCAL_ASN, 110, 10) ~ bgp_large_community then return false;
if bgp_path ~ [ 7018, 3320, 3257, 6830, 3356, 2914, 5511, 3491, 1239, 6453, 6762, 1299, 12956, 701, 6461, 174, 6939] then {
return false;
}
return true;
}
filter direct_peer_import_filter(int ASN) {
if !is_valid() then reject;
pub_add_communities(ASN, 0);
pub_preprocess_communities();
if !is_peer_route() then reject;
accept;
}
filter direct_peer_export_filter(int ASN) {
if !is_valid() then reject;
# Delete Self eBGP Confed Path.
bgp_path.delete([4200000000..4225479999]);
pub_process_communities(ASN, 10);
if !is_peer_route() then reject;
accept;
}

View File

@ -0,0 +1,93 @@
function pub_add_communities(int ASN, int type) {
# DIRECT PEER
if (type=0) then {
bgp_large_community.add((LOCAL_ASN, 110, 0));
bgp_large_community.add((LOCAL_ASN, 110, 2));
# PEER via IX
} else if (type=1) then {
bgp_large_community.add((LOCAL_ASN, 110, 0));
bgp_large_community.add((LOCAL_ASN, 110, 1));
j
# UPSTREAM
}else if (type=10) then {
bgp_large_community.add((LOCAL_ASN, 110, 10));
# DOWNSTREAM
} else if (type=20) then {
bgp_large_community.add((LOCAL_ASN, 110, 20));
}
# Finished (LOCAL_ASN, 110, *);
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, *);
}
function pub_preprocess_communities() {
if (LOCAL_ASN, 115, 1) ~ bgp_large_community then bgp_path.prepend(bgp_path.last);
if (LOCAL_ASN, 115, 3) ~ bgp_large_community then {
bgp_path.prepend(bgp_path.last);
bgp_path.prepend(bgp_path.last);
bgp_path.prepend(bgp_path.last);
}
if (LOCAL_ASN, 115, 5) ~ bgp_large_community then {
bgp_path.prepend(bgp_path.last);
bgp_path.prepend(bgp_path.last);
bgp_path.prepend(bgp_path.last);
bgp_path.prepend(bgp_path.last);
bgp_path.prepend(bgp_path.last);
}
# Finished (LOCAL_ASN, 115, *);
}
function pub_process_communities(int ASN, int type) {
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 reject;
if (65535, 65282) ~ bgp_community then reject;
if (65535, 65283) ~ bgp_community then reject;
if (LOCAL_ASN, 2, ASN) ~ bgp_large_community then reject
# PEER
if (type<10) then {
if (LOCAL_ASN, 1, 1) ~ bgp_large_community then reject;
# UPSTREAM
} else if (type=10) then {
if (LOCAL_ASN, 1, 0) ~ bgp_large_community then reject;
# DOWNSTREAM
} else if (type=20) then {
if (LOCAL_ASN, 1, 2) ~ bgp_large_community then reject;
}
}
filter transit_import_filter(int ASN) {
if !is_valid() then reject;
pub_add_communities(ASN, 10);
pub_preprocess_communities();
accept;
}
filter transit_export_filter(int ASN) {
if !is_valid() then reject;
# Delete Self eBGP Confed Path.
bgp_path.delete([4200000000..4225479999]);
pub_process_communities(ASN, 10);
if bgp_path.last !~ DOWNSTREAM_ASN then reject;
accept;
}

35
lib/util.conf Normal file
View File

@ -0,0 +1,35 @@
include "./constant.conf";
function pub_is_invalid_net_length(){
case net.type {
NET_IP4: return net.len > 24;
NET_IP6: return net.len > 48;
else: print "pub_is_valid_net_length: unexpected net.type ", net.type, " ", net; return false;
}
}
function is_bogon_prefix() {
case net.type {
NET_IP4: return net ~ BOGON_PREFIXES_V4;
NET_IP6: return net ~ BOGON_PREFIXES_V6;
else: print "is_bogon_prefix: unexpected net.type ", net.type, " ", net; return false;
}
}
function is_bogon_asn() {
if bgp_path ~ BOGON_ASNS then return true;
return false;
}
function is_downstream_asn() {
if bgp_path.last ~ DOWNSTREAM_ASN then return true;
return false;
}
function is_valid() {
if pub_is_invalid_net_length() then return false;
if is_bogon_prefix() then return false;
if is_bogon_asn() then return false;
if is_rpki_invalid() then return false;
return true;
}