summaryrefslogtreecommitdiffstats
path: root/usr/local/sbin/ppp-linkup
blob: 9e4aafda8c0775d674216dc6ae7bafd32a0edf76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh

if [ "${2}" == "inet" ]; then

	OLD_ROUTER=`/bin/cat /tmp/${1}_router`
	if [ "${OLD_ROUTER}" != "" ]; then
		echo "Removing states to old router ${OLD_ROUTER}" | logger -t ppp-linkup
		/sbin/pfctl -i ${1} -k 0.0.0.0/0 -k ${OLD_ROUTER}/32
		/sbin/pfctl -i ${1} -k ${OLD_ROUTER}/32 -k 0.0.0.0/0
	fi

	# let the configuration system know that the ipv4 has changed.
	/bin/echo ${4} > /tmp/${1}_router
	/bin/echo ${3} > /tmp/${1}_ip
	/usr/bin/touch /tmp/${1}up

	ALLOWOVERRIDE=`/usr/bin/grep -c dnsallowoverride /conf/config.xml`
	if [ ${ALLOWOVERRIDE} -gt 0 ]; then
		# write nameservers to file
		if [ "`echo ${6}|grep -c dns1`" -gt 0 ]; then
			DNS1=`echo ${6} |awk '{print ${2}}'`
			echo "${DNS1}"> /var/etc/nameserver_${1}
			/sbin/route change "${DNS1}" ${4}
		fi
		if [ "`echo ${7}|grep -c dns2`" -gt 0 ]; then
			DNS2=`echo ${7} |awk '{print ${2}}'`
			echo "${DNS2}" >> /var/etc/nameserver_${1}
			/sbin/route change "${DNS2}" ${4}
		fi
		/usr/local/sbin/pfSctl -c 'service reload dns'
		/bin/sleep 1
	fi
	/usr/local/sbin/pfSctl -c "interface newip ${1}"
fi

if [ "${2}" == "inet6" ]; then
	# let the configuration system know that the ipv6 has changed.
	/bin/echo ${4} |cut -d% -f1 > /tmp/${1}_routerv6
	/bin/echo ${3} |cut -d% -f1 > /tmp/${1}_ipv6
	/usr/bin/touch /tmp/${1}upv6

	ALLOWOVERRIDE=`/usr/bin/grep -c dnsallowoverride /conf/config.xml`
	if [ ${ALLOWOVERRIDE} -gt 0 ]; then
		# write nameservers to file
		if [ "`echo ${6}|grep -c dns1`" -gt 0 ]; then
			DNS1=`echo ${6} |awk '{print ${2}}'`
			echo "${DNS1}"> /var/etc/nameserver_v6${1}
			/sbin/route change -inet6 "${DNS1}" ${4}
		fi
		if [ "`echo ${7}|grep -c dns2`" -gt 0 ]; then
			DNS2=`echo ${7} |awk '{print ${2}}'`
			echo "${DNS2}" >> /var/etc/nameserver_v6${1}
			/sbin/route change -inet6 "${DNS2}" ${4}
		fi
		/usr/local/sbin/pfSctl -c 'service reload dns'
		/bin/sleep 1
	fi
	/usr/local/sbin/pfSctl -c "interface newipv6 ${1}"
fi

exit 0
OpenPOWER on IntegriCloud