[[ ${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() {
local speed=$(__device_get_file ${device} speed)
+ # Exit for no output (i.e. no link detected)
+ isset speed || return ${EXIT_ERROR}
+
# Don't return anything for negative values
[ ${speed} -lt 0 ] && return ${EXIT_ERROR}
device_get_duplex() {
local device=${1}
- __device_get_file ${device} duplex
+ local duplex=$(__device_get_file ${device} duplex)
+
+ case "${duplex}" in
+ unknown)
+ return ${EXIT_ERROR}
+ ;;
+ *)
+ print "${duplex}"
+ ;;
+ esac
}
device_get_link_string() {
local device=${1}
- if lock_acquire "smp-affinity"; then
+ if lock_acquire "smp-affinity" 60; then
device_set_smp_affinity ${device} auto
lock_release "smp-affinity"
done
}
+device_supports_multiqueue() {
+ local device=${1}
+
+ local num_queues=$(device_num_queues ${device})
+
+ if isset num_queues && [ ${num_queues} -gt 2 ]; then
+ return ${EXIT_TRUE}
+ fi
+
+ return ${EXIT_FALSE}
+}
+
+device_num_queues() {
+ local device=${1}
+ local type=${2}
+
+ isset type && assert isoneof type rx tx
+
+ local i=0
+
+ local q
+ for q in $(device_get_queues ${device}); do
+ case "${type},${q}" in
+ rx,rx-*)
+ (( i++ ))
+ ;;
+ tx,tx-*)
+ (( i++ ))
+ ;;
+ *,*)
+ (( i++ ))
+ ;;
+ esac
+ done
+
+ print ${i}
+}
+
+device_queue_get_smp_affinity() {
+ assert [ $# -eq 2 ]
+
+ local device=${1}
+ local queue=${2}
+
+ local path="${SYS_CLASS_NET}/${device}/queues/${queue}"
+
+ case "${queue}" in
+ rx-*)
+ path="${path}/rps_cpus"
+ ;;
+ tx-*)
+ path="${path}/xps_cpus"
+ ;;
+ esac
+ assert [ -r "${path}" ]
+
+ __bitmap_to_processor_ids $(<${path})
+}
+
device_queue_set_smp_affinity() {
assert [ $# -eq 3 ]