2007-04-05 16:48:42 +05:30
|
|
|
# Copyright 2005-2007 Gentoo Foundation
|
|
|
|
# Distributed under the terms of the GNU General Public License v2
|
|
|
|
|
|
|
|
pppd_depend() {
|
|
|
|
program /usr/sbin/pppd
|
|
|
|
after interface
|
|
|
|
before dhcp
|
|
|
|
provide ppp
|
|
|
|
}
|
|
|
|
|
|
|
|
is_ppp() {
|
|
|
|
[ -e /var/run/ppp-"${IFACE}".pid ]
|
|
|
|
}
|
|
|
|
|
|
|
|
requote() {
|
|
|
|
printf "'%s' " "$@"
|
|
|
|
}
|
|
|
|
|
2007-04-19 16:22:37 +05:30
|
|
|
pppd_pre_start() {
|
2007-04-05 16:48:42 +05:30
|
|
|
${IN_BACKGROUND} && return 0
|
|
|
|
|
2007-04-19 16:22:37 +05:30
|
|
|
# Interface has to be called ppp
|
|
|
|
[ "${IFACE%%[0-9]*}" = "ppp" ] || return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
local link= i= opts= unit="${IFACE#ppp}" mtu=
|
2007-04-19 16:22:37 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
# PPP requires a link to communicate over - normally a serial port
|
|
|
|
# PPPoE communicates over Ethernet
|
|
|
|
# PPPoA communicates over ATM
|
|
|
|
# In all cases, the link needs to be available before we start PPP
|
|
|
|
eval link=\$link_${IFVAR}
|
2007-04-19 16:22:37 +05:30
|
|
|
[ -n "${link}" ] || return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
case "${link}" in
|
|
|
|
/*)
|
|
|
|
if [ ! -e "${link}" ] ; then
|
|
|
|
eerror "${link} does not exist"
|
|
|
|
eerror "Please verify hardware or kernel module (driver)"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2007-04-19 16:22:37 +05:30
|
|
|
if [ -z "${unit}" ] ; then
|
|
|
|
eerror "PPP requires a unit - use net.ppp[0-9] instead of net.ppp"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
eval $(_get_array "pppd_${IFVAR}")
|
2007-04-18 20:12:40 +05:30
|
|
|
opts="$@"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-04-18 20:12:40 +05:30
|
|
|
local mtu= hasmtu=false hasmru=false hasmaxfail=false haspersits=false
|
|
|
|
local hasupdetach=false
|
2007-04-05 16:48:42 +05:30
|
|
|
for i in "$@" ; do
|
|
|
|
set -- ${i}
|
|
|
|
case "$1" in
|
|
|
|
unit|nodetach|linkname)
|
|
|
|
eerror "The option \"$1\" is not allowed in pppd_${IFVAR}"
|
|
|
|
return 1
|
|
|
|
;;
|
2007-04-18 20:12:40 +05:30
|
|
|
mtu) hasmtu=true ;;
|
|
|
|
mru) hasmru=true ;;
|
|
|
|
maxfail) hasmaxfail=true ;;
|
|
|
|
persist) haspersist=true ;;
|
|
|
|
updetach) hasupdetach=true;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Might be set in conf.d/net
|
|
|
|
local username= password= passwordset=
|
|
|
|
eval username=\$username_${IFVAR}
|
|
|
|
eval password=\$password_${IFVAR}
|
|
|
|
eval passwordset=\${password_${IFVAR}-x}
|
|
|
|
if [ -n "${username}" ] \
|
|
|
|
&& [ -n "${password}" -o -z "${passwordset}" ] ; then
|
|
|
|
opts="${opts} plugin passwordfd.so passwordfd 0"
|
|
|
|
fi
|
|
|
|
|
2007-04-18 19:51:25 +05:30
|
|
|
if [ -n "${mtu}" ] ; then
|
2007-04-18 20:12:40 +05:30
|
|
|
${hasmtu} || opts="${opts} mtu ${mtu}"
|
|
|
|
${hasmru} || opts="${opts} mru ${mtu}"
|
2007-04-18 19:51:25 +05:30
|
|
|
fi
|
2007-04-18 20:12:40 +05:30
|
|
|
${hasmailfail} || opts="${opts} maxfail 0"
|
|
|
|
${haspersist} || opts="${opts} persist"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Set linkname because we need /var/run/ppp-${linkname}.pid
|
2007-04-18 19:51:25 +05:30
|
|
|
# This pidfile has the advantage of being there,
|
|
|
|
# even if ${IFACE} interface was never started
|
2007-04-05 16:48:42 +05:30
|
|
|
opts="linkname ${IFACE} ${opts}"
|
|
|
|
|
|
|
|
# Setup auth info
|
|
|
|
if [ -n "${username}" ] ; then
|
2007-04-18 20:12:40 +05:30
|
|
|
opts="user '${username}' remotename ${IFACE} ${opts}"
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
# Load a custom interface configuration file if it exists
|
|
|
|
[ -f "/etc/ppp/options.${IFACE}" ] \
|
|
|
|
&& opts="${opts} file /etc/ppp/options.${IFACE}"
|
|
|
|
|
|
|
|
# Set unit
|
|
|
|
opts="unit ${unit} ${opts}"
|
|
|
|
|
|
|
|
# Setup connect script
|
|
|
|
local chatopts="/usr/sbin/chat -e -E -v"
|
|
|
|
eval $(_get_array "phone_number_${IFVAR}")
|
|
|
|
[ -n "$1" ] && chatopts="${chatopts} -T '$1'"
|
|
|
|
[ -n "$2" ] && chatopts="${chatopts} -U '$2'"
|
|
|
|
eval $(_get_array "chat_${IFVAR}")
|
|
|
|
if [ -n "$@" ] ; then
|
|
|
|
opts="${opts} connect $(printf "'%s' " "${chatopts} $(printf "'%s' " "$@")")"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Add plugins
|
|
|
|
local haspppoa=false haspppoe=false
|
|
|
|
eval $(_get_array "plugins_${IFVAR}")
|
|
|
|
for i in "$@" ; do
|
|
|
|
set -- ${i}
|
2007-04-18 19:51:25 +05:30
|
|
|
case "$1" in
|
2007-04-05 16:48:42 +05:30
|
|
|
passwordfd) continue;;
|
2007-04-18 19:53:50 +05:30
|
|
|
pppoa) shift; set -- "pppoatm" "$@" ;;
|
|
|
|
pppoe) shift; set -- "rp-pppoe" "$@" ;;
|
2007-04-05 16:48:42 +05:30
|
|
|
capi) shift; set -- "capiplugin" "$@" ;;
|
|
|
|
esac
|
2007-04-18 19:51:25 +05:30
|
|
|
case "$1" in
|
2007-04-05 16:48:42 +05:30
|
|
|
rp-pppoe) haspppoe=true ;;
|
|
|
|
pppoatm) haspppoa=true ;;
|
|
|
|
esac
|
|
|
|
if [ "$1" = "rp-pppoe" ] || [ "$1" = "pppoatm" -a "${link}" != "/dev/null" ] ; then
|
|
|
|
opts="${opts} connect true"
|
|
|
|
set -- "$@" "${link}"
|
|
|
|
fi
|
|
|
|
opts="${opts} plugin $1.so"
|
|
|
|
shift
|
|
|
|
opts="${opts} $@"
|
|
|
|
done
|
|
|
|
|
|
|
|
#Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi)
|
|
|
|
local insert_link_in_opts=1
|
|
|
|
if ${haspppoe} ; then
|
|
|
|
if [ ! -e /proc/net/pppoe ] ; then
|
|
|
|
# Load the PPPoE kernel module
|
|
|
|
if ! modprobe pppoe ; then
|
|
|
|
eerror "kernel does not support PPPoE"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure that the link exists and is up
|
|
|
|
( IFACE="${link}" ; _exists true && _up ) || return 1
|
|
|
|
insert_link_in_opts=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ${haspppoa} ; then
|
|
|
|
if [ ! -d /proc/net/atm ] ; then
|
|
|
|
# Load the PPPoA kernel module
|
|
|
|
if ! modprobe pppoatm ; then
|
|
|
|
eerror "kernel does not support PPPoATM"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${link}" != "/dev/null" ] ; then
|
|
|
|
insert_link_in_opts=0
|
|
|
|
else
|
|
|
|
ewarn "WARNING: An [itf.]vpi.vci ATM address was expected in link_${IFVAR}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
2007-04-18 19:51:25 +05:30
|
|
|
[ "${insert_link_in_opts}" = "0" ] || opts="${link} ${opts}"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
ebegin "Starting pppd in ${IFACE}"
|
|
|
|
mark_service_inactive "${SVCNAME}"
|
|
|
|
if [ -n "${username}" ] \
|
|
|
|
&& [ -n "${password}" -o -z "${passwordset}" ] ; then
|
2007-04-19 17:39:19 +05:30
|
|
|
printf "%s" "${password}" | \
|
2007-04-05 16:48:42 +05:30
|
|
|
eval start-stop-daemon --start --exec /usr/sbin/pppd \
|
|
|
|
--pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null
|
|
|
|
else
|
|
|
|
eval start-stop-daemon --start --exec /usr/sbin/pppd \
|
|
|
|
--pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null
|
|
|
|
fi
|
|
|
|
|
2007-04-18 19:51:25 +05:30
|
|
|
if ! eend $? "Failed to start PPP" ; then
|
|
|
|
mark_service_starting "net.${IFACE}"
|
2007-04-05 16:48:42 +05:30
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ${hasupdetach} ; then
|
|
|
|
_show_address
|
|
|
|
else
|
|
|
|
einfo "Backgrounding ..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# pppd will re-call us when we bring the interface up
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2007-04-19 16:22:37 +05:30
|
|
|
# Dummy function for users that still have config_ppp0="ppp"
|
|
|
|
pppd_start() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
pppd_stop() {
|
|
|
|
${IN_BACKGROUND} && return 0
|
|
|
|
local pidfile="/var/run/ppp-${IFACE}.pid"
|
|
|
|
|
|
|
|
[ ! -s "${pidfile}" ] && return 0
|
|
|
|
|
|
|
|
# Give pppd at least 30 seconds do die, #147490
|
|
|
|
einfo "Stopping pppd on ${IFACE}"
|
|
|
|
start-stop-daemon --stop --quiet --exec /usr/sbin/pppd \
|
|
|
|
--pidfile "${pidfile}" --retry 30
|
|
|
|
eend $?
|
|
|
|
}
|
|
|
|
|
|
|
|
# vim: set ts=4 :
|