dhcp-client: Log DHCP messages at higher priority.
[sliver-openvswitch.git] / lib / dhcp-client.c
index 1e481cf..c770f2a 100644 (file)
@@ -219,6 +219,14 @@ dhclient_destroy(struct dhclient *cli)
     }
 }
 
+/* Returns the network device in use by 'cli'.  The caller must not destroy
+ * the returned device. */
+struct netdev *
+dhclient_get_netdev(struct dhclient *cli)
+{
+    return cli->netdev;
+}
+
 /* Forces 'cli' into a (re)initialization state, in which no address is bound
  * but the client is advertising to obtain one.  If 'requested_ip' is nonzero,
  * then the client will attempt to re-bind to that IP address; otherwise, it
@@ -792,7 +800,13 @@ void
 dhclient_wait(struct dhclient *cli)
 {
     if (cli->min_timeout != UINT_MAX) {
-        poll_timer_wait(sat_mul(cli->min_timeout, 1000));
+        time_t now = time_now();
+        unsigned int wake = sat_add(cli->state_entered, cli->min_timeout);
+        if (wake <= now) {
+            poll_immediate_wake();
+        } else {
+            poll_timer_wait(sat_mul(sat_sub(wake, now), 1000));
+        }
     }
     /* Reset timeout to 1 second.  This will have no effect ordinarily, because
      * dhclient_run() will typically set it back to a higher value.  If,
@@ -929,8 +943,12 @@ do_receive_msg(struct dhclient *cli, struct dhcp_msg *msg)
         ofpbuf_pull(&b, (char *)b.l7 - (char*)b.data);
         error = dhcp_parse(msg, &b);
         if (!error) {
-            VLOG_DBG_RL(&rl, "received %s",
-                        dhcp_msg_to_string(msg, false, &cli->s));
+            if (VLOG_IS_DBG_ENABLED()) {
+                VLOG_DBG_RL(&rl, "received %s",
+                            dhcp_msg_to_string(msg, false, &cli->s)); 
+            } else {
+                VLOG_WARN_RL(&rl, "received %s", dhcp_type_name(msg->type));
+            }
             ofpbuf_uninit(&b);
             return true;
         }
@@ -1005,7 +1023,11 @@ do_send_msg(struct dhclient *cli, const struct dhcp_msg *msg)
      * frame to have to be discarded or fragmented if it travels over a regular
      * Ethernet at some point.  1500 bytes should be enough for anyone. */
     if (b.size <= ETH_TOTAL_MAX) {
-        VLOG_DBG("sending %s", dhcp_msg_to_string(msg, false, &cli->s));
+        if (VLOG_IS_DBG_ENABLED()) {
+            VLOG_DBG("sending %s", dhcp_msg_to_string(msg, false, &cli->s)); 
+        } else {
+            VLOG_WARN("sending %s", dhcp_type_name(msg->type));
+        }
         error = netdev_send(cli->netdev, &b);
         if (error) {
             VLOG_ERR("send failed on %s: %s",