[package] firewall: make sure that -m mac is used with --mac-source, follow up to...
[openwrt.git] / package / firewall / files / lib / core_interface.sh
index 889dcc9..bc9eb96 100644 (file)
@@ -1,5 +1,29 @@
 # Copyright (C) 2009-2010 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"
+}
+
+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"
+}
+
 fw_configure_interface() {
        local iface=$1
        local action=$2
@@ -51,8 +75,13 @@ fw_configure_interface() {
 
                        # Need v4 while zone is v6
                        */*.*) fw_log info "zone $zone does not support IPv4 address family, skipping"; return ;;
+
+                       # Strip prefix
+                       *) mode="${mode#G}" ;;
                esac
 
+               lock /var/run/firewall-interface.lock
+
                fw $action $mode f ${chain}_ACCEPT ACCEPT $ { -o "$ifname" $onet }
                fw $action $mode f ${chain}_ACCEPT ACCEPT $ { -i "$ifname" $inet }
                fw $action $mode f ${chain}_DROP   DROP   $ { -o "$ifname" $onet }
@@ -67,6 +96,8 @@ fw_configure_interface() {
                fw $action $mode n PREROUTING ${chain}_prerouting $ { -i "$ifname" $inet }
                fw $action $mode r PREROUTING ${chain}_notrack    $ { -i "$ifname" $inet }
                fw $action $mode n POSTROUTING ${chain}_nat       $ { -o "$ifname" $onet }
+
+               lock -u /var/run/firewall-interface.lock
        }
 
        local old_zones old_ifname old_subnets
@@ -83,7 +114,10 @@ fw_configure_interface() {
                                fw__do_rules del $z $old_ifname $n
                        done
 
-                       [ -n "$old_subnets" ] || ACTION=remove ZONE="$z" INTERFACE="$iface" DEVICE="$ifname" /sbin/hotplug-call firewall
+                       [ -n "$old_subnets" ] || {
+                               fw__uci_state_del "${z}_networks" "$iface"
+                               env -i ACTION=remove ZONE="$z" INTERFACE="$iface" DEVICE="$ifname" /sbin/hotplug-call firewall
+                       }
                done
 
                local old_aliases
@@ -139,7 +173,10 @@ fw_configure_interface() {
                fw__do_rules add ${zone_name} "$ifname" "$aliasnet"
                append new_zones $zone_name
 
-               [ -n "$aliasnet" ] || ACTION=add ZONE="$zone_name" INTERFACE="$iface" DEVICE="$ifname" /sbin/hotplug-call firewall
+               [ -n "$aliasnet" ] || {
+                       fw__uci_state_add "${zone_name}_networks" "${zone_network}"
+                       env -i ACTION=add ZONE="$zone_name" INTERFACE="$iface" DEVICE="$ifname" /sbin/hotplug-call firewall
+               }
        }
        config_foreach load_zone zone
 
This page took 0.028948 seconds and 4 git commands to generate.