diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2015-09-21 18:24:07 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2015-10-20 17:13:21 +0200 |
commit | 7cf30fe47ee43e7b7d2e962684b59145fd7ca8a8 (patch) | |
tree | f4deeb541a88313c29f86c071cb894dbffe7aca6 | |
parent | d952ee637f0ec5307de589f108108229059eff9f (diff) | |
download | NetworkManager-7cf30fe47ee43e7b7d2e962684b59145fd7ca8a8.tar.gz |
wake-on-lan: add option to keep existing settings
Add a new 'ignore' option to NMSettingWired.wake-on-lan which disables
management of wake-on-lan by NetworkManager (i.e. the pre-existing
option will not be touched). Also, change the default behavior to be
'ignore' instead of 'disabled'.
https://bugzilla.gnome.org/show_bug.cgi?id=755182
(cherry picked from commit e587dcb16eb045f55f6cba45987be75f83d0c230)
-rw-r--r-- | clients/cli/settings.c | 13 | ||||
-rw-r--r-- | libnm-core/nm-setting-wired.c | 11 | ||||
-rw-r--r-- | libnm-core/nm-setting-wired.h | 19 | ||||
-rw-r--r-- | src/devices/nm-device-ethernet.c | 11 | ||||
-rw-r--r-- | src/platform/nm-platform-utils.c | 3 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/reader.c | 21 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/writer.c | 4 |
7 files changed, 57 insertions, 25 deletions
diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 8d2d70be0a..44395c5447 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -1545,7 +1545,10 @@ nmc_property_wired_set_wake_on_lan (NMSetting *setting, const char *prop, gboolean ret; long int t; - if (nmc_string_to_int_base (val, 0, TRUE, 0, NM_SETTING_WIRED_WAKE_ON_LAN_ALL, &t)) + if (nmc_string_to_int_base (val, 0, TRUE, 0, + NM_SETTING_WIRED_WAKE_ON_LAN_ALL + | NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS, + &t)) wol = (NMSettingWiredWakeOnLan) t; else { ret = nm_utils_enum_from_str (nm_setting_wired_wake_on_lan_get_type (), val, @@ -1557,7 +1560,7 @@ nmc_property_wired_set_wake_on_lan (NMSetting *setting, const char *prop, || g_ascii_strcasecmp (err_token, "disabled") == 0) wol = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; else { - g_set_error (error, 1, 0, _("invalid option '%s', use a combination of [%s] or 'default' or 'none'"), + g_set_error (error, 1, 0, _("invalid option '%s', use a combination of [%s] or 'ignore', 'default' or 'none'"), err_token, nm_utils_enum_to_str (nm_setting_wired_wake_on_lan_get_type (), NM_SETTING_WIRED_WAKE_ON_LAN_ALL)); @@ -1566,9 +1569,9 @@ nmc_property_wired_set_wake_on_lan (NMSetting *setting, const char *prop, } } - if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) && - NM_FLAGS_ANY (wol, NM_SETTING_WIRED_WAKE_ON_LAN_ALL)) { - g_set_error_literal (error, 1, 0, _("'default' is incompatible with other flags")); + if ( NM_FLAGS_ANY (wol, NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS) + && !nm_utils_is_power_of_two (wol)) { + g_set_error_literal (error, 1, 0, _("'default' and 'ignore' are incompatible with other flags")); return FALSE; } diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index 3d0c5b6464..c38b187488 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -696,12 +696,12 @@ verify (NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if ( NM_FLAGS_HAS (priv->wol, NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) - && NM_FLAGS_ANY (priv->wol, NM_SETTING_WIRED_WAKE_ON_LAN_ALL)) { + if ( NM_FLAGS_ANY (priv->wol, NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS) + && !nm_utils_is_power_of_two (priv->wol)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("Wake-on-LAN mode 'default' is incompatible with other flags")); + _("Wake-on-LAN mode 'default' and 'ignore' are exclusive flags")); g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_WAKE_ON_LAN); return FALSE; } @@ -1190,7 +1190,10 @@ nm_setting_wired_class_init (NMSettingWiredClass *setting_class) * May be any combination of %NM_SETTING_WIRED_WAKE_ON_LAN_PHY, * %NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST, %NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST, * %NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST, %NM_SETTING_WIRED_WAKE_ON_LAN_ARP, - * %NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC. + * %NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC or the special values + * %NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT (to use global settings) and + * %NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE (to disable management of Wake-on-LAN in + * NetworkManager). * * Since: 1.0.6 **/ diff --git a/libnm-core/nm-setting-wired.h b/libnm-core/nm-setting-wired.h index 44b7c4d023..e1fd6f6725 100644 --- a/libnm-core/nm-setting-wired.h +++ b/libnm-core/nm-setting-wired.h @@ -43,14 +43,19 @@ G_BEGIN_DECLS /** * NMSettingWiredWakeOnLan: * @NM_SETTING_WIRED_WAKE_ON_LAN_NONE: Wake-on-LAN disabled - * @NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT: Use the default value * @NM_SETTING_WIRED_WAKE_ON_LAN_PHY: Wake on PHY activity * @NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST: Wake on unicast messages * @NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST: Wake on multicast messages * @NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST: Wake on broadcast messages * @NM_SETTING_WIRED_WAKE_ON_LAN_ARP: Wake on ARP * @NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC: Wake on magic packet - * @NM_SETTING_WIRED_WAKE_ON_LAN_ALL: Wake on all events + * @NM_SETTING_WIRED_WAKE_ON_LAN_ALL: Wake on all events. This does not + * include the exclusive flags @NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT or + * @NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE. + * @NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT: Use the default value + * @NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE: Don't change configured settings + * @NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS: Mask of flags that are + * incompatible with other flags * * Options for #NMSettingWired:wake-on-lan. Note that not all options * are supported by all devices. @@ -59,15 +64,19 @@ G_BEGIN_DECLS */ typedef enum { /*< flags >*/ NM_SETTING_WIRED_WAKE_ON_LAN_NONE = 0, /*< skip >*/ - NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT = (1 << 0), NM_SETTING_WIRED_WAKE_ON_LAN_PHY = (1 << 1), NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST = (1 << 2), NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST = (1 << 3), NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST = (1 << 4), NM_SETTING_WIRED_WAKE_ON_LAN_ARP = (1 << 5), NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC = (1 << 6), - _NM_SETTING_WIRED_WAKE_ON_LAN_LAST, /*< skip >*/ - NM_SETTING_WIRED_WAKE_ON_LAN_ALL = (((_NM_SETTING_WIRED_WAKE_ON_LAN_LAST - 1) << 1) - 1 - NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) /*< skip >*/ + + _NM_SETTING_WIRED_WAKE_ON_LAN_LAST_OPT, /*< skip >*/ + NM_SETTING_WIRED_WAKE_ON_LAN_ALL = (((_NM_SETTING_WIRED_WAKE_ON_LAN_LAST_OPT - 1) << 1) - 1) - (1 << 0 /*DEFAULT*/), /*< skip >*/ + + NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT = (1 << 0), + NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE = (1 << 15), + NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS = NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT | NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE, /*< skip >*/ } NMSettingWiredWakeOnLan; #define NM_SETTING_WIRED_PORT "port" diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index bd7554152d..8a02384328 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1198,15 +1198,22 @@ wake_on_lan_enable (NMDevice *device) value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA, "ethernet.wake-on-lan", device); + if (value) { wol = _nm_utils_ascii_str_to_int64 (value, 10, NM_SETTING_WIRED_WAKE_ON_LAN_NONE, - NM_SETTING_WIRED_WAKE_ON_LAN_ALL, + G_MAXINT32, NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT); + + if ( NM_FLAGS_ANY (wol, NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS) + && !nm_utils_is_power_of_two (wol)) { + nm_log_dbg (LOGD_ETHER, "invalid default value %u for wake-on-lan", (guint) wol); + wol = NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT; + } if (wol != NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) goto found; } - wol = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; + wol = NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE; found: return nmp_utils_ethtool_set_wake_on_lan (nm_device_get_iface (device), wol, password); } diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 051a873efe..e9b8d4be87 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -279,6 +279,9 @@ nmp_utils_ethtool_set_wake_on_lan (const char *ifname, { struct ethtool_wolinfo wol_info = { }; + if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE) + return TRUE; + nm_log_dbg (LOGD_PLATFORM, "setting Wake-on-LAN options 0x%x, password '%s'", (unsigned int) wol, wol_password); diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 8502ef49d6..41c182d221 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -3509,18 +3509,23 @@ wireless_connection_from_ifcfg (const char *file, static void parse_ethtool_options (shvarFile *ifcfg, NMSettingWired *s_wired, char *value) { - NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; + NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE; gboolean use_password = FALSE; - char **words, **iter, *flag; + char **words = NULL, **iter = NULL, *flag; - if (!value || !value[0]) + if (!value) return; - words = g_strsplit_set (value, " ", 0); - iter = words; + if (value[0]) { + words = g_strsplit_set (value, " ", 0); + iter = words; + } - while (iter[0]) { + while (iter && iter[0]) { if (g_str_equal (iter[0], "wol") && iter[1] && *iter[1]) { + + wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_NONE; + for (flag = iter[1]; *flag; flag++) { switch (*flag) { case 'p': @@ -3556,7 +3561,6 @@ parse_ethtool_options (shvarFile *ifcfg, NMSettingWired *s_wired, char *value) if (!NM_FLAGS_HAS (wol_flags, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) use_password = FALSE; - g_object_set (s_wired, NM_SETTING_WIRED_WAKE_ON_LAN, wol_flags, NULL); iter += 2; continue; } @@ -3577,6 +3581,7 @@ parse_ethtool_options (shvarFile *ifcfg, NMSettingWired *s_wired, char *value) iter++; } + g_object_set (s_wired, NM_SETTING_WIRED_WAKE_ON_LAN, wol_flags, NULL); g_strfreev (words); } @@ -3715,7 +3720,7 @@ make_wired_setting (shvarFile *ifcfg, g_free (value); } - value = svGetValue (ifcfg, "ETHTOOL_OPTS", FALSE); + value = svGetValueFull (ifcfg, "ETHTOOL_OPTS", FALSE); parse_ethtool_options (ifcfg, s_wired, value); g_free (value); diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index 6289a930c7..ede1e66a7f 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -1137,7 +1137,9 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) wol = nm_setting_wired_get_wake_on_lan (s_wired); wol_password = nm_setting_wired_get_wake_on_lan_password (s_wired); - if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) + if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE) + svSetValueFull (ifcfg, "ETHTOOL_OPTS", "", FALSE); + else if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) svSetValue (ifcfg, "ETHTOOL_OPTS", NULL, FALSE); else { str = g_string_sized_new (30); |