aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Nykryn <lnykryn@redhat.com>2020-07-02 13:56:10 +0200
committerJan Macku <jamacku@redhat.com>2021-06-16 09:34:12 +0200
commit55cdbccad3f6492b1e721154a45e5884044db76d (patch)
tree2d808b735bb420e7c2cf0ebcccec401f142a207d /src
parentb748244cf9905696baf1bc16e0432f85093414c2 (diff)
downloadinitscripts-55cdbccad3f6492b1e721154a45e5884044db76d.tar
initscripts-55cdbccad3f6492b1e721154a45e5884044db76d.tar.gz
initscripts-55cdbccad3f6492b1e721154a45e5884044db76d.tar.bz2
initscripts-55cdbccad3f6492b1e721154a45e5884044db76d.tar.xz
initscripts-55cdbccad3f6492b1e721154a45e5884044db76d.zip
rename_device: also support dracut-style kernel cmdline configuration
There are 2 cases where this might be useful. * On machines with initrd build without dracut-network, you can now still use ifname option * On older kernels where double renaming was allowed, normal system replaced the name set by initrd.
Diffstat (limited to 'src')
-rw-r--r--src/rename_device.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/rename_device.c b/src/rename_device.c
index c39f447d..b67a536b 100644
--- a/src/rename_device.c
+++ b/src/rename_device.c
@@ -278,6 +278,46 @@ char *get_config_by_hwaddr(char *hwaddr, char *current) {
return first;
}
+/* Let's check kernel cmdline and also process ifname= entries
+ * as they are documented in dracut.cmdline(7)
+ * Example: ifname=test:aa:bb:cc:dd:ee:ff
+ */
+char *get_cmdline_by_hwaddr(char *hwaddr) {
+ gchar *contents;
+ gchar **entries;
+ int i;
+ char *name = NULL;
+ g_file_get_contents("/proc/cmdline", &contents, NULL, NULL);
+ entries = g_strsplit(contents," ", 0);
+ for (i = 0; entries[i]; i++) {
+ char *c = (char *) entries[i];
+ char *n;
+
+ if (!g_str_has_prefix((gchar *)c,"ifname="))
+ continue;
+
+ c = strstr(c, "=");
+ if (c == NULL)
+ continue;
+ c++;
+ n=c;
+
+ c = strstr(c, ":");
+ if (c == NULL)
+ continue;
+ *c = '\0';
+ c++;
+
+ if (!strcasecmp(c, hwaddr)) {
+ name = strdup(n);
+ break;
+ }
+ }
+ g_free(contents);
+ g_strfreev(entries);
+ return name;
+}
+
void take_lock() {
int count = 0;
int lockfd;
@@ -343,7 +383,9 @@ int main(int argc, char **argv) {
hw = get_hwaddr(src);
if (!hw)
goto out_unlock;
- target = get_config_by_hwaddr(hw, src);
+ target = get_cmdline_by_hwaddr(hw);
+ if (!target)
+ target = get_config_by_hwaddr(hw, src);
if (!target)
goto out_unlock;