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