]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/initscripts/init.d/networking/red
Add vlan8 with dhcpclient for vdsl-iptv
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / networking / red
index 1a795830604e82411ebb4501f3b00db67bc84b42..08d6c927af8a21d38107419b57f61ffaa1a6b1de 100644 (file)
 
 . /etc/sysconfig/rc 
 . ${rc_functions}
+
+eval $(/usr/local/bin/readhash /var/ipfire/main/settings)
+if [ "$RRDLOG" == "" ]; then
+       RRDLOG=/var/log/rrd
+fi
+
 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
+eval $(/usr/local/bin/readhash /var/ipfire/mac/settings)
+
+MAC=$(tr - : <<<$MAC)
 
 TYPE="${RED_TYPE}"
 DEVICE="${RED_DEV}"
@@ -73,10 +82,6 @@ fi
 
 case "${1}" in
        start)
-               # Stop collectd if running
-               if [ "$(ps -A | grep " collectd$")" != "" ]; then
-                       /etc/rc.d/init.d/collectd stop
-               fi
                if [ "${DEVICE}" != "${GREEN_DEV}" ] && [ "${DEVICE}" != "" ]; then
                        boot_mesg "Bringing up the ${DEVICE} interface..."
                        boot_mesg_flush
@@ -85,13 +90,17 @@ case "${1}" in
                                link_status=`ip link show ${DEVICE} 2> /dev/null`
                                if [ -n "${link_status}" ]; then
                                        if ! echo "${link_status}" | grep -q UP; then
+                                               if [ -n "$MAC" ]; then
+                                                       boot_mesg "Setting mac address on ${DEVICE} to ${MAC}"  
+                                                       ip link set dev ${DEVICE} address ${MAC}
+                                                       evaluate_retval         
+                                               fi
                                                ip link set ${DEVICE} up
                                        fi
                                fi
                        else
                                boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE}
                                echo_failure
-                               /etc/rc.d/init.d/collectd start
                                exit 1
                        fi
                fi
@@ -121,8 +130,40 @@ case "${1}" in
                        evaluate_retval
                        
                        run_subdir ${rc_base}/init.d/networking/red.up/
-                       
+
+                       # Configure aliases only if red static
+                       /usr/local/bin/setaliases
+
                elif [ "${TYPE}" == "DHCP" ]; then
+
+                       if [ -e $LEASEINFO ]; then
+                               boot_mesg -n "Stopping dhcpcd on the ${DEVICE} interface..."
+                               . $LEASEINFO
+                               if [ "$LEASETIME" = "4294967295" ]; then
+                                       # do nothing, just echo ok
+                                       echo ""
+                                       echo_ok
+                               else
+                                       if [ -n "$DHCP_STOP" ]; then
+                                               /sbin/dhcpcd ${DEVICE} $DHCP_STOP &> /dev/null
+                                               RET="$?"
+                                               if [ "$RET" -eq 0 ]; then
+                                                       echo ""
+                                                       echo_ok
+                                               elif [ "$RET" -eq 1 ]; then
+                                                       boot_mesg "dhcpcd not running!" ${WARNING}
+                                                       echo_warning
+                                               else
+                                                       echo ""
+                                                       echo_failure
+                                               fi
+                                       else
+                                               echo ""
+                                               killproc dhcpcd
+                                       fi
+                               fi
+                       fi
+
                        boot_mesg -n "Starting dhcpcd on the ${DEVICE} interface..."            
                        echo -n "${DEVICE}" > /var/ipfire/red/iface
 
@@ -137,7 +178,6 @@ case "${1}" in
                                else
                                        boot_mesg "dhcpcd already running!" ${WARNING}
                                        echo_warning
-                                       /etc/rc.d/init.d/collectd start
                                        exit 2
                                fi
                        fi
@@ -180,6 +220,7 @@ case "${1}" in
                                echo "$GATEWAY gateway"  >> /tmp/hosts
                                mv /tmp/hosts /etc/hosts
                                echo "$GATEWAY" > /var/ipfire/red/remote-ipaddress
+                               touch /var/ipfire/red/active
                        else
                                echo ""
                                $(exit "$RET")
@@ -191,7 +232,6 @@ case "${1}" in
                        if ( ps ax | grep -q [p]ppd ); then 
                            boot_mesg "pppd is still running." ${FAILURE}
                            echo_failure
-                           /etc/init.d/collectd start
                            exit 1
                        fi
                        
@@ -209,6 +249,54 @@ case "${1}" in
                                sleep 0.2
                                ip link set ${PPP_NIC} up
                                TYPE="pppoe"
