From ea81bda9f95757386b1629a21774d927c653cf67 Mon Sep 17 00:00:00 2001 From: emax Date: Wed, 31 Oct 2007 16:42:41 +0000 Subject: [PATCH] MFC: etc/rc.d/ppp,v1.14 and etc/defaults/rc.conf,v1.319 Teach /etc/rc.d/ppp to start multiple instances of ppp. ppp_profile variable can now contain multiple profiles. Overrides for ppp mode and nat can go into ppp_$profile_mode and ppp_$profile_nat variables respectively. If those are not specified, defaults from ppp_mode and ppp_nat are used. MFC: etc/rc.d/ppp v1.15 Teach /etc/rc.d/ppp how to start/stop individual instances of ppp. This is an extension of previous commit. Submitted by: Yuri Kurenkov < y dot kurenkov at init dot ru > Reviewed by: mtm Approved by: re (kensmith) --- etc/defaults/rc.conf | 6 +++ etc/rc.d/ppp | 87 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 83 insertions(+), 10 deletions(-) diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index 1027ec156b7..7a18b9c2902 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -205,6 +205,12 @@ ppp_nat="YES" # Use PPP's internal network address translation or NO. ppp_profile="papchap" # Which profile to use from /etc/ppp/ppp.conf. ppp_user="root" # Which user to run ppp as +# Start multiple instances of ppp at boot time +#ppp_profile="profile1 profile2 profile3" # Which profiles to use +#ppp_profile1_mode="ddial" # Override ppp mode for profile1 +#ppp_profile2_nat="NO" # Override nat mode for profile2 +# profile3 uses default ppp_mode and ppp_nat + ### Network daemon (miscellaneous) ### hostapd_enable="NO" # Run hostap daemon. syslogd_enable="YES" # Run syslog daemon (or NO). diff --git a/etc/rc.d/ppp b/etc/rc.d/ppp index d0c6dc29d1c..b5ca7df0456 100644 --- a/etc/rc.d/ppp +++ b/etc/rc.d/ppp @@ -12,30 +12,70 @@ name="ppp" rcvar=`set_rcvar` command="/usr/sbin/${name}" -start_precmd="ppp_prestart" +start_cmd="ppp_start" +stop_cmd="ppp_stop" start_postcmd="ppp_poststart" -ppp_prestart() +ppp_start_profile() { + local _ppp_profile _ppp_mode _ppp_nat + + _ppp_profile=$1 + + # Check for ppp profile mode override. + # + eval _ppp_mode=\$ppp_${_ppp_profile}_mode + if [ -z "$_ppp_mode" ]; then + _ppp_mode=$ppp_mode + fi + + # Check for ppp profile nat override. + # + eval _ppp_nat=\$ppp_${_ppp_profile}_nat + if [ -z "$_ppp_nat" ]; then + _ppp_nat=$ppp_nat + fi + # Establish ppp mode. # - if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \ - -a "${ppp_mode}" != "dedicated" \ - -a "${ppp_mode}" != "background" ]; then - ppp_mode="auto" + if [ "${_ppp_mode}" != "ddial" -a "${_ppp_mode}" != "direct" \ + -a "${_ppp_mode}" != "dedicated" \ + -a "${_ppp_mode}" != "background" ]; then + _ppp_mode="auto" fi - rc_flags="$rc_flags -quiet -${ppp_mode}" + rc_flags="-quiet -${_ppp_mode}" # Switch on NAT mode? # - case ${ppp_nat} in + case ${_ppp_nat} in [Yy][Ee][Ss]) rc_flags="$rc_flags -nat" ;; esac - rc_flags="$rc_flags ${ppp_profile}" + # Run! + # + su -m $ppp_user -c "$command ${rc_flags} ${_ppp_profile}" +} + +ppp_start() +{ + local _ppp_profile _p + + _ppp_profile=$* + if [ -z "${_ppp_profile}" ]; then + _ppp_profile=$ppp_profile + fi + + echo -n "Starting PPP profile:" + + for _p in $_ppp_profile; do + echo -n " $_p" + ppp_start_profile $_p + done + + echo "." } ppp_poststart() @@ -46,5 +86,32 @@ ppp_poststart() /etc/rc.d/pf resync } +ppp_stop_profile() { + local _ppp_profile + + _ppp_profile=$1 + + /bin/pkill -f "^${command}.*[[:space:]]${_ppp_profile}\$" || \ + echo -n "(not running)" +} + +ppp_stop() { + local _ppp_profile _p + + _ppp_profile=$* + if [ -z "${_ppp_profile}" ]; then + _ppp_profile=$ppp_profile + fi + + echo -n "Stopping PPP profile:" + + for _p in $_ppp_profile; do + echo -n " $_p" + ppp_stop_profile $_p + done + + echo "." +} + load_rc_config $name -run_rc_command "$1" +run_rc_command $* -- 2.45.2