ethtool-util: introduce ethtool_get_permanent_hw_addr()
And replaces all ethtool_get_permanent_macaddr() with it.
This commit is contained in:
@@ -339,14 +339,14 @@ int ethtool_get_link_info(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret) {
|
||||
int ethtool_get_permanent_hw_addr(int *ethtool_fd, const char *ifname, struct hw_addr_data *ret) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
struct {
|
||||
struct ethtool_perm_addr addr;
|
||||
uint8_t space[MAX_ADDR_LEN];
|
||||
uint8_t space[HW_ADDR_MAX_SIZE];
|
||||
} epaddr = {
|
||||
.addr.cmd = ETHTOOL_GPERMADDR,
|
||||
.addr.size = MAX_ADDR_LEN,
|
||||
.addr.size = HW_ADDR_MAX_SIZE,
|
||||
};
|
||||
struct ifreq ifr = {
|
||||
.ifr_data = (caddr_t) &epaddr,
|
||||
@@ -367,17 +367,14 @@ int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct et
|
||||
if (ioctl(*ethtool_fd, SIOCETHTOOL, &ifr) < 0)
|
||||
return -errno;
|
||||
|
||||
if (epaddr.addr.size != 6)
|
||||
return -EOPNOTSUPP;
|
||||
if (epaddr.addr.size == 0)
|
||||
return -ENODATA;
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#if HAVE_ZERO_LENGTH_BOUNDS
|
||||
# pragma GCC diagnostic ignored "-Wzero-length-bounds"
|
||||
#endif
|
||||
for (size_t i = 0; i < epaddr.addr.size; i++)
|
||||
ret->ether_addr_octet[i] = epaddr.addr.data[i];
|
||||
#pragma GCC diagnostic pop
|
||||
if (epaddr.addr.size > HW_ADDR_MAX_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
ret->length = epaddr.addr.size;
|
||||
memcpy(ret->bytes, epaddr.addr.data, epaddr.addr.size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <linux/ethtool.h>
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "ether-addr-util.h"
|
||||
|
||||
#define N_ADVERTISE 3
|
||||
|
||||
@@ -163,7 +164,7 @@ int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret);
|
||||
int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
|
||||
int *ret_autonegotiation, uint64_t *ret_speed,
|
||||
Duplex *ret_duplex, NetDevPort *ret_port);
|
||||
int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret);
|
||||
int ethtool_get_permanent_hw_addr(int *ethtool_fd, const char *ifname, struct hw_addr_data *ret);
|
||||
int ethtool_set_wol(int *ethtool_fd, const char *ifname, uint32_t wolopts, const uint8_t password[SOPASS_MAX]);
|
||||
int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netdev_ring_param *ring);
|
||||
int ethtool_set_features(int *ethtool_fd, const char *ifname, const int features[static _NET_DEV_FEAT_MAX]);
|
||||
|
||||
Reference in New Issue
Block a user