X Tutup
Skip to content

Commit a884071

Browse files
committed
network: make MACAddress= takes hardware address with its length is INFINIBAND_ALEN
Also, the multicast and local bits in the specified MAC address for ethernet are adjusted.
1 parent 37593b7 commit a884071

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

src/network/networkd-link.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct Link {
5656
struct hw_addr_data hw_addr;
5757
struct hw_addr_data bcast_addr;
5858
struct hw_addr_data permanent_hw_addr;
59+
struct hw_addr_data requested_hw_addr;
5960
struct in6_addr ipv6ll_address;
6061
uint32_t mtu;
6162
uint32_t min_mtu;

src/network/networkd-network-gperf.gperf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Match.KernelCommandLine, config_parse_net_condition,
6161
Match.KernelVersion, config_parse_net_condition, CONDITION_KERNEL_VERSION, offsetof(Network, conditions)
6262
Match.Architecture, config_parse_net_condition, CONDITION_ARCHITECTURE, offsetof(Network, conditions)
6363
Match.Firmware, config_parse_net_condition, CONDITION_FIRMWARE, offsetof(Network, conditions)
64-
Link.MACAddress, config_parse_ether_addr, 0, offsetof(Network, mac)
64+
Link.MACAddress, config_parse_hw_addr, 0, offsetof(Network, hw_addr)
6565
Link.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(Network, mtu)
6666
Link.Group, config_parse_link_group, 0, 0
6767
Link.ARP, config_parse_tristate, 0, offsetof(Network, arp)

src/network/networkd-network.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@ static Network *network_free(Network *network) {
674674
set_free(network->dhcp_allow_listed_ip);
675675
set_free(network->dhcp_request_options);
676676
set_free(network->dhcp6_request_options);
677-
free(network->mac);
678677
free(network->dhcp6_mudurl);
679678
strv_free(network->dhcp6_user_class);
680679
strv_free(network->dhcp6_vendor_class);

src/network/networkd-network.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct Network {
9494
Hashmap *stacked_netdev_names;
9595

9696
/* [Link] section */
97-
struct ether_addr *mac;
97+
struct hw_addr_data hw_addr;
9898
uint32_t mtu;
9999
int32_t group;
100100
int arp;

src/network/networkd-setlink.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/if_bridge.h>
77

88
#include "missing_network.h"
9+
#include "netif-util.h"
910
#include "netlink-util.h"
1011
#include "networkd-address.h"
1112
#include "networkd-can.h"
@@ -183,7 +184,7 @@ static int link_set_mac_allow_retry_handler(sd_netlink *rtnl, sd_netlink_message
183184
return 0;
184185
}
185186

186-
/* set_link_mac_handler() also decrement set_link_messages, so once increment the value. */
187+
/* set_link_mac_handler() also decrements set_link_messages, so increment the value once. */
187188
link->set_link_messages++;
188189
return link_set_mac_handler(rtnl, m, link);
189190
}
@@ -463,7 +464,7 @@ static int link_configure(
463464
return log_link_debug_errno(link, r, "Could not append IFLA_GROUP attribute: %m");
464465
break;
465466
case SET_LINK_MAC:
466-
r = sd_netlink_message_append_ether_addr(req, IFLA_ADDRESS, link->network->mac);
467+
r = netlink_message_append_hw_addr(req, IFLA_ADDRESS, &link->requested_hw_addr);
467468
if (r < 0)
468469
return log_link_debug_errno(link, r, "Could not append IFLA_ADDRESS attribute: %m");
469470
break;
@@ -542,7 +543,7 @@ static bool link_is_ready_to_call_set_link(Request *req) {
542543
break;
543544
case SET_LINK_MAC:
544545
if (req->netlink_handler == link_set_mac_handler) {
545-
/* This is the second trial to set MTU. On the first attempt
546+
/* This is the second trial to set hardware address. On the first attempt
546547
* req->netlink_handler points to link_set_mac_allow_retry_handler().
547548
* The first trial failed as the interface was up. */
548549
r = link_down(link);
@@ -777,20 +778,21 @@ int link_request_to_set_group(Link *link) {
777778
}
778779

779780
int link_request_to_set_mac(Link *link, bool allow_retry) {
781+
int r;
782+
780783
assert(link);
781784
assert(link->network);
782785

783-
if (!link->network->mac)
786+
if (link->network->hw_addr.length == 0)
784787
return 0;
785788

786-
if (link->hw_addr.length != sizeof(struct ether_addr)) {
787-
/* Note that for now we only support changing hardware addresses on Ethernet. */
788-
log_link_debug(link, "Size of the hardware address (%zu) does not match the size of MAC address (%zu), ignoring.",
789-
link->hw_addr.length, sizeof(struct ether_addr));
790-
return 0;
791-
}
789+
link->requested_hw_addr = link->network->hw_addr;
790+
r = net_verify_hardware_address(link->ifname, /* warn_invalid = */ true,
791+
link->iftype, &link->hw_addr, &link->requested_hw_addr);
792+
if (r < 0)
793+
return r;
792794

793-
if (ether_addr_equal(&link->hw_addr.ether, link->network->mac))
795+
if (hw_addr_equal(&link->hw_addr, &link->requested_hw_addr))
794796
return 0;
795797

796798
return link_request_set_link(link, SET_LINK_MAC,

test/test-network/systemd-networkd-tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2704,7 +2704,8 @@ def test_ip_link_mac_address(self):
27042704

27052705
output = check_output('ip link show dummy98')
27062706
print(output)
2707-
self.assertRegex(output, '00:01:02:aa:bb:cc')
2707+
# 00:01:02:aa:bb:cc was requested, and the local bit is set by networkd.
2708+
self.assertRegex(output, '02:01:02:aa:bb:cc')
27082709

27092710
def test_ip_link_unmanaged(self):
27102711
copy_unit_to_networkd_unit_path('25-link-section-unmanaged.network', '12-dummy.netdev')

0 commit comments

Comments
 (0)
X Tutup