]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
Worked again on that networking stuff.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 8 Mar 2009 21:35:54 +0000 (22:35 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 8 Mar 2009 21:35:54 +0000 (22:35 +0100)
src/initscripts/core/network
src/initscripts/networking/functions
src/initscripts/networking/hooks/ethernet
src/initscripts/networking/hooks/ipv4-static
src/initscripts/networking/hooks/ipv4-static-route
src/initscripts/networking/hooks/mtu [new file with mode: 0644]
src/initscripts/networking/hooks/stp
src/initscripts/networking/hooks/vlan
src/initscripts/networking/port
src/initscripts/networking/zone
src/rootfiles/core/initscripts

index 9f42d1c3a76fdd1ecce8180e61b667a780af7255..4e4410347421d84295a5d92ca7b90004bf48137a 100644 (file)
 case "${1}" in
        start)
                # Start all network interfaces
-               for zone in $(find ${CONFIG_ZONES}/ -maxdepth 1); do
+               for zone in $(find ${CONFIG_ZONES}/* -maxdepth 1); do
                        [ -d "${zone}" ] || continue
-                       IN_BOOT=1 /etc/init.d/networking/zone ${zone##*/} up
+                       /etc/init.d/networking/zone ${zone##*/} up
                done
                touch /var/lock/subsys/network
                ;;
 
        stop)
                # Stop all network interfaces
-               for zone in $(find ${CONFIG_ZONES}/ -maxdepth 1); do
+               for zone in $(find ${CONFIG_ZONES}/* -maxdepth 1); do
                        [ -d "${zone}" ] || continue
-                       IN_BOOT=1 /etc/init.d/networking/zone ${zone##*/} down
+                       /etc/init.d/networking/zone ${zone##*/} down
                done
                rm -f /var/lock/subsys/network
                ;;
index ba0c74757c447bb083066de810477cf402c8f090..e4b89f8e7df2f1e09f5972d352adc6c283d3b44a 100644 (file)
@@ -30,17 +30,26 @@ function is_mac() {
 
 function get_device_by_mac() {
        local mac
-       local i
+       local device
 
        mac=$1
 
-       for i in /sys/class/net/*; do
-               if [ "$(cat $i/address)" = "$mac" ]; then
-                       grep -q "^${i##*/}" /proc/net/vlan/config 2>/dev/null && continue
-                       echo ${i##*/}
-                       break
+       for device in /sys/class/net/*; do
+               if [ "$(cat $device/address)" = "$mac" ]; then
+                       device=${device##*/}
+                       # Skip virtual devices
+                       if [ -e "/proc/net/vlan/$device" ]; then
+                               continue
+                       fi
+                       # Skip zones
+                       if zone_exists ${device}; then
+                               continue
+                       fi
+                       echo ${device}
+                       return 0
                fi
        done
+       return 1
 }
 
 function get_device_by_mac_and_vid() {
@@ -53,13 +62,15 @@ function get_device_by_mac_and_vid() {
        local i
        local VID
        local DEVICE
-       grep '|' < /proc/net/vlan/config 2>/dev/null | sed "s/|//g" | \
-               while read DEVICE VID PARENT; do
-                       if [ "${vid}" = "${VID}" ] && [ "$(macify ${PARENT})" = "${mac}" ]; then
-                               echo "${DEVICE}"
-                               return 0
-                       fi
-               done
+       if [ -e "/proc/net/vlan/config" ]; then
+               grep '|' /proc/net/vlan/config | sed "s/|//g" | \
+                       while read DEVICE VID PARENT; do
+                               if [ "${vid}" = "${VID}" ] && [ "$(macify ${PARENT})" = "${mac}" ]; then
+                                       echo "${DEVICE}"
+                                       return 0
+                               fi
+                       done
+       fi
        return 1
 }
 
@@ -95,7 +106,13 @@ function devicify() {
                mac=${device}
                device=$(get_device_by_mac ${device})
        fi
-       echo ${device}
+       if [ -n "${device}" ]; then
+               echo ${device}
+               return 0
+       else
+               echo "devicify: Could not find device of $@" >&2
+               return 1
+       fi
 }
 
 function macify() {
@@ -123,12 +140,28 @@ function rename_device() {
        source=$1
        destination=$2
 
+       # Replace + by a valid number
+       if grep -q "+$" <<<${destination}; then
+               local number
+               destination=$(sed -e "s/+//" <<<$destination)
+               number=0
+               while :; do
+                       if ! device_exists "${destination}${number}"; then
+                               destination="${destination}${number}"
+                               break
+                       fi
+                       number=$(($number + 1))
+               done
+       fi
+
        # Check if devices exist
        if ! device_exists ${source} || device_exists ${destination}; then
                return 4
        fi
 
+       ip link set ${source} down
        ip link set ${source} name ${destination}
+       ip link set ${destination} up
        return $?
 }
 
index 8823f9959e8268bf1883f6cb9709629029c31fdf..b88a82addd1528ad2002a38c6bd573b84c6d515e 100644 (file)
@@ -42,11 +42,12 @@ EOF
        ;;
 
        attach)
-               zone_add_port ${ZONE} $(get_device ${port})
+               rename_device $(get_device ${port}) ${ZONE}s+
+               zone_add_port ${ZONE} $(get_device_by_mac ${port})
        ;;
 
        detach)
-               zone_del_port ${ZONE} $(get_device ${port})
+               zone_del_port ${ZONE} $(get_device_by_mac ${port})
        ;;
 
        *)
