Developing lightweight computation at the DSG edge

qmp_gw.sh 3.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/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"
SOURCE_GW=1

[ -z "$SOURCE_COMMON" ] && . $QMP_PATH/qmp_common.sh
[ -z "$SOURCE_NETWORK" ] &&. $QMP_PATH/qmp_functions.sh

27
qmp_gw_search_default_ipv4() {
28
29
30
31
	qmp_uci_set tunnels qmp
	qmp_uci_set tunnels.search_ipv4_tunnel 0.0.0.0/0
	qmp_gw_masq_wan 0
	qmp_uci_del tunnels.offer_ipv4_tunnel
32
33
34
35
36
37
}

qmp_gw_search_default_ipv6() {
	qmp_uci_set tunnels qmp
	qmp_uci_set tunnels.search_ipv6_tunnel ::/0
	qmp_gw_masq_wan 0
38
39
40
	qmp_uci_del tunnels.offer_ipv6_tunnel
}

41
qmp_gw_offer_default_ipv4() {
42
43
44
45
	qmp_uci_set tunnels qmp
	qmp_uci_set tunnels.offer_ipv4_tunnel 0.0.0.0/0
	qmp_gw_masq_wan 1
	qmp_uci_del tunnels.search_ipv4_tunnel
46
47
48
49
50
51
}

qmp_gw_offer_default_ipv6() {
	qmp_uci_set tunnels qmp
	qmp_uci_set tunnels.offer_ipv6_tunnel ::/0
	qmp_gw_masq_wan 1
52
53
54
	qmp_uci_del tunnels.search_ipv6_tunnel
}

55
qmp_gw_disable_default_ipv4() {
56
57
	qmp_uci_del tunnels.offer_ipv4_tunnel
	qmp_uci_del tunnels.search_ipv4_tunnel
58
59
60
61
62
	qmp_gw_masq_wan 0
}

qmp_gw_disable_default_ipv6() {
	qmp_uci_del tunnels.offer_ipv6_tunnel
63
64
65
66
	qmp_uci_del tunnels.search_ipv6_tunnel
	qmp_gw_masq_wan 0
}

67
68
69
70
71
72
73
74
75
76
qmp_gw_default() {
	if [ -n "$2" ]
	then
		qmp_gw_$1_default_$2
	else
		qmp_gw_$1_default_ipv4
		qmp_gw_$1_default_ipv6
	fi
}

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
}