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