]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/networking/red
cadac7c49003aa1ed50630f8ee26a1048aebeb43
2 ########################################################################
5 # Description : RED Device Script
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
16 ########################################################################
24 RED_VDSL_IPTV_DISABLE
=0
26 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/main
/settings
)
27 if [ "$RRDLOG" == "" ]; then
31 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
32 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/dns
/settings
)
33 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/mac
/settings
)
36 MAC1
=$
(tr - : <<<$MAC1)
37 MAC2
=$
(tr - : <<<$MAC2)
42 if [ "$TYPE" == "STATIC" ] ||
[ "$TYPE" == "DHCP" ]; then
43 if [ "$DEVICE" == "" ]; then
44 boot_mesg
"No device for red network. Please run setup." ${FAILURE}
46 [ "${1}" == "start" ] && exit 0
50 if [ "${TYPE}" == "STATIC" ]; then
51 if [ "${DEVICE}" != "${GREEN_DEV}" ]; then
52 ADDRESS
="${RED_ADDRESS}"
53 BROADCAST
="${RED_BROADCAST}"
54 NETADDRESS
="${RED_NETADDRESS}"
55 NETMASK
="${RED_NETMASK}"
57 ADDRESS
="${GREEN_ADDRESS}"
58 BROADCAST
="${GREEN_BROADCAST}"
59 NETADDRESS
="${GREEN_NETADDRESS}"
60 NETMASK
="${GREEN_NETMASK}"
62 GATEWAY
="${DEFAULT_GATEWAY}"
66 if [ -z "${BROADCAST}" ]; then
67 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
71 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
72 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
73 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
75 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
81 PIDFILE
="/var/run/dhcpcd-${DEVICE}.pid"
82 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
88 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
89 boot_mesg
"Bringing up the ${DEVICE} interface..."
91 # Check if an interface is there...
92 if ip link show
${DEVICE} > /dev
/null
2>&1; then
93 link_status
=`ip link show ${DEVICE} 2> /dev/null`
94 if [ -n "${link_status}" ]; then
95 if ! echo "${link_status}" |
grep -q UP
; then
96 if [ -n "$MAC" ]; then
97 boot_mesg
"Setting mac address on ${DEVICE} to ${MAC}"
98 ip link
set dev
${DEVICE} address
${MAC}
101 ip link
set ${DEVICE} up
105 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
111 ## Create & Enable vnstat
112 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
114 if [ "${TYPE}" == "STATIC" ]; then
116 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
117 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
118 ip addr add
${args} dev
${DEVICE}
121 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
122 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
123 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
124 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
125 echo "$GATEWAY gateway" >> /tmp
/hosts
126 mv /tmp
/hosts
/etc
/hosts
127 echo -n "${DNS1}" > /var
/ipfire
/red
/dns1
128 echo -n "${DNS2}" > /var
/ipfire
/red
/dns2
129 touch /var
/ipfire
/red
/active
131 boot_mesg
"Setting up default gateway ${GATEWAY}..."
132 ip route add default via
${GATEWAY} dev
${DEVICE}
135 run_subdir
${rc_base}/init.d
/networking
/red.up
/
137 # Configure aliases only if red static
138 /usr
/local
/bin
/setaliases
140 elif [ "${TYPE}" == "DHCP" ]; then
142 if [ -e $LEASEINFO ]; then
143 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
145 if [ "$dhcp_lease_time" = "4294967295" ]; then
146 # do nothing, just echo ok
150 if [ -n "$DHCP_STOP" ]; then
151 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
153 if [ "$RET" -eq 0 ]; then
156 elif [ "$RET" -eq 1 ]; then
157 boot_mesg
"dhcpcd not running!" ${WARNING}
170 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
171 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
173 ## Create & Enable vnstat
174 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
176 # Test to see if there is a stale pid file
177 if [ -f "$PIDFILE" ]; then
178 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
180 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
182 boot_mesg
"dhcpcd already running!" ${WARNING}
188 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
189 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
191 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
192 DHCP_START
+="-h ${RED_DHCP_HOSTNAME} "
195 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
198 if [ "$RET" = "0" ]; then
199 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
202 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
204 boot_mesg
" IP Address: $ip_address"
206 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
207 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
210 boot_mesg
" Subnet Mask: $subnet_mask"
212 boot_mesg
" Default Gateway: $routers"
214 boot_mesg
" DNS Server: $domain_name_servers"
222 elif [ "$TYPE" == "PPPOE" ]; then
224 if ( ps ax |
grep -q [p
]ppd
); then
225 boot_mesg
"pppd is still running." ${FAILURE}
230 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
232 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
236 if [ "$TYPE" == "vdsl" ]; then
237 boot_mesg
"Createing VLAN Interface ${DEVICE}.${RED_VDSL_INET_VLAN} ..."
239 vconfig add
${DEVICE} ${RED_VDSL_INET_VLAN}
240 if [ -n "$MAC1" ]; then
241 boot_mesg
"Setting mac address on ${DEVICE}.${RED_VDSL_INET_VLAN} to ${MAC1}"
242 ip link
set dev
${DEVICE}.${RED_VDSL_INET_VLAN} address ${MAC1}
245 PPP_NIC
=${DEVICE}.
${RED_VDSL_INET_VLAN}
247 ip link
set ${PPP_NIC} up
249 if [ "${RED_VDSL_IPTV_DISABLE}" == "0" ]; then
250 PIDFILE
="/var/run/dhcpcd-${DEVICE}.${RED_VDSL_IPTV_VLAN}.pid"
251 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${RED_VDSL_IPTV_VLAN}.info"
254 # Test to see if there is a stale pid file
255 if [ -f "$PIDFILE" ]; then
256 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
258 rm -f /var
/run
/dhcpcd-
${DEVICE}.
${RED_VDSL_IPTV_VLAN}.pid
> /dev
/null
262 if [ ! -f "$PIDFILE" ]; then
263 boot_mesg
"Createing VLAN Interface ${DEVICE}.${RED_VDSL_IPTV_VLAN} ..."
264 vconfig add
${DEVICE} ${RED_VDSL_IPTV_VLAN}
265 if [ -n "$MAC2" ]; then
266 boot_mesg
"Setting mac address on ${DEVICE}.${RED_VDSL_IPTV_VLAN} to ${MAC2}"
267 ip link
set dev
${DEVICE}.${RED_VDSL_IPTV_VLAN} address ${MAC2}
270 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.${RED_VDSL_IPTV_VLAN} interface..."
271 /sbin
/dhcpcd
${DEVICE}.${RED_VDSL_IPTV_VLAN} ${DHCP_START} >/dev
/null
2>&1
274 if [ "$RET" = "0" ]; then
275 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.
${RED_VDSL_IPTV_VLAN}.info
278 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.${RED_VDSL_IPTV_VLAN}:"
280 boot_mesg
" IP Address: $ip_address"
282 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
284 boot_mesg
" Subnet Mask: $subnet_mask"
286 boot_mesg
" Default Gateway: $routers"
288 boot_mesg
" DNS Server: $domain_name_servers"
300 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
302 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
303 br2684ctl
-c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev
/null
2>&1 &
305 if [ "$TYPE" == "pppoeatm" ]; then
308 if [ "$TYPE" == "pptpatm" ]; then
312 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
313 if [ "$PPP_NIC" == "" ]; then
314 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
318 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
319 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
320 if [ "$TYPE" == "pptp" ]; then
321 if [ "$PPTP_NICCFG" == "dhcp" ]; then
322 DHCP_START
="-N -R -L /var/ipfire/dhcpc "
325 # Test to see if there is a stale pid file
326 if [ -f "$PIDFILE" ]; then
327 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
329 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
333 if [ ! -f "$PIDFILE" ]; then
334 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
335 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
338 if [ "$RET" = "0" ]; then
339 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
342 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
344 boot_mesg
" IP Address: $IPADDR"
346 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
348 boot_mesg
" Subnet Mask: $NETMASK"
350 boot_mesg
" Default Gateway: $GATEWAY"
352 boot_mesg
" DNS Server: $DNS"
354 /sbin
/route add
$PPTP_PEER gw
$GATEWAY $PPP_NIC
362 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
365 ip link
set ${PPP_NIC} up
367 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
371 ### Configuring the pppd ###
376 if [ "$TYPE" == "pppoe" ]; then
377 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
378 PLUGOPTS
="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so"
386 ### Access Concentrator Name
388 if [ -n "${CONCENTRATORNAME}" ]; then
389 ACNAME
="-C ${CONCENTRATORNAME}"
394 if [ -n "${SERVICENAME}" ]; then
395 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
396 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
398 SERVICENAME
="-S ${SERVICENAME}"
402 ### Authentication Types
404 if [ "${AUTH}" == "pap" ]; then
406 elif [ "${AUTH}" == "chap" ]; then
414 if [ "${DNS}" == "Automatic" ]; then
418 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
419 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
424 if [ "${RECONNECTION}" != "persistent" ]; then
425 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
426 SECONDS
=$
[${TIMEOUT} * 60]
430 if [ "${RECONNECTION}" == "dialondemand" ]; then
431 touch /var
/ipfire
/red
/dial-on-demand
432 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
433 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
437 if [ "$TYPE" == "pppoe" ]; then
438 ### When using pppoe-plugin the device has to be the last option
440 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
443 if [ "$TYPE" == "modem" ]; then
444 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
445 METHOD
="PPPOE_PLUGIN"
446 elif [ "$TYPE" == "serial" ]; then
447 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
448 METHOD
="PPPOE_PLUGIN"
451 ### Standard PPP options we always use
453 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
454 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach mtu ${MTU}"
455 PPP_STD_OPTIONS
+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
456 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
457 PPP_STD_OPTIONS
+=" lcp-echo-failure 3 ${AUTH}"
461 if [ "${DEBUG}" == "on" ]; then
469 if [ "$TYPE" == "pppoe" ]; then
470 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
471 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
476 if [ "$TYPE" == "pptp" ]; then
477 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
483 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
484 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
486 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
488 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
490 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
492 ## Create & Enable vnstat
493 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
494 /etc
/rc.d
/init.d
/connectd start
495 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
496 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
497 $
(date +%s
):: > /dev
/null
2>&1
503 if [ "$TYPE" == "STATIC" ]; then
504 boot_mesg
"Stopping default gateway ${GATEWAY}..."
505 ip route del default via
${GATEWAY} >/dev
/null
2>&1
507 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
508 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
509 ip addr flush dev
${DEVICE}
512 run_subdir
${rc_base}/init.d
/networking
/red.down
/
514 elif [ "$TYPE" == "PPPOE" ]; then
515 boot_mesg
"Bringing down the PPP interface ..."
516 ## Disable vnstat collection
517 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
518 rm -f /var
/ipfire
/red
/keepconnected
519 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
521 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
522 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
523 $
(date +%s
):: > /dev
/null
2>&1
526 if [ -e $LEASEINFO ]; then
527 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
529 if [ "$dchp_lease_time" = "4294967295" ]; then
530 # do nothing, just echo ok
534 if [ -n "$DHCP_STOP" ]; then
535 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
537 if [ "$RET" -eq 0 ]; then
540 elif [ "$RET" -eq 1 ]; then
541 boot_mesg
"dhcpcd not running!" ${WARNING}
554 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
555 link_status
=`ip link show $DEVICE.${RED_VDSL_INET_VLAN} 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}.${RED_VDSL_INET_VLAN} interface..."
559 ip link
set ${DEVICE}.
${RED_VDSL_INET_VLAN} down
560 vconfig rem
${DEVICE}.
${RED_VDSL_INET_VLAN}
564 link_status
=`ip link show $DEVICE 2> /dev/null`
565 if [ -n "${link_status}" ]; then
566 if echo "${link_status}" |
grep -q UP
; then
567 boot_mesg
"Bringing down the ${DEVICE} interface..."
568 ip link
set ${DEVICE} down
574 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
575 killall
-w -s KILL pptp
>/dev
/null
2>&1
576 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
578 ## Disable vnstat collection
579 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
581 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}