ff-policy.conf 4.0 KB

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