adds 5 new chains to the uci firewall that can be used to hook custom rules
[openwrt/svn-archive/archive.git] / package / firewall / files / uci_firewall.sh
index e1c4d4d6732cd1d1b656908f6082cba9f29632cf..f6e82bcb69fea3ac8992daa508e7eb6cb0492eaf 100755 (executable)
@@ -181,6 +181,8 @@ fw_rule() {
        [ -n "$dest" ] && TARGET=zone_${dest}_$target || TARGET=$target
        [ -n "$dest_port" -a -z "$proto" ] && { \
                echo "dport may only be used it proto is defined"; return; }
        [ -n "$dest" ] && TARGET=zone_${dest}_$target || TARGET=$target
        [ -n "$dest_port" -a -z "$proto" ] && { \
                echo "dport may only be used it proto is defined"; return; }
+       [ -n "$src_port" -a -z "$proto" ] && { \
+               echo "sport may only be used it proto is defined"; return; }
        $IPTABLES -I $ZONE 1 \
                ${proto:+-p $proto} \
                ${src_ip:+-s $src_ip} \
        $IPTABLES -I $ZONE 1 \
                ${proto:+-p $proto} \
                ${src_ip:+-s $src_ip} \
@@ -225,6 +227,8 @@ fw_redirect() {
                echo "redirect needs src and dest_ip"; return ; }
        [ -n "$dest_port" -a -z "$proto" ] && { \
                echo "dport may only be used it proto is defined"; return; }
                echo "redirect needs src and dest_ip"; return ; }
        [ -n "$dest_port" -a -z "$proto" ] && { \
                echo "dport may only be used it proto is defined"; return; }
+       [ -n "$src_port" -a -z "$proto" ] && { \
+               echo "sport may only be used it proto is defined"; return; }
        $IPTABLES -A zone_${src}_prerouting -t nat \
                ${proto:+-p $proto} \
                ${src_ip:+-s $src_ip} \
        $IPTABLES -A zone_${src}_prerouting -t nat \
                ${proto:+-p $proto} \
                ${src_ip:+-s $src_ip} \
@@ -257,6 +261,19 @@ fw_addif() {
        (ACTION="ifup" INTERFACE="$1" . /etc/hotplug.d/iface/20-firewall)
 }
 
        (ACTION="ifup" INTERFACE="$1" . /etc/hotplug.d/iface/20-firewall)
 }
 
+fw_custom_chains() {
+       $IPTABLES -N input_rule
+       $IPTABLES -N output_rule
+       $IPTABLES -N forward_rule
+       $IPTABLES -N prerouting_rule -t nat
+       $IPTABLES -N postrouting_rule -t nat
+       $IPTABLES -A INPUT -j input_rule
+       $IPTABLES -A OUTPUT -j output_rule
+       $IPTABLES -A FORWARD -j forward_rule
+       $IPTABLES -A PREROUTING -t nat -j prerouting_rule
+       $IPTABLES -A POSTROUTING -t nat -j postrouting_rule
+}
+
 fw_init() {
        echo "Loading defaults"
        config_foreach fw_defaults defaults
 fw_init() {
        echo "Loading defaults"
        config_foreach fw_defaults defaults
@@ -270,7 +287,9 @@ fw_init() {
        config_foreach fw_redirect redirect
        echo "Loading includes"
        config_foreach fw_include include
        config_foreach fw_redirect redirect
        echo "Loading includes"
        config_foreach fw_include include
-       
+       echo "Adding custom chains"
+       fw_custom_chains
+
        uci_set_state firewall core "" firewall_state 
        uci_set_state firewall core loaded 1
        unset CONFIG_APPEND
        uci_set_state firewall core "" firewall_state 
        uci_set_state firewall core loaded 1
        unset CONFIG_APPEND