diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2020-07-02 10:04:08 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2020-07-03 22:02:34 +0200 |
commit | 79f70bf5d62213e7e6ce2c5e15fdf6981dc19ef0 (patch) | |
tree | 75694cf5a2deb6910e8b7a89f9febff0a25ee1ca /src/initrd/nmi-cmdline-reader.c | |
parent | b2f03544a7947c3157f987f630e6c473cacbb53a (diff) | |
download | NetworkManager-79f70bf5d62213e7e6ce2c5e15fdf6981dc19ef0.tar.gz |
initrd: fix generation of MTU and cloned-mac-address for mastersbg/initrd-bond-cloned-mac
Setting a MTU or a cloned MAC for bonds/bridges/teams fails with:
# nm-initrd-generator -- bond=bond0:eno1,eno2:mode=802.3ad
ip=192.168.1.5::192.168.1.254:255.255.255.0:MyServer:bond0:none::01:02:03:04:05:06
bootdev=bond0 nameserver=192.168.1.1
<warn> cmdline-reader: 'bond' does not support setting cloned-mac-address
Fix this.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/460
Diffstat (limited to 'src/initrd/nmi-cmdline-reader.c')
-rw-r--r-- | src/initrd/nmi-cmdline-reader.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c index 69e5e56d07..e44841e683 100644 --- a/src/initrd/nmi-cmdline-reader.c +++ b/src/initrd/nmi-cmdline-reader.c @@ -237,20 +237,24 @@ get_word (char **argument, const char separator) } static void -_base_setting_set (NMConnection *connection, const char *property, const char *value) +connection_set (NMConnection *connection, const char *setting_name, const char *property, const char *value) { NMSetting *setting; - const char *type_name = nm_connection_get_connection_type (connection); - GObjectClass *object_class = g_type_class_ref (nm_setting_lookup_type (type_name)); - GParamSpec *spec = g_object_class_find_property (object_class, property); - - if (!spec) { - _LOGW (LOGD_CORE, "'%s' does not support setting %s", type_name, property); - return; + GType setting_type; + nm_auto_unref_gtypeclass GObjectClass *object_class = NULL; + GParamSpec *spec; + + setting_type = nm_setting_lookup_type (setting_name); + object_class = g_type_class_ref (setting_type); + spec = g_object_class_find_property (object_class, property); + nm_assert (spec); + + setting = nm_connection_get_setting_by_name (connection, setting_name); + if (!setting) { + setting = g_object_new (setting_type, NULL); + nm_connection_add_setting (connection, setting); } - setting = nm_connection_get_setting_by_name (connection, type_name); - if (G_IS_PARAM_SPEC_UINT (spec)) { guint v; @@ -259,14 +263,12 @@ _base_setting_set (NMConnection *connection, const char *property, const char *v || !nm_g_object_set_property_uint (G_OBJECT (setting), property, v, NULL)) { _LOGW (LOGD_CORE, "Could not set property '%s.%s' to '%s'", - type_name, property, value); + setting_name, property, value); } } else if (G_IS_PARAM_SPEC_STRING (spec)) g_object_set (setting, property, value, NULL); else - _LOGW (LOGD_CORE, "Don't know how to set '%s' of %s", property, type_name); - - g_type_class_unref (object_class); + _LOGW (LOGD_CORE, "Don't know how to set '%s' of %s", property, setting_name); } static void @@ -577,10 +579,10 @@ reader_parse_ip (Reader *reader, const char *sysfs_dir, char *argument) } if (mtu && *mtu) - _base_setting_set (connection, "mtu", mtu); + connection_set (connection, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MTU, mtu); if (macaddr && *macaddr) - _base_setting_set (connection, "cloned-mac-address", macaddr); + connection_set (connection, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, macaddr); } static void @@ -635,7 +637,7 @@ reader_parse_master (Reader *reader, NM_SETTING_CONNECTION_MASTER, master, NULL); if (mtu) - _base_setting_set (connection, "mtu", mtu); + connection_set (connection, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MTU, mtu); } while (slaves && *slaves != '\0'); if (argument && *argument) |