Bonding does work much better.
"network zone show" gives some nice output now.
grep -q "${1}$" /proc/net/vlan/config
}
+function device_has_carrier() {
+ local device=$(devicify ${1})
+ [ "$(</sys/class/net/${device}/carrier)" = "1" ]
+}
+
function device_get_free() {
local destination=${1}
return 4
fi
- ip link set ${source} down
+ local up
+ if device_is_up ${source}; then
+ ip link set ${source} down
+ up=1
+ fi
+
ip link set ${source} name ${destination}
- ip link set ${destination} up
+
+ if [ "${up}" = "1" ]; then
+ ip link set ${destination} up
+ fi
}
function hook_exists() {
INDENT=" "
+HOOK_PRIO=100
+
# Parse the command line
action=
port=
HOOK_NAME=bonding
HOOK_TYPE=port
+HOOK_PRIO=50
DEFAULT_MODE=
-# TODO: Need to detect link failures!
-
function port_name() {
echo "${zone}t+"
}
[ -n "${MODE}" ] && \
echo "${MODE}" > /sys/class/net/${device}/bonding/mode
-
+
+ echo "${MIIMON-100}" > /sys/class/net/${device}/bonding/miimon
+
for slave in ${SLAVES}; do
if device_exists ${slave}; then
if device_is_up ${slave}; then
log_warning_msg "Cannot enslave device \"${slave}\"."
continue
fi
- echo "+$(devicify ${slave})" > /sys/class/net/${device}/bonding/slaves
device_rename "$(devicify ${slave})" "${device}s+"
+ echo "+$(devicify ${slave})" > /sys/class/net/${device}/bonding/slaves
else
log_warning_msg "Device ${slave} does not exist."
fi
;;
status)
- device_is_up $(devicify ${MAC})
- RET=$?
- if [ $RET -eq 0 ]; then
- log_success_msg "Port $(port_name) is up"
+ DEVICE=$(devicify ${MAC})
+ echo -e "# ${CLR_BOLD_CYN}Trunk ${DEVICE} (${MAC})${NORMAL}"
+ if device_is_up ${MAC}; then
+ echo -e "# State: ${CLR_BOLD_GRN}up${NORMAL}"
+ echo "#"
+ for slave in $(</sys/class/net/${DEVICE}/bonding/slaves); do
+ echo -e "# ${CLR_BOLD_CYN}Slave port ${slave}${NORMAL}"
+
+ echo -n "# State: "
+ if device_is_up ${slave}; then
+ echo -e "${CLR_BOLD_GRN}up${NORMAL}"
+ else
+ echo -e "${CLR_BOLD_RED}down${NORMAL}"
+ fi
+
+ echo -n "# Link : "
+ if device_has_carrier ${slave}; then
+ echo -e "${CLR_BOLD_GRN}yes${NORMAL}"
+ else
+ echo -e "${CLR_BOLD_RED}no${NORMAL}"
+ fi
+ done
else
- log_failure_msg "Port $(port_name) is down"
+ echo -e "# State: ${CLR_BOLD_RED}down${NORMAL}"
fi
- exit ${RET}
+
+ device_is_up ${MAC}
+ exit ${?}
;;
*)
;;
status)
- device_is_up ${MAC}
- RET=$?
- if [ $RET -eq 0 ]; then
- echo "Port $(port_name) is up"
+ echo -e "# ${CLR_BOLD_CYN}Ethernet port $(devicify ${MAC}) (${MAC})${NORMAL}"
+ echo -n "# State: "
+ if device_is_up ${MAC}; then
+ echo -e "${CLR_BOLD_GRN}up${NORMAL}"
+ else
+ echo -e "${CLR_BOLD_RED}down${NORMAL}"
+ fi
+ echo -n "# Link : "
+ if device_has_carrier ${MAC}; then
+ echo -e "${CLR_BOLD_GRN}yes${NORMAL}"
else
- echo "Port $(port_name) is down"
+ echo -e "${CLR_BOLD_RED}no${NORMAL}"
fi
- exit ${RET}
+ echo "#"
+
+ device_is_up ${MAC}
+ exit ${?}
;;
*)
post-down)
;;
- config)
+ add)
while [ $# -gt 0 ]; do
case "$1" in
--hostname=*)
EOF
[ "$?" = "0" ] && exit ${EXIT_OK} || exit ${EXIT_ERROR}
;;
+
+ rem)
+ ;;
*)
echo "Usage: ${0} {config|pre-up|post-up|pre-down|post-down|status} [interface]"
status)
check_config
- # XXX Is there a better way?
- if (ip route get ${IP} | grep -q ^local); then
- exit ${EXIT_OK}
- else
- exit ${EXIT_ERROR}
+ echo -e "# ${CLR_BOLD_CYN}IPv4 static: ${IP}/${PREFIX}${NORMAL}"
+ if [ -n "${GATEWAY}" ]; then
+ echo "# Gateway: ${GATEWAY}"
+ echo -n "# Reachable: "
+ if ping -c1 -w1 -I ${zone} ${GATEWAY} &>/dev/null; then
+ echo -e "${CLR_BOLD_GRN}yes${NORMAL}"
+ else
+ echo -e "${CLR_BOLD_RED}no${NORMAL}"
+ fi
fi
+ ip addr show ${zone} | grep "inet " | fgrep -q "${IP}/${PREFIX}"
+ exit ${?}
;;
pre-up)
post-down)
;;
- config)
+ add)
while [ $# -gt 0 ]; do
case "$1" in
--ip=*)
EOF
[ "$?" = "0" ] && exit ${EXIT_OK} || exit ${EXIT_ERROR}
;;
-
+
+ rem)
+ ;;
+
*)
echo "Usage: ${0} {config|pre-up|post-up|pre-down|post-down|status} [interface]"
exit ${EXIT_ERROR}
post-down)
;;
- config)
+ add)
shift 2
while [ $# -gt 0 ]; do
case "$1" in
exit $?
;;
+ rem)
+ ;;
+
*)
echo "Usage: ${0} {pre-up|post-up|pre-down|post-down|config} [interface]"
exit 1
NORMAL="\\033[0;39m"
ERROR="\\033[1;31m"
+. /etc/init/functions
+
if [ -e "/lib/network/functions" ]; then
. /lib/network/functions
elif [ -e "lib/functions" ]; then
fi
echo "##################################################"
- echo -e "# ${ERROR}ZONE INFO - ${zone}${NORMAL}"
- echo "##################################################"
+ echo "#"
+ echo -e "# Zone ${CLR_BOLD_BLU}${zone}${NORMAL}"
+ echo "# ------------------------------------------------"
# Up or down?
- if device_is_up ${zone}; then
- echo -e "# Device is ${ERROR}up${NORMAL}."
+ if zone_is_up ${zone}; then
+ echo -e "# Status: ${CLR_BOLD_GRN}up${NORMAL}"
else
- echo -e "# Device is ${ERROR}down${NORMAL}."
+ echo -e "# Status: ${CLR_BOLD_RED}down${NORMAL}"
fi
echo "#"
# Ports
- echo -e "# ${ERROR}Ports:${NORMAL}"
- local config
- local port
- for config in ${CONFIG_ZONES}/${zone}/port-*; do
- port=${config##*/}; port=${port#port-}; port=${port%%-*}
- if ZONE=${zone} cmd /lib/network/port ${port} attach ${config} &>/dev/null; then
- echo "# ${config#port-} is up"
- else
- echo "# ${config#port-} is down"
- fi
- done
- echo "#"
+ echo -e "# ${CLR_BOLD_BLU}Ports:${NORMAL}"
+ hooks_run_ports status ${CONFIG_ZONES}/${zone} --zone=${zone}
+
+ echo "#"
+ echo -e "# ${CLR_BOLD_BLU}Zone configurations:${NORMAL}"
+ hooks_run_zones status ${CONFIG_ZONES}/${zone} --zone=${zone}
+ echo "#"
}