Add the address waiting state, to match the waitip directive in dhcpcd.conf
authorRoy Marples <roy@marples.name>
Tue, 9 Jun 2015 21:20:08 +0000 (21:20 +0000)
committerRoy Marples <roy@marples.name>
Tue, 9 Jun 2015 21:20:08 +0000 (21:20 +0000)
src/libdhcpcd/dhcpcd.c
src/libdhcpcd/dhcpcd.h

index ab4b29074254eb1c568f7f456c8c49e4c9d80c57..165d16fdc78f2846244085185d26fa2aaa66249c 100644 (file)
@@ -75,7 +75,8 @@ const char * const dhcpcd_cstates[DHC_MAX] = {
        "initialised",
        "disconnected",
        "connecting",
-       "connected"
+       "waiting",
+       "connected",
 };
 
 struct dhcpcd_vs {
@@ -517,10 +518,16 @@ get_status(DHCPCD_CONNECTION *con)
        for (i = con->interfaces; i; i = i->next) {
                if (i->up) {
                        if (i->type == DHT_LINK) {
-                               status = DHC_CONNECTED;
-                               break;
-                       } else
-                               status = DHC_CONNECTING;
+                               if (status == DHC_DISCONNECTED)
+                                       status = DHC_CONNECTING;
+                       } else {
+                               if (con->af_waiting)
+                                       status = DHC_AF_WAITING;
+                               else {
+                                       status = DHC_CONNECTED;
+                                       break;
+                               }
+                       }
                }
        }
        return status;
@@ -819,6 +826,12 @@ dhcpcd_new_if(DHCPCD_CONNECTION *con, char *data, size_t len)
        if (i->ssid == NULL && i->wireless)
                i->ssid = dhcpcd_get_value(i, i->up ? "new_ssid" : "old_ssid");
 
+       /* Work out if we're waiting for any other addresses */
+       if (dhcpcd_get_value(i, "af_waiting") == NULL)
+               con->af_waiting = false;
+       else
+               con->af_waiting = true;
+
        /* Sort! */
        n = nl = NULL;
        p = orderdup;
@@ -932,6 +945,7 @@ dhcpcd_new(void)
        con->command_fd = con->listen_fd = -1;
        con->open = false;
        con->progname = "libdhcpcd";
+       con->af_waiting = false;
        return con;
 }
 
@@ -1059,6 +1073,14 @@ dhcpcd_status(DHCPCD_CONNECTION *con, const char **status)
        return con->status;
 }
 
+bool
+dhcpcd_af_waiting(const DHCPCD_CONNECTION *con)
+{
+
+       assert(con);
+       return con->af_waiting;
+}
+
 const char *
 dhcpcd_version(DHCPCD_CONNECTION *con)
 {
index 35234c4cdcd9cef9e173082c9583345e7faf59cf..1671a4041f564f7ebf0bec238201171c2706a07a 100644 (file)
@@ -73,8 +73,9 @@ extern "C" {
 #define DHC_INITIALISED                 3
 #define DHC_DISCONNECTED        4
 #define DHC_CONNECTING          5
-#define DHC_CONNECTED           6
-#define DHC_MAX                         7
+#define DHC_AF_WAITING          6
+#define DHC_CONNECTED           7
+#define DHC_MAX                         8
 extern const char * const dhcpcd_cstates[];
 
 #define DHT_UNKNOWN             0
@@ -228,6 +229,7 @@ typedef struct dhcpcd_connection {
        int err;
        int errors;
        unsigned int status;
+       bool af_waiting;
 
        char *cffile;
 } DHCPCD_CONNECTION;
@@ -243,6 +245,7 @@ const char * dhcpcd_version(DHCPCD_CONNECTION *);
 void dhcpcd_set_progname(DHCPCD_CONNECTION *, const char *);
 const char * dhcpcd_get_progname(const DHCPCD_CONNECTION *);
 unsigned int dhcpcd_status(DHCPCD_CONNECTION *, const char **);
+bool dhcpcd_af_waiting(const DHCPCD_CONNECTION *);
 const char * dhcpcd_cffile(DHCPCD_CONNECTION *);
 bool dhcpcd_realloc(DHCPCD_CONNECTION *, size_t);
 int dhcpcd_open(DHCPCD_CONNECTION *, bool priv);