2 # This will add $net to the zone firewall (and remove it from other zones where it is referenced)
3 # It will also setup rules defined in /etc/config/freifunk and /etc/config/profile_<community>
12 type="$(uci -q get wireless.$net.type)"
13 vap="$(uci -q get meshwizard.netconfig.$net\_vap)"
14 wan_is_olsr=$(uci -q get meshwizard.netconfig.wan_config)
16 # Delete old firewall zone for freifunk
18 config_get name "$1" name
19 config_get network "$1" network
21 if [ "$2" == "zoneconf" ]; then
22 if [ "$name" == "freifunk" ]; then
23 # rename section if unnamed
24 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
25 section_rename firewall $1 zone_freifunk
28 if [ ! "$name" == "freifunk" ] && [ -n "$netrenamed" -a -n "$(echo $network | grep $netrenamed)" ]; then
29 echo " Removed $netrenamed from firewall zone $name."
30 network_new=$(echo $network | sed -e 's/'$netrenamed'//' -e 's/^ //' -e 's/ / /' -e 's/ $//')
31 uci set firewall.$1.network="$network_new"
37 config_foreach handle_fwzone zone zoneconf
39 # Add $netrenamed and if needed ${netrenamed}dhcp to the "freifunk" zone
40 config_get network zone_freifunk network
42 # remove ${netrenamed}dhcp from networks list
43 [ -n "$network" -a -n "$net" ] && network="${network/${netrenamed}dhcp/}"
44 network=$(echo $network) # Removes leading and trailing whitespaces
46 [ -n "$netrenamed" ] && [ -z "$(echo $network | grep $netrenamed)" ] && network="$network $netrenamed"
48 if [ "$supports_vap" == "1" -a "$vap" == 1 ]; then
49 [ -n "$netrenamed" ] && [ "$network" == "${network/${netrenamed}dhcp/}" ] && network="$network ${netrenamed}dhcp"
52 uci set firewall.zone_freifunk.network="$network"
54 uci_commitverbose "Add '$netrenamed' to freifunk firewall zone" firewall
56 currms=$(uci -q get firewall.zone_freifunk.masq_src)
58 # If interfaces are outside of the mesh network they should be natted
60 if [ "$vap" == 1 ]; then
61 # Get dhcprange and meshnet for the dhcp interface
62 if_ip="$(uci -q get network.${netrenamed}dhcp.ipaddr)"
63 if_mask="$(uci -q get network.${netrenamed}dhcp.netmask)"
65 [ -n "$if_ip" -a "$if_mask" ] && export $(ipcalc.sh $if_ip $if_mask)
66 [ -n "$NETWORK" -a "$PREFIX" ] && dhcprange="$NETWORK/$PREFIX"
68 if [ -n "$dhcprange" ]; then
69 meshnet="$(uci get profile_$community.profile.mesh_network)"
70 # check if the dhcprange is inside meshnet
71 dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)"
72 if [ "$dhcpinmesh" == 1 ]; then
73 # needed or splash will not work
74 if [ "$has_luci_splash" == TRUE ]; then
75 uci set firewall.zone_freifunk.contrack="1"
78 uci set firewall.zone_freifunk.masq=1
79 [ -z "$(echo $currms |grep ${netrenamed}dhcp)" ] && uci add_list firewall.zone_freifunk.masq_src="${netrenamed}dhcp"
84 # Get dhcprange and meshnet for the adhoc dhcp interface
85 if_ip="$(uci -q get network.${netrenamed}ahdhcp.ipaddr)"
86 if_mask="$(uci -q get network.${netrenamed}ahdhcp.netmask)"
88 [ -n "$if_ip" -a "$if_mask" ] && export $(ipcalc.sh $if_ip $if_mask)
89 [ -n "$NETWORK" -a "$PREFIX" ] && dhcprangeah="$NETWORK/$PREFIX"
91 if [ -n "$dhcprangeah" ]; then
92 meshnet="$(uci get profile_$community.profile.mesh_network)"
93 # check if the dhcprange is inside meshnet
94 dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprangeah $meshnet)"
95 if [ "$dhcpinmesh" == 1 ]; then
96 # needed or splash will not work
97 if [ "$has_luci_splash" == TRUE ]; then
98 uci set firewall.zone_freifunk.contrack="1"
101 uci set firewall.zone_freifunk.masq=1
102 [ -z "$(echo $currms |grep ${netrenamed}ahdhcp)" ] && uci add_list firewall.zone_freifunk.masq_src="${netrenamed}ahdhcp"
107 for i in IP NETMASK BROADCAST NETWORK PREFIX; do
111 uci_commitverbose "Setup masquerading rules for '$netrenamed'" firewall