summaryrefslogtreecommitdiff
path: root/etc/systemd/ibft-rule-generator
diff options
context:
space:
mode:
authorLee Duncan <lduncan@suse.com>2022-04-05 11:00:26 -0700
committerGitHub <noreply@github.com>2022-04-05 11:00:26 -0700
commit1451108792c1187974b87399f71822b59d62948c (patch)
treef49bd21ed810f1fdd6f9833cd7b13cde3732fc46 /etc/systemd/ibft-rule-generator
parent4f5c4af2047756f86400ac66491eb1b6c6f7d8bc (diff)
parent147c681385fbb694b87498a3ace64637f79f079d (diff)
downloadopen-iscsi-1451108792c1187974b87399f71822b59d62948c.tar.gz
Merge pull request #335 from gonzoleeman/latest-build-cleanups-v2
Latest build cleanups and bug fixes
Diffstat (limited to 'etc/systemd/ibft-rule-generator')
-rw-r--r--etc/systemd/ibft-rule-generator36
1 files changed, 36 insertions, 0 deletions
diff --git a/etc/systemd/ibft-rule-generator b/etc/systemd/ibft-rule-generator
new file mode 100644
index 0000000..038a4c2
--- /dev/null
+++ b/etc/systemd/ibft-rule-generator
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# Systemd rule generator for ibft interfaces
+#
+# Copyright (c) 2022 Hannes Reinecke, SUSE Labs
+# This script is licensed under the GPL.
+#
+# When booted with 'ip=ibft' dracut will rename the
+# interface to 'ibft*'. After systemd has started
+# it'll try to rename the interface yet again with
+# a persistent name.
+# But as the ibft interface is already renamed _and_
+# in use, the second renaming will fail and udev
+# will complain.
+# So add a dummy rule which signals udev the correct name
+#
+# Interface renaming happes at 80-net-setup-link.rules,
+# so we need to hook in before that.
+#
+IBFT_RULE_DIR=/run/udev/rules.d
+IBFT_RULES=$(IBFT_RULE_DIR)/79-ibft.rules
+
+# ensure we have a rules directory and no rules file
+if [ -d ${IBFT_RULE_DIR} ] ; then
+ rm -f ${IBFT_RULES} 2> /dev/null
+else
+ mkdir -p ${IBFT_RULE_DIR}
+fi
+
+# create an iBFT udev rule for each iBFT NIC found
+for d in /sys/firmware/ibft/ethernet* ; do
+ [ -d "$d" ] || break
+ num="${d##*/ethernet}"
+ read mac < $d/mac
+ printf 'SUBSYSTEM=="net", KERNEL=="ibft*", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", ATTR{type}=="1", NAME="ibft%s"\n' "$mac" "$num" >> $IBFT_RULES
+done