This commit is contained in:
2026-05-23 15:09:44 +08:00
parent 6fe05cf0e4
commit 28294a3e59
13 changed files with 232 additions and 27 deletions

View File

@@ -0,0 +1,18 @@
# 下游过滤器
# 政策:发全表,只收下游和关联下游的
# 下游-发表控制器
function function_dn42_downstream_export() {
if !is_dn42_prefix() || (bgp_path.len > 20) then return false;
# 硬性限制没有1000,0的不放
if bgp_large_community !~ [(DN42_ASN, 1000,0)] then return false;
return true;
}
# 下游-收表控制器
# 注意,配置下游时候,一定要注意手打一个 300 0 ,不然发不出去
function function_dn42_downstream_import() {
if !is_dn42_prefix() || (bgp_path.len > 20) then return false;
return true;
}

View File

@@ -0,0 +1,13 @@
function function_dn42_ibgp_import() {
if is_dn42_self_net() then return false;
if !is_dn42_prefix() then return false;
if bgp_large_community ~ [(DN42_ASN, 1,*)] then return false;
return true;
}
function function_dn42_ibgp_export() {
if is_dn42_self_net() then return false;
if !is_dn42_prefix() then return false;
if bgp_large_community ~ [(DN42_ASN, 1,*)] then return false;
return true;
}

View File

@@ -0,0 +1,10 @@
# 对上游接收过滤器
# 政策:全网照单接受
function function_dn42_bgp_import_from_upstream() {
if is_dn42_self_net() then return false;
if !is_dn42_prefix() || (bgp_path.len > 20) then return false;
# 允许转发给下游
bgp_large_community.add((DN42_ASN,1000,0));
return true;
}

View File

@@ -0,0 +1,34 @@
# 普通上游(发布控制器)
# 政策:只发自己的
function function_dn42_bgp_export_to_upstream0() {
if !is_dn42_self_net() then return false;
if !is_dn42_prefix() then return false;
if source != RTS_STATIC then return false;
# 100禁止性过滤
if bgp_large_community ~ [(DN42_ASN, 100, 100)] then return false;
if bgp_large_community ~ [(DN42_ASN, 100, 200)] then return false;
if bgp_large_community ~ [(DN42_ASN, 200, 201)] then return false;
# 前置过滤:允许自己的段子-所有上游和普通上游
if bgp_large_community ~ [(DN42_ASN, 200, 0)] then return true;
if bgp_large_community ~ [(DN42_ASN, 200, 1)] then return true;
if bgp_large_community ~ [(DN42_ASN, 200, 2)] then return false;
return false;
}
function function_dn42_control_bgp_upstream0(int peer_asn){
# 1.禁止带有 201 0 (禁止一切外发)的发出去
if bgp_large_community ~ [(DN42_ASN, 201, 0)] then return false;
# 2.禁止带有 201 peer asn (禁止向某一外发)的发出去
if bgp_large_community ~ [(DN42_ASN, 201, peer_asn)] then return false;
# 3.不带202,0(允许全体外发)但是带有202,peer asn允许单一外发
if (bgp_large_community !~ [(DN42_ASN, 202, 0)]) then {
if bgp_large_community ~ [(DN42_ASN, 202, peer_asn)] then return true;
}
# 4.带有202,0允许一切外发
if bgp_large_community ~ [(DN42_ASN, 202, 0)] then return true;
return false;
}

View File

@@ -0,0 +1,47 @@
# 能带下游的上游(发布控制器)
# 政策:发自己的+下游的
function function_dn42_bgp_export_to_upstream1() {
if source !~ [RTS_STATIC, RTS_BGP] then return false;
if !is_dn42_prefix() then return false;
# 100禁止性过滤
if bgp_large_community ~ [(DN42_ASN, 100, 100)] then return false;
if bgp_large_community ~ [(DN42_ASN, 100, 200)] then return false;
if bgp_large_community ~ [(DN42_ASN, 200, 202)] then return false;
if source =RTS_STATIC then {
# 静态路由,允许 200[0 2]
if bgp_large_community ~ [(DN42_ASN, 200, 0)] then return true;
if bgp_large_community ~ [(DN42_ASN, 200, 2)] then return true;
if bgp_large_community ~ [(DN42_ASN, 200, 1)] then return false;
}
if source = RTS_BGP then {
# BGP路由允许 3000
if bgp_large_community ~ [(DN42_ASN, 300, 0)] then return true;
}
return false;
}
function function_inet_control_bgp_upstream1(int peer_asn){
# 1.禁止带有 201 0 (禁止一切外发) 301 0禁止下游段子转发的发出去
if bgp_large_community ~ [(DN42_ASN, 201, 0)] then return false;
if bgp_large_community ~ [(DN42_ASN, 301, 0)] then return false;
# 2.禁止带有 201 peer asn (禁止向某一外发) 301 peer asn禁止向某一外发下游的发出去
if bgp_large_community ~ [(DN42_ASN, 201, peer_asn)] then return false;
if bgp_large_community ~ [(DN42_ASN, 301, peer_asn)] then return false;
# 3.不带202,0(允许全体外发)但是带有202,peer asn 放
if (bgp_large_community !~ [(DN42_ASN, 202, 0)]) then {
if bgp_large_community ~ [(DN42_ASN, 202, peer_asn)] then return true;
}
# 不带302 0但是有302 peer asn的
if (bgp_large_community !~ [(DN42_ASN, 302, 0)]) then {
if bgp_large_community ~ [(DN42_ASN, 302, peer_asn)] then return true;
}
# 4.带有202,0允许一切外发和302 0的
if bgp_large_community ~ [(DN42_ASN, 202, 0)] then return true;
if bgp_large_community ~ [(DN42_ASN, 302, 0)] then return true;
return false;
}

View File

@@ -3,7 +3,7 @@
# 下游-发表控制器
function function_inet6_downstream_export() {
if is_bogon_prefix() || (bgp_path.len > 20) then reject;
if is_bogon_prefix() || (bgp_path.len > 20) then return false;
# 硬性限制没有1000,0的不放
if bgp_large_community !~ [(LOCAL_ASN, 1000,0)] then return false;
return true;

View File

@@ -1,27 +1,33 @@
function function_inet4_ibgp_import() {
function function_inet_ibgp_import() {
if is_self_net() then return false;
if is_bogon_prefix() then return false;
if bgp_large_community ~ [(LOCAL_ASN, 1,*)] then reject;
if bgp_large_community ~ [(LOCAL_ASN, 1,*)] then return false;
return true;
}
function function_inet_ibgp_export() {
if is_self_net() then return false;
if is_bogon_prefix() then return false;
if bgp_large_community ~ [(LOCAL_ASN, 1,*)] then return false;
return true;
}
function function_inet4_ibgp_import() {
if !function_inet_ibgp_import() then return false;
return true;
}
function function_inet4_ibgp_export() {
if is_self_net() then return false;
if is_bogon_prefix() then return false;
if bgp_large_community ~ [(LOCAL_ASN, 1,*)] then reject;
if !function_inet_ibgp_export() then return false;
return true;
}
function function_inet6_ibgp_import() {
if is_self_net() then reject;
if is_bogon_prefix() then reject;
if bgp_large_community ~ [(LOCAL_ASN, 1,*)] then reject;
if !function_inet_ibgp_import() then return false;
return true;
}
function function_inet6_ibgp_export() {
if is_self_net() then reject;
if is_bogon_prefix() then reject;
if bgp_large_community ~ [(LOCAL_ASN, 1,*)] then reject;
if !function_inet_ibgp_export() then return false;
return true;
}