summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-11-22 12:59:11 +0100
committerFrancesco Giudici <fgiudici@redhat.com>2016-11-22 15:24:47 +0100
commitd5a743a619f79086e5a85510b49925d5d34bfc2d (patch)
tree673bb570c846529b201979087e66494d4343cff6
parent417f5ad6ed5522de63527b03c92ca08301cf2849 (diff)
downloadNetworkManager-fg/802-3-prop_rh1353612_II.tar.gz
core: merge NM_PLATFORM_LINK_DUPLEX_UNSET and UNKNOWNfg/802-3-prop_rh1353612_II
They have basically the same use, except that certain places handled one but not the other.
-rw-r--r--src/devices/nm-device-ethernet.c71
-rw-r--r--src/platform/nm-platform-utils.c4
-rw-r--r--src/platform/nm-platform.h3
3 files changed, 33 insertions, 45 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index fb6467a23f..313dbc8730 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -782,35 +782,23 @@ supplicant_interface_init (NMDeviceEthernet *self)
return TRUE;
}
-static const char *
-link_duplex_to_string (NMPlatformLinkDuplexType duplex)
-{
- switch (duplex) {
- case NM_PLATFORM_LINK_DUPLEX_FULL:
- return "full";
- break;
- case NM_PLATFORM_LINK_DUPLEX_HALF:
- return "half";
- break;
- default:
- return "unknown";
- break;
- }
-}
+NM_UTILS_LOOKUP_STR_DEFINE_STATIC (link_duplex_to_string, NMPlatformLinkDuplexType,
+ NM_UTILS_LOOKUP_DEFAULT_WARN (NULL),
+ NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_LINK_DUPLEX_UNKNOWN, "unknown"),
+ NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_LINK_DUPLEX_FULL, "full"),
+ NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_LINK_DUPLEX_HALF, "half"),
+);
static NMPlatformLinkDuplexType
link_duplex_to_platform (const char *duplex)
{
if (!duplex)
- return NM_PLATFORM_LINK_DUPLEX_UNSET;
-
+ return NM_PLATFORM_LINK_DUPLEX_UNKNOWN;
if (nm_streq (duplex, "full"))
return NM_PLATFORM_LINK_DUPLEX_FULL;
-
if (nm_streq (duplex, "half"))
return NM_PLATFORM_LINK_DUPLEX_HALF;
-
- return NM_PLATFORM_LINK_DUPLEX_UNKNOWN;
+ g_return_val_if_reached (NM_PLATFORM_LINK_DUPLEX_UNKNOWN);
}
static void
@@ -818,9 +806,12 @@ link_negotiation_set (NMDevice *device)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
NMSettingWired *s_wired;
- gboolean autoneg = TRUE, link_autoneg;
- NMPlatformLinkDuplexType link_duplex, duplex = NM_PLATFORM_LINK_DUPLEX_UNSET;
- guint32 speed = 0, link_speed;
+ gboolean autoneg = TRUE;
+ gboolean link_autoneg;
+ NMPlatformLinkDuplexType duplex = NM_PLATFORM_LINK_DUPLEX_UNKNOWN;
+ NMPlatformLinkDuplexType link_duplex;
+ guint32 speed = 0;
+ guint32 link_speed;
s_wired = (NMSettingWired *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRED);
if (s_wired) {
@@ -842,19 +833,23 @@ link_negotiation_set (NMDevice *device)
}
/* If link negotiation setting are already in place do nothing and return with success */
- if (autoneg != link_autoneg)
- goto set_link;
-
- if (speed && (speed != link_speed))
- goto set_link;
-
- if (duplex && (duplex != link_duplex))
- goto set_link;
+ if ( (!!autoneg == !!link_autoneg)
+ && (!speed || (speed == link_speed))
+ && (!duplex || (duplex == link_duplex))) {
+ _LOGD (LOGD_DEVICE, "set-link: link negotiation is already configured");
+ return;
+ }
- _LOGW (LOGD_DEVICE, "set-link: link negotiation is already configured");
- return;
+ if (autoneg)
+ _LOGD (LOGD_DEVICE, "set-link: configure autonegotiation");
+ else {
+ _LOGD (LOGD_DEVICE, "set-link: configure static negotiation (%u Mbit%s - %s duplex%s)",
+ speed ?: link_speed,
+ speed ? "" : "*",
+ duplex ? link_duplex_to_string (duplex) : link_duplex_to_string (link_duplex),
+ duplex ? "" : "*");
+ }
-set_link:
if (!nm_platform_ethtool_set_link_settings (NM_PLATFORM_GET,
nm_device_get_iface (device),
autoneg,
@@ -863,14 +858,6 @@ set_link:
_LOGW (LOGD_DEVICE, "set-link: failure to set link negotiation");
return;
}
-
- if (autoneg)
- _LOGD (LOGD_DEVICE, "set-link: configure autonegotiation");
- else {
- _LOGD (LOGD_DEVICE, "set-link: configure static negotiation (%u Mbit - %s duplex)",
- speed ?: link_speed,
- duplex ? link_duplex_to_string (duplex) : link_duplex_to_string (link_duplex));
- }
}
static gboolean
diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index dd258045f7..9ef0707d58 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -339,8 +339,10 @@ nmp_utils_ethtool_set_link_settings (const char *ifname, gboolean autoneg, guint
case NM_PLATFORM_LINK_DUPLEX_FULL:
edata.duplex = DUPLEX_FULL;
break;
- default: /* NM_PLATFORM_LINK_DUPLEX_UNSET */
+ case NM_PLATFORM_LINK_DUPLEX_UNKNOWN:
break;
+ default:
+ g_return_val_if_reached (FALSE);
}
}
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 289090c4e2..a546e4eaec 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -482,10 +482,9 @@ typedef struct {
} NMPlatformTunProperties;
typedef enum {
- NM_PLATFORM_LINK_DUPLEX_UNSET = 0,
+ NM_PLATFORM_LINK_DUPLEX_UNKNOWN,
NM_PLATFORM_LINK_DUPLEX_HALF,
NM_PLATFORM_LINK_DUPLEX_FULL,
- NM_PLATFORM_LINK_DUPLEX_UNKNOWN,
} NMPlatformLinkDuplexType;
/*****************************************************************************/