Blame SOURCES/phys-port-name-gen

17b0f1
#!/bin/bash
17b0f1
17b0f1
SYSPATH="/sys/class/net/$1"
17b0f1
DEV_ID=$(<"${SYSPATH}/dev_id")
17b0f1
DEV_PORT=$(<"${SYSPATH}/dev_port")
17b0f1
PHYS_PORT_NAME=$(<"${SYSPATH}/phys_port_name")
17b0f1
17b0f1
#if PHYS_PORT_NAME is empty we are safe
17b0f1
[ -z "${PHYS_PORT_NAME}" ] && exit 0
17b0f1
17b0f1
# On-board index based names
17b0f1
if [ -n "${ID_NET_NAME_ONBOARD}" ]; then
17b0f1
    ID_NET_NAME_ONBOARD="${ID_NET_NAME_ONBOARD%d${DEV_PORT}}n${PHYS_PORT_NAME}"
17b0f1
fi
17b0f1
17b0f1
if [ -n "${DEV_ID}" ]; then
17b0f1
    DEV_ID=$(printf "%u" "${DEV_ID}")
17b0f1
    if [ "${DEV_ID}" -eq "0" ] && [ -n "${DEV_PORT}" ]; then
17b0f1
        # dev_port is decimal string, but we have a bug in net_id and we convert it to integer using base 16
17b0f1
        DEV_ID=$(printf "%u" "0x${DEV_PORT}")
17b0f1
    fi
17b0f1
fi
17b0f1
17b0f1
# PCI hot plug slot number based names
17b0f1
if [ -n "${ID_NET_NAME_SLOT}" ]; then
17b0f1
    ID_NET_NAME_SLOT="${ID_NET_NAME_SLOT%d${DEV_ID}}n${PHYS_PORT_NAME}"
17b0f1
fi
17b0f1
17b0f1
# PCI path based names
17b0f1
if [ -n "${ID_NET_NAME_PATH}" ]; then
17b0f1
    ID_NET_NAME_PATH="${ID_NET_NAME_PATH%d${DEV_ID}}n${PHYS_PORT_NAME}"
17b0f1
fi
17b0f1
17b0f1
[ -n "${ID_NET_NAME_ONBOARD}" ] && echo "ID_NET_NAME_ONBOARD=${ID_NET_NAME_ONBOARD}"
17b0f1
[ -n "${ID_NET_NAME_SLOT}" ] && echo "ID_NET_NAME_SLOT=${ID_NET_NAME_SLOT}"
17b0f1
[ -n "${ID_NET_NAME_PATH}" ] && echo "ID_NET_NAME_PATH=${ID_NET_NAME_PATH}"
17b0f1