]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add --inactive which makes all interfaces inactive on initial start.
authorRoy Marples <roy@marples.name>
Wed, 27 Jul 2016 16:47:34 +0000 (16:47 +0000)
committerRoy Marples <roy@marples.name>
Wed, 27 Jul 2016 16:47:34 +0000 (16:47 +0000)
Subsequent dhcpcd commands will start each interface.

dhcpcd.8.in
dhcpcd.c
if-options.c
if-options.h
if.c

index 3a3ec44b0c2c8beeefc356edbac7be9d11c96db1..e31f3c0c27ea6800875d64dc91b668f5dae73c1b 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd June 27, 2016
+.Dd July 27, 2016
 .Dt DHCPCD 8
 .Os
 .Sh NAME
@@ -59,6 +59,7 @@
 .Op Fl X , Fl Fl blacklist Ar address Ns Op Ar /cidr
 .Op Fl Z , Fl Fl denyinterfaces Ar pattern
 .Op Fl z , Fl Fl allowinterfaces Ar pattern
+.Op Fl Fl inactive
 .Op interface
 .Op ...
 .Nm
@@ -380,7 +381,7 @@ DHCP server.
 .It Fl M , Fl Fl master
 Start
 .Nm
-in master mode even if only one interface specified on the command line.
+in Master mode even if only one interface specified on the command line.
 See the Multiple Interfaces section above.
 .It Fl m , Fl Fl metric Ar metric
 Metrics are used to prefer an interface over another one, lowest wins.
@@ -705,6 +706,13 @@ which is a space or comma separated list of patterns passed to
 If the same interface is matched in
 .Fl Z , Fl Fl denyinterfaces
 then it is still denied.
+.It Fl Fl inactive
+Don't start any interfaces other than those specified on the command line.
+This allows
+.Nm
+to be started in Master mode and then wait for subsequent
+.Nm
+commands to start each interface as required.
 .It Fl Fl nodev
 Don't load any
 .Pa /dev
index d47a9ab882815b9ab2c85a1d55924f18a57e1269..db9947654192acbbd6538a1a4328deb0e6f2dacb 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1043,7 +1043,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname)
                        continue;
 
                /* If running off an interface list, check it's in it. */
-               if (ctx->ifc) {
+               if (ctx->ifc || ctx->options & DHCPCD_INACTIVE) {
                        for (i = 0; i < ctx->ifc; i++)
                                if (strcmp(ctx->ifv[i], ifname) == 0)
                                        break;
@@ -1860,7 +1860,9 @@ printpidfile:
        }
        if (ifp == NULL) {
                if (ctx.ifc == 0)
-                       logger(&ctx, LOG_ERR, "no valid interfaces found");
+                       logger(&ctx,
+                           ctx.options & DHCPCD_INACTIVE ? LOG_DEBUG : LOG_ERR,
+                           "no valid interfaces found");
                else
                        goto exit_failure;
                if (!(ctx.options & DHCPCD_LINK)) {
@@ -1904,7 +1906,9 @@ printpidfile:
                    ctx.options & DHCPCD_LINK &&
                    !(ctx.options & DHCPCD_WAITIP))
                {
-                       logger(&ctx, LOG_WARNING,
+                       logger(&ctx,
+                           ctx.options & DHCPCD_INACTIVE ?
+                           LOG_DEBUG : LOG_WARNING,
                            "no interfaces have a carrier");
                        if (dhcpcd_daemonise(&ctx))
                                goto exit_success;
index 4e7ad72f027fed46c1c0366942717806f39006a1..6012647a007fd06ab94be3ab5574e404574ab593 100644 (file)
 #define O_NODELAY              O_BASE + 44
 #define O_INFORM6              O_BASE + 45
 #define O_LASTLEASE_EXTEND     O_BASE + 46
+#define O_INACTIVE             O_BASE + 47
 
 const struct option cf_options[] = {
        {"background",      no_argument,       NULL, 'b'},
@@ -200,6 +201,7 @@ const struct option cf_options[] = {
        {"nodelay",         no_argument,       NULL, O_NODELAY},
        {"noup",            no_argument,       NULL, O_NOUP},
        {"lastleaseextend", no_argument,       NULL, O_LASTLEASE_EXTEND},
+       {"inactive",        no_argument,       NULL, O_INACTIVE},
        {NULL,              0,                 NULL, '\0'}
 };
 
@@ -2133,6 +2135,9 @@ err_sla:
        case O_LASTLEASE_EXTEND:
                ifo->options |= DHCPCD_LASTLEASE | DHCPCD_LASTLEASE_EXTEND;
                break;
+       case O_INACTIVE:
+               ifo->options |= DHCPCD_INACTIVE;
+               break;
        default:
                return 0;
        }
index a0be326a5bf5eb62d418694ff5a96ff1e6c8ef68..991672a01d44bcb1a2056dd48c907d93aa96cca4 100644 (file)
 #define DHCPCD_INITIAL_DELAY           (1ULL << 58)
 #define DHCPCD_PRINT_PIDFILE           (1ULL << 59)
 #define DHCPCD_ONESHOT                 (1ULL << 60)
+#define DHCPCD_INACTIVE                        (1ULL << 61)
 
 #define DHCPCD_NODROP  (DHCPCD_EXITING | DHCPCD_PERSISTENT)
 
diff --git a/if.c b/if.c
index dad80ca2a2f14ba9e73d7fd3592bf6a393e59f4c..b79f01b1519f1c5f74e7ad3a1a94ad8e8a660c71 100644 (file)
--- a/if.c
+++ b/if.c
@@ -291,20 +291,20 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                if (ifp)
                        continue;
 
-               active = IF_ACTIVE_USER;
                if (argc > 0) {
                        for (i = 0; i < argc; i++) {
                                if (strcmp(argv[i], spec.devname) == 0)
                                        break;
                        }
-                       if (i == argc)
-                               active = IF_INACTIVE;
+                       active = (i == argc) ? IF_INACTIVE : IF_ACTIVE_USER;
                } else {
                        /* -1 means we're discovering against a specific
                         * interface, but we still need the below rules
                         * to apply. */
                        if (argc == -1 && strcmp(argv[0], spec.devname) != 0)
                                continue;
+                       active = ctx->options & DHCPCD_INACTIVE ?
+                           IF_INACTIVE: IF_ACTIVE_USER;
                }
 
                for (i = 0; i < ctx->ifdc; i++)