Break secchan into multiple files, to make it more maintainable.
[sliver-openvswitch.git] / secchan / secchan.c
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2  * Junior University
3  *
4  * We are making the OpenFlow specification and associated documentation
5  * (Software) available for public use and benefit with the expectation
6  * that others will use, modify and enhance the Software and contribute
7  * those enhancements back to the community. However, since we would
8  * like to make the Software available for broadest use, with as few
9  * restrictions as possible permission is hereby granted, free of
10  * charge, to any person obtaining a copy of this Software to deal in
11  * the Software under the copyrights without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  * The name and trademarks of copyright holder(s) may NOT be used in
30  * advertising or publicity pertaining to the Software or any
31  * derivatives without specific, written prior permission.
32  */
33
34 #include <config.h>
35 #include "secchan.h"
36 #include <assert.h>
37 #include <errno.h>
38 #include <getopt.h>
39 #include <netinet/in.h>
40 #include <stdlib.h>
41 #include <signal.h>
42 #include <string.h>
43
44 #include "command-line.h"
45 #include "compiler.h"
46 #include "daemon.h"
47 #include "discovery.h"
48 #include "fail-open.h"
49 #include "fault.h"
50 #include "in-band.h"
51 #include "list.h"
52 #include "ofpbuf.h"
53 #include "openflow.h"
54 #include "packets.h"
55 #include "port-watcher.h"
56 #include "poll-loop.h"
57 #include "ratelimit.h"
58 #include "rconn.h"
59 #ifdef SUPPORT_SNAT
60 #include "snat.h"
61 #endif
62 #include "stp-secchan.h"
63 #include "status.h"
64 #include "timeval.h"
65 #include "util.h"
66 #include "vconn-ssl.h"
67 #include "vconn.h"
68 #include "vlog-socket.h"
69
70 #include "vlog.h"
71 #define THIS_MODULE VLM_secchan
72
73 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 60);
74
75 static void parse_options(int argc, char *argv[], struct settings *);
76 static void usage(void) NO_RETURN;
77
78 static struct pvconn *open_passive_vconn(const char *name);
79 static struct vconn *accept_vconn(struct pvconn *pvconn);
80
81 static struct relay *relay_create(struct rconn *local, struct rconn *remote,
82                                   bool is_mgmt_conn);
83 static struct relay *relay_accept(const struct settings *, struct pvconn *);
84 static void relay_run(struct relay *, const struct hook[], size_t n_hooks);
85 static void relay_wait(struct relay *);
86 static void relay_destroy(struct relay *);
87
88 int
89 main(int argc, char *argv[])
90 {
91     struct settings s;
92
93     struct list relays = LIST_INITIALIZER(&relays);
94
95     struct hook hooks[8];
96     size_t n_hooks = 0;
97
98     struct pvconn *monitor;
99
100     struct pvconn *listeners[MAX_MGMT];
101     size_t n_listeners;
102
103     struct rconn *local_rconn, *remote_rconn;
104     struct relay *controller_relay;
105     struct discovery *discovery;
106     struct switch_status *switch_status;
107     struct port_watcher *pw;
108     int i;
109     int retval;
110
111     set_program_name(argv[0]);
112     register_fault_handlers();
113     time_init();
114     vlog_init();
115     parse_options(argc, argv, &s);
116     signal(SIGPIPE, SIG_IGN);
117
118     /* Start listening for management and monitoring connections. */
119     n_listeners = 0;
120     for (i = 0; i < s.n_listeners; i++) {
121         listeners[n_listeners++] = open_passive_vconn(s.listener_names[i]);
122     }
123     monitor = s.monitor_name ? open_passive_vconn(s.monitor_name) : NULL;
124
125     /* Initialize switch status hook. */
126     hooks[n_hooks++] = switch_status_hook_create(&s, &switch_status);
127
128     /* Start listening for vlogconf requests. */
129     retval = vlog_server_listen(NULL, NULL);
130     if (retval) {
131         ofp_fatal(retval, "Could not listen for vlog connections");
132     }
133
134     die_if_already_running();
135     daemonize();
136
137     VLOG_WARN("OpenFlow reference implementation version %s", VERSION);
138     VLOG_WARN("OpenFlow protocol version 0x%02x", OFP_VERSION);
139
140     /* Connect to datapath. */
141     local_rconn = rconn_create(0, s.max_backoff);
142     rconn_connect(local_rconn, s.dp_name);
143     switch_status_register_category(switch_status, "local",
144                                     rconn_status_cb, local_rconn);
145
146     /* Connect to controller. */
147     remote_rconn = rconn_create(s.probe_interval, s.max_backoff);
148     if (s.controller_name) {
149         retval = rconn_connect(remote_rconn, s.controller_name);
150         if (retval == EAFNOSUPPORT) {
151             ofp_fatal(0, "No support for %s vconn", s.controller_name);
152         }
153     }
154     switch_status_register_category(switch_status, "remote",
155                                     rconn_status_cb, remote_rconn);
156
157     /* Start relaying. */
158     controller_relay = relay_create(local_rconn, remote_rconn, false);
159     list_push_back(&relays, &controller_relay->node);
160
161     /* Set up hooks. */
162     hooks[n_hooks++] = port_watcher_create(local_rconn, remote_rconn, &pw);
163     discovery = s.discovery ? discovery_init(&s, pw, switch_status) : NULL;
164 #ifdef SUPPORT_SNAT
165     hooks[n_hooks++] = snat_hook_create(pw);
166 #endif
167     if (s.enable_stp) {
168         hooks[n_hooks++] = stp_hook_create(&s, pw, local_rconn, remote_rconn);
169     }
170     if (s.in_band) {
171         hooks[n_hooks++] = in_band_hook_create(&s, switch_status, pw,
172                                                remote_rconn);
173     }
174     if (s.fail_mode == FAIL_OPEN) {
175         hooks[n_hooks++] = fail_open_hook_create(&s, switch_status,
176                                                  local_rconn, remote_rconn);
177     }
178     if (s.rate_limit) {
179         hooks[n_hooks++] = rate_limit_hook_create(&s, switch_status,
180                                                   local_rconn, remote_rconn);
181     }
182     assert(n_hooks <= ARRAY_SIZE(hooks));
183
184     for (;;) {
185         struct relay *r, *n;
186         size_t i;
187
188         /* Do work. */
189         LIST_FOR_EACH_SAFE (r, n, struct relay, node, &relays) {
190             relay_run(r, hooks, n_hooks);
191         }
192         for (i = 0; i < n_listeners; i++) {
193             for (;;) {
194                 struct relay *r = relay_accept(&s, listeners[i]);
195                 if (!r) {
196                     break;
197                 }
198                 list_push_back(&relays, &r->node);
199             }
200         }
201         if (monitor) {
202             struct vconn *new = accept_vconn(monitor);
203             if (new) {
204                 rconn_add_monitor(local_rconn, new);
205             }
206         }
207         for (i = 0; i < n_hooks; i++) {
208             if (hooks[i].periodic_cb) {
209                 hooks[i].periodic_cb(hooks[i].aux);
210             }
211         }
212         if (s.discovery) {
213             char *controller_name;
214             if (rconn_is_connectivity_questionable(remote_rconn)) {
215                 discovery_question_connectivity(discovery);
216             }
217             if (discovery_run(discovery, &controller_name)) {
218                 if (controller_name) {
219                     rconn_connect(remote_rconn, controller_name);
220                 } else {
221                     rconn_disconnect(remote_rconn);
222                 }
223             }
224         }
225
226         /* Wait for something to happen. */
227         LIST_FOR_EACH (r, struct relay, node, &relays) {
228             relay_wait(r);
229         }
230         for (i = 0; i < n_listeners; i++) {
231             pvconn_wait(listeners[i]);
232         }
233         if (monitor) {
234             pvconn_wait(monitor);
235         }
236         for (i = 0; i < n_hooks; i++) {
237             if (hooks[i].wait_cb) {
238                 hooks[i].wait_cb(hooks[i].aux);
239             }
240         }
241         if (discovery) {
242             discovery_wait(discovery);
243         }
244         poll_block();
245     }
246
247     return 0;
248 }
249
250 static struct pvconn *
251 open_passive_vconn(const char *name)
252 {
253     struct pvconn *pvconn;
254     int retval;
255
256     retval = pvconn_open(name, &pvconn);
257     if (retval && retval != EAGAIN) {
258         ofp_fatal(retval, "opening %s", name);
259     }
260     return pvconn;
261 }
262
263 static struct vconn *
264 accept_vconn(struct pvconn *pvconn)
265 {
266     struct vconn *new;
267     int retval;
268
269     retval = pvconn_accept(pvconn, OFP_VERSION, &new);
270     if (retval && retval != EAGAIN) {
271         VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
272     }
273     return new;
274 }
275
276 struct hook
277 make_hook(bool (*local_packet_cb)(struct relay *, void *aux),
278           bool (*remote_packet_cb)(struct relay *, void *aux),
279           void (*periodic_cb)(void *aux),
280           void (*wait_cb)(void *aux),
281           void *aux)
282 {
283     struct hook h;
284     h.packet_cb[HALF_LOCAL] = local_packet_cb;
285     h.packet_cb[HALF_REMOTE] = remote_packet_cb;
286     h.periodic_cb = periodic_cb;
287     h.wait_cb = wait_cb;
288     h.aux = aux;
289     return h;
290 }
291
292 struct ofp_packet_in *
293 get_ofp_packet_in(struct relay *r)
294 {
295     struct ofpbuf *msg = r->halves[HALF_LOCAL].rxbuf;
296     struct ofp_header *oh = msg->data;
297     if (oh->type == OFPT_PACKET_IN) {
298         if (msg->size >= offsetof (struct ofp_packet_in, data)) {
299             return msg->data;
300         } else {
301             VLOG_WARN("packet too short (%zu bytes) for packet_in",
302                       msg->size);
303         }
304     }
305     return NULL;
306 }
307
308 bool
309 get_ofp_packet_eth_header(struct relay *r, struct ofp_packet_in **opip,
310                           struct eth_header **ethp)
311 {
312     const int min_len = offsetof(struct ofp_packet_in, data) + ETH_HEADER_LEN;
313     struct ofp_packet_in *opi = get_ofp_packet_in(r);
314     if (opi && ntohs(opi->header.length) >= min_len) {
315         *opip = opi;
316         *ethp = (void *) opi->data;
317         return true;
318     }
319     return false;
320 }
321 \f
322 /* OpenFlow message relaying. */
323
324 static struct relay *
325 relay_accept(const struct settings *s, struct pvconn *pvconn)
326 {
327     struct vconn *new_remote, *new_local;
328     struct rconn *r1, *r2;
329     char *vconn_name;
330     int nl_index;
331     int retval;
332
333     new_remote = accept_vconn(pvconn);
334     if (!new_remote) {
335         return NULL;
336     }
337
338     if (sscanf(s->dp_name, "nl:%d", &nl_index) == 1) {
339         /* nl:123 or nl:123:1 opens a netlink connection to local datapath 123.
340          * nl:123:0 opens a netlink connection to local datapath 123 without
341          * obtaining a subscription for ofp_packet_in or ofp_flow_expired
342          * messages.  That's what we want here; management connections should
343          * not receive those messages, at least by default. */
344         vconn_name = xasprintf("nl:%d:0", nl_index);
345     } else {
346         /* We don't have a way to specify not to subscribe to those messages
347          * for other transports.  (That's a defect: really this should be in
348          * the OpenFlow protocol, not the Netlink transport). */
349         VLOG_WARN_RL(&rl, "new management connection will receive "
350                      "asynchronous messages");
351         vconn_name = xstrdup(s->dp_name);
352     }
353
354     retval = vconn_open(vconn_name, OFP_VERSION, &new_local);
355     if (retval) {
356         VLOG_ERR_RL(&rl, "could not connect to %s (%s)",
357                     vconn_name, strerror(retval));
358         vconn_close(new_remote);
359         free(vconn_name);
360         return NULL;
361     }
362
363     /* Create and return relay. */
364     r1 = rconn_create(0, 0);
365     rconn_connect_unreliably(r1, vconn_name, new_local);
366     free(vconn_name);
367
368     r2 = rconn_create(0, 0);
369     rconn_connect_unreliably(r2, "passive", new_remote);
370
371     return relay_create(r1, r2, true);
372 }
373
374 static struct relay *
375 relay_create(struct rconn *local, struct rconn *remote, bool is_mgmt_conn)
376 {
377     struct relay *r = xcalloc(1, sizeof *r);
378     r->halves[HALF_LOCAL].rconn = local;
379     r->halves[HALF_REMOTE].rconn = remote;
380     r->is_mgmt_conn = is_mgmt_conn;
381     return r;
382 }
383
384 static void
385 relay_run(struct relay *r, const struct hook hooks[], size_t n_hooks)
386 {
387     int iteration;
388     int i;
389
390     for (i = 0; i < 2; i++) {
391         rconn_run(r->halves[i].rconn);
392     }
393
394     /* Limit the number of iterations to prevent other tasks from starving. */
395     for (iteration = 0; iteration < 50; iteration++) {
396         bool progress = false;
397         for (i = 0; i < 2; i++) {
398             struct half *this = &r->halves[i];
399             struct half *peer = &r->halves[!i];
400
401             if (!this->rxbuf) {
402                 this->rxbuf = rconn_recv(this->rconn);
403                 if (this->rxbuf && (i == HALF_REMOTE || !r->is_mgmt_conn)) {
404                     const struct hook *h;
405                     for (h = hooks; h < &hooks[n_hooks]; h++) {
406                         if (h->packet_cb[i] && h->packet_cb[i](r, h->aux)) {
407                             ofpbuf_delete(this->rxbuf);
408                             this->rxbuf = NULL;
409                             progress = true;
410                             break;
411                         }
412                     }
413                 }
414             }
415
416             if (this->rxbuf && !this->n_txq) {
417                 int retval = rconn_send(peer->rconn, this->rxbuf,
418                                         &this->n_txq);
419                 if (retval != EAGAIN) {
420                     if (!retval) {
421                         progress = true;
422                     } else {
423                         ofpbuf_delete(this->rxbuf);
424                     }
425                     this->rxbuf = NULL;
426                 }
427             }
428         }
429         if (!progress) {
430             break;
431         }
432     }
433
434     if (r->is_mgmt_conn) {
435         for (i = 0; i < 2; i++) {
436             struct half *this = &r->halves[i];
437             if (!rconn_is_alive(this->rconn)) {
438                 relay_destroy(r);
439                 return;
440             }
441         }
442     }
443 }
444
445 static void
446 relay_wait(struct relay *r)
447 {
448     int i;
449
450     for (i = 0; i < 2; i++) {
451         struct half *this = &r->halves[i];
452
453         rconn_run_wait(this->rconn);
454         if (!this->rxbuf) {
455             rconn_recv_wait(this->rconn);
456         }
457     }
458 }
459
460 static void
461 relay_destroy(struct relay *r)
462 {
463     int i;
464
465     list_remove(&r->node);
466     for (i = 0; i < 2; i++) {
467         struct half *this = &r->halves[i];
468         rconn_destroy(this->rconn);
469         ofpbuf_delete(this->rxbuf);
470     }
471     free(r);
472 }
473 \f
474 /* User interface. */
475
476 static void
477 parse_options(int argc, char *argv[], struct settings *s)
478 {
479     enum {
480         OPT_ACCEPT_VCONN = UCHAR_MAX + 1,
481         OPT_NO_RESOLV_CONF,
482         OPT_INACTIVITY_PROBE,
483         OPT_MAX_IDLE,
484         OPT_MAX_BACKOFF,
485         OPT_RATE_LIMIT,
486         OPT_BURST_LIMIT,
487         OPT_BOOTSTRAP_CA_CERT,
488         OPT_STP,
489         OPT_NO_STP,
490         OPT_OUT_OF_BAND,
491         OPT_IN_BAND,
492         VLOG_OPTION_ENUMS
493     };
494     static struct option long_options[] = {
495         {"accept-vconn", required_argument, 0, OPT_ACCEPT_VCONN},
496         {"no-resolv-conf", no_argument, 0, OPT_NO_RESOLV_CONF},
497         {"fail",        required_argument, 0, 'F'},
498         {"inactivity-probe", required_argument, 0, OPT_INACTIVITY_PROBE},
499         {"max-idle",    required_argument, 0, OPT_MAX_IDLE},
500         {"max-backoff", required_argument, 0, OPT_MAX_BACKOFF},
501         {"listen",      required_argument, 0, 'l'},
502         {"monitor",     required_argument, 0, 'm'},
503         {"rate-limit",  optional_argument, 0, OPT_RATE_LIMIT},
504         {"burst-limit", required_argument, 0, OPT_BURST_LIMIT},
505         {"stp",         no_argument, 0, OPT_STP},
506         {"no-stp",      no_argument, 0, OPT_NO_STP},
507         {"out-of-band", no_argument, 0, OPT_OUT_OF_BAND},
508         {"in-band",     no_argument, 0, OPT_IN_BAND},
509         {"verbose",     optional_argument, 0, 'v'},
510         {"help",        no_argument, 0, 'h'},
511         {"version",     no_argument, 0, 'V'},
512         DAEMON_LONG_OPTIONS,
513         VLOG_LONG_OPTIONS,
514 #ifdef HAVE_OPENSSL
515         VCONN_SSL_LONG_OPTIONS
516         {"bootstrap-ca-cert", required_argument, 0, OPT_BOOTSTRAP_CA_CERT},
517 #endif
518         {0, 0, 0, 0},
519     };
520     char *short_options = long_options_to_short_options(long_options);
521     char *accept_re = NULL;
522     int retval;
523
524     /* Set defaults that we can figure out before parsing options. */
525     s->n_listeners = 0;
526     s->monitor_name = NULL;
527     s->fail_mode = FAIL_OPEN;
528     s->max_idle = 15;
529     s->probe_interval = 15;
530     s->max_backoff = 15;
531     s->update_resolv_conf = true;
532     s->rate_limit = 0;
533     s->burst_limit = 0;
534     s->enable_stp = false;
535     s->in_band = true;
536     for (;;) {
537         int c;
538
539         c = getopt_long(argc, argv, short_options, long_options, NULL);
540         if (c == -1) {
541             break;
542         }
543
544         switch (c) {
545         case OPT_ACCEPT_VCONN:
546             accept_re = optarg[0] == '^' ? optarg : xasprintf("^%s", optarg);
547             break;
548
549         case OPT_NO_RESOLV_CONF:
550             s->update_resolv_conf = false;
551             break;
552
553         case 'F':
554             if (!strcmp(optarg, "open")) {
555                 s->fail_mode = FAIL_OPEN;
556             } else if (!strcmp(optarg, "closed")) {
557                 s->fail_mode = FAIL_CLOSED;
558             } else {
559                 ofp_fatal(0, "-f or --fail argument must be \"open\" "
560                           "or \"closed\"");
561             }
562             break;
563
564         case OPT_INACTIVITY_PROBE:
565             s->probe_interval = atoi(optarg);
566             if (s->probe_interval < 5) {
567                 ofp_fatal(0, "--inactivity-probe argument must be at least 5");
568             }
569             break;
570
571         case OPT_MAX_IDLE:
572             if (!strcmp(optarg, "permanent")) {
573                 s->max_idle = OFP_FLOW_PERMANENT;
574             } else {
575                 s->max_idle = atoi(optarg);
576                 if (s->max_idle < 1 || s->max_idle > 65535) {
577                     ofp_fatal(0, "--max-idle argument must be between 1 and "
578                               "65535 or the word 'permanent'");
579                 }
580             }
581             break;
582
583         case OPT_MAX_BACKOFF:
584             s->max_backoff = atoi(optarg);
585             if (s->max_backoff < 1) {
586                 ofp_fatal(0, "--max-backoff argument must be at least 1");
587             } else if (s->max_backoff > 3600) {
588                 s->max_backoff = 3600;
589             }
590             break;
591
592         case OPT_RATE_LIMIT:
593             if (optarg) {
594                 s->rate_limit = atoi(optarg);
595                 if (s->rate_limit < 1) {
596                     ofp_fatal(0, "--rate-limit argument must be at least 1");
597                 }
598             } else {
599                 s->rate_limit = 1000;
600             }
601             break;
602
603         case OPT_BURST_LIMIT:
604             s->burst_limit = atoi(optarg);
605             if (s->burst_limit < 1) {
606                 ofp_fatal(0, "--burst-limit argument must be at least 1");
607             }
608             break;
609
610         case OPT_STP:
611             s->enable_stp = true;
612             break;
613
614         case OPT_NO_STP:
615             s->enable_stp = false;
616             break;
617
618         case OPT_OUT_OF_BAND:
619             s->in_band = false;
620             break;
621
622         case OPT_IN_BAND:
623             s->in_band = true;
624             break;
625
626         case 'l':
627             if (s->n_listeners >= MAX_MGMT) {
628                 ofp_fatal(0,
629                           "-l or --listen may be specified at most %d times",
630                           MAX_MGMT);
631             }
632             s->listener_names[s->n_listeners++] = optarg;
633             break;
634
635         case 'm':
636             if (s->monitor_name) {
637                 ofp_fatal(0, "-m or --monitor may only be specified once");
638             }
639             s->monitor_name = optarg;
640             break;
641
642         case 'h':
643             usage();
644
645         case 'V':
646             printf("%s "VERSION" compiled "__DATE__" "__TIME__"\n", argv[0]);
647             exit(EXIT_SUCCESS);
648
649         DAEMON_OPTION_HANDLERS
650
651         VLOG_OPTION_HANDLERS
652
653 #ifdef HAVE_OPENSSL
654         VCONN_SSL_OPTION_HANDLERS
655
656         case OPT_BOOTSTRAP_CA_CERT:
657             vconn_ssl_set_ca_cert_file(optarg, true);
658             break;
659 #endif
660
661         case '?':
662             exit(EXIT_FAILURE);
663
664         default:
665             abort();
666         }
667     }
668     free(short_options);
669
670     argc -= optind;
671     argv += optind;
672     if (argc < 1 || argc > 2) {
673         ofp_fatal(0, "need one or two non-option arguments; "
674                   "use --help for usage");
675     }
676
677     /* Local and remote vconns. */
678     s->dp_name = argv[0];
679     s->controller_name = argc > 1 ? xstrdup(argv[1]) : NULL;
680
681     /* Set accept_controller_regex. */
682     if (!accept_re) {
683         accept_re = vconn_ssl_is_configured() ? "^ssl:.*" : ".*";
684     }
685     retval = regcomp(&s->accept_controller_regex, accept_re,
686                      REG_NOSUB | REG_EXTENDED);
687     if (retval) {
688         size_t length = regerror(retval, &s->accept_controller_regex, NULL, 0);
689         char *buffer = xmalloc(length);
690         regerror(retval, &s->accept_controller_regex, buffer, length);
691         ofp_fatal(0, "%s: %s", accept_re, buffer);
692     }
693     s->accept_controller_re = accept_re;
694
695     /* Mode of operation. */
696     s->discovery = s->controller_name == NULL;
697     if (s->discovery && !s->in_band) {
698         ofp_fatal(0, "Cannot perform discovery with out-of-band control");
699     }
700
701     /* Rate limiting. */
702     if (s->rate_limit) {
703         if (s->rate_limit < 100) {
704             VLOG_WARN("Rate limit set to unusually low value %d",
705                       s->rate_limit);
706         }
707         if (!s->burst_limit) {
708             s->burst_limit = s->rate_limit / 4;
709         }
710         s->burst_limit = MAX(s->burst_limit, 1);
711         s->burst_limit = MIN(s->burst_limit, INT_MAX / 1000);
712     }
713 }
714
715 static void
716 usage(void)
717 {
718     printf("%s: secure channel, a relay for OpenFlow messages.\n"
719            "usage: %s [OPTIONS] nl:DP_IDX [CONTROLLER]\n"
720            "where nl:DP_IDX is a datapath that has been added with dpctl.\n"
721            "CONTROLLER is an active OpenFlow connection method; if it is\n"
722            "omitted, then secchan performs controller discovery.\n",
723            program_name, program_name);
724     vconn_usage(true, true, true);
725     printf("\nController discovery options:\n"
726            "  --accept-vconn=REGEX    accept matching discovered controllers\n"
727            "  --no-resolv-conf        do not update /etc/resolv.conf\n"
728            "\nNetworking options:\n"
729            "  -F, --fail=open|closed  when controller connection fails:\n"
730            "                            closed: drop all packets\n"
731            "                            open (default): act as learning switch\n"
732            "  --inactivity-probe=SECS time between inactivity probes\n"
733            "  --max-idle=SECS         max idle for flows set up by secchan\n"
734            "  --max-backoff=SECS      max time between controller connection\n"
735            "                          attempts (default: 15 seconds)\n"
736            "  -l, --listen=METHOD     allow management connections on METHOD\n"
737            "                          (a passive OpenFlow connection method)\n"
738            "  -m, --monitor=METHOD    copy traffic to/from kernel to METHOD\n"
739            "                          (a passive OpenFlow connection method)\n"
740            "  --out-of-band           controller connection is out-of-band\n"
741            "  --stp                   enable 802.1D Spanning Tree Protocol\n"
742            "  --no-stp                disable 802.1D Spanning Tree Protocol\n"
743            "\nRate-limiting of \"packet-in\" messages to the controller:\n"
744            "  --rate-limit[=PACKETS]  max rate, in packets/s (default: 1000)\n"
745            "  --burst-limit=BURST     limit on packet credit for idle time\n");
746     daemon_usage();
747     vlog_usage();
748     printf("\nOther options:\n"
749            "  -h, --help              display this help message\n"
750            "  -V, --version           display version information\n");
751     exit(EXIT_SUCCESS);
752 }