xref: /freebsd/libexec/rc/rc.d/ppp (revision ab393e9548f8cc0ee28499c411963b798ebb38a5)
1#!/bin/sh
2#
3#
4
5# PROVIDE: ppp
6# REQUIRE: netif
7# KEYWORD: nojail
8
9. /etc/rc.subr
10
11name="ppp"
12desc="Point to Point Protocol"
13rcvar="ppp_enable"
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	local _ppp_profile_cleaned _punct _punct_c
23
24	_ppp_profile=$1
25	_ppp_profile_cleaned=$1
26	_punct=". - / +"
27	for _punct_c in $_punct; do
28		_ppp_profile_cleaned=`ltr ${_ppp_profile_cleaned} ${_punct_c} '_'`
29	done
30
31	# Check for ppp profile mode override.
32	#
33	eval _ppp_mode=\$ppp_${_ppp_profile_cleaned}_mode
34	if [ -z "$_ppp_mode" ]; then
35		_ppp_mode=$ppp_mode
36	fi
37
38	# Check for ppp profile nat override.
39	#
40	eval _ppp_nat=\$ppp_${_ppp_profile_cleaned}_nat
41	if [ -z "$_ppp_nat" ]; then
42		_ppp_nat=$ppp_nat
43	fi
44
45	# Establish ppp mode.
46	#
47	if [ "${_ppp_mode}" != "ddial" -a "${_ppp_mode}" != "direct" \
48		-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	startmsg -n "Starting PPP profile:"
85
86	for _p in $_ppp_profile; do
87		startmsg -n " $_p"
88		ppp_start_profile $_p
89	done
90
91	startmsg "."
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