]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: do not require ethtool_get_permanent_macaddr() to get an fd
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 8 Jan 2020 11:02:01 +0000 (12:02 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 8 Jan 2020 16:14:56 +0000 (17:14 +0100)
src/network/networkctl.c
src/network/networkd-link.c
src/shared/ethtool-util.c

index 244fb0848cbab22edb59010628d2adee52b6d789..182208b56314422c995f4f49f77c9c3174171197 100644 (file)
@@ -320,9 +320,8 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info, char **patterns) {
                 sd_netlink_message_read_ether_addr(m, IFLA_ADDRESS, &info->mac_address) >= 0 &&
                 memcmp(&info->mac_address, &ETHER_ADDR_NULL, sizeof(struct ether_addr)) != 0;
 
-        _cleanup_close_ int fd = -1;
         info->has_permanent_mac_address =
-                ethtool_get_permanent_macaddr(&fd, info->name, &info->permanent_mac_address) >= 0 &&
+                ethtool_get_permanent_macaddr(NULL, info->name, &info->permanent_mac_address) >= 0 &&
                 memcmp(&info->permanent_mac_address, &ETHER_ADDR_NULL, sizeof(struct ether_addr)) != 0 &&
                 memcmp(&info->permanent_mac_address, &info->mac_address, sizeof(struct ether_addr)) != 0;
 
index cd370bef57dc7bdf3679136ca2c644eeda20dde7..97de25a3f84154cf08c3f100c0fa4d9fc97bd4f3 100644 (file)
@@ -618,8 +618,7 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
         if (r < 0)
                 log_link_debug_errno(link, r, "MAC address not found for new device, continuing without");
 
-        _cleanup_close_ int fd = -1;
-        r = ethtool_get_permanent_macaddr(&fd, link->ifname, &link->permanent_mac);
+        r = ethtool_get_permanent_macaddr(NULL, link->ifname, &link->permanent_mac);
         if (r < 0)
                 log_link_debug_errno(link, r, "Permanent MAC address not found for new device, continuing without: %m");
 
index e00ed8e97dbe340cf9717cf92117cbacbcf80cc5..9d62728ca43129ae2f83107abccf33d05028ec3d 100644 (file)
@@ -9,6 +9,7 @@
 #include "conf-parser.h"
 #include "ethtool-util.h"
 #include "extract-word.h"
+#include "fd-util.h"
 #include "log.h"
 #include "memory-util.h"
 #include "socket-util.h"
@@ -219,14 +220,17 @@ int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
 }
 
 int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret) {
+        _cleanup_close_ int fd = -1;
         _cleanup_free_ struct ethtool_perm_addr *epaddr = NULL;
         struct ifreq ifr;
         int r;
 
-        assert(ethtool_fd);
         assert(ifname);
         assert(ret);
 
+        if (!ethtool_fd)
+                ethtool_fd = &fd;
+
         if (*ethtool_fd < 0) {
                 r = ethtool_connect_or_warn(ethtool_fd, false);
                 if (r < 0)