Project

General

Profile

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

    
23
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
24

    
25
DNSALLOWOVERRIDE=$(/usr/local/sbin/read_xml_tag.sh boolean system/dnsallowoverride)
26

    
27
IF="${1}"
28
PROTOCOL="${2}"
29
LOCAL_IP="${3}"
30
REMOTE_IP="${4}"
31
AUTH_NAME="${5}"
32
DNS1_RAW="${6}"
33
DNS2_RAW="${7}"
34

    
35
if [ "${PROTOCOL}" == "inet" ]; then
36

    
37
	OLD_ROUTER=`cat /tmp/${IF}_router`
38
	if [ -n "${OLD_ROUTER}" ]; then
39
		echo "Removing states to old router ${OLD_ROUTER}" | logger -t ppp-linkup
40
		pfctl -i ${IF} -k 0.0.0.0/0 -k ${OLD_ROUTER}/32
41
		pfctl -i ${IF} -k ${OLD_ROUTER}/32 -k 0.0.0.0/0
42
	fi
43

    
44
	# let the configuration system know that the ipv4 has changed.
45
	echo ${REMOTE_IP} > /tmp/${IF}_router
46
	echo ${LOCAL_IP} > /tmp/${IF}_ip
47
	touch /tmp/${IF}up
48

    
49
	if [ "${DNSALLOWOVERRIDE}" = "true" ]; then
50
		# write nameservers to file
51
		echo -n "" > /var/etc/nameserver_${IF}
52
		if echo "${DNS1_RAW}" | grep -q dns1; then
53
			DNS1=`echo "${DNS1_RAW}" | awk '{print $2}'`
54
			echo "${DNS1}" >> /var/etc/nameserver_${IF}
55
			route change "${DNS1}" ${REMOTE_IP} \
56
				|| route add "${DNS1}" ${REMOTE_IP}
57
		fi
58
		if echo "${DNS2_RAW}" | grep -q dns2; then
59
			DNS2=`echo "${DNS2_RAW}" | awk '{print $2}'`
60
			echo "${DNS2}" >> /var/etc/nameserver_${IF}
61
			route change "${DNS2}" ${REMOTE_IP} \
62
				|| route add "${DNS2}" ${REMOTE_IP}
63
		fi
64
		pfSctl -c 'service reload dns'
65
		sleep 1
66
	fi
67
	pfSctl -c "interface newip ${IF}"
68

    
69
elif [ "${PROTOCOL}" == "inet6" ]; then
70
	/usr/local/sbin/ppp-ipv6 ${IF} up
71
	# let the configuration system know that the ipv6 has changed.
72
	echo ${REMOTE_IP} |cut -d% -f1 > /tmp/${IF}_routerv6
73
	echo ${LOCAL_IP} |cut -d% -f1 > /tmp/${IF}_ipv6
74
	touch /tmp/${IF}upv6
75

    
76
	if [ "${DNSALLOWOVERRIDE}" = "true" ]; then
77
		# write nameservers to file
78
		echo -n "" > /var/etc/nameserver_v6${IF}
79
		if echo "${DNS1_RAW}" | grep -q dns1; then
80
			DNS1=`echo "${DNS1_RAW}" | awk '{print $2}'`
81
			echo "${DNS1}" >> /var/etc/nameserver_v6${IF}
82
			route change -inet6 "${DNS1}" ${REMOTE_IP} \
83
				|| route add -inet6 "${DNS1}" ${REMOTE_IP}
84
		fi
85
		if echo "${DNS2_RAW}" | grep -q dns2; then
86
			DNS2=`echo "${DNS2_RAW}" | awk '{print $2}'`
87
			echo "${DNS2}" >> /var/etc/nameserver_v6${IF}
88
			route change -inet6 "${DNS2}" ${REMOTE_IP} \
89
				|| route add -inet6 "${DNS2}" ${REMOTE_IP}
90
		fi
91
		pfSctl -c 'service reload dns'
92
		sleep 1
93
	fi
94
	pfSctl -c "interface newipv6 ${IF}"
95
fi
96

    
97
exit 0
(22-22/36)