Maintain separate async and sync connections to nl:0 in secchan.
[sliver-openvswitch.git] / secchan / secchan.c
index e4fc62f..fa8d6e8 100644 (file)
  */
 
 #include <config.h>
+#include "secchan.h"
 #include <assert.h>
 #include <errno.h>
 #include <getopt.h>
-#include <inttypes.h>
 #include <netinet/in.h>
-#include <poll.h>
-#include <regex.h>
 #include <stdlib.h>
+#include <signal.h>
 #include <string.h>
-#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 "dynamic-string.h"
+#include "dirs.h"
+#include "discovery.h"
+#include "executer.h"
+#include "fail-open.h"
 #include "fault.h"
-#include "flow.h"
-#include "learning-switch.h"
+#include "in-band.h"
 #include "list.h"
-#include "mac-learning.h"
-#include "netdev.h"
-#include "openflow.h"
+#include "ofpbuf.h"
+#include "openflow/openflow.h"
 #include "packets.h"
+#include "port-watcher.h"
 #include "poll-loop.h"
+#include "ratelimit.h"
 #include "rconn.h"
+#ifdef SUPPORT_SNAT
+#include "snat.h"
+#endif
+#include "stp-secchan.h"
+#include "status.h"
 #include "timeval.h"
 #include "util.h"
 #include "vconn-ssl.h"
 #include "vlog.h"
 #define THIS_MODULE VLM_secchan
 
