summaryrefslogtreecommitdiffstats
path: root/linux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xlinux/bin/linux-i40e140
-rw-r--r--linux/share/systemd/linux-i40e.service5
2 files changed, 131 insertions, 14 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
diff --git a/linux/share/systemd/linux-i40e.service b/linux/share/systemd/linux-i40e.service
index 379a6bb..5d7f99f 100644
--- a/linux/share/systemd/linux-i40e.service
+++ b/linux/share/systemd/linux-i40e.service
@@ -1,14 +1,15 @@
# Open Infrastructure: service-tools
[Unit]
-Description=linux-i40e options
+Description=setting recommended options for the Linux i40e device driver
Documentation=man:linux-i40e
Before=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
-ExecStart=/usr/bin/linux-i40e
+ExecStart=/usr/bin/linux-i40e start
+ExecStop=/usr/bin/linux-i40e stop
StandardOutput=journal
StandardError=journal