Set DHCP maximum retransmission timeout to 3 seconds in secchan.
authorBen Pfaff <blp@nicira.com>
Tue, 14 Oct 2008 23:11:06 +0000 (16:11 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 14 Oct 2008 23:14:13 +0000 (16:14 -0700)
This should help discovery complete faster, especially with hops across
multiple OpenFlow switches to the controller.

include/dhcp-client.h
lib/dhcp-client.c
secchan/secchan.c

index e0d1e37..8dfc50c 100644 (file)
@@ -44,6 +44,7 @@ int dhclient_create(const char *netdev,
                     void (*modify_request)(struct dhcp_msg *, void *aux),
                     bool (*validate_offer)(const struct dhcp_msg *, void *aux),
                     void *aux, struct dhclient **);
+void dhclient_set_max_timeout(struct dhclient *, unsigned int max_timeout);
 void dhclient_destroy(struct dhclient *);
 
 struct netdev *dhclient_get_netdev(struct dhclient *);
index c770f2a..460fedf 100644 (file)
@@ -103,6 +103,7 @@ struct dhclient {
     bool changed;
 
     unsigned int retransmit, delay; /* Used by send_reliably(). */
+    unsigned int max_timeout;
 
     unsigned int init_delay;    /* Used by S_INIT. */
 
@@ -199,6 +200,7 @@ dhclient_create(const char *netdev_name,
     cli->ipaddr = 0;
     cli->server_ip = 0;
     cli->retransmit = cli->delay = 0;
+    cli->max_timeout = 64;
     cli->min_timeout = 1;
     ds_init(&cli->s);
     cli->changed = true;
@@ -206,6 +208,15 @@ dhclient_create(const char *netdev_name,
     return 0;
 }
 
+/* Sets the maximum amount of timeout that 'cli' will wait for a reply from
+ * the DHCP server before retransmitting, in seconds, to 'max_timeout'.  The
+ * default is 64 seconds. */
+void
+dhclient_set_max_timeout(struct dhclient *cli, unsigned int max_timeout)
+{
+    cli->max_timeout = MAX(2, max_timeout);
+}
+
 /* Destroys 'cli' and frees all related resources. */
 void
 dhclient_destroy(struct dhclient *cli)
@@ -867,7 +878,7 @@ send_reliably(struct dhclient *cli,
             cli->modify_request(&msg, cli->aux);
         }
         do_send_msg(cli, &msg);
-        cli->delay = MIN(64, MAX(4, cli->delay * 2));
+        cli->delay = MIN(cli->max_timeout, MAX(4, cli->delay * 2));
         cli->retransmit += fuzz(cli->delay, 1);
         timeout(cli, cli->retransmit);
         dhcp_msg_uninit(&msg);
index 78ccf30..27ecf1b 100644 (file)
@@ -2378,6 +2378,7 @@ discovery_local_port_cb(const struct ofp_phy_port *port, void *d_)
                      "discovery disabled: %s", strerror(retval));
             return;
         }
+        dhclient_set_max_timeout(d->dhcp, 3);
         dhclient_init(d->dhcp, 0);
     } else {
         dhclient_destroy(d->dhcp);