From: Vincent Bernat Date: Sat, 6 Aug 2016 21:55:32 +0000 (+0200) Subject: priv: don't use ethtool to get real MAC X-Git-Tag: 0.9.5~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b7f8847b9a16e3dab156a0734cc8c29619b67e1;p=thirdparty%2Flldpd.git priv: don't use ethtool to get real MAC 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 --- diff --git a/NEWS b/NEWS index 59a54941..8e83039e 100644 --- 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: diff --git a/src/daemon/interfaces-linux.c b/src/daemon/interfaces-linux.c index f6b75a42..c2d4e613 100644 --- a/src/daemon/interfaces-linux.c +++ b/src/daemon/interfaces-linux.c @@ -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) { diff --git a/src/daemon/lldpd.h b/src/daemon/lldpd.h index 263f8e2d..9eaf2c59 100644 --- a/src/daemon/lldpd.h +++ b/src/daemon/lldpd.h @@ -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, }; diff --git a/src/daemon/priv-linux.c b/src/daemon/priv-linux.c index ee78bb66..f550a0c7 100644 --- a/src/daemon/priv-linux.c +++ b/src/daemon/priv-linux.c @@ -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, ðc, 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) { diff --git a/src/daemon/priv.c b/src/daemon/priv.c index 7a65b120..f03c90aa 100644 --- a/src/daemon/priv.c +++ b/src/daemon/priv.c @@ -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},