1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-05 15:21:37 +03:00

ethtool: introduce ethtool_get_permanent_macaddr()

Will be used in later commits.
This commit is contained in:
Yu Watanabe 2019-01-07 20:16:18 +09:00
parent ec04aef442
commit 79b4428a7d
2 changed files with 43 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include <net/if.h>
#include <sys/ioctl.h>
#include <linux/ethtool.h>
#include <linux/netdevice.h>
#include <linux/sockios.h>
#include "conf-parser.h"
@ -217,6 +218,46 @@ int ethtool_get_link_info(int *fd, const char *ifname,
return 0;
}
int ethtool_get_permanent_macaddr(int *fd, const char *ifname, struct ether_addr *ret) {
_cleanup_free_ struct ethtool_perm_addr *epaddr = NULL;
struct ifreq ifr;
int r;
assert(fd);
assert(ifname);
assert(ret);
if (*fd < 0) {
r = ethtool_connect_or_warn(fd, false);
if (r < 0)
return r;
}
epaddr = malloc(offsetof(struct ethtool_perm_addr, data) + MAX_ADDR_LEN);
if (!epaddr)
return -ENOMEM;
epaddr->cmd = ETHTOOL_GPERMADDR;
epaddr->size = MAX_ADDR_LEN;
ifr = (struct ifreq) {
.ifr_data = (caddr_t) epaddr,
};
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = ioctl(*fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
if (epaddr->size != 6)
return -EOPNOTSUPP;
for (size_t i = 0; i < epaddr->size; i++)
ret->ether_addr_octet[i] = epaddr->data[i];
return 0;
}
int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex) {
struct ethtool_cmd ecmd = {
.cmd = ETHTOOL_GSET

View File

@ -2,6 +2,7 @@
#pragma once
#include <macro.h>
#include <net/ethernet.h>
#include <linux/ethtool.h>
#include "conf-parser.h"
@ -91,6 +92,7 @@ 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_get_permanent_macaddr(int *fd, const char *ifname, struct ether_addr *ret);
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_nic_buffer_size(int *fd, const char *ifname, netdev_ring_param *ring);