+
+
+                               PIDFILE="/var/run/dhcpcd-${DEVICE}.8.pid"
+                               LEASEINFO="/var/ipfire/dhcpc/dhcpcd-${DEVICE}.8.info"
+                               DHCP_START="-N -R -L /var/ipfire/dhcpc -c /var/ipfire/dhcpc/dhcpcd.exe "
+                               DHCP_STOP="-k -c /var/ipfire/dhcpc/dhcpcd.exe "
+
+
+                               # Test to see if there is a stale pid file
+                               if [ -f "$PIDFILE" ]; then
+                                       ps `cat "$PIDFILE"` | grep dhcpcd > /dev/null
+                                       if [ $? != 0 ]; then
+                                               rm -f /var/run/dhcpcd-${DEVICE}.8.pid > /dev/null
+                                       fi
+                               fi
+                               if [ ! -f "$PIDFILE" ]; then
+                                       #DHCP for VDSL IPTV
+                                       boot_mesg "Createing VLAN Interface ${DEVICE}.8 ..."
+                                       vconfig add ${DEVICE} 8
+
+                                       boot_mesg -n "Starting dhcpcd on the ${DEVICE}.8 interface..."
+
+                                       /sbin/dhcpcd ${DEVICE}.8 ${DHCP_START} >/dev/null 2>&1
+                                       RET="$?"
+
+                                       if [ "$RET" = "0" ]; then
+                                               . /var/ipfire/dhcpc/dhcpcd-${DEVICE}.8.info
+                                               echo ""
+                                               echo_ok
+                                               boot_mesg "           DHCP Assigned Settings for ${DEVICE}.8:"
+                                               boot_mesg_flush
+                                               boot_mesg "           IP Address:      $IPADDR"
+                                               boot_mesg_flush
+                                               boot_mesg "           Hostname:        $RED_DHCP_HOSTNAME"
+                                               boot_mesg_flush
+                                               boot_mesg "           Subnet Mask:     $NETMASK"
+                                               boot_mesg_flush
+                                               boot_mesg "           Default Gateway: $GATEWAY"
+                                               boot_mesg_flush
+                                               boot_mesg "           DNS Server:      $DNS"
+                                               boot_mesg_flush
+
+                                               else
+                                                       echo ""
+                                                       $(exit "$RET")
+                                                       evaluate_retval
+                                       fi
+                               fi
                        fi
 
                        if [ "$TYPE" == "pppoeatm" ] || [ "$TYPE" == "pptpatm" ]; then
@@ -227,7 +315,6 @@ case "${1}" in
                                if [ "$PPP_NIC" == "" ]; then
                                        boot_mesg "No device for red interface given. Check netsetup or dialprofile!" ${FAILURE}
                                        echo_failure
-                                       /etc/rc.d/init.d/collectd start
                                        exit 0
                                fi
                                boot_mesg "Bringing up the $TYPE interface on $PPP_NIC ..."
@@ -365,7 +452,9 @@ case "${1}" in
                        ## Create & Enable vnstat
                        /usr/bin/vnstat -u -i ppp0 -r --enable --force > /dev/null 2>&1
                        /etc/rc.d/init.d/connectd start
-                       /etc/rc.d/init.d/collectd start
+                       # Add a NaN value to ppp0 rrd to supress spikes at reconnect
+                       rrdtool update $RRDLOG/collectd/localhost/interface/if_octets-ppp0.rrd \
+                               $(date +%s):: > /dev/null 2>&1
                        exit 0
                fi
                ;;
@@ -422,6 +511,9 @@ case "${1}" in
                        rm -f /var/ipfire/red/keepconnected
                        killall -w -s TERM /usr/sbin/pppd 2>/dev/null
                        evaluate_retval
+                       # Add a NaN value to ppp0 rrd to supress spikes at reconnect
+                       rrdtool update $RRDLOG/collectd/localhost/interface/if_octets-ppp0.rrd \
+                               $(date +%s):: > /dev/null 2>&1
                fi
 
                if [ "$DEVICE" != "${GREEN_DEV}" ] && [ "$DEVICE" != "" ]; then
@@ -433,13 +525,14 @@ case "${1}" in
                                        vconfig del ${DEVICE} 7
                                        evaluate_retval
                                fi
-                       fi
-                       link_status=`ip link show $DEVICE 2> /dev/null`
-                       if [ -n "${link_status}" ]; then
-                               if echo "${link_status}" | grep -q UP; then
-                                       boot_mesg "Bringing down the ${DEVICE} interface..."
-                                       ip link set ${DEVICE} down
-                                       evaluate_retval
+                       else
+                               link_status=`ip link show $DEVICE 2> /dev/null`
+                               if [ -n "${link_status}" ]; then
+                                       if echo "${link_status}" | grep -q UP; then
+                                               boot_mesg "Bringing down the ${DEVICE} interface..."
+                                               ip link set ${DEVICE} down
+                                               evaluate_retval
+                                       fi
                                fi
                        fi
                fi