ppp revision 177683
1#!/bin/sh
2#
3# $FreeBSD: head/etc/rc.d/ppp 177683 2008-03-28 07:57:52Z brooks $
4#
5
6# PROVIDE: ppp
7# REQUIRE: netif isdnd
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="ppp"
13rcvar=`set_rcvar`
14command="/usr/sbin/${name}"
15start_cmd="ppp_start"
16stop_cmd="ppp_stop"
17start_postcmd="ppp_poststart"
18
19ppp_start_profile()
20{
21	local _ppp_profile _ppp_mode _ppp_nat _ppp_unit
22
23	_ppp_profile=$1
24	_ppp_profile_cleaned=$1
25	_punct=". - / +"
26	for _punct_c in $_punct; do
27		_ppp_profile_cleaned=`ltr ${_ppp_profile_cleaned} ${_punct_c} '_'`
28	done
29
30	# Check for ppp profile mode override.
31	#
32	eval _ppp_mode=\$ppp_${_ppp_profile_cleaned}_mode
33	if [ -z "$_ppp_mode" ]; then
34		_ppp_mode=$ppp_mode
35	fi
36
37	# Check for ppp profile nat override.
38	#
39	eval _ppp_nat=\$ppp_${_ppp_profile_cleaned}_nat
40	if [ -z "$_ppp_nat" ]; then
41		_ppp_nat=$ppp_nat
42	fi
43
44	# Establish ppp mode.
45	#
46	if [ "${_ppp_mode}" != "ddial" -a "${_ppp_mode}" != "direct" \
47		-a "${_ppp_mode}" != "dedicated" \
48		-a "${_ppp_mode}" != "background" ]; then
49		_ppp_mode="auto"
50	fi
51
52	rc_flags="-quiet -${_ppp_mode}"
53
54	# Switch on NAT mode?
55	#
56	case ${_ppp_nat} in
57	[Yy][Ee][Ss])
58		rc_flags="$rc_flags -nat"
59		;;
60	esac
61
62	# Check for hard wired unit
63	eval _ppp_unit=\$ppp_${_ppp_profile_cleaned}_unit
64	if [ -n "_ppp_unit" ]; then
65		_ppp_unit="-unit${_ppp_unit}"
66	fi
67	rc_flags="$rc_flags $_ppp_unit"
68
69	# Run!
70	#
71	su -m $ppp_user -c "$command ${rc_flags} ${_ppp_profile}"
72}
73
74ppp_start()
75{
76	local _ppp_profile _p
77
78	_ppp_profile=$*
79	if [ -z "${_ppp_profile}" ]; then
80		_ppp_profile=$ppp_profile
81	fi
82
83	echo -n "Starting PPP profile:"
84
85	for _p in $_ppp_profile; do
86		echo -n " $_p"
87		ppp_start_profile $_p
88	done
89
90	echo "."
91}
92
93ppp_poststart()
94{
95	# Re-Sync ipfilter and pf so they pick up any new network interfaces
96	#
97	/etc/rc.d/ipfilter quietresync
98	/etc/rc.d/pf quietresync
99}
100
101ppp_stop_profile() {
102	local _ppp_profile
103
104	_ppp_profile=$1
105
106	/bin/pkill -f "^${command}.*[[:space:]]${_ppp_profile}\$" || \
107		echo -n "(not running)"
108}
109
110ppp_stop() {
111	local _ppp_profile _p
112
113	_ppp_profile=$*
114	if [ -z "${_ppp_profile}" ]; then
115		_ppp_profile=$ppp_profile
116	fi
117
118	echo -n "Stopping PPP profile:"
119
120	for _p in $_ppp_profile; do
121		echo -n " $_p"
122		ppp_stop_profile $_p
123	done
124
125	echo "."
126}
127
128load_rc_config $name
129run_rc_command $*
130