From 57d0d4a271b13a912dfa2ba3321a4a0a75d0bff8 Mon Sep 17 00:00:00 2001 From: Leandro Lupori Date: Thu, 4 Jul 2019 12:31:24 +0000 Subject: [PATCH] [PPC64] pseries llan: fix MAC address There was an issue in pseries llan driver, that resulted in the first 2 bytes of the MAC address getting stripped, and the last 2 being always 0. In most cases the network interface still worked, despite the MAC being different of what was specified to QEMU, but when some other host or DHCP server expected a specific MAC, this would fail. This change fixes this by shifting right by 2 the local-mac-address read from device tree, if its length is 6 instead of 8, as observed in QEMU DT, that always presents a 6 bytes value for this property. PR: 237471 Reported by: Alfredo Dal'Ava Junior Reviewed by: jhibbits Differential Revision: https://reviews.freebsd.org/D20843 --- sys/powerpc/pseries/phyp_llan.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sys/powerpc/pseries/phyp_llan.c b/sys/powerpc/pseries/phyp_llan.c index 5b95147dd1a..75b594c2391 100644 --- a/sys/powerpc/pseries/phyp_llan.c +++ b/sys/powerpc/pseries/phyp_llan.c @@ -157,14 +157,23 @@ llan_attach(device_t dev) struct llan_softc *sc; phandle_t node; int error, i; + ssize_t len; sc = device_get_softc(dev); sc->dev = dev; /* Get firmware properties */ node = ofw_bus_get_node(dev); - OF_getprop(node, "local-mac-address", sc->mac_address, + len = OF_getprop(node, "local-mac-address", sc->mac_address, sizeof(sc->mac_address)); + /* If local-mac-address property has only 6 bytes (ETHER_ADDR_LEN) + * instead of 8 (sizeof(sc->mac_address)), then its value must be + * shifted 2 bytes to the right. */ + if (len == ETHER_ADDR_LEN) { + bcopy(sc->mac_address, &sc->mac_address[2], len); + /* Zero out the first 2 bytes. */ + bzero(sc->mac_address, 2); + } OF_getencprop(node, "reg", &sc->unit, sizeof(sc->unit)); mtx_init(&sc->io_lock, "llan", NULL, MTX_DEF); @@ -504,7 +513,7 @@ llan_set_multicast(struct llan_softc *sc) { struct ifnet *ifp = sc->ifp; struct ifmultiaddr *inm; - uint64_t macaddr; + uint64_t macaddr = 0; mtx_assert(&sc->io_lock, MA_OWNED); -- 2.45.0