#!/bin/bash
source "$(dirname "$0")/_lib.sh"
trace "$@"
TARGET="$1"
if [[ "$TARGET" == pci/* ]]; then
    BDF=$(bdf_from_target "$TARGET")
    IFACE=$(iface_from_bdf "$BDF")
else
    IFACE="$TARGET"
fi
[[ -z "$IFACE" ]] && { echo "Error: no interface for ${TARGET}" >&2; exit 1; }
OPER=$(cat "/sys/class/net/${IFACE}/operstate" 2>/dev/null)
case "$OPER" in
    up) echo "oper-status=up" ;;
    down|lowerlayerdown|dormant|notpresent) echo "oper-status=down" ;;
    *) echo "oper-status=unknown" ;;
esac
