-
- fw $action i f ${chain}_ACCEPT ACCEPT ^ { -o "$ifname" }
- fw $action i f ${chain}_ACCEPT ACCEPT ^ { -i "$ifname" }
- fw $action i f ${chain}_DROP DROP ^ { -o "$ifname" }
- fw $action i f ${chain}_DROP DROP ^ { -i "$ifname" }
- fw $action i f ${chain}_REJECT reject ^ { -o "$ifname" }
- fw $action i f ${chain}_REJECT reject ^ { -i "$ifname" }
-
- fw $action i n ${chain}_nat MASQUERADE ^ { -o "$ifname" }
- fw $action i f ${chain}_MSSFIX TCPMSS ^ { -o "$ifname" -p tcp --tcp-flags SYN,RST SYN --clamp-mss-to-pmtu }
-
- fw $action i f input ${chain} $ { -i "$ifname" }
- fw $action i f forward ${chain}_forward $ { -i "$ifname" }
- fw $action i n PREROUTING ${chain}_prerouting ^ { -i "$ifname" }
- fw $action i r PREROUTING ${chain}_notrack ^ { -i "$ifname" }
+ local subnet=$4
+
+ local inet onet mode
+ fw_get_family_mode mode x $zone i
+
+ case "$mode/$subnet" in
+ # Zone supports v6 only or dual, need v6
+ G6/*:*|i/*:*)
+ inet="-s $subnet -d ::/0"
+ onet="-s ::/0 -d $subnet"
+ mode=6
+ ;;
+
+ # Zone supports v4 only or dual, need v4
+ G4/*.*.*.*|i/*.*.*.*)
+ inet="-s $subnet -d 0.0.0.0/0"
+ onet="-s 0.0.0.0/0 -d $subnet"
+ mode=4
+ ;;
+
+ # Need v6 while zone is v4
+ */*:*) fw_log info "zone $zone does not support IPv6 address family, skipping"; return ;;
+
+ # 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 }
+ fw $action $mode f ${chain}_DROP DROP $ { -i "$ifname" $inet }
+ fw $action $mode f ${chain}_REJECT reject $ { -o "$ifname" $onet }
+ fw $action $mode f ${chain}_REJECT reject $ { -i "$ifname" $inet }
+
+ fw $action $mode f ${chain}_MSSFIX TCPMSS $ { -o "$ifname" -p tcp --tcp-flags SYN,RST SYN --clamp-mss-to-pmtu $onet }
+
+ fw $action $mode f input ${chain} $ { -i "$ifname" $inet }
+ fw $action $mode f forward ${chain}_forward $ { -i "$ifname" $inet }
+ 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