init.sls 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #
  2. # Fastd for gateways
  3. #
  4. {% set sites_all = pillar.get ('sites') %}
  5. {% set node_config = salt['pillar.get']('nodes:' ~ grains.id, {}) %}
  6. {% set sites_node = node_config.get('sites', {}) %}
  7. {% set device_no = node_config.get('id', -1) %}
  8. include:
  9. - apt
  10. - network.interfaces
  11. {% if 'fastd_peers' in node_config.get('roles', []) %}
  12. - fastd.peers
  13. {% endif %}
  14. # Install fastd
  15. fastd:
  16. pkg.installed:
  17. - name: fastd
  18. - require:
  19. - sls: network.interfaces
  20. service.dead:
  21. - enable: False
  22. /etc/systemd/system/fastd@.service:
  23. file.managed:
  24. - source: salt://fastd/fastd@.service
  25. /etc/fastd:
  26. file.directory:
  27. - user: root
  28. - group: root
  29. - mode: 711
  30. require:
  31. - pkg: fastd
  32. #
  33. # Set up fastd configuration for every network (nodes4, nodes6, intergw-vpn)
  34. # for every site associated for the current minion ID.
  35. #
  36. {% for site in sites_node %}
  37. {% set site_no = sites_all.get(site, {}).get('site_no') %}
  38. {% set networks = ['intergw'] %}
  39. {% if 'fastd_peers' in node_config.get('roles', []) %}
  40. {% do networks.extend (['nodes4', 'nodes6']) %}
  41. {% endif %}
  42. {% for network in networks %}
  43. {% set network_type = 'nodes' if network.startswith ('nodes') else network %}
  44. {% set instance_name = site ~ '_' ~ network %}
  45. {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, network) %}
  46. /etc/fastd/{{ instance_name }}:
  47. file.directory:
  48. - makedirs: true
  49. - mode: 755
  50. - require:
  51. - file: /etc/fastd
  52. /etc/fastd/{{ instance_name }}/fastd.conf:
  53. file.managed:
  54. - source: salt://fastd/fastd.conf
  55. - template: jinja
  56. network: {{ network }}
  57. network_type: {{ network_type }}
  58. secret: {{ node_config.get('fastd', {}).get(network_type ~ '_privkey') }}
  59. site: {{ site }}
  60. site_no: {{ site_no }}
  61. mac_address: {{ mac_address }}
  62. {% if 'batman_ext' in node_config.get('roles', []) %}
  63. bat_iface: bat-{{ site }}-ext
  64. {% else %}
  65. bat_iface: bat-{{ site }}
  66. {% endif %}
  67. peer_limit: {{ node_config.get('fastd', {}).get('peer_limit', False) }}
  68. - require:
  69. - file: /etc/fastd/{{ instance_name }}
  70. - watch_in:
  71. /etc/fastd/{{ instance_name }}/secret.conf:
  72. file.absent
  73. # Create systemd start link
  74. fastd@{{ instance_name }}:
  75. service.running:
  76. - enable: True
  77. - reload: True
  78. - require:
  79. - file: /etc/systemd/system/fastd@.service
  80. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  81. - service: fastd
  82. - watch:
  83. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  84. {% if network in ['nodes4', 'nodes6'] %}
  85. - git: peers-git
  86. {% else %}
  87. - file: /etc/fastd/{{ instance_name }}/gateways/*
  88. {% endif %}
  89. {% endfor %} # // foreach network in $site
  90. #
  91. # Generate Inter-GW peers from pillar
  92. /etc/fastd/{{ site }}_intergw/gateways:
  93. file.directory:
  94. - makedirs: true
  95. - mode: 755
  96. - require:
  97. - file: /etc/fastd/{{ site }}_intergw
  98. #
  99. # Set up Inter-Gw-VPN link to all nodes of this site
  100. {% set has_ipv6 = False %}
  101. {% if salt['ffho_net.get_node_iface_ips'](node_config, 'vrf_external')['v6']|length %}
  102. {% set has_ipv6 = True %}
  103. {% endif %}
  104. {% for node, peer_config in salt['pillar.get']('nodes').items ()|sort %}
  105. /etc/fastd/{{ site }}_intergw/gateways/{{ node }}:
  106. {% if site in peer_config.get ('sites', {}) and 'fastd' in peer_config %}
  107. file.managed:
  108. - source: salt://fastd/inter-gw.peer.tmpl
  109. - template: jinja
  110. site: {{ site }}
  111. site_no: {{ site_no }}
  112. has_ipv6: {{ has_ipv6 }}
  113. node: {{ node }}
  114. pubkey: {{ peer_config.get('fastd', {}).get('intergw_pubkey') }}
  115. - require:
  116. - file: /etc/fastd/{{ site }}_intergw/gateways
  117. {% else %}
  118. file.absent
  119. {% endif %}
  120. {% endfor %} # // foreach node
  121. {% endfor %} # // foreach site
  122. #
  123. # Cleanup configurations for previosly configured instances.
  124. # Stop fastd instance before purging the configuration.
  125. {% for site in sites_all if site not in sites_node %}
  126. {% for network in ['intergw', 'nodes4', 'nodes6'] %}
  127. {% set instance_name = site ~ '_' ~ network %}
  128. Cleanup /etc/fastd/{{ instance_name }}:
  129. file.absent:
  130. - name: /etc/fastd/{{ instance_name }}
  131. # stop fastd service
  132. Stop fastd@{{ instance_name }}:
  133. service.dead:
  134. - name: fastd@{{ instance_name }}
  135. - enable: False
  136. - prereq:
  137. - file: Cleanup /etc/fastd/{{ instance_name }}
  138. {% endfor %}
  139. {% endfor %}
  140. /usr/local/bin/ff_log_vpnpeer:
  141. file.managed:
  142. - source: salt://fastd/ff_log_vpnpeer
  143. - template: jinja
  144. - mode: 755
  145. ff_fastd_con_pkgs:
  146. pkg.installed:
  147. - pkgs:
  148. - socat
  149. - jq
  150. /usr/local/bin/ff_fastd_conn:
  151. file.managed:
  152. - source: salt://fastd/ff_fastd_con
  153. - mode: 755
  154. - user: root
  155. - group: root