Developing lightweight computation at the DSG edge

Commit e33a0ccb authored by p4u's avatar p4u
Browse files

qmp_gw.sh to change between offering/search gateway in the network....

qmp_gw.sh to change between offering/search gateway in the network. qmp_control.sh to call it from shell"
parent 141d1f80
......@@ -57,6 +57,24 @@ qmp_uci_set_raw() {
return $r
}
qmp_uci_del() {
uci -q del qmp.$1
r=$?
uci commit
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci del qmp.$1)"
return $r
}
qmp_uci_del_raw() {
uci -q del $@
r=$?
uci commit
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci del $@)"
return $r
}
qmp_uci_add() {
uci -q add qmp $1 > /dev/null
r=$?
......@@ -66,6 +84,26 @@ qmp_uci_add() {
return $r
}
qmp_uci_add_raw_get_cfg() {
cfg=$(uci -q add $@)
r=$?
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci add $@)"
echo "$cfg"
return $r
}
qmp_uci_set_cfg() {
uci -q set $@ >/dev/null
return $?
}
qmp_uci_commit() {
uci commit $1
r=$(( $r + $? ))
[ $r -ne 0 ] && logger -t qMp "UCI returned an error (uci commit $1)"
return $r
}
qmp_uci_add_raw() {
uci -q add $@ > /dev/null
r=$?
......
# Copyright (C) 2011 Fundacio Privada per a la Xarxa Oberta, Lliure i Neutral guifi.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# The full GNU General Public License is included in this distribution in
# the file called "COPYING".
QMP_PATH="/etc/qmp"
. $QMP_PATH/qmp_common.sh
. $QMP_PATH/qmp_functions.sh
. $QMP_PATH/qmp_gw.sh
offer_default_gw() {
qmp_gw_offer_default
qmp_gw_apply
}
search_default_gw() {
qmp_gw_search_default
qmp_gw_apply
}
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 ""
}
[ -z "$1" ] && { help; exit 0; }
echo "executing function $1"
$@
#!/bin/sh
# Copyright (C) 2011 Fundacio Privada per a la Xarxa Oberta, Lliure i Neutral guifi.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# The full GNU General Public License is included in this distribution in
# the file called "COPYING".
QMP_PATH="/etc/qmp"
. $QMP_PATH/qmp_common.sh
. $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_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_masq_wan 1
qmp_uci_del tunnels.search_ipv4_tunnel
qmp_uci_del tunnels.search_ipv6_tunnel
}
qmp_gw_masq_wan() {
#First parameter is 1/0 (enable/disable masquerade). Default is 1
[ -z "$1" ] && masq=1 || masq=$1
j=0
v="nothing"
wan=""
#Looking for a firewall zone with name wan
while [ ! -z "$v" ]; do
v=$(qmp_uci_get_raw firewall.@zone[$j].name)
[ "$v" == "wan" ] && { wan=$j; break; }
j=$(( $j +1 ))
done
if [ -z "$wan" ]; then
#if not found, we are going to create it
cfg="$(qmp_uci_add_raw_get_cfg firewall zone)"
qmp_uci_set_cfg firewall.$cfg.input=ACCEPT
qmp_uci_set_cfg firewall.$cfg.output=ACCEPT
qmp_uci_set_cfg firewall.$cfg.forward=ACCEPT
qmp_uci_set_cfg firewall.$cfg.name=wan
qmp_uci_set_cfg firewall.$cfg.masq=$masq
qmp_uci_commit firewall
else
#if found we just change parameters
qmp_uci_set_raw firewall.@zone[$wan].input=ACCEPT
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
fi
}
qmp_gw_apply() {
qmp_configure_bmx6
bmx6 -c --configReload
/etc/init.d/firewall restart
}
......@@ -6,6 +6,6 @@ uci delete firewall.@forwarding[0]
uci delete firewall.@rule[1]
uci delete firewall.@rule[1]
uci set firewall.@defaults[0].forward=ACCEPT
uci set firewall.@defaults[0].disable_ipv6=1
uci set firewall.@defaults[0].disable_ipv6=0
uci commit
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