]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
priv: don't use ethtool to get real MAC
authorVincent Bernat <vincent@bernat.im>
Sat, 6 Aug 2016 21:55:32 +0000 (23:55 +0200)
committerVincent Bernat <vincent@bernat.im>
Sat, 6 Aug 2016 21:57:18 +0000 (23:57 +0200)
It was used if /proc/net/bonding was not available but:

 1. it shouldn't happen
 2. some drivers don't have a permanent MAC
 3. we may override a user setting
 4. more code to maintaing

NEWS
src/daemon/interfaces-linux.c
src/daemon/lldpd.h
src/daemon/priv-linux.c
src/daemon/priv.c

diff --git a/NEWS b/NEWS
index 59a54941f3db602767051da4f7615f624c53c319..8e83039e67fa01dc16fc55c4977d75f6b5df74a4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 lldpd (0.9.5)
   * Fix:
     + Compilation fix with older versions of GCC.
+    + Don't use ethtool at all to get real MAC address for enslaved
+      devices (always use /proc).
 
 lldpd (0.9.4)
   * Change:
index f6b75a4207912c1a47b116bf061e097535383834..c2d4e61384b271fea0ed810558b17bb078bab0b3 100644 (file)
@@ -231,47 +231,6 @@ iflinux_is_bond(struct lldpd *cfg,
        return 0;
 }
 
-/* Get the permanent MAC address using ethtool as a fallback There is a slight
- * difference with /proc/net/bonding method. The /proc/net/bonding method will
- * retrieve the MAC address of the interface before it was added to the
- * bond. The ethtool method will retrieve the real permanent MAC address. For
- * some devices, there is no such address (for example, virtual devices like
- * veth). */
-static void
-iflinux_get_permanent_mac_ethtool(struct lldpd *cfg,
-    struct interfaces_device_list *interfaces,
-    struct interfaces_device *iface)
-{
-       struct interfaces_device *master;
-       u_int8_t mac[ETHER_ADDR_LEN];
-
-       /* We could do that for any interface, but let's do that only for
-        * aggregates. */
-       if ((master = iface->upper) == NULL || master->type != IFACE_BOND_T)
-               return;
-
-       log_debug("interfaces", "get MAC address for %s",
-           iface->name);
-
-       if (priv_iface_mac(iface->name, mac, ETHER_ADDR_LEN) != 0) {
-               log_warnx("interfaces",
-                   "unable to get permanent MAC address for %s",
-                   master->name);
-               return;
-       }
-       size_t i;
-       for (i = 0; i < ETHER_ADDR_LEN; i++)
-               if (mac[i] != 0) break;
-       if (i == ETHER_ADDR_LEN) {
-               log_warnx("interfaces",
-                   "no permanent MAC address found for %s",
-                   master->name);
-               return;
-       }
-       memcpy(iface->address, mac,
-           ETHER_ADDR_LEN);
-}
-
 static void
 iflinux_get_permanent_mac(struct lldpd *cfg,
     struct interfaces_device_list *interfaces,
@@ -304,7 +263,9 @@ iflinux_get_permanent_mac(struct lldpd *cfg,
                f = priv_open(path);
        }
        if (f < 0) {
-               iflinux_get_permanent_mac_ethtool(cfg, interfaces, iface);
+               log_warnx("interfaces",
+                   "unable to get permanent MAC address for %s",
+                   master->name);
                return;
        }
        if ((netbond = fdopen(f, "r")) == NULL) {
index 263f8e2d20b91a57108b0791b598e3624a4db53a..9eaf2c5938b027fe6c625a0358e916556a071d81 100644 (file)
@@ -202,8 +202,6 @@ int          priv_open(char*);
 void    asroot_open(void);
 int             priv_ethtool(char*, void*, size_t);
 void    asroot_ethtool(void);
-int             priv_iface_mac(char*, void*, size_t);
-void    asroot_iface_mac(void);
 #endif
 int             priv_iface_init(int, char *);
 int     asroot_iface_init_os(int, char *, int *);
@@ -224,7 +222,6 @@ enum priv_cmd {
        PRIV_IFACE_MULTICAST,
        PRIV_IFACE_DESCRIPTION,
        PRIV_IFACE_PROMISC,
-       PRIV_IFACE_MAC,
        PRIV_SNMP_SOCKET,
 };
 
index ee78bb664d9ab761716f7c8cf3bb4f6c2a64409f..f550a0c79820f8774a6b899216f7ad208da6061e 100644 (file)
@@ -72,25 +72,6 @@ priv_ethtool(char *ifname, void *ethc, size_t length)
        return rc;
 }
 
-/* Proxy to get permanent MAC address. Not needed since
- * 75f3123c118743f52b690d9ab41649814befda0a (2.6.19). */
-int
-priv_iface_mac(char *ifname, void *mac, size_t length)
-{
-       int rc, len;
-       enum priv_cmd cmd = PRIV_IFACE_MAC;
-       must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
-       len = strlen(ifname);
-       must_write(PRIV_UNPRIVILEGED, &len, sizeof(int));
-       must_write(PRIV_UNPRIVILEGED, ifname, len);
-       priv_wait();
-       must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
-       if (rc != 0)
-               return rc;
-       must_read(PRIV_UNPRIVILEGED, mac, length);
-       return rc;
-}
-
 void
 asroot_open()
 {
@@ -179,40 +160,6 @@ asroot_ethtool()
        must_write(PRIV_PRIVILEGED, &ethc, sizeof(struct ethtool_cmd));
 }
 
-void
-asroot_iface_mac()
-{
-       struct ifreq ifr = {};
-       int len, rc, sock = -1;
-       char *ifname;
-       struct ethtool_perm_addr *epaddr;
-
-       must_read(PRIV_PRIVILEGED, &len, sizeof(int));
-       if ((ifname = (char*)malloc(len + 1)) == NULL)
-               fatal("privsep", NULL);
-       must_read(PRIV_PRIVILEGED, ifname, len);
-       ifname[len] = '\0';
-       strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
-       free(ifname);
-
-       if ((epaddr = malloc(sizeof(struct ethtool_perm_addr) + ETHER_ADDR_LEN)) == NULL)
-               fatal("privsep", NULL);
-       epaddr->cmd = ETHTOOL_GPERMADDR;
-       epaddr->size = ETHER_ADDR_LEN;
-       ifr.ifr_data = (caddr_t)epaddr;
-       if (((rc = sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) ||
-           (rc = ioctl(sock, SIOCETHTOOL, &ifr)) != 0) {
-               if (sock != -1) close(sock);
-               free(epaddr);
-               must_write(PRIV_PRIVILEGED, &rc, sizeof(int));
-               return;
-       }
-       close(sock);
-       must_write(PRIV_PRIVILEGED, &rc, sizeof(int));
-       must_write(PRIV_PRIVILEGED, epaddr->data, ETHER_ADDR_LEN);
-       free(epaddr);
-}
-
 int
 asroot_iface_init_os(int ifindex, char *name, int *fd)
 {
index 7a65b120de79b6b8f6a70745450b164fb489fbe2..f03c90aa1e30834ff6d03decbd7b940b64df1f23 100644 (file)
@@ -388,7 +388,6 @@ static struct dispatch_actions actions[] = {
 #ifdef HOST_OS_LINUX
        {PRIV_OPEN, asroot_open},
        {PRIV_ETHTOOL, asroot_ethtool},
-       {PRIV_IFACE_MAC, asroot_iface_mac},
 #endif
        {PRIV_IFACE_INIT, asroot_iface_init},
        {PRIV_IFACE_MULTICAST, asroot_iface_multicast},