init.sls 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #
  2. # Fastd for gateways
  3. #
  4. include:
  5. - network
  6. {% set sites_all = pillar.get ('sites') %}
  7. {% set node_config = salt['pillar.get']('nodes:' ~ grains.id, {}) %}
  8. {% set sites_node = node_config.get('sites', {}) %}
  9. {% set device_no = node_config.get('id', -1) %}
  10. # Install fastd
  11. fastd:
  12. pkg.installed:
  13. - name: fastd
  14. service.dead:
  15. - enable: False
  16. /etc/systemd/system/fastd@.service:
  17. file.managed:
  18. - source: salt://fastd/fastd@.service
  19. /etc/fastd:
  20. file.directory:
  21. - user: root
  22. - group: root
  23. - mode: 711
  24. require:
  25. - pkg: fastd
  26. #
  27. # Is this instance to be used by external clients?
  28. {% if 'fastd_peers' in node_config.get ('roles', []) %}
  29. # publish blacklist
  30. /etc/fastd/peers-blacklist:
  31. file.managed:
  32. - source: salt://fastd/peers-blacklist
  33. - user: root
  34. - group: root
  35. - mode: 644
  36. - require:
  37. - file: /etc/fastd
  38. /etc/fastd/verify-peer.sh:
  39. file.managed:
  40. - source: salt://fastd/verify-peer.sh
  41. - user: root
  42. - group: root
  43. - mode: 744
  44. - require:
  45. - file: /etc/fastd
  46. {% endif %}
  47. #
  48. # Set up fastd configuration for every network (nodes4, nodes6, intergw-vpn)
  49. # for every site associated for the current minion ID.
  50. #
  51. {% for site in sites_all %}
  52. {% set networks_absent = [] %}
  53. {% set networks_present = [] %}
  54. {% set site_no = sites_all.get(site, {}).get('site_no') %}
  55. {% if site in sites_node %}
  56. {% do networks_present.extend(['intergw']) %}
  57. {% if 'fastd_peers' in node_config.get('roles', []) %}
  58. {% do networks_present.extend(['nodes4', 'nodes6']) %}
  59. {% else %}
  60. {% do networks_absent.extend(['nodes4', 'nodes6']) %}
  61. {% endif %}
  62. {% else %}
  63. {% do networks_absent.extend(['intergw', 'nodes4', 'nodes6']) %}
  64. {% endif %}
  65. {% for network in networks_present %}
  66. {% set network_type = 'nodes' if network.startswith ('nodes') else network %}
  67. {% set instance_name = site ~ '_' ~ network %}
  68. {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, network) %}
  69. /etc/fastd/{{ instance_name }}:
  70. file.directory:
  71. - makedirs: true
  72. - mode: 755
  73. - require:
  74. - file: /etc/fastd
  75. /etc/fastd/{{ instance_name }}/fastd.conf:
  76. file.managed:
  77. - source: salt://fastd/fastd.conf
  78. - template: jinja
  79. network: {{ network }}
  80. network_type: {{ network_type }}
  81. secret: {{ node_config.get('fastd', {}).get(network_type ~ '_privkey') }}
  82. site: {{ site }}
  83. site_no: {{ site_no }}
  84. mac_address: {{ mac_address }}
  85. {% if 'batman_ext' in node_config.get('roles', []) %}
  86. bat_iface: bat-{{ site }}-ext
  87. {% else %}
  88. bat_iface: bat-{{ site }}
  89. {% endif %}
  90. peer_limit: {{ node_config.get('fastd', {}).get('peer_limit', False) }}
  91. - require:
  92. - file: /etc/fastd/{{ instance_name }}
  93. /etc/fastd/{{ instance_name }}/secret.conf:
  94. file.absent
  95. # Create systemd start link
  96. fastd@{{ instance_name }}:
  97. service.running:
  98. - enable: True
  99. - require:
  100. - file: /etc/systemd/system/fastd@.service
  101. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  102. - service: fastd
  103. - watch:
  104. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  105. {% endfor %}{# for network in networks #}
  106. #
  107. # Cleanup configurations for previosly configured instances.
  108. # Stop fastd instance before purging the configuration.
  109. {% for network in networks_absent %}
  110. {% set instance_name = site ~ '_' ~ network %}
  111. Cleanup /etc/fastd/{{ instance_name }}:
  112. file.absent:
  113. - name: /etc/fastd/{{ instance_name }}
  114. # stop fastd service
  115. Stop fastd@{{ instance_name }}:
  116. service.dead:
  117. - name: fastd@{{ instance_name }}
  118. - enable: False
  119. - prereq:
  120. - file: Cleanup /etc/fastd/{{ instance_name }}
  121. {% endfor %}
  122. {% endfor %}{# for site in sites_all #}
  123. ff_fastd_con_pkgs:
  124. pkg.installed:
  125. - pkgs:
  126. - socat
  127. - jq
  128. /usr/local/bin/ff_fastd_conn:
  129. file.managed:
  130. - source: salt://fastd/ff_fastd_con
  131. - mode: 755
  132. - user: root
  133. - group: root