220-interface-lan 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. type = 'bridge',
  13. igmp_snooping = false,
  14. proto = 'gluon_wired',
  15. index = 4,
  16. legacy = old_proto == 'gluon_mesh',
  17. })
  18. local enable = site.mesh_on_lan(false)
  19. local old_auto = uci:get('network', 'mesh_lan', 'auto')
  20. local old_disabled = uci:get('network', 'mesh_lan', 'disabled')
  21. if old_auto ~= nil or old_disabled ~= nil then
  22. enable = old_auto ~= '0' and old_disabled ~= '1'
  23. end
  24. if enable then
  25. local interfaces = uci:get_list('network', 'client', 'ifname')
  26. if interfaces then
  27. for lanif in sysconfig.lan_ifname:gmatch('%S+') do
  28. if util.contains(interfaces, lanif) then
  29. enable = false
  30. break
  31. end
  32. end
  33. end
  34. end
  35. uci:set('network', 'mesh_lan', 'disabled', not enable)
  36. if uci:get('network', 'mesh_lan', 'transitive') == nil then
  37. uci:set('network', 'mesh_lan', 'transitive', true)
  38. end
  39. if uci:get('network', 'mesh_lan', 'legacy') == nil then
  40. uci:set('network', 'mesh_lan', 'legacy', old_proto == 'gluon_mesh')
  41. end
  42. uci:delete('network', 'mesh_lan', 'auto')
  43. uci:delete('network', 'mesh_lan', 'fixed_mtu')
  44. uci:save('network')