init.sls 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. /etc/fastd/{{ instance_name }}/secret.conf:
  71. file.absent
  72. # Create systemd start link
  73. fastd@{{ instance_name }}:
  74. service.running:
  75. - enable: True
  76. - require:
  77. - file: /etc/systemd/system/fastd@.service
  78. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  79. - service: fastd
  80. - watch:
  81. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  82. {% if network_type == 'nodes' %}
  83. - git: peers-git
  84. {% endif %}
  85. {% endfor %}{# for network in networks #}
  86. #
  87. # Remove old Inter-GW peers folder
  88. /etc/fastd/{{ site }}_intergw/gateways:
  89. file.absent
  90. {% endfor %}{# for site in sites_node #}
  91. #
  92. # Cleanup configurations for previosly configured instances.
  93. # Stop fastd instance before purging the configuration.
  94. {% for site in sites_all if site not in sites_node %}
  95. {% for network in ['intergw', 'nodes4', 'nodes6'] %}
  96. {% set instance_name = site ~ '_' ~ network %}
  97. Cleanup /etc/fastd/{{ instance_name }}:
  98. file.absent:
  99. - name: /etc/fastd/{{ instance_name }}
  100. # stop fastd service
  101. Stop fastd@{{ instance_name }}:
  102. service.dead:
  103. - name: fastd@{{ instance_name }}
  104. - enable: False
  105. - prereq:
  106. - file: Cleanup /etc/fastd/{{ instance_name }}
  107. {% endfor %}
  108. {% endfor %}
  109. /usr/local/bin/ff_log_vpnpeer:
  110. file.managed:
  111. - source: salt://fastd/ff_log_vpnpeer
  112. - template: jinja
  113. - mode: 755
  114. ff_fastd_con_pkgs:
  115. pkg.installed:
  116. - pkgs:
  117. - socat
  118. - jq
  119. /usr/local/bin/ff_fastd_conn:
  120. file.managed:
  121. - source: salt://fastd/ff_fastd_con
  122. - mode: 755
  123. - user: root
  124. - group: root