diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2011-07-15 15:03:57 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2011-07-15 15:03:57 +0000 |
commit | 4885c7ec719b9d734148c1e283b965f900f05a04 (patch) | |
tree | 24630ab420edcf890d3b3cac01b98640e24f71b6 /package/firewall/files/lib | |
parent | ada59a09ce70d6f1bcf6613ad25141842dc7534e (diff) | |
download | master-187ad058-4885c7ec719b9d734148c1e283b965f900f05a04.tar.gz master-187ad058-4885c7ec719b9d734148c1e283b965f900f05a04.tar.bz2 master-187ad058-4885c7ec719b9d734148c1e283b965f900f05a04.zip |
[package] firewall: rework state variable handling, use uci_toggle_state() where applicable and properly handle duplicates in add and del state helpers (#9152, #9710)
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@27618 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/firewall/files/lib')
-rw-r--r-- | package/firewall/files/lib/core_interface.sh | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/package/firewall/files/lib/core_interface.sh b/package/firewall/files/lib/core_interface.sh index bc9eb96dde..ab58201e24 100644 --- a/package/firewall/files/lib/core_interface.sh +++ b/package/firewall/files/lib/core_interface.sh @@ -1,27 +1,34 @@ -# Copyright (C) 2009-2010 OpenWrt.org +# Copyright (C) 2009-2011 OpenWrt.org fw__uci_state_add() { local var="$1" local item="$2" - local val=" $(uci_get_state firewall core $var) " - val="${val// $item / }" - val="${val# }" - val="${val% }" - uci_revert_state firewall core $var - uci_set_state firewall core $var "${val:+$val }$item" + local val="$(uci_get_state firewall core $var)" + local e1; for e1 in $item; do + local e2; for e2 in $val; do + [ "$e1" = "$e2" ] && e1="" + done + val="${val:+$val${e1:+ }}$e1" + done + + uci_toggle_state $var "$val" } fw__uci_state_del() { local var="$1" local item="$2" - local val=" $(uci_get_state firewall core $var) " - val="${val// $item / }" - val="${val# }" - val="${val% }" - uci_revert_state firewall core $var - uci_set_state firewall core $var "$val" + local rest="" + local val="$(uci_get_state firewall core $var)" + local e1; for e1 in $val; do + local e2; for e2 in $item; do + [ "$e1" = "$e2" ] && e1="" + done + rest="${rest:+$rest${e1:+ }}$e1" + done + + uci_toggle_state $var "$val" } fw_configure_interface() { @@ -154,14 +161,14 @@ fw_configure_interface() { fw_sysctl_interface $ifname fw_callback post interface - uci_set_state firewall core "${iface}_aliases" "$aliases" + uci_toggle_state firewall core "${iface}_aliases" "$aliases" } || { local subnets= config_get subnets core "${iface}_subnets" append subnets "$aliasnet" 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= @@ -180,8 +187,8 @@ fw_configure_interface() { } config_foreach load_zone zone - uci_set_state firewall core "${iface}_zone" "$new_zones" - uci_set_state firewall core "${iface}_ifname" "$ifname" + uci_toggle_state firewall core "${iface}_zone" "$new_zones" + uci_toggle_state firewall core "${iface}_ifname" "$ifname" } fw_sysctl_interface() { |