Project

General

Profile

Download (3.04 KB) Statistics
| Branch: | Tag: | Revision:
1 e1c8cdf5 Scott Ullrich
#!/bin/sh
2 ac24dc24 Renato Botelho
#
3
# ppp-linkup
4
#
5
# part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
# Copyright (c) 2004-2013 BSD Perimeter
7
# Copyright (c) 2013-2016 Electric Sheep Fencing
8 0284d79e jim-p
# Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9 ac24dc24 Renato Botelho
# All rights reserved.
10
#
11 b12ea3fb Renato Botelho
# 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 ac24dc24 Renato Botelho
#
15 b12ea3fb Renato Botelho
# http://www.apache.org/licenses/LICENSE-2.0
16 ac24dc24 Renato Botelho
#
17 b12ea3fb Renato Botelho
# 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 e1c8cdf5 Scott Ullrich
23 db63c043 Renato Botelho
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
24
25 a5c36eb2 Renato Botelho
DNSALLOWOVERRIDE=$(/usr/local/sbin/read_xml_tag.sh boolean system/dnsallowoverride)
26
27 55fe5491 David Wood
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 766cd450 jim-p
35 55fe5491 David Wood
if [ "${PROTOCOL}" == "inet" ]; then
36
37
	OLD_ROUTER=`cat /tmp/${IF}_router`
38 db63c043 Renato Botelho
	if [ -n "${OLD_ROUTER}" ]; then
39 766cd450 jim-p
		echo "Removing states to old router ${OLD_ROUTER}" | logger -t ppp-linkup
40 55fe5491 David Wood
		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 766cd450 jim-p
	fi
43
44 e32cb5d0 smos
	# let the configuration system know that the ipv4 has changed.
45 55fe5491 David Wood
	echo ${REMOTE_IP} > /tmp/${IF}_router
46
	echo ${LOCAL_IP} > /tmp/${IF}_ip
47
	touch /tmp/${IF}up
48 1cba5c58 smos
49 a5c36eb2 Renato Botelho
	if [ "${DNSALLOWOVERRIDE}" = "true" ]; then
50 1cba5c58 smos
		# write nameservers to file
51 55fe5491 David Wood
		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 94bd7fb3 Renato Botelho
			route change "${DNS1}" ${REMOTE_IP} \
56
				|| route add "${DNS1}" ${REMOTE_IP}
57 1cba5c58 smos
		fi
58 55fe5491 David Wood
		if echo "${DNS2_RAW}" | grep -q dns2; then
59
			DNS2=`echo "${DNS2_RAW}" | awk '{print $2}'`
60
			echo "${DNS2}" >> /var/etc/nameserver_${IF}
61 94bd7fb3 Renato Botelho
			route change "${DNS2}" ${REMOTE_IP} \
62
				|| route add "${DNS2}" ${REMOTE_IP}
63 1cba5c58 smos
		fi
64 db63c043 Renato Botelho
		pfSctl -c 'service reload dns'
65
		sleep 1
66 1cba5c58 smos
	fi
67 55fe5491 David Wood
	pfSctl -c "interface newip ${IF}"
68 e32cb5d0 smos
69 55fe5491 David Wood
elif [ "${PROTOCOL}" == "inet6" ]; then
70
	/usr/local/sbin/ppp-ipv6 ${IF} up
71 e32cb5d0 smos
	# let the configuration system know that the ipv6 has changed.
72 55fe5491 David Wood
	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 5b06d9cc Ermal
76 a5c36eb2 Renato Botelho
	if [ "${DNSALLOWOVERRIDE}" = "true" ]; then
77 1cba5c58 smos
		# write nameservers to file
78 55fe5491 David Wood
		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 94bd7fb3 Renato Botelho
			route change -inet6 "${DNS1}" ${REMOTE_IP} \
83
				|| route add -inet6 "${DNS1}" ${REMOTE_IP}
84 1cba5c58 smos
		fi
85 55fe5491 David Wood
		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 94bd7fb3 Renato Botelho
			route change -inet6 "${DNS2}" ${REMOTE_IP} \
89
				|| route add -inet6 "${DNS2}" ${REMOTE_IP}
90 1cba5c58 smos
		fi
91 db63c043 Renato Botelho
		pfSctl -c 'service reload dns'
92
		sleep 1
93 a73a9886 Ermal
	fi
94 55fe5491 David Wood
	pfSctl -c "interface newipv6 ${IF}"
95 e1c8cdf5 Scott Ullrich
fi
96
97 1f0ddd30 Ermal
exit 0