From f8f8a9ce004ca7f2b9c884a692c076d7962e08e5 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 27 Apr 2016 17:25:07 +0200 Subject: [PATCH] gluon-mesh-batman-adv-*: configure batadv interfaces from hotplug script instead of netifd --- package/gluon-mesh-batman-adv-14/Makefile | 2 - .../hotplug.d/net/30-gluon-mesh-batman-adv-14 | 6 +++ .../upgrade/350-gluon-mesh-batman-adv-14 | 47 ------------------- package/gluon-mesh-batman-adv-15/Makefile | 2 - .../hotplug.d/net/30-gluon-mesh-batman-adv-15 | 6 +++ .../upgrade/350-gluon-mesh-batman-adv-15 | 47 ------------------- .../enable_mesh_interface | 38 +++++++++++++++ .../320-gluon-mesh-batman-adv-core-wireless | 12 ++--- ...330-gluon-mesh-batman-adv-core-mesh-on-wan | 4 +- ...340-gluon-mesh-batman-adv-core-mesh-on-lan | 10 +--- 10 files changed, 59 insertions(+), 115 deletions(-) create mode 100644 package/gluon-mesh-batman-adv-14/files/etc/hotplug.d/net/30-gluon-mesh-batman-adv-14 delete mode 100755 package/gluon-mesh-batman-adv-14/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-14 create mode 100644 package/gluon-mesh-batman-adv-15/files/etc/hotplug.d/net/30-gluon-mesh-batman-adv-15 delete mode 100755 package/gluon-mesh-batman-adv-15/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-15 create mode 100755 package/gluon-mesh-batman-adv-core/files/lib/gluon/mesh-batman-adv-core/enable_mesh_interface diff --git a/package/gluon-mesh-batman-adv-14/Makefile b/package/gluon-mesh-batman-adv-14/Makefile index 504d7c2f..aa53e85f 100644 --- a/package/gluon-mesh-batman-adv-14/Makefile +++ b/package/gluon-mesh-batman-adv-14/Makefile @@ -24,12 +24,10 @@ define Build/Configure endef define Build/Compile - $(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/) endef define Package/gluon-mesh-batman-adv-14/install $(CP) ./files/* $(1)/ - $(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/ endef $(eval $(call BuildPackage,gluon-mesh-batman-adv-14)) diff --git a/package/gluon-mesh-batman-adv-14/files/etc/hotplug.d/net/30-gluon-mesh-batman-adv-14 b/package/gluon-mesh-batman-adv-14/files/etc/hotplug.d/net/30-gluon-mesh-batman-adv-14 new file mode 100644 index 00000000..979d7d77 --- /dev/null +++ b/package/gluon-mesh-batman-adv-14/files/etc/hotplug.d/net/30-gluon-mesh-batman-adv-14 @@ -0,0 +1,6 @@ +[ "$ACTION" = 'add' ] || exit 0 + +# Exit if we're in setup mode +[ $(lua -e 'uci_state=require("luci.model.uci").cursor_state(); print(uci_state:get_first("gluon-setup-mode", "setup_mode", "running", "0"))') = 0 ] || exit 0 + +exec /lib/gluon/mesh-batman-adv-core/enable_mesh_interface "$INTERFACE" 1528 diff --git a/package/gluon-mesh-batman-adv-14/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-14 b/package/gluon-mesh-batman-adv-14/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-14 deleted file mode 100755 index 30e2682b..00000000 --- a/package/gluon-mesh-batman-adv-14/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-14 +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/lua - -local site = require 'gluon.site_config' - -local uci = require('luci.model.uci').cursor() - - -local function configure_mtu(radio, config, mtu) - if config.ibss then - local network = 'ibss_' .. radio - - if config.ibss.vlan then - uci:set('network', network, 'mtu', mtu + 4) - uci:set('network', network .. '_vlan', 'mtu', mtu) - else - uci:set('network', network, 'mtu', mtu) - end - end - - if config.mesh then - uci:set('network', 'mesh_' .. radio, 'mtu', mtu) - end -end - - -local radios = {} - -uci:foreach('wireless', 'wifi-device', - function(s) - table.insert(radios, s['.name']) - end -) - -local mtu = 1528 - -for _, radio in ipairs(radios) do - local hwmode = uci:get('wireless', radio, 'hwmode') - - if hwmode == '11g' or hwmode == '11ng' then - configure_mtu(radio, site.wifi24, mtu) - elseif hwmode == '11a' or hwmode == '11na' then - configure_mtu(radio, site.wifi5, mtu) - end -end - - -uci:save('network') diff --git a/package/gluon-mesh-batman-adv-15/Makefile b/package/gluon-mesh-batman-adv-15/Makefile index d07d2832..d64fea88 100644 --- a/package/gluon-mesh-batman-adv-15/Makefile +++ b/package/gluon-mesh-batman-adv-15/Makefile @@ -24,12 +24,10 @@ define Build/Configure endef define Build/Compile - $(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/) endef define Package/gluon-mesh-batman-adv-15/install $(CP) ./files/* $(1)/ - $(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/ endef $(eval $(call BuildPackage,gluon-mesh-batman-adv-15)) diff --git a/package/gluon-mesh-batman-adv-15/files/etc/hotplug.d/net/30-gluon-mesh-batman-adv-15 b/package/gluon-mesh-batman-adv-15/files/etc/hotplug.d/net/30-gluon-mesh-batman-adv-15 new file mode 100644 index 00000000..2706668e --- /dev/null +++ b/package/gluon-mesh-batman-adv-15/files/etc/hotplug.d/net/30-gluon-mesh-batman-adv-15 @@ -0,0 +1,6 @@ +[ "$ACTION" = 'add' ] || exit 0 + +# Exit if we're in setup mode +[ $(lua -e 'uci_state=require("luci.model.uci").cursor_state(); print(uci_state:get_first("gluon-setup-mode", "setup_mode", "running", "0"))') = 0 ] || exit 0 + +exec /lib/gluon/mesh-batman-adv-core/enable_mesh_interface "$INTERFACE" 1532 diff --git a/package/gluon-mesh-batman-adv-15/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-15 b/package/gluon-mesh-batman-adv-15/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-15 deleted file mode 100755 index 7148d42c..00000000 --- a/package/gluon-mesh-batman-adv-15/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-15 +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/lua - -local site = require 'gluon.site_config' - -local uci = require('luci.model.uci').cursor() - - -local function configure_mtu(radio, config, mtu) - if config.ibss then - local network = 'ibss_' .. radio - - if config.ibss.vlan then - uci:set('network', network, 'mtu', mtu + 4) - uci:set('network', network .. '_vlan', 'mtu', mtu) - else - uci:set('network', network, 'mtu', mtu) - end - end - - if config.mesh then - uci:set('network', 'mesh_' .. radio, 'mtu', mtu) - end -end - - -local radios = {} - -uci:foreach('wireless', 'wifi-device', - function(s) - table.insert(radios, s['.name']) - end -) - -local mtu = 1532 - -for _, radio in ipairs(radios) do - local hwmode = uci:get('wireless', radio, 'hwmode') - - if hwmode == '11g' or hwmode == '11ng' then - configure_mtu(radio, site.wifi24, mtu) - elseif hwmode == '11a' or hwmode == '11na' then - configure_mtu(radio, site.wifi5, mtu) - end -end - - -uci:save('network') diff --git a/package/gluon-mesh-batman-adv-core/files/lib/gluon/mesh-batman-adv-core/enable_mesh_interface b/package/gluon-mesh-batman-adv-core/files/lib/gluon/mesh-batman-adv-core/enable_mesh_interface new file mode 100755 index 00000000..5406af0f --- /dev/null +++ b/package/gluon-mesh-batman-adv-core/files/lib/gluon/mesh-batman-adv-core/enable_mesh_interface @@ -0,0 +1,38 @@ +#!/usr/bin/lua + +local mesh = require 'gluon.mesh' +local util = require 'gluon.util' + +local fs = require 'nixio.fs' + + +local ifname = arg[1] +local mtu = tonumber(arg[2]) + +local interfaces = mesh.interfaces() +local interface = interfaces[ifname] + +if not interface then + os.exit(0) +end + +if not interface.fixed_mtu then + -- If we have a VLAN on a wireless interface, we need to adjust the MTU of the real interface... + local lower = fs.glob('/sys/class/net/' .. ifname .. '/lower_*')() + if lower then + lower = lower:match('/lower_([^/]+)$') + if fs.access('/sys/class/net/' .. lower .. '/wireless') then + util.exec('ip', 'link', 'set', 'dev', lower, 'mtu', tostring(mtu+4)) + end + end + + util.exec('ip', 'link', 'set', 'dev', ifname, 'mtu', tostring(mtu)) +end + +local file = assert(io.open('/sys/class/net/' .. ifname .. '/batman_adv/mesh_iface', 'w')) +file:write('bat0') +file:close() + +file = assert(io.open('/sys/class/net/' .. ifname .. '/batman_adv/no_rebroadcast', 'w')) +file:write(interface.transitive and '1' or '0') +file:close() diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless index 864e23b2..ea6580a9 100755 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless +++ b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless @@ -50,8 +50,8 @@ local function configure_ibss(config, radio, index, suffix, disabled) uci:section('network', 'interface', name .. '_vlan', { ifname = '@' .. name .. '.' .. config.vlan, - proto = 'batadv', - mesh = 'bat0', + proto = 'none', + auto = 1, } ) @@ -59,8 +59,8 @@ local function configure_ibss(config, radio, index, suffix, disabled) else uci:section('network', 'interface', name, { - proto = 'batadv', - mesh = 'bat0', + proto = 'none', + auto = 1, } ) @@ -104,8 +104,8 @@ local function configure_mesh(config, radio, index, suffix, disabled) uci:section('network', 'interface', name, { - proto = 'batadv', - mesh = 'bat0', + proto = 'none', + auto = 1, } ) diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/330-gluon-mesh-batman-adv-core-mesh-on-wan b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/330-gluon-mesh-batman-adv-core-mesh-on-wan index 33b77abf..9272196f 100755 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/330-gluon-mesh-batman-adv-core-mesh-on-wan +++ b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/330-gluon-mesh-batman-adv-core-mesh-on-wan @@ -9,9 +9,7 @@ local c = uci.cursor() if not c:get('network', 'mesh_wan') then c:section('network', 'interface', 'mesh_wan', { ifname = 'br-wan' - , proto = 'batadv' - , mesh = 'bat0' - , mesh_no_rebroadcast = '1' + , proto = 'none' , auto = site.mesh_on_wan and 1 or 0 }) end diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/340-gluon-mesh-batman-adv-core-mesh-on-lan b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/340-gluon-mesh-batman-adv-core-mesh-on-lan index 81452587..dc3a4f42 100755 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/340-gluon-mesh-batman-adv-core-mesh-on-lan +++ b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/340-gluon-mesh-batman-adv-core-mesh-on-lan @@ -16,9 +16,7 @@ uci:section('network', 'interface', 'mesh_lan', { ifname = sysconfig.lan_ifname, type = 'bridge', igmp_snooping = 0, - proto = 'batadv', - mesh = 'bat0', - mesh_no_rebroadcast = '1', + proto = 'none', macaddr = util.get_mac(3), }) @@ -43,8 +41,4 @@ end uci:save('network') -if uci:get_bool('network', 'mesh_lan', 'auto') then - mesh.register_interface('br-mesh_lan', {transitive = true}) -else - mesh.unregister_interface('br-mesh_lan') -end +mesh.register_interface('br-mesh_lan', {transitive = true})