index 1a192764fe982fc0477382810ca4b884bc67d420..13fbbc37e528d66e085ca1210c12d178bbb5f689 100644 (file)
@@ -5,7 +5,7 @@
 # Description : IPV4 Static Boot Script
 #
 # Authors     : Nathan Coulson - nathan@linuxfromscratch.org
-#              Kevin P. Fleming - kpfleming@linuxfromscratch.org
+#               Kevin P. Fleming - kpfleming@linuxfromscratch.org
 #
 # Version     : 00.00
 #
 . /lib/lsb/init-functions
 [ -n "${CONFIG}" ] && . ${CONFIG}
 
+zone=$1
+
 if [ -z "${IP}" ]; then
-       log_failure_msg "IP variable missing from ${IFCONFIG}, cannot continue."
+       log_failure_msg "IP variable missing from ${CONFIG}, cannot continue."
        exit 1
 fi
 
 if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
-       log_warning_msg "PREFIX variable missing from ${IFCONFIG}, assuming 24."
+       log_warning_msg "PREFIX variable missing from ${CONFIG}, assuming 24."
        PREFIX=24
        args="${args} ${IP}/${PREFIX}"
 elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
-       log_failure_msg "PREFIX and PEER both specified in ${IFCONFIG}, cannot continue."
+       log_failure_msg "PREFIX and PEER both specified in ${CONFIG}, cannot continue."
        exit 1
 elif [ -n "${PREFIX}" ]; then
        args="${args} ${IP}/${PREFIX}"
@@ -44,8 +46,8 @@ fi
 
 case "${2}" in
        up)
-               MESSAGE="Adding IPv4 address ${IP} to the ${1} interface..."
-               ip addr add ${args} dev ${1}
+               MESSAGE="Adding IPv4 address ${IP} to zone ${zone} interface..."
+               ip addr add ${args} dev ${zone}
                evaluate_retval
        
                if [ -n "${GATEWAY}" ]; then
@@ -53,7 +55,7 @@ case "${2}" in
                                log_warning_msg "Gateway already setup; skipping." ${WARNING}
                        else
                                MESSAGE="Setting up default gateway..."
-                               ip route add default via ${GATEWAY} dev ${1}
+                               ip route add default via ${GATEWAY} dev ${zone}
                                evaluate_retval
                         fi
                fi
@@ -66,13 +68,17 @@ case "${2}" in
                        evaluate_retval
                fi
        
-               MESSAGE="Removing IPv4 address ${IP} from the ${1} interface..."
-               ip addr del ${args} dev ${1}
+               MESSAGE="Removing IPv4 address ${IP} from zone ${zone}..."
+               ip addr del ${args} dev ${zone}
                evaluate_retval
        ;;
        
+       config)
+               : # TODO
+       ;;
+       
        *)
-               echo "Usage: ${0} [interface] {up|down}"
+               echo "Usage: ${0} [interface] {up|down|config}"
                exit 1
        ;;
 esac
index 7dc90fe9f9b2158a99995edbb270ac909105397c..436154279753eedec84ee3010477f1e1c97e35da 100644 (file)
@@ -15,6 +15,8 @@
 . /lib/lsb/init-functions
 [ -n "${CONFIG}" ] && . ${CONFIG}
 
