]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
if: Fix hardware address randomisation
authorRoy Marples <roy@marples.name>
Wed, 15 Jan 2020 15:48:27 +0000 (15:48 +0000)
committerRoy Marples <roy@marples.name>
Wed, 15 Jan 2020 15:48:27 +0000 (15:48 +0000)
And copy back the actual length of it, not the whole buffer.

src/if.c

index ff1a88bbcc47e649493e5cb7207b4e8954efb1dd..75776512ca0a69a2ae6ef81d2868183bc3a4f76d 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -198,23 +198,20 @@ if_randomisemac(struct interface *ifp)
                        rp = (uint8_t *)&randnum;
                        rlen = sizeof(randnum);
                }
-               if (bp == buf) {
-                       /* First octet is special. We need to preserve
-                        * bit 8 (unicast/multicast) and set
-                        * bit 7 (locally administered address) */
-                       *bp = *rp++ & 0xFC;
-                       *bp++ |= 2;
-               } else
-                       *bp++ = *rp++;
+               *bp++ = *rp++;
                rlen--;
        }
 
+       /* Unicast address and locally administered. */
+       buf[0] &= 0xFC;
+       buf[0] |= 0x02;
+
        logdebugx("%s: hardware address randomised to %s",
            ifp->name,
            hwaddr_ntoa(buf, sizeof(buf), sbuf, sizeof(sbuf)));
        retval = if_setmac(ifp, buf, ifp->hwlen);
        if (retval == 0)
-               memcpy(ifp->hwaddr, buf, sizeof(ifp->hwaddr));
+               memcpy(ifp->hwaddr, buf, ifp->hwlen);
        return retval;
 }