summaryrefslogtreecommitdiffhomepage
path: root/modules/freifunk/root/etc/hotplug.d/iface
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-01-25 16:45:19 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-01-25 16:45:19 +0000
commit58d15fdedb105997156c86aedde87a18786da433 (patch)
tree59a96e6b98a2302bebb0685ed4faf6b1b9ea3205 /modules/freifunk/root/etc/hotplug.d/iface
parent9b01a6e862d119b999ce57173f8de55c15cc8818 (diff)
modules/freifunk:
- implement generic fix for firewall MASQUERADE - implement advanced uci config to control sysctl and /proc values
Diffstat (limited to 'modules/freifunk/root/etc/hotplug.d/iface')
-rw-r--r--modules/freifunk/root/etc/hotplug.d/iface/22-firewall-nat-fix61
1 files changed, 61 insertions, 0 deletions
diff --git a/modules/freifunk/root/etc/hotplug.d/iface/22-firewall-nat-fix b/modules/freifunk/root/etc/hotplug.d/iface/22-firewall-nat-fix
new file mode 100644
index 0000000000..634f432f08
--- /dev/null
+++ b/modules/freifunk/root/etc/hotplug.d/iface/22-firewall-nat-fix
@@ -0,0 +1,61 @@
+. /lib/firewall/uci_firewall.sh
+unset ZONE
+config_get ifname $INTERFACE ifname
+[ "$ifname" == "lo" ] && exit 0
+
+load_zones() {
+ local name
+ local network
+ config_get name $1 name
+ config_get network $1 network
+ [ -z "$network" ] && network=$name
+ for n in $network; do
+ [ "$n" = "$INTERFACE" ] && ZONE="$ZONE $name"
+ done
+}
+
+config_foreach load_zones zone
+
+[ -z "$ZONE" ] && exit 0
+
+natfix_addr_add() {
+ local network=$1
+ local iface=$2
+
+ config_get parent "$1" interface
+ [ "$network" != "$INTERFACE" -a "$parent" != "$INTERFACE" ] && return 0
+
+ config_get ipaddr "$network" ipaddr
+ [ -n "$ipaddr" ] || return 0
+ config_get netmask "$network" netmask
+ [ -n "$netmask" ] || return 0
+ eval "$(ipcalc.sh $ipaddr $netmask)"
+
+ logger -t firewall.freifunk "adding nat rule for $iface($NETWORK/$PREFIX)"
+ iptables -t nat -A "natfix_$iface" -s "$NETWORK/$PREFIX" -d "$NETWORK/$PREFIX" -j ACCEPT
+}
+
+[ ifup = "$ACTION" ] && {
+ iptables -t nat -N "natfix_$ifname"
+ natfix_addr_add "$INTERFACE" "$ifname"
+ config_foreach natfix_addr_add alias "$ifname"
+
+ for z in $ZONE; do
+ local loaded
+ config_get loaded core loaded
+ [ -n "$loaded" ] && {
+ logger -t firewall.freifunk "applying nat rules on zone $z"
+ iptables -t nat -I "zone_${z}_nat" 1 -o "$ifname" -j "natfix_$ifname"
+ }
+ done
+}
+
+[ ifdown = "$ACTION" ] && {
+ for z in $ZONE; do
+ local up
+ config_get up $z up
+ iptables -t nat -D "zone_${z}_nat" -o "$ifname" -j "natfix_$ifname" 2>/dev/null
+ done
+ iptables -t nat -F "natfix_$ifname" 2>/dev/null
+ iptables -t nat -X "natfix_$ifname" 2>/dev/null
+}