Mercurial > hg > dhcpcd
changeset 4960:cf298b786d8c draft
if: Fix hardware address randomisation
And copy back the actual length of it, not the whole buffer.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Wed, 15 Jan 2020 15:48:27 +0000 |
| parents | 1b7325caa3ce |
| children | cd7f5f9ed3cb |
| files | src/if.c |
| diffstat | 1 files changed, 6 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/if.c Wed Jan 15 15:47:45 2020 +0000 +++ b/src/if.c Wed Jan 15 15:48:27 2020 +0000 @@ -198,23 +198,20 @@ 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; }
