1
|
#!/bin/sh
|
2
|
#
|
3
|
# ppp-linkdown
|
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-2023 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
|
IF="${1}"
|
24
|
PROTOCOL="${2}"
|
25
|
LOCAL_IP="${3}"
|
26
|
|
27
|
if [ -f /tmp/${IF}up ] && [ -f /conf/${IF}.log ]; then
|
28
|
seconds=$((`date -j +%s` - `/usr/bin/stat -f %m /tmp/${IF}up`))
|
29
|
/usr/local/sbin/ppp-log-uptime.sh $seconds ${IF} &
|
30
|
fi
|
31
|
|
32
|
if echo "${IF}" | /usr/bin/egrep -qv "ppp[0-9]+"; then
|
33
|
/etc/rc.kill_states ${IF} ${LOCAL_IP}
|
34
|
fi
|
35
|
|
36
|
if [ "${PROTOCOL}" == "inet" && -s "/tmp/${IF}_defaultgw" ]; then
|
37
|
GW=`head -n 1 /tmp/${IF}_defaultgw`
|
38
|
DGW=`/sbin/route -n get -inet default | /usr/bin/awk '/gateway:/ {print $2}'`
|
39
|
# Only remove the default gateway if it matches the gateway for this interface. See redmine #1837
|
40
|
if [ "${GW}" = "${DGW}" ]; then
|
41
|
/sbin/route -q delete default ${GW}
|
42
|
fi
|
43
|
fi
|
44
|
|
45
|
if [ "${PROTOCOL}" == "inet6" ]; then
|
46
|
/usr/local/sbin/ppp-ipv6 ${IF} down
|
47
|
fi
|
48
|
# delete the node just in case mpd cannot do that
|
49
|
/usr/sbin/ngctl shutdown ${IF}:
|
50
|
if [ -f "/var/etc/nameserver_${IF}" ]; then
|
51
|
# Remove old entries
|
52
|
for nameserver in `cat /var/etc/nameserver_${IF}`; do
|
53
|
/sbin/route -q delete ${nameserver} >/dev/null 2>&1
|
54
|
done
|
55
|
/bin/rm -f /var/etc/nameserver_${IF}
|
56
|
fi
|
57
|
# Do not remove gateway used during filter reload.
|
58
|
|
59
|
if [ -f "/tmp/${IF}_router" ]; then
|
60
|
/bin/mv /tmp/${IF}_router /tmp/${IF}_router.last
|
61
|
fi
|
62
|
|
63
|
# cleanup all VIPs, see https://redmine.pfsense.org/issues/11629
|
64
|
while
|
65
|
aliases=$(/sbin/ifconfig ${IF} | /usr/bin/grep netmask)
|
66
|
if [ -z "${aliases}" ]; then
|
67
|
break
|
68
|
fi
|
69
|
do ifconfig ${IF} -alias ; done
|
70
|
|
71
|
/bin/rm -f /tmp/${IF}up
|
72
|
/bin/rm -f /tmp/${IF}_ip
|
73
|
/usr/local/sbin/pfSctl -c 'service reload dns'
|