]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/networking/red
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
)
40 if [ "$TYPE" == "STATIC" ] ||
[ "$TYPE" == "DHCP" ]; then
41 if [ "$DEVICE" == "" ]; then
42 boot_mesg
"No device for red network. Please run setup." ${FAILURE}
44 [ "${1}" == "start" ] && exit 0
48 if [ "${TYPE}" == "STATIC" ]; then
49 if [ "${DEVICE}" != "${GREEN_DEV}" ]; then
50 ADDRESS
="${RED_ADDRESS}"
51 BROADCAST
="${RED_BROADCAST}"
52 NETADDRESS
="${RED_NETADDRESS}"
53 NETMASK
="${RED_NETMASK}"
55 ADDRESS
="${GREEN_ADDRESS}"
56 BROADCAST
="${GREEN_BROADCAST}"
57 NETADDRESS
="${GREEN_NETADDRESS}"
58 NETMASK
="${GREEN_NETMASK}"
60 GATEWAY
="${DEFAULT_GATEWAY}"
64 if [ -z "${BROADCAST}" ]; then
65 boot_mesg
"BROADCAST variable missing, cannot continue." ${FAILURE}
69 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
70 PREFIX
=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
71 args
="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
73 boot_mesg
"ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
78 elif [ "${TYPE}" == "DHCP" ]; then
80 PIDFILE
="/var/run/dhcpcd-${DEVICE}.pid"
81 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.info"
82 DHCP_START
="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
83 DHCP_STOP
="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
89 if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
90 boot_mesg
"Bringing up the ${DEVICE} interface..."
92 # Check if an interface is there...
93 if ip link show
${DEVICE} > /dev
/null
2>&1; then
94 link_status
=`ip link show ${DEVICE} 2> /dev/null`
95 if [ -n "${link_status}" ]; then
96 if ! echo "${link_status}" |
grep -q UP
; then
97 if [ -n "$MAC" ]; then
98 boot_mesg
"Setting mac address on ${DEVICE} to ${MAC}"
99 ip link
set dev
${DEVICE} address
${MAC}
103 ip link
set ${DEVICE} up
107 boot_mesg
"Interface ${DEVICE} doesn't exist." ${FAILURE}
113 ## Create & Enable vnstat
114 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
116 if [ "${TYPE}" == "STATIC" ]; then
118 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
119 boot_mesg
"Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
120 ip addr add
${args} dev
${DEVICE}
123 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
124 echo -n "${ADDRESS}" > /var
/ipfire
/red
/local-ipaddress
125 echo -n "${GATEWAY}" > /var
/ipfire
/red
/remote-ipaddress
126 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
127 echo "$GATEWAY gateway" >> /tmp
/hosts
128 mv /tmp
/hosts
/etc
/hosts
129 echo -n "${DNS1}" > /var
/ipfire
/red
/dns1
130 echo -n "${DNS2}" > /var
/ipfire
/red
/dns2
131 touch /var
/ipfire
/red
/active
133 boot_mesg
"Setting up default gateway ${GATEWAY}..."
134 ip route add default via
${GATEWAY} dev
${DEVICE}
137 run_subdir
${rc_base}/init.d
/networking
/red.up
/
139 # Configure aliases only if red static
140 /usr
/local
/bin
/setaliases
142 elif [ "${TYPE}" == "DHCP" ]; then
144 if [ -e $LEASEINFO ]; then
145 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
147 if [ "$LEASETIME" = "4294967295" ]; then
148 # do nothing, just echo ok
152 if [ -n "$DHCP_STOP" ]; then
153 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
155 if [ "$RET" -eq 0 ]; then
158 elif [ "$RET" -eq 1 ]; then
159 boot_mesg
"dhcpcd not running!" ${WARNING}
172 boot_mesg
-n "Starting dhcpcd on the ${DEVICE} interface..."
173 echo -n "${DEVICE}" > /var
/ipfire
/red
/iface
175 ## Create & Enable vnstat
176 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --enable --force > /dev
/null
2>&1
178 # Test to see if there is a stale pid file
179 if [ -f "$PIDFILE" ]; then
180 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
182 rm -f /var
/run
/dhcpcd-
${DEVICE}.pid
> /dev
/null
184 boot_mesg
"dhcpcd already running!" ${WARNING}
190 iptables
-A REDINPUT
-p tcp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
191 iptables
-A REDINPUT
-p udp
--source-port 67 --destination-port 68 -i ${DEVICE} -j ACCEPT
193 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
194 DHCP_START
+="-h ${RED_DHCP_HOSTNAME} "
197 /sbin
/dhcpcd
${DEVICE} ${DHCP_START} >/dev
/null
2>&1
200 if [ "$RET" = "0" ]; then
201 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
204 boot_mesg
" DHCP Assigned Settings for ${DEVICE}:"
206 boot_mesg
" IP Address: $IPADDR"
208 if [ -n "${RED_DHCP_HOSTNAME}" ]; then
209 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
212 boot_mesg
" Subnet Mask: $NETMASK"
214 boot_mesg
" Default Gateway: $GATEWAY"
216 boot_mesg
" DNS Server: $DNS"
218 if [ -n "$DNS0" ] && [ -n "$DNS1" ]; then
219 boot_mesg
"Overwritting DNS-Server addresses with ${DNS0},${DNS1}"
220 echo -n ${DNS0} > /var
/ipfire
/red
/dns1
221 echo -n ${DNS1} > /var
/ipfire
/red
/dns2
224 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 1` > /var
/ipfire
/red
/dns1
225 echo -n `/etc/rc.d/helper/getdnsfromdhcpc.pl 2` > /var
/ipfire
/red
/dns2
228 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.info
229 echo "$IPADDR" > /var
/ipfire
/red
/local-ipaddress
230 grep -v "gateway" /etc
/hosts
> /tmp
/hosts
231 echo "$GATEWAY gateway" >> /tmp
/hosts
232 mv /tmp
/hosts
/etc
/hosts
233 echo "$GATEWAY" > /var
/ipfire
/red
/remote-ipaddress
234 touch /var
/ipfire
/red
/active
241 elif [ "$TYPE" == "PPPOE" ]; then
243 if ( ps ax |
grep -q [p
]ppd
); then
244 boot_mesg
"pppd is still running." ${FAILURE}
249 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ppp
/settings
)
251 [ -c "/dev/ppp" ] || mknod
/dev
/ppp c
108 0
255 if [ "$TYPE" == "vdsl" ]; then
256 boot_mesg
"Createing VLAN Interface ${DEVICE}.${RED_VDSL_INET_VLAN} ..."
258 vconfig add
${DEVICE} ${RED_VDSL_INET_VLAN}
259 PPP_NIC
=${DEVICE}.
${RED_VDSL_INET_VLAN}
261 ip link
set ${PPP_NIC} up
264 if [ "${RED_VDSL_IPTV_DISABLE}" == "0" ]; then
265 PIDFILE
="/var/run/dhcpcd-${DEVICE}.${RED_VDSL_IPTV_VLAN}.pid"
266 LEASEINFO
="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.${RED_VDSL_IPTV_VLAN}.info"
267 DHCP_START
="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
268 DHCP_STOP
="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
270 # Test to see if there is a stale pid file
271 if [ -f "$PIDFILE" ]; then
272 ps
`cat "$PIDFILE"` |
grep dhcpcd
> /dev
/null
274 rm -f /var
/run
/dhcpcd-
${DEVICE}.
${RED_VDSL_IPTV_VLAN}.pid
> /dev
/null
278 if [ ! -f "$PIDFILE" ]; then
279 boot_mesg
"Createing VLAN Interface ${DEVICE}.${RED_VDSL_IPTV_VLAN} ..."
280 vconfig add
${DEVICE} ${RED_VDSL_IPTV_VLAN}
281 boot_mesg
-n "Starting dhcpcd on the ${DEVICE}.${RED_VDSL_IPTV_VLAN} interface..."
282 /sbin
/dhcpcd
${DEVICE}.${RED_VDSL_IPTV_VLAN} ${DHCP_START} >/dev
/null
2>&1
285 if [ "$RET" = "0" ]; then
286 .
/var
/ipfire
/dhcpc
/dhcpcd-
${DEVICE}.
${RED_VDSL_IPTV_VLAN}.info
289 boot_mesg
" DHCP Assigned Settings for ${DEVICE}.${RED_VDSL_IPTV_VLAN}:"
291 boot_mesg
" IP Address: $IPADDR"
293 boot_mesg
" Hostname: $RED_DHCP_HOSTNAME"
295 boot_mesg
" Subnet Mask: $NETMASK"
297 boot_mesg
" Default Gateway: $GATEWAY"
299 boot_mesg
" DNS Server: $DNS"
311 if [ "$TYPE" == "pppoeatm" ] ||
[ "$TYPE" == "pptpatm" ]; then
313 boot_mesg
"Createing ATM-Bridge as $PPP_NIC ..."
314 br2684ctl
-c0 -e${ENCAP} -a0.${VPI}.${VCI} >/dev
/null
2>&1 &
316 if [ "$TYPE" == "pppoeatm" ]; then
319 if [ "$TYPE" == "pptpatm" ]; then
323 if [ "$TYPE" == "pppoe" ] ||
[ "$TYPE" == "pptp" ]; then
324 if [ "$PPP_NIC" == "" ]; then
325 boot_mesg
"No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
329 boot_mesg
"Bringing up the $TYPE interface on $PPP_NIC ..."
330 ip addr flush dev
$PPP_NIC >/dev
/null
2>&1
331 if [ "$TYPE" == "pptp" ]; then
332 ip addr add
$PPTP_NICCFG dev
$PPP_NIC
334 ip link
set ${PPP_NIC} up
336 boot_mesg
"Bringing up the PPP via ${TYPE} on ${COMPORT}..."
340 ### Configuring the pppd ###
345 if [ "$TYPE" == "pppoe" ]; then
346 [ "${METHOD}" == "PPPOE_PLUGIN" ] && \
347 PLUGOPTS
="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so"
355 ### Access Concentrator Name
357 if [ -n "${CONCENTRATORNAME}" ]; then
358 ACNAME
="-C ${CONCENTRATORNAME}"
363 if [ -n "${SERVICENAME}" ]; then
364 if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
365 PLUGOPTS
+=" rp_pppoe_service ${SERVICENAME}"
367 SERVICENAME
="-S ${SERVICENAME}"
371 ### Authentication Types
373 if [ "${AUTH}" == "pap" ]; then
375 elif [ "${AUTH}" == "chap" ]; then
383 if [ "${DNS}" == "Automatic" ]; then
387 echo nameserver
=$DNS1 > /etc
/ppp
/resolv.conf
388 echo nameserver
=$DNS2 >> /etc
/ppp
/resolv.conf
393 if [ "${RECONNECTION}" != "persistent" ]; then
394 if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
395 SECONDS
=$
[${TIMEOUT} * 60]
399 if [ "${RECONNECTION}" == "dialondemand" ]; then
400 touch /var
/ipfire
/red
/dial-on-demand
401 DEMAND
="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
402 DEMAND
+=" ipcp-accept-remote ipcp-accept-local noipdefault ktune"
406 if [ "$TYPE" == "pppoe" ]; then
407 ### When using pppoe-plugin the device has to be the last option
409 [ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS
+=" $PPP_NIC"
412 if [ "$TYPE" == "modem" ]; then
413 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /etc/ppp/dialer lock modem crtscts"
414 METHOD
="PPPOE_PLUGIN"
415 elif [ "$TYPE" == "serial" ]; then
416 PLUGOPTS
=" /dev/${COMPORT} ${DTERATE} connect /bin/true lock modem crtscts"
417 METHOD
="PPPOE_PLUGIN"
420 ### Standard PPP options we always use
422 PPP_STD_OPTIONS
="$PLUGOPTS $DNS defaultroute noipdefault noauth"
423 PPP_STD_OPTIONS
+=" default-asyncmap hide-password nodetach mtu ${MTU}"
424 PPP_STD_OPTIONS
+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
425 PPP_STD_OPTIONS
+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
426 PPP_STD_OPTIONS
+=" lcp-echo-failure 3 ${AUTH}"
430 if [ "${DEBUG}" == "on" ]; then
438 if [ "$TYPE" == "pppoe" ]; then
439 PPPOE_CMD
="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I $PPP_NIC"
440 PPPOE_CMD
+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
445 if [ "$TYPE" == "pptp" ]; then
446 PPPOE_CMD
="pptp $PPTP_PEER --nolaunchpppd"
452 if [ "$METHOD" == "PPPOE_PLUGIN" ]; then
453 /usr
/sbin
/pppd
$PPP_STD_OPTIONS $DEBUG $DEMAND >/dev
/null
2>&1 &
455 # echo PLUGIN: /usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND
457 /usr
/sbin
/pppd pty
"$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev
/null
2>&1 &
459 # echo PPP: /usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC
461 ## Create & Enable vnstat
462 /usr
/bin
/vnstat
-u -i ppp0
-r --enable --force > /dev
/null
2>&1
463 /etc
/rc.d
/init.d
/connectd start
464 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
465 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
466 $
(date +%s
):: > /dev
/null
2>&1
472 if [ "$TYPE" == "STATIC" ]; then
473 boot_mesg
"Stopping default gateway ${GATEWAY}..."
474 ip route del default via
${GATEWAY} >/dev
/null
2>&1
476 if [ "$DEVICE" != "${GREEN_DEV}" ]; then
477 boot_mesg
"Removing IPv4 addresses from the ${DEVICE} interface..."
478 ip addr flush dev
${DEVICE}
481 run_subdir
${rc_base}/init.d
/networking
/red.down
/
483 elif [ "$TYPE" == "DHCP" ]; then
484 boot_mesg
-n "Stopping dhcpcd on the ${DEVICE} interface..."
485 if [ -e $LEASEINFO ]; then
487 if [ "$LEASETIME" = "4294967295" ]; then
488 # do nothing, just echo ok
492 if [ -n "$DHCP_STOP" ]; then
493 /sbin
/dhcpcd
${DEVICE} $DHCP_STOP &> /dev
/null
495 if [ "$RET" -eq 0 ]; then
498 elif [ "$RET" -eq 1 ]; then
499 boot_mesg
"dhcpcd not running!" ${WARNING}
511 boot_mesg
-n "LEASEINFO Test failed! - " ${WARNING}
512 boot_mesg
"dhcpcd is not running!" ${WARNING}
516 elif [ "$TYPE" == "PPPOE" ]; then
517 boot_mesg
"Bringing down the PPP interface ..."
518 ## Disable vnstat collection
519 /usr
/bin
/vnstat
-u -i ppp0
-r --disable > /dev
/null
2>&1
520 rm -f /var
/ipfire
/red
/keepconnected
521 killall
-w -s TERM
/usr
/sbin
/pppd
2>/dev
/null
523 # Add a NaN value to ppp0 rrd to supress spikes at reconnect
524 rrdtool update
$RRDLOG/collectd
/localhost
/interface
/if_octets-ppp0.rrd \
525 $
(date +%s
):: > /dev
/null
2>&1
528 if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
529 link_status
=`ip link show $DEVICE.${RED_VDSL_INET_VLAN} 2> /dev/null`
530 if [ -n "${link_status}" ]; then
531 if echo "${link_status}" |
grep -q UP
; then
532 boot_mesg
"Bringing down the ${DEVICE}.${RED_VDSL_INET_VLAN} interface..."
533 ip link
set ${DEVICE}.
${RED_VDSL_INET_VLAN} down
534 vconfig del
${DEVICE} ${RED_VDSL_INET_VLAN}
538 link_status
=`ip link show $DEVICE 2> /dev/null`
539 if [ -n "${link_status}" ]; then
540 if echo "${link_status}" |
grep -q UP
; then
541 boot_mesg
"Bringing down the ${DEVICE} interface..."
542 ip link
set ${DEVICE} down
548 killall
-w -s KILL
/usr
/sbin
/pppd
>/dev
/null
2>&1
549 killall
-w -s KILL pptp
>/dev
/null
2>&1
550 killall
-w -s KILL br2684ctl
>/dev
/null
2>&1
552 ## Disable vnstat collection
553 /usr
/bin
/vnstat
-u -i ${DEVICE} -r --disable > /dev
/null
2>&1
555 rm -f /var
/ipfire
/red
/{active
,device
,dial-on-demand
,dns1
,dns2
,local-ipaddress
,remote-ipaddress
,resolv.conf
}