IGP.conf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. {%- if proto == 'v6' %}
  11. # Bloody workaround for bird6's unwillingness to read !LL IPv6 addresses from lo
  12. protocol direct lo_v6 {
  13. interface "lo";
  14. }
  15. {%- endif %}
  16. protocol ospf IGP {
  17. import all;
  18. {%- if proto == 'v4' %}
  19. {%- if grains['id'].startswith ('cr') %}
  20. export filter {
  21. if net = 0.0.0.0/0 then {
  22. ospf_metric1 = 100;
  23. accept;
  24. }
  25. reject;
  26. };
  27. {%- else %}
  28. export none;
  29. {%- endif %}
  30. {%- elif proto == 'v6' %}
  31. export filter {
  32. {%- if grains['id'].startswith ('cr') %}
  33. if net = ::/0 then {
  34. ospf_metric1 = 100;
  35. accept;
  36. }
  37. {%- endif %}
  38. if proto = "lo_v6" then {
  39. ospf_metric1 = 100;
  40. accept;
  41. }
  42. reject;
  43. };
  44. {%- endif %}
  45. area 0.0.0.0 {
  46. stub {{ ospf_node_config.get ('stub_router', 'no') }} ;
  47. interface "lo" {
  48. stub yes;
  49. };
  50. {%- set ospf_interface_config = salt['ffho_net.get_ospf_interface_config'](node_config, grains['id']) %}
  51. {%- for iface in ospf_interface_config|sort %}
  52. {%- set config = ospf_interface_config.get (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. }