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