]>
Commit | Line | Data |
---|---|---|
8ae238a5 | 1 | #!/bin/bash |
66c36198 PM |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | . /etc/sysconfig/rc | |
d1e90efc | 23 | . ${rc_functions} |
71ea0d68 | 24 | . /etc/init.d/networking/functions.network |
1f2ff0fa | 25 | |
ff07f865 | 26 | #Define some defaults |
ff7a3950 AF |
27 | INET_VLAN=7 |
28 | IPTV_VLAN=8 | |
872d5a1e | 29 | ATM_DEV=0 |
ff07f865 | 30 | |
1f2ff0fa AF |
31 | eval $(/usr/local/bin/readhash /var/ipfire/main/settings) |
32 | if [ "$RRDLOG" == "" ]; then | |
33 | RRDLOG=/var/log/rrd | |
34 | fi | |
35 | ||
d1e90efc | 36 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) |
c3190a33 | 37 | eval $(/usr/local/bin/readhash /var/ipfire/dns/settings) |
b8c750f3 JPT |
38 | eval $(/usr/local/bin/readhash /var/ipfire/mac/settings) |
39 | ||
40 | MAC=$(tr - : <<<$MAC) | |
1bffb899 | 41 | MAC1=$(tr - : <<<$MAC1) |
d66c870e | 42 | MAC2=$(tr - : <<<$MAC2) |
d1e90efc MT |
43 | |
44 | TYPE="${RED_TYPE}" | |
45 | DEVICE="${RED_DEV}" | |
46 | ||
0dde24fa MT |
47 | if [ "$TYPE" == "STATIC" ] || [ "$TYPE" == "DHCP" ]; then |
48 | if [ "$DEVICE" == "" ]; then | |
49 | boot_mesg "No device for red network. Please run setup." ${FAILURE} | |
50 | echo_failure | |
51 | [ "${1}" == "start" ] && exit 0 | |
52 | fi | |
53 | fi | |
66c36198 | 54 | |
0dde24fa MT |
55 | if [ "${TYPE}" == "STATIC" ]; then |
56 | if [ "${DEVICE}" != "${GREEN_DEV}" ]; then | |
57 | ADDRESS="${RED_ADDRESS}" | |
0dde24fa MT |
58 | NETADDRESS="${RED_NETADDRESS}" |
59 | NETMASK="${RED_NETMASK}" | |
9bdf5e71 | 60 | MTU="${RED_MTU}" |
0dde24fa MT |
61 | else |
62 | ADDRESS="${GREEN_ADDRESS}" | |
0dde24fa MT |
63 | NETADDRESS="${GREEN_NETADDRESS}" |
64 | NETMASK="${GREEN_NETMASK}" | |
9bdf5e71 | 65 | MTU="${GREEN_MTU}" |
0dde24fa | 66 | fi |
d1e90efc | 67 | GATEWAY="${DEFAULT_GATEWAY}" |
0db33b56 MT |
68 | # DNS1 |
69 | # DNS2 | |
d1e90efc | 70 | |
d1e90efc MT |
71 | if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then |
72 | PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-` | |
b67f02d5 | 73 | args="${args} ${ADDRESS}/${PREFIX}" |
d1e90efc MT |
74 | else |
75 | boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE} | |
76 | echo_failure | |
77 | exit 1 | |
78 | fi | |
d1e90efc MT |
79 | fi |
80 | ||
81 | case "${1}" in | |
82 | start) | |
6361fa73 JS |
83 | # Remove possible leftover files |
84 | rm -f /var/ipfire/red/{active,device,dial-on-demand,dns1,dns2,local-ipaddress,remote-ipaddress,resolv.conf} | |
85 | ||
0dde24fa MT |
86 | if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then |
87 | boot_mesg "Bringing up the ${DEVICE} interface..." | |
88 | boot_mesg_flush | |
89 | # Check if an interface is there... | |
90 | if ip link show ${DEVICE} > /dev/null 2>&1; then | |
91 | link_status=`ip link show ${DEVICE} 2> /dev/null` | |
92 | if [ -n "${link_status}" ]; then | |
93 | if ! echo "${link_status}" | grep -q UP; then | |
b8c750f3 | 94 | if [ -n "$MAC" ]; then |
66c36198 | 95 | boot_mesg "Setting mac address on ${DEVICE} to ${MAC}" |
b8c750f3 | 96 | ip link set dev ${DEVICE} address ${MAC} |
d66c870e | 97 | evaluate_retval |
b8c750f3 | 98 | fi |
0dde24fa MT |
99 | ip link set ${DEVICE} up |
100 | fi | |
d1e90efc | 101 | fi |
0dde24fa MT |
102 | else |
103 | boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE} | |
104 | echo_failure | |
105 | exit 1 | |
d1e90efc | 106 | fi |
d1e90efc | 107 | fi |
6c33dc5c | 108 | |
d1e90efc | 109 | if [ "${TYPE}" == "STATIC" ]; then |
9bdf5e71 MT |
110 | # Set the MTU |
111 | if [ -n "${MTU}" ]; then | |
112 | if ! ip link set dev "${DEVICE}" mtu "${MTU}" &>/dev/null; then | |
113 | boot_mesg "Could not set MTU of ${MTU} to ${DEVICE}..." | |
114 | echo_warning | |
115 | fi | |
116 | fi | |
117 | ||
0dde24fa MT |
118 | if [ "$DEVICE" != "${GREEN_DEV}" ]; then |
119 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..." | |
120 | ip addr add ${args} dev ${DEVICE} | |
121 | evaluate_retval | |
122 | fi | |
0db33b56 MT |
123 | echo -n "${DEVICE}" > /var/ipfire/red/iface |
124 | echo -n "${ADDRESS}" > /var/ipfire/red/local-ipaddress | |
125 | echo -n "${GATEWAY}" > /var/ipfire/red/remote-ipaddress | |
3d9d5884 AF |
126 | grep -v -E "\<gateway\>" /etc/hosts > /tmp/hosts |
127 | echo "$GATEWAY gateway" >> /tmp/hosts | |
b2f872eb | 128 | mv /tmp/hosts /etc/hosts |
bcdde652 | 129 | touch /var/ipfire/red/active |
66c36198 | 130 | |
0be884d6 | 131 | # Create route to default gateway |
d258c7a4 | 132 | ip route add ${GATEWAY} dev ${DEVICE} |
0be884d6 | 133 | |
040e5040 | 134 | boot_mesg "Setting up default gateway ${GATEWAY}..." |
d258c7a4 | 135 | ip route add default via ${GATEWAY} dev ${DEVICE} |
040e5040 | 136 | evaluate_retval |
66c36198 | 137 | |
a83bcf91 AF |
138 | if [ -d "/sys/class/net/${DEVICE}" ]; then |
139 | # has carrier ? | |
fff96e39 | 140 | if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then |
a83bcf91 AF |
141 | boot_mesg -n "Wait for carrier on ${DEVICE} " |
142 | for (( i=30; i>1; i-- )) do | |
143 | if [ "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then | |
144 | break; | |
145 | fi | |
146 | boot_mesg -n "." | |
147 | sleep 2 | |
148 | done | |
149 | boot_mesg "" | |
150 | if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then | |
151 | echo_failure | |
152 | else | |
153 | echo_ok | |
154 | fi | |
fff96e39 AF |
155 | fi |
156 | fi | |
157 | ||
0e42072a | 158 | run_subdir ${rc_base}/init.d/networking/red.up/ |
bbe6aff7 AF |
159 | |
160 | # Configure aliases only if red static | |
161 | /usr/local/bin/setaliases | |
162 | ||
d1e90efc | 163 | elif [ "${TYPE}" == "DHCP" ]; then |
71ea0d68 SS |
164 | # Add firewall rules to allow comunication with the dhcp server on red. |
165 | iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT | |
166 | iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT | |
7e0cd11d | 167 | |
d1e90efc MT |
168 | echo -n "${DEVICE}" > /var/ipfire/red/iface |
169 | ||
71ea0d68 SS |
170 | # Check if the wlan-client is used on red. |
171 | # To determine this we check if a wpa_supplicant is running. | |
172 | pid="$(pidof wpa_supplicant)" | |
173 | ||
174 | if [ -z "${pid}" ]; then | |
175 | # No wpa_supplicant is running. So it's save to start dhcpcd. | |
176 | dhcpcd_start "${DEVICE}" | |
177 | fi | |
178 | ||
d1e90efc | 179 | elif [ "$TYPE" == "PPPOE" ]; then |
06b912c5 | 180 | |
a89770fa | 181 | if ( ps ax | grep -q [p]ppd ); then |
0dde24fa MT |
182 | boot_mesg "pppd is still running." ${FAILURE} |
183 | echo_failure | |
184 | exit 1 | |
a89770fa | 185 | fi |
66c36198 | 186 | |
d1e90efc | 187 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) |
66c36198 | 188 | |
905fbf3e | 189 | [ -c "/dev/ppp" ] || mknod /dev/ppp c 108 0 |
06b912c5 MT |
190 | |
191 | # We force the plugin method, anyway. | |
192 | METHOD="PPPOE_PLUGIN" | |
193 | ||
a89770fa | 194 | PPP_NIC=${DEVICE} |
40049855 | 195 | |
d0c3a0c5 | 196 | if [ "$TYPE" == "pppoeatm" ] || [ "$TYPE" == "pptpatm" ]; then |
872d5a1e AF |
197 | PPP_NIC=nas${ATM_DEV} |
198 | DEVICE=nas${ATM_DEV} | |
7f263dc7 | 199 | boot_mesg "Creating ATM-Bridge as $PPP_NIC ..." |
872d5a1e | 200 | br2684ctl -c${ATM_DEV} -e${ENCAP} -a${ATM_DEV}.${VPI}.${VCI} >/dev/null 2>&1 & |
d0c3a0c5 | 201 | sleep 1 |
d0ff84a6 AF |
202 | |
203 | # use user-defined or green mac address for nas0 | |
204 | if [ -n "$MAC" ]; then | |
872d5a1e | 205 | ip link set dev nas${ATM_DEV} address ${MAC} |
d0ff84a6 | 206 | else |
872d5a1e | 207 | ip link set dev nas${ATM_DEV} address $(cat /sys/class/net/green0/address) |
d0ff84a6 AF |
208 | fi |
209 | ||
d0c3a0c5 AF |
210 | if [ "$TYPE" == "pppoeatm" ]; then |
211 | TYPE="pppoe" | |
212 | fi | |
213 | if [ "$TYPE" == "pptpatm" ]; then | |
214 | TYPE="pptp" | |
215 | fi | |
957863f7 MT |
216 | |
217 | # QMI | |
218 | elif [ "$TYPE" = "qmi" ]; then | |
219 | DEVICE="$(qmi_find_device "${RED_DEV}")" | |
220 | ||
221 | boot_mesg "Bringing up QMI on ${RED_DEV} (${DEVICE})..." | |
222 | ||
223 | # Enable RAW-IP mode | |
224 | qmi_enable_rawip_mode "${RED_DEV}" | |
225 | ||
226 | # Configure APN | |
227 | qmi_configure_apn "${DEVICE}" "${APN}" "${AUTH}" "${USERNAME}" "${PASSWORD}" | |
228 | ||
229 | # Set up the interface | |
230 | ip link set "${RED_DEV}" up &>/dev/null | |
231 | ||
883ec31e SS |
232 | # Write red device name to the corresponding file. |
233 | echo -n "${RED_DEV}" > /var/ipfire/red/iface | |
234 | ||
957863f7 | 235 | # Start the DHCP client |
8d09028b | 236 | dhcpcd_start "${RED_DEV}" --dhcp |
957863f7 MT |
237 | |
238 | # Done | |
239 | exit 0 | |
d0c3a0c5 AF |
240 | fi |
241 | ||
40049855 | 242 | if [ "$TYPE" == "vdsl" ]; then |
7f263dc7 | 243 | boot_mesg "Creating VLAN Interface ${DEVICE}.${INET_VLAN} ..." |
40049855 | 244 | modprobe 8021q |
ff7a3950 | 245 | vconfig add ${DEVICE} ${INET_VLAN} |
1bffb899 | 246 | if [ -n "$MAC1" ]; then |
ff7a3950 AF |
247 | boot_mesg "Setting mac address on ${DEVICE}.${INET_VLAN} to ${MAC1}" |
248 | ip link set dev ${DEVICE}.${INET_VLAN} address ${MAC1} | |
1bffb899 AF |
249 | evaluate_retval |
250 | fi | |
ff7a3950 | 251 | PPP_NIC=${DEVICE}.${INET_VLAN} |
40049855 AF |
252 | sleep 0.2 |
253 | ip link set ${PPP_NIC} up | |
254 | TYPE="pppoe" | |
d0c3a0c5 AF |
255 | fi |
256 | if [ "${IPTV}" == "enable" ]; then | |
18136c5c | 257 | PIDFILE="/var/run/dhcpcd/${DEVICE}.${IPTV_VLAN}.pid" |
ff7a3950 | 258 | LEASEINFO="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info" |
d0c3a0c5 AF |
259 | # Test to see if there is a stale pid file |
260 | if [ -f "$PIDFILE" ]; then | |
261 | ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null | |
262 | if [ $? != 0 ]; then | |
18136c5c | 263 | rm -f /var/run/dhcpcd/${DEVICE}.${IPTV_VLAN}.pid > /dev/null |
bbe6aff7 | 264 | fi |
d0c3a0c5 | 265 | fi |
bbe6aff7 | 266 | |
d0c3a0c5 | 267 | if [ ! -f "$PIDFILE" ]; then |
7f263dc7 | 268 | boot_mesg "Creating VLAN Interface ${DEVICE}.${IPTV_VLAN} ..." |
d0c3a0c5 | 269 | modprobe 8021q |
ff7a3950 | 270 | vconfig add ${DEVICE} ${IPTV_VLAN} |
d0c3a0c5 | 271 | if [ -n "$MAC2" ]; then |
66c36198 | 272 | boot_mesg "Setting mac address on ${DEVICE}.${IPTV_VLAN} to ${MAC2}" |
ff7a3950 | 273 | ip link set dev ${DEVICE}.${IPTV_VLAN} address ${MAC2} |
d0c3a0c5 AF |
274 | evaluate_retval |
275 | fi | |
ff7a3950 AF |
276 | boot_mesg -n "Starting dhcpcd on the ${DEVICE}.${IPTV_VLAN} interface..." |
277 | /sbin/dhcpcd ${DEVICE}.${IPTV_VLAN} ${DHCP_START} >/dev/null 2>&1 | |
d0c3a0c5 | 278 | RET="$?" |
bbe6aff7 | 279 | |
d0c3a0c5 | 280 | if [ "$RET" = "0" ]; then |
ff7a3950 | 281 | . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info |
d0c3a0c5 AF |
282 | echo "" |
283 | echo_ok | |
ff7a3950 | 284 | boot_mesg " DHCP Assigned Settings for ${DEVICE}.${IPTV_VLAN}:" |
d0c3a0c5 AF |
285 | boot_mesg_flush |
286 | boot_mesg " IP Address: $ip_address" | |
287 | boot_mesg_flush | |
288 | boot_mesg " Hostname: $RED_DHCP_HOSTNAME" | |
289 | boot_mesg_flush | |
290 | boot_mesg " Subnet Mask: $subnet_mask" | |
291 | boot_mesg_flush | |
292 | boot_mesg " Default Gateway: $routers" | |
293 | boot_mesg_flush | |
294 | boot_mesg " DNS Server: $domain_name_servers" | |
295 | boot_mesg_flush | |
bbe6aff7 | 296 | |
d0c3a0c5 AF |
297 | else |
298 | echo "" | |
299 | $(exit "$RET") | |
300 | evaluate_retval | |
bbe6aff7 AF |
301 | fi |
302 | fi | |
40049855 | 303 | fi |
5aae218d | 304 | if [ "$TYPE" == "pppoe" ] || [ "$TYPE" == "pptp" ]; then |
4cd4876a | 305 | if [ "$PPP_NIC" == "" ]; then |
0dde24fa MT |
306 | boot_mesg "No device for red interface given. Check netsetup or dialprofile!" ${FAILURE} |
307 | echo_failure | |
cb1fb691 | 308 | exit 0 |
0dde24fa | 309 | fi |
5aae218d | 310 | boot_mesg "Bringing up the $TYPE interface on $PPP_NIC ..." |
58e9b9dc | 311 | ip addr flush dev $PPP_NIC >/dev/null 2>&1 |
5aae218d | 312 | if [ "$TYPE" == "pptp" ]; then |
fd850b7e | 313 | if [ "$PPTP_NICCFG" == "dhcp" ]; then |
fd850b7e AF |
314 | # Test to see if there is a stale pid file |
315 | if [ -f "$PIDFILE" ]; then | |
316 | ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null | |
317 | if [ $? != 0 ]; then | |
18136c5c | 318 | rm -f /var/run/dhcpcd/${DEVICE}.pid > /dev/null |
fd850b7e AF |
319 | fi |
320 | fi | |
321 | ||
322 | if [ ! -f "$PIDFILE" ]; then | |
d9563c55 | 323 | boot_mesg -n "Starting dhcpcd on the ${DEVICE} interface..." |
367a7770 | 324 | /sbin/dhcpcd ${DEVICE} ${DHCP_START} >/dev/null 2>&1 |
fd850b7e AF |
325 | RET="$?" |
326 | ||
327 | if [ "$RET" = "0" ]; then | |
328 | . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info | |
329 | echo "" | |
330 | echo_ok | |
331 | boot_mesg " DHCP Assigned Settings for ${DEVICE}:" | |
332 | boot_mesg_flush | |
7f8e589b | 333 | boot_mesg " IP Address: $ip_address" |
fd850b7e AF |
334 | boot_mesg_flush |
335 | boot_mesg " Hostname: $RED_DHCP_HOSTNAME" | |
336 | boot_mesg_flush | |
7f8e589b | 337 | boot_mesg " Subnet Mask: $subnet_mask" |
fd850b7e | 338 | boot_mesg_flush |
7f8e589b | 339 | boot_mesg " Default Gateway: $routers" |
fd850b7e | 340 | boot_mesg_flush |
7f8e589b | 341 | boot_mesg " DNS Server: $domain_name_servers" |
fd850b7e | 342 | boot_mesg_flush |
7f8e589b | 343 | /sbin/route add $PPTP_PEER gw $routers $PPP_NIC |
fd850b7e AF |
344 | else |
345 | echo "" | |
346 | $(exit "$RET") | |
347 | evaluate_retval | |
348 | fi | |
349 | fi | |
350 | else | |
351 | ip addr add $PPTP_NICCFG dev $PPP_NIC | |
352 | fi | |
5aae218d | 353 | fi |
58e9b9dc | 354 | ip link set ${PPP_NIC} up |
164a3b51 AF |
355 | if [ -n "${PPTP_ROUTE}" ]; then |
356 | boot_mesg "Set route ${PPTP_ROUTE} to pptp server..." | |
357 | route add ${PPTP_ROUTE} | |
358 | fi | |
27b8cc24 MT |
359 | else |
360 | boot_mesg "Bringing up the PPP via ${TYPE} on ${COMPORT}..." | |
361 | fi | |
66c36198 | 362 | |
905fbf3e MT |
363 | ### ### |
364 | ### Configuring the pppd ### | |
365 | ### ### | |
66c36198 | 366 | |
905fbf3e | 367 | ### Plugin Options |
66c36198 | 368 | # |
5aae218d AF |
369 | if [ "$TYPE" == "pppoe" ]; then |
370 | [ "${METHOD}" == "PPPOE_PLUGIN" ] && \ | |
0803c50f | 371 | PLUGOPTS="plugin pppoe.so" |
5aae218d | 372 | fi |
d1e90efc | 373 | |
905fbf3e MT |
374 | ### Synchronous Mode |
375 | # | |
376 | #PPPOE_SYNC=-s | |
a89770fa | 377 | #PPPD_SYNC=sync |
66c36198 | 378 | |
a89770fa MT |
379 | ### Access Concentrator Name |
380 | # | |
905fbf3e MT |
381 | if [ -n "${CONCENTRATORNAME}" ]; then |
382 | ACNAME="-C ${CONCENTRATORNAME}" | |
d1e90efc | 383 | fi |
905fbf3e MT |
384 | |
385 | ### Service Name | |
386 | # | |
387 | if [ -n "${SERVICENAME}" ]; then | |
388 | if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then | |
389 | PLUGOPTS+=" rp_pppoe_service ${SERVICENAME}" | |
390 | else | |
391 | SERVICENAME="-S ${SERVICENAME}" | |
392 | fi | |
d1e90efc | 393 | fi |
a89770fa | 394 | |
905fbf3e MT |
395 | ### Authentication Types |
396 | # | |
d1e90efc | 397 | if [ "${AUTH}" == "pap" ]; then |
905fbf3e | 398 | AUTH="-chap" |
d1e90efc | 399 | elif [ "${AUTH}" == "chap" ]; then |
905fbf3e | 400 | AUTH="-pap" |
57cb9775 CS |
401 | else |
402 | AUTH="" | |
d1e90efc | 403 | fi |
a89770fa | 404 | |
66c36198 | 405 | ### Dial On Demand |
905fbf3e | 406 | # |
d1e90efc MT |
407 | if [ "${RECONNECTION}" != "persistent" ]; then |
408 | if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then | |
409 | SECONDS=$[${TIMEOUT} * 60] | |
905fbf3e MT |
410 | else |
411 | SECONDS=300 | |
d1e90efc MT |
412 | fi |
413 | if [ "${RECONNECTION}" == "dialondemand" ]; then | |
414 | touch /var/ipfire/red/dial-on-demand | |
905fbf3e | 415 | DEMAND="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113" |
a89770fa | 416 | DEMAND+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune" |
d1e90efc | 417 | fi |
905fbf3e | 418 | fi |
66c36198 | 419 | |
5aae218d AF |
420 | if [ "$TYPE" == "pppoe" ]; then |
421 | ### When using pppoe-plugin the device has to be the last option | |
422 | # | |
423 | [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS+=" $PPP_NIC" | |
424 | fi | |
66c36198 | 425 | |
27b8cc24 | 426 | if [ "$TYPE" == "modem" ]; then |
a89770fa | 427 | PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts" |
7c653e4b | 428 | METHOD="PPPOE_PLUGIN" |
27b8cc24 | 429 | elif [ "$TYPE" == "serial" ]; then |
a89770fa | 430 | PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts" |
7c653e4b | 431 | METHOD="PPPOE_PLUGIN" |
27b8cc24 | 432 | fi |
66c36198 | 433 | |
905fbf3e MT |
434 | ### Standard PPP options we always use |
435 | # | |
c3ae88ca | 436 | PPP_STD_OPTIONS="$PLUGOPTS usepeerdns defaultroute noipdefault noauth" |
52764dbe | 437 | PPP_STD_OPTIONS+=" default-asyncmap hide-password nodetach noipv6" |
463f9ede | 438 | PPP_STD_OPTIONS+=" noaccomp nodeflate nopcomp novj novjccomp" |
905fbf3e | 439 | PPP_STD_OPTIONS+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20" |
fb27520e | 440 | PPP_STD_OPTIONS+=" lcp-echo-failure 5 ${AUTH}" |
89baf6d5 MT |
441 | |
442 | if [ -n "${MTU}" ]; then | |
443 | PPP_STD_OPTIONS="${PPP_STD_OPTIONS} mtu ${MTU}" | |
444 | fi | |
445 | ||
446 | if [ -n "${MRU}" ]; then | |
447 | PPP_STD_OPTIONS="${PPP_STD_OPTIONS} mru ${MRU}" | |
448 | fi | |
66c36198 | 449 | |
905fbf3e MT |
450 | ### Debugging |
451 | # | |
452 | if [ "${DEBUG}" == "on" ]; then | |
453 | DEBUG="debug" | |
d1e90efc | 454 | else |
905fbf3e | 455 | DEBUG="" |
d1e90efc | 456 | fi |
66c36198 | 457 | |
905fbf3e MT |
458 | ### PPPoE invocation |
459 | # | |
a89770fa MT |
460 | if [ "$TYPE" == "pppoe" ]; then |
461 | PPPOE_CMD="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC" | |
27b8cc24 MT |
462 | PPPOE_CMD+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT" |
463 | fi | |
5aae218d AF |
464 | |
465 | ### PPTP ### | |
466 | # | |
467 | if [ "$TYPE" == "pptp" ]; then | |
468 | PPPOE_CMD="pptp $PPTP_PEER --nolaunchpppd" | |
7c653e4b | 469 | METHOD="" |
5aae218d | 470 | fi |
66c36198 | 471 | |
905fbf3e MT |
472 | ### Run everything |
473 | # | |
7c653e4b | 474 | if [ "$METHOD" == "PPPOE_PLUGIN" ]; then |
905fbf3e MT |
475 | /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND >/dev/null 2>&1 & |
476 | evaluate_retval | |
a89770fa | 477 | # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND |
905fbf3e MT |
478 | else |
479 | /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev/null 2>&1 & | |
480 | evaluate_retval | |
a89770fa | 481 | # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC |
905fbf3e | 482 | fi |
5806ff0c | 483 | |
905fbf3e | 484 | /etc/rc.d/init.d/connectd start |
1f2ff0fa | 485 | # Add a NaN value to ppp0 rrd to supress spikes at reconnect |
c772568a | 486 | rrdtool update $RRDLOG/collectd/localhost/interface/if_octets-ppp0.rrd \ |
49ab1173 | 487 | $(date +%s):: > /dev/null 2>&1 |
28ec28bc | 488 | exit 0 |
d1e90efc | 489 | fi |
d1e90efc MT |
490 | ;; |
491 | ||
492 | stop) | |
ebf64a93 MT |
493 | rm -f /var/ipfire/red/{active,device,dial-on-demand,dns1,dns2,local-ipaddress,remote-ipaddress,resolv.conf} |
494 | ||
d1e90efc | 495 | if [ "$TYPE" == "STATIC" ]; then |
0dde24fa MT |
496 | boot_mesg "Stopping default gateway ${GATEWAY}..." |
497 | ip route del default via ${GATEWAY} >/dev/null 2>&1 | |
498 | echo_ok | |
499 | if [ "$DEVICE" != "${GREEN_DEV}" ]; then | |
70631572 AF |
500 | boot_mesg "Removing IPv4 addresses from the ${DEVICE} interface..." |
501 | ip addr flush dev ${DEVICE} | |
0dde24fa MT |
502 | evaluate_retval |
503 | fi | |
0e42072a | 504 | run_subdir ${rc_base}/init.d/networking/red.down/ |
f8841352 | 505 | |
5aae218d | 506 | elif [ "$TYPE" == "PPPOE" ]; then |
957863f7 MT |
507 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) |
508 | ||
509 | if [ "${TYPE}" = "qmi" ]; then | |
510 | boot_mesg "Bringing down the QMI interface ${RED_DEV}..." | |
511 | DEVICE="$(qmi_find_device "${RED_DEV}")" | |
512 | ||
513 | # Stop the DHCP client on RED | |
514 | dhcpcd_stop "${RED_DEV}" | |
515 | ||
516 | # Reset any QMI settings | |
517 | qmi_reset "${DEVICE}" | |
518 | ||
519 | exit 0 | |
520 | fi | |
521 | ||
a89770fa | 522 | boot_mesg "Bringing down the PPP interface ..." |
93b34528 | 523 | rm -f /var/ipfire/red/keepconnected |
a89770fa | 524 | killall -w -s TERM /usr/sbin/pppd 2>/dev/null |
352e626f | 525 | evaluate_retval |
1f2ff0fa | 526 | # Add a NaN value to ppp0 rrd to supress spikes at reconnect |
c772568a | 527 | rrdtool update $RRDLOG/collectd/localhost/interface/if_octets-ppp0.rrd \ |
49ab1173 | 528 | $(date +%s):: > /dev/null 2>&1 |
0dde24fa | 529 | |
71ea0d68 SS |
530 | elif [ "$TYPE" == "DHCP" ]; then |
531 | # Check if the wlan-client is used on red. | |
532 | # To determine this we check if a wpa_supplicant is running. | |
533 | pid="$(pidof wpa_supplicant)" | |
534 | ||
535 | if [ -z "${pid}" ]; then | |
536 | # Stop dhcpcd. | |
537 | dhcpcd_stop "${DEVICE}" | |
fd850b7e AF |
538 | fi |
539 | fi | |
540 | ||
164a3b51 AF |
541 | if [ -n "${PPTP_ROUTE}" ]; then |
542 | route del ${PPTP_ROUTE} | |
543 | fi | |
544 | ||
0dde24fa | 545 | if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then |
ff7a3950 | 546 | link_status=`ip link show $DEVICE.${INET_VLAN} 2> /dev/null` |
40049855 AF |
547 | if [ -n "${link_status}" ]; then |
548 | if echo "${link_status}" | grep -q UP; then | |
ff7a3950 AF |
549 | boot_mesg "Bringing down the ${DEVICE}.${INET_VLAN} interface..." |
550 | ip link set ${DEVICE}.${INET_VLAN} down | |
551 | vconfig rem ${DEVICE}.${INET_VLAN} | |
40049855 AF |
552 | evaluate_retval |
553 | fi | |
bbe6aff7 AF |
554 | else |
555 | link_status=`ip link show $DEVICE 2> /dev/null` | |
556 | if [ -n "${link_status}" ]; then | |
557 | if echo "${link_status}" | grep -q UP; then | |
558 | boot_mesg "Bringing down the ${DEVICE} interface..." | |
559 | ip link set ${DEVICE} down | |
560 | evaluate_retval | |
561 | fi | |
0dde24fa | 562 | fi |
d1e90efc MT |
563 | fi |
564 | fi | |
cb1fb691 | 565 | killall -w -s KILL /usr/sbin/pppd >/dev/null 2>&1 |
5aae218d | 566 | killall -w -s KILL pptp >/dev/null 2>&1 |
cb1fb691 | 567 | killall -w -s KILL br2684ctl >/dev/null 2>&1 |
6c33dc5c | 568 | |
6c33dc5c | 569 | exit 0; |
d1e90efc | 570 | ;; |
d1e90efc | 571 | esac |