IGP.conf 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 'ops-vpn' in roles %}
  103. interface "tun-ops" {
  104. stub yes;
  105. };
  106. {%- endif %}
  107. };
  108. {#- Interfaces for non-backbone areas (OOBM e.g.) #}
  109. {%- for area in ospf_config if area != 0 %}
  110. # Area {{ area }}
  111. {%- set area_ifaces = ospf_config[area] %}
  112. area {{ area }} {
  113. {%- for iface in area_ifaces|sort %}
  114. {%- set iface_config = area_ifaces[iface] %}
  115. {%- if iface_config.get('AF', AF) != AF %}
  116. {%- continue %}
  117. {%- endif %}
  118. interface "{{ iface }}" {
  119. {%- if 'desc' in iface_config %}
  120. # {{ iface_config.get ('desc') }}
  121. {%- endif %}
  122. {%- for attr in iface_config|sort if attr not in ['desc', 'AF'] %}
  123. {%- set value = iface_config.get (attr) %}
  124. {#- 'is bool' only introduced in Jinja 2.11 #}
  125. {%- if salt['ffho.is_bool'](value) %}
  126. {%- set value = 'yes' if value else 'no' %}
  127. {%- endif %}
  128. {{ attr }} {{ value }};
  129. {%- endfor %}
  130. };
  131. {%- endfor %}
  132. };
  133. {%- endfor %}
  134. }