/[vps]/baselayout-vserver/trunk/net-scripts/net.modules.d/pppd
Gentoo

Diff of /baselayout-vserver/trunk/net-scripts/net.modules.d/pppd

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 235 Revision 236
13 13
14# bool pppd_check_installed(void) 14# bool pppd_check_installed(void)
15# 15#
16# Returns 1 if pppd is installed, otherwise 0 16# Returns 1 if pppd is installed, otherwise 0
17pppd_check_installed() { 17pppd_check_installed() {
18 if [[ ! -x /usr/sbin/pppd ]]; then 18 if [[ ! -x /usr/sbin/pppd ]] ; then
19 ${1:-false} && eerror "For PPP support, emerge net-dialup/ppp" 19 ${1:-false} && eerror "For PPP support, emerge net-dialup/ppp"
20 return 1 20 return 1
21 fi 21 fi
22 return 0 22 return 0
23} 23}
54# char* remotename, char* password) 54# char* remotename, char* password)
55# 55#
56# Add/update PAP/CHAP authentication information 56# Add/update PAP/CHAP authentication information
57pppd_update_secrets_file() { 57pppd_update_secrets_file() {
58 local filepath="$1" username="$2" remotename="$3" password="$4" 58 local filepath="$1" username="$2" remotename="$3" password="$4"
59 if [[ ! -s ${filepath} ]]; then 59 if [[ ! -s ${filepath} ]] ; then
60 echo '#'client$'\t'server$'\t'secret$'\t'IP addresses > "${filepath}" \ 60 echo '#'client$'\t'server$'\t'secret$'\t'IP addresses > "${filepath}" \
61 && chmod 0600 "${filepath}" \ 61 && chmod 0600 "${filepath}" \
62 || return 1 62 || return 1
63 fi 63 fi
64 64
75 {s/^${regex_filter}(\".*\")[ \t]*\$/\1/;q;};\ 75 {s/^${regex_filter}(\".*\")[ \t]*\$/\1/;q;};\
76 d;" \ 76 d;" \
77 ${filepath} 77 ${filepath}
78 ) 78 )
79 79
80 if [[ -z "${old_password}" ]]; then 80 if [[ -z "${old_password}" ]] ; then
81 regex_username="${username//\\/\\\\}" 81 regex_username="${username//\\/\\\\}"
82 regex_remotename="${remotename//\\/\\\\}" 82 regex_remotename="${remotename//\\/\\\\}"
83 regex_password="${password//\\/\\\\}" 83 regex_password="${password//\\/\\\\}"
84 regex_password=${password//"/\\\\"} 84 regex_password=${password//"/\\\\"}
85 sed -r -i -e "\$a\"${regex_username}\" ${regex_remotename} \"${regex_password}\"" ${filepath} 85 sed -r -i -e "\$a\"${regex_username}\" ${regex_remotename} \"${regex_password}\"" ${filepath}
86 vewarn "Authentication info has been added to ${filepath}" 86 vewarn "Authentication info has been added to ${filepath}"
87 elif [[ "\"${password//\"/\\\"}\"" != "${old_password}" ]]; then 87 elif [[ "\"${password//\"/\\\"}\"" != "${old_password}" ]] ; then
88 regex_password="${password//\\/\\\\}" 88 regex_password="${password//\\/\\\\}"
89 regex_password="${regex_password//\//\\/}" 89 regex_password="${regex_password//\//\\/}"
90 regex_password="${regex_password//&/\\&}" 90 regex_password="${regex_password//&/\\&}"
91 regex_password=${regex_password//\"/\\\\\"} 91 regex_password=${regex_password//\"/\\\\\"}
92 sed -r -i -e "s/^(${regex_filter}\").*(\"[ \t]*)\$/\1${regex_password}\2/" ${filepath} 92 sed -r -i -e "s/^(${regex_filter}\").*(\"[ \t]*)\$/\1${regex_password}\2/" ${filepath}
102# Returns 0 (true) when successful, otherwise 1 102# Returns 0 (true) when successful, otherwise 1
103pppd_start() { 103pppd_start() {
104 ${IN_BACKGROUND} && return 0 104 ${IN_BACKGROUND} && return 0
105 105
106 local iface="$1" ifvar=$( bash_variable "$1" ) opts="" link 106 local iface="$1" ifvar=$( bash_variable "$1" ) opts="" link
107 if [[ ${iface%%[0-9]*} != "ppp" ]]; then 107 if [[ ${iface%%[0-9]*} != "ppp" ]] ; then
108 eerror "PPP can only be invoked from net.ppp[0-9]" 108 eerror "PPP can only be invoked from net.ppp[0-9]"
109 return 1 109 return 1
110 fi 110 fi
111 111
112 local unit="${iface#ppp}" 112 local unit="${iface#ppp}"
118 # PPP requires a link to communicate over - normally a serial port 118 # PPP requires a link to communicate over - normally a serial port
119 # PPPoE communicates over Ethernet 119 # PPPoE communicates over Ethernet
120 # PPPoA communicates over ATM 120 # PPPoA communicates over ATM
121 # In all cases, the link needs to be available before we start PPP 121 # In all cases, the link needs to be available before we start PPP
122 link="link_${ifvar}" 122 link="link_${ifvar}"
123 if [[ -z ${!link} ]]; then 123 if [[ -z ${!link} ]] ; then
124 eerror "${link} has not been set in /etc/conf.d/net" 124 eerror "${link} has not been set in /etc/conf.d/net"
125 return 1 125 return 1
126 fi 126 fi
127 127
128 # Might or might not be set in conf.d/net 128 # Might or might not be set in conf.d/net
129 local user password i 129 local user password i
130 username="username_${ifvar}" 130 username="username_${ifvar}"
131 password="password_${ifvar}" 131 password="password_${ifvar}"
132 132
133 #Add/update info in PAP/CHAP secrets files 133 #Add/update info in PAP/CHAP secrets files
134 if [[ -n ${!username} && -n ${!password} ]]; then 134 if [[ -n ${!username} && -n ${!password} ]] ; then
135 for i in chap pap ; do 135 for i in chap pap ; do
136 if ! pppd_update_secrets_file "/etc/ppp/${i}-secrets" \ 136 if ! pppd_update_secrets_file "/etc/ppp/${i}-secrets" \
137 "${!username}" "${iface}" "${!password}" ; then 137 "${!username}" "${iface}" "${!password}" ; then
138 eerror "Failed to update /etc/ppp/${i}-secrets" 138 eerror "Failed to update /etc/ppp/${i}-secrets"
139 return 1 139 return 1
144 # Load any commandline options 144 # Load any commandline options
145 opts="pppd_${ifvar}[@]" 145 opts="pppd_${ifvar}[@]"
146 opts="${!opts}" 146 opts="${!opts}"
147 147
148 # We don't work with these options set by the user 148 # We don't work with these options set by the user
149 for i in unit nodetach linkname maxfail persist ; do 149 for i in unit nodetach linkname ; do
150 if [[ " ${opts} " == *" ${i} "* ]]; then 150 if [[ " ${opts} " == *" ${i} "* ]] ; then
151 eerror "The option \"${i}\" is not allowed" 151 eerror "The option \"${i}\" is not allowed in pppd_${ifvar}"
152 return 1 152 return 1
153 fi 153 fi
154 done 154 done
155 155
156 # Check for mtu/mru 156 # Check for mtu/mru
157 local mtu="mtu_${ifvar}" 157 local mtu="mtu_${ifvar}"
158 if [[ -n ${!mtu} ]]; then 158 if [[ -n ${!mtu} ]] ; then
159 [[ " ${opts} " != *" mtu "* ]] && opts="${opts} mtu ${!mtu}" 159 [[ " ${opts} " != *" mtu "* ]] && opts="${opts} mtu ${!mtu}"
160 [[ " ${opts} " != *" mru "* ]] && opts="${opts} mru ${!mtu}" 160 [[ " ${opts} " != *" mru "* ]] && opts="${opts} mru ${!mtu}"
161 fi 161 fi
162 162
163 # Set linkname because we need /var/run/ppp-${linkname}.pid 163 # Set linkname because we need /var/run/ppp-${linkname}.pid
170 170
171 # Load a custom interface configuration file if it exists 171 # Load a custom interface configuration file if it exists
172 [[ -f "/etc/ppp/options.${iface}" ]] \ 172 [[ -f "/etc/ppp/options.${iface}" ]] \
173 && opts="${opts} file /etc/ppp/options.${iface}" 173 && opts="${opts} file /etc/ppp/options.${iface}"
174 174
175 # Set forced options 175 # Set unit
176 opts="unit ${unit} persist maxfail 0 ${opts}" 176 opts="unit ${unit} ${opts}"
177 177
178 # Default maxfail to 0 unless specified
179 [[ " ${opts} " != *" maxfail "* ]] && opts="${opts} maxfail 0"
180
181 # Append persist
182 [[ " ${opts} " != *" persist "* ]] && opts="${opts} persist"
183
178 # Setup connect script 184 # Setup connect script
179 local chat="chat_${ifvar}[@]" 185 local chat="chat_${ifvar}[@]"
180 if [[ -n "${!chat}" ]]; then 186 if [[ -n "${!chat}" ]] ; then
181 opts="${opts} connect \"/usr/sbin/chat -e -E -v" 187 local chatopts="/usr/sbin/chat -e -E -v"
182
183 local -a phone_number="phone_number_${ifvar}[@]" 188 local -a phone_number="phone_number_${ifvar}[@]"
184 phone_number=( "${!phone_number}" ) 189 phone_number=( "${!phone_number}" )
185 if [[ ${#phone_number[@]} -ge 1 ]]; then 190 if [[ ${#phone_number[@]} -ge 1 ]] ; then
186 opts="${opts} -T '${phone_number[0]}'" 191 chatopts="${chatopts} -T '${phone_number[0]}'"
187 if [[ ${#phone_number[@]} -ge 2 ]]; then 192 if [[ ${#phone_number[@]} -ge 2 ]] ; then
188 opts="${opts} -U '${phone_number[1]}'" 193 chatopts="${chatopts} -U '${phone_number[1]}'"
189 fi
190 fi 194 fi
191 195 fi
192 for i in "${!chat}"; do 196 opts="${opts} connect $(requote "${chatopts} $(requote "${!chat}")")"
193 opts="${opts} '${i}'"
194 done
195
196 opts="${opts}\""
197 fi 197 fi
198 198
199 # Add plugins 199 # Add plugins
200 local plugins="plugins_${ifvar}[@]" 200 local plugins="plugins_${ifvar}[@]"
201 for i in "${!plugins}" ; do 201 for i in "${!plugins}" ; do
210 [[ ${plugin[0]} == "rp-pppoe" ]] && opts="${opts} ${!link}" 210 [[ ${plugin[0]} == "rp-pppoe" ]] && opts="${opts} ${!link}"
211 done 211 done
212 212
213 #Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi) 213 #Specialized stuff. Insert here actions particular to connection type (pppoe,pppoa,capi)
214 local insert_link_in_opts=1 214 local insert_link_in_opts=1
215 if [[ " ${opts} " == *" plugin rp-pppoe.so "* ]]; then 215 if [[ " ${opts} " == *" plugin rp-pppoe.so "* ]] ; then
216 if [[ ! -e /proc/net/pppoe ]]; then 216 if [[ ! -e /proc/net/pppoe ]] ; then
217 # Load the PPPoE kernel module 217 # Load the PPPoE kernel module
218 if ! modprobe pppoe ; then 218 if ! modprobe pppoe ; then
219 eerror "kernel does not support PPPoE" 219 eerror "kernel does not support PPPoE"
220 return 1 220 return 1
221 fi 221 fi
226 interface_up "${!link}" 226 interface_up "${!link}"
227 227
228 insert_link_in_opts=0 228 insert_link_in_opts=0
229 fi 229 fi
230 230
231 if [[ " ${opts} " == *" plugin pppoatm.so "* ]]; then 231 if [[ " ${opts} " == *" plugin pppoatm.so "* ]] ; then
232 if [[ ! -d /proc/net/atm ]]; then 232 if [[ ! -d /proc/net/atm ]] ; then
233 # Load the PPPoA kernel module 233 # Load the PPPoA kernel module
234 if ! modprobe pppoatm ; then 234 if ! modprobe pppoatm ; then
235 eerror "kernel does not support PPPoATM" 235 eerror "kernel does not support PPPoATM"
236 return 1 236 return 1
237 fi 237 fi
241 241
242 ebegin "Running pppd" 242 ebegin "Running pppd"
243 [[ " ${opts} " != *" updetach "* ]] && mark_service_inactive "net.${iface}" 243 [[ " ${opts} " != *" updetach "* ]] && mark_service_inactive "net.${iface}"
244 eval start-stop-daemon --start --exec /usr/sbin/pppd \ 244 eval start-stop-daemon --start --exec /usr/sbin/pppd \
245 --pidfile "/var/run/ppp-${iface}.pid" -- "${opts}" >/dev/null 245 --pidfile "/var/run/ppp-${iface}.pid" -- "${opts}" >/dev/null
246 if [[ $? != "0" ]]; then 246 if [[ $? != "0" ]] ; then
247 eend $? "Failed to start PPP" 247 eend $? "Failed to start PPP"
248 mark_service_starting "net.${iface}" 248 mark_service_starting "net.${iface}"
249 return $? 249 return $?
250 fi 250 fi
251 251
252 if [[ " ${opts} " == *" updetach "* ]]; then 252 if [[ " ${opts} " == *" updetach "* ]] ; then
253 local addr=$( interface_get_address "${iface}" ) 253 local addr=$( interface_get_address "${iface}" )
254 einfo "${iface} received address ${addr}" 254 einfo "${iface} received address ${addr}"
255 else 255 else
256 einfo "Backgrounding ..." 256 einfo "Backgrounding ..."
257 exit 0 257 exit 0

Legend:
Removed from v.235  
changed lines
  Added in v.236

  ViewVC Help
Powered by ViewVC 1.1.20