diff options
-rw-r--r-- | src/shared/ethtool-util.c | 38 | ||||
-rw-r--r-- | src/shared/ethtool-util.h | 3 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index 3fba238ac4..b2a81e4215 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -160,6 +160,44 @@ int ethtool_get_driver(int *fd, const char *ifname, char **ret) { return 0; } +int ethtool_get_link_info(int *fd, const char *ifname, + int *ret_autonegotiation, size_t *ret_speed, + Duplex *ret_duplex, NetDevPort *ret_port) { + struct ethtool_cmd ecmd = { + .cmd = ETHTOOL_GSET, + }; + struct ifreq ifr = { + .ifr_data = (void*) &ecmd, + }; + int r; + + if (*fd < 0) { + r = ethtool_connect_or_warn(fd, false); + if (r < 0) + return r; + } + + strscpy(ifr.ifr_name, IFNAMSIZ, ifname); + + r = ioctl(*fd, SIOCETHTOOL, &ifr); + if (r < 0) + return -errno; + + if (ret_autonegotiation) + *ret_autonegotiation = ecmd.autoneg; + + if (ret_speed) + *ret_speed = ethtool_cmd_speed(&ecmd) * 1000 * 1000; + + if (ret_duplex) + *ret_duplex = ecmd.duplex; + + if (ret_port) + *ret_port = ecmd.port; + + return 0; +} + int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex) { struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET diff --git a/src/shared/ethtool-util.h b/src/shared/ethtool-util.h index cbbe041799..03976c6ee3 100644 --- a/src/shared/ethtool-util.h +++ b/src/shared/ethtool-util.h @@ -80,6 +80,9 @@ typedef struct netdev_channels { } netdev_channels; int ethtool_get_driver(int *fd, const char *ifname, char **ret); +int ethtool_get_link_info(int *fd, const char *ifname, + int *ret_autonegotiation, size_t *ret_speed, + Duplex *ret_duplex, NetDevPort *ret_port); int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex); int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol); int ethtool_set_features(int *fd, const char *ifname, int *features); |