Developing lightweight computation at the DSG edge

Commit 280848c6 authored by p4u's avatar p4u
Browse files

Merge branch 'testing' into clean-packages

parents 5a5efbae 4c79ca2d
......@@ -24,8 +24,8 @@ PKG_NAME:=gwck-qmp
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=git://qmp.cat/gwck.git
PKG_REV:=cd29c7207036881f5e977b6c48dcc17fb625ef75
PKG_VERSION:=r2013031301
PKG_REV:=e927991d4db0d82dfb5a4ed8fe718a0a7283984b
PKG_VERSION:=r2013050101
PKG_SOURCE_VERSION:=$(PKG_REV)
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
......@@ -64,7 +64,7 @@ define Package/gwck-qmp/install
$(INSTALL_DATA) $(PKG_BUILD_DIR)/etc/gwck/gwck_conf_qmp_ipv4 $(1)/etc/gwck/gwck_conf_qmp_ipv4
$(INSTALL_DATA) $(PKG_BUILD_DIR)/etc/gwck/gwck_conf_qmp_ipv6 $(1)/etc/gwck/gwck_conf_qmp_ipv6
$(INSTALL_DATA) $(PKG_BUILD_DIR)/etc/gwck/module/specific_routes $(1)/etc/gwck/module/specific_routes
$(INSTALL_DATA) $(PKG_BUILD_DIR)/etc/gwck/module/bmx6 $(1)/etc/gwck/module/bmx6
$(INSTALL_DATA) $(PKG_BUILD_DIR)/etc/gwck/module/qmp $(1)/etc/gwck/module/qmp
endef
......
......@@ -59,12 +59,54 @@ config 'qmp' 'networks'
option 'babel_mesh_prefix48' 'fd03:0:0'
option 'netserver' '1'
config 'qmp' 'tunnels'
option 'search_ipv4_tunnel' '0.0.0.0/0'
option 'search_ipv6_tunnel' '::/0'
# option 'offer_ipv4_tunnel' '0.0.0.0/0'
# option 'offer_ipv6_tunnel' '::/0'
config 'gateway'
option 'type' 'search'
option 'network' '::/0'
config 'gateway'
option 'ignore' '1'
option 'type' 'offer'
option 'network' '::/0'
option 'bandwidth' '100000'
config 'gateway'
option 'type' 'search'
option 'network' '0.0.0.0/0'
option 'maxPrefixLen' '0'
config 'gateway'
option 'ignore' '1'
option 'type' 'offer'
option 'network' '0.0.0.0/0'
option 'bandwidth' '100000'
config 'gateway'
option 'type' 'search'
option 'network' '10.0.0.0/8'
option 'maxPrefixLen' '8'
config 'gateway'
option 'type' 'search'
option 'network' '10.0.0.0/8'
option 'minPrefixLen' '16'
config 'gateway'
option 'ignore' '1'
option 'type' 'search'
option 'network' '::/0'
option 'gwName' 'qMp-d6'
config 'gateway'
option 'ignore' '1'
option 'type' 'search'
option 'gwName' 'qMp-ab'
option 'network' '10.1.0.0/16'
option 'address' '10.2.2.2/32'
option 'minPrefixLen' '16'
option 'maxPrefixLen' '24'
option 'hysteresis' '20'
option 'bonus' '10'
option 'exportDistance' '10'
config 'qmp' 'wireless'
option 'driver' 'mac80211'
......
......@@ -32,18 +32,18 @@ QMP_PATH="/etc/qmp"
. $QMP_PATH/qmp_update.sh
offer_default_gw() {
qmp_gw_offer_default
qmp_gw_default offer $1
qmp_gw_apply
}
search_default_gw() {
qmp_gw_search_default
qmp_gw_default search $1
qmp_gw_apply
}
disable_default_gw() {
qmp_gw_disable_default
qmp_gw_apply
qmp_gw_default disable $1
qmp_gw_apply
}
configure_wifi() {
......@@ -53,7 +53,7 @@ configure_wifi() {
}
apply_netserver() {
[ "$(qmp_uci_get networks.netserver)" == "1" ] && qmp_enable_netserver || qmp_disable_netserver
[ "$(qmp_uci_get networks.netserver)" == "1" ] && qmp_enable_netserver || qmp_disable_netserver
}
configure_network() {
......@@ -100,18 +100,18 @@ help() {
echo "Use: $0 <function> [params]"
echo ""
echo "Available functions:"
echo " offer_default_gw : Offers default gw to the network"
echo " search_default_gw : Search for a default gw in the network"
echo " disable_default_gw : Disables the search/offer of default gw"
echo " configure_wifi : Configure and apply current wifi settings"
echo " configure_network : Configure and apply current network settings"
echo " configure_system : Configure and apply current system settings (qmp.node section and so on)"
echo " publish_hna : Publish an IP range (v4 or v6): publish_hna <IP/NETMASK> [ID]"
echo " unpublish_hna : Unpublish a current HNA: unpublish_hna <ID>"
echo " apply_netserver : Start/stop nerserver depending on qmp configuration"
echo " enable_ns_ppt : Enable POE passtrought from NanoStation M2/5 devices. Be careful with this"
echo " upgrade [URL] : Upgrade system. By default to the last version, but image url can be provided to force"
echo " hard_reboot : Performs a hard reboot (using kernel sysrq)"
echo " offer_default_gw [ipv4|ipv6] : Offers default gw to the network IPv4 or IPv6, both versions if no value."
echo " search_default_gw [ipv4|ipv6] : Search for a default gw in the network IPv4 or IPv6, both versions if no value."
echo " disable_default_gw [ipv4|ipv6] : Disables the search/offer of default gw IPv4 and/or IPv6"
echo " configure_wifi : Configure and apply current wifi settings"
echo " configure_network : Configure and apply current network settings"
echo " configure_system : Configure and apply current system settings (qmp.node section and so on)"
echo " publish_hna : Publish an IP range (v4 or v6): publish_hna <IP/NETMASK> [ID]"
echo " unpublish_hna : Unpublish a current HNA: unpublish_hna <ID>"
echo " apply_netserver : Start/stop nerserver depending on qmp configuration"
echo " enable_ns_ppt : Enable POE passtrought from NanoStation M2/5 devices. Be careful with this"
echo " upgrade [URL] : Upgrade system. By default to the last version, but image url can be provided to force"
echo " hard_reboot : Performs a hard reboot (using kernel sysrq)"
echo ""
exit 1
}
......
......@@ -29,6 +29,11 @@ SOURCE_FUNCTIONS=1
#######################
# Importing files
######################
if [ -z "$SOURCE_OPENWRT_FUNCTIONS" ]
then
. /lib/functions.sh
SOURCE_OPENWRT_FUNCTIONS=1
fi
. $QMP_PATH/qmp_common.sh
[ -z "$SOURCE_GW" ] && . $QMP_PATH/qmp_gw.sh
[ -z "$SOURCE_NET" ] && . $QMP_PATH/qmp_network.sh
......@@ -791,6 +796,84 @@ qmp_configure_network() {
}
qmp_remove_qmp_bmx6_tunnels()
{
if echo "$1" | grep -q "^qmp-[0-9]*$"
then
uci delete bmx6.$1
fi
}
qmp_unconfigure_bmx6_gateways()
{
config_load bmx6
config_foreach qmp_remove_qmp_bmx6_tunnels tunInNet
config_foreach qmp_remove_qmp_bmx6_tunnels tunOut
}
qmp_translate_configuration()
{
orig_config=$1
orig_section=$2
orig_option=$3
dest_config=$4
dest_section=$5
dest_option=${6:-$orig_option}
value="$(uci -q get $orig_config.$orig_section.$orig_option)"
if [ -n "$value" ]
then
uci set $dest_config.$dest_section.$dest_option="$value"
fi
}
qmp_add_qmp_bmx6_tunnels()
{
local section=$1
local config=bmx6
local name="qmp_$gateway"
local ignore
config_get ignore "$section" ignore
if [ "$ignore" = "1" ]
then
return
fi
local type
config_get type "$section" type
if [ "$type" = "offer" ]
then
bmx6_type=tunInNet
uci set $config.$name="$bmx6_type"
qmp_translate_configuration qmp $section network $config $name $bmx6_type
qmp_translate_configuration qmp $section bandwidth $config $name
else
# if [ "$type" = "search" ]
bmx6_type=tunOut
uci set $config.$name="$bmx6_type"
uci set $config.$name.$bmx6_type="$name"
qmp_translate_configuration qmp $section network $config $name
qmp_translate_configuration qmp $section gwName $config $name
qmp_translate_configuration qmp $section address $config $name
qmp_translate_configuration qmp $section minPrefixLen $config $name
qmp_translate_configuration qmp $section maxPrefixLen $config $name
qmp_translate_configuration qmp $section hysteresis $config $name
qmp_translate_configuration qmp $section bonus $config $name
qmp_translate_configuration qmp $section exportDistance $config $name
fi
gateway="$(($gateway + 1))"
}
qmp_configure_bmx6_gateways()
{
qmp_unconfigure_bmx6_gateways
config_load qmp
gateway=0
config_foreach qmp_add_qmp_bmx6_tunnels gateway
}
qmp_configure_bmx6() {
# set -x
......@@ -890,31 +973,7 @@ qmp_configure_bmx6() {
uci set $conf.general.tun6Address="$(uci get qmp.networks.bmx6_ripe_prefix48):$community_node_id:0:0:0:1/64"
fi
if qmp_uci_test qmp.tunnels.search_ipv6_tunnel ; then
uci set $conf.tun6Out="tunOut"
uci set $conf.tun6Out.tunOut="tun6Out"
uci set $conf.tun6Out.network="$(uci get qmp.tunnels.search_ipv6_tunnel)"
fi
if qmp_uci_test qmp.tunnels.search_ipv4_tunnel ; then
uci set $conf.tun4Out="tunOut"
uci set $conf.tun4Out.tunOut="tun4Out"
uci set $conf.tun4Out.network="$(uci get qmp.tunnels.search_ipv4_tunnel)"
elif qmp_uci_test qmp.tunnels.offer_ipv4_tunnel ; then
uci set $conf.tunInRemote="tunInRemote"
uci set $conf.tunInRemote.tunInRemote="$(qmp_get_ula96 $(uci get qmp.networks.bmx6_mesh_prefix48):: $primary_mesh_device 2002::ffff )"
uci set $conf.tun4InNet="tunInNet"
uci set $conf.tun4InNet.tunInNet="$(uci get qmp.tunnels.offer_ipv4_tunnel)"
uci set $conf.tun4InNet.bandwidth="1000000"
fi
#Configuring the tunnel to search 10/8 networks
uci set $conf.nodes10="tunOut"
uci set $conf.nodes10.tunOut="nodes10"
uci set $conf.nodes10.network="10.0.0.0/8"
qmp_configure_bmx6_gateways
uci commit $conf
# /etc/init.d/$conf restart
......
......@@ -17,39 +17,140 @@
#
# The full GNU General Public License is included in this distribution in
# the file called "COPYING".
#
# Contributors:
# Simó Albert i Beltran
#
QMP_PATH="/etc/qmp"
SOURCE_GW=1
if [ -z "$SOURCE_OPENWRT_FUNCTIONS" ]
then
. /lib/functions.sh
SOURCE_OPENWRT_FUNCTIONS=1
fi
[ -z "$SOURCE_COMMON" ] && . $QMP_PATH/qmp_common.sh
[ -z "$SOURCE_NETWORK" ] &&. $QMP_PATH/qmp_functions.sh
qmp_gw_search_default() {
qmp_uci_set tunnels qmp
qmp_uci_set tunnels.search_ipv4_tunnel 0.0.0.0/0
qmp_uci_set tunnels.search_ipv6_tunnel ::/0
qmp_exists_gateway()
{
local config=$1
shift
local ignore=0
local exists
args_key_values="$(echo $@ | awk -v RS=' ' 'NR % 2 == 1 && $0 !~ "(ignore|bandwidth)" {a+=1} END {print a}')"
uci_key_values=$(env | grep -v -e "^CONFIG_${config}_\(TYPE\|ignore\|bandwidth\)=" | grep -c "^CONFIG_${config}_")
if [ "$args_key_values" != "$uci_key_values" ]
then
return
fi
while [ $# -ge 2 ]
do
if [ "$1" = "ignore" ]
then
ignore="$2"
else
config_get exists "$config" $1
if [ "$1" = "bandwidth" ]
then
if [ -z "$exists" ]
then
return
fi
elif [ "$exists" != "$2" ]
then
return
fi
fi
shift
shift
done
uci_set qmp "$config" ignore "$ignore"
uci_commit
qmp_gateway_found=true
}
qmp_set_gateway()
{
config_load qmp
qmp_gateway_found=false
config_foreach qmp_exists_gateway gateway $@
if ! $qmp_gateway_found
then
local config
config="$(uci add qmp gateway)"
while [ $# -ge 2 ]
do
uci_set qmp "$config" "$1" "$2"
shift
shift
done
uci_commit
fi
}
qmp_gw_search_default_ipv4() {
qmp_set_gateway ignore 1 type offer network 0.0.0.0/0 bandwidth 100000
qmp_set_gateway ignore 0 type search network 0.0.0.0/0 maxPrefixLen 0
qmp_gw_masq_wan 0
}
qmp_gw_search_default_ipv6() {
qmp_set_gateway ignore 1 type offer network ::/0 bandwidth 100000
qmp_set_gateway ignore 0 type search network ::/0
qmp_gw_masq_wan 0
qmp_uci_del tunnels.offer_ipv4_tunnel
qmp_uci_del tunnels.offer_ipv6_tunnel
}
qmp_gw_offer_default() {
qmp_uci_set tunnels qmp
qmp_uci_set tunnels.offer_ipv4_tunnel 0.0.0.0/0
qmp_uci_set tunnels.offer_ipv6_tunnel ::/0
qmp_gw_offer_default_ipv4() {
qmp_set_gateway ignore 1 type search network 0.0.0.0/0 maxPrefixLen 0
qmp_set_gateway ignore 0 type offer network 0.0.0.0/0 bandwidth 100000
qmp_gw_masq_wan 1
}
qmp_gw_offer_default_ipv6() {
qmp_set_gateway ignore 1 type search network ::/0
qmp_set_gateway ignore 0 type offer network ::/0 bandwidth 100000
qmp_gw_masq_wan 1
qmp_uci_del tunnels.search_ipv4_tunnel
qmp_uci_del tunnels.search_ipv6_tunnel
}
qmp_gw_disable_default() {
qmp_uci_del tunnels.offer_ipv4_tunnel
qmp_uci_del tunnels.offer_ipv6_tunnel
qmp_uci_del tunnels.search_ipv4_tunnel
qmp_uci_del tunnels.search_ipv6_tunnel
qmp_gw_disable_default_ipv4() {
qmp_set_gateway ignore 1 type search network 0.0.0.0/0 maxPrefixLen 0
qmp_set_gateway ignore 1 type offer network 0.0.0.0/0 bandwidth 100000
qmp_gw_masq_wan 0
}
qmp_gw_disable_default_ipv6() {
qmp_set_gateway ignore 1 type search network ::/0
qmp_set_gateway ignore 1 type offer network ::/0 bandwidth 100000
qmp_gw_masq_wan 0
}
qmp_gw_default() {
if [ -n "$2" ]
then
qmp_gw_$1_default_$2
else
qmp_gw_$1_default_ipv4
qmp_gw_$1_default_ipv6
fi
}
qmp_gw_add_interfaces_to_firewall_zone() {
local cfg=$1
local $virtual_interfaces
for interface in $(qmp_get_devices wan)
do
[ -n "$virtual_interfaces" ] && virtual_interfaces="$virtual_interfaces "
virtual_interfaces="$virtual_interfaces$(qmp_get_virtual_iface $interface)"
done
qmp_uci_set_raw firewall.$cfg.network="$virtual_interfaces"
}
qmp_gw_masq_wan() {
#First parameter is 1/0 (enable/disable masquerade). Default is 1
[ -z "$1" ] && masq=1 || masq=$1
......@@ -80,12 +181,15 @@ qmp_gw_masq_wan() {
qmp_uci_set_raw firewall.@zone[$wan].output=ACCEPT
qmp_uci_set_raw firewall.@zone[$wan].forward=ACCEPT
qmp_uci_set_raw firewall.@zone[$wan].masq=$masq
cfg=@zone[$wan]
fi
qmp_gw_add_interfaces_to_firewall_zone $cfg
}
qmp_gw_apply() {
qmp_configure_bmx6
bmx6 -c --configReload
bmx6 -c --configReload || /etc/init.d/bmx6 restart
/etc/init.d/firewall restart
}
#
# Update gateways configuration
#
# Copyright (C) 2013 Simó Albert i Beltran
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Change gateways configuration on /etc/config/qmp from:
#
# config 'qmp' 'tunnels'
# option 'search_ipv4_tunnel' '0.0.0.0/0'
# # option 'offer_ipv4_tunnel' '0.0.0.0/0'
# option 'search_ipv6_tunnel' '::/0'
# # option 'offer_ipv6_tunnel' '::/0'
#
# to:
#
# config 'gateway'
# option 'ignore' '0'
# # option 'ignore' '1'
# option 'type' 'search'
# option 'network' '::/0'
#
# config 'gateway'
# option 'ignore' '1'
# # option 'ignore' '0'
# option 'type' 'offer'
# option 'network' '::/0'
# option 'bandwidth' '100000'
#
# config 'gateway'
# option 'ignore' '0'
# # option 'ignore' '1'
# option 'type' 'search'
# option 'network' '0.0.0.0/0'
# option 'maxPrefixLen' '0'
#
# config 'gateway'
# option 'ignore' '1'
# # option 'ignore' '0'
# option 'type' 'offer'
# option 'network' '0.0.0.0/0'
# option 'bandwidth' '100000'
#
# config 'gateway'
# option 'type' 'search'
# option 'network' '10.0.0.0/8'
# option 'maxPrefixLen' '8'
#
# config 'gateway'
# option 'type' 'search'
# option 'network' '10.0.0.0/8'
# option 'minPrefixLen' '16'
#
# See also: http://qmp.cat/issues/210
[ -z "$SOURCE_GW" ] && . /etc/qmp/qmp_gw.sh
translate_tunnel()
{
local ipv="$1"
local extra_args_ignore=""
local extra_args_no_ignore=""
local tunnel_network
config_get tunnel_network tunnels search_ipv${ipv}_tunnel
if [ -n "$tunnel_network" ]
then
type_ignore="offer"
type_no_ignore="search"
extra_args_ignore="bandwidth 100000"
if [ "$ipv" = 4 ] && [ "$tunnel_network" = "0.0.0.0/0" ]
then
extra_args_no_ignore="maxPrefixLen 0"
fi
else
config_get tunnel_network tunnels offer_ipv${ipv}_tunnel
if [ -n "$tunnel_network" ]
then
type_ignore="search"
type_no_ignore="offer"
extra_args_no_ignore="bandwidth 100000"
if [ "$ipv" = 4 ] && [ "$tunnel_network" = "0.0.0.0/0" ]
then
extra_args_ignore="maxPrefixLen 0"
fi
fi
fi
if [ -n "$tunnel_network" ]
then
qmp_set_gateway ignore 1 type $type_ignore network $tunnel_network $extra_args_ignore
qmp_set_gateway ignore 0 type $type_no_ignore network $tunnel_network $extra_args_no_ignore
fi
}
if uci -q get qmp.tunnels > /dev/null
then
config_load qmp
translate_tunnel 6
translate_tunnel 4
qmp_set_gateway type search network 10.0.0.0/8 maxPrefixLen 8
qmp_set_gateway type search network 10.0.0.0/8 minPrefixLen 16
uci delete qmp.tunnels
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment