1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

ethtool-util: introduce ethtool_get_link_info()

Will be used in later commits.
This commit is contained in:
Yu Watanabe 2019-06-17 15:31:20 +09:00
parent 7864b16b27
commit 33a8695fdc
2 changed files with 41 additions and 0 deletions

View File

@ -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

View File

@ -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);