1 /* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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 "fatal-signal.h"
38 #include "openflow/openflow.h"
39 #include "ovsdb-idl.h"
40 #include "poll-loop.h"
42 #include "stream-ssl.h"
48 #include "openvswitch/vconn.h"
49 #include "openvswitch/vlog.h"
50 #include "lib/vswitch-idl.h"
52 VLOG_DEFINE_THIS_MODULE(vswitchd);
54 /* --mlockall: If set, locks all process memory into physical RAM, preventing
55 * the kernel from paging any of its memory to disk. */
56 static bool want_mlockall;
58 static unixctl_cb_func ovs_vswitchd_exit;
60 static char *parse_options(int argc, char *argv[], char **unixctl_path);
61 OVS_NO_RETURN static void usage(void);
64 main(int argc, char *argv[])
66 char *unixctl_path = NULL;
67 struct unixctl_server *unixctl;
72 set_program_name(argv[0]);
74 ovs_cmdl_proctitle_init(argc, argv);
75 service_start(&argc, &argv);
76 remote = parse_options(argc, argv, &unixctl_path);
77 fatal_ignore_sigpipe();
80 daemonize_start(true);
84 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
85 VLOG_ERR("mlockall failed: %s", ovs_strerror(errno));
88 VLOG_ERR("mlockall not supported on this system");
92 retval = unixctl_server_create(unixctl_path, &unixctl);
96 unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting);
104 if (memory_should_report()) {
108 bridge_get_memory_usage(&usage);
109 memory_report(&usage);
110 simap_destroy(&usage);
113 unixctl_server_run(unixctl);
118 unixctl_server_wait(unixctl);
121 poll_immediate_wake();
124 if (should_service_stop()) {
129 unixctl_server_destroy(unixctl);
136 parse_options(int argc, char *argv[], char **unixctl_pathp)
139 OPT_PEER_CA_CERT = UCHAR_MAX + 1,
143 OPT_BOOTSTRAP_CA_CERT,
150 static const struct option long_options[] = {
151 {"help", no_argument, NULL, 'h'},
152 {"version", no_argument, NULL, 'V'},
153 {"mlockall", no_argument, NULL, OPT_MLOCKALL},
154 {"unixctl", required_argument, NULL, OPT_UNIXCTL},
157 STREAM_SSL_LONG_OPTIONS,
158 {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
159 {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
160 {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
161 {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM},
162 {"dpdk", optional_argument, NULL, OPT_DPDK},
163 {"dummy-numa", required_argument, NULL, OPT_DUMMY_NUMA},
166 char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
171 c = getopt_long(argc, argv, short_options, long_options, NULL);
181 ovs_print_version(0, 0);
185 want_mlockall = true;
189 *unixctl_pathp = optarg;
193 DAEMON_OPTION_HANDLERS
194 STREAM_SSL_OPTION_HANDLERS
196 case OPT_PEER_CA_CERT:
197 stream_ssl_set_peer_ca_cert_file(optarg);
200 case OPT_BOOTSTRAP_CA_CERT:
201 stream_ssl_set_ca_cert_file(optarg, true);
204 case OPT_ENABLE_DUMMY:
205 dummy_enable(optarg);
208 case OPT_DISABLE_SYSTEM:
209 dp_blacklist_provider("system");
216 ovs_fatal(0, "Using --dpdk to configure DPDK is not supported.");
220 ovs_numa_set_dummy(optarg);
234 return xasprintf("unix:%s/db.sock", ovs_rundir());
237 return xstrdup(argv[0]);
240 VLOG_FATAL("at most one non-option argument accepted; "
241 "use --help for usage");
248 printf("%s: Open vSwitch daemon\n"
249 "usage: %s [OPTIONS] [DATABASE]\n"
250 "where DATABASE is a socket on which ovsdb-server is listening\n"
251 " (default: \"unix:%s/db.sock\").\n",
252 program_name, program_name, ovs_rundir());
253 stream_usage("DATABASE", true, false, true);
256 printf("\nDPDK options:\n"
257 "Configuration of DPDK via command-line is removed from this\n"
258 "version of Open vSwitch. DPDK is configured through ovsdb.\n"
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");
268 ovs_vswitchd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
269 const char *argv[] OVS_UNUSED, void *exiting_)
271 bool *exiting = exiting_;
273 unixctl_command_reply(conn, NULL);