|
6 | 6 | #include <linux/if_bridge.h> |
7 | 7 |
|
8 | 8 | #include "missing_network.h" |
| 9 | +#include "netif-util.h" |
9 | 10 | #include "netlink-util.h" |
10 | 11 | #include "networkd-address.h" |
11 | 12 | #include "networkd-can.h" |
@@ -183,7 +184,7 @@ static int link_set_mac_allow_retry_handler(sd_netlink *rtnl, sd_netlink_message |
183 | 184 | return 0; |
184 | 185 | } |
185 | 186 |
|
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. */ |
187 | 188 | link->set_link_messages++; |
188 | 189 | return link_set_mac_handler(rtnl, m, link); |
189 | 190 | } |
@@ -463,7 +464,7 @@ static int link_configure( |
463 | 464 | return log_link_debug_errno(link, r, "Could not append IFLA_GROUP attribute: %m"); |
464 | 465 | break; |
465 | 466 | 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); |
467 | 468 | if (r < 0) |
468 | 469 | return log_link_debug_errno(link, r, "Could not append IFLA_ADDRESS attribute: %m"); |
469 | 470 | break; |
@@ -542,7 +543,7 @@ static bool link_is_ready_to_call_set_link(Request *req) { |
542 | 543 | break; |
543 | 544 | case SET_LINK_MAC: |
544 | 545 | 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 |
546 | 547 | * req->netlink_handler points to link_set_mac_allow_retry_handler(). |
547 | 548 | * The first trial failed as the interface was up. */ |
548 | 549 | r = link_down(link); |
@@ -777,20 +778,21 @@ int link_request_to_set_group(Link *link) { |
777 | 778 | } |
778 | 779 |
|
779 | 780 | int link_request_to_set_mac(Link *link, bool allow_retry) { |
| 781 | + int r; |
| 782 | + |
780 | 783 | assert(link); |
781 | 784 | assert(link->network); |
782 | 785 |
|
783 | | - if (!link->network->mac) |
| 786 | + if (link->network->hw_addr.length == 0) |
784 | 787 | return 0; |
785 | 788 |
|
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; |
792 | 794 |
|
793 | | - if (ether_addr_equal(&link->hw_addr.ether, link->network->mac)) |
| 795 | + if (hw_addr_equal(&link->hw_addr, &link->requested_hw_addr)) |
794 | 796 | return 0; |
795 | 797 |
|
796 | 798 | return link_request_set_link(link, SET_LINK_MAC, |
|
0 commit comments