From 5cd6295265592e1a941ce20a029803aee8365b2f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Aug 2016 00:19:14 +0200 Subject: [PATCH 1/8] gluon-core: add gluon_mesh netifd proto This new protocol will allow configuring mesh interfaces independently of the used mesh protocol. --- .../files/lib/gluon/core/mesh/setup.d/.keep | 0 .../lib/gluon/core/mesh/teardown.d/.keep | 0 .../files/lib/netifd/proto/gluon_mesh.sh | 39 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 package/gluon-core/files/lib/gluon/core/mesh/setup.d/.keep create mode 100644 package/gluon-core/files/lib/gluon/core/mesh/teardown.d/.keep create mode 100755 package/gluon-core/files/lib/netifd/proto/gluon_mesh.sh diff --git a/package/gluon-core/files/lib/gluon/core/mesh/setup.d/.keep b/package/gluon-core/files/lib/gluon/core/mesh/setup.d/.keep new file mode 100644 index 00000000..e69de29b diff --git a/package/gluon-core/files/lib/gluon/core/mesh/teardown.d/.keep b/package/gluon-core/files/lib/gluon/core/mesh/teardown.d/.keep new file mode 100644 index 00000000..e69de29b diff --git a/package/gluon-core/files/lib/netifd/proto/gluon_mesh.sh b/package/gluon-core/files/lib/netifd/proto/gluon_mesh.sh new file mode 100755 index 00000000..aaa24c84 --- /dev/null +++ b/package/gluon-core/files/lib/netifd/proto/gluon_mesh.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +. /lib/functions.sh +. ../netifd-proto.sh +init_proto "$@" + +proto_gluon_mesh_init_config() { + proto_config_add_boolean fixed_mtu + proto_config_add_boolean transitive +} + +proto_gluon_mesh_setup() { + export CONFIG="$1" + export IFNAME="$2" + + local fixed_mtu transitive + json_get_vars fixed_mtu transitive + + export FIXED_MTU="$fixed_mtu" + export TRANSITIVE="$transitive" + + for script in /lib/gluon/core/mesh/setup.d/*; do + [ ! -x "$script" ] || "$script" + done + + proto_init_update "$IFNAME" 1 + proto_send_update "$CONFIG" +} + +proto_gluon_mesh_teardown() { + export CONFIG="$1" + export IFNAME="$2" + + for script in /lib/gluon/core/mesh/teardown.d/*; do + [ ! -x "$script" ] || "$script" + done +} + +add_protocol gluon_mesh From b7380decc28b069cdf74b526230cd1d01df9d581 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Aug 2016 01:02:50 +0200 Subject: [PATCH 2/8] gluon-mesh-batman-adv-*: add gluon_mesh protocol handlers --- .../mesh/setup.d/30-gluon-mesh-batman-adv-14 | 3 ++ .../teardown.d/70-gluon-mesh-batman-adv-14 | 3 ++ .../mesh/setup.d/30-gluon-mesh-batman-adv-15 | 3 ++ .../teardown.d/70-gluon-mesh-batman-adv-15 | 3 ++ .../config_mesh_interface | 44 +++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100755 package/gluon-mesh-batman-adv-14/files/lib/gluon/core/mesh/setup.d/30-gluon-mesh-batman-adv-14 create mode 100755 package/gluon-mesh-batman-adv-14/files/lib/gluon/core/mesh/teardown.d/70-gluon-mesh-batman-adv-14 create mode 100755 package/gluon-mesh-batman-adv-15/files/lib/gluon/core/mesh/setup.d/30-gluon-mesh-batman-adv-15 create mode 100755 package/gluon-mesh-batman-adv-15/files/lib/gluon/core/mesh/teardown.d/70-gluon-mesh-batman-adv-15 create mode 100755 package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface diff --git a/package/gluon-mesh-batman-adv-14/files/lib/gluon/core/mesh/setup.d/30-gluon-mesh-batman-adv-14 b/package/gluon-mesh-batman-adv-14/files/lib/gluon/core/mesh/setup.d/30-gluon-mesh-batman-adv-14 new file mode 100755 index 00000000..8be4037a --- /dev/null +++ b/package/gluon-mesh-batman-adv-14/files/lib/gluon/core/mesh/setup.d/30-gluon-mesh-batman-adv-14 @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /lib/gluon/mesh-batman-adv-core/config_mesh_interface setup 1528 diff --git a/package/gluon-mesh-batman-adv-14/files/lib/gluon/core/mesh/teardown.d/70-gluon-mesh-batman-adv-14 b/package/gluon-mesh-batman-adv-14/files/lib/gluon/core/mesh/teardown.d/70-gluon-mesh-batman-adv-14 new file mode 100755 index 00000000..494a4f9c --- /dev/null +++ b/package/gluon-mesh-batman-adv-14/files/lib/gluon/core/mesh/teardown.d/70-gluon-mesh-batman-adv-14 @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /lib/gluon/mesh-batman-adv-core/config_mesh_interface teardown diff --git a/package/gluon-mesh-batman-adv-15/files/lib/gluon/core/mesh/setup.d/30-gluon-mesh-batman-adv-15 b/package/gluon-mesh-batman-adv-15/files/lib/gluon/core/mesh/setup.d/30-gluon-mesh-batman-adv-15 new file mode 100755 index 00000000..a9b67cb0 --- /dev/null +++ b/package/gluon-mesh-batman-adv-15/files/lib/gluon/core/mesh/setup.d/30-gluon-mesh-batman-adv-15 @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /lib/gluon/mesh-batman-adv-core/config_mesh_interface setup 1532 diff --git a/package/gluon-mesh-batman-adv-15/files/lib/gluon/core/mesh/teardown.d/70-gluon-mesh-batman-adv-15 b/package/gluon-mesh-batman-adv-15/files/lib/gluon/core/mesh/teardown.d/70-gluon-mesh-batman-adv-15 new file mode 100755 index 00000000..494a4f9c --- /dev/null +++ b/package/gluon-mesh-batman-adv-15/files/lib/gluon/core/mesh/teardown.d/70-gluon-mesh-batman-adv-15 @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /lib/gluon/mesh-batman-adv-core/config_mesh_interface teardown diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface new file mode 100755 index 00000000..ad2d11d4 --- /dev/null +++ b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface @@ -0,0 +1,44 @@ +#!/usr/bin/lua + +local util = require 'gluon.util' +local fs = require 'nixio.fs' + + +local ifname = os.getenv('IFNAME') +local cmd = arg[1] + + +if cmd == 'setup' then + + local fixed_mtu = tonumber(os.getenv('FIXED_MTU')) or 0 + local transitive = tonumber(os.getenv('TRANSITIVE')) or 0 + + local mtu = tonumber(arg[2]) + + if fixed_mtu == 0 then + local lower = fs.glob('/sys/class/net/' .. ifname .. '/lower_*/wireless')() + if lower then + lower = lower:match('/lower_([^/]+)/wireless$') + util.exec('ip', 'link', 'set', 'dev', lower, 'mtu', tostring(mtu+4)) + 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(tostring(transitive)) + file:close() + +elseif cmd == 'teardown' then + + local file = io.open('/sys/class/net/' .. ifname .. '/batman_adv/mesh_iface', 'w') + if file then + file:write('none') + file:close() + end + +end From d1e6dfb7e3a02ede79224fbce1a3e9772ed81471 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Aug 2016 01:13:34 +0200 Subject: [PATCH 3/8] gluon-mesh-batman-adv-*, gluon-mesh-vpn-fastd: configure batman-adv through gluon_mesh proto --- package/gluon-mesh-batman-adv-14/Makefile | 2 - .../upgrade/350-gluon-mesh-batman-adv-14 | 47 ------------------- package/gluon-mesh-batman-adv-15/Makefile | 2 - .../upgrade/350-gluon-mesh-batman-adv-15 | 47 ------------------- .../320-gluon-mesh-batman-adv-core-wireless | 9 ++-- ...330-gluon-mesh-batman-adv-core-mesh-on-wan | 14 +++--- ...340-gluon-mesh-batman-adv-core-mesh-on-lan | 12 ++--- .../lib/gluon/upgrade/400-mesh-vpn-fastd | 14 +++--- 8 files changed, 23 insertions(+), 124 deletions(-) delete mode 100755 package/gluon-mesh-batman-adv-14/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-14 delete mode 100755 package/gluon-mesh-batman-adv-15/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-15 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/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/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/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 217fbe6a..9e23eb39 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 @@ -48,15 +48,13 @@ local function configure_ibss(config, radio, index, suffix, disabled) uci:section('network', 'interface', name .. '_vlan', { ifname = '@' .. name .. '.' .. config.vlan, - proto = 'batadv', - mesh = 'bat0', + proto = 'gluon_mesh', } ) else uci:section('network', 'interface', name, { - proto = 'batadv', - mesh = 'bat0', + proto = 'gluon_mesh', } ) end @@ -95,8 +93,7 @@ local function configure_mesh(config, radio, index, suffix, disabled) uci:section('network', 'interface', name, { - proto = 'batadv', - mesh = 'bat0', + proto = 'gluon_mesh', } ) 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 7a964ee2..eefa8d0f 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 @@ -6,13 +6,13 @@ local uci = require 'luci.model.uci' 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' - , auto = site.mesh_on_wan and 1 or 0 - }) + c:section('network', 'interface', 'mesh_wan', { + ifname = 'br-wan', + proto = 'gluon_mesh', + transitive = 1, + fixed_mtu = 1, + auto = site.mesh_on_wan and 1 or 0, + }) end c:save('network') 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 116944f8..5df00909 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 @@ -12,13 +12,13 @@ if not sysconfig.lan_ifname then end uci:section('network', 'interface', 'mesh_lan', { - ifname = sysconfig.lan_ifname, - type = 'bridge', + ifname = sysconfig.lan_ifname, + type = 'bridge', igmp_snooping = 0, - proto = 'batadv', - mesh = 'bat0', - mesh_no_rebroadcast = '1', - macaddr = util.get_mac(2), + proto = 'gluon_mesh', + transitive = 1, + fixed_mtu = 1, + macaddr = util.get_mac(2), }) if uci:get('network', 'mesh_lan', 'auto') == nil then diff --git a/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd b/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd index e660db9e..2fd35a1f 100755 --- a/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd +++ b/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd @@ -122,13 +122,13 @@ uci:save('fastd') uci:section('network', 'interface', 'mesh_vpn', - { - ifname = 'mesh-vpn', - proto = 'batadv', - mesh = 'bat0', - mesh_no_rebroadcast = 1, - macaddr = util.get_mac(3), - } + { + ifname = 'mesh-vpn', + proto = 'gluon_mesh', + transitive = 1, + fixed_mtu = 1, + macaddr = util.get_mac(3), + } ) uci:save('network') From 8434896014b8a6f5eda97720d2236591747b9a08 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 1 May 2016 14:12:23 +0200 Subject: [PATCH 4/8] gluon-mesh-batman-adv-core: move config not specific to batman-adv to gluon-core --- .../luasrc/lib/gluon/upgrade/200-wireless | 193 ++++++++++++++++-- .../lib/gluon/upgrade/210-interface-wan} | 10 +- .../lib/gluon/upgrade/220-interface-lan} | 1 - ...-gluon-mesh-batman-adv-core-mac-addresses} | 3 +- .../320-gluon-mesh-batman-adv-core-wireless | 144 ------------- .../350-gluon-mesh-batman-adv-core-rssid | 13 -- 6 files changed, 177 insertions(+), 187 deletions(-) rename package/{gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/330-gluon-mesh-batman-adv-core-mesh-on-wan => gluon-core/luasrc/lib/gluon/upgrade/210-interface-wan} (55%) rename package/{gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/340-gluon-mesh-batman-adv-core-mesh-on-lan => gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan} (96%) rename package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/{300-gluon-mesh-batman-adv-core-wan => 320-gluon-mesh-batman-adv-core-mac-addresses} (61%) delete mode 100755 package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless delete mode 100755 package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-core-rssid diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless index 2760fae7..ae23427f 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless @@ -1,10 +1,11 @@ #!/usr/bin/lua local util = require 'gluon.util' -local uci = require('luci.model.uci').cursor() local site = require 'gluon.site_config' local sysconfig = require 'gluon.sysconfig' +local uci = require('luci.model.uci').cursor() + -- Initial if not sysconfig.gluon_version then uci:delete_all('wireless', 'wifi-iface') @@ -18,30 +19,178 @@ local function get_channel(radio, config) end end -local function configure_radio(radio, index, config) - if config then - local channel = get_channel(radio, config) - - uci:delete('wireless', radio, 'disabled') - - uci:set('wireless', radio, 'channel', channel) - uci:set('wireless', radio, 'htmode', 'HT20') - uci:set('wireless', radio, 'country', site.regdom) - - if config.supported_rates then - uci:set_list('wireless', radio, 'supported_rates', config.supported_rates) - else - uci:delete('wireless', radio, 'supported_rates') - end - - if config.basic_rate then - uci:set_list('wireless', radio, 'basic_rate', config.basic_rate) - else - uci:delete('wireless', radio, 'basic_rate') - end +local function is_disabled(name) + if uci:get('wireless', name) then + return uci:get_bool('wireless', name, 'disabled') end end +-- Returns the first argument that is not nil; don't call without any non-nil arguments! +local function first_non_nil(first, ...) + if first ~= nil then + return first + else + return first_non_nil(...) + end +end + + +local function configure_ibss(config, radio, index, suffix, disabled) + local name = 'ibss_' .. radio + + uci:delete('network', name) + uci:delete('network', name .. '_vlan') + uci:delete('wireless', name) + + if not config then + return + end + + local macaddr = util.get_wlan_mac(radio, index, 3) + if not macaddr then + return + end + + if config.vlan then + uci:section('network', 'interface', name, + { + proto = 'none', + } + ) + + uci:section('network', 'interface', name .. '_vlan', + { + ifname = '@' .. name .. '.' .. config.vlan, + proto = 'gluon_mesh', + } + ) + else + uci:section('network', 'interface', name, + { + proto = 'gluon_mesh', + } + ) + end + + uci:section('wireless', 'wifi-iface', name, + { + device = radio, + network = name, + mode = 'adhoc', + ssid = config.ssid, + bssid = config.bssid, + macaddr = macaddr, + mcast_rate = config.mcast_rate, + ifname = suffix and 'ibss' .. suffix, + disabled = disabled and 1 or 0, + } + ) +end + +local function configure_mesh(config, radio, index, suffix, disabled) + local name = 'mesh_' .. radio + local macfilter = uci:get('wireless', name, 'macfilter') + local maclist = uci:get('wireless', name, 'maclist') + + uci:delete('network', name) + uci:delete('wireless', name) + + if not config then + return + end + + local macaddr = util.get_wlan_mac(radio, index, 2) + if not macaddr then + return + end + + uci:section('network', 'interface', name, + { + proto = 'gluon_mesh', + } + ) + + uci:section('wireless', 'wifi-iface', name, + { + device = radio, + network = name, + mode = 'mesh', + mesh_id = config.id, + mesh_fwding = 0, + macaddr = macaddr, + mcast_rate = config.mcast_rate, + ifname = suffix and 'mesh' .. suffix, + disabled = disabled and 1 or 0, + macfilter = macfilter, + maclist = maclist, + } + ) +end + +local function configure_radio(radio, index, config) + if not config then + return + end + + local suffix = radio:match('^radio(%d+)$') + if not suffix then + return + end + + local channel = get_channel(radio, config) + + uci:delete('wireless', radio, 'disabled') + + uci:set('wireless', radio, 'channel', channel) + uci:set('wireless', radio, 'htmode', 'HT20') + uci:set('wireless', radio, 'country', site.regdom) + + if config.supported_rates then + uci:set_list('wireless', radio, 'supported_rates', config.supported_rates) + else + uci:delete('wireless', radio, 'supported_rates') + end + + if config.basic_rate then + uci:set_list('wireless', radio, 'basic_rate', config.basic_rate) + else + uci:delete('wireless', radio, 'basic_rate') + end + + + local ibss_disabled = is_disabled('ibss_' .. radio) + local mesh_disabled = is_disabled('mesh_' .. radio) + + configure_ibss(config.ibss, radio, index, suffix, + first_non_nil( + ibss_disabled, + mesh_disabled, + (config.ibss or {}).disabled, -- will be nil if config.ibss or config.ibss.disabled is unset + false + ) + ) + configure_mesh(config.mesh, radio, index, suffix, + first_non_nil( + mesh_disabled, + ibss_disabled, + (config.mesh or {}).disabled, -- will be nil if config.mesh or config.mesh.disabled is unset + false + ) + ) +end + util.iterate_radios(configure_radio) + +if uci:get('system', 'rssid_wlan0') then + if uci:get('wireless', 'mesh_radio0') then + uci:set('system', 'rssid_wlan0', 'dev', 'mesh0') + else + uci:set('system', 'rssid_wlan0', 'dev', 'ibss0') + end + + uci:save('system') +end + uci:save('wireless') +uci:save('network') 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-core/luasrc/lib/gluon/upgrade/210-interface-wan similarity index 55% rename from package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/330-gluon-mesh-batman-adv-core-mesh-on-wan rename to package/gluon-core/luasrc/lib/gluon/upgrade/210-interface-wan index eefa8d0f..0c780f07 100755 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/330-gluon-mesh-batman-adv-core-mesh-on-wan +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/210-interface-wan @@ -1,12 +1,10 @@ #!/usr/bin/lua local site = require 'gluon.site_config' -local uci = require 'luci.model.uci' +local uci = require('luci.model.uci').cursor() -local c = uci.cursor() - -if not c:get('network', 'mesh_wan') then - c:section('network', 'interface', 'mesh_wan', { +if not uci:get('network', 'mesh_wan') then + uci:section('network', 'interface', 'mesh_wan', { ifname = 'br-wan', proto = 'gluon_mesh', transitive = 1, @@ -15,4 +13,4 @@ if not c:get('network', 'mesh_wan') then }) end -c:save('network') +uci:save('network') 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-core/luasrc/lib/gluon/upgrade/220-interface-lan similarity index 96% rename from package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/340-gluon-mesh-batman-adv-core-mesh-on-lan rename to package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan index 5df00909..21759aa9 100755 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/340-gluon-mesh-batman-adv-core-mesh-on-lan +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan @@ -18,7 +18,6 @@ uci:section('network', 'interface', 'mesh_lan', { proto = 'gluon_mesh', transitive = 1, fixed_mtu = 1, - macaddr = util.get_mac(2), }) if uci:get('network', 'mesh_lan', 'auto') == nil then diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/300-gluon-mesh-batman-adv-core-wan b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-mac-addresses similarity index 61% rename from package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/300-gluon-mesh-batman-adv-core-wan rename to package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-mac-addresses index 0d64d5b4..ca4f1474 100755 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/300-gluon-mesh-batman-adv-core-wan +++ b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-mac-addresses @@ -4,6 +4,7 @@ local util = require 'gluon.util' local uci = require('luci.model.uci').cursor() --- fix up duplicate mac addresses (for mesh-on-WAN) +-- fix up duplicate mac addresses (for meshing) uci:set('network', 'wan', 'macaddr', util.get_mac(1)) +uci:set('network', 'mesh_lan', 'macaddr', util.get_mac(2)) uci:save('network') 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 deleted file mode 100755 index 9e23eb39..00000000 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/lua - -local site = require 'gluon.site_config' -local util = require 'gluon.util' - -local uci = require('luci.model.uci').cursor() - - -local function is_disabled(name) - if uci:get('wireless', name) then - return uci:get_bool('wireless', name, 'disabled') - end -end - --- Returns the first argument that is not nil; don't call without any non-nil arguments! -local function first_non_nil(first, ...) - if first ~= nil then - return first - else - return first_non_nil(...) - end -end - - -local function configure_ibss(config, radio, index, suffix, disabled) - local name = 'ibss_' .. radio - - uci:delete('network', name) - uci:delete('network', name .. '_vlan') - uci:delete('wireless', name) - - if not config then - return - end - - local macaddr = util.get_wlan_mac(radio, index, 3) - if not macaddr then - return - end - - if config.vlan then - uci:section('network', 'interface', name, - { - proto = 'none', - } - ) - - uci:section('network', 'interface', name .. '_vlan', - { - ifname = '@' .. name .. '.' .. config.vlan, - proto = 'gluon_mesh', - } - ) - else - uci:section('network', 'interface', name, - { - proto = 'gluon_mesh', - } - ) - end - - uci:section('wireless', 'wifi-iface', name, - { - device = radio, - network = name, - mode = 'adhoc', - ssid = config.ssid, - bssid = config.bssid, - macaddr = macaddr, - mcast_rate = config.mcast_rate, - ifname = suffix and 'ibss' .. suffix, - disabled = disabled and 1 or 0, - } - ) -end - -local function configure_mesh(config, radio, index, suffix, disabled) - local name = 'mesh_' .. radio - local macfilter = uci:get('wireless', name, 'macfilter') - local maclist = uci:get('wireless', name, 'maclist') - - uci:delete('network', name) - uci:delete('wireless', name) - - if not config then - return - end - - local macaddr = util.get_wlan_mac(radio, index, 2) - if not macaddr then - return - end - - uci:section('network', 'interface', name, - { - proto = 'gluon_mesh', - } - ) - - uci:section('wireless', 'wifi-iface', name, - { - device = radio, - network = name, - mode = 'mesh', - mesh_id = config.id, - mesh_fwding = 0, - macaddr = macaddr, - mcast_rate = config.mcast_rate, - ifname = suffix and 'mesh' .. suffix, - disabled = disabled and 1 or 0, - macfilter = macfilter, - maclist = maclist, - } - ) -end - -local function configure_radio(radio, index, config) - local suffix = radio:match('^radio(%d+)$') - - local ibss_disabled = is_disabled('ibss_' .. radio) - local mesh_disabled = is_disabled('mesh_' .. radio) - - configure_ibss(config.ibss, radio, index, suffix, - first_non_nil( - ibss_disabled, - mesh_disabled, - (config.ibss or {}).disabled, -- will be nil if config.ibss or config.ibss.disabled is unset - false - ) - ) - configure_mesh(config.mesh, radio, index, suffix, - first_non_nil( - mesh_disabled, - ibss_disabled, - (config.mesh or {}).disabled, -- will be nil if config.mesh or config.mesh.disabled is unset - false - ) - ) -end - -util.iterate_radios(configure_radio) - -uci:save('wireless') -uci:save('network') diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-core-rssid b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-core-rssid deleted file mode 100755 index b6b16574..00000000 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/350-gluon-mesh-batman-adv-core-rssid +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/lua - -local uci = require('luci.model.uci').cursor() - -if uci:get('system', 'rssid_wlan0') then - if uci:get('wireless', 'mesh_radio0') then - uci:set('system', 'rssid_wlan0', 'dev', 'mesh0') - else - uci:set('system', 'rssid_wlan0', 'dev', 'ibss0') - end - - uci:save('system') -end From 9a5a8e0ab0715852b3b6fd56a4d8861b851ed674 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 1 May 2016 14:21:20 +0200 Subject: [PATCH 5/8] gluon-client-bridge: add LAN interfaces to client bridge by default (instead of doing this in the batman-adv-specific scripts) This allows to weaken the gluon-mesh-batman-adv-core dependency of gluon-luci-portconfig to gluon-client-bridge. --- .../upgrade/300-gluon-client-bridge-network | 21 ++++++++++++------- package/gluon-luci-portconfig/Makefile | 2 +- .../310-gluon-mesh-batman-adv-core-mesh | 10 +-------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/300-gluon-client-bridge-network b/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/300-gluon-client-bridge-network index 4a897f74..f5ab8582 100755 --- a/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/300-gluon-client-bridge-network +++ b/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/300-gluon-client-bridge-network @@ -1,16 +1,16 @@ #!/usr/bin/lua local sysconfig = require 'gluon.sysconfig' + +local lutil = require 'luci.util' local uci = require('luci.model.uci').cursor() -if not uci:get('network', 'client') then - uci:section('network', 'interface', 'client', - { - type = 'bridge', - } - ) -end +uci:section('network', 'interface', 'client', + { + type = 'bridge', + } +) local ifname = uci:get('network', 'client', 'ifname') @@ -21,6 +21,13 @@ if type(ifname) == 'string' then end end +if sysconfig.lan_ifname and not ifname and not uci:get_bool('network', 'mesh_lan', 'auto') then + for _, lanif in ipairs(lutil.split(sysconfig.lan_ifname, ' ')) do + uci:add_to_set('network', 'client', 'ifname', lanif) + end +end + + uci:set('network', 'client', 'macaddr', sysconfig.primary_mac) uci:save('network') diff --git a/package/gluon-luci-portconfig/Makefile b/package/gluon-luci-portconfig/Makefile index e2d0a225..d4590864 100644 --- a/package/gluon-luci-portconfig/Makefile +++ b/package/gluon-luci-portconfig/Makefile @@ -18,7 +18,7 @@ define Package/gluon-luci-portconfig SECTION:=gluon CATEGORY:=Gluon TITLE:=Luci module for advanced ethernet port configuration - DEPENDS:=+gluon-luci-admin +gluon-mesh-batman-adv + DEPENDS:=+gluon-luci-admin +gluon-client-bridge endef define Build/Prepare diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-core-mesh b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-core-mesh index 3224768c..4710d47c 100755 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-core-mesh +++ b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-core-mesh @@ -5,7 +5,6 @@ local sysctl = require 'gluon.sysctl' local site = require 'gluon.site_config' local uci = require('luci.model.uci').cursor() -local lutil = require 'luci.util' local gw_sel_class @@ -25,15 +24,8 @@ uci:section('batman-adv', 'mesh', 'bat0', ) uci:save('batman-adv') -if not uci:get('network', 'client', 'ifname') then - uci:add_to_set('network', 'client', 'ifname', 'bat0') - if sysconfig.lan_ifname and not site.mesh_on_lan then - for _, lanif in ipairs(lutil.split(sysconfig.lan_ifname, ' ')) do - uci:add_to_set('network', 'client', 'ifname', lanif) - end - end -end +uci:add_to_set('network', 'client', 'ifname', 'bat0') uci:set('network', 'client', 'proto', 'dhcpv6') uci:set('network', 'client', 'reqprefix', 'no') From 4f39be09c938888e94e6792a731b538282dd7a3f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 30 Aug 2016 03:48:12 +0200 Subject: [PATCH 6/8] gluon-core: migrate custom batadv interfaces to gluon_mesh proto Users may have defined additional mesh interfaces. Properly migrate these to avoid subtly breaking the network config (and make them ready for new mesh protocols). --- .../lib/gluon/upgrade/800-migrate-batadv | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 package/gluon-core/luasrc/lib/gluon/upgrade/800-migrate-batadv diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/800-migrate-batadv b/package/gluon-core/luasrc/lib/gluon/upgrade/800-migrate-batadv new file mode 100755 index 00000000..7843e6a1 --- /dev/null +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/800-migrate-batadv @@ -0,0 +1,24 @@ +#!/usr/bin/lua + +local uci = require('luci.model.uci').cursor() + +local function migrate_iface(iface) + if iface.proto ~= 'batadv' or iface.mesh ~= 'bat0' then + return + end + + local s = iface['.name'] + + uci:set('network', s, 'proto', 'gluon_mesh') + uci:set('network', s, 'fixed_mtu', '1') + + if iface.mesh_no_rebroadcast then + uci:set('network', s, 'transitive', iface.mesh_no_rebroadcast) + end + + uci:delete('network', s, 'mesh') + uci:delete('network', s, 'mesh_no_rebroadcast') +end + +uci:foreach('network', 'interface', migrate_iface) +uci:save('network') From 6cddaedfc70958c4acd51ba5cb0a1c66553fe0d7 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 31 Aug 2016 00:37:59 +0200 Subject: [PATCH 7/8] Reorganize MAC addresses, always explicitly set address for private WLAN Fixes #842 --- docs/dev/mac_addresses.rst | 18 +++++++++++ docs/index.rst | 1 + .../luasrc/lib/gluon/upgrade/200-wireless | 17 +++++++++++ .../luasrc/usr/lib/lua/gluon/util.lua | 30 ++++++++----------- .../lua/luci/model/cbi/admin/privatewifi.lua | 27 ++++++++--------- ...0-gluon-mesh-batman-adv-core-mac-addresses | 6 ++-- .../lib/gluon/upgrade/400-mesh-vpn-fastd | 2 +- 7 files changed, 65 insertions(+), 36 deletions(-) create mode 100644 docs/dev/mac_addresses.rst diff --git a/docs/dev/mac_addresses.rst b/docs/dev/mac_addresses.rst new file mode 100644 index 00000000..b221a302 --- /dev/null +++ b/docs/dev/mac_addresses.rst @@ -0,0 +1,18 @@ +MAC addresses +============= + +Many devices don't have enough unique MAC addresses assigned by the vendor +(in batman-adv, each mesh interface needs an own MAC address that must be unique +mesh-wide). + +Gluon tries to solve this issue by using a hash of the primary MAC address as a +45 bit MAC address prefix. The resulting 8 addresses are used as follows: + +* 0: client0; WAN +* 1: mesh0 +* 2: ibss0 +* 3: wan_radio0 (private WLAN); batman-adv primary address +* 4: client1; LAN +* 5: mesh1 +* 6: ibss1 +* 7: wan_radio1 (private WLAN); mesh VPN diff --git a/docs/index.rst b/docs/index.rst index 389f9a99..0344232e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -43,6 +43,7 @@ Developer Documentation dev/configmode dev/wan dev/i18n + dev/mac_addresses Packages -------- diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless index ae23427f..6e809572 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless @@ -127,6 +127,21 @@ local function configure_mesh(config, radio, index, suffix, disabled) ) end +local function fixup_wan(radio, index) + local name = 'wan_' .. radio + + if not uci:get('wireless', name) then + return + end + + local macaddr = util.get_wlan_mac(radio, index, 4) + if not macaddr then + return + end + + uci:set('wireless', name, 'macaddr', macaddr) +end + local function configure_radio(radio, index, config) if not config then return @@ -177,6 +192,8 @@ local function configure_radio(radio, index, config) false ) ) + + fixup_wan(radio, index) end util.iterate_radios(configure_radio) diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua index 677cfc52..0ae50b4d 100644 --- a/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua +++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua @@ -114,18 +114,18 @@ local function get_addresses(radio) end -- Generates a (hopefully) unique MAC address --- The parameter defines the ID to add to the mac addr +-- The parameter defines the ID to add to the MAC address -- -- IDs defined so far: --- 0: client0; mesh-vpn +-- 0: client0; WAN -- 1: mesh0 -- 2: ibss0 --- 3: client1; mesh-on-wan --- 4: mesh1 --- 5: ibss1 --- 6: mesh-on-lan --- 7: unused -local function generate_mac(i) +-- 3: wan_radio0 (private WLAN); batman-adv primary address +-- 4: client1; LAN +-- 5: mesh1 +-- 6: ibss1 +-- 7: wan_radio1 (private WLAN); mesh VPN +function generate_mac(i) if i > 7 or i < 0 then return nil end -- max allowed id (0b111) local hashed = string.sub(hash.md5(sysconfig.primary_mac), 0, 12) @@ -137,9 +137,9 @@ local function generate_mac(i) m1 = nixio.bit.bor(m1, 0x02) -- set locally administered bit m1 = nixio.bit.band(m1, 0xFE) -- unset the multicast bit - -- It's necessary that the first 45 bits of the mac do - -- not vary on a single hardware interface, since some chips are using - -- a hardware mac filter. (e.g 'ramips-rt305x') + -- It's necessary that the first 45 bits of the MAC address don't + -- vary on a single hardware interface, since some chips are using + -- a hardware MAC filter. (e.g 'rt305x') m6 = nixio.bit.band(m6, 0xF8) -- zero the last three bits (space needed for counting) m6 = m6 + i -- add virtual interface id @@ -147,11 +147,7 @@ local function generate_mac(i) return string.format('%02x:%s:%s:%s:%s:%02x', m1, m2, m3, m4, m5, m6) end -function get_mac(index) - return generate_mac(3*(index-1)) -end - -function get_wlan_mac_from_driver(radio, vif) +local function get_wlan_mac_from_driver(radio, vif) local primary = sysconfig.primary_mac:lower() local i = 1 @@ -172,7 +168,7 @@ function get_wlan_mac(radio, index, vif) return addr end - return generate_mac(3*(index-1) + (vif-1)) + return generate_mac(4*(index-1) + (vif-1)) end -- Iterate over all radios defined in UCI calling diff --git a/package/gluon-luci-private-wifi/luasrc/usr/lib/lua/luci/model/cbi/admin/privatewifi.lua b/package/gluon-luci-private-wifi/luasrc/usr/lib/lua/luci/model/cbi/admin/privatewifi.lua index f05eaa47..46a1a9d7 100644 --- a/package/gluon-luci-private-wifi/luasrc/usr/lib/lua/luci/model/cbi/admin/privatewifi.lua +++ b/package/gluon-luci-private-wifi/luasrc/usr/lib/lua/luci/model/cbi/admin/privatewifi.lua @@ -2,11 +2,10 @@ local uci = luci.model.uci.cursor() local util = require 'gluon.util' local f, s, o, ssid -local config = 'wireless' -- where to read the configuration from local primary_iface = 'wan_radio0' -local ssid = uci:get(config, primary_iface, "ssid") +local ssid = uci:get('wireless', primary_iface, "ssid") f = SimpleForm("wifi", translate("Private WLAN")) f.template = "admin/expertmode" @@ -19,7 +18,7 @@ s = f:section(SimpleSection, nil, translate( )) o = s:option(Flag, "enabled", translate("Enabled")) -o.default = (ssid and not uci:get_bool(config, primary_iface, "disabled")) and o.enabled or o.disabled +o.default = (ssid and not uci:get_bool('wireless', primary_iface, "disabled")) and o.enabled or o.disabled o.rmempty = false o = s:option(Value, "ssid", translate("Name (SSID)")) @@ -30,22 +29,19 @@ o.default = ssid o = s:option(Value, "key", translate("Key"), translate("8-63 characters")) o:depends("enabled", '1') o.datatype = "wpakey" -o.default = uci:get(config, primary_iface, "key") +o.default = uci:get('wireless', primary_iface, "key") function f.handle(self, state, data) if state == FORM_VALID then - uci:foreach(config, "wifi-device", - function(s) - local radio = s['.name'] + util.iterate_radios( + function(radio, index) local name = "wan_" .. radio if data.enabled == '1' then - -- get_wlan_mac_from_driver will return nil (and thus leave the - -- MAC address unset) if the driver doesn't provide enough addresses - local macaddr = util.get_wlan_mac_from_driver(radio, 4) + local macaddr = util.get_wlan_mac(radio, index, 4) -- set up WAN wifi-iface - uci:section(config, "wifi-iface", name, + uci:section('wireless', "wifi-iface", name, { device = radio, network = "wan", @@ -59,12 +55,13 @@ function f.handle(self, state, data) ) else -- disable WAN wifi-iface - uci:set(config, name, "disabled", 1) + uci:set('wireless', name, "disabled", 1) end - end) + end + ) - uci:save(config) - uci:commit(config) + uci:save('wireless') + uci:commit('wireless') end end diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-mac-addresses b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-mac-addresses index ca4f1474..38011107 100755 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-mac-addresses +++ b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-mac-addresses @@ -4,7 +4,7 @@ local util = require 'gluon.util' local uci = require('luci.model.uci').cursor() --- fix up duplicate mac addresses (for meshing) -uci:set('network', 'wan', 'macaddr', util.get_mac(1)) -uci:set('network', 'mesh_lan', 'macaddr', util.get_mac(2)) +-- fix up potentially duplicate MAC addresses (for meshing) +uci:set('network', 'wan', 'macaddr', util.generate_mac(0)) +uci:set('network', 'mesh_lan', 'macaddr', util.generate_mac(4)) uci:save('network') diff --git a/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd b/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd index 2fd35a1f..74ab4a41 100755 --- a/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd +++ b/package/gluon-mesh-vpn-fastd/luasrc/lib/gluon/upgrade/400-mesh-vpn-fastd @@ -127,7 +127,7 @@ uci:section('network', 'interface', 'mesh_vpn', proto = 'gluon_mesh', transitive = 1, fixed_mtu = 1, - macaddr = util.get_mac(3), + macaddr = util.generate_mac(7), } ) From d05cee5b55f4c5202516ad1f500986324941323d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 31 Aug 2016 01:18:10 +0200 Subject: [PATCH 8/8] gluon-mesh-batman-adv-core: explicitly set primary MAC address using a dummy interface Fixes #834 --- package/gluon-mesh-batman-adv-core/Makefile | 2 +- .../config_mesh_interface | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/package/gluon-mesh-batman-adv-core/Makefile b/package/gluon-mesh-batman-adv-core/Makefile index bd6ab490..efcf1698 100644 --- a/package/gluon-mesh-batman-adv-core/Makefile +++ b/package/gluon-mesh-batman-adv-core/Makefile @@ -13,7 +13,7 @@ define Package/gluon-mesh-batman-adv-core SECTION:=gluon CATEGORY:=Gluon TITLE:=Support for batman-adv meshing (core) - DEPENDS:=+gluon-core +libgluonutil +gluon-client-bridge +firewall +libiwinfo + DEPENDS:=+gluon-core +libgluonutil +gluon-client-bridge +firewall +libiwinfo +kmod-dummy endef define Build/Prepare diff --git a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface index ad2d11d4..bb069497 100755 --- a/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface +++ b/package/gluon-mesh-batman-adv-core/luasrc/lib/gluon/mesh-batman-adv-core/config_mesh_interface @@ -15,6 +15,15 @@ if cmd == 'setup' then local mtu = tonumber(arg[2]) + if os.execute('ip link show primary0 >/dev/null 2>&1') ~= 0 then + os.execute([[ + ip link add primary0 type dummy + echo 1 > /proc/sys/net/ipv6/conf/primary0/disable_ipv6 + ip link set primary0 address ]] .. util.generate_mac(3) .. [[ mtu ]] .. mtu .. [[ up + echo 'bat0' > /sys/class/net/primary0/batman_adv/mesh_iface + ]]) + end + if fixed_mtu == 0 then local lower = fs.glob('/sys/class/net/' .. ifname .. '/lower_*/wireless')() if lower then @@ -41,4 +50,15 @@ elseif cmd == 'teardown' then file:close() end + local other = false + for lower in fs.glob('/sys/class/net/bat0/lower_*') do + if lower ~= '/sys/class/net/bat0/lower_primary0' then + other = true + break + end + end + + if not other then + os.execute('ip link del primary0') + end end