NetDev.Name, config_parse_ifname, 0, offsetof(NetDev, ifname)
NetDev.Kind, config_parse_netdev_kind, 0, offsetof(NetDev, kind)
NetDev.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(NetDev, mtu)
-NetDev.MACAddress, config_parse_ether_addr, 0, offsetof(NetDev, mac)
+NetDev.MACAddress, config_parse_hw_addr, ETH_ALEN, offsetof(NetDev, hw_addr)
VLAN.Id, config_parse_vlanid, 0, offsetof(VLan, id)
VLAN.Protocol, config_parse_vlanprotocol, 0, offsetof(VLan, protocol)
VLAN.GVRP, config_parse_tristate, 0, offsetof(VLan, gvrp)
L2TPSession.Layer2SpecificHeader, config_parse_l2tp_session_l2spec, 0, 0
L2TPSession.Name, config_parse_l2tp_session_name, 0, 0
Peer.Name, config_parse_ifname, 0, offsetof(Veth, ifname_peer)
-Peer.MACAddress, config_parse_ether_addr, 0, offsetof(Veth, mac_peer)
+Peer.MACAddress, config_parse_hw_addr, ETH_ALEN, offsetof(Veth, hw_addr_peer)
VXCAN.Peer, config_parse_ifname, 0, offsetof(VxCan, ifname_peer)
VXLAN.VNI, config_parse_uint32, 0, offsetof(VxLan, vni)
VXLAN.Id, config_parse_uint32, 0, offsetof(VxLan, vni) /* deprecated */
free(netdev->description);
free(netdev->ifname);
- free(netdev->mac);
condition_free_list(netdev->conditions);
/* Invoke the per-kind done() destructor, but only if the state field is initialized. We conditionalize that
#define HASH_KEY SD_ID128_MAKE(52,e1,45,bd,00,6f,29,96,21,c6,30,6d,83,71,04,48)
-int netdev_get_mac(const char *ifname, struct ether_addr **ret) {
- _cleanup_free_ struct ether_addr *mac = NULL;
+int netdev_generate_hw_addr(const char *name, struct hw_addr_data *ret) {
uint64_t result;
size_t l, sz;
uint8_t *v;
assert(ifname);
assert(ret);
- mac = new0(struct ether_addr, 1);
- if (!mac)
- return -ENOMEM;
-
l = strlen(ifname);
sz = sizeof(sd_id128_t) + l;
v = newa(uint8_t, sz);
result = siphash24(v, sz, HASH_KEY.bytes);
assert_cc(ETH_ALEN <= sizeof(result));
- memcpy(mac->ether_addr_octet, &result, ETH_ALEN);
+ ret->length = ETH_ALEN;
+ memcpy(ret->bytes, &result, ETH_ALEN);
/* see eth_random_addr in the kernel */
- mac->ether_addr_octet[0] &= 0xfe; /* clear multicast bit */
- mac->ether_addr_octet[0] |= 0x02; /* set local assignment bit (IEEE802) */
-
- *ret = TAKE_PTR(mac);
+ ret->ether.ether_addr_octet[0] &= 0xfe; /* clear multicast bit */
+ ret->ether.ether_addr_octet[0] |= 0x02; /* set local assignment bit (IEEE802) */
return 0;
}
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IFNAME, attribute: %m");
- if (netdev->mac) {
- r = sd_netlink_message_append_ether_addr(m, IFLA_ADDRESS, netdev->mac);
+ if (netdev->hw_addr.length > 0) {
+ r = netlink_message_append_hw_addr(m, IFLA_ADDRESS, &netdev->hw_addr);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m");
}
if (!netdev->filename)
return log_oom();
- if (!netdev->mac && NETDEV_VTABLE(netdev)->generate_mac) {
- r = netdev_get_mac(netdev->ifname, &netdev->mac);
+ if (netdev->hw_addr.length == 0 && NETDEV_VTABLE(netdev)->generate_mac) {
+ r = netdev_generate_hw_addr(netdev->ifname, &netdev->hw_addr);
if (r < 0)
return log_netdev_error_errno(netdev, r,
"Failed to generate predictable MAC address: %m");
#include "sd-netlink.h"
#include "conf-parser.h"
+#include "ether-addr-util.h"
#include "list.h"
#include "log-link.h"
#include "networkd-link.h"
NetDevKind kind;
char *description;
char *ifname;
- struct ether_addr *mac;
+ struct hw_addr_data hw_addr;
uint32_t mtu;
int ifindex;
} NetDev;
bool netdev_is_managed(NetDev *netdev);
int netdev_get(Manager *manager, const char *name, NetDev **ret);
int netdev_set_ifindex(NetDev *netdev, sd_netlink_message *newlink);
-int netdev_get_mac(const char *ifname, struct ether_addr **ret);
+int netdev_generate_hw_addr(const char *name, struct hw_addr_data *ret);
int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t cb);
int request_process_stacked_netdev(Request *req);
assert(netdev);
assert(filename);
- if (netdev->mac) {
+ if (netdev->hw_addr.length > 0) {
log_netdev_warning(netdev, "%s: MACAddress= is not supported. Ignoring", filename);
- netdev->mac = mfree(netdev->mac);
+ netdev->hw_addr = HW_ADDR_NULL;
}
return 0;
"Please set it in the corresponding .network file.",
netdev_kind_to_string(netdev->kind), filename);
- if (netdev->mac)
+ if (netdev->hw_addr.length > 0)
log_netdev_warning(netdev,
"MACAddress= configured for %s device in %s will be ignored.\n"
"Please set it in the corresponding .network file.",
#include <linux/if_arp.h>
#include <linux/veth.h>
+#include "netlink-util.h"
#include "veth.h"
static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
return log_netdev_error_errno(netdev, r, "Failed to add netlink interface name: %m");
}
- if (v->mac_peer) {
- r = sd_netlink_message_append_ether_addr(m, IFLA_ADDRESS, v->mac_peer);
+ if (v->hw_addr_peer.length > 0) {
+ r = netlink_message_append_hw_addr(m, IFLA_ADDRESS, &v->hw_addr_peer);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m");
}
"Veth NetDev without peer name configured in %s. Ignoring",
filename);
- if (!v->mac_peer) {
- r = netdev_get_mac(v->ifname_peer, &v->mac_peer);
+ if (v->hw_addr_peer.length == 0) {
+ r = netdev_generate_hw_addr(v->ifname_peer, &v->hw_addr_peer);
if (r < 0)
return log_netdev_warning_errno(netdev, r,
- "Failed to generate predictable MAC address for %s: %m",
+ "Failed to generate persistent hardware address for peer '%s': %m",
v->ifname_peer);
}
assert(v);
free(v->ifname_peer);
- free(v->mac_peer);
}
const NetDevVTable veth_vtable = {
NetDev meta;
char *ifname_peer;
- struct ether_addr *mac_peer;
+ struct hw_addr_data hw_addr_peer;
};
DEFINE_NETDEV_CAST(VETH, Veth);