Project

General

Profile

Download (2.65 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2
#
3
# ovpn-dnslinkup
4
#
5
# part of pfSense (https://www.pfsense.org)
6
# Copyright (c) 2021 Rubicon Communications, LLC (Netgate)
7
# All rights reserved.
8
#
9
# Licensed under the Apache License, Version 2.0 (the "License");
10
# you may not use this file except in compliance with the License.
11
# You may obtain a copy of the License at
12
#
13
# http://www.apache.org/licenses/LICENSE-2.0
14
#
15
# Unless required by applicable law or agreed to in writing, software
16
# distributed under the License is distributed on an "AS IS" BASIS,
17
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
# See the License for the specific language governing permissions and
19
# limitations under the License.
20

    
21
if [ "${dev_type}" = "tun" ]; then
22
	if [ -n "${route_vpn_gateway}" ]; then
23
		/bin/echo ${route_vpn_gateway} > /tmp/${1}_router
24
	elif [ -n "${ifconfig_remote}" ]; then
25
		/bin/echo ${ifconfig_remote} > /tmp/${1}_router
26
	elif [ -n "${ifconfig_local}" ]; then
27
		/bin/echo ${ifconfig_local} > /tmp/${1}_router
28
	else
29
		/bin/echo ${5} > /tmp/${1}_router
30
	fi
31

    
32
	if [ -n "${route_ipv6_gateway_1}" ]; then
33
		/bin/echo ${route_ipv6_gateway_1} > /tmp/${1}_routerv6
34
	elif [ -n "${ifconfig_ipv6_remote}" ]; then
35
		/bin/echo ${ifconfig_ipv6_remote} > /tmp/${1}_routerv6
36
	elif [ -n "${ifconfig_ipv6_local}" ]; then
37
		/bin/echo ${ifconfig_ipv6_local} > /tmp/${1}_routerv6
38
	fi
39

    
40
else
41
	if [ -n "${route_vpn_gateway}" ]; then
42
		/bin/echo ${route_vpn_gateway} > /tmp/${1}_router
43
	fi
44

    
45
	if [ -n "${route_ipv6_gateway_1}" ]; then
46
		/bin/echo ${route_ipv6_gateway_1} > /tmp/${1}_routerv6
47
	fi
48
fi
49

    
50
# use OpenVPN provided DNS, see https://redmine.pfsense.org/issues/11140
51
/bin/rm -f /var/etc/nameserver_${1}
52
/bin/rm -f /var/etc/nameserver_v6${1}
53
/bin/rm -f /var/etc/searchdomain_${1}
54
for num in `seq 50`; do
55
	option="$(eval echo \$foreign_option_${num})"
56
	if [ -z "${option}" ]; then
57
		break
58
	fi
59
	part1="$(/bin/echo ${option} | /usr/bin/cut -d ' ' -f 1)"
60
	if [ "$part1" == "dhcp-option" ]; then
61
		part2="$(/bin/echo ${option} | /usr/bin/cut -d ' ' -f 2)"
62
		part3="$(/bin/echo ${option} | /usr/bin/cut -d ' ' -f 3)"
63
		if [ "$part2" = "DNS" ]; then
64
			DNS="${part3}"
65
			/bin/echo ${DNS} >> /var/etc/nameserver_${1}
66
			/sbin/route change -inet "${DNS}" -iface ${1} || /sbin/route add -inet "${DNS}" -iface ${1}
67
		elif [ "$part2" = "DNS6" ]; then
68
			DNS="${part3}"
69
			/bin/echo ${DNS} >> /var/etc/nameserver_v6${1}
70
			/sbin/route change -inet6 "${DNS}" -iface ${1} || /sbin/route add -inet6 "${DNS}" -iface ${1}
71
		elif [ "$part2" = "DOMAIN" -o "$part2" = "DOMAIN-SEARCH" ]; then
72
			/bin/echo ${part3} >> /var/etc/searchdomain_${1}
73
		fi
74
	fi
75
done
76

    
77
/usr/bin/touch /tmp/${1}up
78
# reload filter
79
/usr/local/sbin/pfSctl -c "interface newip ${1}"
80
exit 0
(13-13/36)