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 2>/dev/null); do
[ -d "${zone}" ] || continue
/etc/init.d/networking/zone ${zone##*/} up
done
stop)
# Stop all network interfaces
- for zone in $(find ${CONFIG_ZONES}/* -maxdepth 1); do
+ for zone in $(find ${CONFIG_ZONES}/* -maxdepth 1 2>/dev/null); do
[ -d "${zone}" ] || continue
/etc/init.d/networking/zone ${zone##*/} down
done
[ -d "${zone}" ] && echo ${zone}
done
}
+
+function run_hooks() {
+ local action
+ local dir
+ local failed
+ local hook
+ local hooks
+
+ action=${1}
+ dir=${2}
+ shift 2
+
+ if [ -z "${action}" ] || [ -z "${dir}" ]; then
+ echo "Not enough parameters given." >&2
+ return 1
+ fi
+
+ for hook in $(find ${dir} -type f); do
+ (
+ . ${hook}
+ if [ -n "${HOOK}" -a -x "/etc/init.d/networking/hooks/${HOOK}" ]; then
+ CONFIG=${hook} /etc/init.d/networking/hooks/${HOOK} ${action} $@
+ RET=$?
+ 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
+ exit ${RET}
+ ) || failed=1
+ done
+
+ return ${failed}
+}
########################################################################
. /lib/lsb/init-functions
+. /etc/init.d/networking/functions
[ -n "${CONFIG}" ] && . ${CONFIG}
-zone=$1
+zone=$2
-if [ -z "${IP}" ]; then
- 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 ${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 ${CONFIG}, cannot continue."
- exit 1
-elif [ -n "${PREFIX}" ]; then
- args="${args} ${IP}/${PREFIX}"
-elif [ -n "${PEER}" ]; then
- args="${args} ${IP} peer ${PEER}"
-fi
-
-if [ -n "${BROADCAST}" ]; then
- args="${args} broadcast ${BROADCAST}"
-fi
+function check_config() {
+ if [ -z "${IP}" ]; then
+ log_failure_msg "IP variable missing, cannot continue."
+ exit 1
+ fi
+
+ if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
+ log_warning_msg "PREFIX variable missing, assuming 24."
+ PREFIX=24
+ args="${args} ${IP}/${PREFIX}"
+ elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
+ log_failure_msg "PREFIX and PEER both specified, cannot continue."
+ exit 1
+ elif [ -n "${PREFIX}" ]; then
+ args="${args} ${IP}/${PREFIX}"
+ elif [ -n "${PEER}" ]; then
+ args="${args} ${IP} peer ${PEER}"
+ fi
+
+ if [ -n "${BROADCAST}" ]; then
+ args="${args} broadcast ${BROADCAST}"
+ fi
+
+ if [ -n "${SOURCE}" ]; then
+ args="${args} src ${SOURCE}"
+ fi
+}
-if [ -n "${SOURCE}" ]; then
- args="${args} src ${SOURCE}"
-fi
+case "${1}" in
+ pre-up)
+ ;;
-case "${2}" in
- up)
+ post-up)
+ check_config
MESSAGE="Adding IPv4 address ${IP} to zone ${zone} interface..."
ip addr add ${args} dev ${zone}
evaluate_retval
fi
fi
;;
-
- down)
+
+ pre-down)
+ check_config
if [ -n "${GATEWAY}" ]; then
MESSAGE="Removing default gateway..."
ip route del default
MESSAGE="Removing IPv4 address ${IP} from zone ${zone}..."
ip addr del ${args} dev ${zone}
evaluate_retval
- ;;
-
+ ;;
+
+ post-down)
+ ;;
+
config)
- : # TODO
- ;;
+ shift 2
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --ip)
+ IP=$2
+ shift 2
+ ;;
+ --prefix)
+ PREFIX=$2
+ shift 2
+ ;;
+ --peer)
+ PEER=$2
+ shift 2
+ ;;
+ --broadcast)
+ BROADCAST=$2
+ shift 2
+ ;;
+ --source)
+ SOURCE=$2
+ shift 2
+ ;;
+ --gateway)
+ GATEWAY=$2
+ shift 2
+ ;;
+ *)
+ echo "Unknown option: $1" >&2
+ exit 1
+ ;;
+ esac
+ done
+ check_config
+ cat << EOF >> ${CONFIG_ZONES}/${zone}/ipv4-static_$IP
+HOOK=ipv4-static
+IP=$IP
+PREFIX=$PREFIX
+PEER=$PEER
+BROADCAST=$BROADCAST
+SOURCE=$SOURCE
+GATEWAY=$GATEWAY
+EOF
+ exit $?
+ ;;
*)
- echo "Usage: ${0} [interface] {up|down|config}"
+ echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]"
exit 1
;;
esac
. /lib/lsb/init-functions
[ -n "${CONFIG}" ] && . ${CONFIG}
-zone=$1
+zone=$2
case "${TYPE}" in
("" | "network")
args="${args} via ${GATEWAY}"
fi
-case "${2}" in
+case "${1}" in
up)
boot_mesg "Adding '${desc}' route to zone ${zone}..."
ip route add ${args} dev ${zone}
########################################################################
. /lib/lsb/init-functions
+. /etc/init.d/networking/functions
[ -n "${CONFIG}" ] && . ${CONFIG}
-zone=$1
+function check_config() {
+ if [ -z "${MTU}" ]; then
+ log_failure_msg "MTU variable missing from ${CONFIG}, cannot continue."
+ exit 1
+ fi
+ if [ -z "${zone}" ]; then
+ usage
+ exit 1
+ fi
+}
+
+function usage() {
+ echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]"
+}
-if [ -z "${MTU}" ]
-then
- log_failure_msg "MTU variable missing from ${CONFIG}, cannot continue."
- exit 1
-fi
+zone=$2
-case "${2}" in
- up)
+case "${1}" in
+ pre-up)
+ ;;
+
+ post-up)
+ check_config
message="Setting the MTU for ${zone} to ${MTU}..."
echo "${MTU}" > "/sys/class/net/${zone}/mtu"
evaluate_retval standard
- ;;
+ ;;
- down)
- ;;
+ pre-down)
+ check_config
+ message="Resetting MTU for ${zone} to 1500..."
+ echo "1500" > "/sys/class/net/${zone}/mtu"
+ evaluate_retval standard
+ ;;
+
+ post-down)
+ ;;
+
+ config)
+ ;;
*)
- echo "Usage: ${0} [interface] {up|down}"
+ usage
exit 1
;;
esac
. /lib/lsb/init-functions
[ -n "${CONFIG}" ] && . ${CONFIG}
-zone=$1
+zone=$2
-case "${2}" in
- up)
+case "${1}" in
+ pre-up)
+ ;;
+
+ post-up)
MESSAGE="Enabling Spanning Tree Protocol on zone ${zone}..."
brctl stp ${zone} on
evaluate_retval
- ;;
+ ;;
- down)
+ pre-down)
MESSAGE="Disabling Spanning Tree Protocol on zone ${zone}..."
brctl stp ${zone} off
evaluate_retval
- ;;
+ ;;
+
+ post-down)
+ ;;
config)
: # TODO
- ;;
+ ;;
*)
- echo "Usage: ${0} [interface] {up|down|config}"
+ echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]"
exit 1
- ;;
+ ;;
esac
# End $NETWORK_DEVICES/services/stp
up)
message="Bringing up zone ${zone}..."
+ run_hooks pre-up ${CONFIG_ZONES}/${zone} ${zone}
+
# Check if bridge already exists
zone_status=`brctl show 2>/dev/null`
if ! echo "${zone_status}" | grep -q "^${zone}"; then
ip link set ${zone} up || failed=1
(exit ${failed})
evaluate_retval standard
+ fi
- # Attach ports
- for config in ${CONFIG_ZONES}/${zone}/port-*; do
- port=${config##*/}; port=${port#port-}; port=${port%%-*}
- ZONE=${zone} /etc/init.d/networking/port ${port} attach ${config}
- done
+ # Attach ports
+ for config in $(find ${CONFIG_ZONES}/${zone}/ -name "port-*" 2>/dev/null); do
+ port=${config##*/}; port=${port#port-}; port=${port%%-*}
+ ZONE=${zone} /etc/init.d/networking/port ${port} attach ${config}
+ done
- ###/etc/init.d/networking/hooks post-up ${CONFIG_ZONES}/${zone}
- else
- log_warning_msg
- message="Zone ${zone} does already exist."
- log_warning_msg
- fi
+ run_hooks post-up ${CONFIG_ZONES}/${zone} ${zone}
;;
down)
# Check if bridge already exists
zone_status=`brctl show 2>/dev/null`
if echo "${zone_status}" | grep -q "^${zone}"; then
- #/etc/init.d/networking/hooks pre-down ${CONFIG_ZONES}/${zone}
+ run_hooks pre-down ${CONFIG_ZONES}/${zone} ${zone}
# Detach ports
- for config in ${CONFIG_ZONES}/${zone}/port-*; do
+ for config in $(find ${CONFIG_ZONES}/${zone}/ -name "port-*" 2>/dev/null); do
port=${config##*/}; port=${port#port-}; port=${port%%-*}
ZONE=${zone} /etc/init.d/networking/port ${port} detach ${config}
done
brctl delbr ${zone} || failed=1
(exit ${failed})
evaluate_retval standard
+
+ run_hooks post-down ${CONFIG_ZONES}/${zone} ${zone}
else
- log_warning_msg
- message="Zone ${zone} does not exist."
- log_warning_msg
+ log_warning_msg ${message}
+ log_warning_msg "Zone ${zone} does not exist."
fi
;;
esac
function cmd() {
decho "Running command: $@"
- if verbose; then
+ if debug; then
$@
else
$@ >/dev/null
error "Hook ${BOLD}${hook}${NORMAL} does not exist or is not executeable."
return 1
fi
+ cmd /etc/init.d/networking/zone ${zone} up
}
function port_del() {
mkdir -p ${CONFIG_ZONES}/${zone}
vecho "Successfully added zone ${zone}."
+ cmd /etc/init.d/networking/zone ${zone} up
}
function zone_del() {
return 1
fi
+ cmd /etc/init.d/networking/zone ${zone} down
rm -rf ${CONFIG_ZONES}/${zone}
vecho "Successfully removed zone ${zone}."
}
port_del $@
_exit $?
;;
+ list)
+ all_zones
+ _exit $?
+ ;;
+ config)
+ zone=$1; shift
+ hook=$1; shift
+ if [ -x /etc/init.d/networking/hooks/${hook} ]; then
+ /etc/init.d/networking/hooks/${hook} config ${zone} $@
+ RET=$?
+ else
+ error "\"${hook}\" is not a known hook."
+ fi
+ _exit $RET
+ ;;
help)
DO_RELOAD=0 usage zone 0
;;