+zone=$1
+
 case "${TYPE}" in
        ("" | "network")
                need_ip=1
@@ -38,7 +40,7 @@ case "${TYPE}" in
        ;;
 
        (*)
-               boot_mesg "Unknown route type (${TYPE}) in ${IFCONFIG}, cannot continue." ${FAILURE}
+               boot_mesg "Unknown route type (${TYPE}) in ${CONFIG}, cannot continue." ${FAILURE}
                echo_failure
                exit 1
        ;;
@@ -46,13 +48,13 @@ esac
 
 if [ -n "${need_ip}" ]; then
        if [ -z "${IP}" ]; then
-               boot_mesg "IP variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
+               boot_mesg "IP variable missing from ${CONFIG}, cannot continue." ${FAILURE}
                echo_failure
                exit 1
        fi
 
        if [ -z "${PREFIX}" ]; then
-               boot_mesg "PREFIX variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
+               boot_mesg "PREFIX variable missing from ${CONFIG}, cannot continue." ${FAILURE}
                echo_failure
                exit 1
        fi
@@ -63,7 +65,7 @@ fi
 
 if [ -n "${need_gateway}" ]; then
        if [ -z "${GATEWAY}" ]; then
-               boot_mesg "GATEWAY variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
+               boot_mesg "GATEWAY variable missing from ${CONFIG}, cannot continue." ${FAILURE}
                echo_failure
                exit 1
        fi
@@ -72,14 +74,14 @@ fi
 
 case "${2}" in
        up)
-               boot_mesg "Adding '${desc}' route to the ${1} interface..."
-               ip route add ${args} dev ${1}
+               boot_mesg "Adding '${desc}' route to zone ${zone}..."
+               ip route add ${args} dev ${zone}
                evaluate_retval
        ;;
        
        down)
-               boot_mesg "Removing '${desc}' route from the ${1} interface..."
-               ip route del ${args} dev ${1}
+               boot_mesg "Removing '${desc}' route from zone ${zone}..."
+               ip route del ${args} dev ${zone}
                evaluate_retval
        ;;
        
diff --git a/src/initscripts/networking/hooks/mtu b/src/initscripts/networking/hooks/mtu
new file mode 100644 (file)
index 0000000..685c8df
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh
+########################################################################
+# Begin $NETWORK_DEVICES/services/mtu
+#
+# Description : Sets MTU per interface
+#
+# Authors     : Nathan Coulson - nathan@linuxfromscratch.org
+#               Jim Gifford - jim@linuxfromscratch.org
+#
+# Version     : 00.00
+#
+# Notes       : This sets the maximum amount of bytes that can be
+#               transmitted within a packet. By default, this
+#               value is set to 1500.
+#
+########################################################################
+
+. /lib/lsb/init-functions
+[ -n "${CONFIG}" ] && . ${CONFIG}
+
+zone=$1
+
+if [ -z "${MTU}" ]
+then
+       log_failure_msg "MTU variable missing from ${CONFIG}, cannot continue."
+       exit 1
+fi
+
+case "${2}" in
+       up)
+               message="Setting the MTU for ${zone} to ${MTU}..."
+               echo "${MTU}" > "/sys/class/net/${zone}/mtu"
+               evaluate_retval standard
+       ;;
+
+       down)
+       ;;
+
+       *)
+               echo "Usage: ${0} [interface] {up|down}"
+               exit 1
+       ;;
+esac
+
+# End $NETWORK_DEVICES/services/mtu
index 9e87e4a85be676470b3a33800588e37a0d3c5501..4a8f2b0b591da0fe8b4873276a23cce7ec712fa7 100644 (file)
 . /lib/lsb/init-functions
 [ -n "${CONFIG}" ] && . ${CONFIG}
 
+zone=$1
+
 case "${2}" in
        up)
-               MESSAGE="Enabling Spanning Tree Protocol on interface ${1}..."
-               brctl stp ${1} on
+               MESSAGE="Enabling Spanning Tree Protocol on zone ${zone}..."
+               brctl stp ${zone} on
                evaluate_retval
        ;;
 
        down)
