1 /* Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
30 #include "command-line.h"
36 #include "leak-checker.h"
38 #include "openflow/openflow.h"
39 #include "ovsdb-idl.h"
40 #include "poll-loop.h"
43 #include "stream-ssl.h"
52 #include "lib/vswitch-idl.h"
54 VLOG_DEFINE_THIS_MODULE(vswitchd);
56 static unixctl_cb_func ovs_vswitchd_exit;
58 static char *parse_options(int argc, char *argv[], char **unixctl_path);
59 static void usage(void) NO_RETURN;
62 main(int argc, char *argv[])
64 char *unixctl_path = NULL;
65 struct unixctl_server *unixctl;
66 struct signal *sighup;
71 proctitle_init(argc, argv);
72 set_program_name(argv[0]);
73 stress_init_command();
74 remote = parse_options(argc, argv, &unixctl_path);
75 signal(SIGPIPE, SIG_IGN);
76 sighup = signal_register(SIGHUP);
82 retval = unixctl_server_create(unixctl_path, &unixctl);
86 unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting);
93 if (signal_poll(sighup)) {
94 vlog_reopen_log_file();
99 unixctl_server_run(unixctl);
104 unixctl_server_wait(unixctl);
107 poll_immediate_wake();
112 unixctl_server_destroy(unixctl);
113 signal_unregister(sighup);
119 parse_options(int argc, char *argv[], char **unixctl_pathp)
122 OPT_PEER_CA_CERT = UCHAR_MAX + 1,
126 LEAK_CHECKER_OPTION_ENUMS,
127 OPT_BOOTSTRAP_CA_CERT,
132 static struct option long_options[] = {
133 {"help", no_argument, NULL, 'h'},
134 {"version", no_argument, NULL, 'V'},
135 {"mlockall", no_argument, NULL, OPT_MLOCKALL},
136 {"unixctl", required_argument, NULL, OPT_UNIXCTL},
139 LEAK_CHECKER_LONG_OPTIONS,
140 STREAM_SSL_LONG_OPTIONS,
141 {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
142 {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
143 {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
144 {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM},
147 char *short_options = long_options_to_short_options(long_options);
152 c = getopt_long(argc, argv, short_options, long_options, NULL);
162 ovs_print_version(OFP10_VERSION, OFP10_VERSION);
167 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
168 VLOG_ERR("mlockall failed: %s", strerror(errno));
171 VLOG_ERR("mlockall not supported on this system");
176 *unixctl_pathp = optarg;
180 DAEMON_OPTION_HANDLERS
181 LEAK_CHECKER_OPTION_HANDLERS
182 STREAM_SSL_OPTION_HANDLERS
184 case OPT_PEER_CA_CERT:
185 stream_ssl_set_peer_ca_cert_file(optarg);
188 case OPT_BOOTSTRAP_CA_CERT:
189 stream_ssl_set_ca_cert_file(optarg, true);
192 case OPT_ENABLE_DUMMY:
193 dummy_enable(optarg && !strcmp(optarg, "override"));
196 case OPT_DISABLE_SYSTEM:
197 dp_blacklist_provider("system");
214 return xasprintf("unix:%s/db.sock", ovs_rundir());
217 return xstrdup(argv[0]);
220 VLOG_FATAL("at most one non-option argument accepted; "
221 "use --help for usage");
228 printf("%s: Open vSwitch daemon\n"
229 "usage: %s [OPTIONS] [DATABASE]\n"
230 "where DATABASE is a socket on which ovsdb-server is listening\n"
231 " (default: \"unix:%s/db.sock\").\n",
232 program_name, program_name, ovs_rundir());
233 stream_usage("DATABASE", true, false, true);
236 printf("\nOther options:\n"
237 " --unixctl=SOCKET override default control socket name\n"
238 " -h, --help display this help message\n"
239 " -V, --version display version information\n");
240 leak_checker_usage();
245 ovs_vswitchd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
246 const char *argv[] OVS_UNUSED, void *exiting_)
248 bool *exiting = exiting_;
250 unixctl_command_reply(conn, NULL);