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.
29 #include "command-line.h"
35 #include "leak-checker.h"
38 #include "openflow/openflow.h"
39 #include "ovsdb-idl.h"
40 #include "poll-loop.h"
44 #include "stream-ssl.h"
53 #include "lib/vswitch-idl.h"
56 VLOG_DEFINE_THIS_MODULE(vswitchd);
58 /* --mlockall: If set, locks all process memory into physical RAM, preventing
59 * the kernel from paging any of its memory to disk. */
60 static bool want_mlockall;
62 static unixctl_cb_func ovs_vswitchd_exit;
64 static char *parse_options(int argc, char *argv[], char **unixctl_path);
65 static void usage(void) NO_RETURN;
68 main(int argc, char *argv[])
70 char *unixctl_path = NULL;
71 struct unixctl_server *unixctl;
72 struct signal *sighup;
77 proctitle_init(argc, argv);
78 set_program_name(argv[0]);
79 stress_init_command();
80 remote = parse_options(argc, argv, &unixctl_path);
81 signal(SIGPIPE, SIG_IGN);
82 sighup = signal_register(SIGHUP);
90 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
91 VLOG_ERR("mlockall failed: %s", strerror(errno));
94 VLOG_ERR("mlockall not supported on this system");
100 retval = unixctl_server_create(unixctl_path, &unixctl);
104 unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting);
112 if (signal_poll(sighup)) {
113 vlog_reopen_log_file();
116 if (memory_should_report()) {
120 bridge_get_memory_usage(&usage);
121 memory_report(&usage);
122 simap_destroy(&usage);
127 unixctl_server_run(unixctl);
134 unixctl_server_wait(unixctl);
137 poll_immediate_wake();
142 unixctl_server_destroy(unixctl);
143 signal_unregister(sighup);
149 parse_options(int argc, char *argv[], char **unixctl_pathp)
152 OPT_PEER_CA_CERT = UCHAR_MAX + 1,
156 LEAK_CHECKER_OPTION_ENUMS,
157 OPT_BOOTSTRAP_CA_CERT,
162 static struct option long_options[] = {
163 {"help", no_argument, NULL, 'h'},
164 {"version", no_argument, NULL, 'V'},
165 {"mlockall", no_argument, NULL, OPT_MLOCKALL},
166 {"unixctl", required_argument, NULL, OPT_UNIXCTL},
169 LEAK_CHECKER_LONG_OPTIONS,
170 STREAM_SSL_LONG_OPTIONS,
171 {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
172 {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
173 {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
174 {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM},
177 char *short_options = long_options_to_short_options(long_options);
182 c = getopt_long(argc, argv, short_options, long_options, NULL);
192 ovs_print_version(OFP10_VERSION, OFP10_VERSION);
196 want_mlockall = true;
200 *unixctl_pathp = optarg;
204 DAEMON_OPTION_HANDLERS
205 LEAK_CHECKER_OPTION_HANDLERS
206 STREAM_SSL_OPTION_HANDLERS
208 case OPT_PEER_CA_CERT:
209 stream_ssl_set_peer_ca_cert_file(optarg);
212 case OPT_BOOTSTRAP_CA_CERT:
213 stream_ssl_set_ca_cert_file(optarg, true);
216 case OPT_ENABLE_DUMMY:
217 dummy_enable(optarg && !strcmp(optarg, "override"));
220 case OPT_DISABLE_SYSTEM:
221 dp_blacklist_provider("system");
238 return xasprintf("unix:%s/db.sock", ovs_rundir());
241 return xstrdup(argv[0]);
244 VLOG_FATAL("at most one non-option argument accepted; "
245 "use --help for usage");
252 printf("%s: Open vSwitch daemon\n"
253 "usage: %s [OPTIONS] [DATABASE]\n"
254 "where DATABASE is a socket on which ovsdb-server is listening\n"
255 " (default: \"unix:%s/db.sock\").\n",
256 program_name, program_name, ovs_rundir());
257 stream_usage("DATABASE", true, false, true);
260 printf("\nOther options:\n"
261 " --unixctl=SOCKET override default control socket name\n"
262 " -h, --help display this help message\n"
263 " -V, --version display version information\n");
264 leak_checker_usage();
269 ovs_vswitchd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
270 const char *argv[] OVS_UNUSED, void *exiting_)
272 bool *exiting = exiting_;
274 unixctl_command_reply(conn, NULL);