]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
dhcpcd: For anonymous do not bring interface up if was down
authorRoy Marples <roy@marples.name>
Sat, 25 Jan 2020 13:27:36 +0000 (13:27 +0000)
committerRoy Marples <roy@marples.name>
Sat, 25 Jan 2020 13:27:36 +0000 (13:27 +0000)
We need to bring the interface down on carrier loss to change the
hardware address, but we should only bring it up again if it was
up previously.

After all it's really an administrative flag.

src/dhcpcd.c

index df2aff95e8c84c0c9ff276caa6a6b2056465f9b7..20ade526865bcc3faad3755d81b8c9038919a94c 100644 (file)
@@ -728,10 +728,14 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
 #endif
                                dhcpcd_drop(ifp, 0);
                        if (ifp->options->options & DHCPCD_ANONYMOUS) {
-                               if_down(ifp);
+                               bool was_up = ifp->flags & IFF_UP;
+
+                               if (was_up)
+                                       if_down(ifp);
                                if (if_randomisemac(ifp) == -1 && errno != ENXIO)
                                        logerr(__func__);
-                               if_up(ifp);
+                               if (was_up)
+                                       if_up(ifp);
                        }
                }
        } else if (carrier == LINK_UP && ifp->flags & IFF_UP) {