Add the ability to disable the STP implementation.
[openvswitch] / secchan / secchan.c
index 0aaa7cb1aca507cec701d7636399899e651ed58e..341e146c2890d4a92a98fbc04ba2aa3fa5251e36 100644 (file)
 #include <time.h>
 #include <unistd.h>
 
-#include "buffer.h"
 #include "command-line.h"
 #include "compiler.h"
 #include "daemon.h"
-#include "dhcp.h"
 #include "dhcp-client.h"
+#include "dhcp.h"
 #include "dynamic-string.h"
 #include "fault.h"
 #include "flow.h"
@@ -59,6 +58,7 @@
 #include "mac-learning.h"
 #include "netdev.h"
 #include "nicira-ext.h"
+#include "ofpbuf.h"
 #include "openflow.h"
 #include "packets.h"
 #include "poll-loop.h"
@@ -110,11 +110,14 @@ 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 {
     struct rconn *rconn;
-    struct buffer *rxbuf;
+    struct ofpbuf *rxbuf;
     int n_txq;                  /* No. of packets queued for tx on 'rconn'. */
 };
 
@@ -140,12 +143,12 @@ static struct vlog_rate_limit vrl = VLOG_RATE_LIMIT_INIT(60, 60);
 static void parse_options(int argc, char *argv[], struct settings *);
 static void usage(void) NO_RETURN;
 
-static struct vconn *open_passive_vconn(const char *name);
-static struct vconn *accept_vconn(struct vconn *vconn);
+static struct pvconn *open_passive_vconn(const char *name);
+static struct vconn *accept_vconn(struct pvconn *pvconn);
 
 static struct relay *relay_create(struct rconn *local, struct rconn *remote,
                                   bool is_mgmt_conn);
-static struct relay *relay_accept(const struct settings *, struct vconn *);
+static struct relay *relay_accept(const struct settings *, struct pvconn *);
 static void relay_run(struct relay *, const struct hook[], size_t n_hooks);
 static void relay_wait(struct relay *);
 static void relay_destroy(struct relay *);
@@ -158,7 +161,7 @@ static struct hook make_hook(bool (*local_packet_cb)(struct relay *, void *),
 static struct ofp_packet_in *get_ofp_packet_in(struct relay *);
 static bool get_ofp_packet_eth_header(struct relay *, struct ofp_packet_in **,
                                       struct eth_header **);
-static void get_ofp_packet_payload(struct ofp_packet_in *, struct buffer *);
+static void get_ofp_packet_payload(struct ofp_packet_in *, struct ofpbuf *);
 
 struct switch_status;
 struct status_reply;
@@ -220,9 +223,9 @@ main(int argc, char *argv[])
     struct hook hooks[8];
     size_t n_hooks = 0;
 
-    struct vconn *monitor;
+    struct pvconn *monitor;
 
-    struct vconn *listeners[MAX_MGMT];
+    struct pvconn *listeners[MAX_MGMT];
     size_t n_listeners;
 
     struct rconn *local_rconn, *remote_rconn;
@@ -256,7 +259,7 @@ main(int argc, char *argv[])
     /* Start listening for vlogconf requests. */
     retval = vlog_server_listen(NULL, NULL);
     if (retval) {
-        fatal(retval, "Could not listen for vlog connections");
+        ofp_fatal(retval, "Could not listen for vlog connections");
     }
 
     die_if_already_running();
@@ -276,7 +279,7 @@ main(int argc, char *argv[])
     if (s.controller_name) {
         retval = rconn_connect(remote_rconn, s.controller_name);
         if (retval == EAFNOSUPPORT) {
-            fatal(0, "No support for %s vconn", s.controller_name);
+            ofp_fatal(0, "No support for %s vconn", s.controller_name);
         }
     }
     switch_status_register_category(switch_status, "remote",
@@ -288,7 +291,9 @@ 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);
+    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,
                                                remote_rconn);
@@ -350,10 +355,10 @@ main(int argc, char *argv[])
             relay_wait(r);
         }
         for (i = 0; i < n_listeners; i++) {
-            vconn_accept_wait(listeners[i]);
+            pvconn_wait(listeners[i]);
         }
         if (monitor) {
-            vconn_accept_wait(monitor);
+            pvconn_wait(monitor);
         }
         for (i = 0; i < n_hooks; i++) {
             if (hooks[i].wait_cb) {
@@ -369,29 +374,26 @@ main(int argc, char *argv[])
     return 0;
 }
 
-static struct vconn *
-open_passive_vconn(const char *name) 
+static struct pvconn *
+open_passive_vconn(const char *name)
 {
-    struct vconn *vconn;
+    struct pvconn *pvconn;
     int retval;
 
-    retval = vconn_open(name, &vconn);
+    retval = pvconn_open(name, &pvconn);
     if (retval && retval != EAGAIN) {
-        fatal(retval, "opening %s", name);
-    }
-    if (!vconn_is_passive(vconn)) {
-        fatal(0, "%s is not a passive vconn", name);
+        ofp_fatal(retval, "opening %s", name);
     }
-    return vconn;
+    return pvconn;
 }
 
 static struct vconn *
-accept_vconn(struct vconn *vconn) 
+accept_vconn(struct pvconn *pvconn)
 {
     struct vconn *new;
     int retval;
 
-    retval = vconn_accept(vconn, &new);
+    retval = pvconn_accept(pvconn, OFP_VERSION, &new);
     if (retval && retval != EAGAIN) {
         VLOG_WARN_RL(&vrl, "accept failed (%s)", strerror(retval));
     }
@@ -417,7 +419,7 @@ make_hook(bool (*local_packet_cb)(struct relay *, void *aux),
 static struct ofp_packet_in *
 get_ofp_packet_in(struct relay *r)
 {
-    struct buffer *msg = r->halves[HALF_LOCAL].rxbuf;
+    struct ofpbuf *msg = r->halves[HALF_LOCAL].rxbuf;
     struct ofp_header *oh = msg->data;
     if (oh->type == OFPT_PACKET_IN) {
         if (msg->size >= offsetof (struct ofp_packet_in, data)) {
@@ -448,14 +450,14 @@ get_ofp_packet_eth_header(struct relay *r, struct ofp_packet_in **opip,
 /* OpenFlow message relaying. */
 
 static struct relay *
-relay_accept(const struct settings *s, struct vconn *listen_vconn)
+relay_accept(const struct settings *s, struct pvconn *pvconn)
 {
     struct vconn *new_remote, *new_local;
     char *nl_name_without_subscription;
     struct rconn *r1, *r2;
     int retval;
 
-    new_remote = accept_vconn(listen_vconn);
+    new_remote = accept_vconn(pvconn);
     if (!new_remote) {
         return NULL;
     }
@@ -467,7 +469,7 @@ relay_accept(const struct settings *s, struct vconn *listen_vconn)
      * 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, &new_local);
+    retval = vconn_open(nl_name_without_subscription, OFP_VERSION, &new_local);
     if (retval) {
         VLOG_ERR_RL(&vrl, "could not connect to %s (%s)",
                     nl_name_without_subscription, strerror(retval));
@@ -520,7 +522,7 @@ relay_run(struct relay *r, const struct hook hooks[], size_t n_hooks)
                     const struct hook *h;
                     for (h = hooks; h < &hooks[n_hooks]; h++) {
                         if (h->packet_cb[i] && h->packet_cb[i](r, h->aux)) {
-                            buffer_delete(this->rxbuf);
+                            ofpbuf_delete(this->rxbuf);
                             this->rxbuf = NULL;
                             progress = true;
                             break;
@@ -536,7 +538,7 @@ relay_run(struct relay *r, const struct hook hooks[], size_t n_hooks)
                     if (!retval) {
                         progress = true;
                     } else {
-                        buffer_delete(this->rxbuf);
+                        ofpbuf_delete(this->rxbuf);
                     }
                     this->rxbuf = NULL;
                 }
@@ -582,20 +584,22 @@ relay_destroy(struct relay *r)
     for (i = 0; i < 2; i++) {
         struct half *this = &r->halves[i];
         rconn_destroy(this->rconn);
-        buffer_delete(this->rxbuf);
+        ofpbuf_delete(this->rxbuf);
     }
     free(r);
 }
 \f
 /* Port status watcher. */
 
-typedef void port_watcher_cb_func(uint16_t port_no,
+typedef void edit_port_cb_func(struct ofp_phy_port *port, void *aux);
+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;
+    edit_port_cb_func *edit_port;
+    port_changed_cb_func *port_changed;
     void *aux;
 };
 
@@ -646,14 +650,29 @@ 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;
+            if (port_changed) {
+                (port_changed)(port_no, old, new, pw->cbs[i].aux);
+            }
+        }
+    }
+}
+
+static void
+call_edit_port_callbacks(struct port_watcher *pw, struct ofp_phy_port *p)
+{
+    int i;
+    for (i = 0; i < pw->n_cbs; i++) {
+        edit_port_cb_func *edit_port = pw->cbs[i].edit_port;
+        if (edit_port) {
+            (edit_port)(p, pw->cbs[i].aux); 
         }
     }
 }
@@ -686,14 +705,14 @@ update_phy_port(struct port_watcher *pw, struct ofp_phy_port *opp,
         *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
 port_watcher_local_packet_cb(struct relay *r, void *pw_)
 {
     struct port_watcher *pw = pw_;
-    struct buffer *msg = r->halves[HALF_LOCAL].rxbuf;
+    struct ofpbuf *msg = r->halves[HALF_LOCAL].rxbuf;
     struct ofp_header *oh = msg->data;
 
     if (oh->type == OFPT_FEATURES_REPLY
@@ -710,7 +729,9 @@ 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];
+            call_edit_port_callbacks(pw, opp);
+            update_phy_port(pw, opp, OFPPR_MOD, seen);
         }
 
         /* Delete all the ports not included in the message. */
@@ -722,18 +743,44 @@ port_watcher_local_packet_cb(struct relay *r, void *pw_)
     } else if (oh->type == OFPT_PORT_STATUS
                && msg->size >= sizeof(struct ofp_port_status)) {
         struct ofp_port_status *ops = msg->data;
+        call_edit_port_callbacks(pw, &ops->desc);
         update_phy_port(pw, &ops->desc, ops->reason, NULL);
     }
     return false;
 }
 
+static bool
+port_watcher_remote_packet_cb(struct relay *r, void *pw_)
+{
+    struct port_watcher *pw = pw_;
+    struct ofpbuf *msg = r->halves[HALF_REMOTE].rxbuf;
+    struct ofp_header *oh = msg->data;
+
+    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);
+        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_port_changed_callbacks(pw, port_no, &old, pw_opp);
+            }
+        }
+    }
+    return false;
+}
+
 static void
 port_watcher_periodic_cb(void *pw_)
 {
     struct port_watcher *pw = pw_;
 
     if (!pw->got_feature_reply && time_now() >= pw->last_feature_request + 5) {
-        struct buffer *b;
+        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);
         pw->last_feature_request = time_now();
@@ -805,11 +852,13 @@ log_port_status(uint16_t port_no,
 
 static void
 port_watcher_register_callback(struct port_watcher *pw,
-                               port_watcher_cb_func *function,
+                               edit_port_cb_func *edit_port,
+                               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].edit_port = edit_port;
+    pw->cbs[pw->n_cbs].port_changed = port_changed;
     pw->cbs[pw->n_cbs].aux = aux;
     pw->n_cbs++;
 }
@@ -829,7 +878,7 @@ port_watcher_set_flags(struct port_watcher *pw,
     struct ofp_phy_port *p;
     struct ofp_port_mod *opm;
     struct ofp_port_status *ops;
-    struct buffer *b;
+    struct ofpbuf *b;
     int idx;
 
     idx = port_no_to_pw_idx(port_no);
@@ -844,8 +893,8 @@ port_watcher_set_flags(struct port_watcher *pw,
     old = *p;
 
     /* Update our idea of the flags. */
-    p->flags = ntohl(flags);
-    call_pw_callbacks(pw, port_no, &old, p);
+    p->flags = htonl((ntohl(p->flags) & ~mask) | (flags & 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);
@@ -880,8 +929,9 @@ 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);
     }
-    port_watcher_register_callback(pw, log_port_status, NULL);
-    return make_hook(port_watcher_local_packet_cb, NULL,
+    port_watcher_register_callback(pw, NULL, log_port_status, NULL);
+    return make_hook(port_watcher_local_packet_cb,
+                     port_watcher_remote_packet_cb,
                      port_watcher_periodic_cb, NULL, pw);
 }
 \f
@@ -904,14 +954,24 @@ 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;
     struct llc_header *llc;
-    struct buffer payload;
+    struct ofpbuf payload;
     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;
@@ -938,7 +998,7 @@ stp_local_packet_cb(struct relay *r, void *stp_)
         VLOG_DBG("non-LLC frame received on STP multicast address");
         return false;
     }
-    llc = buffer_at_assert(&payload, sizeof *eth, sizeof *llc);
+    llc = ofpbuf_at_assert(&payload, sizeof *eth, sizeof *llc);
     if (llc->llc_dsap != STP_LLC_DSAP) {
         VLOG_DBG("bad DSAP 0x%02"PRIx8" received on STP multicast address",
                  llc->llc_dsap);
@@ -949,7 +1009,7 @@ stp_local_packet_cb(struct relay *r, void *stp_)
     if (payload.size > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
         payload.size = ntohs(eth->eth_type) + ETH_HEADER_LEN;
     }
-    if (buffer_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
+    if (ofpbuf_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
         struct stp_port *p = stp_get_port(stp->stp, port_no);
         stp_received_bpdu(p, payload.data, payload.size);
     }
@@ -1036,13 +1096,13 @@ send_bpdu(const void *bpdu, size_t bpdu_size, int port_no, void *stp_)
     struct stp_data *stp = stp_;
     struct eth_header *eth;
     struct llc_header *llc;
-    struct buffer pkt, *opo;
+    struct ofpbuf pkt, *opo;
 
     /* Packet skeleton. */
-    buffer_init(&pkt, ETH_HEADER_LEN + LLC_HEADER_LEN + bpdu_size);
-    eth = buffer_put_uninit(&pkt, sizeof *eth);
-    llc = buffer_put_uninit(&pkt, sizeof *llc);
-    buffer_put(&pkt, bpdu, bpdu_size);
+    ofpbuf_init(&pkt, ETH_HEADER_LEN + LLC_HEADER_LEN + bpdu_size);
+    eth = ofpbuf_put_uninit(&pkt, sizeof *eth);
+    llc = ofpbuf_put_uninit(&pkt, sizeof *llc);
+    ofpbuf_put(&pkt, bpdu, bpdu_size);
 
     /* 802.2 header. */
     memcpy(eth->eth_dst, stp_eth_addr, ETH_ADDR_LEN);
@@ -1055,12 +1115,29 @@ send_bpdu(const void *bpdu, size_t bpdu_size, int port_no, void *stp_)
     llc->llc_cntl = STP_LLC_CNTL;
 
     opo = make_unbuffered_packet_out(&pkt, OFPP_NONE, port_no);
-    buffer_uninit(&pkt);
+    ofpbuf_uninit(&pkt);
     rconn_send_with_limit(stp->local_rconn, opo, &stp->n_txq, OFPP_MAX);
 }
 
+static bool
+stp_is_port_supported(uint16_t port_no)
+{
+    /* STP only supports a maximum of 255 ports, one less than OpenFlow.  We
+     * don't support STP on OFPP_LOCAL, either.  */
+    return port_no < STP_MAX_PORTS;
+}
+
 static void
-stp_port_watcher_cb(uint16_t port_no,
+stp_edit_port_cb(struct ofp_phy_port *p, void *stp_ UNUSED)
+{
+    uint16_t port_no = ntohs(p->port_no);
+    if (stp_is_port_supported(port_no)) {
+        p->features |= htonl(OFPPF_STP);
+    }
+}
+
+static void
+stp_port_changed_cb(uint16_t port_no,
                     const struct ofp_phy_port *old,
                     const struct ofp_phy_port *new,
                     void *stp_)
@@ -1068,9 +1145,7 @@ 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;
     }
 
@@ -1095,7 +1170,7 @@ stp_hook_create(const struct settings *s, struct port_watcher *pw,
 
     retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE, &netdev);
     if (retval) {
-        fatal(retval, "Could not open %s device", s->of_name);
+        ofp_fatal(retval, "Could not open %s device", s->of_name);
     }
     memcpy(dpid, netdev_get_etheraddr(netdev), ETH_ADDR_LEN);
     netdev_close(netdev);
@@ -1108,7 +1183,8 @@ stp_hook_create(const struct settings *s, struct port_watcher *pw,
     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_edit_port_cb,
+                                   stp_port_changed_cb, stp);
     return make_hook(stp_local_packet_cb, NULL,
                      stp_periodic_cb, stp_wait_cb, stp);
 }
@@ -1125,7 +1201,7 @@ struct in_band_data {
 };
 
 static void
-queue_tx(struct rconn *rc, struct in_band_data *in_band, struct buffer *b)
+queue_tx(struct rconn *rc, struct in_band_data *in_band, struct ofpbuf *b)
 {
     rconn_send_with_limit(rc, b, &in_band->n_queued, 10);
 }
@@ -1204,7 +1280,7 @@ in_band_local_packet_cb(struct relay *r, void *in_band_)
     struct rconn *rc = r->halves[HALF_LOCAL].rconn;
     struct ofp_packet_in *opi;
     struct eth_header *eth;
-    struct buffer payload;
+    struct ofpbuf payload;
     struct flow flow;
     uint16_t in_port;
     int out_port;
@@ -1270,7 +1346,7 @@ in_band_local_packet_cb(struct relay *r, void *in_band_)
     } else {
         /* We don't know that MAC.  Send along the packet without setting up a
          * flow. */
-        struct buffer *b;
+        struct ofpbuf *b;
         if (ntohl(opi->buffer_id) == UINT32_MAX) {
             b = make_unbuffered_packet_out(&payload, in_port, out_port);
         } else {
@@ -1309,7 +1385,7 @@ in_band_status_cb(struct status_reply *sr, void *in_band_)
 }
 
 static void
-get_ofp_packet_payload(struct ofp_packet_in *opi, struct buffer *payload)
+get_ofp_packet_payload(struct ofp_packet_in *opi, struct ofpbuf *payload)
 {
     payload->data = opi->data;
     payload->size = ntohs(opi->header.length) - offsetof(struct ofp_packet_in,
@@ -1329,7 +1405,7 @@ in_band_hook_create(const struct settings *s, struct switch_status *ss,
     retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE,
                          &in_band->of_device);
     if (retval) {
-        fatal(retval, "Could not open %s device", s->of_name);
+        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);
@@ -1420,7 +1496,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,
@@ -1432,7 +1510,7 @@ struct rate_limiter {
     struct rconn *remote_rconn;
 
     /* One queue per physical port. */
-    struct queue queues[OFPP_MAX];
+    struct ofp_queue queues[OFPP_MAX];
     int n_queued;               /* Sum over queues[*].n. */
     int next_tx_port;           /* Next port to check in round-robin. */
 
@@ -1459,9 +1537,9 @@ struct rate_limiter {
 static void
 drop_packet(struct rate_limiter *rl)
 {
-    struct queue *longest;      /* Queue currently selected as longest. */
+    struct ofp_queue *longest;  /* Queue currently selected as longest. */
     int n_longest;              /* # of queues of same length as 'longest'. */
-    struct queue *q;
+    struct ofp_queue *q;
 
     longest = &rl->queues[0];
     n_longest = 1;
@@ -1481,19 +1559,19 @@ drop_packet(struct rate_limiter *rl)
     }
 
     /* FIXME: do we want to pop the tail instead? */
-    buffer_delete(queue_pop_head(longest));
+    ofpbuf_delete(queue_pop_head(longest));
     rl->n_queued--;
 }
 
 /* Remove and return the next packet to transmit (in round-robin order). */
-static struct buffer *
+static struct ofpbuf *
 dequeue_packet(struct rate_limiter *rl)
 {
     unsigned int i;
 
     for (i = 0; i < OFPP_MAX; i++) {
         unsigned int port = (rl->next_tx_port + i) % OFPP_MAX;
-        struct queue *q = &rl->queues[port];
+        struct ofp_queue *q = &rl->queues[port];
         if (q->n) {
             rl->next_tx_port = (port + 1) % OFPP_MAX;
             rl->n_queued--;
@@ -1549,12 +1627,12 @@ rate_limit_local_packet_cb(struct relay *r, void *rl_)
         return false;
     } else {
         /* Otherwise queue it up for the periodic callback to drain out. */
-        struct buffer *msg = r->halves[HALF_LOCAL].rxbuf;
+        struct ofpbuf *msg = r->halves[HALF_LOCAL].rxbuf;
         int port = ntohs(opi->in_port) % OFPP_MAX;
         if (rl->n_queued >= s->burst_limit) {
             drop_packet(rl);
         }
-        queue_push_tail(&rl->queues[port], buffer_clone(msg));
+        queue_push_tail(&rl->queues[port], ofpbuf_clone(msg));
         rl->n_queued++;
         rl->n_limited++;
         return true;
@@ -1586,7 +1664,7 @@ rate_limit_periodic_cb(void *rl_)
          * because the TCP connection is responsible for buffering and there is
          * no point in trying to transmit faster than the TCP connection can
          * handle. */
-        struct buffer *b = dequeue_packet(rl);
+        struct ofpbuf *b = dequeue_packet(rl);
         if (rconn_send_with_limit(rl->remote_rconn, b, &rl->n_txq, 10)) {
             rl->n_tx_dropped++;
         }
@@ -1656,12 +1734,12 @@ switch_status_remote_packet_cb(struct relay *r, void *ss_)
 {
     struct switch_status *ss = ss_;
     struct rconn *rc = r->halves[HALF_REMOTE].rconn;
-    struct buffer *msg = r->halves[HALF_REMOTE].rxbuf;
+    struct ofpbuf *msg = r->halves[HALF_REMOTE].rxbuf;
     struct switch_status_category *c;
     struct nicira_header *request;
     struct nicira_header *reply;
     struct status_reply sr;
-    struct buffer *b;
+    struct ofpbuf *b;
     int retval;
 
     if (msg->size < sizeof(struct nicira_header)) {
@@ -1865,11 +1943,11 @@ discovery_init(const struct settings *s, struct switch_status *ss)
     /* Bring ofX network device up. */
     retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE, &netdev);
     if (retval) {
-        fatal(retval, "Could not open %s device", s->of_name);
+        ofp_fatal(retval, "Could not open %s device", s->of_name);
     }
     retval = netdev_turn_flags_on(netdev, NETDEV_UP, true);
     if (retval) {
-        fatal(retval, "Could not bring %s device up", s->of_name);
+        ofp_fatal(retval, "Could not bring %s device up", s->of_name);
     }
     netdev_close(netdev);
 
@@ -1877,7 +1955,7 @@ discovery_init(const struct settings *s, struct switch_status *ss)
     retval = dhclient_create(s->of_name, modify_dhcp_request,
                              validate_dhcp_offer, (void *) s, &dhcp);
     if (retval) {
-        fatal(retval, "Failed to initialize DHCP client");
+        ofp_fatal(retval, "Failed to initialize DHCP client");
     }
     dhclient_init(dhcp, 0);
 
@@ -1970,7 +2048,9 @@ parse_options(int argc, char *argv[], struct settings *s)
         OPT_MAX_IDLE,
         OPT_MAX_BACKOFF,
         OPT_RATE_LIMIT,
-        OPT_BURST_LIMIT
+        OPT_BURST_LIMIT,
+        OPT_BOOTSTRAP_CA_CERT,
+        OPT_NO_STP
     };
     static struct option long_options[] = {
         {"accept-vconn", required_argument, 0, OPT_ACCEPT_VCONN},
@@ -1983,13 +2063,17 @@ 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},
+        {"no-stp",      no_argument, 0, OPT_NO_STP},
         {"detach",      no_argument, 0, 'D'},
         {"force",       no_argument, 0, 'f'},
         {"pidfile",     optional_argument, 0, 'P'},
         {"verbose",     optional_argument, 0, 'v'},
         {"help",        no_argument, 0, 'h'},
         {"version",     no_argument, 0, 'V'},
+#ifdef HAVE_OPENSSL
         VCONN_SSL_LONG_OPTIONS
+        {"bootstrap-ca-cert", required_argument, 0, OPT_BOOTSTRAP_CA_CERT},
+#endif
         {0, 0, 0, 0},
     };
     char *short_options = long_options_to_short_options(long_options);
@@ -2006,6 +2090,7 @@ 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 = true;
     for (;;) {
         int c;
 
@@ -2029,15 +2114,15 @@ parse_options(int argc, char *argv[], struct settings *s)
             } else if (!strcmp(optarg, "closed")) {
                 s->fail_mode = FAIL_CLOSED;
             } else {
-                fatal(0,
-                      "-f or --fail argument must be \"open\" or \"closed\"");
+                ofp_fatal(0, "-f or --fail argument must be \"open\" "
+                          "or \"closed\"");
             }
             break;
 
         case OPT_INACTIVITY_PROBE:
             s->probe_interval = atoi(optarg);
             if (s->probe_interval < 5) {
-                fatal(0, "--inactivity-probe argument must be at least 5");
+                ofp_fatal(0, "--inactivity-probe argument must be at least 5");
             }
             break;
 
@@ -2047,8 +2132,8 @@ parse_options(int argc, char *argv[], struct settings *s)
             } else {
                 s->max_idle = atoi(optarg);
                 if (s->max_idle < 1 || s->max_idle > 65535) {
-                    fatal(0, "--max-idle argument must be between 1 and "
-                          "65535 or the word 'permanent'");
+                    ofp_fatal(0, "--max-idle argument must be between 1 and "
+                              "65535 or the word 'permanent'");
                 }
             }
             break;
@@ -2056,7 +2141,7 @@ parse_options(int argc, char *argv[], struct settings *s)
         case OPT_MAX_BACKOFF:
             s->max_backoff = atoi(optarg);
             if (s->max_backoff < 1) {
-                fatal(0, "--max-backoff argument must be at least 1");
+                ofp_fatal(0, "--max-backoff argument must be at least 1");
             } else if (s->max_backoff > 3600) {
                 s->max_backoff = 3600;
             }
@@ -2066,7 +2151,7 @@ parse_options(int argc, char *argv[], struct settings *s)
             if (optarg) {
                 s->rate_limit = atoi(optarg);
                 if (s->rate_limit < 1) {
-                    fatal(0, "--rate-limit argument must be at least 1");
+                    ofp_fatal(0, "--rate-limit argument must be at least 1");
                 }
             } else {
                 s->rate_limit = 1000;
@@ -2076,10 +2161,14 @@ parse_options(int argc, char *argv[], struct settings *s)
         case OPT_BURST_LIMIT:
             s->burst_limit = atoi(optarg);
             if (s->burst_limit < 1) {
-                fatal(0, "--burst-limit argument must be at least 1");
+                ofp_fatal(0, "--burst-limit argument must be at least 1");
             }
             break;
 
+        case OPT_NO_STP:
+            s->enable_stp = false;
+            break;
+
         case 'D':
             set_detach();
             break;
@@ -2094,15 +2183,16 @@ parse_options(int argc, char *argv[], struct settings *s)
 
         case 'l':
             if (s->n_listeners >= MAX_MGMT) {
-                fatal(0, "-l or --listen may be specified at most %d times",
-                      MAX_MGMT);
+                ofp_fatal(0,
+                          "-l or --listen may be specified at most %d times",
+                          MAX_MGMT);
             }
             s->listener_names[s->n_listeners++] = optarg;
             break;
 
         case 'm':
             if (s->monitor_name) {
-                fatal(0, "-m or --monitor may only be specified once");
+                ofp_fatal(0, "-m or --monitor may only be specified once");
             }
             s->monitor_name = optarg;
             break;
@@ -2118,8 +2208,14 @@ parse_options(int argc, char *argv[], struct settings *s)
             vlog_set_verbosity(optarg);
             break;
 
+#ifdef HAVE_OPENSSL
         VCONN_SSL_OPTION_HANDLERS
 
+        case OPT_BOOTSTRAP_CA_CERT:
+            vconn_ssl_set_ca_cert_file(optarg, true);
+            break;
+#endif
+
         case '?':
             exit(EXIT_FAILURE);
 
@@ -2132,7 +2228,8 @@ parse_options(int argc, char *argv[], struct settings *s)
     argc -= optind;
     argv += optind;
     if (argc < 1 || argc > 2) {
-        fatal(0, "need one or two non-option arguments; use --help for usage");
+        ofp_fatal(0, "need one or two non-option arguments; "
+                  "use --help for usage");
     }
 
     /* Local and remote vconns. */
@@ -2140,7 +2237,8 @@ parse_options(int argc, char *argv[], struct settings *s)
     if (strncmp(s->nl_name, "nl:", 3)
         || strlen(s->nl_name) < 4
         || s->nl_name[strspn(s->nl_name + 3, "0123456789") + 3]) {
-        fatal(0, "%s: argument is not of the form \"nl:DP_IDX\"", s->nl_name);
+        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->controller_name = argc > 1 ? xstrdup(argv[1]) : NULL;
@@ -2155,7 +2253,7 @@ parse_options(int argc, char *argv[], struct settings *s)
         size_t length = regerror(retval, &s->accept_controller_regex, NULL, 0);
         char *buffer = xmalloc(length);
         regerror(retval, &s->accept_controller_regex, buffer, length);
-        fatal(0, "%s: %s", accept_re, buffer);
+        ofp_fatal(0, "%s: %s", accept_re, buffer);
     }
     s->accept_controller_re = accept_re;
 
@@ -2169,12 +2267,12 @@ parse_options(int argc, char *argv[], struct settings *s)
 
         retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE, &netdev);
         if (retval) {
-            fatal(retval, "Could not open %s device", s->of_name);
+            ofp_fatal(retval, "Could not open %s device", s->of_name);
         }
 
         retval = netdev_get_flags(netdev, &flags);
         if (retval) {
-            fatal(retval, "Could not get flags for %s device", s->of_name);
+            ofp_fatal(retval, "Could not get flags for %s device", s->of_name);
         }
 
         s->in_band = (flags & NETDEV_UP) != 0;
@@ -2209,7 +2307,7 @@ usage(void)
            "CONTROLLER is an active OpenFlow connection method; if it is\n"
            "omitted, then secchan performs controller discovery.\n",
            program_name, program_name);
-    vconn_usage(true, true);
+    vconn_usage(true, true, true);
     printf("\nController discovery options:\n"
            "  --accept-vconn=REGEX    accept matching discovered controllers\n"
            "  --no-resolv-conf        do not update /etc/resolv.conf\n"
@@ -2225,6 +2323,7 @@ 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"
+           "  --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"