220-interface-lan 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/lua
  2. local site = require 'gluon.site'
  3. local util = require 'gluon.util'
  4. local sysconfig = require 'gluon.sysconfig'
  5. local uci = require('simple-uci').cursor()
  6. if not sysconfig.lan_ifname then
  7. os.exit(0)
  8. end
  9. local old_proto = uci:get('network', 'mesh_lan', 'proto')
  10. uci:section('network', 'interface', 'mesh_lan', {
  11. ifname = sysconfig.lan_ifname,
  12. igmp_snooping = false,
  13. proto = 'gluon_wired',
  14. index = 4,
  15. })
  16. if sysconfig.lan_ifname:match(' ') then
  17. uci:set('network', 'mesh_lan', 'type', 'bridge')
  18. else
  19. uci:delete('network', 'mesh_lan', 'type')
  20. end
  21. local enable = site.mesh_on_lan(false)
  22. local old_auto = uci:get('network', 'mesh_lan', 'auto')
  23. local old_disabled = uci:get('network', 'mesh_lan', 'disabled')
  24. if old_auto ~= nil or old_disabled ~= nil then
  25. enable = old_auto ~= '0' and old_disabled ~= '1'
  26. end
  27. if enable then
  28. local interfaces = uci:get_list('network', 'client', 'ifname')
  29. if interfaces then
  30. for lanif in sysconfig.lan_ifname:gmatch('%S+') do
  31. if util.contains(interfaces, lanif) then
  32. enable = false
  33. break
  34. end
  35. end
  36. end
  37. end
  38. uci:set('network', 'mesh_lan', 'disabled', not enable)
  39. if uci:get('network', 'mesh_lan', 'transitive') == nil then
  40. uci:set('network', 'mesh_lan', 'transitive', true)
  41. end
  42. if uci:get('network', 'mesh_lan', 'legacy') == nil then
  43. uci:set('network', 'mesh_lan', 'legacy', old_proto == 'gluon_mesh')
  44. end
  45. uci:delete('network', 'mesh_lan', 'auto')
  46. uci:delete('network', 'mesh_lan', 'fixed_mtu')
  47. uci:save('network')