IGP.conf 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #
  2. # FFHO IGP / OSPF configuration (Salt managed)
  3. #
  4. {%- set node_config = salt['pillar.get']('nodes:' ~ grains['id'], {}) %}
  5. {%- set roles = node_config.get ('roles', []) %}
  6. {%- set ospf_node_config = node_config.get('ospf', {}) %}
  7. {%- if 'stub_router' in ospf_node_config and ospf_node_config['stub_router'] in [ True, 'yes'] %}
  8. {%- do ospf_node_config.update ({'stub_router': 'yes'}) %}
  9. {%- endif %}
  10. {%- set ospf_config = salt['ffho_net.get_ospf_config'](node_config, grains['id']) %}
  11. {%- if AF == 6 %}
  12. # Bloody workaround for bird6's unwillingness to read !LL IPv6 addresses from lo
  13. protocol direct lo_v6 {
  14. interface "lo";
  15. }
  16. {%- endif %}
  17. protocol ospf IGP {
  18. import all;
  19. {%- if AF == 4 %}
  20. {%- if grains['id'].startswith ('cr') %}
  21. export filter {
  22. if net = 0.0.0.0/0 then {
  23. ospf_metric1 = 100;
  24. accept;
  25. }
  26. reject;
  27. };
  28. {%- else %}
  29. export none;
  30. {%- endif %}
  31. {%- elif AF == 6 %}
  32. export filter {
  33. {%- if grains['id'].startswith ('cr') %}
  34. if net = ::/0 then {
  35. ospf_metric1 = 100;
  36. accept;
  37. }
  38. {%- endif %}
  39. if proto = "lo_v6" then {
  40. ospf_metric1 = 100;
  41. accept;
  42. }
  43. reject;
  44. };
  45. {%- endif %}
  46. area 0.0.0.0 {
  47. stub {{ ospf_node_config.get ('stub_router', 'no') }} ;
  48. interface "lo" {
  49. stub yes;
  50. };
  51. {%- for iface in ospf_config.get(0, {})|sort %}
  52. {%- set config = ospf_config[0][iface] %}
  53. {%- if config.get('AF', AF) != AF %}
  54. {%- continue %}
  55. {%- endif %}
  56. {#- Interface description? #}
  57. {%- set desc = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces:' ~ iface ~ ':desc', "") %}
  58. # {{ desc }}
  59. interface "{{ iface }}" {
  60. {%- if 'desc' in config %}
  61. # {{ config.get ('desc') }}
  62. {%- endif %}
  63. {%- for attr in config|sort if attr not in ['desc', 'AF'] %}
  64. {%- set value = config.get (attr) %}
  65. {#- 'is bool' only introduced in Jinja 2.11 #}
  66. {%- if salt['ffho.is_bool'](value) %}
  67. {%- set value = 'yes' if value else 'no' %}
  68. {%- endif %}
  69. {{ attr }} {{ value }};
  70. {%- endfor %}
  71. };
  72. {%- endfor %}
  73. {#-
  74. # Backbone OpenVPNs
  75. #}
  76. {%- set interfaces = {} %}
  77. {%- for vpn, vpn_config in salt['pillar.get']('ovpn', {}).items () %}
  78. {%- if grains['id'] in vpn_config %}
  79. {%- set host_config = vpn_config.get (grains['id'], {}).get ('config', {}) %}
  80. {%- set interface = host_config.get ('interface', vpn_config.get ('interface', '')) %}
  81. {%- if interface.startswith ('ovpn-') %}
  82. {%- do interfaces.update({interface: { 'cost': vpn_config.get (grains['id'], {}).get ('config', {}).get ('cost', False) }}) %}
  83. {%- endif %}
  84. {%- endif %}
  85. {%- endfor %}
  86. {%- for interface, iface_config in interfaces.items()|sort %}
  87. interface "{{ interface }}" {
  88. {%- if interface.startswith ('ovpn-er-') and not 'yni' in interface and AF == 6 %}
  89. type broadcast;
  90. {%- else %}
  91. type pointopoint;
  92. {%- endif %}
  93. {%- if iface_config.cost %}
  94. cost {{ iface_config.cost }};
  95. {%- elif interface.startswith ('ovpn-cr') %}
  96. cost 5000;
  97. {%- else %}
  98. cost 10000;
  99. {%- endif %}
  100. };
  101. {% endfor %}
  102. {%- if 'veth_int2ext' in node_config.get ('ifaces', {}) %}
  103. # Learn transfer prefix to external VRF for BGP recursive lookup.
  104. interface "veth_int2ext" {
  105. stub yes;
  106. };
  107. {%- endif %}
  108. {%- if 'ops-vpn' in roles %}
  109. interface "tun-ops" {
  110. stub yes;
  111. };
  112. {%- endif %}
  113. };
  114. {#- Interfaces for non-backbone areas (OOBM e.g.) #}
  115. {%- for area in ospf_config if area != 0 %}
  116. # Area {{ area }}
  117. {%- set area_ifaces = ospf_config[area] %}
  118. area {{ area }} {
  119. {%- for iface in area_ifaces|sort %}
  120. {%- set iface_config = area_ifaces[iface] %}
  121. {%- if iface_config.get('AF', AF) != AF %}
  122. {%- continue %}
  123. {%- endif %}
  124. interface "{{ iface }}" {
  125. {%- if 'desc' in iface_config %}
  126. # {{ iface_config.get ('desc') }}
  127. {%- endif %}
  128. {%- for attr in iface_config|sort if attr not in ['desc', 'AF'] %}
  129. {%- set value = iface_config.get (attr) %}
  130. {#- 'is bool' only introduced in Jinja 2.11 #}
  131. {%- if salt['ffho.is_bool'](value) %}
  132. {%- set value = 'yes' if value else 'no' %}
  133. {%- endif %}
  134. {{ attr }} {{ value }};
  135. {%- endfor %}
  136. };
  137. {%- endfor %}
  138. };
  139. {%- endfor %}
  140. }