mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 14:40:08 +01:00
core: configure Wake-on-LAN parameters for Ethernet devices
This commit is contained in:
parent
de92df6c9f
commit
996cbcd25c
3 changed files with 79 additions and 0 deletions
|
|
@ -53,6 +53,7 @@
|
|||
#include "nm-device-factory.h"
|
||||
#include "nm-core-internal.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "gsystem-local-alloc.h"
|
||||
|
||||
#include "nm-device-ethernet-glue.h"
|
||||
|
||||
|
|
@ -1175,6 +1176,40 @@ dcb_carrier_changed (NMDevice *device, GParamSpec *pspec, gpointer unused)
|
|||
|
||||
/****************************************************************/
|
||||
|
||||
static gboolean
|
||||
wake_on_lan_enable (NMDevice *device)
|
||||
{
|
||||
NMSettingWiredWakeOnLan wol;
|
||||
NMSettingWired *s_wired;
|
||||
const char *password = NULL;
|
||||
gs_free char *value = NULL;
|
||||
|
||||
s_wired = (NMSettingWired *) device_get_setting (device, NM_TYPE_SETTING_WIRED);
|
||||
if (s_wired) {
|
||||
wol = nm_setting_wired_get_wake_on_lan (s_wired);
|
||||
password = nm_setting_wired_get_wake_on_lan_password (s_wired);
|
||||
if (wol != NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT)
|
||||
goto found;
|
||||
}
|
||||
|
||||
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,
|
||||
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;
|
||||
found:
|
||||
return nmp_utils_ethtool_set_wake_on_lan (nm_device_get_iface (device), wol, password);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
static NMActStageReturn
|
||||
act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
|
||||
{
|
||||
|
|
@ -1207,6 +1242,8 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
|
|||
}
|
||||
}
|
||||
|
||||
wake_on_lan_enable (device);
|
||||
|
||||
/* DCB and FCoE setup */
|
||||
s_dcb = (NMSettingDcb *) device_get_setting (device, NM_TYPE_SETTING_DCB);
|
||||
if (s_dcb) {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include "nm-utils.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
#include "nm-setting-wired.h"
|
||||
|
||||
|
||||
/******************************************************************
|
||||
|
|
@ -258,6 +259,43 @@ nmp_utils_ethtool_get_link_speed (const char *ifname, guint32 *out_speed)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nmp_utils_ethtool_set_wake_on_lan (const char *ifname,
|
||||
NMSettingWiredWakeOnLan wol,
|
||||
const char *wol_password)
|
||||
{
|
||||
struct ethtool_wolinfo wol_info = { };
|
||||
|
||||
nm_log_dbg (LOGD_PLATFORM, "setting Wake-on-LAN options 0x%x, password '%s'",
|
||||
(unsigned int) wol, wol_password);
|
||||
|
||||
wol_info.cmd = ETHTOOL_SWOL;
|
||||
wol_info.wolopts = 0;
|
||||
|
||||
if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_PHY))
|
||||
wol_info.wolopts |= WAKE_PHY;
|
||||
if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST))
|
||||
wol_info.wolopts |= WAKE_UCAST;
|
||||
if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST))
|
||||
wol_info.wolopts |= WAKE_MCAST;
|
||||
if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_BROADCAST))
|
||||
wol_info.wolopts |= WAKE_BCAST;
|
||||
if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_ARP))
|
||||
wol_info.wolopts |= WAKE_ARP;
|
||||
if (NM_FLAGS_HAS (wol, NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC))
|
||||
wol_info.wolopts |= WAKE_MAGIC;
|
||||
|
||||
if (wol_password) {
|
||||
if (!nm_utils_hwaddr_aton (wol_password, wol_info.sopass, ETH_ALEN)) {
|
||||
nm_log_dbg (LOGD_PLATFORM, "couldn't parse Wake-on-LAN password '%s'", wol_password);
|
||||
return FALSE;
|
||||
}
|
||||
wol_info.wolopts |= WAKE_MAGICSECURE;
|
||||
}
|
||||
|
||||
return ethtool_get (ifname, &wol_info);
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
* mii
|
||||
******************************************************************/
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include <gudev/gudev.h>
|
||||
|
||||
#include "nm-platform.h"
|
||||
#include "nm-setting-wired.h"
|
||||
|
||||
|
||||
const char *nmp_utils_ethtool_get_driver (const char *ifname);
|
||||
|
|
@ -33,6 +34,9 @@ gboolean nmp_utils_ethtool_supports_carrier_detect (const char *ifname);
|
|||
gboolean nmp_utils_ethtool_supports_vlans (const char *ifname);
|
||||
int nmp_utils_ethtool_get_peer_ifindex (const char *ifname);
|
||||
gboolean nmp_utils_ethtool_get_wake_on_lan (const char *ifname);
|
||||
gboolean nmp_utils_ethtool_set_wake_on_lan (const char *ifname, NMSettingWiredWakeOnLan wol,
|
||||
const char *wol_password);
|
||||
|
||||
gboolean nmp_utils_ethtool_get_link_speed (const char *ifname, guint32 *out_speed);
|
||||
|
||||
gboolean nmp_utils_ethtool_get_driver_info (const char *ifname,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue