firewall: rework state variable handling, use uci_toggle_state() where applicable and properly handle duplicates in add and del state helpers (#9152, #9710)

SVN-Revision: 27618
This commit is contained in:
Jo-Philipp Wich 2011-07-15 15:03:57 +00:00
parent e0e6d1029e
commit 78fa88ca81
2 changed files with 25 additions and 18 deletions

View file

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=firewall PKG_NAME:=firewall
PKG_VERSION:=2 PKG_VERSION:=2
PKG_RELEASE:=30 PKG_RELEASE:=31
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk

View file

@ -1,27 +1,34 @@
# Copyright (C) 2009-2010 OpenWrt.org # Copyright (C) 2009-2011 OpenWrt.org
fw__uci_state_add() { fw__uci_state_add() {
local var="$1" local var="$1"
local item="$2" local item="$2"
local val=" $(uci_get_state firewall core $var) " local val="$(uci_get_state firewall core $var)"
val="${val// $item / }" local e1; for e1 in $item; do
val="${val# }" local e2; for e2 in $val; do
val="${val% }" [ "$e1" = "$e2" ] && e1=""
uci_revert_state firewall core $var done
uci_set_state firewall core $var "${val:+$val }$item" val="${val:+$val${e1:+ }}$e1"
done
uci_toggle_state $var "$val"
} }
fw__uci_state_del() { fw__uci_state_del() {
local var="$1" local var="$1"
local item="$2" local item="$2"
local val=" $(uci_get_state firewall core $var) " local rest=""
val="${val// $item / }" local val="$(uci_get_state firewall core $var)"
val="${val# }" local e1; for e1 in $val; do
val="${val% }" local e2; for e2 in $item; do
uci_revert_state firewall core $var [ "$e1" = "$e2" ] && e1=""
uci_set_state firewall core $var "$val" done
rest="${rest:+$rest${e1:+ }}$e1"
done
uci_toggle_state $var "$val"
} }
fw_configure_interface() { fw_configure_interface() {
@ -154,14 +161,14 @@ fw_configure_interface() {
fw_sysctl_interface $ifname fw_sysctl_interface $ifname
fw_callback post interface fw_callback post interface
uci_set_state firewall core "${iface}_aliases" "$aliases" uci_toggle_state firewall core "${iface}_aliases" "$aliases"
} || { } || {
local subnets= local subnets=
config_get subnets core "${iface}_subnets" config_get subnets core "${iface}_subnets"
append subnets "$aliasnet" append subnets "$aliasnet"
config_set core "${iface}_subnets" "$subnets" config_set core "${iface}_subnets" "$subnets"
uci_set_state firewall core "${iface}_subnets" "$subnets" uci_toggle_state firewall core "${iface}_subnets" "$subnets"
} }
local new_zones= local new_zones=
@ -180,8 +187,8 @@ fw_configure_interface() {
} }
config_foreach load_zone zone config_foreach load_zone zone
uci_set_state firewall core "${iface}_zone" "$new_zones" uci_toggle_state firewall core "${iface}_zone" "$new_zones"
uci_set_state firewall core "${iface}_ifname" "$ifname" uci_toggle_state firewall core "${iface}_ifname" "$ifname"
} }
fw_sysctl_interface() { fw_sysctl_interface() {