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
;;
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() {
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
}
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() {
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 $?
}
;;
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})
;;
*)
# 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}"
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
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
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
. /lib/lsb/init-functions
[ -n "${CONFIG}" ] && . ${CONFIG}
+zone=$1
+
case "${TYPE}" in
("" | "network")
need_ip=1
;;
(*)
- 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
;;
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
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
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
;;
--- /dev/null
+#!/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
. /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
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
;;
;;
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})
;;
*)
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
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}..."
(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}
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