2010-05-01 18:22:01 +00:00
|
|
|
# Copyright (C) 2009-2010 OpenWrt.org
|
|
|
|
|
|
|
|
fw_configure_interface() {
|
|
|
|
local iface=$1
|
|
|
|
local action=$2
|
|
|
|
local ifname=$3
|
|
|
|
|
2010-05-19 00:50:14 +00:00
|
|
|
[ "$action" == "add" ] && {
|
|
|
|
local status=$(uci_get_state network "$iface" up 0)
|
|
|
|
[ "$status" == 1 ] || return 0
|
2010-05-01 18:22:01 +00:00
|
|
|
}
|
2010-05-19 00:50:14 +00:00
|
|
|
|
|
|
|
[ -n "$ifname" ] || ifname=$(uci_get_state network "$iface" ifname "$iface")
|
2010-05-01 18:22:01 +00:00
|
|
|
[ "$ifname" == "lo" ] && return 0
|
|
|
|
|
|
|
|
fw_callback pre interface
|
|
|
|
|
|
|
|
fw__do_rules() {
|
|
|
|
local action=$1
|
2010-05-19 21:35:23 +00:00
|
|
|
local zone=$2
|
|
|
|
local chain=zone_${zone}
|
2010-05-01 18:22:01 +00:00
|
|
|
local ifname=$3
|
|
|
|
|
2010-05-19 21:35:23 +00:00
|
|
|
local mode=$(fw_get_family_mode x $zone i)
|
2010-05-01 18:22:01 +00:00
|
|
|
|
2010-05-19 21:35:23 +00:00
|
|
|
fw $action $mode f ${chain}_ACCEPT ACCEPT ^ { -o "$ifname" }
|
|
|
|
fw $action $mode f ${chain}_ACCEPT ACCEPT ^ { -i "$ifname" }
|
|
|
|
fw $action $mode f ${chain}_DROP DROP ^ { -o "$ifname" }
|
|
|
|
fw $action $mode f ${chain}_DROP DROP ^ { -i "$ifname" }
|
|
|
|
fw $action $mode f ${chain}_REJECT reject ^ { -o "$ifname" }
|
|
|
|
fw $action $mode f ${chain}_REJECT reject ^ { -i "$ifname" }
|
2010-05-01 18:22:01 +00:00
|
|
|
|
2010-05-19 21:35:23 +00:00
|
|
|
fw $action $mode n ${chain}_nat MASQUERADE ^ { -o "$ifname" }
|
|
|
|
fw $action $mode f ${chain}_MSSFIX TCPMSS ^ { -o "$ifname" -p tcp --tcp-flags SYN,RST SYN --clamp-mss-to-pmtu }
|
|
|
|
|
|
|
|
fw $action $mode f input ${chain} $ { -i "$ifname" }
|
|
|
|
fw $action $mode f forward ${chain}_forward $ { -i "$ifname" }
|
|
|
|
fw $action $mode n PREROUTING ${chain}_prerouting ^ { -i "$ifname" }
|
|
|
|
fw $action $mode r PREROUTING ${chain}_notrack ^ { -i "$ifname" }
|
2010-05-01 18:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local old_zones old_ifname
|
|
|
|
config_get old_zones core "${iface}_zone"
|
|
|
|
[ -n "$old_zones" ] && {
|
|
|
|
config_get old_ifname core "${iface}_ifname"
|
|
|
|
for z in $old_zones; do
|
|
|
|
fw_log info "removing $iface ($old_ifname) from zone $z"
|
2010-05-19 21:35:23 +00:00
|
|
|
fw__do_rules del $z $old_ifname
|
2010-05-01 18:22:01 +00:00
|
|
|
|
|
|
|
ACTION=remove ZONE="$z" INTERFACE="$iface" DEVICE="$ifname" /sbin/hotplug-call firewall
|
|
|
|
done
|
|
|
|
uci_revert_state firewall core "${iface}_zone"
|
|
|
|
uci_revert_state firewall core "${iface}_ifname"
|
|
|
|
}
|
|
|
|
[ "$action" == del ] && return
|
|
|
|
|
|
|
|
local new_zones
|
|
|
|
load_zone() {
|
|
|
|
fw_config_get_zone "$1"
|
|
|
|
list_contains zone_network "$iface" || return
|
|
|
|
|
|
|
|
fw_log info "adding $iface ($ifname) to zone $zone_name"
|
2010-05-19 21:35:23 +00:00
|
|
|
fw__do_rules add ${zone_name} "$ifname"
|
2010-05-01 18:22:01 +00:00
|
|
|
append new_zones $zone_name
|
|
|
|
|
|
|
|
ACTION=add ZONE="$zone_name" INTERFACE="$iface" DEVICE="$ifname" /sbin/hotplug-call firewall
|
|
|
|
}
|
|
|
|
config_foreach load_zone zone
|
|
|
|
|
|
|
|
uci_set_state firewall core "${iface}_zone" "$new_zones"
|
|
|
|
uci_set_state firewall core "${iface}_ifname" "$ifname"
|
|
|
|
|
|
|
|
fw_sysctl_interface $ifname
|
|
|
|
|
|
|
|
fw_callback post interface
|
|
|
|
}
|
|
|
|
|
|
|
|
fw_sysctl_interface() {
|
|
|
|
local ifname=$1
|
|
|
|
{
|
|
|
|
sysctl -w net.ipv4.conf.${ifname}.accept_redirects=$FW_ACCEPT_REDIRECTS
|
|
|
|
sysctl -w net.ipv6.conf.${ifname}.accept_redirects=$FW_ACCEPT_REDIRECTS
|
|
|
|
sysctl -w net.ipv4.conf.${ifname}.accept_source_route=$FW_ACCEPT_SRC_ROUTE
|
|
|
|
sysctl -w net.ipv6.conf.${ifname}.accept_source_route=$FW_ACCEPT_SRC_ROUTE
|
|
|
|
} >/dev/null 2>/dev/null
|
|
|
|
}
|
|
|
|
|