summaryrefslogtreecommitdiffstats
path: root/src/if.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2020-01-15 15:48:27 +0000
committerRoy Marples <roy@marples.name>2020-01-15 15:48:27 +0000
commitc003fd8cff645876bd5b8116aee0170d0ed478ae (patch)
treef7f0c2cfb003be18d469181caeee553544ebe3c8 /src/if.c
parent9da144a68a9477781efc22a097417bfa7f9494a9 (diff)
downloaddhcpcd-c003fd8cff645876bd5b8116aee0170d0ed478ae.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.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/if.c b/src/if.c
index ff1a88bb..75776512 100644
--- 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;
}