ppp revision 177649
198184Sgordon#!/bin/sh
298184Sgordon#
398184Sgordon# $FreeBSD: head/etc/rc.d/ppp 177649 2008-03-26 21:54:48Z brooks $
498184Sgordon#
598184Sgordon
6151806Syar# PROVIDE: ppp
7113676Smtm# REQUIRE: netif isdnd
8136224Smtm# KEYWORD: nojail
998184Sgordon
1098184Sgordon. /etc/rc.subr
1198184Sgordon
1298184Sgordonname="ppp"
13138889Sbrianrcvar=`set_rcvar`
14151807Syarcommand="/usr/sbin/${name}"
15172586Semaxstart_cmd="ppp_start"
16172761Semaxstop_cmd="ppp_stop"
17168119Smtmstart_postcmd="ppp_poststart"
1898184Sgordon
19172586Semaxppp_start_profile()
2098184Sgordon{
21172586Semax	local _ppp_profile _ppp_mode _ppp_nat
22172586Semax
23172586Semax	_ppp_profile=$1
24177649Sbrooks	_ppp_profile_cleaned=$1
25177649Sbrooks	_punct=". - / +"
26177649Sbrooks	for _punct_c in $_punct; do
27177649Sbrooks		_ppp_profile_cleaned=`ltr ${_ppp_profile_cleaned} ${_punct_c} '_'`
28177649Sbrooks	done
29172586Semax
30172586Semax	# Check for ppp profile mode override.
31172586Semax	#
32177649Sbrooks	eval _ppp_mode=\$ppp_${_ppp_profile_cleaned}_mode
33172586Semax	if [ -z "$_ppp_mode" ]; then
34172586Semax		_ppp_mode=$ppp_mode
35172586Semax	fi
36172586Semax
37172586Semax	# Check for ppp profile nat override.
38172586Semax	#
39177649Sbrooks	eval _ppp_nat=\$ppp_${_ppp_profile_cleaned}_nat
40172586Semax	if [ -z "$_ppp_nat" ]; then
41172586Semax		_ppp_nat=$ppp_nat
42172586Semax	fi
43172586Semax
4498184Sgordon	# Establish ppp mode.
4598184Sgordon	#
46172586Semax	if [ "${_ppp_mode}" != "ddial" -a "${_ppp_mode}" != "direct" \
47172586Semax		-a "${_ppp_mode}" != "dedicated" \
48172586Semax		-a "${_ppp_mode}" != "background" ]; then
49172586Semax		_ppp_mode="auto"
5098184Sgordon	fi
5198184Sgordon
52172586Semax	rc_flags="-quiet -${_ppp_mode}"
5398184Sgordon
5498184Sgordon	# Switch on NAT mode?
5598184Sgordon	#
56172586Semax	case ${_ppp_nat} in
5798184Sgordon	[Yy][Ee][Ss])
58138889Sbrian		rc_flags="$rc_flags -nat"
5998184Sgordon		;;
6098184Sgordon	esac
6198184Sgordon
62172586Semax	# Run!
63172586Semax	#
64172586Semax	su -m $ppp_user -c "$command ${rc_flags} ${_ppp_profile}"
65138889Sbrian}
6698184Sgordon
67172586Semaxppp_start()
68172586Semax{
69172761Semax	local _ppp_profile _p
70172586Semax
71172761Semax	_ppp_profile=$*
72172761Semax	if [ -z "${_ppp_profile}" ]; then
73172761Semax		_ppp_profile=$ppp_profile
74172761Semax	fi
75172761Semax
76172586Semax	echo -n "Starting PPP profile:"
77172586Semax
78172761Semax	for _p in $_ppp_profile; do
79172586Semax		echo -n " $_p"
80172586Semax		ppp_start_profile $_p
81172586Semax	done
82172586Semax
83172586Semax	echo "."
84172586Semax}
85172586Semax
86168119Smtmppp_poststart()
87138889Sbrian{
88163696Savatar	# Re-Sync ipfilter and pf so they pick up any new network interfaces
8998184Sgordon	#
90175686Smtm	/etc/rc.d/ipfilter quietresync
91175686Smtm	/etc/rc.d/pf quietresync
9298184Sgordon}
9398184Sgordon
94172761Semaxppp_stop_profile() {
95172761Semax	local _ppp_profile
96172761Semax
97172761Semax	_ppp_profile=$1
98172761Semax
99172761Semax	/bin/pkill -f "^${command}.*[[:space:]]${_ppp_profile}\$" || \
100172761Semax		echo -n "(not running)"
101172761Semax}
102172761Semax
103172761Semaxppp_stop() {
104172761Semax	local _ppp_profile _p
105172761Semax
106172761Semax	_ppp_profile=$*
107172761Semax	if [ -z "${_ppp_profile}" ]; then
108172761Semax		_ppp_profile=$ppp_profile
109172761Semax	fi
110172761Semax
111172761Semax	echo -n "Stopping PPP profile:"
112172761Semax
113172761Semax	for _p in $_ppp_profile; do
114172761Semax		echo -n " $_p"
115172761Semax		ppp_stop_profile $_p
116172761Semax	done
117172761Semax
118172761Semax	echo "."
119172761Semax}
120172761Semax
12198184Sgordonload_rc_config $name
122172761Semaxrun_rc_command $*
123