Files
bird_config/bird/function/inet_community.conf
2026-06-12 18:11:53 +08:00

66 lines
2.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 社区属性转换与本地优先级修正函数BIRD 2.18 纯净稳定版)
function function_inet_community_make(){
# 1. 从上游收到的路由 => 赋予兜底优先级 (Local Pref = 100)
if bgp_large_community ~ [(LOCAL_ASN, 10100, 0)] then {
bgp_local_pref = 100;
bgp_large_community.add((LOCAL_ASN, 2, 4));
bgp_large_community.delete((LOCAL_ASN, 10100, 0));
return true;
}
# 2. 私有上游 => 赋予兜底优先级 (Local Pref = 100)
if bgp_large_community ~ [(LOCAL_ASN, 10100, 1)] then {
bgp_local_pref = 100;
bgp_large_community.delete((LOCAL_ASN, 10100, 1));
return true;
}
# 3. Peer/IXP 收到的路由 => 赋予中等优先 (Local Pref = 140)
if bgp_large_community ~ [(LOCAL_ASN, 10100, 2), (LOCAL_ASN, 10100, 3)] then {
bgp_local_pref = 140;
bgp_large_community.add((LOCAL_ASN, 2, 4));
bgp_large_community.delete([(LOCAL_ASN, 10100, 2), (LOCAL_ASN, 10100, 3)]);
return true;
}
# 4. 下游客户发来的路由 => 赋予高优先级 (Local Pref = 180)
if bgp_large_community ~ [(LOCAL_ASN, 10100, 4)] then {
bgp_local_pref = 180;
# 修复BIRD 的 add 不支持中括号批量加,必须拆开单次调用
bgp_large_community.add((LOCAL_ASN, 2, 1));
bgp_large_community.add((LOCAL_ASN, 2, 2));
bgp_large_community.add((LOCAL_ASN, 2, 3));
bgp_large_community.add((LOCAL_ASN, 2, 4));
bgp_large_community.delete((LOCAL_ASN, 10100, 4));
return true;
}
# 5. 自身宣告的前缀 => 赋予最高级封顶 (Local Pref = 200)
if bgp_large_community ~ [(LOCAL_ASN, 200, 0)] then {
bgp_local_pref = 200;
# 修复:拆开单独 add
bgp_large_community.add((LOCAL_ASN, 2, 0));
bgp_large_community.add((LOCAL_ASN, 2, 1));
bgp_large_community.add((LOCAL_ASN, 2, 2));
bgp_large_community.add((LOCAL_ASN, 2, 3));
bgp_large_community.add((LOCAL_ASN, 2, 4));
bgp_large_community.delete((LOCAL_ASN, 200, 0));
return true;
}
return false;
}
# 社区安全检查/清理(全量通配版)
function function_inet_bgp_community_clear(){
# 使用 [ (ASN, Data1, *) ] 语法,直接清空该分类下的所有子标记
bgp_large_community.delete([
(LOCAL_ASN, 1, *),
(LOCAL_ASN, 2, *),
(LOCAL_ASN, 3, *),
(LOCAL_ASN, 200, *),
(LOCAL_ASN, 10100, *),
(LOCAL_ASN, 10101, *),
(LOCAL_ASN, 10102, *)
]);
}