-/* Behavior when the connection to the controller fails. */
-enum fail_mode {
-    FAIL_OPEN,                  /* Act as learning switch. */
-    FAIL_CLOSED                 /* Drop all packets. */
-};
-
-/* Settings that may be configured by the user. */
-struct settings {
-    /* Overall mode of operation. */
-    bool discovery;           /* Discover the controller automatically? */
-    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 *controller_name; /* Controller (if not discovery mode). */
-    const char *listen_vconn_name; /* Listens for mgmt connections. */
-
-    /* Failure behavior. */
-    enum fail_mode fail_mode; /* Act as learning switch if no controller? */
-    int max_idle;             /* Idle time for flows in fail-open mode. */
-    int probe_interval;       /* # seconds idle before sending echo request. */
-    int max_backoff;          /* Max # seconds between connection attempts. */
-
-    /* Discovery behavior. */
-    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? */
+struct hook {
+    const struct hook_class *class;
+    void *aux;
 };
 
-struct half {
-    struct rconn *rconn;
-    struct buffer *rxbuf;
+struct secchan {
+    struct hook *hooks;
+    size_t n_hooks, allocated_hooks;
 };
 
-struct relay {
-    struct list node;
-
-#define HALF_LOCAL 0
-#define HALF_REMOTE 1
-    struct half halves[2];
-
-    bool is_mgmt_conn;
-};
-
-struct hook {
-    bool (*packet_cb)(struct relay *, int half, void *aux);
-    void (*periodic_cb)(void *aux);
-    void *aux;
-};
+static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 60);
 
 static void parse_options(int argc, char *argv[], struct settings *);
 static void usage(void) NO_RETURN;
 
-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 void relay_run(struct relay *, const struct hook[], size_t n_hooks);
+static char *vconn_name_without_subscription(const char *);
+static struct pvconn *open_passive_vconn(const char *name);
+static struct vconn *accept_vconn(struct pvconn *pvconn);
+
+static struct relay *relay_create(struct rconn *async,
+                                  struct rconn *local, struct rconn *remote);
+static struct relay *relay_accept(const struct settings *, struct pvconn *);
+static void relay_run(struct relay *, struct secchan *);
 static void relay_wait(struct relay *);
 static void relay_destroy(struct relay *);
 
-static struct hook make_hook(bool (*packet_cb)(struct relay *, int, void *),
-                             void (*periodic_cb)(void *),
-                             void *aux);
-
-static struct discovery *discovery_init(const struct settings *);
-static void discovery_question_connectivity(struct discovery *);
-static bool discovery_run(struct discovery *, char **controller_name);
-static void discovery_wait(struct discovery *);
-
-static struct hook in_band_hook_create(const struct settings *);
-static struct hook fail_open_hook_create(const struct settings *,
-                                         struct rconn *local,
-                                         struct rconn *remote);
-
-static void modify_dhcp_request(struct dhcp_msg *, void *aux);
-static bool validate_dhcp_offer(const struct dhcp_msg *, void *aux);
-
 int
 main(int argc, char *argv[])
 {
@@ -155,13 +105,20 @@ main(int argc, char *argv[])
 
     struct list relays = LIST_INITIALIZER(&relays);
 
-    struct hook hooks[3];
-    size_t n_hooks;
+    struct secchan secchan;
+
+    struct pvconn *monitor;
 
-    struct rconn *local_rconn, *remote_rconn;
-    struct vconn *listen_vconn;
+    struct pvconn *listeners[MAX_MGMT];
+    size_t n_listeners;
+
+    char *local_rconn_name;
+    struct rconn *async_rconn, *local_rconn, *remote_rconn;
     struct relay *controller_relay;
     struct discovery *discovery;
+    struct switch_status *switch_status;
+    struct port_watcher *pw;
+    int i;
     int retval;
 
     set_program_name(argv[0]);
@@ -169,58 +126,92 @@ main(int argc, char *argv[])
     time_init();
     vlog_init();
     parse_options(argc, argv, &s);
+    signal(SIGPIPE, SIG_IGN);
 
-    /* Start listening for management connections. */
-    if (s.listen_vconn_name) {
-        retval = vconn_open(s.listen_vconn_name, &listen_vconn);
-        if (retval && retval != EAGAIN) {
-            fatal(retval, "opening %s", s.listen_vconn_name);
-        }
-        if (!vconn_is_passive(listen_vconn)) {
-            fatal(0, "%s is not a passive vconn", s.listen_vconn_name);
-        }
-    } else {
-        listen_vconn = NULL;
+    secchan.hooks = NULL;
+    secchan.n_hooks = 0;
+    secchan.allocated_hooks = 0;
+
+    /* Start listening for management and monitoring connections. */
+    n_listeners = 0;
+    for (i = 0; i < s.n_listeners; i++) {
+        listeners[n_listeners++] = open_passive_vconn(s.listener_names[i]);
     }
+    monitor = s.monitor_name ? open_passive_vconn(s.monitor_name) : NULL;
 
-    /* Start controller discovery. */
-    discovery = s.discovery ? discovery_init(&s) : NULL;
+    /* Initialize switch status hook. */
+    switch_status_start(&secchan, &s, &switch_status);
+
+    die_if_already_running();
+    daemonize();
 
     /* 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");
     }
 
-    daemonize();
+    VLOG_WARN("OpenFlow reference implementation version %s", VERSION BUILDNR);
+    VLOG_WARN("OpenFlow protocol version 0x%02x", OFP_VERSION);
 
-    /* Connect to datapath. */
-    local_rconn = rconn_create(1, 0, s.max_backoff);
-    rconn_connect(local_rconn, s.nl_name);
+    /* Check datapath name, to try to catch command-line invocation errors. */
+    if (strncmp(s.dp_name, "nl:", 3) && strncmp(s.dp_name, "unix:", 5)
+        && !s.controller_name) {
+        VLOG_WARN("Controller not specified and datapath is not nl: or "
+                  "unix:.  (Did you forget to specify the datapath?)");
+    }
+
+    /* Connect to datapath with a subscription for asynchronous events. */
+    async_rconn = rconn_create(0, s.max_backoff);
+    rconn_connect(async_rconn, s.dp_name);
+    switch_status_register_category(switch_status, "async",
+                                    rconn_status_cb, async_rconn);
+
+    /* Connect to datapath without a subscription, for requests and replies. */
+    local_rconn_name = vconn_name_without_subscription(s.dp_name);
+    local_rconn = rconn_create(0, s.max_backoff);
+    rconn_connect(local_rconn, local_rconn_name);
+    free(local_rconn_name);
+    switch_status_register_category(switch_status, "local",
+                                    rconn_status_cb, local_rconn);
 
     /* Connect to controller. */
-    remote_rconn = rconn_create(1, s.probe_interval, s.max_backoff);
+    remote_rconn = rconn_create(s.probe_interval, s.max_backoff);
     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",
+                                    rconn_status_cb, remote_rconn);
 
     /* Start relaying. */
-    controller_relay = relay_create(local_rconn, remote_rconn, false);
+    controller_relay = relay_create(async_rconn, local_rconn, remote_rconn);
     list_push_back(&relays, &controller_relay->node);
 
     /* Set up hooks. */
-    n_hooks = 0;
+    port_watcher_start(&secchan, local_rconn, remote_rconn, &pw);
+    discovery = s.discovery ? discovery_init(&s, pw, switch_status) : NULL;
+#ifdef SUPPORT_SNAT
+    snat_start(&secchan, pw);
+#endif
+    if (s.enable_stp) {
+        stp_start(&secchan, &s, pw, local_rconn, remote_rconn);
+    }
     if (s.in_band) {
-        hooks[n_hooks++] = in_band_hook_create(&s);
+        in_band_start(&secchan, &s, switch_status, pw, remote_rconn);
     }
     if (s.fail_mode == FAIL_OPEN) {
-        hooks[n_hooks++] = fail_open_hook_create(&s,
-                                                 local_rconn, remote_rconn);
+        fail_open_start(&secchan, &s, switch_status,
+                        local_rconn, remote_rconn);
+    }
+    if (s.rate_limit) {
+        rate_limit_start(&secchan, &s, switch_status, remote_rconn);
+    }
+    if (s.command_acl[0]) {
+        executer_start(&secchan, &s);
     }
-    assert(n_hooks <= ARRAY_SIZE(hooks));
 
     for (;;) {
         struct relay *r, *n;
@@ -228,20 +219,28 @@ main(int argc, char *argv[])
 
         /* Do work. */
         LIST_FOR_EACH_SAFE (r, n, struct relay, node, &relays) {
-            relay_run(r, hooks, n_hooks);
+            relay_run(r, &secchan);
         }
-        if (listen_vconn) {
+        for (i = 0; i < n_listeners; i++) {
             for (;;) {
-                struct relay *r = relay_accept(&s, listen_vconn);
+                struct relay *r = relay_accept(&s, listeners[i]);
                 if (!r) {
                     break;
                 }
                 list_push_back(&relays, &r->node);
             }
         }
-        for (i = 0; i < n_hooks; i++) {
-            if (hooks[i].periodic_cb) {
-                hooks[i].periodic_cb(hooks[i].aux);
+        if (monitor) {
+            struct vconn *new = accept_vconn(monitor);
+            if (new) {
+                /* XXX should monitor async_rconn too but rconn_add_monitor()
+                 * takes ownership of the vconn passed in. */
+                rconn_add_monitor(local_rconn, new);
+            }
+        }
+        for (i = 0; i < secchan.n_hooks; i++) {
+            if (secchan.hooks[i].class->periodic_cb) {
+                secchan.hooks[i].class->periodic_cb(secchan.hooks[i].aux);
             }
         }
         if (s.discovery) {
@@ -262,8 +261,16 @@ main(int argc, char *argv[])
         LIST_FOR_EACH (r, struct relay, node, &relays) {
             relay_wait(r);
         }
-        if (listen_vconn) {
-            vconn_accept_wait(listen_vconn);
+        for (i = 0; i < n_listeners; i++) {
+            pvconn_wait(listeners[i]);
+        }
+        if (monitor) {
+            pvconn_wait(monitor);
+        }
+        for (i = 0; i < secchan.n_hooks; i++) {
+            if (secchan.hooks[i].class->wait_cb) {
+                secchan.hooks[i].class->wait_cb(secchan.hooks[i].aux);
+            }
         }
         if (discovery) {
             discovery_wait(discovery);
@@ -274,85 +281,183 @@ main(int argc, char *argv[])
     return 0;
 }
 
-static struct hook
-make_hook(bool (*packet_cb)(struct relay *, int half, void *aux),
-          void (*periodic_cb)(void *aux),
-          void *aux)
+static struct pvconn *
+open_passive_vconn(const char *name)
+{
+    struct pvconn *pvconn;
+    int retval;
+
+    retval = pvconn_open(name, &pvconn);
+    if (retval && retval != EAGAIN) {
+        ofp_fatal(retval, "opening %s", name);
+    }
+    return pvconn;
+}
+
+static struct vconn *
+accept_vconn(struct pvconn *pvconn)
+{
+    struct vconn *new;
+    int retval;
+
+    retval = pvconn_accept(pvconn, OFP_VERSION, &new);
+    if (retval && retval != EAGAIN) {
+        VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
+    }
+    return new;
+}
+
+void
+add_hook(struct secchan *secchan, const struct hook_class *class, void *aux)
+{
+    struct hook *hook;
+
+    if (secchan->n_hooks >= secchan->allocated_hooks) {
+        secchan->allocated_hooks = secchan->allocated_hooks * 2 + 1;
+        secchan->hooks = xrealloc(secchan->hooks,
+                                  (sizeof *secchan->hooks
+                                   * secchan->allocated_hooks));
+    }
+    hook = &secchan->hooks[secchan->n_hooks++];
+    hook->class = class;
+    hook->aux = aux;
+}
+
+struct ofp_packet_in *
+get_ofp_packet_in(struct relay *r)
+{
+    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)) {
+            return msg->data;
+        } else {
+            VLOG_WARN("packet too short (%zu bytes) for packet_in",
+                      msg->size);
+        }
+    }
+    return NULL;
+}
+
+bool
+get_ofp_packet_eth_header(struct relay *r, struct ofp_packet_in **opip,
+                          struct eth_header **ethp)
 {
-    struct hook h;
-    h.packet_cb = packet_cb;
-    h.periodic_cb = periodic_cb;
-    h.aux = aux;
-    return h;
+    const int min_len = offsetof(struct ofp_packet_in, data) + ETH_HEADER_LEN;
+    struct ofp_packet_in *opi = get_ofp_packet_in(r);
+    if (opi && ntohs(opi->header.length) >= min_len) {
+        *opip = opi;
+        *ethp = (void *) opi->data;
+        return true;
+    }
+    return false;
 }
 \f
 /* OpenFlow message relaying. */
 
+/* Returns a malloc'd string containing a copy of 'vconn_name' modified not to
+ * subscribe to asynchronous messages such as 'ofp_packet_in' events (if
+ * possible). */
+static char *
+vconn_name_without_subscription(const char *vconn_name)
+{
+    int nl_index;
+    if (sscanf(vconn_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. */
+        return 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(&rl, "new management connection will receive "
+                     "asynchronous messages");
+        return xstrdup(vconn_name);
+    }
+}
+
 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;
+    char *vconn_name;
     int retval;
 
-    retval = vconn_accept(listen_vconn, &new_remote);
-    if (retval) {
-        if (retval != EAGAIN) {
-            VLOG_WARN("accept failed (%s)", strerror(retval));
-        }
+    new_remote = accept_vconn(pvconn);
+    if (!new_remote) {
         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, &new_local);
+    vconn_name = vconn_name_without_subscription(s->dp_name);
+    retval = vconn_open(vconn_name, OFP_VERSION, &new_local);
     if (retval) {
-        VLOG_ERR("could not connect to %s (%s)",
-                 nl_name_without_subscription, strerror(retval));
+        VLOG_ERR_RL(&rl, "could not connect to %s (%s)",
+                    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(1, 0, 0);
-    rconn_connect_unreliably(r1, nl_name_without_subscription, new_local);
-    free(nl_name_without_subscription);
+    r1 = rconn_create(0, 0);
+    rconn_connect_unreliably(r1, vconn_name, new_local);
+    free(vconn_name);
 
-    r2 = rconn_create(1, 0, 0);
+    r2 = rconn_create(0, 0);
     rconn_connect_unreliably(r2, "passive", new_remote);
 
-    return relay_create(r1, r2, true);
+    return relay_create(NULL, r1, r2);
 }
 
 static struct relay *
-relay_create(struct rconn *local, struct rconn *remote, bool is_mgmt_conn)
+relay_create(struct rconn *async, struct rconn *local, struct rconn *remote)
 {
-    struct relay *r;
-    int i;
-
-    r = xmalloc(sizeof *r);
+    struct relay *r = xcalloc(1, sizeof *r);
     r->halves[HALF_LOCAL].rconn = local;
     r->halves[HALF_REMOTE].rconn = remote;
-    for (i = 0; i < 2; i++) {
-        r->halves[i].rxbuf = NULL;
-    }
-    r->is_mgmt_conn = is_mgmt_conn;
+    r->is_mgmt_conn = async == NULL;
+    r->async_rconn = async;
     return r;
 }
 
+static bool
+call_local_packet_cbs(struct secchan *secchan, struct relay *r)
+{
+    const struct hook *h;
+    for (h = secchan->hooks; h < &secchan->hooks[secchan->n_hooks]; h++) {
+        bool (*cb)(struct relay *, void *aux) = h->class->local_packet_cb;
+        if (cb && (cb)(r, h->aux)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+static bool
+call_remote_packet_cbs(struct secchan *secchan, struct relay *r)
+{
+    const struct hook *h;
+    for (h = secchan->hooks; h < &secchan->hooks[secchan->n_hooks]; h++) {
+        bool (*cb)(struct relay *, void *aux) = h->class->remote_packet_cb;
+        if (cb && (cb)(r, h->aux)) {
+            return true;
+        }
+    }
+    return false;
+}
+
 static void
-relay_run(struct relay *r, const struct hook hooks[], size_t n_hooks)
+relay_run(struct relay *r, struct secchan *secchan)
 {
     int iteration;
     int i;
 
+    if (r->async_rconn) {
+        rconn_run(r->async_rconn);
+    }
     for (i = 0; i < 2; i++) {
         rconn_run(r->halves[i].rconn);
     }
@@ -366,26 +471,30 @@ relay_run(struct relay *r, const struct hook hooks[], size_t n_hooks)
 
             if (!this->rxbuf) {
                 this->rxbuf = rconn_recv(this->rconn);
-                if (this->rxbuf) {
-                    const struct hook *h;
-                    for (h = hooks; h < &hooks[n_hooks]; h++) {
-                        if (h->packet_cb(r, i, h->aux)) {
-                            buffer_delete(this->rxbuf);
-                            this->rxbuf = NULL;
-                            progress = true;
-                            break;
-                        }
+                if (!this->rxbuf && i == HALF_LOCAL && r->async_rconn) {
+                    this->rxbuf = rconn_recv(r->async_rconn);
+                }
+                if (this->rxbuf && (i == HALF_REMOTE || !r->is_mgmt_conn)) {
+                    if (i == HALF_LOCAL
+                        ? call_local_packet_cbs(secchan, r)
+                        : call_remote_packet_cbs(secchan, r))
+                    {
+                        ofpbuf_delete(this->rxbuf);
+                        this->rxbuf = NULL;
+                        progress = true;
+                        break;
                     }
                 }
             }
 
-            if (this->rxbuf) {
-                int retval = rconn_send(peer->rconn, this->rxbuf);
+            if (this->rxbuf && !this->n_txq) {
+                int retval = rconn_send(peer->rconn, this->rxbuf,
+                                        &this->n_txq);
                 if (retval != EAGAIN) {
                     if (!retval) {
                         progress = true;
                     } else {
-                        buffer_delete(this->rxbuf);
+                        ofpbuf_delete(this->rxbuf);
                     }
                     this->rxbuf = NULL;
                 }
@@ -412,12 +521,18 @@ relay_wait(struct relay *r)
 {
     int i;
 
+    if (r->async_rconn) {
+        rconn_run_wait(r->async_rconn);
+    }
     for (i = 0; i < 2; i++) {
         struct half *this = &r->halves[i];
 
         rconn_run_wait(this->rconn);
         if (!this->rxbuf) {
             rconn_recv_wait(this->rconn);
+            if (i == HALF_LOCAL && r->async_rconn) {
+                rconn_recv_wait(r->async_rconn);
+            }
         }
     }
 }
@@ -428,370 +543,15 @@ relay_destroy(struct relay *r)
     int i;
 
     list_remove(&r->node);
+    rconn_destroy(r->async_rconn);
     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
-/* In-band control. */
-
-struct in_band_data {
-    const struct settings *s;
-    struct mac_learning *ml;
-    struct netdev *of_device;
-    uint8_t mac[ETH_ADDR_LEN];
-};
-
-static void
-queue_tx(struct rconn *rc, struct buffer *b)
-{
-    if (rconn_force_send(rc, b)) {
-        buffer_delete(b);
-    }
-}
-
-static const uint8_t *
-get_controller_mac(struct netdev *netdev, struct rconn *controller)
-{
-    static uint32_t ip, last_nonzero_ip;
-    static uint8_t mac[ETH_ADDR_LEN], last_nonzero_mac[ETH_ADDR_LEN];
-    static time_t next_refresh = 0;
-
-    uint32_t last_ip = ip;
-
-    time_t now = time_now();
-
-    ip = rconn_get_ip(controller);
-    if (last_ip != ip || !next_refresh || now >= next_refresh) {
-        bool have_mac;
-
-        /* Look up MAC address. */
-        memset(mac, 0, sizeof mac);
-        if (ip) {
-            int retval = netdev_arp_lookup(netdev, ip, mac);
-            if (retval) {
-                VLOG_DBG("cannot look up controller hw address ("IP_FMT"): %s",
-                         IP_ARGS(&ip), strerror(retval));
-            }
-        }
-        have_mac = !eth_addr_is_zero(mac);
-
-        /* Log changes in IP, MAC addresses. */
-        if (ip && ip != last_nonzero_ip) {
-            VLOG_DBG("controller IP address changed from "IP_FMT
-                     " to "IP_FMT, IP_ARGS(&last_nonzero_ip), IP_ARGS(&ip));
-            last_nonzero_ip = ip;
-        }
-        if (have_mac && memcmp(last_nonzero_mac, mac, ETH_ADDR_LEN)) {
-            VLOG_DBG("controller MAC address changed from "ETH_ADDR_FMT" to "
-                     ETH_ADDR_FMT,
-                     ETH_ADDR_ARGS(last_nonzero_mac), ETH_ADDR_ARGS(mac));
-            memcpy(last_nonzero_mac, mac, ETH_ADDR_LEN);
-        }
-
-        /* Schedule next refresh.
-         *
-         * If we have an IP address but not a MAC address, then refresh
-         * quickly, since we probably will get a MAC address soon (via ARP).
-         * Otherwise, we can afford to wait a little while. */
-        next_refresh = now + (!ip || have_mac ? 10 : 1);
-    }
-    return !eth_addr_is_zero(mac) ? mac : NULL;
-}
-
-static bool
-is_controller_mac(const uint8_t mac[ETH_ADDR_LEN],
-                  const uint8_t *controller_mac)
-{
-    return controller_mac && eth_addr_equals(mac, controller_mac);
-}
-
-static bool
-in_band_packet_cb(struct relay *r, int half, void *in_band_)
-{
-    struct in_band_data *in_band = in_band_;
-    struct rconn *rc = r->halves[HALF_LOCAL].rconn;
-    struct buffer *msg = r->halves[HALF_LOCAL].rxbuf;
-    struct ofp_packet_in *opi;
-    struct ofp_header *oh;
-    size_t pkt_ofs, pkt_len;
-    struct buffer pkt;
-    struct flow flow;
-    uint16_t in_port, out_port;
-    const uint8_t *controller_mac;
-
-    if (half != HALF_LOCAL || r->is_mgmt_conn) {
-        return false;
-    }
-
-    oh = msg->data;
-    if (oh->type != OFPT_PACKET_IN) {
-        return false;
-    }
-    if (msg->size < offsetof (struct ofp_packet_in, data)) {
-        VLOG_WARN("packet too short (%zu bytes) for packet_in", msg->size);
-        return false;
-    }
-
-    /* Extract flow data from 'opi' into 'flow'. */
-    opi = msg->data;
-    in_port = ntohs(opi->in_port);
-    pkt_ofs = offsetof(struct ofp_packet_in, data);
-    pkt_len = ntohs(opi->header.length) - pkt_ofs;
-    pkt.data = opi->data;
-    pkt.size = pkt_len;
-    flow_extract(&pkt, in_port, &flow);
-
-    /* Deal with local stuff. */
-    controller_mac = get_controller_mac(in_band->of_device,
-                                        r->halves[HALF_REMOTE].rconn);
-    if (in_port == OFPP_LOCAL) {
-        /* Sent by secure channel. */
-        out_port = mac_learning_lookup(in_band->ml, flow.dl_dst);
-    } else if (eth_addr_equals(flow.dl_dst, in_band->mac)) {
-        /* Sent to secure channel. */
-        out_port = OFPP_LOCAL;
-        if (mac_learning_learn(in_band->ml, flow.dl_src, in_port)) {
-            VLOG_DBG("learned that "ETH_ADDR_FMT" is on port %"PRIu16,
-                     ETH_ADDR_ARGS(flow.dl_src), in_port);
-        }
-    } else if (flow.dl_type == htons(ETH_TYPE_ARP)
-               && eth_addr_is_broadcast(flow.dl_dst)
-               && is_controller_mac(flow.dl_src, controller_mac)) {
-        /* ARP sent by controller. */
-        out_port = OFPP_FLOOD;
-    } else if (is_controller_mac(flow.dl_dst, controller_mac)
-               && in_port == mac_learning_lookup(in_band->ml,
-                                                 controller_mac)) {
-        /* Drop controller traffic that arrives on the controller port. */
-        queue_tx(rc, make_add_flow(&flow, ntohl(opi->buffer_id),
-                                   in_band->s->max_idle, 0));
-        return true;
-    } else {
-        return false;
-    }
-
-    if (out_port != OFPP_FLOOD) {
-        /* The output port is known, so add a new flow. */
-        queue_tx(rc, make_add_simple_flow(&flow, ntohl(opi->buffer_id),
-                                          out_port, in_band->s->max_idle));
-
-        /* If the switch didn't buffer the packet, we need to send a copy. */
-        if (ntohl(opi->buffer_id) == UINT32_MAX) {
-            queue_tx(rc, make_unbuffered_packet_out(&pkt, in_port, out_port));
-        }
-    } else {
-        /* We don't know that MAC.  Send along the packet without setting up a
-         * flow. */
-        struct buffer *b;
-        if (ntohl(opi->buffer_id) == UINT32_MAX) {
-            b = make_unbuffered_packet_out(&pkt, in_port, out_port);
-        } else {
-            b = make_buffered_packet_out(ntohl(opi->buffer_id),
-                                         in_port, out_port);
-        }
-        queue_tx(rc, b);
-    }
-    return true;
-}
-
-static struct hook
-in_band_hook_create(const struct settings *s)
-{
-    struct in_band_data *in_band;
-    int retval;
-
-    in_band = xmalloc(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) {
-        fatal(retval, "Could not open %s device", s->of_name);
-    }
-    memcpy(in_band->mac, netdev_get_etheraddr(in_band->of_device),
-           ETH_ADDR_LEN);
-
-    return make_hook(in_band_packet_cb, NULL, in_band);
-}
-\f
-/* Fail open support. */
-
-struct fail_open_data {
-    const struct settings *s;
-    struct rconn *local_rconn;
-    struct rconn *remote_rconn;
-    struct lswitch *lswitch;
-    int last_disconn_secs;
-};
-
-/* Causes 'r' to enter or leave fail-open mode, if appropriate. */
-static void
-fail_open_periodic_cb(void *fail_open_)
-{
-    struct fail_open_data *fail_open = fail_open_;
-    int disconn_secs;
-    bool open;
-
-    disconn_secs = rconn_disconnected_duration(fail_open->remote_rconn);
-    open = disconn_secs >= fail_open->s->probe_interval * 3;
-    if (open != (fail_open->lswitch != NULL)) {
-        if (!open) {
-            VLOG_WARN("No longer in fail-open mode");
-            lswitch_destroy(fail_open->lswitch);
-            fail_open->lswitch = NULL;
-        } else {
-            VLOG_WARN("Could not connect to controller for %d seconds, "
-                      "failing open", disconn_secs);
-            fail_open->lswitch = lswitch_create(fail_open->local_rconn, true,
-                                                fail_open->s->max_idle);
-            fail_open->last_disconn_secs = disconn_secs;
-        }
-    } else if (open && disconn_secs > fail_open->last_disconn_secs + 60) {
-        VLOG_WARN("Still in fail-open mode after %d seconds disconnected "
-                  "from controller", disconn_secs);
-        fail_open->last_disconn_secs = disconn_secs;
-    }
-}
-
-static bool
-fail_open_packet_cb(struct relay *r, int half, void *fail_open_)
-{
-    struct fail_open_data *fail_open = fail_open_;
-    if (half != HALF_LOCAL || r->is_mgmt_conn || !fail_open->lswitch) {
-        return false;
-    } else {
-        lswitch_process_packet(fail_open->lswitch, fail_open->local_rconn,
-                               r->halves[HALF_LOCAL].rxbuf);
-        rconn_run(fail_open->local_rconn);
-        return true;
-    }
-}
-
-static struct hook
-fail_open_hook_create(const struct settings *s, struct rconn *local_rconn,
-                      struct rconn *remote_rconn)
-{
-    struct fail_open_data *fail_open = xmalloc(sizeof *fail_open);
-    fail_open->s = s;
-    fail_open->local_rconn = local_rconn;
-    fail_open->remote_rconn = remote_rconn;
-    fail_open->lswitch = NULL;
-    return make_hook(fail_open_packet_cb, fail_open_periodic_cb, fail_open);
-}
-\f
-/* Controller discovery. */
-
-struct discovery
-{
-    const struct settings *s;
-    struct dhclient *dhcp;
-    bool ever_successful;
-};
-
-static struct discovery *
-discovery_init(const struct settings *s)
-{
-    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) {
-        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);
-    }
-    netdev_close(netdev);
-
-    /* Initialize DHCP client. */
-    retval = dhclient_create(s->of_name, modify_dhcp_request,
-                             validate_dhcp_offer, (void *) s, &dhcp);
-    if (retval) {
-        fatal(retval, "Failed to initialize DHCP client");
-    }
-    dhclient_init(dhcp, 0);
-
-    d = xmalloc(sizeof *d);
-    d->s = s;
-    d->dhcp = dhcp;
-    d->ever_successful = false;
-    return d;
-}
-
-static void
-discovery_question_connectivity(struct discovery *d)
-{
-    dhclient_force_renew(d->dhcp, 15);
-}
-
-static bool
-discovery_run(struct discovery *d, char **controller_name)
-{
-    dhclient_run(d->dhcp);
-    if (!dhclient_changed(d->dhcp)) {
-        return false;
-    }
-
-    dhclient_configure_netdev(d->dhcp);
-    if (d->s->update_resolv_conf) {
-        dhclient_update_resolv_conf(d->dhcp);
-    }
-
-    if (dhclient_is_bound(d->dhcp)) {
-        *controller_name = dhcp_msg_get_string(dhclient_get_config(d->dhcp),
-                                               DHCP_CODE_OFP_CONTROLLER_VCONN);
-        VLOG_WARN("%s: discovered controller", *controller_name);
-        d->ever_successful = true;
-    } else if (controller_name) {
-        *controller_name = NULL;
-        if (d->ever_successful) {
-            VLOG_WARN("discovered controller no longer available");
-        }
-    }
-    return true;
-}
-
-static void
-discovery_wait(struct discovery *d)
-{
-    dhclient_wait(d->dhcp);
-}
-
-static void
-modify_dhcp_request(struct dhcp_msg *msg, void *aux)
-{
-    dhcp_msg_put_string(msg, DHCP_CODE_VENDOR_CLASS, "OpenFlow");
-}
-
-static bool
-validate_dhcp_offer(const struct dhcp_msg *msg, void *s_)
-{
-    const struct settings *s = s_;
-    char *vconn_name;
-    bool accept;
-
-    vconn_name = dhcp_msg_get_string(msg, DHCP_CODE_OFP_CONTROLLER_VCONN);
-    if (!vconn_name) {
-        VLOG_WARN("rejecting DHCP offer missing controller vconn");
-        return false;
-    }
-    accept = !regexec(&s->accept_controller_regex, vconn_name, 0, NULL, 0);
-    if (!accept) {
-        VLOG_WARN("rejecting controller vconn that fails to match %s",
-                  s->accept_controller_re);
-    }
-    free(vconn_name);
-    return accept;
-}
-\f
 /* User interface. */
 
 static void
@@ -802,22 +562,44 @@ parse_options(int argc, char *argv[], struct settings *s)
         OPT_NO_RESOLV_CONF,
         OPT_INACTIVITY_PROBE,
         OPT_MAX_IDLE,
-        OPT_MAX_BACKOFF
+        OPT_MAX_BACKOFF,
+        OPT_RATE_LIMIT,
+        OPT_BURST_LIMIT,
+        OPT_BOOTSTRAP_CA_CERT,
+        OPT_STP,
+        OPT_NO_STP,
+        OPT_OUT_OF_BAND,
+        OPT_IN_BAND,
+        OPT_COMMAND_ACL,
+        OPT_COMMAND_DIR,
+        VLOG_OPTION_ENUMS
     };
     static struct option long_options[] = {
         {"accept-vconn", required_argument, 0, OPT_ACCEPT_VCONN},
         {"no-resolv-conf", no_argument, 0, OPT_NO_RESOLV_CONF},
-        {"fail",        required_argument, 0, 'f'},
+        {"fail",        required_argument, 0, 'F'},
         {"inactivity-probe", required_argument, 0, OPT_INACTIVITY_PROBE},
         {"max-idle",    required_argument, 0, OPT_MAX_IDLE},
         {"max-backoff", required_argument, 0, OPT_MAX_BACKOFF},
         {"listen",      required_argument, 0, 'l'},
-        {"detach",      no_argument, 0, 'D'},
-        {"pidfile",     optional_argument, 0, 'P'},
+        {"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},
+        {"command-acl", required_argument, 0, OPT_COMMAND_ACL},
+        {"command-dir", required_argument, 0, OPT_COMMAND_DIR},
         {"verbose",     optional_argument, 0, 'v'},
         {"help",        no_argument, 0, 'h'},
         {"version",     no_argument, 0, 'V'},
+        DAEMON_LONG_OPTIONS,
+        VLOG_LONG_OPTIONS,
+#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);
@@ -825,12 +607,19 @@ parse_options(int argc, char *argv[], struct settings *s)
     int retval;
 
     /* Set defaults that we can figure out before parsing options. */
-    s->listen_vconn_name = NULL;
+    s->n_listeners = 0;
+    s->monitor_name = NULL;
     s->fail_mode = FAIL_OPEN;
     s->max_idle = 15;
     s->probe_interval = 15;
     s->max_backoff = 15;
     s->update_resolv_conf = true;
+    s->rate_limit = 0;
+    s->burst_limit = 0;
+    s->enable_stp = false;
+    s->in_band = true;
+    s->command_acl = "";
+    s->command_dir = xasprintf("%s/commands", ofp_pkgdatadir);
     for (;;) {
         int c;
 
@@ -848,21 +637,21 @@ parse_options(int argc, char *argv[], struct settings *s)
             s->update_resolv_conf = false;
             break;
 
-        case 'f':
+        case 'F':
             if (!strcmp(optarg, "open")) {
                 s->fail_mode = FAIL_OPEN;
             } 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;
 
@@ -872,8 +661,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;
@@ -881,40 +670,92 @@ 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;
             }
             break;
 
-        case 'D':
-            set_detach();
+        case OPT_RATE_LIMIT:
+            if (optarg) {
+                s->rate_limit = atoi(optarg);
+                if (s->rate_limit < 1) {
+                    ofp_fatal(0, "--rate-limit argument must be at least 1");
+                }
+            } else {
+                s->rate_limit = 1000;
+            }
+            break;
+
+        case OPT_BURST_LIMIT:
+            s->burst_limit = atoi(optarg);
+            if (s->burst_limit < 1) {
+                ofp_fatal(0, "--burst-limit argument must be at least 1");
+            }
+            break;
+
+        case OPT_STP:
+            s->enable_stp = true;
+            break;
+
+        case OPT_NO_STP:
+            s->enable_stp = false;
             break;
 
-        case 'P':
-            set_pidfile(optarg);
+        case OPT_OUT_OF_BAND:
+            s->in_band = false;
+            break;
+
+        case OPT_IN_BAND:
+            s->in_band = true;
+            break;
+
+        case OPT_COMMAND_ACL:
+            s->command_acl = (s->command_acl[0]
+                              ? xasprintf("%s,%s", s->command_acl, optarg)
+                              : optarg);
+            break;
+
+        case OPT_COMMAND_DIR:
+            s->command_dir = optarg;
             break;
 
         case 'l':
-            if (s->listen_vconn_name) {
-                fatal(0, "-l or --listen may be only specified once");
+            if (s->n_listeners >= MAX_MGMT) {
+                ofp_fatal(0,
+                          "-l or --listen may be specified at most %d times",
+                          MAX_MGMT);
             }
-            s->listen_vconn_name = optarg;
+            s->listener_names[s->n_listeners++] = optarg;
+            break;
+
+        case 'm':
+            if (s->monitor_name) {
+                ofp_fatal(0, "-m or --monitor may only be specified once");
+            }
+            s->monitor_name = optarg;
             break;
 
         case 'h':
             usage();
 
         case 'V':
-            printf("%s "VERSION" compiled "__DATE__" "__TIME__"\n", argv[0]);
+            printf("%s %s compiled "__DATE__" "__TIME__"\n",
+                   program_name, VERSION BUILDNR);
             exit(EXIT_SUCCESS);
 
-        case 'v':
-            vlog_set_verbosity(optarg);
-            break;
+        DAEMON_OPTION_HANDLERS
+
+        VLOG_OPTION_HANDLERS
 
+#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);
 
@@ -927,17 +768,12 @@ 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. */
-    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]) {
-        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. */
@@ -950,35 +786,27 @@ 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;
 
     /* Mode of operation. */
     s->discovery = s->controller_name == NULL;
-    if (s->discovery) {
-        s->in_band = true;
-    } else {
-        enum netdev_flags flags;
-        struct netdev *netdev;
+    if (s->discovery && !s->in_band) {
+        ofp_fatal(0, "Cannot perform discovery with out-of-band control");
+    }
 
-        retval = netdev_open(s->of_name, NETDEV_ETH_TYPE_NONE, &netdev);
-        if (retval) {
-            fatal(retval, "Could not open %s device", s->of_name);
+    /* Rate limiting. */
+    if (s->rate_limit) {
+        if (s->rate_limit < 100) {
+            VLOG_WARN("Rate limit set to unusually low value %d",
+                      s->rate_limit);
         }
-
-        retval = netdev_get_flags(netdev, &flags);
-        if (retval) {
-            fatal(retval, "Could not get flags for %s device", s->of_name);
+        if (!s->burst_limit) {
+            s->burst_limit = s->rate_limit / 4;
         }
-
-        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);
+        s->burst_limit = MAX(s->burst_limit, 1);
+        s->burst_limit = MIN(s->burst_limit, INT_MAX / 1000);
     }
 }
 
@@ -991,12 +819,12 @@ 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"
            "\nNetworking options:\n"
-           "  -f, --fail=open|closed  when controller connection fails:\n"
+           "  -F, --fail=open|closed  when controller connection fails:\n"
            "                            closed: drop all packets\n"
            "                            open (default): act as learning switch\n"
            "  --inactivity-probe=SECS time between inactivity probes\n"
@@ -1005,13 +833,22 @@ usage(void)
            "                          attempts (default: 15 seconds)\n"
            "  -l, --listen=METHOD     allow management connections on METHOD\n"
            "                          (a passive OpenFlow connection method)\n"
-           "\nOther options:\n"
-           "  -D, --detach            run in background as daemon\n"
-           "  -P, --pidfile[=FILE]    create pidfile (default: %s/secchan.pid)\n"
-           "  -v, --verbose=MODULE[:FACILITY[:LEVEL]]  set logging levels\n"
-           "  -v, --verbose           set maximum verbosity level\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"
+           "\nRemote command execution options:\n"
+           "  --command-acl=[!]GLOB[,[!]GLOB...] set allowed/denied commands\n"
+           "  --command-dir=DIR       set command dir (default: %s/commands)\n",
+           ofp_pkgdatadir);
+    daemon_usage();
+    vlog_usage();
+    printf("\nOther options:\n"
            "  -h, --help              display this help message\n"
-           "  -V, --version           display version information\n",
-           RUNDIR);
+           "  -V, --version           display version information\n");
     exit(EXIT_SUCCESS);
 }