diff options
author | Thomas Haller <thaller@redhat.com> | 2015-05-03 12:49:46 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-05-05 23:11:08 +0200 |
commit | d85efe28c8d405b3e00befb18bfd8b03221a22bb (patch) | |
tree | 2dd3ece94ad2177a16cda0d5131518b6c8dedd76 | |
parent | 09cf809e25688bca96691e33be3c0868aca0d308 (diff) | |
download | NetworkManager-d85efe28c8d405b3e00befb18bfd8b03221a22bb.tar.gz |
platform: move supports_mii_carrier_detect() to nmp_utils_mii_supports_carrier_detect()
-rw-r--r-- | src/platform/nm-linux-platform.c | 45 | ||||
-rw-r--r-- | src/platform/nm-platform-utils.c | 50 | ||||
-rw-r--r-- | src/platform/nm-platform-utils.h | 1 |
3 files changed, 52 insertions, 44 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 705f01b9b6..7e9b24c1ef 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -31,9 +31,6 @@ #include <linux/if_link.h> #include <linux/if_tun.h> #include <linux/if_tunnel.h> -#include <sys/ioctl.h> -#include <linux/sockios.h> -#include <linux/mii.h> #include <netlink/netlink.h> #include <netlink/object.h> #include <netlink/cache.h> @@ -2506,46 +2503,6 @@ link_set_user_ipv6ll_enabled (NMPlatform *platform, int ifindex, gboolean enable } static gboolean -supports_mii_carrier_detect (const char *ifname) -{ - int fd; - struct ifreq ifr; - struct mii_ioctl_data *mii; - gboolean supports_mii = FALSE; - - fd = socket (PF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - nm_log_err (LOGD_PLATFORM, "couldn't open control socket."); - return FALSE; - } - - memset (&ifr, 0, sizeof (struct ifreq)); - strncpy (ifr.ifr_name, ifname, IFNAMSIZ); - - errno = 0; - if (ioctl (fd, SIOCGMIIPHY, &ifr) < 0) { - nm_log_dbg (LOGD_PLATFORM, "SIOCGMIIPHY failed: %d", errno); - goto out; - } - - /* If we can read the BMSR register, we assume that the card supports MII link detection */ - mii = (struct mii_ioctl_data *) &ifr.ifr_ifru; - mii->reg_num = MII_BMSR; - - if (ioctl (fd, SIOCGMIIREG, &ifr) == 0) { - nm_log_dbg (LOGD_PLATFORM, "SIOCGMIIREG result 0x%X", mii->val_out); - supports_mii = TRUE; - } else { - nm_log_dbg (LOGD_PLATFORM, "SIOCGMIIREG failed: %d", errno); - } - - out: - close (fd); - nm_log_dbg (LOGD_PLATFORM, "MII %s supported", supports_mii ? "is" : "not"); - return supports_mii; -} - -static gboolean link_supports_carrier_detect (NMPlatform *platform, int ifindex) { const char *name = nm_platform_link_get_name (platform, ifindex); @@ -2557,7 +2514,7 @@ link_supports_carrier_detect (NMPlatform *platform, int ifindex) * us whether the device actually supports carrier detection in the first * place. We assume any device that does implements one of these two APIs. */ - return nmp_utils_ethtool_supports_carrier_detect (name) || supports_mii_carrier_detect (name); + return nmp_utils_ethtool_supports_carrier_detect (name) || nmp_utils_mii_supports_carrier_detect (name); } static gboolean diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 935e3d4073..a282be1d1f 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -26,6 +26,7 @@ #include <sys/ioctl.h> #include <linux/ethtool.h> #include <linux/sockios.h> +#include <linux/mii.h> #include "gsystem-local-alloc.h" #include "nm-logging.h" @@ -194,6 +195,55 @@ nmp_utils_ethtool_get_wake_on_lan (const char *ifname) } /****************************************************************** + * mii + ******************************************************************/ + +gboolean +nmp_utils_mii_supports_carrier_detect (const char *ifname) +{ + int fd, errsv; + struct ifreq ifr; + struct mii_ioctl_data *mii; + gboolean supports_mii = FALSE; + + if (!ifname) + return FALSE; + + fd = socket (PF_INET, SOCK_DGRAM, 0); + if (fd < 0) { + nm_log_err (LOGD_PLATFORM, "mii: couldn't open control socket (%s)", ifname); + return FALSE; + } + + memset (&ifr, 0, sizeof (struct ifreq)); + strncpy (ifr.ifr_name, ifname, IFNAMSIZ); + + errno = 0; + if (ioctl (fd, SIOCGMIIPHY, &ifr) < 0) { + errsv = errno; + nm_log_dbg (LOGD_PLATFORM, "mii: SIOCGMIIPHY failed: %s (%d) (%s)", strerror (errsv), errsv, ifname); + goto out; + } + + /* If we can read the BMSR register, we assume that the card supports MII link detection */ + mii = (struct mii_ioctl_data *) &ifr.ifr_ifru; + mii->reg_num = MII_BMSR; + + if (ioctl (fd, SIOCGMIIREG, &ifr) == 0) { + nm_log_dbg (LOGD_PLATFORM, "mii: SIOCGMIIREG result 0x%X (%s)", mii->val_out, ifname); + supports_mii = TRUE; + } else { + errsv = errno; + nm_log_dbg (LOGD_PLATFORM, "mii: SIOCGMIIREG failed: %s (%d) (%s)", strerror (errsv), errsv, ifname); + } + +out: + close (fd); + nm_log_dbg (LOGD_PLATFORM, "mii: MII %s supported (%s)", supports_mii ? "is" : "not", ifname); + return supports_mii; +} + +/****************************************************************** * udev ******************************************************************/ diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h index 12db5aab7a..d021113a52 100644 --- a/src/platform/nm-platform-utils.h +++ b/src/platform/nm-platform-utils.h @@ -34,6 +34,7 @@ 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_mii_supports_carrier_detect (const char *ifname); const char *nmp_utils_udev_get_driver (GUdevDevice *device); |