diff options
| author | Roy Marples <roy@marples.name> | 2020-01-15 15:48:27 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2020-01-15 15:48:27 +0000 |
| commit | a7fdc3fc1092923e37630d8d35c2616b4ae119a1 (patch) | |
| tree | f7f0c2cfb003be18d469181caeee553544ebe3c8 /src/if.c | |
| parent | f94226d3c06d23ceedaabd7cbef586ceb6e7022e (diff) | |
| download | dhcpcd-a7fdc3fc1092923e37630d8d35c2616b4ae119a1.tar.xz | |
if: Fix hardware address randomisation
And copy back the actual length of it, not the whole buffer.
Diffstat (limited to 'src/if.c')
| -rw-r--r-- | src/if.c | 15 |
1 files changed, 6 insertions, 9 deletions
@@ -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; } |
