New hook: ipv4-dhcp.
A lot of minor changes and changes that beatify the output.
local destination=$2
# Replace + by a valid number
- if grep -qE "+$" <<<${destination}; then
+ if grep -q "+$" <<<${destination}; then
local number=0
destination=$(sed -e "s/+//" <<<$destination)
while [ "${number}" -le "100" ]; do
--- /dev/null
+#!/bin/sh
+
+. /lib/lsb/init-functions
+. /lib/network/functions
+
+INDENT=" "
+
+# Parse the command line
+action=
+port=
+zone=
+
+while [ $# -gt 0 ]; do
+ case "${1}" in
+ --zone=*)
+ zone=${1#--zone=}
+ ;;
+ --config=*)
+ . ${1#--config=}
+ ;;
+ --port=*)
+ port=${1#--port=}
+ ;;
+ -*)
+ log_failure_msg "Unrecognized option: ${1}"
+ exit ${EXIT_ERROR}
+ ;;
+ *)
+ action=${1}
+ shift
+ break
+ ;;
+ esac
+ shift
+done
+
#
########################################################################
-. /lib/lsb/init-functions
-. /lib/network/functions
+. /lib/network/hook-header
HOOK_NAME=ethernet
HOOK_TYPE=port
# Device is already attached to the bridge
return 0
fi
+ message="Attaching ethernet port ${port}..."
device_rename $(get_device ${port}) $(port_name)
zone_add_port ${zone} $(get_device_by_mac ${port})
+ evaluate_retval
}
function do_detach() {
if zone_has_device_attached ${zone} $(get_device ${port}); then
+ message="Detatching ethernet port ${port}..."
zone_del_port ${zone} $(get_device_by_mac ${port})
device_rename $(get_device_by_mac ${port}) ${COMMON_DEVICE}
+ evaluate_retval
fi
}
# TODO: Check if device is attached to a bridge.
}
-# First, parse the command line
-
-while [ $# -gt 0 ]; do
- case "${1}" in
- --port=*)
- port=$(macify ${1#--port=})
- ;;
- --config=*)
- . ${1#--config=}
- check_config
- ;;
- --zone=*)
- zone=${1#--zone=}
- ;;
- -*)
- log_failure_msg "Unrecognized option: ${1}"
- exit ${EXIT_ERROR}
- ;;
- *)
- action=${1}
- shift
- break
- ;;
- esac
- shift
-done
-
case "${action}" in
help)
echo -e "${BOLD}Hook (${HOOK_NAME}) help:"
--- /dev/null
+#!/bin/sh
+
+. /lib/network/hook-header
+
+HOOK_NAME="ipv4-dhcp"
+HOOK_TYPE="zone"
+
+MESSAGE="DHCP Daemon..."
+EXECUTEABLE="/sbin/dhclient"
+
+case "${action}" in
+ help)
+ ;;
+
+ info)
+ echo "HOOK_NAME=$HOOK_NAME"
+ echo "HOOK_TYPE=$HOOK_TYPE"
+ ;;
+
+ status)
+ check_config zone
+ pidfile="/var/run/dhclient_${zone}.pid"
+ pidofproc -p ${pidfile} ${EXECUTEABLE} &>/dev/null
+ exit $?
+ ;;
+
+ pre-up)
+ ;;
+
+ post-up)
+ check_config zone
+ pidfile="/var/run/dhclient_${zone}.pid"
+ if [ -e "${pidfile}" ]; then
+ kill $(<${pidfile}) &>/dev/null
+ sleep 1
+ fi
+ ${EXECUTEABLE} -pf ${pidfile} ${zone}
+ evaluate_retval start
+ ;;
+
+ pre-down)
+ check_config zone
+ pidfile="/var/run/dhclient_${zone}.pid"
+ killproc -p ${pidfile} ${EXECUTEABLE}
+ evaluate_retval stop
+ ;;
+
+ post-down)
+ ;;
+
+ config)
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --hostname=*)
+ HOSTNAME=${1#--hostname=}
+ ;;
+ *)
+ echo "Unknown option: $1" >&2
+ exit 1
+ ;;
+ esac
+ shift
+ done
+ cat <<EOF >${CONFIG_ZONES}/${zone}/ipv4-dhcp
+HOOK="${HOOK_NAME}"
+HOSTNAME="${HOSTNAME}"
+EOF
+ [ "$?" = "0" ] && exit ${EXIT_OK} || exit ${EXIT_ERROR}
+ ;;
+
+ *)
+ echo "Usage: ${0} {config|pre-up|post-up|pre-down|post-down|status} [interface]"
+ exit ${EXIT_ERROR}
+ ;;
+esac
+
+# End $NETWORK_DEVICES/services/ipv4-dhcp
#
########################################################################
-. /lib/lsb/init-functions
-. /lib/network/functions
+. /lib/network/hook-header
HOOK_NAME="ipv4-static"
HOOK_TYPE="zone"
fi
}
-# First, parse the command line
-
-while [ $# -gt 0 ]; do
- case "${1}" in
- --zone=*)
- zone=${1#--zone=}
- ;;
- --config=*)
- . ${1#--config=}
- check_config
- ;;
- -*)
- log_failure_msg "Unrecognized option: ${1}"
- exit ${EXIT_ERROR}
- ;;
- *)
- action=${1}
- shift
- break
- ;;
- esac
- shift
-done
-
-# Second, do the $action
-
case "${action}" in
help)
;;
#
########################################################################
-. /lib/lsb/init-functions
-. /lib/network/functions
+. /lib/network/hook-header
HOOK_NAME=mtu
HOOK_TYPE=zone
-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
-}
+DEFAULT_MTU=1500
function usage() {
echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]"
}
-# First, parse the command line
-
-while [ $# -gt 0 ]; do
- case "${1}" in
- --zone=*)
- zone=${1#--zone=}
- ;;
- --config=*)
- . ${1#--config=}
- check_config
- ;;
- -*)
- log_failure_msg "Unrecognized option: ${1}"
- exit ${EXIT_ERROR}
- ;;
- *)
- action=${1}
- shift
- break
- ;;
- esac
- shift
-done
-
-# Second, do the $action
-
case "${action}" in
help)
;;
;;
status)
- check_config
+ check_config zone MTU
mtu=$(cat /sys/class/net/${zone}/mtu 2>/dev/null)
[ "$MTU" = "$mtu" ]
exit $?
;;
post-up)
- check_config
+ check_config zone MTU
message="Setting the MTU for ${zone} to ${MTU}..."
echo "${MTU}" > "/sys/class/net/${zone}/mtu"
evaluate_retval standard
;;
pre-down)
- check_config
+ check_config zone MTU
message="Resetting MTU for ${zone} to 1500..."
- echo "1500" > "/sys/class/net/${zone}/mtu"
+ echo ${DEFAULT_MTU} > "/sys/class/net/${zone}/mtu"
evaluate_retval standard
;;
config)
MTU=$1
- check_config
+ check_config zone MTU
cat << EOF >> ${CONFIG_ZONES}/${zone}/${HOOK_NAME}
HOOK="${HOOK_NAME}"
MTU="${MTU}"
#
########################################################################
-. /lib/lsb/init-functions
-. /lib/network/functions
+. /lib/network/hook-header
HOOK_NAME=vlan
HOOK_TYPE=port
return $RET
}
-# First, parse the command line
-
-while [ $# -gt 0 ]; do
- case "${1}" in
- --port=*)
- port=$(macify ${1#--port=})
- ;;
- --config=*)
- . ${1#--config=}
- check_config
- ;;
- --zone=*)
- zone=${1#--zone=}
- ;;
- -*)
- log_failure_msg "Unrecognized option: ${1}"
- exit ${EXIT_ERROR}
- ;;
- *)
- action=${1}
- shift
- break
- ;;
- esac
- shift
-done
-
case "${action}" in
help)
;;
(
. ${hook}
if [ -n "${HOOK}" ] && hook_exists ${HOOK}; then
- /lib/network/hooks/${HOOK} --config=${hook} --port=${port} --zone=${zone} ${action}
+ hook_run ${HOOK} --config=${hook} --port=${port} --zone=${zone} ${action}
RET=$?
else
echo -e "${FAILURE}Unable to process ${hook}. Either"
if ! echo "${zone_status}" | grep -q "^${zone}"; then
# Create and bring up the zone
brctl addbr ${zone} || failed=1
+ brctl stp ${zone} on || failed=1
+ brctl setfd ${zone} 0 || failed=1
ip link set ${zone} up || failed=1
(exit ${failed})
evaluate_retval standard