300-gluon-client-bridge-network 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/lua
  2. local site = require 'gluon.site_config'
  3. local sysconfig = require 'gluon.sysconfig'
  4. local ip = require 'luci.ip'
  5. local lutil = require 'luci.util'
  6. local uci = require('luci.model.uci').cursor()
  7. local ip4, netmask, ip6
  8. if site.next_node.ip4 then
  9. ip4 = site.next_node.ip4
  10. netmask = ip.IPv4(site.prefix4):mask():string()
  11. end
  12. if site.next_node.ip6 then
  13. ip6 = site.next_node.ip6 .. '/128'
  14. end
  15. uci:section('network', 'interface', 'client',
  16. {
  17. type = 'bridge',
  18. proto = 'static',
  19. macaddr = site.next_node.mac,
  20. ipaddr = ip4,
  21. netmask = netmask,
  22. ip6addr = ip6,
  23. }
  24. )
  25. uci:delete('network', 'client', 'reqprefix')
  26. uci:delete('network', 'client', 'peerdns')
  27. uci:delete('network', 'client', 'sourcefilter')
  28. local ifname = uci:get('network', 'client', 'ifname')
  29. if type(ifname) == 'string' then
  30. uci:delete('network', 'client', 'ifname')
  31. for x in ifname:gmatch("[^%s]+") do
  32. uci:add_to_set('network', 'client', 'ifname', x)
  33. end
  34. end
  35. if sysconfig.lan_ifname and not ifname and not uci:get_bool('network', 'mesh_lan', 'auto') then
  36. for _, lanif in ipairs(lutil.split(sysconfig.lan_ifname, ' ')) do
  37. uci:add_to_set('network', 'client', 'ifname', lanif)
  38. end
  39. end
  40. uci:save('network')
  41. local dnsmasq = uci:get_first('dhcp', 'dnsmasq')
  42. uci:set('dhcp', dnsmasq, 'boguspriv', 0)
  43. uci:set('dhcp', dnsmasq, 'localise_queries', 0)
  44. uci:set('dhcp', dnsmasq, 'rebind_protection', 0)
  45. uci:delete('dhcp', 'client')
  46. uci:section('dhcp', 'dhcp', 'client',
  47. {
  48. interface = 'client',
  49. ignore = 1,
  50. }
  51. )
  52. uci:save('dhcp')