mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
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
This commit is contained in:
parent
35802ac01c
commit
e587dcb16e
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
**/
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -3560,18 +3560,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':
|
||||
|
@ -3607,7 +3612,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;
|
||||
}
|
||||
|
@ -3628,6 +3632,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);
|
||||
}
|
||||
|
||||
|
@ -3766,7 +3771,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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue