rconn: Be pickier about what constitutes a successful connection.
[openvswitch] / secchan / secchan.c
index e2a9585c1e95a192cd30fc407d51b9d81342d1f9..2fcd3f04b69f959b2d51ece3ec367012fcaf9c62 100644 (file)
@@ -89,8 +89,7 @@ struct settings {
     bool in_band;             /* Connect to controller in-band? */
 
     /* Related vconns and network devices. */
-    const char *nl_name;        /* Local datapath (must be "nl:" vconn). */
-    char *of_name;              /* ofX network device name. */
+    const char *dp_name;        /* Local datapath. */
     const char *controller_name; /* Controller (if not discovery mode). */
     const char *listener_names[MAX_MGMT]; /* Listen for mgmt connections. */
     size_t n_listeners;          /* Number of mgmt connection listeners. */
@@ -110,6 +109,9 @@ struct settings {
     regex_t accept_controller_regex;  /* Controller vconns to accept. */
     const char *accept_controller_re; /* String version of regex. */
     bool update_resolv_conf;          /* Update /etc/resolv.conf? */
+
+    /* Spanning tree protocol. */
+    bool enable_stp;
 };
 
 struct half {
@@ -174,7 +176,9 @@ static void status_reply_put(struct status_reply *, const char *, ...)
 
 static void rconn_status_cb(struct status_reply *, void *rconn_);
 
+struct port_watcher;
 static struct discovery *discovery_init(const struct settings *,
+                                        struct port_watcher *,
                                         struct switch_status *);
 static void discovery_question_connectivity(struct discovery *);
 static bool discovery_run(struct discovery *, char **controller_name);
@@ -182,16 +186,17 @@ static void discovery_wait(struct discovery *);
 
 static struct hook in_band_hook_create(const struct settings *,
                                        struct switch_status *,
+                                       struct port_watcher *,
                                        struct rconn *remote);
 
-struct port_watcher;
 static struct hook port_watcher_create(struct rconn *local,
                                        struct rconn *remote,
                                        struct port_watcher **);
-static uint32_t port_watcher_get_flags(const struct port_watcher *,
+static uint32_t port_watcher_get_config(const struct port_watcher *,
                                        int port_no);
-static void port_watcher_set_flags(struct port_watcher *,
-                                   int port_no, uint32_t flags, uint32_t mask);
+static void port_watcher_set_flags(struct port_watcher *, int port_no, 
+                                   uint32_t config, uint32_t c_mask,
+                                   uint32_t state, uint32_t s_mask);
 
 static struct hook stp_hook_create(const struct settings *,
                                    struct port_watcher *,
@@ -250,9 +255,6 @@ main(int argc, char *argv[])
     /* Initialize switch status hook. */
     hooks[n_hooks++] = switch_status_hook_create(&s, &switch_status);
 
-    /* Start controller discovery. */
-    discovery = s.discovery ? discovery_init(&s, switch_status) : NULL;
-
     /* Start listening for vlogconf requests. */
     retval = vlog_server_listen(NULL, NULL);
     if (retval) {
@@ -267,7 +269,7 @@ main(int argc, char *argv[])
 
     /* Connect to datapath. */
     local_rconn = rconn_create(0, s.max_backoff);
-    rconn_connect(local_rconn, s.nl_name);
+    rconn_connect(local_rconn, s.dp_name);
     switch_status_register_category(switch_status, "local",
                                     rconn_status_cb, local_rconn);
 
@@ -288,9 +290,12 @@ main(int argc, char *argv[])
 
     /* Set up hooks. */
     hooks[n_hooks++] = port_watcher_create(local_rconn, remote_rconn, &pw);
-    hooks[n_hooks++] = stp_hook_create(&s, pw, local_rconn, remote_rconn);
+    discovery = s.discovery ? discovery_init(&s, pw, switch_status) : NULL;
+    if (s.enable_stp) {
+        hooks[n_hooks++] = stp_hook_create(&s, pw, local_rconn, remote_rconn);
+    }
     if (s.in_band) {
-        hooks[n_hooks++] = in_band_hook_create(&s, switch_status,
+        hooks[n_hooks++] = in_band_hook_create(&s, switch_status, pw,
                                                remote_rconn);
     }
     if (s.fail_mode == FAIL_OPEN) {
@@ -448,8 +453,9 @@ static struct relay *
 relay_accept(const struct settings *s, struct pvconn *pvconn)
 {
     struct vconn *new_remote, *new_local;
-    char *nl_name_without_subscription;
     struct rconn *r1, *r2;
+    char *vconn_name;
+    int nl_index;
     int retval;
 
     new_remote = accept_vconn(pvconn);
@@ -457,26 +463,35 @@ relay_accept(const struct settings *s, struct pvconn *pvconn)
         return NULL;
     }
 
-    /* nl:123 or nl:123:1 opens a netlink connection to local datapath 123.  We
-     * only accept the former syntax in main().
-     *
-     * nl:123:0 opens a netlink connection to local datapath 123 without
-     * obtaining a subscription for ofp_packet_in or ofp_flow_expired
-     * messages.*/
-    nl_name_without_subscription = xasprintf("%s:0", s->nl_name);
-    retval = vconn_open(nl_name_without_subscription, OFP_VERSION, &new_local);
+    if (sscanf(s->dp_name, "nl:%d", &nl_index) == 1) {
+        /* nl:123 or nl:123:1 opens a netlink connection to local datapath 123.
+         * nl:123:0 opens a netlink connection to local datapath 123 without
+         * obtaining a subscription for ofp_packet_in or ofp_flow_expired
+         * messages.  That's what we want here; management connections should
+         * not receive those messages, at least by default. */
+        vconn_name = xasprintf("nl:%d:0", nl_index);
+    } else {
+        /* We don't have a way to specify not to subscribe to those messages
+         * for other transports.  (That's a defect: really this should be in
+         * the OpenFlow protocol, not the Netlink transport). */
+        VLOG_WARN_RL(&vrl, "new management connection will receive "
+                     "asynchronous messages");
+        vconn_name = xstrdup(s->dp_name);
+    }
+
+    retval = vconn_open(vconn_name, OFP_VERSION, &new_local);
     if (retval) {
         VLOG_ERR_RL(&vrl, "could not connect to %s (%s)",
-                    nl_name_without_subscription, strerror(retval));
+                    vconn_name, strerror(retval));
         vconn_close(new_remote);
-        free(nl_name_without_subscription);
+        free(vconn_name);
         return NULL;
     }
 
     /* Create and return relay. */
     r1 = rconn_create(0, 0);
-    rconn_connect_unreliably(r1, nl_name_without_subscription, new_local);
-    free(nl_name_without_subscription);
+    rconn_connect_unreliably(r1, vconn_name, new_local);
+    free(vconn_name);
 
     r2 = rconn_create(0, 0);
     rconn_connect_unreliably(r2, "passive", new_remote);
@@ -586,13 +601,21 @@ relay_destroy(struct relay *r)
 \f
 /* Port status watcher. */
 
-typedef void port_watcher_cb_func(uint16_t port_no,
+typedef void port_changed_cb_func(uint16_t port_no,
                                   const struct ofp_phy_port *old,
                                   const struct ofp_phy_port *new,
                                   void *aux);
 
 struct port_watcher_cb {
-    port_watcher_cb_func *function;
+    port_changed_cb_func *port_changed;
+    void *aux;
+};
+
+typedef void local_port_changed_cb_func(const struct ofp_phy_port *new,
+                                        void *aux);
+
+struct port_watcher_local_cb {
+    local_port_changed_cb_func *local_port_changed;
     void *aux;
 };
 
@@ -605,19 +628,25 @@ struct port_watcher {
     int n_txq;
     struct port_watcher_cb cbs[2];
     int n_cbs;
+    struct port_watcher_local_cb local_cbs[2];
+    int n_local_cbs;
+    char local_port_name[OFP_MAX_PORT_NAME_LEN + 1];
 };
 
 /* Returns the number of fields that differ from 'a' to 'b'. */
 static int
 opp_differs(const struct ofp_phy_port *a, const struct ofp_phy_port *b)
 {
-    BUILD_ASSERT_DECL(sizeof *a == 36); /* Trips when we add or remove fields. */
+    BUILD_ASSERT_DECL(sizeof *a == 48); /* Trips when we add or remove fields. */
     return ((a->port_no != b->port_no)
             + (memcmp(a->hw_addr, b->hw_addr, sizeof a->hw_addr) != 0)
             + (memcmp(a->name, b->name, sizeof a->name) != 0)
-            + (a->flags != b->flags)
-            + (a->speed != b->speed)
-            + (a->features != b->features));
+            + (a->config != b->config)
+            + (a->state != b->state)
+            + (a->curr != b->curr)
+            + (a->advertised != b->advertised)
+            + (a->supported != b->supported)
+            + (a->peer != b->peer));
 }
 
 static void
@@ -643,18 +672,69 @@ port_no_to_pw_idx(int port_no)
 }
 
 static void
-call_pw_callbacks(struct port_watcher *pw, int port_no,
-                  const struct ofp_phy_port *old,
-                  const struct ofp_phy_port *new)
+call_port_changed_callbacks(struct port_watcher *pw, int port_no,
+                            const struct ofp_phy_port *old,
+                            const struct ofp_phy_port *new)
 {
     if (opp_differs(old, new)) {
         int i;
         for (i = 0; i < pw->n_cbs; i++) {
-            pw->cbs[i].function(port_no, old, new, pw->cbs[i].aux);
+            port_changed_cb_func *port_changed = pw->cbs[i].port_changed;
+            (port_changed)(port_no, old, new, pw->cbs[i].aux);
+        }
+    }
+}
+
+static void
+get_port_name(const struct ofp_phy_port *port, char *name, size_t name_size)
+{
+    char *p;
+
+    memcpy(name, port->name, MIN(name_size, sizeof port->name));
+    name[name_size - 1] = '\0';
+    for (p = name; *p != '\0'; p++) {
+        if (*p < 32 || *p > 126) {
+            *p = '.';
         }
     }
 }
 
+static void
+call_local_port_changed_callbacks(struct port_watcher *pw)
+{
+    char name[OFP_MAX_PORT_NAME_LEN + 1];
+    const struct ofp_phy_port *port;
+    int i;
+
+    /* Pass the local port to the callbacks, if it exists.
+       Pass a null pointer if there is no local port. */
+    port = &pw->ports[port_no_to_pw_idx(OFPP_LOCAL)];
+    if (port->port_no != htons(OFPP_LOCAL)) {
+        port = NULL;
+    }
+
+    /* Log the name of the local port. */
+    if (port) {
+        get_port_name(port, name, sizeof name);
+    } else {
+        name[0] = '\0';
+    }
+    if (strcmp(pw->local_port_name, name)) {
+        if (name[0]) {
+            VLOG_WARN("Identified data path local port as \"%s\".", name);
+        } else {
+            VLOG_WARN("Data path has no local port.");
+        }
+        strcpy(pw->local_port_name, name);
+    }
+
+    /* Invoke callbacks. */
+    for (i = 0; i < pw->n_local_cbs; i++) {
+        local_port_changed_cb_func *cb = pw->local_cbs[i].local_port_changed;
+        (cb)(port, pw->local_cbs[i].aux);
+    }
+}
+
 static void
 update_phy_port(struct port_watcher *pw, struct ofp_phy_port *opp,
                 uint8_t reason, bool seen[OFPP_MAX + 1])
@@ -679,11 +759,11 @@ update_phy_port(struct port_watcher *pw, struct ofp_phy_port *opp,
     if (reason == OFPPR_DELETE) {
         memset(pw_opp, 0, sizeof *pw_opp);
         pw_opp->port_no = htons(OFPP_NONE);
-    } else if (reason == OFPPR_MOD || reason == OFPPR_ADD) {
+    } else if (reason == OFPPR_MODIFY || reason == OFPPR_ADD) {
         *pw_opp = *opp;
         sanitize_opp(pw_opp);
     }
-    call_pw_callbacks(pw, port_no, &old, pw_opp);
+    call_port_changed_callbacks(pw, port_no, &old, pw_opp);
 }
 
 static bool
@@ -707,7 +787,8 @@ port_watcher_local_packet_cb(struct relay *r, void *pw_)
         n_ports = ((msg->size - offsetof(struct ofp_switch_features, ports))
                    / sizeof *osf->ports);
         for (i = 0; i < n_ports; i++) {
-            update_phy_port(pw, &osf->ports[i], OFPPR_MOD, seen);
+            struct ofp_phy_port *opp = &osf->ports[i];
+            update_phy_port(pw, opp, OFPPR_MODIFY, seen);
         }
 
         /* Delete all the ports not included in the message. */
@@ -716,10 +797,15 @@ port_watcher_local_packet_cb(struct relay *r, void *pw_)
                 update_phy_port(pw, &pw->ports[i], OFPPR_DELETE, NULL);
             }
         }
+
+        call_local_port_changed_callbacks(pw);
     } else if (oh->type == OFPT_PORT_STATUS
                && msg->size >= sizeof(struct ofp_port_status)) {
         struct ofp_port_status *ops = msg->data;
         update_phy_port(pw, &ops->desc, ops->reason, NULL);
+        if (ops->desc.port_no == htons(OFPP_LOCAL)) {
+            call_local_port_changed_callbacks(pw);
+        }
     }
     return false;
 }
@@ -734,15 +820,18 @@ port_watcher_remote_packet_cb(struct relay *r, void *pw_)
     if (oh->type == OFPT_PORT_MOD
         && msg->size >= sizeof(struct ofp_port_mod)) {
         struct ofp_port_mod *opm = msg->data;
-        uint16_t port_no = ntohs(opm->desc.port_no);
+        uint16_t port_no = ntohs(opm->port_no);
         int idx = port_no_to_pw_idx(port_no);
         if (idx >= 0) {
             struct ofp_phy_port *pw_opp = &pw->ports[idx];
             if (pw_opp->port_no != htons(OFPP_NONE)) {
                 struct ofp_phy_port old = *pw_opp;
-                pw_opp->flags = ((pw_opp->flags & ~opm->mask)
-                                 | (opm->desc.flags & opm->mask));
-                call_pw_callbacks(pw, port_no, &old, pw_opp);
+                pw_opp->config = ((pw_opp->config & ~opm->mask)
+                                 | (opm->config & opm->mask));
+                call_port_changed_callbacks(pw, port_no, &old, pw_opp);
+                if (pw_opp->port_no == htons(OFPP_LOCAL)) {
+                    call_local_port_changed_callbacks(pw);
+                }
             }
         }
     }
@@ -754,7 +843,9 @@ port_watcher_periodic_cb(void *pw_)
 {
     struct port_watcher *pw = pw_;
 
-    if (!pw->got_feature_reply && time_now() >= pw->last_feature_request + 5) {
+    if (!pw->got_feature_reply
+        && time_now() >= pw->last_feature_request + 5
+        && rconn_is_connected(pw->local_rconn)) {
         struct ofpbuf *b;
         make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &b);
         rconn_send_with_limit(pw->local_rconn, b, &pw->n_txq, 1);
@@ -762,6 +853,19 @@ port_watcher_periodic_cb(void *pw_)
     }
 }
 
+static void
+port_watcher_wait_cb(void *pw_)
+{
+    struct port_watcher *pw = pw_;
+    if (!pw->got_feature_reply && rconn_is_connected(pw->local_rconn)) {
+        if (pw->last_feature_request != TIME_MIN) {
+            poll_timer_wait(pw->last_feature_request + 5 - time_now());
+        } else {
+            poll_immediate_wake();
+        }
+    }
+}
+
 static void
 put_duplexes(struct ds *ds, const char *name, uint32_t features,
              uint32_t hd_bit, uint32_t fd_bit)
@@ -777,6 +881,32 @@ put_duplexes(struct ds *ds, const char *name, uint32_t features,
     }
 }
 
+static void
+put_features(struct ds *ds, const char *name, uint32_t features)
+{
+    if (features & (OFPPF_10MB_HD | OFPPF_10MB_FD
+                    | OFPPF_100MB_HD | OFPPF_100MB_FD
+                    | OFPPF_1GB_HD | OFPPF_1GB_FD | OFPPF_10GB_FD)) {
+        ds_put_cstr(ds, name);
+        put_duplexes(ds, "10M", features, OFPPF_10MB_HD, OFPPF_10MB_FD);
+        put_duplexes(ds, "100M", features,
+                     OFPPF_100MB_HD, OFPPF_100MB_FD);
+        put_duplexes(ds, "1G", features, OFPPF_100MB_HD, OFPPF_100MB_FD);
+        if (features & OFPPF_10GB_FD) {
+            ds_put_cstr(ds, " 10G");
+        }
+        if (features & OFPPF_AUTONEG) {
+            ds_put_cstr(ds, " AUTO_NEG");
+        }
+        if (features & OFPPF_PAUSE) {
+            ds_put_cstr(ds, " PAUSE");
+        }
+        if (features & OFPPF_PAUSE_ASYM) {
+            ds_put_cstr(ds, " PAUSE_ASYM");
+        }
+    }
+}
+
 static void
 log_port_status(uint16_t port_no,
                 const struct ofp_phy_port *old,
@@ -786,10 +916,12 @@ log_port_status(uint16_t port_no,
     if (VLOG_IS_DBG_ENABLED()) {
         bool was_enabled = old->port_no != htons(OFPP_NONE);
         bool now_enabled = new->port_no != htons(OFPP_NONE);
-        uint32_t features = ntohl(new->features);
+        uint32_t curr = ntohl(new->curr);
+        uint32_t supported = ntohl(new->supported);
         struct ds ds;
 
-        if (old->flags != new->flags && opp_differs(old, new) == 1) {
+        if (((old->config != new->config) || (old->state != new->state))
+                && opp_differs(old, new) == 1) {
             /* Don't care if only flags changed. */
             return;
         }
@@ -797,20 +929,11 @@ log_port_status(uint16_t port_no,
         ds_init(&ds);
         ds_put_format(&ds, "\"%s\", "ETH_ADDR_FMT, new->name,
                       ETH_ADDR_ARGS(new->hw_addr));
-        if (ntohl(new->speed)) {
-            ds_put_format(&ds, ", speed %"PRIu32, ntohl(new->speed));
-        }
-        if (features & (OFPPF_10MB_HD | OFPPF_10MB_FD
-                        | OFPPF_100MB_HD | OFPPF_100MB_FD
-                        | OFPPF_1GB_HD | OFPPF_1GB_FD | OFPPF_10GB_FD)) {
-            ds_put_cstr(&ds, ", supports");
-            put_duplexes(&ds, "10M", features, OFPPF_10MB_HD, OFPPF_10MB_FD);
-            put_duplexes(&ds, "100M", features,
-                         OFPPF_100MB_HD, OFPPF_100MB_FD);
-            put_duplexes(&ds, "1G", features, OFPPF_100MB_HD, OFPPF_100MB_FD);
-            if (features & OFPPF_10GB_FD) {
-                ds_put_cstr(&ds, " 10G");
-            }
+        if (curr) {
+            put_features(&ds, ", current", curr);
+        }
+        if (supported) {
+            put_features(&ds, ", supports", supported);
         }
         if (was_enabled != now_enabled) {
             if (now_enabled) {
@@ -827,25 +950,37 @@ log_port_status(uint16_t port_no,
 
 static void
 port_watcher_register_callback(struct port_watcher *pw,
-                               port_watcher_cb_func *function,
+                               port_changed_cb_func *port_changed,
                                void *aux)
 {
     assert(pw->n_cbs < ARRAY_SIZE(pw->cbs));
-    pw->cbs[pw->n_cbs].function = function;
+    pw->cbs[pw->n_cbs].port_changed = port_changed;
     pw->cbs[pw->n_cbs].aux = aux;
     pw->n_cbs++;
 }
 
+static void
+port_watcher_register_local_port_callback(struct port_watcher *pw,
+                                          local_port_changed_cb_func *cb,
+                                          void *aux)
+{
+    assert(pw->n_local_cbs < ARRAY_SIZE(pw->local_cbs));
+    pw->local_cbs[pw->n_local_cbs].local_port_changed = cb;
+    pw->local_cbs[pw->n_local_cbs].aux = aux;
+    pw->n_local_cbs++;
+}
+
 static uint32_t
-port_watcher_get_flags(const struct port_watcher *pw, int port_no)
+port_watcher_get_config(const struct port_watcher *pw, int port_no)
 {
     int idx = port_no_to_pw_idx(port_no);
-    return idx >= 0 ? ntohl(pw->ports[idx].flags) : 0;
+    return idx >= 0 ? ntohl(pw->ports[idx].config) : 0;
 }
 
 static void
-port_watcher_set_flags(struct port_watcher *pw,
-                       int port_no, uint32_t flags, uint32_t mask)
+port_watcher_set_flags(struct port_watcher *pw, int port_no, 
+                       uint32_t config, uint32_t c_mask,
+                       uint32_t state, uint32_t s_mask)
 {
     struct ofp_phy_port old;
     struct ofp_phy_port *p;
@@ -860,24 +995,29 @@ port_watcher_set_flags(struct port_watcher *pw,
     }
 
     p = &pw->ports[idx];
-    if (!((ntohl(p->flags) ^ flags) & mask)) {
+    if (!((ntohl(p->state) ^ state) & s_mask) 
+            && (!((ntohl(p->config) ^ config) & c_mask))) {
         return;
     }
     old = *p;
 
     /* Update our idea of the flags. */
-    p->flags = htonl((ntohl(p->flags) & ~mask) | (flags & mask));
-    call_pw_callbacks(pw, port_no, &old, p);
+    p->config = htonl((ntohl(p->config) & ~c_mask) | (config & c_mask));
+    p->state = htonl((ntohl(p->state) & ~s_mask) | (state & s_mask));
+    call_port_changed_callbacks(pw, port_no, &old, p);
 
     /* Change the flags in the datapath. */
     opm = make_openflow(sizeof *opm, OFPT_PORT_MOD, &b);
-    opm->mask = htonl(mask);
-    opm->desc = *p;
+    opm->port_no = p->port_no;
+    memcpy(opm->hw_addr, p->hw_addr, OFP_ETH_ALEN);
+    opm->config = p->config;
+    opm->mask = htonl(c_mask);
+    opm->advertise = htonl(0);
     rconn_send(pw->local_rconn, b, NULL);
 
     /* Notify the controller that the flags changed. */
     ops = make_openflow(sizeof *ops, OFPT_PORT_STATUS, &b);
-    ops->reason = OFPPR_MOD;
+    ops->reason = OFPPR_MODIFY;
     ops->desc = *p;
     rconn_send(pw->remote_rconn, b, NULL);
 }
@@ -902,10 +1042,12 @@ port_watcher_create(struct rconn *local_rconn, struct rconn *remote_rconn,
     for (i = 0; i < OFPP_MAX; i++) {
         pw->ports[i].port_no = htons(OFPP_NONE);
     }
+    pw->local_port_name[0] = '\0';
     port_watcher_register_callback(pw, log_port_status, NULL);
     return make_hook(port_watcher_local_packet_cb,
                      port_watcher_remote_packet_cb,
-                     port_watcher_periodic_cb, NULL, pw);
+                     port_watcher_periodic_cb,
+                     port_watcher_wait_cb, pw);
 }
 \f
 /* Spanning tree protocol. */
@@ -919,7 +1061,6 @@ struct stp_data {
     struct port_watcher *pw;
     struct rconn *local_rconn;
     struct rconn *remote_rconn;
-    uint8_t dpid[ETH_ADDR_LEN];
     long long int last_tick_256ths;
     int n_txq;
 };
@@ -927,6 +1068,8 @@ struct stp_data {
 static bool
 stp_local_packet_cb(struct relay *r, void *stp_)
 {
+    struct ofpbuf *msg = r->halves[HALF_LOCAL].rxbuf;
+    struct ofp_header *oh;
     struct stp_data *stp = stp_;
     struct ofp_packet_in *opi;
     struct eth_header *eth;
@@ -935,6 +1078,14 @@ stp_local_packet_cb(struct relay *r, void *stp_)
     uint16_t port_no;
     struct flow flow;
 
+    oh = msg->data;
+    if (oh->type == OFPT_FEATURES_REPLY
+        && msg->size >= offsetof(struct ofp_switch_features, ports)) {
+        struct ofp_switch_features *osf = msg->data;
+        osf->capabilities |= htonl(OFPC_STP);
+        return false;
+    }
+
     if (!get_ofp_packet_eth_header(r, &opi, &eth)
         || !eth_addr_equals(eth->eth_dst, stp_eth_addr)) {
         return false;
@@ -945,7 +1096,7 @@ stp_local_packet_cb(struct relay *r, void *stp_)
         /* STP only supports 255 ports. */
         return false;
     }
-    if (port_watcher_get_flags(stp->pw, port_no) & OFPPFL_NO_STP) {
+    if (port_watcher_get_config(stp->pw, port_no) & OFPPC_NO_STP) {
         /* We're not doing STP on this port. */
         return false;
     }
@@ -1008,39 +1159,41 @@ stp_periodic_cb(void *stp_)
 
     while (stp_get_changed_port(stp->stp, &p)) {
         int port_no = stp_port_no(p);
-        enum stp_state state = stp_port_get_state(p);
+        enum stp_state s_state = stp_port_get_state(p);
 
-        if (state != STP_DISABLED) {
+        if (s_state != STP_DISABLED) {
             VLOG_WARN("STP: Port %d entered %s state",
-                      port_no, stp_state_name(state));
+                      port_no, stp_state_name(s_state));
         }
-        if (!(port_watcher_get_flags(stp->pw, port_no) & OFPPFL_NO_STP)) {
-            uint32_t flags;
-            switch (state) {
+        if (!(port_watcher_get_config(stp->pw, port_no) & OFPPC_NO_STP)) {
+            uint32_t p_config = 0;
+            uint32_t p_state;
+            switch (s_state) {
             case STP_LISTENING:
-                flags = OFPPFL_STP_LISTEN;
+                p_state = OFPPS_STP_LISTEN;
                 break;
             case STP_LEARNING:
-                flags = OFPPFL_STP_LEARN;
+                p_state = OFPPS_STP_LEARN;
                 break;
             case STP_DISABLED:
             case STP_FORWARDING:
-                flags = OFPPFL_STP_FORWARD;
+                p_state = OFPPS_STP_FORWARD;
                 break;
             case STP_BLOCKING:
-                flags = OFPPFL_STP_BLOCK;
+                p_state = OFPPS_STP_BLOCK;
                 break;
             default:
                 VLOG_DBG_RL(&vrl, "STP: Port %d has bad state %x",
-                            port_no, state);
-                flags = OFPPFL_STP_FORWARD;
+                            port_no, s_state);
+                p_state = OFPPS_STP_FORWARD;
                 break;
             }
-            if (!stp_forward_in_state(state)) {
-                flags |= OFPPFL_NO_FLOOD;
+            if (!stp_forward_in_state(s_state)) {
+                p_config = OFPPC_NO_FLOOD;
             }
-            port_watcher_set_flags(stp->pw, port_no, flags,
-                                   OFPPFL_STP_MASK | OFPPFL_NO_FLOOD);
+            port_watcher_set_flags(stp->pw, port_no, 
+                                   p_config, OFPPC_NO_FLOOD,
+                                   p_state, OFPPS_STP_MASK);
         } else {
             /* We don't own those flags. */
         }
@@ -1082,8 +1235,17 @@ send_bpdu(const void *bpdu, size_t bpdu_size, int port_no, void *stp_)
     rconn_send_with_limit(stp->local_rconn, opo, &stp->n_txq, OFPP_MAX);
 }
 
+static bool
+stp_is_port_supported(uint16_t port_no)
+{
+    /* We should be able to support STP on all possible OpenFlow physical
+     * ports.  (But we don't support STP on OFPP_LOCAL.)  */
+    BUILD_ASSERT_DECL(STP_MAX_PORTS >= OFPP_MAX);
+    return port_no < STP_MAX_PORTS;
+}
+
 static void
-stp_port_watcher_cb(uint16_t port_no,
+stp_port_changed_cb(uint16_t port_no,
                     const struct ofp_phy_port *old,
                     const struct ofp_phy_port *new,
                     void *stp_)
@@ -1091,19 +1253,37 @@ stp_port_watcher_cb(uint16_t port_no,
     struct stp_data *stp = stp_;
     struct stp_port *p;
 
-    /* STP only supports a maximum of 255 ports, one less than OpenFlow.  We
-     * don't support STP on OFPP_LOCAL, either.  */
-    if (port_no >= STP_MAX_PORTS) {
+    if (!stp_is_port_supported(port_no)) {
         return;
     }
 
     p = stp_get_port(stp->stp, port_no);
     if (new->port_no == htons(OFPP_NONE)
-        || new->flags & htonl(OFPPFL_NO_STP)) {
+        || new->config & htonl(OFPPC_NO_STP | OFPPC_PORT_DOWN)
+        || new->state & htonl(OFPPS_LINK_DOWN)) {
         stp_port_disable(p);
     } else {
+        int speed = 0;
         stp_port_enable(p);
-        stp_port_set_speed(p, new->speed);
+        if (new->curr & (OFPPF_10MB_HD | OFPPF_10MB_FD)) {
+            speed = 10;
+        } else if (new->curr & (OFPPF_100MB_HD | OFPPF_100MB_FD)) {
+            speed = 100;
+        } else if (new->curr & (OFPPF_1GB_HD | OFPPF_1GB_FD)) {
+            speed = 1000;
+        } else if (new->curr & OFPPF_100MB_FD) {
+            speed = 10000;
+        }
+        stp_port_set_speed(p, speed);
+    }
+}
+
+static void
+stp_local_port_changed_cb(const struct ofp_phy_port *port, void *stp_)
+{
+    struct stp_data *stp = stp_;
+    if (port) {
+        stp_set_bridge_id(stp->stp, eth_addr_to_uint64(port->hw_addr));
     }
 }
 
@@ -1112,26 +1292,19 @@ stp_hook_create(const struct settings *s, struct port_watcher *pw,
                 struct rconn *local, struct rconn *remote)
 {
     uint8_t dpid[ETH_ADDR_LEN];
-    struct netdev *netdev;
     struct stp_data *stp;
-    int retval;
-
-    retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE, &netdev);
-    if (retval) {
-        ofp_fatal(retval, "Could not open %s device", s->of_name);
-    }
-    memcpy(dpid, netdev_get_etheraddr(netdev), ETH_ADDR_LEN);
-    netdev_close(netdev);
 
     stp = xcalloc(1, sizeof *stp);
+    eth_addr_random(dpid);
     stp->stp = stp_create("stp", eth_addr_to_uint64(dpid), send_bpdu, stp);
     stp->pw = pw;
-    memcpy(stp->dpid, dpid, ETH_ADDR_LEN);
     stp->local_rconn = local;
     stp->remote_rconn = remote;
     stp->last_tick_256ths = time_256ths();
 
-    port_watcher_register_callback(pw, stp_port_watcher_cb, stp);
+    port_watcher_register_callback(pw, stp_port_changed_cb, stp);
+    port_watcher_register_local_port_callback(pw, stp_local_port_changed_cb,
+                                              stp);
     return make_hook(stp_local_packet_cb, NULL,
                      stp_periodic_cb, stp_wait_cb, stp);
 }
@@ -1143,7 +1316,6 @@ struct in_band_data {
     struct mac_learning *ml;
     struct netdev *of_device;
     struct rconn *controller;
-    uint8_t mac[ETH_ADDR_LEN];
     int n_queued;
 };
 
@@ -1170,11 +1342,11 @@ get_controller_mac(struct in_band_data *in_band)
 
         /* Look up MAC address. */
         memset(mac, 0, sizeof mac);
-        if (ip) {
+        if (ip && in_band->of_device) {
             int retval = netdev_arp_lookup(in_band->of_device, ip, mac);
             if (retval) {
-                VLOG_DBG("cannot look up controller hw address ("IP_FMT"): %s",
-                         IP_ARGS(&ip), strerror(retval));
+                VLOG_DBG_RL(&vrl, "cannot look up controller hw address "
+                            "("IP_FMT"): %s", IP_ARGS(&ip), strerror(retval));
             }
         }
         have_mac = !eth_addr_is_zero(mac);
@@ -1232,7 +1404,7 @@ in_band_local_packet_cb(struct relay *r, void *in_band_)
     uint16_t in_port;
     int out_port;
 
-    if (!get_ofp_packet_eth_header(r, &opi, &eth)) {
+    if (!get_ofp_packet_eth_header(r, &opi, &eth) || !in_band->of_device) {
         return false;
     }
     in_port = ntohs(opi->in_port);
@@ -1241,7 +1413,8 @@ in_band_local_packet_cb(struct relay *r, void *in_band_)
     if (in_port == OFPP_LOCAL) {
         /* Sent by secure channel. */
         out_port = mac_learning_lookup(in_band->ml, eth->eth_dst);
-    } else if (eth_addr_equals(eth->eth_dst, in_band->mac)) {
+    } else if (eth_addr_equals(eth->eth_dst,
+                               netdev_get_etheraddr(in_band->of_device))) {
         /* Sent to secure channel. */
         out_port = OFPP_LOCAL;
         in_band_learn_mac(in_band, in_port, eth->eth_src);
@@ -1313,21 +1486,23 @@ in_band_status_cb(struct status_reply *sr, void *in_band_)
     uint32_t controller_ip;
     const uint8_t *controller_mac;
 
-    if (netdev_get_in4(in_band->of_device, &local_ip)) {
-        status_reply_put(sr, "local-ip="IP_FMT, IP_ARGS(&local_ip.s_addr));
-    }
-    status_reply_put(sr, "local-mac="ETH_ADDR_FMT,
-                     ETH_ADDR_ARGS(in_band->mac));
+    if (in_band->of_device) {
+        const uint8_t *mac = netdev_get_etheraddr(in_band->of_device);
+        if (netdev_get_in4(in_band->of_device, &local_ip)) {
+            status_reply_put(sr, "local-ip="IP_FMT, IP_ARGS(&local_ip.s_addr));
+        }
+        status_reply_put(sr, "local-mac="ETH_ADDR_FMT, ETH_ADDR_ARGS(mac));
 
-    controller_ip = rconn_get_ip(in_band->controller);
-    if (controller_ip) {
-        status_reply_put(sr, "controller-ip="IP_FMT,
-                      IP_ARGS(&controller_ip));
-    }
-    controller_mac = get_controller_mac(in_band);
-    if (controller_mac) {
-        status_reply_put(sr, "controller-mac="ETH_ADDR_FMT,
-                      ETH_ADDR_ARGS(controller_mac));
+        controller_ip = rconn_get_ip(in_band->controller);
+        if (controller_ip) {
+            status_reply_put(sr, "controller-ip="IP_FMT,
+                             IP_ARGS(&controller_ip));
+        }
+        controller_mac = get_controller_mac(in_band);
+        if (controller_mac) {
+            status_reply_put(sr, "controller-mac="ETH_ADDR_FMT,
+                             ETH_ADDR_ARGS(controller_mac));
+        }
     }
 }
 
@@ -1339,25 +1514,46 @@ get_ofp_packet_payload(struct ofp_packet_in *opi, struct ofpbuf *payload)
                                                          data);
 }
 
+static void
+in_band_local_port_cb(const struct ofp_phy_port *port, void *in_band_)
+{
+    struct in_band_data *in_band = in_band_;
+    if (port) {
+        char name[sizeof port->name + 1];
+        get_port_name(port, name, sizeof name);
+
+        if (!in_band->of_device
+            || strcmp(netdev_get_name(in_band->of_device), name))
+        {
+            int error;
+            netdev_close(in_band->of_device);
+            error = netdev_open(name, NETDEV_ETH_TYPE_NONE,
+                                &in_band->of_device);
+            if (error) {
+                VLOG_ERR("failed to open in-band control network device "
+                         "\"%s\": %s", name, strerror(errno));
+            }
+        }
+    } else {
+        netdev_close(in_band->of_device);
+        in_band->of_device = NULL;
+    }
+}
+
 static struct hook
 in_band_hook_create(const struct settings *s, struct switch_status *ss,
-                    struct rconn *remote)
+                    struct port_watcher *pw, struct rconn *remote)
 {
     struct in_band_data *in_band;
-    int retval;
 
     in_band = xcalloc(1, sizeof *in_band);
     in_band->s = s;
     in_band->ml = mac_learning_create();
-    retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE,
-                         &in_band->of_device);
-    if (retval) {
-        ofp_fatal(retval, "Could not open %s device", s->of_name);
-    }
-    memcpy(in_band->mac, netdev_get_etheraddr(in_band->of_device),
-           ETH_ADDR_LEN);
+    in_band->of_device = NULL;
     in_band->controller = remote;
     switch_status_register_category(ss, "in-band", in_band_status_cb, in_band);
+    port_watcher_register_local_port_callback(pw, in_band_local_port_cb,
+                                              in_band);
     return make_hook(in_band_local_packet_cb, NULL, NULL, NULL, in_band);
 }
 \f
@@ -1383,7 +1579,7 @@ fail_open_periodic_cb(void *fail_open_)
     if (time_now() < fail_open->boot_deadline) {
         return;
     }
-    disconn_secs = rconn_disconnected_duration(fail_open->remote_rconn);
+    disconn_secs = rconn_failure_duration(fail_open->remote_rconn);
     open = disconn_secs >= fail_open->s->probe_interval * 3;
     if (open != (fail_open->lswitch != NULL)) {
         if (!open) {
@@ -1424,7 +1620,7 @@ fail_open_status_cb(struct status_reply *sr, void *fail_open_)
     struct fail_open_data *fail_open = fail_open_;
     const struct settings *s = fail_open->s;
     int trigger_duration = s->probe_interval * 3;
-    int cur_duration = rconn_disconnected_duration(fail_open->remote_rconn);
+    int cur_duration = rconn_failure_duration(fail_open->remote_rconn);
 
     status_reply_put(sr, "trigger-duration=%d", trigger_duration);
     status_reply_put(sr, "current-duration=%d", cur_duration);
@@ -1443,7 +1639,9 @@ fail_open_hook_create(const struct settings *s, struct switch_status *ss,
     fail_open->remote_rconn = remote_rconn;
     fail_open->lswitch = NULL;
     fail_open->boot_deadline = time_now() + s->probe_interval * 3;
-    fail_open->boot_deadline += STP_EXTRA_BOOT_TIME;
+    if (s->enable_stp) {
+        fail_open->boot_deadline += STP_EXTRA_BOOT_TIME;
+    }
     switch_status_register_category(ss, "fail-open",
                                     fail_open_status_cb, fail_open);
     return make_hook(fail_open_local_packet_cb, NULL,
@@ -1842,74 +2040,108 @@ discovery_status_cb(struct status_reply *sr, void *d_)
 
     status_reply_put(sr, "accept-remote=%s", d->s->accept_controller_re);
     status_reply_put(sr, "n-changes=%d", d->n_changes);
-    status_reply_put(sr, "state=%s", dhclient_get_state(d->dhcp));
-    status_reply_put(sr, "state-elapsed=%u",
-                     dhclient_get_state_elapsed(d->dhcp));
-    if (dhclient_is_bound(d->dhcp)) {
-        uint32_t ip = dhclient_get_ip(d->dhcp);
-        uint32_t netmask = dhclient_get_netmask(d->dhcp);
-        uint32_t router = dhclient_get_router(d->dhcp);
+    if (d->dhcp) {
+        status_reply_put(sr, "state=%s", dhclient_get_state(d->dhcp));
+        status_reply_put(sr, "state-elapsed=%u",
+                         dhclient_get_state_elapsed(d->dhcp)); 
+        if (dhclient_is_bound(d->dhcp)) {
+            uint32_t ip = dhclient_get_ip(d->dhcp);
+            uint32_t netmask = dhclient_get_netmask(d->dhcp);
+            uint32_t router = dhclient_get_router(d->dhcp);
+
+            const struct dhcp_msg *cfg = dhclient_get_config(d->dhcp);
+            uint32_t dns_server;
+            char *domain_name;
+            int i;
+
+            status_reply_put(sr, "ip="IP_FMT, IP_ARGS(&ip));
+            status_reply_put(sr, "netmask="IP_FMT, IP_ARGS(&netmask));
+            if (router) {
+                status_reply_put(sr, "router="IP_FMT, IP_ARGS(&router));
+            }
 
-        const struct dhcp_msg *cfg = dhclient_get_config(d->dhcp);
-        uint32_t dns_server;
-        char *domain_name;
-        int i;
+            for (i = 0; dhcp_msg_get_ip(cfg, DHCP_CODE_DNS_SERVER, i,
+                                        &dns_server);
+                 i++) {
+                status_reply_put(sr, "dns%d="IP_FMT, i, IP_ARGS(&dns_server));
+            }
 
-        status_reply_put(sr, "ip="IP_FMT, IP_ARGS(&ip));
-        status_reply_put(sr, "netmask="IP_FMT, IP_ARGS(&netmask));
-        if (router) {
-            status_reply_put(sr, "router="IP_FMT, IP_ARGS(&router));
+            domain_name = dhcp_msg_get_string(cfg, DHCP_CODE_DOMAIN_NAME);
+            if (domain_name) {
+                status_reply_put(sr, "domain=%s", domain_name);
+                free(domain_name);
+            }
+
+            status_reply_put(sr, "lease-remaining=%u",
+                             dhclient_get_lease_remaining(d->dhcp));
         }
+    }
+}
 
-        for (i = 0; dhcp_msg_get_ip(cfg, DHCP_CODE_DNS_SERVER, i, &dns_server);
-             i++) {
-            status_reply_put(sr, "dns%d="IP_FMT, i, IP_ARGS(&dns_server));
+static void
+discovery_local_port_cb(const struct ofp_phy_port *port, void *d_) 
+{
+    struct discovery *d = d_;
+    if (port) {
+        char name[OFP_MAX_PORT_NAME_LEN + 1];
+        struct netdev *netdev;
+        int retval;
+
+        /* Check that this was really a change. */
+        get_port_name(port, name, sizeof name);
+        if (d->dhcp && !strcmp(netdev_get_name(dhclient_get_netdev(d->dhcp)),
+                               name)) {
+            return;
         }
 
-        domain_name = dhcp_msg_get_string(cfg, DHCP_CODE_DOMAIN_NAME);
-        if (domain_name) {
-            status_reply_put(sr, "domain=%s", domain_name);
-            free(domain_name);
+        /* Destroy current DHCP client. */
+        dhclient_destroy(d->dhcp);
+        d->dhcp = NULL;
+
+        /* Bring local network device up. */
+        retval = netdev_open(name, NETDEV_ETH_TYPE_NONE, &netdev);
+        if (retval) {
+            VLOG_ERR("Could not open %s device, discovery disabled: %s",
+                     name, strerror(retval));
+            return;
+        }
+        retval = netdev_turn_flags_on(netdev, NETDEV_UP, true);
+        if (retval) {
+            VLOG_ERR("Could not bring %s device up, discovery disabled: %s",
+                     name, strerror(retval));
+            return;
         }
+        netdev_close(netdev);
 
-        status_reply_put(sr, "lease-remaining=%u",
-                         dhclient_get_lease_remaining(d->dhcp));
+        /* Initialize DHCP client. */
+        retval = dhclient_create(name, modify_dhcp_request,
+                                 validate_dhcp_offer, (void *) d->s, &d->dhcp);
+        if (retval) {
+            VLOG_ERR("Failed to initialize DHCP client, "
+                     "discovery disabled: %s", strerror(retval));
+            return;
+        }
+        dhclient_init(d->dhcp, 0);
+    } else {
+        dhclient_destroy(d->dhcp);
+        d->dhcp = NULL;
     }
 }
 
+
 static struct discovery *
-discovery_init(const struct settings *s, struct switch_status *ss)
+discovery_init(const struct settings *s, struct port_watcher *pw,
+               struct switch_status *ss)
 {
-    struct netdev *netdev;
     struct discovery *d;
-    struct dhclient *dhcp;
-    int retval;
-
-    /* Bring ofX network device up. */
-    retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE, &netdev);
-    if (retval) {
-        ofp_fatal(retval, "Could not open %s device", s->of_name);
-    }
-    retval = netdev_turn_flags_on(netdev, NETDEV_UP, true);
-    if (retval) {
-        ofp_fatal(retval, "Could not bring %s device up", s->of_name);
-    }
-    netdev_close(netdev);
-
-    /* Initialize DHCP client. */
-    retval = dhclient_create(s->of_name, modify_dhcp_request,
-                             validate_dhcp_offer, (void *) s, &dhcp);
-    if (retval) {
-        ofp_fatal(retval, "Failed to initialize DHCP client");
-    }
-    dhclient_init(dhcp, 0);
 
     d = xmalloc(sizeof *d);
     d->s = s;
-    d->dhcp = dhcp;
+    d->dhcp = NULL;
     d->n_changes = 0;
 
     switch_status_register_category(ss, "discovery", discovery_status_cb, d);
+    port_watcher_register_local_port_callback(pw, discovery_local_port_cb, d);
 
     return d;
 }
@@ -1917,12 +2149,19 @@ discovery_init(const struct settings *s, struct switch_status *ss)
 static void
 discovery_question_connectivity(struct discovery *d)
 {
-    dhclient_force_renew(d->dhcp, 15);
+    if (d->dhcp) {
+        dhclient_force_renew(d->dhcp, 15); 
+    }
 }
 
 static bool
 discovery_run(struct discovery *d, char **controller_name)
 {
+    if (!d->dhcp) {
+        *controller_name = NULL;
+        return true;
+    }
+
     dhclient_run(d->dhcp);
     if (!dhclient_changed(d->dhcp)) {
         return false;
@@ -1951,7 +2190,9 @@ discovery_run(struct discovery *d, char **controller_name)
 static void
 discovery_wait(struct discovery *d)
 {
-    dhclient_wait(d->dhcp);
+    if (d->dhcp) {
+        dhclient_wait(d->dhcp); 
+    }
 }
 
 static void
@@ -1994,7 +2235,11 @@ parse_options(int argc, char *argv[], struct settings *s)
         OPT_MAX_BACKOFF,
         OPT_RATE_LIMIT,
         OPT_BURST_LIMIT,
-        OPT_BOOTSTRAP_CA_CERT
+        OPT_BOOTSTRAP_CA_CERT,
+        OPT_STP,
+        OPT_NO_STP,
+        OPT_OUT_OF_BAND,
+        OPT_IN_BAND
     };
     static struct option long_options[] = {
         {"accept-vconn", required_argument, 0, OPT_ACCEPT_VCONN},
@@ -2007,6 +2252,10 @@ parse_options(int argc, char *argv[], struct settings *s)
         {"monitor",     required_argument, 0, 'm'},
         {"rate-limit",  optional_argument, 0, OPT_RATE_LIMIT},
         {"burst-limit", required_argument, 0, OPT_BURST_LIMIT},
+        {"stp",         no_argument, 0, OPT_STP},
+        {"no-stp",      no_argument, 0, OPT_NO_STP},
+        {"out-of-band", no_argument, 0, OPT_OUT_OF_BAND},
+        {"in-band",     no_argument, 0, OPT_IN_BAND},
         {"detach",      no_argument, 0, 'D'},
         {"force",       no_argument, 0, 'f'},
         {"pidfile",     optional_argument, 0, 'P'},
@@ -2033,6 +2282,8 @@ parse_options(int argc, char *argv[], struct settings *s)
     s->update_resolv_conf = true;
     s->rate_limit = 0;
     s->burst_limit = 0;
+    s->enable_stp = false;
+    s->in_band = true;
     for (;;) {
         int c;
 
@@ -2107,6 +2358,22 @@ parse_options(int argc, char *argv[], struct settings *s)
             }
             break;
 
+        case OPT_STP:
+            s->enable_stp = true;
+            break;
+
+        case OPT_NO_STP:
+            s->enable_stp = false;
+            break;
+
+        case OPT_OUT_OF_BAND:
+            s->in_band = false;
+            break;
+
+        case OPT_IN_BAND:
+            s->in_band = true;
+            break;
+
         case 'D':
             set_detach();
             break;
@@ -2171,14 +2438,7 @@ parse_options(int argc, char *argv[], struct settings *s)
     }
 
     /* Local and remote vconns. */
-    s->nl_name = argv[0];
-    if (strncmp(s->nl_name, "nl:", 3)
-        || strlen(s->nl_name) < 4
-        || s->nl_name[strspn(s->nl_name + 3, "0123456789") + 3]) {
-        ofp_fatal(0, "%s: argument is not of the form \"nl:DP_IDX\"",
-                  s->nl_name);
-    }
-    s->of_name = xasprintf("of%s", s->nl_name + 3);
+    s->dp_name = argv[0];
     s->controller_name = argc > 1 ? xstrdup(argv[1]) : NULL;
 
     /* Set accept_controller_regex. */
@@ -2197,29 +2457,8 @@ parse_options(int argc, char *argv[], struct settings *s)
 
     /* Mode of operation. */
     s->discovery = s->controller_name == NULL;
-    if (s->discovery) {
-        s->in_band = true;
-    } else {
-        enum netdev_flags flags;
-        struct netdev *netdev;
-
-        retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE, &netdev);
-        if (retval) {
-            ofp_fatal(retval, "Could not open %s device", s->of_name);
-        }
-
-        retval = netdev_get_flags(netdev, &flags);
-        if (retval) {
-            ofp_fatal(retval, "Could not get flags for %s device", s->of_name);
-        }
-
-        s->in_band = (flags & NETDEV_UP) != 0;
-        if (s->in_band && netdev_get_in6(netdev, NULL)) {
-            VLOG_WARN("Ignoring IPv6 address on %s device: IPv6 not supported",
-                      s->of_name);
-        }
-
-        netdev_close(netdev);
+    if (s->discovery && !s->in_band) {
+        ofp_fatal(0, "Cannot perform discovery with out-of-band control");
     }
 
     /* Rate limiting. */
@@ -2261,6 +2500,9 @@ usage(void)
            "                          (a passive OpenFlow connection method)\n"
            "  -m, --monitor=METHOD    copy traffic to/from kernel to METHOD\n"
            "                          (a passive OpenFlow connection method)\n"
+           "  --out-of-band           controller connection is out-of-band\n"
+           "  --stp                   enable 802.1D Spanning Tree Protocol\n"
+           "  --no-stp                disable 802.1D Spanning Tree Protocol\n"
            "\nRate-limiting of \"packet-in\" messages to the controller:\n"
            "  --rate-limit[=PACKETS]  max rate, in packets/s (default: 1000)\n"
            "  --burst-limit=BURST     limit on packet credit for idle time\n"