summaryrefslogtreecommitdiffstats
path: root/linux/bin
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2022-05-24 05:47:26 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2022-05-24 10:50:12 +0000
commita42d19fefdb99e1bf6787fe79460a27ffeb222ed (patch)
tree696bc01d37926ffc9ba4c06022d2e2e8e8b3faba /linux/bin
parentAdding link-down-on-close=on in linux-i40e. (diff)
downloadservice-tools-a42d19fefdb99e1bf6787fe79460a27ffeb222ed.tar.xz
service-tools-a42d19fefdb99e1bf6787fe79460a27ffeb222ed.zip
Refactoring linux-i40e for start/stop/status actions.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'linux/bin')
-rwxr-xr-xlinux/bin/linux-i40e140
1 files changed, 128 insertions, 12 deletions
diff --git a/linux/bin/linux-i40e b/linux/bin/linux-i40e
index b86c063..2c8f322 100755
--- a/linux/bin/linux-i40e
+++ b/linux/bin/linux-i40e
@@ -22,22 +22,138 @@
set -e
PROGRAM="$(basename ${0})"
-DEVICES="$(grep DRIVER=i40e /sys/class/net/*/device/uevent | awk -F/ '{ print $5 }' | sort -V)"
+
+RED="\033[1;33;31m"
+GREEN="\033[1;33;32m"
+YELLOW="\033[1;33;33m"
+BLUE="\033[1;33;34m"
+WHITE="\033[1;33;37m"
+NORMAL="\033[0m"
+
+Ethtool_get ()
+{
+ DEVICE="${1}"
+ FLAG="${2}"
+ TARGET_VALUE="${3}"
+
+ if ethtool --show-priv-flags ${DEVICE} | awk '{ print $1 }' | grep -qs "^${FLAG}$"
+ then
+ CURRENT_VALUE="$(ethtool --show-priv-flags ${DEVICE} | awk "/^${FLAG} / { print \$3 }")"
+
+ if [ "${CURRENT_VALUE}" = "${TARGET_VALUE}" ]
+ then
+ echo -n " ${FLAG}=${GREEN}${CURRENT_VALUE}${NORMAL}"
+ else
+ echo -n " ${FLAG}=${RED}${CURRENT_VALUE}${NORMAL}"
+ fi
+ fi
+}
+
+Ethtool_set ()
+{
+ DEVICE="${1}"
+ FLAG="${2}"
+ VALUE="${3}"
+
+ if ethtool --show-priv-flags ${DEVICE} | awk '{ print $1 }' | grep -qs "^${FLAG}$"
+ then
+ echo -n " ${FLAG}"
+ ethtool --set-priv-flags ${DEVICE} ${FLAG} ${VALUE}
+ echo -n "=${VALUE}"
+ fi
+}
+
+Test_root ()
+{
+ case "$(id -u)" in
+ 0)
+ ;;
+
+ *)
+ echo "'${PROGRAM}': must be run as root (or use sudo)" >&2
+ exit 1
+ ;;
+ esac
+}
+
+Start ()
+{
+ Test_root
+
+ for DEVICE in ${DEVICES}
+ do
+ echo -n "Configuring ${DEVICE}:"
+ Ethtool_set ${DEVICE} disable-fw-lldp on
+ Ethtool_set ${DEVICE} link-down-on-close on
+ echo
+ done
+}
+
+Stop ()
+{
+ Test_root
+
+ for DEVICE in ${DEVICES}
+ do
+ echo -n "Deconfiguring ${DEVICE}:"
+ Ethtool_set ${DEVICE} disable-fw-lldp off
+ Ethtool_set ${DEVICE} link-down-on-close off
+ echo
+ done
+}
+
+Status ()
+{
+ for DEVICE in ${DEVICES}
+ do
+ echo -n "${DEVICE}:"
+ Ethtool_get ${DEVICE} disable-fw-lldp on
+ Ethtool_get ${DEVICE} link-down-on-close on
+ echo
+ done
+}
+
+Usage ()
+{
+ echo "Usage: ${PROGRAM} {start|stop|status}" >&2
+ echo >&2
+ echo "See ${PROGRAM}(1) for more information." >&2
+
+ exit 1
+}
+
+if [ -z "${1}" ]
+then
+ Usage
+fi
+
+if [ ! -x /usr/sbin/ethtool ]
+then
+ echo "'${PROGRAM}': /usr/sbin/ethtool - no such file." >&2
+ exit 1
+fi
+
+DEVICES="$(grep -s '^DRIVER=i40e' /sys/class/net/*/device/uevent | awk -F/ '{ print $5 }' | sort -V)"
if [ -z "${DEVICES}" ]
then
- echo "'${PROGRAM}': no network devices available with i40e driver"
+ echo "'${PROGRAM}': no network devices available with i40e driver" >&2
fi
-for DEVICE in ${DEVICES}
-do
- echo -n "'${DEVICE}':"
+case "${1}" in
+ start)
+ Start
+ ;;
+
+ stop)
+ Stop
+ ;;
- echo -n " disable-fw-lldp"
- ethtool --set-priv-flags ${DEVICE} disable-fw-lldp on
- echo -n "=on"
+ status)
+ Status
+ ;;
- echo -n " link-down-on-close"
- ethtool --set-priv-flags ${DEVICE} link-down-on-close on
- echo "=on"
-done
+ *)
+ Usage
+ ;;
+esac