IGP.conf 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 proto == 'v6' %}
  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 proto == 'v4' %}
  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 proto == 'v6' %}
  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. {#- Interface description? #}
  54. {%- set desc = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces:' ~ iface ~ ':desc', "") %}
  55. # {{ desc }}
  56. interface "{{ iface }}" {
  57. {%- if 'desc' in config %}
  58. # {{ config.get ('desc') }}
  59. {%- endif %}
  60. {%- for attr in config|sort if attr not in ['desc'] %}
  61. {%- set value = config.get (attr) %}
  62. {#- 'is bool' only introduced in Jinja 2.11 #}
  63. {%- if salt['ffho.is_bool'](value) %}
  64. {%- set value = 'yes' if value else 'no' %}
  65. {%- endif %}
  66. {{ attr }} {{ value }};
  67. {%- endfor %}
  68. };
  69. {%- endfor %}
  70. {#-
  71. # Backbone OpenVPNs
  72. #}
  73. {%- set interfaces = {} %}
  74. {%- for vpn, vpn_config in salt['pillar.get']('ovpn', {}).items () %}
  75. {%- if grains['id'] in vpn_config %}
  76. {%- set host_config = vpn_config.get (grains['id'], {}).get ('config', {}) %}
  77. {%- set interface = host_config.get ('interface', vpn_config.get ('interface', '')) %}
  78. {%- if interface.startswith ('ovpn-') %}
  79. {%- do interfaces.update({interface: { 'cost': vpn_config.get (grains['id'], {}).get ('config', {}).get ('cost', False) }}) %}
  80. {%- endif %}
  81. {%- endif %}
  82. {%- endfor %}
  83. {%- for interface, iface_config in interfaces.items()|sort %}
  84. interface "{{ interface }}" {
  85. {%- if interface.startswith ('ovpn-er-') and not 'yni' in interface and proto == 'v6' %}
  86. type broadcast;
  87. {%- else %}
  88. type pointopoint;
  89. {%- endif %}
  90. {%- if iface_config.cost %}
  91. cost {{ iface_config.cost }};
  92. {%- elif interface.startswith ('ovpn-cr') %}
  93. cost 5000;
  94. {%- else %}
  95. cost 10000;
  96. {%- endif %}
  97. };
  98. {% endfor %}
  99. {%- if 'veth_int2ext' in node_config.get ('ifaces', {}) %}
  100. # Learn transfer prefix to external VRF for BGP recursive lookup.
  101. interface "veth_int2ext" {
  102. stub yes;
  103. };
  104. {%- endif %}
  105. {%- if 'ops-vpn' in roles %}
  106. interface "tun-ops" {
  107. stub yes;
  108. };
  109. {%- endif %}
  110. };
  111. {#- Interfaces for non-backbone areas (OOBM e.g.) #}
  112. {%- for area in ospf_config if area != 0 %}
  113. # Area {{ area }}
  114. {%- set area_ifaces = ospf_config[area] %}
  115. area {{ area }} {
  116. {%- for iface in area_ifaces|sort %}
  117. {%- set iface_config = area_ifaces[iface] %}
  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'] %}
  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. }