1 # Copyright (C) 2009-2010 OpenWrt.org
3 fw_configure_interface
() {
9 [ "$action" == "add" ] && {
10 local status
=$
(uci_get_state network
"$iface" up
0)
11 [ "$status" == 1 ] ||
[ -n "$aliasnet" ] ||
return 0
15 ifname
=$
(uci_get_state network
"$iface" ifname
)
16 ifname
="${ifname%%:*}"
17 [ -z "$ifname" ] && return 0
20 [ "$ifname" == "lo" ] && return 0
22 fw_callback pre interface
27 local chain
=zone_
${zone}
32 fw_get_family_mode mode x
$zone i
34 case "$mode/$subnet" in
35 # Zone supports v6 only or dual, need v6
37 inet
="-s $subnet -d ::/0"
38 onet
="-s ::/0 -d $subnet"
42 # Zone supports v4 only or dual, need v4
44 inet
="-s $subnet -d 0.0.0.0/0"
45 onet
="-s 0.0.0.0/0 -d $subnet"
49 # Need v6 while zone is v4
50 */*:*) fw_log info
"zone $zone does not support IPv6 address family, skipping"; return ;;
52 # Need v4 while zone is v6
53 */*.
*) fw_log info
"zone $zone does not support IPv4 address family, skipping"; return ;;
56 fw
$action $mode f
${chain}_ACCEPT ACCEPT $
{ -o "$ifname" $onet }
57 fw
$action $mode f
${chain}_ACCEPT ACCEPT $
{ -i "$ifname" $inet }
58 fw
$action $mode f
${chain}_DROP DROP $
{ -o "$ifname" $onet }
59 fw
$action $mode f
${chain}_DROP DROP $
{ -i "$ifname" $inet }
60 fw
$action $mode f
${chain}_REJECT reject $
{ -o "$ifname" $onet }
61 fw
$action $mode f
${chain}_REJECT reject $
{ -i "$ifname" $inet }
63 fw
$action $mode f
${chain}_MSSFIX TCPMSS $
{ -o "$ifname" -p tcp
--tcp-flags SYN
,RST SYN
--clamp-mss-to-pmtu $onet }
65 fw
$action $mode f input
${chain} $
{ -i "$ifname" $inet }
66 fw
$action $mode f forward
${chain}_forward $
{ -i "$ifname" $inet }
67 fw
$action $mode n PREROUTING
${chain}_prerouting $
{ -i "$ifname" $inet }
68 fw
$action $mode r PREROUTING
${chain}_notrack $
{ -i "$ifname" $inet }
69 fw
$action $mode n POSTROUTING
${chain}_nat $
{ -o "$ifname" $onet }
72 local old_zones old_ifname old_subnets
73 config_get old_zones core
"${iface}_zone"
74 [ -n "$old_zones" ] && {
75 config_get old_ifname core
"${iface}_ifname"
76 config_get old_subnets core
"${iface}_subnets"
79 for z
in $old_zones; do
81 for n
in ${old_subnets:-""}; do
82 fw_log info
"removing $iface ($old_ifname${n:+ alias $n}) from zone $z"
83 fw__do_rules del
$z $old_ifname $n
86 [ -n "$old_subnets" ] || ACTION
=remove ZONE
="$z" INTERFACE
="$iface" DEVICE
="$ifname" /sbin
/hotplug-call firewall
90 config_get old_aliases core
"${iface}_aliases"
93 for a
in $old_aliases; do
94 fw_configure_interface
"$a" del
"$old_ifname"
97 uci_revert_state firewall core
"${iface}_zone"
98 uci_revert_state firewall core
"${iface}_ifname"
99 uci_revert_state firewall core
"${iface}_subnets"
100 uci_revert_state firewall core
"${iface}_aliases"
103 [ "$action" == del
] && return
105 [ -z "$aliasnet" ] && {
107 config_get aliases
"$iface" aliases
110 for a
in $aliases; do
111 local ipaddr netmask ip6addr
112 config_get ipaddr
"$a" ipaddr
113 config_get netmask
"$a" netmask
114 config_get ip6addr
"$a" ip6addr
116 [ -n "$ipaddr" ] && fw_configure_interface
"$a" add
"" "$ipaddr${netmask:+/$netmask}"
117 [ -n "$ip6addr" ] && fw_configure_interface
"$a" add
"" "$ip6addr"
120 fw_sysctl_interface
$ifname
121 fw_callback post interface
123 uci_set_state firewall core
"${iface}_aliases" "$aliases"
126 config_get subnets core
"${iface}_subnets"
127 append subnets
"$aliasnet"
129 config_set core
"${iface}_subnets" "$subnets"
130 uci_set_state firewall core
"${iface}_subnets" "$subnets"
135 fw_config_get_zone
"$1"
136 list_contains zone_network
"$iface" ||
return
138 fw_log info
"adding $iface ($ifname${aliasnet:+ alias $aliasnet}) to zone $zone_name"
139 fw__do_rules add
${zone_name} "$ifname" "$aliasnet"
140 append new_zones
$zone_name
142 [ -n "$aliasnet" ] || ACTION
=add ZONE
="$zone_name" INTERFACE
="$iface" DEVICE
="$ifname" /sbin
/hotplug-call firewall
144 config_foreach load_zone zone
146 uci_set_state firewall core
"${iface}_zone" "$new_zones"
147 uci_set_state firewall core
"${iface}_ifname" "$ifname"
150 fw_sysctl_interface
() {
153 sysctl
-w net.ipv4.conf.
${ifname}.accept_redirects
=$FW_ACCEPT_REDIRECTS
154 sysctl
-w net.ipv6.conf.
${ifname}.accept_redirects
=$FW_ACCEPT_REDIRECTS
155 sysctl
-w net.ipv4.conf.
${ifname}.accept_source_route
=$FW_ACCEPT_SRC_ROUTE
156 sysctl
-w net.ipv6.conf.
${ifname}.accept_source_route
=$FW_ACCEPT_SRC_ROUTE
157 } >/dev
/null
2>/dev
/null