198184Sgordon#!/bin/sh 298184Sgordon# 398184Sgordon# $FreeBSD$ 498184Sgordon# 598184Sgordon 6151806Syar# PROVIDE: ppp 7179315Sbz# REQUIRE: netif 8136224Smtm# KEYWORD: nojail 998184Sgordon 1098184Sgordon. /etc/rc.subr 1198184Sgordon 1298184Sgordonname="ppp" 13230099Sdougbrcvar="ppp_enable" 14151807Syarcommand="/usr/sbin/${name}" 15172586Semaxstart_cmd="ppp_start" 16172761Semaxstop_cmd="ppp_stop" 17168119Smtmstart_postcmd="ppp_poststart" 1898184Sgordon 19172586Semaxppp_start_profile() 2098184Sgordon{ 21177683Sbrooks local _ppp_profile _ppp_mode _ppp_nat _ppp_unit 22178056Sbrooks local _ppp_profile_cleaned _punct _punct_c 23172586Semax 24172586Semax _ppp_profile=$1 25177649Sbrooks _ppp_profile_cleaned=$1 26177649Sbrooks _punct=". - / +" 27177649Sbrooks for _punct_c in $_punct; do 28177649Sbrooks _ppp_profile_cleaned=`ltr ${_ppp_profile_cleaned} ${_punct_c} '_'` 29177649Sbrooks done 30172586Semax 31172586Semax # Check for ppp profile mode override. 32172586Semax # 33177649Sbrooks eval _ppp_mode=\$ppp_${_ppp_profile_cleaned}_mode 34172586Semax if [ -z "$_ppp_mode" ]; then 35172586Semax _ppp_mode=$ppp_mode 36172586Semax fi 37172586Semax 38172586Semax # Check for ppp profile nat override. 39172586Semax # 40177649Sbrooks eval _ppp_nat=\$ppp_${_ppp_profile_cleaned}_nat 41172586Semax if [ -z "$_ppp_nat" ]; then 42172586Semax _ppp_nat=$ppp_nat 43172586Semax fi 44172586Semax 4598184Sgordon # Establish ppp mode. 4698184Sgordon # 47172586Semax if [ "${_ppp_mode}" != "ddial" -a "${_ppp_mode}" != "direct" \ 48172586Semax -a "${_ppp_mode}" != "dedicated" \ 49172586Semax -a "${_ppp_mode}" != "background" ]; then 50172586Semax _ppp_mode="auto" 5198184Sgordon fi 5298184Sgordon 53172586Semax rc_flags="-quiet -${_ppp_mode}" 5498184Sgordon 5598184Sgordon # Switch on NAT mode? 5698184Sgordon # 57172586Semax case ${_ppp_nat} in 5898184Sgordon [Yy][Ee][Ss]) 59138889Sbrian rc_flags="$rc_flags -nat" 6098184Sgordon ;; 6198184Sgordon esac 6298184Sgordon 63177683Sbrooks # Check for hard wired unit 64177683Sbrooks eval _ppp_unit=\$ppp_${_ppp_profile_cleaned}_unit 65177959Sbrooks if [ -n "${_ppp_unit}" ]; then 66177683Sbrooks _ppp_unit="-unit${_ppp_unit}" 67177683Sbrooks fi 68177683Sbrooks rc_flags="$rc_flags $_ppp_unit" 69177683Sbrooks 70172586Semax # Run! 71172586Semax # 72172586Semax su -m $ppp_user -c "$command ${rc_flags} ${_ppp_profile}" 73138889Sbrian} 7498184Sgordon 75172586Semaxppp_start() 76172586Semax{ 77172761Semax local _ppp_profile _p 78172586Semax 79172761Semax _ppp_profile=$* 80172761Semax if [ -z "${_ppp_profile}" ]; then 81172761Semax _ppp_profile=$ppp_profile 82172761Semax fi 83172761Semax 84172586Semax echo -n "Starting PPP profile:" 85172586Semax 86172761Semax for _p in $_ppp_profile; do 87172586Semax echo -n " $_p" 88172586Semax ppp_start_profile $_p 89172586Semax done 90172586Semax 91172586Semax echo "." 92172586Semax} 93172586Semax 94168119Smtmppp_poststart() 95138889Sbrian{ 96163696Savatar # Re-Sync ipfilter and pf so they pick up any new network interfaces 9798184Sgordon # 98197196Semaste if [ -f /etc/rc.d/ipfilter ]; then 99197196Semaste /etc/rc.d/ipfilter quietresync 100197196Semaste fi 101197196Semaste if [ -f /etc/rc.d/pf ]; then 102197196Semaste /etc/rc.d/pf quietresync 103197196Semaste fi 10498184Sgordon} 10598184Sgordon 106172761Semaxppp_stop_profile() { 107172761Semax local _ppp_profile 108172761Semax 109172761Semax _ppp_profile=$1 110172761Semax 111172761Semax /bin/pkill -f "^${command}.*[[:space:]]${_ppp_profile}\$" || \ 112172761Semax echo -n "(not running)" 113172761Semax} 114172761Semax 115172761Semaxppp_stop() { 116172761Semax local _ppp_profile _p 117172761Semax 118172761Semax _ppp_profile=$* 119172761Semax if [ -z "${_ppp_profile}" ]; then 120172761Semax _ppp_profile=$ppp_profile 121172761Semax fi 122172761Semax 123172761Semax echo -n "Stopping PPP profile:" 124172761Semax 125172761Semax for _p in $_ppp_profile; do 126172761Semax echo -n " $_p" 127172761Semax ppp_stop_profile $_p 128172761Semax done 129172761Semax 130172761Semax echo "." 131172761Semax} 132172761Semax 13398184Sgordonload_rc_config $name 134172761Semaxrun_rc_command $* 135