310-gluon-mesh-batman-adv-core-mesh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/lua
  2. local sysconfig = require 'gluon.sysconfig'
  3. local sysctl = require 'gluon.sysctl'
  4. local site = require 'gluon.site_config'
  5. local uci = require('luci.model.uci').cursor()
  6. local gw_sel_class
  7. if site.mesh and site.mesh.batman_adv then
  8. gw_sel_class = site.mesh.batman_adv.gw_sel_class
  9. end
  10. uci:delete('batman-adv', 'bat0')
  11. uci:section('batman-adv', 'mesh', 'bat0',
  12. {
  13. orig_interval = 5000,
  14. gw_mode = 'client',
  15. gw_sel_class = gw_sel_class,
  16. hop_penalty = 15,
  17. multicast_mode = 0,
  18. }
  19. )
  20. uci:save('batman-adv')
  21. uci:commit('batman-adv')
  22. if not uci:get('network', 'client') then
  23. uci:section('network', 'interface', 'client',
  24. {
  25. type = 'bridge',
  26. proto = 'dhcpv6',
  27. reqprefix = 'no',
  28. }
  29. )
  30. uci:add_to_set('network', 'client', 'ifname', 'bat0')
  31. if sysconfig.lan_ifname and not site.mesh_on_lan then
  32. uci:add_to_set('network', 'client', 'ifname', sysconfig.lan_ifname)
  33. end
  34. end
  35. local ifname = uci:get('network', 'client', 'ifname')
  36. if type(ifname) == 'string' then
  37. uci:delete('network', 'client', 'ifname')
  38. for x in ifname:gmatch("[^%s]+") do
  39. uci:add_to_set('network', 'client', 'ifname', x)
  40. end
  41. end
  42. uci:set('network', 'client', 'igmp_snooping', 0)
  43. uci:set('network', 'client', 'macaddr', sysconfig.primary_mac)
  44. uci:set('network', 'client', 'peerdns', 1)
  45. uci:set('network', 'client', 'sourcefilter', 0)
  46. uci:delete('network', 'bat0')
  47. uci:section('network', 'interface', 'bat0',
  48. {
  49. ifname = 'bat0',
  50. proto = 'none',
  51. macaddr = sysconfig.primary_mac,
  52. }
  53. )
  54. uci:save('network')
  55. uci:commit('network')
  56. uci:delete('firewall', 'client')
  57. uci:section('firewall', 'zone', 'client',
  58. {
  59. name = 'client',
  60. network = {'client'},
  61. input = 'ACCEPT',
  62. output = 'ACCEPT',
  63. forward = 'REJECT',
  64. }
  65. )
  66. uci:section('firewall', 'rule', 'client_dns',
  67. {
  68. name = 'client_dns',
  69. src = 'client',
  70. dest_port = '53',
  71. target = 'REJECT',
  72. }
  73. )
  74. uci:save('firewall')
  75. uci:commit('firewall')
  76. local dnsmasq = uci:get_first('dhcp', 'dnsmasq')
  77. uci:set('dhcp', dnsmasq, 'boguspriv', 0)
  78. uci:set('dhcp', dnsmasq, 'localise_queries', 0)
  79. uci:set('dhcp', dnsmasq, 'rebind_protection', 0)
  80. uci:delete('dhcp', 'client')
  81. uci:section('dhcp', 'dhcp', 'client',
  82. {
  83. interface = 'client',
  84. ignore = 1,
  85. }
  86. )
  87. uci:save('dhcp')
  88. uci:commit('dhcp')
  89. sysctl.set('net.ipv6.conf.br-client.forwarding', 0)