ff-policy.conf 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #
  2. # FFHO Routing Policy
  3. #
  4. {%- set node_roles = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
  5. {%- set node_sites = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', []) %}
  6. {%- set sites = salt['pillar.get']('sites', {}) %}
  7. {%- set te = salt['pillar.get']('te', {}) %}
  8. ################################################################################
  9. # Static Filters #
  10. ################################################################################
  11. filter own_prefixes {
  12. if net ~ [
  13. {%- if proto == 'v4' %}
  14. 10.132.0.0/16,
  15. 172.30.0.0/16{24,24}
  16. {%- else %}
  17. fdca:ffee:ff12::/48,
  18. 2a03:2260:2342::/48
  19. {%- endif %}
  20. ] then accept;
  21. reject;
  22. };
  23. ################################################################################
  24. # iBGP routing policy (Communities + Filter) + TE #
  25. ################################################################################
  26. {%- for site in node_sites %}
  27. {%- set site_config = sites.get (site) %}
  28. {%- set community = 'SITE_' ~ site|upper|replace('-', '') ~ '_ROUTE' %}
  29. {%- set community_id = site_config.get ('site_no')|int + 100 %}
  30. define {{ community }} = (65132,{{ community_id }});
  31. {%- endfor %}
  32. # Prefixes longer that site prefix leaving a gateway as TE prefixes.
  33. # They are for TE core -> gateway only and must not be imported on other gateways.
  34. define GATEWAY_TE_ROUTE = (65132,300);
  35. # All our prefixes learned in the external VRF and redistributed into the
  36. # internal network
  37. define EXTERNAL_ROUTE = (65132,1023);
  38. # TE routes only to be exported by specific border routers
  39. define EXPORT_RESTRICT = (65132, 100);
  40. define EXPORT_ONLY_AT_CR01 = (65132, 101);
  41. define EXPORT_ONLY_AT_CR02 = (65132, 102);
  42. define EXPORT_ONLY_AT_CR03 = (65132, 103);
  43. define EXPORT_ONLY_AT_CR04 = (65132, 104);
  44. define EXPORT_ONLY_AT_BBR_KT = (65132, 197);
  45. # Anycasted prefix
  46. define ANYCAST_PREFIX = (65132,999);
  47. # To be placed in /etc/bird/ff_killswitch.conf
  48. define SITE_LEGACY_ONLINE = 1;
  49. define SITE_PADCTY_ONLINE = 1;
  50. define SITE_PADUML_ONLINE = 1;
  51. define DRAINED = 0;
  52. {%- if 'batman_gw' in node_roles %}
  53. function tag_site_routes ()
  54. {
  55. {%- for site in node_sites %}
  56. {%- set site_config = sites.get (site) %}
  57. {%- set prefix = site_config.get ('prefix_' ~ proto) %}
  58. {%- set prefix_mask_te = prefix.split ('/')[1]|int + 1 %}
  59. {%- set community = 'SITE_' ~ site|upper|replace('-', '') ~ '_ROUTE' %}
  60. # {{ site_config.get ('name', site) }}
  61. if net ~ [ {{ prefix }}+ ] then {
  62. bgp_community.add ({{ community }});
  63. }
  64. {#-
  65. # Tag all routes for prefixes longer than site prefix leaving a gateway
  66. # as TE prefixes. They are for TE core -> gateway only and must not be
  67. # imported on other gateways.
  68. #}
  69. {%- if proto == 'v4' %}
  70. if net ~ [ {{ prefix ~ '{' ~ prefix_mask_te ~ ',32}' }} ] then {
  71. bgp_community.add (GATEWAY_TE_ROUTE);
  72. }
  73. {%- endif %}
  74. {% endfor %}
  75. }
  76. {%- endif %}
  77. filter ibgp_in {
  78. {#- Don't import other gateways TE prefixes here #}
  79. {%- if 'batman_gw' in node_roles %}
  80. if (GATEWAY_TE_ROUTE ~ bgp_community) then {
  81. reject;
  82. }
  83. {%- endif %}
  84. accept;
  85. }
  86. filter ibgp_out {
  87. # Don't redistribute OSPF into iBGP
  88. if "IGP" = proto then
  89. reject;
  90. # Don't redistribute v6 LO IP
  91. if "lo_v6" = proto then
  92. reject;
  93. # Don't redistribute null routes for bogon prefixes
  94. if "bogon_unreach" = proto then
  95. reject;
  96. # Don't redistribute TE prefixes for FFRL
  97. if "ffrl_te" = proto then
  98. reject;
  99. # Don't redistribute anything IF we are drained
  100. if 1 = DRAINED then
  101. reject;
  102. {%- if 'batman_gw' in node_roles %}
  103. tag_site_routes ();
  104. {%- endif %}
  105. accept;
  106. }
  107. # Traffic engineering routes
  108. protocol static ffho_te {
  109. preference 23;
  110. {% set prefixes = salt['ffho_net.get_te_prefixes'](te, grains['id'], proto) %}
  111. {% for prefix in prefixes|sort %}
  112. {%- set config = prefixes.get (prefix) %}
  113. {%- if 'desc' in config %}
  114. # {{ config.get ('desc') }}
  115. {%- endif %}
  116. route {{ prefix }} unreachable {
  117. {%- for community in config.get ('communities', []) %}
  118. bgp_community.add ({{ community }});
  119. {%- endfor %}
  120. };
  121. {%- endfor %}
  122. }