summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clients/cli/settings.c13
-rw-r--r--libnm-core/nm-setting-wired.c11
-rw-r--r--libnm-core/nm-setting-wired.h19
-rw-r--r--src/devices/nm-device-ethernet.c11
-rw-r--r--src/platform/nm-platform-utils.c3
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.c111
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c3
-rw-r--r--src/settings/plugins/ifcfg-rh/writer.c4
8 files changed, 126 insertions, 49 deletions
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
index 0c10cf533e..992f8415b5 100644
--- a/clients/cli/settings.c
+++ b/clients/cli/settings.c
@@ -1587,7 +1587,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,
@@ -1599,7 +1602,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));
@@ -1608,9 +1611,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 8dc823d562..64b6697119 100644
--- a/libnm-core/nm-setting-wired.c
+++ b/libnm-core/nm-setting-wired.c
@@ -701,12 +701,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;
}
@@ -1195,7 +1195,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.2
**/
diff --git a/libnm-core/nm-setting-wired.h b/libnm-core/nm-setting-wired.h
index fa49db7b68..7eb53d3021 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 556569e1d6..d1202dc72f 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -1230,15 +1230,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 3ebb73bfb9..953ac8c543 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -278,6 +278,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 5a29e924ea..57de73faaa 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -3558,21 +3558,49 @@ wireless_connection_from_ifcfg (const char *file,
}
static void
-parse_ethtool_options (shvarFile *ifcfg, NMSettingWired *s_wired, char *value)
+parse_ethtool_option (const char *value, NMSettingWiredWakeOnLan *out_flags, char **out_password)
{
- NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_NONE;
- gboolean use_password = FALSE;
- char **words, **iter, *flag;
+ gs_strfreev char **words = NULL;
+ const char **iter = NULL, *flag;
+ gboolean has_flags = FALSE;
+ gboolean has_password = FALSE;
if (!value || !value[0])
return;
- words = g_strsplit_set (value, " ", 0);
- iter = words;
+ words = g_strsplit_set (value, "\t ", 0);
+ iter = (const char **) words;
while (iter[0]) {
- if (g_str_equal (iter[0], "wol") && iter[1] && *iter[1]) {
- for (flag = iter[1]; *flag; flag++) {
+ gboolean is_wol;
+
+ if (g_str_equal (iter[0], "wol"))
+ is_wol = TRUE;
+ else if (g_str_equal (iter[0], "sopass"))
+ is_wol = FALSE;
+ else {
+ /* Silently skip unknown options */
+ iter++;
+ continue;
+ }
+
+ iter++;
+
+ /* g_strsplit_set() returns empty tokens, meaning that we must skip over repeated
+ * space characters like to parse "wol d". */
+ while (iter[0] && !*iter[0])
+ iter++;
+
+ if (is_wol) {
+ NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_NONE;
+ has_flags = TRUE;
+
+ if (!iter[0]) {
+ PARSE_WARNING ("Wake-on-LAN options missing");
+ break;
+ }
+
+ for (flag = iter[0]; *flag; flag++) {
switch (*flag) {
case 'p':
wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_PHY;
@@ -3593,42 +3621,65 @@ parse_ethtool_options (shvarFile *ifcfg, NMSettingWired *s_wired, char *value)
wol_flags |= NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC;
break;
case 's':
- use_password = TRUE;
break;
case 'd':
wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_NONE;
- use_password = FALSE;
break;
default:
PARSE_WARNING ("unrecognized Wake-on-LAN option '%c'", *flag);
}
}
- if (!NM_FLAGS_HAS (wol_flags, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC))
- use_password = FALSE;
+ *out_flags = wol_flags;
+ } else {
+ has_password = TRUE;
- g_object_set (s_wired, NM_SETTING_WIRED_WAKE_ON_LAN, wol_flags, NULL);
- iter += 2;
- continue;
- }
+ if (!iter[0]) {
+ PARSE_WARNING ("Wake-on-LAN password missing");
+ break;
+ }
- if (g_str_equal (iter[0], "sopass") && iter[1] && *iter[1]) {
- if (use_password) {
- if (nm_utils_hwaddr_valid (iter[1], ETH_ALEN))
- g_object_set (s_wired, NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, iter[1], NULL);
- else
- PARSE_WARNING ("Wake-on-LAN password '%s' is invalid", iter[1]);
- } else
- PARSE_WARNING ("Wake-on-LAN password not expected");
- iter += 2;
- continue;
- }
- /* Silently skip unknown options */
+ g_clear_pointer (out_password, g_free);
+ if (nm_utils_hwaddr_valid (iter[0], ETH_ALEN))
+ *out_password = g_strdup (iter[0]);
+ else
+ PARSE_WARNING ("Wake-on-LAN password '%s' is invalid", iter[0]);
+ }
iter++;
}
+}
+
+static void
+parse_ethtool_options (shvarFile *ifcfg, NMSettingWired *s_wired, const char *value)
+{
+ NMSettingWiredWakeOnLan wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT;
+ gs_free char *wol_password = NULL;
+ gboolean ignore_wol_password = FALSE;
+
+ if (value) {
+ gs_strfreev char **opts = NULL;
+ const char **iter;
+
+ wol_flags = NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE;
+
+ opts = g_strsplit_set (value, ";", 0);
+ for (iter = (const char **) opts; iter[0]; iter++) {
+ /* in case of repeated wol_passwords, parse_ethtool_option()
+ * will do the right thing and clear wol_password before resetting. */
+ parse_ethtool_option (iter[0], &wol_flags, &wol_password);
+ }
+ }
- g_strfreev (words);
+ if ( wol_password
+ && !NM_FLAGS_HAS (wol_flags, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC)) {
+ PARSE_WARNING ("Wake-on-LAN password not expected");
+ ignore_wol_password = TRUE;
+ }
+ g_object_set (s_wired,
+ NM_SETTING_WIRED_WAKE_ON_LAN, wol_flags,
+ NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, ignore_wol_password ? NULL : wol_password,
+ NULL);
}
static NMSetting *
@@ -3766,7 +3817,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/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 2e8b68f3ea..f75247b190 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -6291,8 +6291,7 @@ test_write_wired_static (void)
g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip4), ==, 204);
g_assert_cmpint (nm_setting_ip_config_get_route_metric (reread_s_ip6), ==, 206);
- ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
- "wired-static-write", "written and re-read connection weren't the same.");
+ nmtst_assert_connection_equals (connection, FALSE, reread, FALSE);
route6file = utils_get_route6_path (testfile);
unlink (route6file);
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index 376f38c0bd..3d03718a81 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);