-               MESSAGE="Disabling Spanning Tree Protocol on interface ${1}..."
-               brctl stp ${1} off
+               MESSAGE="Disabling Spanning Tree Protocol on zone ${zone}..."
+               brctl stp ${zone} off
                evaluate_retval
        ;;
 
+       config)
+               : # TODO
+       ;;
+
        *)
-               echo "Usage: ${0} [interface] {up|down}"
+               echo "Usage: ${0} [interface] {up|down|config}"
                exit 1
        ;;
 esac
index 3647882e0dfe543d4318edc1c9d0570a29f22b32..682c96bf5eaae0869ce6d618e1e1258a2d996a4b 100644 (file)
@@ -21,18 +21,18 @@ device=$(devicify ${port})
 
 case "${2}" in
        up)
-               if ! get_device ${port} ${ID}; then
+               if ! get_device_by_mac_and_vid ${port} ${ID} >/dev/null; then
                        modprobe 8021q
                        MESSAGE="Adding VLAN ${ID} to port ${port}..."
-                       vconfig add ${device} ${ID} &>/dev/null
+                       vconfig add ${device} ${ID} >/dev/null
                        evaluate_retval
                fi
        ;;
 
        down)
-               if get_device ${port} ${ID}; then
+               if get_device_by_mac_and_vid ${port} ${ID} >/dev/null; then
                        MESSAGE="Removing VLAN ${ID} from port ${port}..."
-                       vconfig rem ${device} ${ID} &>/dev/null
+                       vconfig rem ${device} ${ID} >/dev/null
                        evaluate_retval
                fi
        ;;
@@ -56,11 +56,12 @@ EOF
        ;;
 
        attach)
+               rename_device $(get_device_by_mac_and_vid ${port} ${ID}) ${ZONE}v${ID}
                zone_add_port ${ZONE} $(get_device ${port} ${ID})
        ;;
        
        detach)
-               zone_del_port ${ZONE} $(get_device ${port} ${ID})
+               zone_del_port ${ZONE} $(get_device_by_mac_and_vid ${port} ${ID})
        ;;
 
        *)
index f85556be20cfbdab2fcba07368fd568a32f8b3b2..2856e2fc75874edbec8094bad5e7ee66b347bca7 100644 (file)
@@ -27,77 +27,65 @@ action=$2
 
 shift 2
 
-if ! device_exists ${port}; then
-       echo "Port ${port} does not exist."
+if [ -z "${port}" ] || [ -z "${action}" ]; then
+       echo "Usage: $0 <port> <up|down|attach|detach> [hooks]"
+       echo
        exit 1
 fi
 
-if [ -z "${port}" ] || [ -z "${action}" ]; then
-       echo "Usage: $0 <port> <up|down> [hooks]"
-       echo
+if ! device_exists ${port}; then
+       echo "Port ${port} does not exist."
+       exit 1
 fi
 
 for arg in ${@-$(find ${CONFIG_PORTS}/${port}/)}; do
+       [ -L "${arg}" ] && arg=$(readlink ${arg})
        arg=${arg##*/}
        [ -e "${CONFIG_PORTS}/${port}/${arg}" ] || continue
        hooks="${hooks} ${CONFIG_PORTS}/${port}/${arg}"
 done
 
-# Getting zone variable
-#local zone
-#if [ -z "$ZONE" ]; then
-#      for zone in $(all_zones); do
-#              for i in ${zone}/port-*; do
-#                      i=$(readlink ${i})
-#                      for j in ${ports}; do
-#                              if [ "${i}" = "${j}" ]; then
-#                                      ZONE=${i%/*}
-#                                      ZONE=${ZONE##*/}
-#                              fi
-#                      done
-#              done
-#      done
-#fi
-
 case "$action" in
        up)
                message="Setting up port ${port}..."
                ip link set $(devicify ${port}) up
                evaluate_retval
-
-               for hook in ${hooks}; do
-                       [ -d "${hook}" ] && continue
-                       (
-                               . ${hook}
-                               if [ -n "${HOOK}" -a -x "/etc/init.d/networking/hooks/${HOOK}" ]; then
-                                       CONFIG=${hook} /etc/init.d/networking/hooks/${HOOK} ${port} up
-                               else
-                                       echo -e "${FAILURE}Unable to process ${hook}. Either"
-                                       echo -e "${FAILURE}the HOOK variable was not set,"
-                                       echo -e "${FAILURE}or the specified hook cannot be executed."
-                                       message=""
-                                       log_failure_msg
-                               fi
-                       )
-               done
                ;;
