[[ ${device} =~ ^dummy[0-9]+$ ]]
}
+device_is_ipsec() {
+ local device="${1}"
+
+ [[ ${device} =~ ^ipsec\- ]]
+}
+
# Check if the device is a wireless device
device_is_wireless() {
local device=${1}
[ -d "${SYS_CLASS_NET}/${device}/phy80211" ]
}
+device_is_vti() {
+ local device=${1}
+
+ local type=$(__device_get_file ${device} type)
+
+ [ "${type}" = "768" ] && return ${EXIT_OK} || return ${EXIT_ERROR}
+}
+
device_get_phy() {
local device="${1}"
}
device_is_phy() {
- phy_exists $@
+ phy_exists "$@"
}
device_is_serial() {
- serial_exists $@
+ serial_exists "$@"
}
# Returns true if a device is a tun device
elif device_is_phy ${device}; then
echo "phy"
+ elif device_is_vti ${device}; then
+ echo "vti"
+
else
echo "unknown"
fi
# Check if the device is free
device_is_free() {
- ! device_is_used $@
+ ! device_is_used "$@"
}
# Check if the device is used
fi
}
+device_set_master() {
+ local device="${1}"
+ assert isset device
+
+ local master="${2}"
+ assert isset master
+
+ if ! cmd ip link set "${device}" master "${master}"; then
+ log ERROR "Could not set master ${master} for device ${device}"
+ return ${EXIT_ERROR}
+ fi
+
+ return ${EXIT_OK}
+}
+
+device_remove_master() {
+ local device="${1}"
+ assert isset device
+
+ if ! cmd ip link set "${device}" nomaster; then
+ log ERROR "Could not remove master for device ${device}"
+ return ${EXIT_ERROR}
+ fi
+
+ return ${EXIT_OK}
+}
+
# Set device up
device_set_up() {
assert [ $# -eq 1 ]
seconds="$(cli_get_val "${arg}")"
;;
esac
- done <<< "$(args $@)"
+ done <<< "$(args "$@")"
assert isinteger seconds
;;
esac
- listmatch ${addr} $(device_get_addresses ${device})
+ list_match ${addr} $(device_get_addresses ${device})
}
device_get_addresses() {
local device=${1}
local file=${2}
- assert isset device
- assert isset file
-
- local path="${SYS_CLASS_NET}/${device}/${file}"
- [ -r "${path}" ] || return ${EXIT_ERROR}
-
- echo "$(<${path})"
+ fread "${SYS_CLASS_NET}/${device}/${file}"
}
__device_set_file() {
local file="${2}"
local value="${3}"
- local path="${SYS_CLASS_NET}/${device}/${file}"
- if [ ! -w "${path}" ]; then
- log DEBUG "Cannot write to file '${file}' (${value})"
- return ${EXIT_ERROR}
- fi
-
- echo "${value}" > "${path}"
+ fappend "${SYS_CLASS_NET}/${device}/${file}" "${value}"
}
device_get_rx_bytes() {