2011-01-28 12:44:00 -08:00
|
|
|
/* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-07-08 13:19:16 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-11-30 13:17:34 -08:00
|
|
|
#ifdef HAVE_MLOCKALL
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
#include "bridge.h"
|
|
|
|
#include "command-line.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "daemon.h"
|
2011-07-26 10:13:07 -07:00
|
|
|
#include "dirs.h"
|
2010-11-29 12:21:08 -08:00
|
|
|
#include "dummy.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "leak-checker.h"
|
2009-07-30 16:04:45 -07:00
|
|
|
#include "netdev.h"
|
2009-12-03 11:28:40 -08:00
|
|
|
#include "ovsdb-idl.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "poll-loop.h"
|
|
|
|
#include "process.h"
|
|
|
|
#include "signals.h"
|
2010-01-06 14:35:20 -08:00
|
|
|
#include "stream-ssl.h"
|
2009-12-03 11:28:40 -08:00
|
|
|
#include "stream.h"
|
2010-11-30 13:44:01 -08:00
|
|
|
#include "stress.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "svec.h"
|
|
|
|
#include "timeval.h"
|
|
|
|
#include "unixctl.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "vconn.h"
|
2010-07-16 11:02:49 -07:00
|
|
|
#include "vlog.h"
|
2009-12-03 11:28:40 -08:00
|
|
|
#include "vswitchd/vswitch-idl.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-10-19 14:47:01 -07:00
|
|
|
VLOG_DEFINE_THIS_MODULE(vswitchd);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-05-03 15:43:49 -07:00
|
|
|
static unixctl_cb_func ovs_vswitchd_exit;
|
|
|
|
|
2011-07-26 10:13:07 -07:00
|
|
|
static char *parse_options(int argc, char *argv[]);
|
2009-07-08 13:19:16 -07:00
|
|
|
static void usage(void) NO_RETURN;
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct unixctl_server *unixctl;
|
|
|
|
struct signal *sighup;
|
2011-07-26 10:13:07 -07:00
|
|
|
char *remote;
|
2010-06-10 14:17:41 -07:00
|
|
|
bool exiting;
|
2009-07-08 13:19:16 -07:00
|
|
|
int retval;
|
|
|
|
|
2010-01-19 15:00:56 -08:00
|
|
|
proctitle_init(argc, argv);
|
2009-07-08 13:19:16 -07:00
|
|
|
set_program_name(argv[0]);
|
2010-11-30 13:44:01 -08:00
|
|
|
stress_init_command();
|
2009-12-03 11:28:40 -08:00
|
|
|
remote = parse_options(argc, argv);
|
2009-07-08 13:19:16 -07:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
sighup = signal_register(SIGHUP);
|
|
|
|
process_init();
|
2010-02-08 14:09:36 -08:00
|
|
|
ovsrec_init();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2009-12-17 10:56:01 -08:00
|
|
|
daemonize_start();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
retval = unixctl_server_create(NULL, &unixctl);
|
|
|
|
if (retval) {
|
2010-01-15 10:31:57 -08:00
|
|
|
exit(EXIT_FAILURE);
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
2011-09-26 14:59:35 -07:00
|
|
|
unixctl_command_register("exit", "", ovs_vswitchd_exit, &exiting);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-06-10 14:17:41 -07:00
|
|
|
bridge_init(remote);
|
2011-07-26 10:13:07 -07:00
|
|
|
free(remote);
|
|
|
|
|
2010-05-03 15:43:49 -07:00
|
|
|
exiting = false;
|
|
|
|
while (!exiting) {
|
2009-12-03 11:28:40 -08:00
|
|
|
if (signal_poll(sighup)) {
|
2009-07-08 13:19:16 -07:00
|
|
|
vlog_reopen_log_file();
|
|
|
|
}
|
2010-06-10 14:17:41 -07:00
|
|
|
bridge_run();
|
2009-07-08 13:19:16 -07:00
|
|
|
unixctl_server_run(unixctl);
|
2009-07-30 16:04:45 -07:00
|
|
|
netdev_run();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
signal_wait(sighup);
|
2010-06-10 14:17:41 -07:00
|
|
|
bridge_wait();
|
2009-07-08 13:19:16 -07:00
|
|
|
unixctl_server_wait(unixctl);
|
2009-07-30 16:04:45 -07:00
|
|
|
netdev_wait();
|
2010-11-16 15:14:58 -08:00
|
|
|
if (exiting) {
|
|
|
|
poll_immediate_wake();
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
poll_block();
|
|
|
|
}
|
2010-12-13 13:08:31 -08:00
|
|
|
bridge_exit();
|
|
|
|
unixctl_server_destroy(unixctl);
|
2011-06-07 13:17:57 -07:00
|
|
|
signal_unregister(sighup);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-26 10:13:07 -07:00
|
|
|
static char *
|
2009-07-08 13:19:16 -07:00
|
|
|
parse_options(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
enum {
|
|
|
|
OPT_PEER_CA_CERT = UCHAR_MAX + 1,
|
2009-11-30 13:17:34 -08:00
|
|
|
OPT_MLOCKALL,
|
2009-07-08 13:19:16 -07:00
|
|
|
VLOG_OPTION_ENUMS,
|
2009-12-21 13:06:47 -08:00
|
|
|
LEAK_CHECKER_OPTION_ENUMS,
|
2010-11-29 12:21:08 -08:00
|
|
|
OPT_BOOTSTRAP_CA_CERT,
|
2011-01-28 12:39:15 -08:00
|
|
|
OPT_ENABLE_DUMMY,
|
|
|
|
DAEMON_OPTION_ENUMS
|
2009-07-08 13:19:16 -07:00
|
|
|
};
|
|
|
|
static struct option long_options[] = {
|
2011-05-04 13:49:42 -07:00
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
{"mlockall", no_argument, NULL, OPT_MLOCKALL},
|
2009-07-08 13:19:16 -07:00
|
|
|
DAEMON_LONG_OPTIONS,
|
|
|
|
VLOG_LONG_OPTIONS,
|
|
|
|
LEAK_CHECKER_LONG_OPTIONS,
|
2011-05-10 09:17:37 -07:00
|
|
|
STREAM_SSL_LONG_OPTIONS,
|
2011-05-04 13:49:42 -07:00
|
|
|
{"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
|
|
|
|
{"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
|
|
|
|
{"enable-dummy", no_argument, NULL, OPT_ENABLE_DUMMY},
|
|
|
|
{NULL, 0, NULL, 0},
|
2009-07-08 13:19:16 -07:00
|
|
|
};
|
|
|
|
char *short_options = long_options_to_short_options(long_options);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, short_options, long_options, NULL);
|
|
|
|
if (c == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
|
|
|
|
case 'V':
|
2011-08-02 12:16:44 -07:00
|
|
|
ovs_print_version(OFP_VERSION, OFP_VERSION);
|
2009-07-08 13:19:16 -07:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
2009-11-30 13:17:34 -08:00
|
|
|
case OPT_MLOCKALL:
|
|
|
|
#ifdef HAVE_MLOCKALL
|
|
|
|
if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
|
|
|
|
VLOG_ERR("mlockall failed: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
VLOG_ERR("mlockall not supported on this system");
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
VLOG_OPTION_HANDLERS
|
|
|
|
DAEMON_OPTION_HANDLERS
|
|
|
|
LEAK_CHECKER_OPTION_HANDLERS
|
2010-01-06 14:35:20 -08:00
|
|
|
STREAM_SSL_OPTION_HANDLERS
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
case OPT_PEER_CA_CERT:
|
2010-01-06 14:35:20 -08:00
|
|
|
stream_ssl_set_peer_ca_cert_file(optarg);
|
2009-07-08 13:19:16 -07:00
|
|
|
break;
|
2009-12-21 13:06:47 -08:00
|
|
|
|
|
|
|
case OPT_BOOTSTRAP_CA_CERT:
|
|
|
|
stream_ssl_set_ca_cert_file(optarg, true);
|
|
|
|
break;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
case OPT_ENABLE_DUMMY:
|
|
|
|
dummy_enable();
|
|
|
|
break;
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(short_options);
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2011-07-26 10:13:07 -07:00
|
|
|
switch (argc) {
|
|
|
|
case 0:
|
|
|
|
return xasprintf("unix:%s/db.sock", ovs_rundir());
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
return xstrdup(argv[0]);
|
|
|
|
|
|
|
|
default:
|
|
|
|
VLOG_FATAL("at most one non-option argument accepted; "
|
2011-03-31 16:23:50 -07:00
|
|
|
"use --help for usage");
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2009-06-23 14:18:43 -07:00
|
|
|
printf("%s: Open vSwitch daemon\n"
|
2011-07-26 10:13:07 -07:00
|
|
|
"usage: %s [OPTIONS] [DATABASE]\n"
|
|
|
|
"where DATABASE is a socket on which ovsdb-server is listening\n"
|
|
|
|
" (default: \"unix:%s/db.sock\").\n",
|
|
|
|
program_name, program_name, ovs_rundir());
|
2009-12-21 13:13:48 -08:00
|
|
|
stream_usage("DATABASE", true, false, true);
|
2009-07-08 13:19:16 -07:00
|
|
|
daemon_usage();
|
|
|
|
vlog_usage();
|
2011-02-11 13:16:28 -08:00
|
|
|
printf("\nOther options:\n"
|
2009-07-08 13:19:16 -07:00
|
|
|
" -h, --help display this help message\n"
|
|
|
|
" -V, --version display version information\n");
|
|
|
|
leak_checker_usage();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2010-05-03 15:43:49 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
ovs_vswitchd_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED,
|
|
|
|
void *exiting_)
|
|
|
|
{
|
|
|
|
bool *exiting = exiting_;
|
|
|
|
*exiting = true;
|
|
|
|
unixctl_command_reply(conn, 200, NULL);
|
|
|
|
}
|