2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2005-2007 Gentoo Foundation
|
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2011-06-30 05:16:31 +05:30
|
|
|
# Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
pppd_depend()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
program /usr/sbin/pppd
|
|
|
|
after interface
|
|
|
|
before dhcp
|
|
|
|
provide ppp
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
is_ppp()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
[ -e /var/run/ppp-"${IFACE}".pid ]
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
requote()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
printf "'%s' " "$@"
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
pppd_pre_start()
|
|
|
|
{
|
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
|
|
|
|
2007-08-08 02:31:16 +05:30
|
|
|
# Set our base metric
|
|
|
|
metric=4000
|
|
|
|
|
2007-11-22 18:58:14 +05:30
|
|
|
if yesno ${IN_BACKGROUND}; then
|
2007-04-19 18:30:59 +05:30
|
|
|
local config=
|
|
|
|
eval config=\$config_${IFVAR}
|
2011-01-17 15:19:07 +05:30
|
|
|
# If no config for ppp then don't default to DHCP
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -z "${config}" ]; then
|
2007-08-08 01:53:38 +05:30
|
|
|
eval config_${IFVAR}=null
|
2007-04-19 18:30:59 +05:30
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2007-11-02 16:32:07 +05:30
|
|
|
local link= i= unit="${IFACE#ppp}" opts=
|
2011-01-17 15:19:07 +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
|
|
|
|
/*)
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ ! -e "${link}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "${link} does not exist"
|
|
|
|
eerror "Please verify hardware or kernel module (driver)"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -z "${unit}" ]; then
|
2007-04-19 16:22:37 +05:30
|
|
|
eerror "PPP requires a unit - use net.ppp[0-9] instead of net.ppp"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2007-11-02 16:32:07 +05:30
|
|
|
# We need to flatten the useless array
|
|
|
|
set -- $(_get_array "pppd_${IFVAR}")
|
|
|
|
opts="$@"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
2007-08-08 01:53:38 +05:30
|
|
|
local mtu= hasmtu=false hasmru=false hasmaxfail=false haspersist=false
|
2007-08-08 02:21:08 +05:30
|
|
|
local hasupdetach=false hasdefaultmetric=false
|
2007-10-29 15:15:49 +05:30
|
|
|
for i in ${opts}; do
|
|
|
|
case "${i}" in
|
2007-04-05 16:48:42 +05:30
|
|
|
unit|nodetach|linkname)
|
2007-10-29 15:15:49 +05:30
|
|
|
eerror "The option \"${i}\" is not allowed in pppd_${IFVAR}"
|
2007-04-05 16:48:42 +05:30
|
|
|
return 1
|
|
|
|
;;
|
2007-11-28 21:15:03 +05:30
|
|
|
defaultmetric) hasdefaultmetric=true;;
|
|
|
|
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}
|
2007-08-08 01:53:38 +05:30
|
|
|
eval passwordset=\$\{password_${IFVAR}-x\}
|
2007-04-05 16:48:42 +05:30
|
|
|
if [ -n "${username}" ] \
|
2007-11-28 21:15:03 +05:30
|
|
|
&& [ -n "${password}" -o -z "${passwordset}" ]; then
|
2009-11-05 01:10:52 +05:30
|
|
|
opts="plugin passwordfd.so ${opts} passwordfd 0"
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if ! ${hasdefaultmetric}; then
|
2007-08-21 13:51:40 +05:30
|
|
|
local m=
|
|
|
|
eval m=\$metric_${IFVAR}
|
2011-11-11 08:16:08 +05:30
|
|
|
[ -z "${m}" ] && : $(( m = metric + $(_ifindex) ))
|
2007-08-08 02:31:16 +05:30
|
|
|
opts="${opts} defaultmetric ${m}"
|
2007-08-08 02:21:08 +05:30
|
|
|
fi
|
2007-11-28 21:15:03 +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-08-08 01:53:38 +05:30
|
|
|
${hasmaxfail} || opts="${opts} maxfail 0"
|
2007-04-18 20:12:40 +05:30
|
|
|
${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
|
2007-11-28 21:15:03 +05:30
|
|
|
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}" ] \
|
2007-10-29 15:15:49 +05:30
|
|
|
&& opts="${opts} file '/etc/ppp/options.${IFACE}'"
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# Set unit
|
|
|
|
opts="unit ${unit} ${opts}"
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
# Setup connect script
|
2007-11-02 16:32:07 +05:30
|
|
|
local chatprog="/usr/sbin/chat -e -E -v" phone=
|
2007-10-29 15:15:49 +05:30
|
|
|
eval phone=\$phone_number_${IFVAR}
|
|
|
|
set -- ${phone}
|
2007-11-02 16:32:07 +05:30
|
|
|
[ -n "$1" ] && chatprog="${chatprog} -T '$1'"
|
|
|
|
[ -n "$2" ] && chatprog="${chatprog} -U '$2'"
|
|
|
|
# We need to flatten the useless array
|
|
|
|
set -- $(_get_array "chat_${IFVAR}")
|
|
|
|
if [ $# != 0 ]; then
|
|
|
|
opts="${opts} connect '$(echo ${chatprog} $@ | sed -e "s:':'\\\\'':g")'"
|
2007-04-05 16:48:42 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
# Add plugins
|
2007-10-29 15:15:49 +05:30
|
|
|
local haspppoa=false haspppoe=false plugins="$(_get_array "plugins_${IFVAR}")"
|
2007-10-30 17:08:23 +05:30
|
|
|
local IFS="$__IFS"
|
2007-10-29 15:15:49 +05:30
|
|
|
for i in ${plugins}; do
|
|
|
|
unset IFS
|
2007-04-05 16:48:42 +05:30
|
|
|
set -- ${i}
|
2007-04-18 19:51:25 +05:30
|
|
|
case "$1" in
|
2007-04-05 16:48:42 +05:30
|
|
|
passwordfd) continue;;
|
2007-11-28 21:15:03 +05:30
|
|
|
pppoa) shift; set -- "pppoatm" "$@";;
|
|
|
|
pppoe) shift; set -- "rp-pppoe" "$@";;
|
|
|
|
capi) shift; set -- "capiplugin" "$@";;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
2007-04-18 19:51:25 +05:30
|
|
|
case "$1" in
|
2007-11-28 21:15:03 +05:30
|
|
|
rp-pppoe) haspppoe=true;;
|
|
|
|
pppoatm) haspppoa=true;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ "$1" = "rp-pppoe" ] || [ "$1" = "pppoatm" -a "${link}" != "/dev/null" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
opts="${opts} connect true"
|
|
|
|
set -- "$@" "${link}"
|
|
|
|
fi
|
2009-11-05 01:10:52 +05:30
|
|
|
opts="plugin $1.so ${opts}"
|
2007-04-05 16:48:42 +05:30
|
|
|
shift
|
|
|
|
opts="${opts} $@"
|
|
|
|
done
|
2007-10-29 15:15:49 +05:30
|
|
|
unset IFS
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
#Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi)
|
|
|
|
local insert_link_in_opts=1
|
2007-11-28 21:15:03 +05:30
|
|
|
if ${haspppoe}; then
|
|
|
|
if [ ! -e /proc/net/pppoe ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
# Load the PPPoE kernel module
|
2007-11-28 21:15:03 +05:30
|
|
|
if ! modprobe pppoe; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "kernel does not support PPPoE"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure that the link exists and is up
|
2007-11-28 21:15:03 +05:30
|
|
|
( IFACE="${link}"; _exists true && _up ) || return 1
|
2007-04-05 16:48:42 +05:30
|
|
|
insert_link_in_opts=0
|
|
|
|
fi
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if ${haspppoa}; then
|
|
|
|
if [ ! -d /proc/net/atm ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
# Load the PPPoA kernel module
|
2007-11-28 21:15:03 +05:30
|
|
|
if ! modprobe pppoatm; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "kernel does not support PPPoATM"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ "${link}" != "/dev/null" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
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}"
|
2007-12-18 23:29:29 +05:30
|
|
|
mark_service_inactive
|
2007-04-05 16:48:42 +05:30
|
|
|
if [ -n "${username}" ] \
|
2007-11-28 21:15:03 +05:30
|
|
|
&& [ -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-11-28 21:15:03 +05:30
|
|
|
if ! eend $? "Failed to start PPP"; then
|
2007-12-18 23:29:29 +05:30
|
|
|
mark_service_stopped
|
2007-04-05 16:48:42 +05:30
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2007-11-28 21:15:03 +05:30
|
|
|
if ${hasupdetach}; then
|
2007-04-05 16:48:42 +05:30
|
|
|
_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"
|
2008-01-11 20:38:57 +05:30
|
|
|
pppd_start()
|
|
|
|
{
|
2007-04-19 16:22:37 +05:30
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
pppd_stop()
|
|
|
|
{
|
2007-11-22 18:58:14 +05:30
|
|
|
yesno ${IN_BACKGROUND} && return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
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 $?
|
|
|
|
}
|