#!/bin/sh
# OpenVPN firewall helper script
# Copyright (C) 2009 Andrea Borgia
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.

. /etc/functions.sh
. /lib/firewall/uci_firewall.sh
. /lib/config/uci.sh


vpnifup() {
	local section="$1"
	local ifname=""	

	config_get ifname "$section" ifname
	[ -z "$ifname" ] && return 0
	[ "$ifname" = "$vpnif" ] || return 0 
	delif "$section" "$ifname" "$section"
	addif "$section" "$ifname" "$section"
}


# Remove and readd vpn if to vpn zone to activate rules
vpnif="$1"
config_load network
config_foreach vpnifup interface

# Add vpn if to dnsmasq cmdline and reload
dnsif=`uci -P /var/state get dhcp.@dnsmasq[0].interfaces`
config_load dhcp
dnsif="$dnsif,$vpnif"
uci_set_state dhcp @dnsmasq[0] interfaces "$dnsif"
/etc/init.d/dnsmasq reload

