]> git.pld-linux.org Git - projects/rc-scripts.git/blob - sysconfig/network-scripts/ifup-ppp
d0a9871bf45deba0e1971cb95082d381f1253a88
[projects/rc-scripts.git] / sysconfig / network-scripts / ifup-ppp
1 #!/bin/sh
2 #
3 #       $Id$
4 #
5 # ifup-ppp script for pppd-2.3.5 (with persist & demand options) ver 0.2
6 # Grzegorz Stanislawski <stangrze@open.net.pl>
7 # Features:
8 #  - since persist option is included to pppd it's no need to do werid loops
9 #    ifup-ppp script. This also makes your logfile grow slower when Your link
10 #    is down.
11 #  - chat-ppp? file with script for chat is now parsed by shell, so You can
12 #    include in it shell variables (for example $PHONE, $USERNAME)
13 #    You can define any variable in ifcfg-ppp? file and use it in chat-ppp?
14 #    You only have to add it's name into DATAFORCHAT variable
15 #    Note, that chat-ppp file is now parsed by shell, so you have to escape
16 #    with "\" all shell special characters like \$;:)(& etc.
17
18 PATH=/sbin:/usr/sbin:/bin:/usr/bin
19
20 # ifup-post for PPP is handled through /etc/ppp/ip-up
21
22 . /etc/sysconfig/network
23 . /etc/rc.d/init.d/functions
24 . /etc/sysconfig/network-scripts/functions.network
25
26 CONFIG=$1
27 source_config
28 # set all major variables
29 setup_ip_param
30
31 if [ "$2" = "boot" ] && is_no "${ONBOOT}"; then
32         exit
33 fi
34 if [ ! -x /usr/sbin/pppd ]; then
35         nls "%s does not exist or is not executable" "/usr/sbin/pppd"
36         nls "%s for %s exiting" "ifup-ppp" "$DEVICE"
37         logger -p daemon.info -t ifup-ppp \
38                 "$(nls '%s does not exist or is not executable for %s' \
39                 "/usr/sbin/pppd" "$DEVICE")"
40         exit 1
41 fi
42
43 # modprobe ppp modules (udev and devfsd case)
44 [ ! -e /dev/ppp ] && modprobe -s -k char-major-108
45
46 opts="lock"
47
48 if [ -z "${REPORTFILE}" ] ; then
49         REPORTFILE=/dev/null
50 fi
51
52 if [ -n "${PPPOE_DEV}" ]; then
53         if is_yes "${PPPOE_KERNEL}"; then
54                 modprobe -s -k pppoe
55                 MODEMMODE="plugin rp-pppoe.so"
56                 MODEMPORT="${PPPOE_DEV}"
57         else
58                 MODEMMODE="pty"
59                 MODEMPORT="pppoe -I ${PPPOE_DEV} ${PPPOE_OPT}"
60         fi
61 elif is_yes "${PPPOA_EAGLE}"; then
62         EAGLECTRL="/usr/sbin/adictrl"
63         if [ ! -x $EAGLECTRL ]; then
64                 EAGLECTRL="/usr/sbin/eaglectrl"
65         fi
66         if [ ! -x $EAGLECTRL ]; then
67                 nls "%s does not exist or is not executable" "$EAGLECTRL"
68                 nls "%s for %s exiting" "ifup-ppp" "$DEVICE"
69                 exit 1
70         fi
71         $EAGLECTRL -w
72         PPPOA_IFACE=$( $EAGLECTRL -i 2>/dev/null)
73         if [ -z "$PPPOA_IFACE" ]; then
74                 PPPOA_IFACE="(unknown)"
75         else
76                 ip link set "$PPPOA_IFACE" up
77         fi
78         MODEMMODE="pty"
79         MODEMPORT="pppoa -I ${PPPOA_IFACE} ${PPPOA_OPT}"
80 elif is_yes "${PPPOA_SPEEDTOUCH}"; then
81         if is_yes "${PPPOA_KERNEL}"; then
82                 modprobe -s -k speedtch
83                 modprobe -s -k pppoatm
84                 if [ -n "${PPPOA_FIRMWARE}" ]; then
85                         modem_run -k -s -f "${PPPOA_FIRMWARE}"
86                 fi
87                 MODEMMODE="plugin pppoatm.so"
88                 MODEMPORT="${PPPOA_VPI}.${PPPOA_VCI}"
89         else
90                 modem_run -s -f "${PPPOA_FIRMWARE}"
91                 MODEMMODE="pty"
92                 MODEMPORT="pppoa3 -v1 -c -vpi ${PPPOA_VPI} -vci ${PPPOA_VCI} ${PPPOA_OPT}"
93         fi
94 elif is_yes "${PPPOA}"; then
95         MODEMMODE="plugin pppoatm.so"
96         MODEMPORT="${PPPOA_VPI}.${PPPOA_VCI}"
97 else
98         if is_no "${DIRECT_CONNECT}" || [ -z "${DIRECT_CONNECT}" ]; then
99                 PEERCONF=/etc/ppp/peers/${DEVNAME}
100                 if [ ! -f ${PEERCONF} ]; then
101                         if [ -z "${WVDIALSECT}" ]; then
102                                 # XXX: REPORTFILE support is problematic here --misiek
103                                 [ -f "${CHATSCRIPT}" ] || CHATSCRIPT=/etc/sysconfig/interfaces/data/chat-${PARENTDEVNAME}
104                                 if [ ! -f "${CHATSCRIPT}" ]; then
105                                         nls '%s does not exist, perhaps set $CHATSCRIPT' "${CHATSCRIPT}"
106                                         nls 'ifup-ppp for %s exiting' "${DEVNAME}"
107                                         logger -p daemon.info -t ifup-ppp \
108                                                 "$(nls '%s does not exist for %s' "${CHATSCRIPT}" "${DEVICE}")"
109                                         exit 1
110                                 fi
111                         fi
112                         logger -s -p daemon.notice -t ifup-ppp "$(nls 'Setting up a new %s config file' "${PEERCONF}")"
113                         if [ -f /etc/ppp/peers/${DEVICE} ]; then
114                                 cp -f /etc/ppp/peers/${DEVICE} ${PEERCONF}
115                         else
116                                 touch ${PEERCONF}
117                         fi
118                         if [ "${WVDIALSECT}" ]; then
119                                 echo "connect \"/usr/bin/wvdial --chat ${WVDIALSECT} --config /etc/wvdial.conf >> ${REPORTFILE} 2>&1 \"" >> ${PEERCONF}
120                         else
121                                 if is_yes "${DEBUG}"; then
122                                         chatdbg="-v"
123                                 fi
124                                 if [ -n "${DATAFORCHAT}" ]; then
125                                         chatreadenv=-E
126                                 fi
127                                 echo "connect \"/usr/sbin/chat $chatreadenv -f ${CHATSCRIPT} -r ${REPORTFILE} ${chatdbg}\"" >> ${PEERCONF}
128                         fi
129                 fi
130                 opts="$opts call ${DEVNAME}"
131         fi
132 fi
133
134 if [ -z "$MODEMPORT" ]; then
135         echo >&2 "Missing modemport!"
136         exit 1
137 fi
138
139 if [ -z "$HOLDOFF" ]; then
140         HOLDOFF=30
141 fi
142 if is_yes "${PERSIST}"; then
143         if [ -z "${MAXFAIL}" ]; then
144                 MAXFAIL="0"
145         fi
146         opts="$opts persist holdoff $HOLDOFF maxfail $MAXFAIL"
147 fi
148 if is_yes "${DEMAND}"; then
149         if [ -z "${IDLE}" ]; then
150                 IDLE="0"
151         fi
152         opts="$opts demand ktune idle ${IDLE}"
153 fi
154 if ! is_no "${HARDFLOWCTL}"; then
155         opts="$opts crtscts"
156 fi
157 if is_yes "${MODEMCTL}"; then
158         opts="$opts modem"
159 fi
160 if is_yes "${ESCAPECHARS}"; then
161         opts="$opts asyncmap FFFFFFFF"
162 else
163         opts="$opts asyncmap 00000000"
164 fi
165 if is_yes "${DEFROUTE}"; then
166         # pppd will no longer delete an existing default route
167         # so we have to help it out a little here.
168         ip route del 0/0 > /dev/null 2>&1
169         opts="$opts defaultroute"
170 elif ! is_no "${DEFROUTE}"; then
171         opts="$opts defaultroute"
172 fi
173 if ! is_no "${PEERDNS}"; then
174         opts="$opts usepeerdns"
175 fi
176 if [ -n "${MRU}" ] ; then
177         opts="$opts mru ${MRU}"
178 fi
179 if [ -n "${MTU}" ] ; then
180         opts="$opts mtu ${MTU}"
181 fi
182 if is_yes "$IPV4_NETWORKING" && [ -n "${IP4ADDR}${REMIP}" ] ; then
183         # if either IP address is set, the following will work.
184         opts="$opts ${IP4ADDR}:${REMIP}"
185 fi
186 if is_yes "$IPV6_NETWORKING"; then
187         if is_yes "$IPV6_PPP"; then
188                 if [ -n "${IP6ADDR}${REMIP6}" ] ; then
189                         opts="$opts ipv6 ${IP6ADDR},${REMIP6}"
190                 elif is_yes "$IPV6_CP_USEV4"; then
191                         opts="$opts ipv6cp-use-ipaddr"
192                 elif is_yes "$IPV6_CP_PERSISTENT"; then
193                         opts="$opts ipv6cp-use-persistent"
194                 fi
195         elif is_no "$IPV6_PPP"; then
196                 opts="$opts noipv6"
197         fi
198 elif is_no "$IPV6_NETWORKING"; then
199         opts="$opts noipv6"
200 fi
201 if is_yes "${IPX_PPP}"; then
202         opts="$opts ipx"
203         if [ -n "${IPX_PPP_NETWORK}" ]; then
204                 opts="$opts ipx-network ${IPX_PPP_NETWORK}"
205         fi
206         if [ -n "${IPX_PPP_NODE}" ]; then
207                 opts="$opts ipx-node ${IPX_PPP_NODE}"
208         fi
209         if [ -n "${IPX_PPP_ROUTING}" ]; then
210                 opts="$opts ipx-routing ${IPX_PPP_ROUTING}"
211         fi
212 fi
213
214 if [ -n "${PAPNAME}" ] ; then
215         opts="$opts user ${PAPNAME}"
216 fi
217 if [ -n "${REMOTENAME}" ] ; then
218         opts="$opts remotename ${REMOTENAME}"
219 fi
220 if is_yes "${DEBUG}"; then
221         opts="$opts debug"
222 fi
223 if is_yes "${AUTH}"; then
224         opts="$opts auth"
225 elif is_no "${AUTH}"; then
226         opts="$opts noauth"
227 fi
228 if is_yes "$PLUGIN_IFCFG_PASSWORD" && [ -n "$PASSWORD" ]; then
229         if [ -f "$CONFIG" ]; then
230                 ifcfg_password_config="$CONFIG"
231         else
232                 ifcfg_password_config="/etc/sysconfig/interfaces/$CONFIG"
233         fi
234         opts="$opts plugin ifcfg-password.so ifcfg $ifcfg_password_config"
235 fi
236
237 if ! is_no "${UNIT}"; then
238         UNIT=$(echo "${DEVICE}" | awk ' { gsub(/ppp/,NUL); print $0} ')
239         opts="$opts unit ${UNIT}"
240 fi
241
242 MODEM="${MODEMPORT}"; export MODEM
243
244 (logger -p daemon.info -t ifup-ppp \
245         "$(nls 'pppd started for %s on device %s at speed %s' "$DEVICE" \
246         "$MODEMPORT" "${LINESPEED:-(unspecified)} on unit ${UNIT}")" &)&
247
248 if [ -n "${DATAFORCHAT}" ]; then
249         export $DATAFORCHAT
250 fi
251 /usr/sbin/pppd $opts ${MODEMMODE} "${MODEMPORT}" ${LINESPEED} \
252         ipparam ${DEVNAME} linkname ${DEVNAME} \
253         ${PPPOPTIONS}
254
255 # This must be last line !
256 # vi:syntax=sh
This page took 0.038563 seconds and 2 git commands to generate.