]>
Commit | Line | Data |
---|---|---|
d1e90efc | 1 | #!/bin/sh |
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) | |
0dde24fa MT |
83 | if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then |
84 | boot_mesg "Bringing up the ${DEVICE} interface..." | |
85 | boot_mesg_flush | |
86 | # Check if an interface is there... | |
87 | if ip link show ${DEVICE} > /dev/null 2>&1; then | |
88 | link_status=`ip link show ${DEVICE} 2> /dev/null` | |
89 | if [ -n "${link_status}" ]; then | |
90 | if ! echo "${link_status}" | grep -q UP; then | |
b8c750f3 | 91 | if [ -n "$MAC" ]; then |
66c36198 | 92 | boot_mesg "Setting mac address on ${DEVICE} to ${MAC}" |
b8c750f3 | 93 | ip link set dev ${DEVICE} address ${MAC} |
d66c870e | 94 | evaluate_retval |
b8c750f3 | 95 | fi |
0dde24fa MT |
96 | ip link set ${DEVICE} up |
97 | fi | |
d1e90efc | 98 | fi |
0dde24fa MT |
99 | else |
100 | boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE} | |
101 | echo_failure | |
102 | exit 1 | |
d1e90efc | 103 | fi |
d1e90efc | 104 | fi |
6c33dc5c | 105 | |
d1e90efc | 106 | if [ "${TYPE}" == "STATIC" ]; then |
9bdf5e71 MT |
107 | # Set the MTU |
108 | if [ -n "${MTU}" ]; then | |
109 | if ! ip link set dev "${DEVICE}" mtu "${MTU}" &>/dev/null; then | |
110 | boot_mesg "Could not set MTU of ${MTU} to ${DEVICE}..." | |
111 | echo_warning | |
112 | fi | |
113 | fi | |
114 | ||
0dde24fa MT |
115 | if [ "$DEVICE" != "${GREEN_DEV}" ]; then |
116 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..." | |
117 | ip addr add ${args} dev ${DEVICE} | |
118 | evaluate_retval | |
119 | fi | |
0db33b56 MT |
120 | echo -n "${DEVICE}" > /var/ipfire/red/iface |
121 | echo -n "${ADDRESS}" > /var/ipfire/red/local-ipaddress | |
122 | echo -n "${GATEWAY}" > /var/ipfire/red/remote-ipaddress | |
3d9d5884 AF |
123 | grep -v -E "\<gateway\>" /etc/hosts > /tmp/hosts |
124 | echo "$GATEWAY gateway" >> /tmp/hosts | |
b2f872eb | 125 | mv /tmp/hosts /etc/hosts |
bcdde652 | 126 | touch /var/ipfire/red/active |
66c36198 | 127 | |
0be884d6 MT |
128 | # Create route to default gateway |
129 | ip route add ${GATEWAY} dev ${DEVICE} | |
130 | ||
040e5040 MT |
131 | boot_mesg "Setting up default gateway ${GATEWAY}..." |
132 | ip route add default via ${GATEWAY} dev ${DEVICE} | |
133 | evaluate_retval | |
66c36198 | 134 | |
a83bcf91 AF |
135 | if [ -d "/sys/class/net/${DEVICE}" ]; then |
136 | # has carrier ? | |
fff96e39 | 137 | if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then |
a83bcf91 AF |
138 | boot_mesg -n "Wait for carrier on ${DEVICE} " |
139 | for (( i=30; i>1; i-- )) do | |
140 | if [ "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then | |
141 | break; | |
142 | fi | |
143 | boot_mesg -n "." | |
144 | sleep 2 | |
145 | done | |
146 | boot_mesg "" | |
147 | if [ ! "$(</sys/class/net/${DEVICE}/carrier)" = "1" ]; then | |
148 | echo_failure | |
149 | else | |
150 | echo_ok | |
151 | fi | |
fff96e39 AF |
152 | fi |
153 | fi | |
154 | ||
0e42072a | 155 | run_subdir ${rc_base}/init.d/networking/red.up/ |
bbe6aff7 AF |
156 | |
157 | # Configure aliases only if red static | |
158 | /usr/local/bin/setaliases | |
159 | ||
d1e90efc | 160 | elif [ "${TYPE}" == "DHCP" ]; then |
71ea0d68 SS |
161 | # Add firewall rules to allow comunication with the dhcp server on red. |
162 | iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT | |
163 | iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT | |
7e0cd11d | 164 | |
d1e90efc MT |
165 | echo -n "${DEVICE}" > /var/ipfire/red/iface |
166 | ||
71ea0d68 SS |
167 | # Check if the wlan-client is used on red. |
168 | # To determine this we check if a wpa_supplicant is running. | |
169 | pid="$(pidof wpa_supplicant)" | |
170 | ||
171 | if [ -z "${pid}" ]; then | |
172 | # No wpa_supplicant is running. So it's save to start dhcpcd. | |
173 | dhcpcd_start "${DEVICE}" | |
174 | fi | |
175 | ||
d1e90efc | 176 | elif [ "$TYPE" == "PPPOE" ]; then |
06b912c5 | 177 | |
a89770fa | 178 | if ( ps ax | grep -q [p]ppd ); then |
0dde24fa MT |
179 | boot_mesg "pppd is still running." ${FAILURE} |
180 | echo_failure | |
181 | exit 1 | |
a89770fa | 182 | fi |
66c36198 | 183 | |
d1e90efc | 184 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) |
66c36198 | 185 | |
905fbf3e | 186 | [ -c "/dev/ppp" ] || mknod /dev/ppp c 108 0 |
06b912c5 MT |
187 | |
188 | # We force the plugin method, anyway. | |
189 | METHOD="PPPOE_PLUGIN" | |
190 | ||
a89770fa | 191 | PPP_NIC=${DEVICE} |
40049855 | 192 | |
d0c3a0c5 | 193 | if [ "$TYPE" == "pppoeatm" ] || [ "$TYPE" == "pptpatm" ]; then |
872d5a1e AF |
194 | PPP_NIC=nas${ATM_DEV} |
195 | DEVICE=nas${ATM_DEV} | |
7f263dc7 | 196 | boot_mesg "Creating ATM-Bridge as $PPP_NIC ..." |
872d5a1e | 197 | br2684ctl -c${ATM_DEV} -e${ENCAP} -a${ATM_DEV}.${VPI}.${VCI} >/dev/null 2>&1 & |
d0c3a0c5 | 198 | sleep 1 |
d0ff84a6 AF |
199 | |
200 | # use user-defined or green mac address for nas0 | |
201 | if [ -n "$MAC" ]; then | |
872d5a1e | 202 | ip link set dev nas${ATM_DEV} address ${MAC} |
d0ff84a6 | 203 | else |
872d5a1e | 204 | ip link set dev nas${ATM_DEV} address $(cat /sys/class/net/green0/address) |
d0ff84a6 AF |
205 | fi |
206 | ||
d0c3a0c5 AF |
207 | if [ "$TYPE" == "pppoeatm" ]; then |
208 | TYPE="pppoe" | |
209 | fi | |
210 | if [ "$TYPE" == "pptpatm" ]; then | |
211 | TYPE="pptp" | |
212 | fi | |
213 | fi | |
214 | ||
40049855 | 215 | if [ "$TYPE" == "vdsl" ]; then |
7f263dc7 | 216 | boot_mesg "Creating VLAN Interface ${DEVICE}.${INET_VLAN} ..." |
40049855 | 217 | modprobe 8021q |
ff7a3950 | 218 | vconfig add ${DEVICE} ${INET_VLAN} |
1bffb899 | 219 | if [ -n "$MAC1" ]; then |
ff7a3950 AF |
220 | boot_mesg "Setting mac address on ${DEVICE}.${INET_VLAN} to ${MAC1}" |
221 | ip link set dev ${DEVICE}.${INET_VLAN} address ${MAC1} | |
1bffb899 AF |
222 | evaluate_retval |
223 | fi | |
ff7a3950 | 224 | PPP_NIC=${DEVICE}.${INET_VLAN} |
40049855 AF |
225 | sleep 0.2 |
226 | ip link set ${PPP_NIC} up | |
227 | TYPE="pppoe" | |
d0c3a0c5 AF |
228 | fi |
229 | if [ "${IPTV}" == "enable" ]; then | |
18136c5c | 230 | PIDFILE="/var/run/dhcpcd/${DEVICE}.${IPTV_VLAN}.pid" |
ff7a3950 | 231 | LEASEINFO="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info" |
d0c3a0c5 AF |
232 | # Test to see if there is a stale pid file |
233 | if [ -f "$PIDFILE" ]; then | |
234 | ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null | |
235 | if [ $? != 0 ]; then | |
18136c5c | 236 | rm -f /var/run/dhcpcd/${DEVICE}.${IPTV_VLAN}.pid > /dev/null |
bbe6aff7 | 237 | fi |
d0c3a0c5 | 238 | fi |
bbe6aff7 | 239 | |
d0c3a0c5 | 240 | if [ ! -f "$PIDFILE" ]; then |
7f263dc7 | 241 | boot_mesg "Creating VLAN Interface ${DEVICE}.${IPTV_VLAN} ..." |
d0c3a0c5 | 242 | modprobe 8021q |
ff7a3950 | 243 | vconfig add ${DEVICE} ${IPTV_VLAN} |
d0c3a0c5 | 244 | if [ -n "$MAC2" ]; then |
66c36198 | 245 | boot_mesg "Setting mac address on ${DEVICE}.${IPTV_VLAN} to ${MAC2}" |
ff7a3950 | 246 | ip link set dev ${DEVICE}.${IPTV_VLAN} address ${MAC2} |
d0c3a0c5 AF |
247 | evaluate_retval |
248 | fi | |
ff7a3950 AF |
249 | boot_mesg -n "Starting dhcpcd on the ${DEVICE}.${IPTV_VLAN} interface..." |
250 | /sbin/dhcpcd ${DEVICE}.${IPTV_VLAN} ${DHCP_START} >/dev/null 2>&1 | |
d0c3a0c5 | 251 | RET="$?" |
bbe6aff7 | 252 | |
d0c3a0c5 | 253 | if [ "$RET" = "0" ]; then |
ff7a3950 | 254 | . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.${IPTV_VLAN}.info |
d0c3a0c5 AF |
255 | echo "" |
256 | echo_ok | |
ff7a3950 | 257 | boot_mesg " DHCP Assigned Settings for ${DEVICE}.${IPTV_VLAN}:" |
d0c3a0c5 AF |
258 | boot_mesg_flush |
259 | boot_mesg " IP Address: $ip_address" | |
260 | boot_mesg_flush | |
261 | boot_mesg " Hostname: $RED_DHCP_HOSTNAME" | |
262 | boot_mesg_flush | |
263 | boot_mesg " Subnet Mask: $subnet_mask" | |
264 | boot_mesg_flush | |
265 | boot_mesg " Default Gateway: $routers" | |
266 | boot_mesg_flush | |
267 | boot_mesg " DNS Server: $domain_name_servers" | |
268 | boot_mesg_flush | |
bbe6aff7 | 269 | |
d0c3a0c5 AF |
270 | else |
271 | echo "" | |
272 | $(exit "$RET") | |
273 | evaluate_retval | |
bbe6aff7 AF |
274 | fi |
275 | fi | |
40049855 | 276 | fi |
5aae218d | 277 | if [ "$TYPE" == "pppoe" ] || [ "$TYPE" == "pptp" ]; then |
4cd4876a | 278 | if [ "$PPP_NIC" == "" ]; then |
0dde24fa MT |
279 | boot_mesg "No device for red interface given. Check netsetup or dialprofile!" ${FAILURE} |
280 | echo_failure | |
cb1fb691 | 281 | exit 0 |
0dde24fa | 282 | fi |
5aae218d | 283 | boot_mesg "Bringing up the $TYPE interface on $PPP_NIC ..." |
58e9b9dc | 284 | ip addr flush dev $PPP_NIC >/dev/null 2>&1 |
5aae218d | 285 | if [ "$TYPE" == "pptp" ]; then |
fd850b7e | 286 | if [ "$PPTP_NICCFG" == "dhcp" ]; then |
fd850b7e AF |
287 | # Test to see if there is a stale pid file |
288 | if [ -f "$PIDFILE" ]; then | |
289 | ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null | |
290 | if [ $? != 0 ]; then | |
18136c5c | 291 | rm -f /var/run/dhcpcd/${DEVICE}.pid > /dev/null |
fd850b7e AF |
292 | fi |
293 | fi | |
294 | ||
295 | if [ ! -f "$PIDFILE" ]; then | |
d9563c55 | 296 | boot_mesg -n "Starting dhcpcd on the ${DEVICE} interface..." |
367a7770 | 297 | /sbin/dhcpcd ${DEVICE} ${DHCP_START} >/dev/null 2>&1 |
fd850b7e AF |
298 | RET="$?" |
299 | ||
300 | if [ "$RET" = "0" ]; then | |
301 | . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info | |
302 | echo "" | |
303 | echo_ok | |
304 | boot_mesg " DHCP Assigned Settings for ${DEVICE}:" | |
305 | boot_mesg_flush | |
7f8e589b | 306 | boot_mesg " IP Address: $ip_address" |
fd850b7e AF |
307 | boot_mesg_flush |
308 | boot_mesg " Hostname: $RED_DHCP_HOSTNAME" | |
309 | boot_mesg_flush | |
7f8e589b | 310 | boot_mesg " Subnet Mask: $subnet_mask" |
fd850b7e | 311 | boot_mesg_flush |
7f8e589b | 312 | boot_mesg " Default Gateway: $routers" |
fd850b7e | 313 | boot_mesg_flush |
7f8e589b | 314 | boot_mesg " DNS Server: $domain_name_servers" |
fd850b7e | 315 | boot_mesg_flush |
7f8e589b | 316 | /sbin/route add $PPTP_PEER gw $routers $PPP_NIC |
fd850b7e AF |
317 | else |
318 | echo "" | |
319 | $(exit "$RET") | |
320 | evaluate_retval | |
321 | fi | |
322 | fi | |
323 | else | |
324 | ip addr add $PPTP_NICCFG dev $PPP_NIC | |
325 | fi | |
5aae218d | 326 | fi |
58e9b9dc | 327 | ip link set ${PPP_NIC} up |
164a3b51 AF |
328 | if [ -n "${PPTP_ROUTE}" ]; then |
329 | boot_mesg "Set route ${PPTP_ROUTE} to pptp server..." | |
330 | route add ${PPTP_ROUTE} | |
331 | fi | |
27b8cc24 MT |
332 | else |
333 | boot_mesg "Bringing up the PPP via ${TYPE} on ${COMPORT}..." | |
334 | fi | |
66c36198 | 335 | |
905fbf3e MT |
336 | ### ### |
337 | ### Configuring the pppd ### | |
338 | ### ### | |
66c36198 | 339 | |
905fbf3e | 340 | ### Plugin Options |
66c36198 | 341 | # |
5aae218d AF |
342 | if [ "$TYPE" == "pppoe" ]; then |
343 | [ "${METHOD}" == "PPPOE_PLUGIN" ] && \ | |
d94eba78 | 344 | PLUGOPTS="plugin rp-pppoe.so" |
5aae218d | 345 | fi |
d1e90efc | 346 | |
905fbf3e MT |
347 | ### Synchronous Mode |
348 | # | |
349 | #PPPOE_SYNC=-s | |
a89770fa | 350 | #PPPD_SYNC=sync |
66c36198 | 351 | |
a89770fa MT |
352 | ### Access Concentrator Name |
353 | # | |
905fbf3e MT |
354 | if [ -n "${CONCENTRATORNAME}" ]; then |
355 | ACNAME="-C ${CONCENTRATORNAME}" | |
d1e90efc | 356 | fi |
905fbf3e MT |
357 | |
358 | ### Service Name | |
359 | # | |
360 | if [ -n "${SERVICENAME}" ]; then | |
361 | if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then | |
362 | PLUGOPTS+=" rp_pppoe_service ${SERVICENAME}" | |
363 | else | |
364 | SERVICENAME="-S ${SERVICENAME}" | |
365 | fi | |
d1e90efc | 366 | fi |
a89770fa | 367 | |
905fbf3e MT |
368 | ### Authentication Types |
369 | # | |
d1e90efc | 370 | if [ "${AUTH}" == "pap" ]; then |
905fbf3e | 371 | AUTH="-chap" |
d1e90efc | 372 | elif [ "${AUTH}" == "chap" ]; then |
905fbf3e | 373 | AUTH="-pap" |
57cb9775 CS |
374 | else |
375 | AUTH="" | |
d1e90efc | 376 | fi |
a89770fa | 377 | |
66c36198 | 378 | ### Dial On Demand |
905fbf3e | 379 | # |
d1e90efc MT |
380 | if [ "${RECONNECTION}" != "persistent" ]; then |
381 | if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then | |
382 | SECONDS=$[${TIMEOUT} * 60] | |
905fbf3e MT |
383 | else |
384 | SECONDS=300 | |
d1e90efc MT |
385 | fi |
386 | if [ "${RECONNECTION}" == "dialondemand" ]; then | |
387 | touch /var/ipfire/red/dial-on-demand | |
905fbf3e | 388 | DEMAND="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113" |
a89770fa | 389 | DEMAND+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune" |
d1e90efc | 390 | fi |
905fbf3e | 391 | fi |
66c36198 | 392 | |
5aae218d AF |
393 | if [ "$TYPE" == "pppoe" ]; then |
394 | ### When using pppoe-plugin the device has to be the last option | |
395 | # | |
396 | [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS+=" $PPP_NIC" | |
397 | fi | |
66c36198 | 398 | |
27b8cc24 | 399 | if [ "$TYPE" == "modem" ]; then |
a89770fa | 400 | PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts" |
7c653e4b | 401 | METHOD="PPPOE_PLUGIN" |
27b8cc24 | 402 | elif [ "$TYPE" == "serial" ]; then |
a89770fa | 403 | PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts" |
7c653e4b | 404 | METHOD="PPPOE_PLUGIN" |
27b8cc24 | 405 | fi |
66c36198 | 406 | |
905fbf3e MT |
407 | ### Standard PPP options we always use |
408 | # | |
c3ae88ca | 409 | PPP_STD_OPTIONS="$PLUGOPTS usepeerdns defaultroute noipdefault noauth" |
52764dbe | 410 | PPP_STD_OPTIONS+=" default-asyncmap hide-password nodetach noipv6" |
463f9ede | 411 | PPP_STD_OPTIONS+=" noaccomp nodeflate nopcomp novj novjccomp" |
905fbf3e | 412 | PPP_STD_OPTIONS+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20" |
fb27520e | 413 | PPP_STD_OPTIONS+=" lcp-echo-failure 5 ${AUTH}" |
89baf6d5 MT |
414 | |
415 | if [ -n "${MTU}" ]; then | |
416 | PPP_STD_OPTIONS="${PPP_STD_OPTIONS} mtu ${MTU}" | |
417 | fi | |
418 | ||
419 | if [ -n "${MRU}" ]; then | |
420 | PPP_STD_OPTIONS="${PPP_STD_OPTIONS} mru ${MRU}" | |
421 | fi | |
66c36198 | 422 | |
905fbf3e MT |
423 | ### Debugging |
424 | # | |
425 | if [ "${DEBUG}" == "on" ]; then | |
426 | DEBUG="debug" | |
d1e90efc | 427 | else |
905fbf3e | 428 | DEBUG="" |
d1e90efc | 429 | fi |
66c36198 | 430 | |
905fbf3e MT |
431 | ### PPPoE invocation |
432 | # | |
a89770fa MT |
433 | if [ "$TYPE" == "pppoe" ]; then |
434 | PPPOE_CMD="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC" | |
27b8cc24 MT |
435 | PPPOE_CMD+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT" |
436 | fi | |
5aae218d AF |
437 | |
438 | ### PPTP ### | |
439 | # | |
440 | if [ "$TYPE" == "pptp" ]; then | |
441 | PPPOE_CMD="pptp $PPTP_PEER --nolaunchpppd" | |
7c653e4b | 442 | METHOD="" |
5aae218d | 443 | fi |
66c36198 | 444 | |
905fbf3e MT |
445 | ### Run everything |
446 | # | |
7c653e4b | 447 | if [ "$METHOD" == "PPPOE_PLUGIN" ]; then |
905fbf3e MT |
448 | /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND >/dev/null 2>&1 & |
449 | evaluate_retval | |
a89770fa | 450 | # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND |
905fbf3e MT |
451 | else |
452 | /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev/null 2>&1 & | |
453 | evaluate_retval | |
a89770fa | 454 | # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC |
905fbf3e | 455 | fi |
5806ff0c | 456 | |
905fbf3e | 457 | /etc/rc.d/init.d/connectd start |
1f2ff0fa | 458 | # Add a NaN value to ppp0 rrd to supress spikes at reconnect |
c772568a | 459 | rrdtool update $RRDLOG/collectd/localhost/interface/if_octets-ppp0.rrd \ |
49ab1173 | 460 | $(date +%s):: > /dev/null 2>&1 |
28ec28bc | 461 | exit 0 |
d1e90efc | 462 | fi |
d1e90efc MT |
463 | ;; |
464 | ||
465 | stop) | |
ebf64a93 MT |
466 | rm -f /var/ipfire/red/{active,device,dial-on-demand,dns1,dns2,local-ipaddress,remote-ipaddress,resolv.conf} |
467 | ||
d1e90efc | 468 | if [ "$TYPE" == "STATIC" ]; then |
0dde24fa MT |
469 | boot_mesg "Stopping default gateway ${GATEWAY}..." |
470 | ip route del default via ${GATEWAY} >/dev/null 2>&1 | |
471 | echo_ok | |
472 | if [ "$DEVICE" != "${GREEN_DEV}" ]; then | |
70631572 AF |
473 | boot_mesg "Removing IPv4 addresses from the ${DEVICE} interface..." |
474 | ip addr flush dev ${DEVICE} | |
0dde24fa MT |
475 | evaluate_retval |
476 | fi | |
0e42072a | 477 | run_subdir ${rc_base}/init.d/networking/red.down/ |
f8841352 | 478 | |
5aae218d | 479 | elif [ "$TYPE" == "PPPOE" ]; then |
a89770fa | 480 | boot_mesg "Bringing down the PPP interface ..." |
93b34528 | 481 | rm -f /var/ipfire/red/keepconnected |
a89770fa | 482 | killall -w -s TERM /usr/sbin/pppd 2>/dev/null |
352e626f | 483 | evaluate_retval |
1f2ff0fa | 484 | # Add a NaN value to ppp0 rrd to supress spikes at reconnect |
c772568a | 485 | rrdtool update $RRDLOG/collectd/localhost/interface/if_octets-ppp0.rrd \ |
49ab1173 | 486 | $(date +%s):: > /dev/null 2>&1 |
0dde24fa | 487 | |
71ea0d68 SS |
488 | elif [ "$TYPE" == "DHCP" ]; then |
489 | # Check if the wlan-client is used on red. | |
490 | # To determine this we check if a wpa_supplicant is running. | |
491 | pid="$(pidof wpa_supplicant)" | |
492 | ||
493 | if [ -z "${pid}" ]; then | |
494 | # Stop dhcpcd. | |
495 | dhcpcd_stop "${DEVICE}" | |
fd850b7e AF |
496 | fi |
497 | fi | |
498 | ||
164a3b51 AF |
499 | if [ -n "${PPTP_ROUTE}" ]; then |
500 | route del ${PPTP_ROUTE} | |
501 | fi | |
502 | ||
0dde24fa | 503 | if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then |
ff7a3950 | 504 | link_status=`ip link show $DEVICE.${INET_VLAN} 2> /dev/null` |
40049855 AF |
505 | if [ -n "${link_status}" ]; then |
506 | if echo "${link_status}" | grep -q UP; then | |
ff7a3950 AF |
507 | boot_mesg "Bringing down the ${DEVICE}.${INET_VLAN} interface..." |
508 | ip link set ${DEVICE}.${INET_VLAN} down | |
509 | vconfig rem ${DEVICE}.${INET_VLAN} | |
40049855 AF |
510 | evaluate_retval |
511 | fi | |
bbe6aff7 AF |
512 | else |
513 | link_status=`ip link show $DEVICE 2> /dev/null` | |
514 | if [ -n "${link_status}" ]; then | |
515 | if echo "${link_status}" | grep -q UP; then | |
516 | boot_mesg "Bringing down the ${DEVICE} interface..." | |
517 | ip link set ${DEVICE} down | |
518 | evaluate_retval | |
519 | fi | |
0dde24fa | 520 | fi |
d1e90efc MT |
521 | fi |
522 | fi | |
cb1fb691 | 523 | killall -w -s KILL /usr/sbin/pppd >/dev/null 2>&1 |
5aae218d | 524 | killall -w -s KILL pptp >/dev/null 2>&1 |
cb1fb691 | 525 | killall -w -s KILL br2684ctl >/dev/null 2>&1 |
6c33dc5c | 526 | |
6c33dc5c | 527 | exit 0; |
d1e90efc | 528 | ;; |
d1e90efc | 529 | esac |