| 1 |
# Copyright 2005-2007 Gentoo Foundation |
| 2 |
# Distributed under the terms of the GNU General Public License v2 |
| 3 |
|
| 4 |
pppd_depend() { |
| 5 |
program /usr/sbin/pppd |
| 6 |
after interface |
| 7 |
before dhcp |
| 8 |
provide ppp |
| 9 |
} |
| 10 |
|
| 11 |
is_ppp() { |
| 12 |
[ -e /var/run/ppp-"${IFACE}".pid ] |
| 13 |
} |
| 14 |
|
| 15 |
requote() { |
| 16 |
printf "'%s' " "$@" |
| 17 |
} |
| 18 |
|
| 19 |
pppd_start() { |
| 20 |
${IN_BACKGROUND} && return 0 |
| 21 |
|
| 22 |
if [ "${iface%%[0-9]*}" != "ppp" ] ; then |
| 23 |
eerror "PPP can only be invoked from net.ppp[0-9]" |
| 24 |
return 1 |
| 25 |
fi |
| 26 |
|
| 27 |
local link= i= opts= unit="${IFACE#ppp}" mtu= |
| 28 |
if [ -z "${unit}" ] ; then |
| 29 |
eerror $"PPP requires a unit - use net.ppp[0-9] instead of net.ppp" |
| 30 |
return 1 |
| 31 |
fi |
| 32 |
|
| 33 |
# PPP requires a link to communicate over - normally a serial port |
| 34 |
# PPPoE communicates over Ethernet |
| 35 |
# PPPoA communicates over ATM |
| 36 |
# In all cases, the link needs to be available before we start PPP |
| 37 |
eval link=\$link_${IFVAR} |
| 38 |
if [ -z "${link}" ] ; then |
| 39 |
eerror "link_${IFVAR} has not been set in /etc/conf.d/net" |
| 40 |
return 1 |
| 41 |
fi |
| 42 |
|
| 43 |
case "${link}" in |
| 44 |
/*) |
| 45 |
if [ ! -e "${link}" ] ; then |
| 46 |
eerror "${link} does not exist" |
| 47 |
eerror "Please verify hardware or kernel module (driver)" |
| 48 |
return 1 |
| 49 |
fi |
| 50 |
;; |
| 51 |
esac |
| 52 |
|
| 53 |
eval $(_get_array "pppd_${IFVAR}") |
| 54 |
opts="$@" |
| 55 |
|
| 56 |
# We don't work with these options set by the user |
| 57 |
for i in "$@" ; do |
| 58 |
set -- ${i} |
| 59 |
case "$1" in |
| 60 |
unit|nodetach|linkname) |
| 61 |
eerror "The option \"$1\" is not allowed in pppd_${IFVAR}" |
| 62 |
return 1 |
| 63 |
;; |
| 64 |
esac |
| 65 |
done |
| 66 |
|
| 67 |
# Might be set in conf.d/net |
| 68 |
local username= password= passwordset= |
| 69 |
eval username=\$username_${IFVAR} |
| 70 |
eval password=\$password_${IFVAR} |
| 71 |
eval passwordset=\${password_${IFVAR}-x} |
| 72 |
if [ -n "${username}" ] \ |
| 73 |
&& [ -n "${password}" -o -z "${passwordset}" ] ; then |
| 74 |
opts="${opts} plugin passwordfd.so passwordfd 0" |
| 75 |
fi |
| 76 |
|
| 77 |
# Check for mtu/mru |
| 78 |
local mtu= hasmtu=false hasmru=false hasmaxfail=false haspersits=false |
| 79 |
loal hasupdetach=false |
| 80 |
eval mtu=\$mtu_${IFVAR} |
| 81 |
for i in ${opts} ; do |
| 82 |
case "${i}" in |
| 83 |
mtu" "*) hasmtu=true ;; |
| 84 |
mru" "*) hasmru=true ;; |
| 85 |
maxfail" "*) hasmaxfail=true ;; |
| 86 |
persist) haspersist=true ;; |
| 87 |
updetach) hasupdetach=true; |
| 88 |
esac |
| 89 |
done |
| 90 |
! ${hasmtu} && opts="${opts} mtu ${mtu}" |
| 91 |
! ${hasmru} && opts="${opts} mru ${mtu}" |
| 92 |
! ${hasmailfail} && opts="${opts} maxfail 0" |
| 93 |
! ${haspersist} && opts="${opts} persist" |
| 94 |
|
| 95 |
# Set linkname because we need /var/run/ppp-${linkname}.pid |
| 96 |
# This pidfile has the advantage of being there, even if ${iface} interface was never started |
| 97 |
opts="linkname ${IFACE} ${opts}" |
| 98 |
|
| 99 |
# Setup auth info |
| 100 |
if [ -n "${username}" ] ; then |
| 101 |
opts="user '"${username}"' remotename ${IFACE} ${opts}" |
| 102 |
fi |
| 103 |
|
| 104 |
# Load a custom interface configuration file if it exists |
| 105 |
[ -f "/etc/ppp/options.${IFACE}" ] \ |
| 106 |
&& opts="${opts} file /etc/ppp/options.${IFACE}" |
| 107 |
|
| 108 |
# Set unit |
| 109 |
opts="unit ${unit} ${opts}" |
| 110 |
|
| 111 |
# Setup connect script |
| 112 |
local chatopts="/usr/sbin/chat -e -E -v" |
| 113 |
eval $(_get_array "phone_number_${IFVAR}") |
| 114 |
[ -n "$1" ] && chatopts="${chatopts} -T '$1'" |
| 115 |
[ -n "$2" ] && chatopts="${chatopts} -U '$2'" |
| 116 |
eval $(_get_array "chat_${IFVAR}") |
| 117 |
if [ -n "$@" ] ; then |
| 118 |
opts="${opts} connect $(printf "'%s' " "${chatopts} $(printf "'%s' " "$@")")" |
| 119 |
fi |
| 120 |
|
| 121 |
# Add plugins |
| 122 |
local haspppoa=false haspppoe=false |
| 123 |
eval $(_get_array "plugins_${IFVAR}") |
| 124 |
for i in "$@" ; do |
| 125 |
set -- ${i} |
| 126 |
case "${i}" in |
| 127 |
passwordfd) continue;; |
| 128 |
pppoa) shift; set -- "rp-pppoe" "$@" ;; |
| 129 |
pppoe) shift; set -- "pppoatm" "$@" ;; |
| 130 |
capi) shift; set -- "capiplugin" "$@" ;; |
| 131 |
esac |
| 132 |
case "${i}" in |
| 133 |
rp-pppoe) haspppoe=true ;; |
| 134 |
pppoatm) haspppoa=true ;; |
| 135 |
esac |
| 136 |
if [ "$1" = "rp-pppoe" ] || [ "$1" = "pppoatm" -a "${link}" != "/dev/null" ] ; then |
| 137 |
opts="${opts} connect true" |
| 138 |
set -- "$@" "${link}" |
| 139 |
fi |
| 140 |
opts="${opts} plugin $1.so" |
| 141 |
shift |
| 142 |
opts="${opts} $@" |
| 143 |
done |
| 144 |
|
| 145 |
#Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi) |
| 146 |
local insert_link_in_opts=1 |
| 147 |
if ${haspppoe} ; then |
| 148 |
if [ ! -e /proc/net/pppoe ] ; then |
| 149 |
# Load the PPPoE kernel module |
| 150 |
if ! modprobe pppoe ; then |
| 151 |
eerror "kernel does not support PPPoE" |
| 152 |
return 1 |
| 153 |
fi |
| 154 |
fi |
| 155 |
|
| 156 |
# Ensure that the link exists and is up |
| 157 |
( IFACE="${link}" ; _exists true && _up ) || return 1 |
| 158 |
insert_link_in_opts=0 |
| 159 |
fi |
| 160 |
|
| 161 |
if ${haspppoa} ; then |
| 162 |
if [ ! -d /proc/net/atm ] ; then |
| 163 |
# Load the PPPoA kernel module |
| 164 |
if ! modprobe pppoatm ; then |
| 165 |
eerror "kernel does not support PPPoATM" |
| 166 |
return 1 |
| 167 |
fi |
| 168 |
fi |
| 169 |
|
| 170 |
if [ "${link}" != "/dev/null" ] ; then |
| 171 |
insert_link_in_opts=0 |
| 172 |
else |
| 173 |
ewarn "WARNING: An [itf.]vpi.vci ATM address was expected in link_${IFVAR}" |
| 174 |
fi |
| 175 |
|
| 176 |
fi |
| 177 |
[ "${insert_link_in_opts}" == "0" ] || opts="${link} ${opts}" |
| 178 |
|
| 179 |
ebegin "Starting pppd in ${IFACE}" |
| 180 |
mark_service_inactive "${SVCNAME}" |
| 181 |
if [ -n "${username}" ] \ |
| 182 |
&& [ -n "${password}" -o -z "${passwordset}" ] ; then |
| 183 |
echo "${password}" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' | \ |
| 184 |
eval start-stop-daemon --start --exec /usr/sbin/pppd \ |
| 185 |
--pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null |
| 186 |
else |
| 187 |
eval start-stop-daemon --start --exec /usr/sbin/pppd \ |
| 188 |
--pidfile "/var/run/ppp-${IFACE}.pid" -- "${opts}" >/dev/null |
| 189 |
fi |
| 190 |
|
| 191 |
if ! eend $? $"Failed to start PPP" ; then |
| 192 |
mark_service_starting "net.${iface}" |
| 193 |
return 1 |
| 194 |
fi |
| 195 |
|
| 196 |
if ${hasupdetach} ; then |
| 197 |
_show_address |
| 198 |
else |
| 199 |
einfo "Backgrounding ..." |
| 200 |
fi |
| 201 |
|
| 202 |
# pppd will re-call us when we bring the interface up |
| 203 |
exit 0 |
| 204 |
} |
| 205 |
|
| 206 |
pppd_stop() { |
| 207 |
${IN_BACKGROUND} && return 0 |
| 208 |
local pidfile="/var/run/ppp-${IFACE}.pid" |
| 209 |
|
| 210 |
[ ! -s "${pidfile}" ] && return 0 |
| 211 |
|
| 212 |
# Give pppd at least 30 seconds do die, #147490 |
| 213 |
einfo "Stopping pppd on ${IFACE}" |
| 214 |
start-stop-daemon --stop --quiet --exec /usr/sbin/pppd \ |
| 215 |
--pidfile "${pidfile}" --retry 30 |
| 216 |
eend $? |
| 217 |
} |
| 218 |
|
| 219 |
# vim: set ts=4 : |