ppp revision 231653
154359Sroberto#!/bin/sh
254359Sroberto#
354359Sroberto# $FreeBSD: stable/9/etc/rc.d/ppp 231653 2012-02-14 10:16:56Z dougb $
454359Sroberto#
554359Sroberto
654359Sroberto# PROVIDE: ppp
754359Sroberto# REQUIRE: netif
854359Sroberto# KEYWORD: nojail
954359Sroberto
1054359Sroberto. /etc/rc.subr
1154359Sroberto
1254359Srobertoname="ppp"
1354359Srobertorcvar="ppp_enable"
1454359Srobertocommand="/usr/sbin/${name}"
1554359Srobertostart_cmd="ppp_start"
1654359Srobertostop_cmd="ppp_stop"
1754359Srobertostart_postcmd="ppp_poststart"
1854359Sroberto
1954359Srobertoppp_start_profile()
2054359Sroberto{
2154359Sroberto	local _ppp_profile _ppp_mode _ppp_nat _ppp_unit
2254359Sroberto	local _ppp_profile_cleaned _punct _punct_c
2354359Sroberto
2454359Sroberto	_ppp_profile=$1
2554359Sroberto	_ppp_profile_cleaned=$1
2654359Sroberto	_punct=". - / +"
2754359Sroberto	for _punct_c in $_punct; do
2854359Sroberto		_ppp_profile_cleaned=`ltr ${_ppp_profile_cleaned} ${_punct_c} '_'`
2954359Sroberto	done
3054359Sroberto
3154359Sroberto	# Check for ppp profile mode override.
3254359Sroberto	#
3354359Sroberto	eval _ppp_mode=\$ppp_${_ppp_profile_cleaned}_mode
3454359Sroberto	if [ -z "$_ppp_mode" ]; then
3554359Sroberto		_ppp_mode=$ppp_mode
3654359Sroberto	fi
3754359Sroberto
3854359Sroberto	# Check for ppp profile nat override.
3954359Sroberto	#
4054359Sroberto	eval _ppp_nat=\$ppp_${_ppp_profile_cleaned}_nat
4154359Sroberto	if [ -z "$_ppp_nat" ]; then
4254359Sroberto		_ppp_nat=$ppp_nat
4354359Sroberto	fi
4454359Sroberto
4554359Sroberto	# Establish ppp mode.
4654359Sroberto	#
4754359Sroberto	if [ "${_ppp_mode}" != "ddial" -a "${_ppp_mode}" != "direct" \
4854359Sroberto		-a "${_ppp_mode}" != "dedicated" \
49		-a "${_ppp_mode}" != "background" ]; then
50		_ppp_mode="auto"
51	fi
52
53	rc_flags="-quiet -${_ppp_mode}"
54
55	# Switch on NAT mode?
56	#
57	case ${_ppp_nat} in
58	[Yy][Ee][Ss])
59		rc_flags="$rc_flags -nat"
60		;;
61	esac
62
63	# Check for hard wired unit
64	eval _ppp_unit=\$ppp_${_ppp_profile_cleaned}_unit
65	if [ -n "${_ppp_unit}" ]; then
66		_ppp_unit="-unit${_ppp_unit}"
67	fi
68	rc_flags="$rc_flags $_ppp_unit"
69
70	# Run!
71	#
72	su -m $ppp_user -c "$command ${rc_flags} ${_ppp_profile}"
73}
74
75ppp_start()
76{
77	local _ppp_profile _p
78
79	_ppp_profile=$*
80	if [ -z "${_ppp_profile}" ]; then
81		_ppp_profile=$ppp_profile
82	fi
83
84	echo -n "Starting PPP profile:"
85
86	for _p in $_ppp_profile; do
87		echo -n " $_p"
88		ppp_start_profile $_p
89	done
90
91	echo "."
92}
93
94ppp_poststart()
95{
96	# Re-Sync ipfilter and pf so they pick up any new network interfaces
97	#
98	if [ -f /etc/rc.d/ipfilter ]; then
99		/etc/rc.d/ipfilter quietresync
100	fi
101	if [ -f /etc/rc.d/pf ]; then
102		/etc/rc.d/pf quietresync
103	fi
104}
105
106ppp_stop_profile() {
107	local _ppp_profile
108
109	_ppp_profile=$1
110
111	/bin/pkill -f "^${command}.*[[:space:]]${_ppp_profile}\$" || \
112		echo -n "(not running)"
113}
114
115ppp_stop() {
116	local _ppp_profile _p
117
118	_ppp_profile=$*
119	if [ -z "${_ppp_profile}" ]; then
120		_ppp_profile=$ppp_profile
121	fi
122
123	echo -n "Stopping PPP profile:"
124
125	for _p in $_ppp_profile; do
126		echo -n " $_p"
127		ppp_stop_profile $_p
128	done
129
130	echo "."
131}
132
133load_rc_config $name
134run_rc_command $*
135