1
|
#!/bin/sh
|
2
|
#
|
3
|
# ppp-linkup
|
4
|
#
|
5
|
# part of pfSense (https://www.pfsense.org)
|
6
|
# Copyright (c) 2004-2016 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
|
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
|
22
|
|
23
|
DNSALLOWOVERRIDE=$(/usr/local/sbin/read_xml_tag.sh boolean system/dnsallowoverride)
|
24
|
|
25
|
IF="${1}"
|
26
|
PROTOCOL="${2}"
|
27
|
LOCAL_IP="${3}"
|
28
|
REMOTE_IP="${4}"
|
29
|
AUTH_NAME="${5}"
|
30
|
DNS1_RAW="${6}"
|
31
|
DNS2_RAW="${7}"
|
32
|
|
33
|
if [ "${PROTOCOL}" == "inet" ]; then
|
34
|
|
35
|
OLD_ROUTER=`cat /tmp/${IF}_router`
|
36
|
if [ -n "${OLD_ROUTER}" ]; then
|
37
|
echo "Removing states to old router ${OLD_ROUTER}" | logger -t ppp-linkup
|
38
|
pfctl -i ${IF} -k 0.0.0.0/0 -k ${OLD_ROUTER}/32
|
39
|
pfctl -i ${IF} -k ${OLD_ROUTER}/32 -k 0.0.0.0/0
|
40
|
fi
|
41
|
|
42
|
# let the configuration system know that the ipv4 has changed.
|
43
|
echo ${REMOTE_IP} > /tmp/${IF}_router
|
44
|
echo ${LOCAL_IP} > /tmp/${IF}_ip
|
45
|
touch /tmp/${IF}up
|
46
|
|
47
|
if [ "${DNSALLOWOVERRIDE}" = "true" ]; then
|
48
|
# write nameservers to file
|
49
|
echo -n "" > /var/etc/nameserver_${IF}
|
50
|
if echo "${DNS1_RAW}" | grep -q dns1; then
|
51
|
DNS1=`echo "${DNS1_RAW}" | awk '{print $2}'`
|
52
|
echo "${DNS1}" >> /var/etc/nameserver_${IF}
|
53
|
route change "${DNS1}" ${REMOTE_IP} \
|
54
|
|| route add "${DNS1}" ${REMOTE_IP}
|
55
|
fi
|
56
|
if echo "${DNS2_RAW}" | grep -q dns2; then
|
57
|
DNS2=`echo "${DNS2_RAW}" | awk '{print $2}'`
|
58
|
echo "${DNS2}" >> /var/etc/nameserver_${IF}
|
59
|
route change "${DNS2}" ${REMOTE_IP} \
|
60
|
|| route add "${DNS2}" ${REMOTE_IP}
|
61
|
fi
|
62
|
pfSctl -c 'service reload dns'
|
63
|
sleep 1
|
64
|
fi
|
65
|
pfSctl -c "interface newip ${IF}"
|
66
|
|
67
|
elif [ "${PROTOCOL}" == "inet6" ]; then
|
68
|
/usr/local/sbin/ppp-ipv6 ${IF} up
|
69
|
# let the configuration system know that the ipv6 has changed.
|
70
|
echo ${REMOTE_IP} |cut -d% -f1 > /tmp/${IF}_routerv6
|
71
|
echo ${LOCAL_IP} |cut -d% -f1 > /tmp/${IF}_ipv6
|
72
|
touch /tmp/${IF}upv6
|
73
|
|
74
|
if [ "${DNSALLOWOVERRIDE}" = "true" ]; then
|
75
|
# write nameservers to file
|
76
|
echo -n "" > /var/etc/nameserver_v6${IF}
|
77
|
if echo "${DNS1_RAW}" | grep -q dns1; then
|
78
|
DNS1=`echo "${DNS1_RAW}" | awk '{print $2}'`
|
79
|
echo "${DNS1}" >> /var/etc/nameserver_v6${IF}
|
80
|
route change -inet6 "${DNS1}" ${REMOTE_IP} \
|
81
|
|| route add -inet6 "${DNS1}" ${REMOTE_IP}
|
82
|
fi
|
83
|
if echo "${DNS2_RAW}" | grep -q dns2; then
|
84
|
DNS2=`echo "${DNS2_RAW}" | awk '{print $2}'`
|
85
|
echo "${DNS2}" >> /var/etc/nameserver_v6${IF}
|
86
|
route change -inet6 "${DNS2}" ${REMOTE_IP} \
|
87
|
|| route add -inet6 "${DNS2}" ${REMOTE_IP}
|
88
|
fi
|
89
|
pfSctl -c 'service reload dns'
|
90
|
sleep 1
|
91
|
fi
|
92
|
pfSctl -c "interface newipv6 ${IF}"
|
93
|
fi
|
94
|
|
95
|
exit 0
|