diff options
author | Dan HorĂ¡k <dan@danny.cz> | 2019-10-22 16:56:38 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2019-11-04 16:21:58 +0100 |
commit | c7423dca894caa6083f0160c61eaa5e3fa724efd (patch) | |
tree | c64bfcc71deabb561c1e5a5710d112c2dc3e0a26 | |
parent | c27f5030e9dd5ec9065de439bc43330e84e0c273 (diff) | |
download | NetworkManager-c7423dca894caa6083f0160c61eaa5e3fa724efd.tar.gz |
initrd: prepare interface in rd.znet only if persistent interface names are enabled
When processing the rd.znet option set the interface name only in case when
the persistent interface names feature isn't disabled via net.ifnames=0
[lkundrak@v3.sk: minor tweaks to the net.ifnames=0 parsing]
-rw-r--r-- | src/initrd/nmi-cmdline-reader.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c index 3a3227254a..76abb2bb77 100644 --- a/src/initrd/nmi-cmdline-reader.c +++ b/src/initrd/nmi-cmdline-reader.c @@ -683,27 +683,18 @@ parse_rd_peerdns (GHashTable *connections, char *argument) } static void -parse_rd_znet (GHashTable *connections, char *argument) +parse_rd_znet (GHashTable *connections, char *argument, gboolean net_ifnames) { const char *nettype; const char *subchannels[4] = { 0, 0, 0, 0 }; const char *tmp; - const char *ifname, *prefix; - const char *bus_id; - size_t bus_id_len; - size_t bus_id_start; + gs_free char *ifname = NULL; + const char *prefix; NMConnection *connection; NMSettingWired *s_wired; nettype = get_word (&argument, ','); subchannels[0] = get_word (&argument, ','); - - /* The following logic is taken from names_ccw() in systemd/src/udev/udev-builtin-net_id.c */ - bus_id = subchannels[0]; - bus_id_len = strlen (bus_id); - bus_id_start = strspn (bus_id, ".0"); - bus_id += bus_id_start < bus_id_len ? bus_id_start : bus_id_len - 1; - subchannels[1] = get_word (&argument, ','); if (nm_streq0 (nettype, "ctc")) { @@ -713,7 +704,20 @@ parse_rd_znet (GHashTable *connections, char *argument) prefix = "en"; } - ifname = g_strdup_printf ("%sc%s", prefix, bus_id); + if (net_ifnames == TRUE) { + const char *bus_id; + size_t bus_id_len; + size_t bus_id_start; + + /* The following logic is taken from names_ccw() in systemd/src/udev/udev-builtin-net_id.c */ + bus_id = subchannels[0]; + bus_id_len = strlen (bus_id); + bus_id_start = strspn (bus_id, ".0"); + bus_id += bus_id_start < bus_id_len ? bus_id_start : bus_id_len - 1; + + ifname = g_strdup_printf ("%sc%s", prefix, bus_id); + } + connection = get_conn (connections, ifname, NM_SETTING_WIRED_SETTING_NAME); s_wired = nm_connection_get_setting_wired (connection); g_object_set (s_wired, @@ -752,11 +756,19 @@ nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv) gboolean ignore_bootif = FALSE; gboolean neednet = FALSE; gs_free char *bootif_val = NULL; + gboolean net_ifnames = TRUE; int i; connections = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_object_unref); for (i = 0; argv[i]; i++) { + if (strcmp (argv[i], "net.ifnames=0") == 0) + net_ifnames = FALSE; + else if (g_str_has_prefix (argv[i], "net.ifnames=")) + net_ifnames = TRUE; + } + + for (i = 0; argv[i]; i++) { gs_free char *argument_clone = NULL; char *argument; @@ -787,7 +799,7 @@ nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv) else if (strcmp (tag, "rd.neednet") == 0) neednet = _nm_utils_ascii_str_to_bool (argument, TRUE); else if (strcmp (tag, "rd.znet") == 0) - parse_rd_znet (connections, argument); + parse_rd_znet (connections, argument, net_ifnames); else if (strcasecmp (tag, "BOOTIF") == 0) { nm_clear_g_free (&bootif_val); bootif_val = g_strdup (argument); |