400-mesh-vpn-fastd 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/lua
  2. local site = require 'gluon.site_config'
  3. local users = require 'gluon.users'
  4. local util = require 'gluon.util'
  5. local uci = require('luci.model.uci').cursor()
  6. -- The previously used user is removed, we need root privileges to use the packet_mark option
  7. users.remove_user('gluon-fastd')
  8. -- Group for iptables rule
  9. users.add_group('gluon-fastd', 800)
  10. local enabled = uci:get('fastd', 'mesh_vpn', 'enabled')
  11. if not enabled then
  12. enabled = site.fastd_mesh_vpn.enabled and 1 or 0
  13. end
  14. uci:section('fastd', 'fastd', 'mesh_vpn',
  15. {
  16. enabled = enabled,
  17. group = 'gluon-fastd',
  18. syslog_level = 'verbose',
  19. interface = 'mesh-vpn',
  20. mode = 'tap',
  21. mtu = site.fastd_mesh_vpn.mtu,
  22. secure_handshakes = 1,
  23. method = site.fastd_mesh_vpn.methods,
  24. packet_mark = 1,
  25. status_socket = '/var/run/fastd.mesh_vpn.socket',
  26. }
  27. )
  28. uci:delete('fastd', 'mesh_vpn', 'user')
  29. uci:delete('fastd', 'mesh_vpn_backbone')
  30. uci:section('fastd', 'peer_group', 'mesh_vpn_backbone',
  31. {
  32. enabled = 1,
  33. net = 'mesh_vpn',
  34. peer_limit = site.fastd_mesh_vpn.backbone.limit,
  35. }
  36. )
  37. uci:delete_all('fastd', 'peer',
  38. function(peer)
  39. return peer.net == 'mesh_vpn' and peer.group == 'mesh_vpn_backbone'
  40. end
  41. )
  42. for name, config in pairs(site.fastd_mesh_vpn.backbone.peers) do
  43. uci:section('fastd', 'peer', 'mesh_vpn_backbone_peer_' .. name,
  44. {
  45. enabled = 1,
  46. net = 'mesh_vpn',
  47. group = 'mesh_vpn_backbone',
  48. key = config.key,
  49. remote = config.remotes,
  50. }
  51. )
  52. end
  53. uci:save('fastd')
  54. uci:commit('fastd')
  55. uci:section('network', 'interface', 'mesh_vpn',
  56. {
  57. ifname = 'mesh-vpn',
  58. proto = 'batadv',
  59. mesh = 'bat0',
  60. mesh_no_rebroadcast = 1,
  61. macaddr = util.generate_mac(4, 0),
  62. }
  63. )
  64. uci:save('network')
  65. uci:commit('network')
  66. uci:section('firewall', 'include', 'mesh_vpn_dns',
  67. {
  68. type = 'restore',
  69. path = '/lib/gluon/mesh-vpn-fastd/iptables.rules',
  70. family = 'ipv4',
  71. }
  72. )
  73. uci:save('firewall')
  74. uci:commit('firewall')