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