diff options
author | Francesco Giudici <fgiudici@redhat.com> | 2016-09-10 16:58:10 +0200 |
---|---|---|
committer | Francesco Giudici <fgiudici@redhat.com> | 2016-09-20 10:50:12 +0200 |
commit | b201332fd7233feabfcf837d008eb9f34c97a9eb (patch) | |
tree | f42721e5edd45a2b6200888301bd25c16677ee2e | |
parent | 4f7e846036aa287b49becba7bfb0da79425794e5 (diff) | |
download | NetworkManager-fg/802-3-prop_rh1353612.tar.gz |
device/ethernet: check and apply link negotiation propertiesfg/802-3-prop_rh1353612
This will allow to enforce link mode (autonegotiation, speed and duplex)
as specified in 802-3-ethernet properties.
Please, note that now link negotiation will always be checked and
enforced to the one specified in the properties each time the connection
is started.
-rw-r--r-- | src/devices/nm-device-ethernet.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 7af9d81485..9b1e8cc399 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -784,6 +784,51 @@ supplicant_interface_init (NMDeviceEthernet *self) return TRUE; } +static void +link_negotiation_set (NMDevice *device) +{ + NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device); + NMSettingWired *s_wired; + gboolean autoneg = TRUE, link_autoneg, link_duplex_full; + const char *duplex = NULL; + guint32 speed = 0, link_speed; + + s_wired = (NMSettingWired *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRED); + if (s_wired) { + autoneg = nm_setting_wired_get_auto_negotiate (s_wired); + if (!autoneg) { + speed = nm_setting_wired_get_speed (s_wired); + duplex = nm_setting_wired_get_duplex (s_wired); + } + } + + if (!nm_platform_ethtool_get_link_settings (NM_PLATFORM_GET, nm_device_get_iface (device), + &link_autoneg, &link_speed, &link_duplex_full)) { + _LOGW (LOGD_DEVICE, "unable to retrieve link mode, skip configuration"); + return; + } + + /* If link negotiation setting are already in place do nothing and return with success */ + if ( (autoneg == link_autoneg) + && (autoneg || ((link_speed == speed) && (nm_streq0 (duplex, "full") == link_duplex_full)))) + return; + + if (!nm_platform_ethtool_set_link_settings (NM_PLATFORM_GET, + nm_device_get_iface (device), + autoneg, + speed, + duplex)) { + _LOGW (LOGD_DEVICE, "unable to set link mode configuration"); + return; + } + + if (autoneg) + _LOGD (LOGD_DEVICE, "link autonegotiation enabled"); + else + _LOGD (LOGD_DEVICE, "enabled static link negotiation (%d Mbit - %s duplex)", + speed, duplex); +} + static gboolean pppoe_reconnect_delay (gpointer user_data) { @@ -809,6 +854,8 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) if (ret != NM_ACT_STAGE_RETURN_SUCCESS) return ret; + link_negotiation_set (dev); + if (!nm_device_hw_addr_set_cloned (dev, nm_device_get_applied_connection (dev), FALSE)) return NM_ACT_STAGE_RETURN_FAILURE; @@ -1520,7 +1567,7 @@ get_link_speed (NMDevice *device) NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); guint32 speed; - if (!nm_platform_ethtool_get_link_speed (NM_PLATFORM_GET, nm_device_get_iface (device), &speed)) + if (!nm_platform_ethtool_get_link_settings (NM_PLATFORM_GET, nm_device_get_iface (device), NULL, &speed, NULL)) return; if (priv->speed == speed) return; |