[[ $1 =~ ^[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]\:[0-9a-f][0-9a-f]$ ]]
}
+function is_uuid() {
+ local string=${1}
+
+ # Length must be 37 characters
+ if [ ${#string} -eq 36 ] \
+ && [ "${string:8:1}" = "-" ] \
+ && [ "${string:13:1}" = "-" ] \
+ && [ "${string:18:1}" = "-" ] \
+ && [ "${string:23:1}" = "-" ]; then
+ return ${EXIT_OK}
+ fi
+ return ${EXIT_ERROR}
+}
+
function get_device_by_mac() {
local mac=${1}
local device
[ "${1:0:3}" = "ppp" ]
}
+function device_is_loopback() {
+ local device=$(devicify ${1})
+ [ "${device}" = "lo" ]
+}
+
function device_is_real() {
local device=${1}
- [ "${device}" = "lo" ] && \
+ device_is_loopback ${device} && \
return ${EXIT_ERROR}
device_is_bonding ${device} && \
return ${EXIT_OK}
}
+function device_type() {
+ local device=$(devicify ${1})
+
+ if device_is_vlan ${device}; then
+ echo "vlan"
+
+ elif device_is_bonding ${device}; then
+ echo "bonding"
+
+ elif device_is_bridge ${device}; then
+ echo "bridge"
+
+ elif device_is_ppp ${device}; then
+ echo "ppp"
+
+ elif device_is_loopback ${device}; then
+ echo "loopback"
+
+ elif device_is_real ${device}; then
+ echo "real"
+
+ else
+ echo "unknown"
+ fi
+}
+
function device_has_vlans() {
if [ ! -e "/proc/net/vlan/config" ]; then
return 1
esac
shift
done
+
if [ "${reload}" = "1" ]; then
# Reloading network to apply changes immediately
vecho "Reloading network settings..."
cmd $0 reload
+
+ # Reload firewall, too
+ firewall=$(which firewall 2>/dev/null)
+ if [ -n "${firewall}" ]; then
+ vecho "Reloading firewall..."
+ cmd ${firewall} reload
+ fi
fi
decho "Exiting with code ${code}."
}
function port_show() {
- local port=$(devicify $1)
+ local port
+ if [ $# -eq 0 ]; then
+ for port in /sys/class/net/*; do
+ port=${port##*/}
+ device_is_real ${port} || continue
+ port_show ${port}
+ done
+ return
+ fi
+
+ port=$(devicify $1)
echo "##################################################"
echo "#"
echo "#"
}
+function port_raw() {
+ local port
+ if [ $# -eq 0 ]; then
+ for port in /sys/class/net/*; do
+ port=${port##*/}
+ device_is_real ${port} || continue
+ port_raw ${port}
+ done
+ return
+ fi
+
+ port=$(devicify $1)
+
+ cat <<EOF
+[${port}]
+type=$(device_type ${port})
+mac=$(macify ${port})
+carrier=$(device_has_carrier ${port} && echo "1" || echo "0")
+up=$(device_is_up ${port} && echo "1" || echo "0")
+
+EOF
+}
+
function port_add() {
local zone=${1}
local hook=${2}
shift 2
- decho "Function: port_add"
- decho " Zone: ${zone} Hook: ${hook} $@"
-
if ! zone_exists ${zone}; then
error "Zone ${BOLD}${zone}${NORMAL} does not exist."
return 1
}
function port_del() {
- local port
- local zone
+ local config
local hook
+ local uuid
- zone=$1
- port=$(devicify $2)
- hook=${3-ethernet}
+ local zone=${1}
+ shift
- shift 3
+ if is_uuid ${1}; then
+ uuid=${1}
+ config="${CONFIG_UUIDS}/${uuid}"
- decho "Function: port_del"
- decho " Zone: ${zone} Port: ${port} Hook: ${hook}"
-
- if [ -x "/lib/network/hooks/${hook}" ]; then
- cmd /lib/network/port ${port} down ## XXX How do we identify only that one hook?
- cmd /lib/network/hooks/${hook} --port=${port} --zone=${zone} remove $@
- RET=$?
- if [ "$RET" -eq "0" ]; then
- vecho "Successfully removed port ${BOLD}${port}${NORMAL} (${hook} $@) from ${BOLD}${zone}${NORMAL}."
+ if [ -e "${config}" ]; then
+ hook=$(config_get_hook ${config})
else
- error "Hook ${BOLD}${hook}${NORMAL} exited with $RET."
- return $RET
+ error "Given config file does not exist: ${config}."
+ return 1
fi
- else
- error "Hook ${BOLD}${hook}${NORMAL} does not exist or is not executeable."
- return 1
fi
+
+ hook_run --config=${config} pre-down
+ hook_run --config=${config} post-down
+ hook_run --config=${config} rem
}
function zone_discover() {
}
+function zone_raw() {
+ local zone
+ if [ $# -eq 0 ]; then
+ for zone in $(zone_list); do
+ zone_raw ${zone##*/}
+ done
+ return
+ fi
+
+ zone=${1}
+
+cat <<EOF
+[${zone}]
+up=$(zone_is_up ${zone} && echo "1" || echo "0")
+
+EOF
+}
+
function zone_add() {
local zone=$1
hook|hooks)
case "$1" in
list)
- for i in ${HOOKS_DIR}/*; do
- hook_exists ${i##*/} && echo ${i}
- done
+ hook_list
_exit $?
;;
*)
port_show $@
_exit $?
;;
+ _raw)
+ port_raw $@
+ _exit $?
+ ;;
esac
;;
z*)
zone=$1; shift
zone_run --zone=${zone} ${arg} $@
;;
+ _raw)
+ zone_raw $@
+ _exit $?
+ ;;
esac
;;
show)
- case "${1}" in
+ arg=${1}
+ shift
+ case "${arg}" in
ports)
- for port in /sys/class/net/*; do
- port=${port##*/}
- device_is_real ${port} || continue
- port_show ${port}
- done
+ port_show $@
_exit 0
;;
esac