local device=${1}
local mac
+ [ -n "${device}" ] || return 1
+
if is_mac ${device}; then
mac=${device}
device=$(get_device_by_mac ${device})
local destination=$2
# Replace + by a valid number
- if grep -q "+$" <<<${destination}; then
- local number
+ if [[ ${destination} =~ +$ ]]; then
+ local number=0
destination=$(sed -e "s/+//" <<<$destination)
- number=0
while [ "${number}" -le "100" ]; do
if ! device_exists "${destination}${number}"; then
destination="${destination}${number}"
done
fi
- # Check if devices exist
+ # Check if devices exists
if ! device_exists ${source} || device_exists ${destination}; then
return 4
fi
}
function do_attach() {
- device_rename $(get_device_by_mac_and_vid ${port} ${ID}) $(port_name)
- zone_add_port ${zone} $(get_device ${port} ${ID})
+ if ! zone_has_device_attached ${zone} $(port_name); then
+ device_rename $(get_device_by_mac_and_vid ${port} ${ID}) $(port_name)
+ zone_add_port ${zone} $(get_device ${port} ${ID})
+ fi
}
function do_detach() {
- zone_del_port ${zone} $(get_device_by_mac_and_vid ${port} ${ID})
+ if zone_has_device_attached ${zone} $(port_name); then
+ zone_del_port ${zone} $(get_device_by_mac_and_vid ${port} ${ID})
+ fi
}
function do_status() {
RET=$?
if [ "$RET" -eq "0" ]; then
vecho "Successfully added port ${BOLD}${port}${NORMAL} (${hook} $@) to ${BOLD}${zone}${NORMAL}."
- cmd /lib/network/port --port=${port} up
else
error "Hook ${BOLD}${hook}${NORMAL} exited with $RET."
return $RET
error "Hook ${BOLD}${hook}${NORMAL} does not exist or is not executeable."
return 1
fi
- cmd /lib/network/zone --zone=${zone} up
}
function port_del() {
mkdir -p ${CONFIG_ZONES}/${zone}
vecho "Successfully added zone ${BOLD}${zone}${NORMAL}."
- cmd /lib/network/zone --zone=${zone} up # Done by reload??
}
function zone_del() {