]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
dhcpcd: randomise hardware address on start if no carrier
authorRoy Marples <roy@marples.name>
Fri, 7 Feb 2020 15:04:25 +0000 (15:04 +0000)
committerRoy Marples <roy@marples.name>
Fri, 7 Feb 2020 15:04:25 +0000 (15:04 +0000)
For more anonymity.

src/dhcpcd.c
src/if.c

index 3da529829c53c0da45587989d2285e5e7805fdb2..46564d013b7576124d16221355da310b65ba5df5 100644 (file)
@@ -940,9 +940,19 @@ static void
 dhcpcd_prestartinterface(void *arg)
 {
        struct interface *ifp = arg;
+       bool anondown;
+
+       if (ifp->carrier == LINK_DOWN &&
+           ifp->options->options & DHCPCD_ANONYMOUS &&
+           ifp->flags & IFF_UP)
+       {
+               if_down(ifp);
+               anondown = true;
+       } else
+               anondown = false;
 
        if ((!(ifp->ctx->options & DHCPCD_MASTER) ||
-           ifp->options->options & DHCPCD_IF_UP) &&
+           ifp->options->options & DHCPCD_IF_UP || anondown) &&
            !(ifp->flags & IFF_UP))
        {
                if (ifp->options->options & DHCPCD_ANONYMOUS &&
index 2172ec4e8a073beab50e6746fdd3d268eb99cf04..a4bf4d6187f58900dce68d65aa3f38db363e4fd3 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -213,7 +213,7 @@ if_randomisemac(struct interface *ifp)
 
        logdebugx("%s: hardware address randomised to %s",
            ifp->name,
-           hwaddr_ntoa(buf, sizeof(buf), sbuf, sizeof(sbuf)));
+           hwaddr_ntoa(buf, ifp->hwlen, sbuf, sizeof(sbuf)));
        retval = if_setmac(ifp, buf, ifp->hwlen);
        if (retval == 0)
                memcpy(ifp->hwaddr, buf, ifp->hwlen);