summaryrefslogtreecommitdiff
blob: b072ec12a7904a622e49ffa567b08c3cc5e9229f (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dialup/isdn4k-utils/files/net.ippp0,v 1.1 2005/03/29 08:40:14 mrness Exp $

#NB: Config is in /etc/conf.d/net

depend() {
	need isdn
}

checkconfig() {
	if [ -z "$(eval echo \$\{iface_${IFACE}\})" ]
	then
		eerror "Please make sure that /etc/conf.d/net has \$iface_$IFACE set"
		return 1
	fi
}

start() {
	checkconfig || return 1

	local iface_args="$(eval echo \$\{iface_${IFACE}\})"
	local ipppd_opts=""

	ebegin "Starting ipppd for ${IFACE}"
	[ -n "${gateway}" ] && [ "${gateway%/*}" = "${IFACE}" ] && ipppd_opts='defaultroute'
	/usr/sbin/ipppd ${ipppd_opts} pidfile /var/run/ipppd.${IFACE}.pid file /etc/ppp/options.${IFACE} || {
		local retval=$?
		eend ${retval} "Failed to start ipppd"
		return ${retval}
	}
	eend 0

	ebegin "Bringing ${IFACE} up"
	/sbin/ifconfig ${IFACE} ${iface_args} >/dev/null || {
		local retval=$?
		eend ${retval} "Failed to bring ${IFACE} up"
		stop
		return ${retval}
	}
	eend 0

	if [ -n "$(eval echo \$\{inet6_${IFACE}\})" ]
	then
		local x=""
		ebegin "  Adding inet6 addresses"
		for x in $(eval echo \$\{inet6_${IFACE}\})
		do
			ebegin "    ${IFACE} inet6 add ${x}"
			/sbin/ifconfig ${IFACE} inet6 add ${x} >/dev/null
			eend 0
		done
		save_options "inet6" "$(eval echo \$\{inet6_${IFACE}\})"
	fi

	if [ -n "${gateway}" ] && [ "${gateway%/*}" = "${IFACE}" ]
	then
		ebegin "  Setting default gateway"
		/sbin/route add default dev ${gateway%/*} >/dev/null || {
			local retval=$?
			eend ${retval} "Failed to bring ${IFACE} up"
			stop
			return ${retval}
		}
		eend 0
	fi

	# Enabling rp_filter causes wacky packets to be auto-dropped by
	# the kernel
	if [ -e /proc/sys/net/ipv4/conf/${IFACE}/rp_filter ]
	then
		echo 1 > /proc/sys/net/ipv4/conf/${IFACE}/rp_filter
	fi
}

stop() {
	local myinet6="$(get_options inet6)"
	local pidfile="/var/run/ipppd.${IFACE}.pid"

	ebegin "Bringing ${IFACE} down"

	# Also down the inet6 interfaces
	if [ -n "${myinet6}" ]
	then
		local x=""
		for x in ${myinet6}
		do
			/sbin/ifconfig ${IFACE} inet6 del ${x} >/dev/null
		done
	fi

	/sbin/ifconfig ${IFACE} down >/dev/null

	# Kill ipppd
	test -s "${pidfile}" && kill `cat ${pidfile}`
	sleep 1
	test -s "${pidfile}" && sleep 2 && test -s "${pidfile}" && einfon "Killing ipppd" && kill -KILL `cat ${pidfile}`

	eend 0
}