1 /* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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"
41 #include "ovs-router.h"
42 #include "ovs-thread.h"
43 #include "openvswitch/poll-loop.h"
45 #include "stream-ssl.h"
51 #include "openvswitch/vconn.h"
52 #include "openvswitch/vlog.h"
53 #include "lib/vswitch-idl.h"
54 #include "lib/dns-resolve.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 OVS_NO_RETURN
static void usage(void);
67 struct ovs_vswitchd_exit_args
{
73 main(int argc
, char *argv
[])
75 char *unixctl_path
= NULL
;
76 struct unixctl_server
*unixctl
;
78 bool exiting
, cleanup
;
79 struct ovs_vswitchd_exit_args exit_args
= {&exiting
, &cleanup
};
82 set_program_name(argv
[0]);
85 dns_resolve_init(true);
86 ovs_cmdl_proctitle_init(argc
, argv
);
87 service_start(&argc
, &argv
);
88 remote
= parse_options(argc
, argv
, &unixctl_path
);
89 fatal_ignore_sigpipe();
91 daemonize_start(true);
95 if (mlockall(MCL_CURRENT
| MCL_FUTURE
)) {
96 VLOG_ERR("mlockall failed: %s", ovs_strerror(errno
));
101 VLOG_ERR("mlockall not supported on this system");
105 retval
= unixctl_server_create(unixctl_path
, &unixctl
);
109 unixctl_command_register("exit", "[--cleanup]", 0, 1,
110 ovs_vswitchd_exit
, &exit_args
);
119 if (memory_should_report()) {
123 bridge_get_memory_usage(&usage
);
124 memory_report(&usage
);
125 simap_destroy(&usage
);
128 unixctl_server_run(unixctl
);
133 unixctl_server_wait(unixctl
);
136 poll_immediate_wake();
139 if (should_service_stop()) {
143 bridge_exit(cleanup
);
144 unixctl_server_destroy(unixctl
);
146 vlog_disable_async();
148 dns_resolve_destroy();
154 parse_options(int argc
, char *argv
[], char **unixctl_pathp
)
157 OPT_PEER_CA_CERT
= UCHAR_MAX
+ 1,
161 OPT_BOOTSTRAP_CA_CERT
,
164 OPT_DISABLE_SYSTEM_ROUTE
,
170 static const struct option long_options
[] = {
171 {"help", no_argument
, NULL
, 'h'},
172 {"version", no_argument
, NULL
, 'V'},
173 {"mlockall", no_argument
, NULL
, OPT_MLOCKALL
},
174 {"unixctl", required_argument
, NULL
, OPT_UNIXCTL
},
177 STREAM_SSL_LONG_OPTIONS
,
178 {"peer-ca-cert", required_argument
, NULL
, OPT_PEER_CA_CERT
},
179 {"bootstrap-ca-cert", required_argument
, NULL
, OPT_BOOTSTRAP_CA_CERT
},
180 {"enable-dummy", optional_argument
, NULL
, OPT_ENABLE_DUMMY
},
181 {"disable-system", no_argument
, NULL
, OPT_DISABLE_SYSTEM
},
182 {"disable-system-route", no_argument
, NULL
, OPT_DISABLE_SYSTEM_ROUTE
},
183 {"dpdk", optional_argument
, NULL
, OPT_DPDK
},
184 {"dummy-numa", required_argument
, NULL
, OPT_DUMMY_NUMA
},
187 char *short_options
= ovs_cmdl_long_options_to_short_options(long_options
);
192 c
= getopt_long(argc
, argv
, short_options
, long_options
, NULL
);
202 ovs_print_version(0, 0);
203 print_dpdk_version();
207 want_mlockall
= true;
211 *unixctl_pathp
= optarg
;
215 DAEMON_OPTION_HANDLERS
216 STREAM_SSL_OPTION_HANDLERS
218 case OPT_PEER_CA_CERT
:
219 stream_ssl_set_peer_ca_cert_file(optarg
);
222 case OPT_BOOTSTRAP_CA_CERT
:
223 stream_ssl_set_ca_cert_file(optarg
, true);
226 case OPT_ENABLE_DUMMY
:
227 dummy_enable(optarg
);
230 case OPT_DISABLE_SYSTEM
:
231 dp_disallow_provider("system");
234 case OPT_DISABLE_SYSTEM_ROUTE
:
235 ovs_router_disable_system_routing_table();
242 ovs_fatal(0, "Using --dpdk to configure DPDK is not supported.");
246 ovs_numa_set_dummy(optarg
);
260 return xasprintf("unix:%s/db.sock", ovs_rundir());
263 return xstrdup(argv
[0]);
266 VLOG_FATAL("at most one non-option argument accepted; "
267 "use --help for usage");
274 printf("%s: Open vSwitch daemon\n"
275 "usage: %s [OPTIONS] [DATABASE]\n"
276 "where DATABASE is a socket on which ovsdb-server is listening\n"
277 " (default: \"unix:%s/db.sock\").\n",
278 program_name
, program_name
, ovs_rundir());
279 stream_usage("DATABASE", true, false, true);
282 printf("\nDPDK options:\n"
283 "Configuration of DPDK via command-line is removed from this\n"
284 "version of Open vSwitch. DPDK is configured through ovsdb.\n"
286 printf("\nOther options:\n"
287 " --unixctl=SOCKET override default control socket name\n"
288 " -h, --help display this help message\n"
289 " -V, --version display version information\n");
294 ovs_vswitchd_exit(struct unixctl_conn
*conn
, int argc
,
295 const char *argv
[], void *exit_args_
)
297 struct ovs_vswitchd_exit_args
*exit_args
= exit_args_
;
298 *exit_args
->exiting
= true;
299 *exit_args
->cleanup
= argc
== 2 && !strcmp(argv
[1], "--cleanup");
300 unixctl_command_reply(conn
, NULL
);