From 84b63749700d501157a28ec0b11cb018bb7b71e8 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Tue, 18 Aug 2015 00:53:40 +0200 Subject: [PATCH] gluon-client-bridge: basic br-client config and wireless AP This package provides br-client and sets up a wireless AP interface for clients. --- docs/index.rst | 8 ++++ docs/package/gluon-client-bridge.rst | 11 +++++ package/gluon-client-bridge/Makefile | 36 ++++++++++++++ package/gluon-client-bridge/check_site.lua | 6 +++ .../upgrade/300-gluon-client-bridge-network | 27 +++++++++++ .../upgrade/320-gluon-client-bridge-wireless | 48 +++++++++++++++++++ package/gluon-mesh-batman-adv-core/Makefile | 2 +- .../gluon-mesh-batman-adv-core/check_site.lua | 5 -- .../310-gluon-mesh-batman-adv-core-mesh | 23 ++------- .../320-gluon-mesh-batman-adv-core-wireless | 22 --------- 10 files changed, 140 insertions(+), 48 deletions(-) create mode 100644 docs/package/gluon-client-bridge.rst create mode 100644 package/gluon-client-bridge/Makefile create mode 100644 package/gluon-client-bridge/check_site.lua create mode 100755 package/gluon-client-bridge/files/lib/gluon/upgrade/300-gluon-client-bridge-network create mode 100755 package/gluon-client-bridge/files/lib/gluon/upgrade/320-gluon-client-bridge-wireless diff --git a/docs/index.rst b/docs/index.rst index 8af06f4f..1719c239 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -43,6 +43,14 @@ Developer Documentation dev/wan dev/i18n +Packages +-------- + +.. toctree:: + :maxdepth: 1 + + package/gluon-client-bridge + Releases -------- diff --git a/docs/package/gluon-client-bridge.rst b/docs/package/gluon-client-bridge.rst new file mode 100644 index 00000000..131072f6 --- /dev/null +++ b/docs/package/gluon-client-bridge.rst @@ -0,0 +1,11 @@ +gluon-client-bridge +=================== + +This package provides a bridge (*br-client*) for connecting clients. It will +also setup a wireless interface, provided it is configured in *site.conf*. + +site.conf +--------- + +wifi24.ap.ssid / wifi5.ap.ssid + SSID for the client network diff --git a/package/gluon-client-bridge/Makefile b/package/gluon-client-bridge/Makefile new file mode 100644 index 00000000..6bbfed64 --- /dev/null +++ b/package/gluon-client-bridge/Makefile @@ -0,0 +1,36 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-client-bridge +PKG_VERSION:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(GLUONDIR)/include/package.mk + +define Package/gluon-client-bridge + SECTION:=gluon + CATEGORY:=Gluon + TITLE:=Provides a bridge and a wireless interface for clients to connect to + DEPENDS:=+gluon-core +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/gluon-client-bridge/install + $(CP) ./files/* $(1)/ +endef + +define Package/gluon-client-bridge/postinst +#!/bin/sh +$(call GluonCheckSite,check_site.lua) +endef + +$(eval $(call BuildPackage,gluon-client-bridge)) diff --git a/package/gluon-client-bridge/check_site.lua b/package/gluon-client-bridge/check_site.lua new file mode 100644 index 00000000..3a7d81ee --- /dev/null +++ b/package/gluon-client-bridge/check_site.lua @@ -0,0 +1,6 @@ +for _, config in ipairs({'wifi24', 'wifi5'}) do + if need_table(config .. '.ap', nil, false) then + need_string(config .. '.ap.ssid') + need_boolean(config .. '.ap.disabled', false) + end +end diff --git a/package/gluon-client-bridge/files/lib/gluon/upgrade/300-gluon-client-bridge-network b/package/gluon-client-bridge/files/lib/gluon/upgrade/300-gluon-client-bridge-network new file mode 100755 index 00000000..5ee558cf --- /dev/null +++ b/package/gluon-client-bridge/files/lib/gluon/upgrade/300-gluon-client-bridge-network @@ -0,0 +1,27 @@ +#!/usr/bin/lua + +local sysconfig = require 'gluon.sysconfig' +local uci = require('luci.model.uci').cursor() + + +if not uci:get('network', 'client') then + uci:section('network', 'interface', 'client', + { + type = 'bridge', + } + ) +end + +local ifname = uci:get('network', 'client', 'ifname') + +if type(ifname) == 'string' then + uci:delete('network', 'client', 'ifname') + for x in ifname:gmatch("[^%s]+") do + uci:add_to_set('network', 'client', 'ifname', x) + end +end + +uci:set('network', 'client', 'macaddr', sysconfig.primary_mac) + +uci:save('network') +uci:commit('network') diff --git a/package/gluon-client-bridge/files/lib/gluon/upgrade/320-gluon-client-bridge-wireless b/package/gluon-client-bridge/files/lib/gluon/upgrade/320-gluon-client-bridge-wireless new file mode 100755 index 00000000..4eaccacb --- /dev/null +++ b/package/gluon-client-bridge/files/lib/gluon/upgrade/320-gluon-client-bridge-wireless @@ -0,0 +1,48 @@ +#!/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(config, name) + local disabled = config and config.disabled + if uci:get('wireless', name) then + disabled = uci:get_bool('wireless', name, 'disabled') + end + + return disabled and 1 or 0 +end + +local function configure_client(config, radio, index, suffix) + local name = 'client_' .. radio + local disabled = is_disabled(config, name) + + uci:delete('wireless', name) + + if config then + uci:section('wireless', 'wifi-iface', name, + { + device = radio, + network = 'client', + mode = 'ap', + ssid = config.ssid, + macaddr = util.generate_mac(2, index), + ifname = suffix and 'client' .. suffix, + disabled = disabled, + } + ) + end +end + +local function configure_radio(radio, index, config) + local suffix = radio:match('^radio(%d+)$') + + configure_client(config.ap, radio, index, suffix) +end + +util.iterate_radios(configure_radio) + +uci:save('wireless') +uci:commit('wireless') diff --git a/package/gluon-mesh-batman-adv-core/Makefile b/package/gluon-mesh-batman-adv-core/Makefile index 8358089c..c256ac93 100644 --- a/package/gluon-mesh-batman-adv-core/Makefile +++ b/package/gluon-mesh-batman-adv-core/Makefile @@ -11,7 +11,7 @@ define Package/gluon-mesh-batman-adv-core SECTION:=gluon CATEGORY:=Gluon TITLE:=Support for batman-adv meshing (core) - DEPENDS:=+gluon-core +firewall +libiwinfo-lua + DEPENDS:=+gluon-core +gluon-client-bridge +firewall +libiwinfo-lua endef define Build/Prepare diff --git a/package/gluon-mesh-batman-adv-core/check_site.lua b/package/gluon-mesh-batman-adv-core/check_site.lua index 49fff159..19774871 100644 --- a/package/gluon-mesh-batman-adv-core/check_site.lua +++ b/package/gluon-mesh-batman-adv-core/check_site.lua @@ -1,9 +1,4 @@ for _, config in ipairs({'wifi24', 'wifi5'}) do - if need_table(config .. '.ap', nil, false) then - need_string(config .. '.ap.ssid') - need_boolean(config .. '.ap.disabled', false) - end - if need_table(config .. '.ibss', nil, false) then need_string(config .. '.ibss.ssid') need_string_match(config .. '.ibss.bssid', '^%x[02468aAcCeE]:%x%x:%x%x:%x%x:%x%x:%x%x$') diff --git a/package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/310-gluon-mesh-batman-adv-core-mesh b/package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/310-gluon-mesh-batman-adv-core-mesh index fe576e33..9fd5b4b0 100755 --- a/package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/310-gluon-mesh-batman-adv-core-mesh +++ b/package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/310-gluon-mesh-batman-adv-core-mesh @@ -24,16 +24,7 @@ uci:section('batman-adv', 'mesh', 'bat0', uci:save('batman-adv') uci:commit('batman-adv') - -if not uci:get('network', 'client') then - uci:section('network', 'interface', 'client', - { - type = 'bridge', - proto = 'dhcpv6', - reqprefix = 'no', - } - ) - +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 @@ -41,17 +32,9 @@ if not uci:get('network', 'client') then end end -local ifname = uci:get('network', 'client', 'ifname') - -if type(ifname) == 'string' then - uci:delete('network', 'client', 'ifname') - for x in ifname:gmatch("[^%s]+") do - uci:add_to_set('network', 'client', 'ifname', x) - end -end - +uci:set('network', 'client', 'proto', 'dhcpv6') +uci:set('network', 'client', 'reqprefix', 'no') uci:set('network', 'client', 'igmp_snooping', 0) -uci:set('network', 'client', 'macaddr', sysconfig.primary_mac) uci:set('network', 'client', 'peerdns', 1) uci:set('network', 'client', 'sourcefilter', 0) diff --git a/package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless b/package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless index b1423f46..66b438d8 100755 --- a/package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless +++ b/package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/320-gluon-mesh-batman-adv-core-wireless @@ -15,27 +15,6 @@ local function is_disabled(config, name) return disabled and 1 or 0 end -local function configure_client(config, radio, index, suffix) - local name = 'client_' .. radio - local disabled = is_disabled(config, name) - - uci:delete('wireless', name) - - if config then - uci:section('wireless', 'wifi-iface', name, - { - device = radio, - network = 'client', - mode = 'ap', - ssid = config.ssid, - macaddr = util.generate_mac(2, index), - ifname = suffix and 'client' .. suffix, - disabled = disabled, - } - ) - end -end - local function configure_ibss(config, radio, index, suffix) local name = 'ibss_' .. radio local disabled = is_disabled(config, name) @@ -122,7 +101,6 @@ end local function configure_radio(radio, index, config) local suffix = radio:match('^radio(%d+)$') - configure_client(config.ap, radio, index, suffix) configure_ibss(config.ibss, radio, index, suffix) configure_mesh(config.mesh, radio, index, suffix) end