]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/initscripts/init.d/networking/red
corrected mpfire stream url
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / networking / red
CommitLineData
d1e90efc
MT
1#!/bin/sh
2########################################################################
3# Begin
4#
5# Description : RED Device Script
6#
7# Authors : Michael Tremer - mitch@ipfire.org
8# Maniacikarus - maniacikarus@ipfire.org
9# Inspired by : Nathan Coulson - nathan@linuxfromscratch.org
10# Kevin P. Fleming - kpfleming@linuxfromscratch.org
11#
12# Version : 01.00
13#
14# Notes :
15#
16########################################################################
17
18. /etc/sysconfig/rc
19. ${rc_functions}
20eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
21
22TYPE="${RED_TYPE}"
23DEVICE="${RED_DEV}"
24
25if [ "$TYPE" == "STATIC" ]; then
26 ADDRESS="${RED_ADDRESS}"
27 BROADCAST="${RED_BROADCAST}"
28 NETADDRESS="${RED_NETADDRESS}"
29 NETMASK="${RED_NETMASK}"
30 GATEWAY="${DEFAULT_GATEWAY}"
0db33b56
MT
31 # DNS1
32 # DNS2
d1e90efc
MT
33
34 if [ -z "${BROADCAST}" ]; then
35 boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE}
36 echo_failure
37 exit 1
38 fi
39 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
40 PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
41 args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
42 else
43 boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
44 echo_failure
45 exit 1
46 fi
47
48elif [ "${TYPE}" == "DHCP" ]; then
49
50 PIDFILE="/var/run/dhcpcd-${DEVICE}.pid"
51 LEASEINFO="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
52 DHCP_START="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
53 DHCP_STOP="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
54
55fi
56
57case "${1}" in
58 start)
59 boot_mesg "Bringing up the ${DEVICE} interface..."
60 boot_mesg_flush
61
62 # Check if an interface is there...
63 if ip link show ${DEVICE} > /dev/null 2>&1; then
64 link_status=`ip link show ${DEVICE} 2> /dev/null`
65 if [ -n "${link_status}" ]; then
66 if ! echo "${link_status}" | grep -q UP; then
67 ip link set ${DEVICE} up
68 fi
69 fi
70 else
71 boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE}
72 echo_failure
73 exit 1
74 fi
75
76 if [ "${TYPE}" == "STATIC" ]; then
77 boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
78 ip addr add ${args} dev ${DEVICE}
79 evaluate_retval
0db33b56
MT
80 echo -n "${DEVICE}" > /var/ipfire/red/iface
81 echo -n "${ADDRESS}" > /var/ipfire/red/local-ipaddress
82 echo -n "${GATEWAY}" > /var/ipfire/red/remote-ipaddress
83 echo -n "${DNS1}" > /var/ipfire/red/dns1
84 echo -n "${DNS2}" > /var/ipfire/red/dns2
bcdde652 85 touch /var/ipfire/red/active
d1e90efc 86
040e5040
MT
87 boot_mesg "Setting up default gateway ${GATEWAY}..."
88 ip route add default via ${GATEWAY} dev ${DEVICE}
89 evaluate_retval
90
0e42072a
MT
91 run_subdir ${rc_base}/init.d/networking/red.up/
92
d1e90efc
MT
93 elif [ "${TYPE}" == "DHCP" ]; then
94 boot_mesg -n "Starting dhcpcd on the ${DEVICE} interface..."
95 echo -n "${DEVICE}" > /var/ipfire/red/iface
96
97 # Test to see if there is a stale pid file
98 if [ -f "$PIDFILE" ]; then
99 ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null
100 if [ $? != 0 ]; then
101 rm -f /var/run/dhcpcd-${DEVICE}.pid > /dev/null
102 else
103 boot_mesg "dhcpcd already running!" ${WARNING}
104 echo_warning
105 exit 2
106 fi
107 fi
108
109 iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
110 iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
111
112 if [ -n "${DHCP_HOSTNAME}" ]; then
113 DHCP_START+="-h ${DHCP_HOSTNAME} "
114 fi
115
116 /sbin/dhcpcd ${DEVICE} ${DHCP_START} >/dev/null 2>&1
117 RET="$?"
118
119 if [ "$RET" = "0" ]; then
120 . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info
121 echo ""
122 echo_ok
123 boot_mesg " DHCP Assigned Settings for ${DEVICE}:"
124 boot_mesg_flush
125 boot_mesg " IP Address: $IPADDR"
126 boot_mesg_flush
127 if [ -n "${DHCP_HOSTNAME}" ]; then
128 boot_mesg " Hostname: $DHCP_HOSTNAME"
129 boot_mesg_flush
130 fi
131 boot_mesg " Subnet Mask: $NETMASK"
132 boot_mesg_flush
133 boot_mesg " Default Gateway: $GATEWAY"
134 boot_mesg_flush
135 boot_mesg " DNS Server: $DNS"
136 boot_mesg_flush
137
138 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var/ipfire/red/dns1
139 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var/ipfire/red/dns2
140
141 . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.info
142 echo "$IPADDR" > /var/ipfire/red/local-ipaddress
143 echo "$GATEWAY" > /var/ipfire/red/remote-ipaddress
144 else
145 echo ""
146 $(exit "$RET")
147 evaluate_retval
148 fi
149
150 elif [ "$TYPE" == "PPPOE" ]; then
a89770fa
MT
151
152 if ( ps ax | grep -q [p]ppd ); then
153 echo Error! A pppd is still running. Stop it first.
154 echo
155 exit 1;
156 fi
d1e90efc
MT
157 eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
158
905fbf3e 159 [ -c "/dev/ppp" ] || mknod /dev/ppp c 108 0
d1e90efc 160
a89770fa
MT
161 PPP_NIC=${DEVICE}
162
163 if [ "$TYPE" == "pppoeatm" ]; then
164 PPP_NIC=nas0
165 boot_mesg "Create ATM-Bridge as $PPP_NIC ..."
166 br2684ctl -c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev/null 2>&1 &
167 sleep 1
168 ifconfig $PPP_NIC up
169 TYPE="pppoe"
170 fi
171 if [ "$TYPE" == "pppoe" ]; then
172 boot_mesg "Bringing up the PPPoE interface on $PPP_NIC ..."
173 ip addr add 1.1.1.1/24 broadcast 1.1.1.255 dev $PPP_NIC
27b8cc24
MT
174 else
175 boot_mesg "Bringing up the PPP via ${TYPE} on ${COMPORT}..."
176 fi
905fbf3e
MT
177 ### ###
178 ### Configuring the pppd ###
179 ### ###
180
181 ### Plugin Options
182 #
183 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
a89770fa
MT
184 PLUGOPTS="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so"
185
186 # PLUGOPTS="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so nic-$PPP_NIC"
d1e90efc 187
905fbf3e
MT
188 ### Synchronous Mode
189 #
190 #PPPOE_SYNC=-s
a89770fa
MT
191 #PPPD_SYNC=sync
192
193 ### Access Concentrator Name
194 #
905fbf3e
MT
195 if [ -n "${CONCENTRATORNAME}" ]; then
196 ACNAME="-C ${CONCENTRATORNAME}"
d1e90efc 197 fi
905fbf3e
MT
198
199 ### Service Name
200 #
201 if [ -n "${SERVICENAME}" ]; then
202 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
203 PLUGOPTS+=" rp_pppoe_service ${SERVICENAME}"
204 else
205 SERVICENAME="-S ${SERVICENAME}"
206 fi
d1e90efc 207 fi
a89770fa 208
905fbf3e
MT
209 ### Authentication Types
210 #
d1e90efc 211 if [ "${AUTH}" == "pap" ]; then
905fbf3e 212 AUTH="-chap"
d1e90efc 213 elif [ "${AUTH}" == "chap" ]; then
905fbf3e 214 AUTH="-pap"
57cb9775
CS
215 else
216 AUTH=""
d1e90efc 217 fi
a89770fa
MT
218
219 ### DNS Config
220 #
221 if [ "${DNS}" == "Automatic" ]; then
222 DNS="usepeerdns"
223 else
224 DNS=""
225 echo nameserver=$DNS1 > /etc/ppp/resolv.conf
226 echo nameserver=$DNS2 >> /etc/ppp/resolv.conf
227
228 fi
229
905fbf3e
MT
230 ### Dial On Demand
231 #
d1e90efc
MT
232 if [ "${RECONNECTION}" != "persistent" ]; then
233 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
234 SECONDS=$[${TIMEOUT} * 60]
905fbf3e
MT
235 else
236 SECONDS=300
d1e90efc
MT
237 fi
238 if [ "${RECONNECTION}" == "dialondemand" ]; then
239 touch /var/ipfire/red/dial-on-demand
905fbf3e 240 DEMAND="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
a89770fa 241 DEMAND+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
d1e90efc 242 fi
905fbf3e
MT
243 fi
244
27b8cc24 245 ### When using pppoe-plugin the device has to be the last option
905fbf3e 246 #
a89770fa 247 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS+=" $PPP_NIC"
27b8cc24
MT
248
249 if [ "$TYPE" == "modem" ]; then
a89770fa 250 PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
27b8cc24 251 elif [ "$TYPE" == "serial" ]; then
a89770fa 252 PLUGOPTS=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
27b8cc24 253 fi
905fbf3e
MT
254
255 ### Standard PPP options we always use
256 #
a89770fa 257 PPP_STD_OPTIONS="$PLUGOPTS $DNS defaultroute noipdefault noauth"
905fbf3e
MT
258 PPP_STD_OPTIONS+=" default-asyncmap hide-password nodetach mtu ${MTU}"
259 PPP_STD_OPTIONS+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
260 PPP_STD_OPTIONS+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
261 PPP_STD_OPTIONS+=" lcp-echo-failure 3 ${AUTH}"
a89770fa 262
905fbf3e
MT
263 ### Debugging
264 #
265 if [ "${DEBUG}" == "on" ]; then
266 DEBUG="debug"
d1e90efc 267 else
905fbf3e 268 DEBUG=""
d1e90efc
MT
269 fi
270
905fbf3e
MT
271 ### PPPoE invocation
272 #
a89770fa
MT
273 if [ "$TYPE" == "pppoe" ]; then
274 PPPOE_CMD="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
27b8cc24
MT
275 PPPOE_CMD+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
276 fi
d1e90efc 277
905fbf3e
MT
278 ### Run everything
279 #
280 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
281 /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND >/dev/null 2>&1 &
282 evaluate_retval
a89770fa 283 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
905fbf3e
MT
284 else
285 /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev/null 2>&1 &
286 evaluate_retval
a89770fa 287 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
905fbf3e
MT
288 fi
289
290 /etc/rc.d/init.d/connectd start
291
d1e90efc 292 fi
d1e90efc
MT
293 ;;
294
295 stop)
296 if [ "$TYPE" == "STATIC" ]; then
297 boot_mesg "Removing IPv4 address ${ADDRESS} from the ${DEVICE} interface..."
298 ip addr del ${args} dev ${DEVICE}
299 evaluate_retval
300
0e42072a
MT
301 run_subdir ${rc_base}/init.d/networking/red.down/
302
d1e90efc
MT
303 elif [ "$TYPE" == "DHCP" ]; then
304 boot_mesg -n "Stopping dhcpcd on the ${DEVICE} interface..."
305 if [ -e $LEASEINFO ]; then
306 . $LEASEINFO
307 if [ "$LEASETIME" = "4294967295" ]; then
308 # do nothing, just echo ok
309 echo ""
310 echo_ok
311 else
312 if [ -n "$DHCP_STOP" ]; then
313 /sbin/dhcpcd ${DEVICE} $DHCP_STOP &> /dev/null
314 RET="$?"
315 if [ "$RET" -eq 0 ]; then
316 echo ""
317 echo_ok
318 elif [ "$RET" -eq 1 ]; then
319 boot_mesg "dhcpcd not running!" ${WARNING}
320 echo_warning
321 else
322 echo ""
323 echo_failure
324 fi
325 else
326 echo ""
327 killproc dhcpcd
328 fi
329 fi
330 else
331 boot_mesg -n "LEASEINFO Test failed! - " ${WARNING}
332 boot_mesg "dhcpcd is not running!" ${WARNING}
333 echo_warning
334 exit 1
335 fi
336
337 elif [ "$TYPE" == "PPPOE" ]; then
a89770fa 338 boot_mesg "Bringing down the PPP interface ..."
93b34528 339 rm -f /var/ipfire/red/keepconnected
a89770fa 340 killall -w -s TERM /usr/sbin/pppd 2>/dev/null
352e626f 341 evaluate_retval
a89770fa 342 killall -w -s TERM br2684ctl >/dev/null 2>&1
d1e90efc
MT
343 ip addr del 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE}
344
345 fi
346
347 link_status=`ip link show $DEVICE 2> /dev/null`
348 if [ -n "${link_status}" ]; then
349 if echo "${link_status}" | grep -q UP; then
350 boot_mesg "Bringing down the ${DEVICE} interface..."
351 ip link set ${DEVICE} down
352 evaluate_retval
353 fi
354 fi
355
f480386f 356 rm -f /var/ipfire/red/{active,device,dial-on-demand,dns1,dns2,local-ipaddress,remote-ipaddress,resolv.conf}
d1e90efc
MT
357 ;;
358
359esac
360
361# End