From: Michael Tremer Date: Sun, 8 Mar 2009 21:35:54 +0000 (+0100) Subject: Worked again on that networking stuff. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bded84486405820e153db3d7b61ecd8e5737191;p=ipfire-3.x.git Worked again on that networking stuff. --- diff --git a/src/initscripts/core/network b/src/initscripts/core/network index 9f42d1c3a..4e4410347 100644 --- a/src/initscripts/core/network +++ b/src/initscripts/core/network @@ -22,18 +22,18 @@ 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 ;; diff --git a/src/initscripts/networking/functions b/src/initscripts/networking/functions index ba0c74757..e4b89f8e7 100644 --- a/src/initscripts/networking/functions +++ b/src/initscripts/networking/functions @@ -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 $? } diff --git a/src/initscripts/networking/hooks/ethernet b/src/initscripts/networking/hooks/ethernet index 8823f9959..b88a82add 100644 --- a/src/initscripts/networking/hooks/ethernet +++ b/src/initscripts/networking/hooks/ethernet @@ -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}) ;; *) diff --git a/src/initscripts/networking/hooks/ipv4-static b/src/initscripts/networking/hooks/ipv4-static index 1a192764f..13fbbc37e 100644 --- a/src/initscripts/networking/hooks/ipv4-static +++ b/src/initscripts/networking/hooks/ipv4-static @@ -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 # @@ -16,17 +16,19 @@ . /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 diff --git a/src/initscripts/networking/hooks/ipv4-static-route b/src/initscripts/networking/hooks/ipv4-static-route index 7dc90fe9f..436154279 100644 --- a/src/initscripts/networking/hooks/ipv4-static-route +++ b/src/initscripts/networking/hooks/ipv4-static-route @@ -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 index 000000000..685c8df26 --- /dev/null +++ b/src/initscripts/networking/hooks/mtu @@ -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 diff --git a/src/initscripts/networking/hooks/stp b/src/initscripts/networking/hooks/stp index 9e87e4a85..4a8f2b0b5 100644 --- a/src/initscripts/networking/hooks/stp +++ b/src/initscripts/networking/hooks/stp @@ -15,21 +15,27 @@ . /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 diff --git a/src/initscripts/networking/hooks/vlan b/src/initscripts/networking/hooks/vlan index 3647882e0..682c96bf5 100644 --- a/src/initscripts/networking/hooks/vlan +++ b/src/initscripts/networking/hooks/vlan @@ -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}) ;; *) diff --git a/src/initscripts/networking/port b/src/initscripts/networking/port index f85556be2..2856e2fc7 100644 --- a/src/initscripts/networking/port +++ b/src/initscripts/networking/port @@ -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 [hooks]" + echo exit 1 fi -if [ -z "${port}" ] || [ -z "${action}" ]; then - echo "Usage: $0 [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 diff --git a/src/initscripts/networking/zone b/src/initscripts/networking/zone index a8b5cd6a8..075afa985 100644 --- a/src/initscripts/networking/zone +++ b/src/initscripts/networking/zone @@ -25,6 +25,17 @@ zone=$1 action=$2 +if [ -z "${zone}" ] || [ -z "${action}" ]; then + echo "Usage: $0 " + 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} diff --git a/src/rootfiles/core/initscripts b/src/rootfiles/core/initscripts index 9359f5f12..f69961e6f 100644 --- a/src/rootfiles/core/initscripts +++ b/src/rootfiles/core/initscripts @@ -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