2009-07-08 13:19:16 -07:00
|
|
|
/* Copyright (c) 2008, 2009 Nicira Networks
|
|
|
|
*
|
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>
|
|
|
|
|
|
|
|
#include "bridge.h"
|
|
|
|
#include "command-line.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "daemon.h"
|
2009-06-19 14:09:09 -07:00
|
|
|
#include "dpif.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 "proc-net-compat.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"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "svec.h"
|
|
|
|
#include "timeval.h"
|
|
|
|
#include "unixctl.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "vconn.h"
|
2009-12-03 11:28:40 -08:00
|
|
|
#include "vswitchd/vswitch-idl.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
#include "vlog.h"
|
|
|
|
#define THIS_MODULE VLM_vswitchd
|
|
|
|
|
2009-12-03 11:28:40 -08:00
|
|
|
static const 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;
|
2009-12-03 11:28:40 -08:00
|
|
|
struct ovsdb_idl *idl;
|
|
|
|
const char *remote;
|
|
|
|
bool need_reconfigure;
|
|
|
|
bool inited;
|
|
|
|
unsigned int idl_seqno;
|
2009-07-08 13:19:16 -07:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
set_program_name(argv[0]);
|
|
|
|
time_init();
|
|
|
|
vlog_init();
|
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();
|
|
|
|
|
|
|
|
die_if_already_running();
|
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) {
|
|
|
|
ovs_fatal(retval, "could not listen for control connections");
|
|
|
|
}
|
|
|
|
|
2009-12-17 10:56:01 -08:00
|
|
|
daemonize_complete();
|
|
|
|
|
2009-12-03 11:28:40 -08:00
|
|
|
idl = ovsdb_idl_create(remote, &ovsrec_idl_class);
|
|
|
|
idl_seqno = ovsdb_idl_get_seqno(idl);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
need_reconfigure = false;
|
2009-12-03 11:28:40 -08:00
|
|
|
inited = false;
|
2009-07-08 13:19:16 -07:00
|
|
|
for (;;) {
|
2009-12-03 11:28:40 -08:00
|
|
|
if (signal_poll(sighup)) {
|
2009-07-08 13:19:16 -07:00
|
|
|
vlog_reopen_log_file();
|
|
|
|
}
|
2009-12-03 11:28:40 -08:00
|
|
|
if (inited && bridge_run()) {
|
2009-06-19 17:41:42 -07:00
|
|
|
need_reconfigure = true;
|
|
|
|
}
|
2009-12-03 11:28:40 -08:00
|
|
|
ovsdb_idl_run(idl);
|
|
|
|
if (idl_seqno != ovsdb_idl_get_seqno(idl)) {
|
|
|
|
idl_seqno = ovsdb_idl_get_seqno(idl);
|
2009-07-08 13:19:16 -07:00
|
|
|
need_reconfigure = true;
|
|
|
|
}
|
2009-12-03 11:28:40 -08:00
|
|
|
if (need_reconfigure) {
|
|
|
|
const struct ovsrec_open_vswitch *cfg;
|
|
|
|
|
|
|
|
need_reconfigure = false;
|
|
|
|
cfg = ovsrec_open_vswitch_first(idl);
|
|
|
|
if (cfg) {
|
|
|
|
if (inited) {
|
|
|
|
bridge_reconfigure(cfg);
|
|
|
|
} else {
|
|
|
|
bridge_init(cfg);
|
|
|
|
inited = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
unixctl_server_run(unixctl);
|
2009-06-19 14:09:09 -07:00
|
|
|
dp_run();
|
2009-07-30 16:04:45 -07:00
|
|
|
netdev_run();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
signal_wait(sighup);
|
2009-12-03 11:28:40 -08:00
|
|
|
if (inited) {
|
|
|
|
bridge_wait();
|
|
|
|
}
|
|
|
|
ovsdb_idl_wait(idl);
|
2009-07-08 13:19:16 -07:00
|
|
|
unixctl_server_wait(unixctl);
|
2009-06-19 14:09:09 -07:00
|
|
|
dp_wait();
|
2009-07-30 16:04:45 -07:00
|
|
|
netdev_wait();
|
2009-07-08 13:19:16 -07:00
|
|
|
poll_block();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-03 11:28:40 -08:00
|
|
|
static const char *
|
2009-07-08 13:19:16 -07:00
|
|
|
parse_options(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
enum {
|
|
|
|
OPT_PEER_CA_CERT = UCHAR_MAX + 1,
|
|
|
|
OPT_FAKE_PROC_NET,
|
|
|
|
VLOG_OPTION_ENUMS,
|
2009-12-21 13:06:47 -08:00
|
|
|
LEAK_CHECKER_OPTION_ENUMS,
|
|
|
|
OPT_BOOTSTRAP_CA_CERT
|
2009-07-08 13:19:16 -07:00
|
|
|
};
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"version", no_argument, 0, 'V'},
|
|
|
|
{"fake-proc-net", no_argument, 0, OPT_FAKE_PROC_NET},
|
|
|
|
DAEMON_LONG_OPTIONS,
|
|
|
|
VLOG_LONG_OPTIONS,
|
|
|
|
LEAK_CHECKER_LONG_OPTIONS,
|
|
|
|
#ifdef HAVE_OPENSSL
|
2010-01-06 14:35:20 -08:00
|
|
|
STREAM_SSL_LONG_OPTIONS
|
2009-07-08 13:19:16 -07:00
|
|
|
{"peer-ca-cert", required_argument, 0, OPT_PEER_CA_CERT},
|
2009-12-21 13:06:47 -08:00
|
|
|
{"bootstrap-ca-cert", required_argument, 0, OPT_BOOTSTRAP_CA_CERT},
|
2009-07-08 13:19:16 -07:00
|
|
|
#endif
|
|
|
|
{0, 0, 0, 0},
|
|
|
|
};
|
|
|
|
char *short_options = long_options_to_short_options(long_options);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, short_options, long_options, NULL);
|
|
|
|
if (c == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'H':
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
|
|
|
case OPT_FAKE_PROC_NET:
|
|
|
|
error = proc_net_compat_init();
|
|
|
|
if (error) {
|
|
|
|
ovs_fatal(error, "failed to initialize /proc/net "
|
|
|
|
"compatibility");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
VLOG_OPTION_HANDLERS
|
|
|
|
DAEMON_OPTION_HANDLERS
|
|
|
|
LEAK_CHECKER_OPTION_HANDLERS
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENSSL
|
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
|
|
|
#endif
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(short_options);
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc != 1) {
|
2009-12-03 11:28:40 -08:00
|
|
|
ovs_fatal(0, "database socket is only non-option argument; "
|
2009-07-08 13:19:16 -07:00
|
|
|
"use --help for usage");
|
|
|
|
}
|
|
|
|
|
2009-12-03 11:28:40 -08:00
|
|
|
return argv[0];
|
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"
|
2009-12-03 11:28:40 -08:00
|
|
|
"usage: %s [OPTIONS] DATABASE\n"
|
|
|
|
"where DATABASE is a socket on which ovsdb-server is listening.\n",
|
2009-07-08 13:19:16 -07:00
|
|
|
program_name, program_name);
|
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();
|
|
|
|
printf("\nLegacy compatibility options:\n"
|
|
|
|
" --fake-proc-net simulate some files in /proc/net\n"
|
|
|
|
"\nOther options:\n"
|
|
|
|
" -h, --help display this help message\n"
|
|
|
|
" -V, --version display version information\n");
|
|
|
|
leak_checker_usage();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|