+
        down)
-               for hook in ${hooks}; do
-                       [ -d "${hook}" ] && continue
-                       (
-                               . ${hook}
-                               if [ -n "${HOOK}" -a -x "/etc/init.d/networking/hooks/${HOOK}" ]; then
-                                       CONFIG=${hook} /etc/init.d/networking/hooks/${HOOK} ${port} down
-                               else
-                                       echo -e "${FAILURE}Unable to process ${hook}. Either"
-                                       echo -e "${FAILURE}the HOOK variable was not set,"
-                                       echo -e "${FAILURE}or the specified hook cannot be executed."
-                                       message=""
-                                       log_failure_msg
-                               fi
-                       )
-               done
+               ;;
+
+       attach|detach)
+               if [ -z "${ZONE}" ]; then
+                       log_failure_msg "ZONE is not set."
+                       exit 1
+               fi
+               ;;
+
+       *)
+               log_failure_msg "\"${action}\" is not a valid command."
+               exit 1
+               ;;
+esac
 
+for hook in ${hooks}; do
+       [ -d "${hook}" ] && continue
+       (
+               . ${hook}
+               if [ -n "${HOOK}" -a -x "/etc/init.d/networking/hooks/${HOOK}" ]; then
+                       CONFIG=${hook} /etc/init.d/networking/hooks/${HOOK} ${port} ${action}
+               else
+                       echo -e "${FAILURE}Unable to process ${hook}. Either"
+                       echo -e "${FAILURE}the HOOK variable was not set,"
+                       echo -e "${FAILURE}or the specified hook cannot be executed."
+                       message=""
+                       log_failure_msg
+               fi
+       )
+done
+
+case "${action}" in
+       down)
                message="Pushing down port ${port}..."
                ip link set $(devicify ${port}) down
                evaluate_retval
index a8b5cd6a8ff08eefa377a270def36f59ea06d58b..075afa98580922a2da1dcc6362cd5876ea19cc40 100644 (file)
 zone=$1
 action=$2
 
+if [ -z "${zone}" ] || [ -z "${action}" ]; then
+       echo "Usage: $0 <zone> <up|down>"
+       echo
+       exit 1
+fi
+
+if ! zone_exists ${zone}; then
+       echo "Zone ${zone} does not exist."
+       exit 1
+fi
+
 case "$action" in
        up)
                message="Bringing up zone ${zone}..."
@@ -38,18 +49,16 @@ case "$action" in
                        (exit ${failed})
                        evaluate_retval standard
 
-                       # When we boot, we should bring up every port
-                       [ "${IN_BOOT}" = "1" ] && \
-                               for port in ${CONFIG_ZONES}/${zone}/port-*; do
-                                       ZONE=${zone} /etc/init.d/networking/port ${port} up
-                               done
+                       # We should bring up every port
+                       for config in ${CONFIG_ZONES}/${zone}/port-*; do
+                               port=${config##*/}; port=${port#port-}; port=${port%%-*}
+                               ZONE=${zone} /etc/init.d/networking/port ${port} up
+                       done
 
                        # Attach ports
                        for config in ${CONFIG_ZONES}/${zone}/port-*; do
                                port=${config##*/}; port=${port#port-}; port=${port%%-*}
-                               echo "DEBUG: port $port"
-                               ZONE=${zone} CONFIG=${config} \
-                                       /etc/init.d/networking/port ${port} attach
+                               ZONE=${zone} /etc/init.d/networking/port ${port} attach ${config}
                        done
 
                        ###/etc/init.d/networking/hooks post-up ${CONFIG_ZONES}/${zone}
index 9359f5f124779abff5e1579126a0fc8edc921f09..f69961e6fd1ab7fdf2c36bba2a85bbcf26902084 100644 (file)
@@ -22,6 +22,7 @@ etc/init.d/networking/hooks/bridge-slave
 etc/init.d/networking/hooks/ethernet
 etc/init.d/networking/hooks/ipv4-static
 etc/init.d/networking/hooks/ipv4-static-route
+etc/init.d/networking/hooks/mtu
 etc/init.d/networking/hooks/stp
 etc/init.d/networking/hooks/vlan
 etc/init.d/networking/net-hotplug