]>
Commit | Line | Data |
---|---|---|
74e98efd | 1 | /* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc. |
064af421 | 2 | * |
a14bc59f BP |
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: | |
064af421 | 6 | * |
a14bc59f | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
064af421 | 8 | * |
a14bc59f BP |
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. | |
064af421 BP |
14 | */ |
15 | ||
16 | #include <config.h> | |
17 | ||
064af421 BP |
18 | #include <errno.h> |
19 | #include <getopt.h> | |
20 | #include <limits.h> | |
21 | #include <signal.h> | |
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
86a06318 BP |
24 | #ifdef HAVE_MLOCKALL |
25 | #include <sys/mman.h> | |
26 | #endif | |
064af421 BP |
27 | |
28 | #include "bridge.h" | |
064af421 BP |
29 | #include "command-line.h" |
30 | #include "compiler.h" | |
31 | #include "daemon.h" | |
80df177a | 32 | #include "dirs.h" |
579a77e0 | 33 | #include "dpif.h" |
614c4892 | 34 | #include "dummy.h" |
8a777cf6 | 35 | #include "fatal-signal.h" |
0d085684 | 36 | #include "memory.h" |
8b61709d | 37 | #include "netdev.h" |
3021ea60 | 38 | #include "openflow/openflow.h" |
76343538 | 39 | #include "ovsdb-idl.h" |
9a3cf0ac | 40 | #include "ovs-rcu.h" |
898d7b05 | 41 | #include "ovs-router.h" |
91b8ec6c | 42 | #include "ovs-thread.h" |
fd016ae3 | 43 | #include "openvswitch/poll-loop.h" |
0d085684 | 44 | #include "simap.h" |
fe55ad15 | 45 | #include "stream-ssl.h" |
76343538 | 46 | #include "stream.h" |
064af421 BP |
47 | #include "svec.h" |
48 | #include "timeval.h" | |
49 | #include "unixctl.h" | |
50 | #include "util.h" | |
4a1f523f | 51 | #include "openvswitch/vconn.h" |
e6211adc | 52 | #include "openvswitch/vlog.h" |
eaa67ba8 | 53 | #include "lib/vswitch-idl.h" |
064af421 | 54 | |
d98e6007 | 55 | VLOG_DEFINE_THIS_MODULE(vswitchd); |
064af421 | 56 | |
908ff19a BP |
57 | /* --mlockall: If set, locks all process memory into physical RAM, preventing |
58 | * the kernel from paging any of its memory to disk. */ | |
59 | static bool want_mlockall; | |
60 | ||
9e15c889 BP |
61 | static unixctl_cb_func ovs_vswitchd_exit; |
62 | ||
3542148e | 63 | static char *parse_options(int argc, char *argv[], char **unixctl_path); |
cab50449 | 64 | OVS_NO_RETURN static void usage(void); |
064af421 | 65 | |
fe13ccdc AZ |
66 | struct ovs_vswitchd_exit_args { |
67 | bool *exiting; | |
68 | bool *cleanup; | |
69 | }; | |
70 | ||
064af421 BP |
71 | int |
72 | main(int argc, char *argv[]) | |
73 | { | |
3542148e | 74 | char *unixctl_path = NULL; |
064af421 | 75 | struct unixctl_server *unixctl; |
80df177a | 76 | char *remote; |
fe13ccdc AZ |
77 | bool exiting, cleanup; |
78 | struct ovs_vswitchd_exit_args exit_args = {&exiting, &cleanup}; | |
064af421 BP |
79 | int retval; |
80 | ||
81 | set_program_name(argv[0]); | |
91b8ec6c | 82 | ovsthread_id_init(); |
8a9562d2 | 83 | |
5f383751 | 84 | ovs_cmdl_proctitle_init(argc, argv); |
42dd41ef | 85 | service_start(&argc, &argv); |
3542148e | 86 | remote = parse_options(argc, argv, &unixctl_path); |
8a777cf6 | 87 | fatal_ignore_sigpipe(); |
064af421 | 88 | |
e91b927d | 89 | daemonize_start(true); |
064af421 | 90 | |
908ff19a BP |
91 | if (want_mlockall) { |
92 | #ifdef HAVE_MLOCKALL | |
93 | if (mlockall(MCL_CURRENT | MCL_FUTURE)) { | |
10a89ef0 | 94 | VLOG_ERR("mlockall failed: %s", ovs_strerror(errno)); |
908ff19a BP |
95 | } |
96 | #else | |
97 | VLOG_ERR("mlockall not supported on this system"); | |
98 | #endif | |
99 | } | |
100 | ||
3542148e | 101 | retval = unixctl_server_create(unixctl_path, &unixctl); |
064af421 | 102 | if (retval) { |
4d12270a | 103 | exit(EXIT_FAILURE); |
064af421 | 104 | } |
fe13ccdc AZ |
105 | unixctl_command_register("exit", "[--cleanup]", 0, 1, |
106 | ovs_vswitchd_exit, &exit_args); | |
064af421 | 107 | |
c5187f17 | 108 | bridge_init(remote); |
80df177a BP |
109 | free(remote); |
110 | ||
9e15c889 | 111 | exiting = false; |
fe13ccdc | 112 | cleanup = false; |
9e15c889 | 113 | while (!exiting) { |
0d085684 BP |
114 | memory_run(); |
115 | if (memory_should_report()) { | |
116 | struct simap usage; | |
117 | ||
118 | simap_init(&usage); | |
119 | bridge_get_memory_usage(&usage); | |
120 | memory_report(&usage); | |
121 | simap_destroy(&usage); | |
122 | } | |
c5187f17 | 123 | bridge_run(); |
064af421 | 124 | unixctl_server_run(unixctl); |
8b61709d | 125 | netdev_run(); |
064af421 | 126 | |
0d085684 | 127 | memory_wait(); |
c5187f17 | 128 | bridge_wait(); |
064af421 | 129 | unixctl_server_wait(unixctl); |
8b61709d | 130 | netdev_wait(); |
6d37aaf1 BP |
131 | if (exiting) { |
132 | poll_immediate_wake(); | |
133 | } | |
064af421 | 134 | poll_block(); |
42dd41ef GS |
135 | if (should_service_stop()) { |
136 | exiting = true; | |
137 | } | |
064af421 | 138 | } |
fe13ccdc | 139 | bridge_exit(cleanup); |
ee45ad81 | 140 | unixctl_server_destroy(unixctl); |
42dd41ef | 141 | service_stop(); |
93f55842 | 142 | vlog_disable_async(); |
9a3cf0ac | 143 | ovsrcu_exit(); |
064af421 BP |
144 | |
145 | return 0; | |
146 | } | |
147 | ||
80df177a | 148 | static char * |
3542148e | 149 | parse_options(int argc, char *argv[], char **unixctl_pathp) |
064af421 BP |
150 | { |
151 | enum { | |
152 | OPT_PEER_CA_CERT = UCHAR_MAX + 1, | |
86a06318 | 153 | OPT_MLOCKALL, |
3542148e | 154 | OPT_UNIXCTL, |
064af421 | 155 | VLOG_OPTION_ENUMS, |
614c4892 | 156 | OPT_BOOTSTRAP_CA_CERT, |
8274ae95 | 157 | OPT_ENABLE_DUMMY, |
579a77e0 | 158 | OPT_DISABLE_SYSTEM, |
8a9562d2 PS |
159 | DAEMON_OPTION_ENUMS, |
160 | OPT_DPDK, | |
e18a1d08 | 161 | SSL_OPTION_ENUMS, |
b4e28b7f | 162 | OPT_DUMMY_NUMA, |
064af421 | 163 | }; |
07fc4ed3 | 164 | static const struct option long_options[] = { |
e3c17733 BP |
165 | {"help", no_argument, NULL, 'h'}, |
166 | {"version", no_argument, NULL, 'V'}, | |
167 | {"mlockall", no_argument, NULL, OPT_MLOCKALL}, | |
3542148e | 168 | {"unixctl", required_argument, NULL, OPT_UNIXCTL}, |
064af421 BP |
169 | DAEMON_LONG_OPTIONS, |
170 | VLOG_LONG_OPTIONS, | |
bf8f2167 | 171 | STREAM_SSL_LONG_OPTIONS, |
e3c17733 BP |
172 | {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT}, |
173 | {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, | |
0cbfe35d | 174 | {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY}, |
579a77e0 | 175 | {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM}, |
bab69409 | 176 | {"dpdk", optional_argument, NULL, OPT_DPDK}, |
b4e28b7f | 177 | {"dummy-numa", required_argument, NULL, OPT_DUMMY_NUMA}, |
e3c17733 | 178 | {NULL, 0, NULL, 0}, |
064af421 | 179 | }; |
5f383751 | 180 | char *short_options = ovs_cmdl_long_options_to_short_options(long_options); |
064af421 BP |
181 | |
182 | for (;;) { | |
183 | int c; | |
184 | ||
185 | c = getopt_long(argc, argv, short_options, long_options, NULL); | |
186 | if (c == -1) { | |
187 | break; | |
188 | } | |
189 | ||
190 | switch (c) { | |
064af421 BP |
191 | case 'h': |
192 | usage(); | |
193 | ||
194 | case 'V': | |
11b06842 | 195 | ovs_print_version(0, 0); |
40c23a57 | 196 | print_dpdk_version(); |
064af421 BP |
197 | exit(EXIT_SUCCESS); |
198 | ||
86a06318 | 199 | case OPT_MLOCKALL: |
908ff19a | 200 | want_mlockall = true; |
86a06318 BP |
201 | break; |
202 | ||
3542148e AL |
203 | case OPT_UNIXCTL: |
204 | *unixctl_pathp = optarg; | |
205 | break; | |
206 | ||
064af421 BP |
207 | VLOG_OPTION_HANDLERS |
208 | DAEMON_OPTION_HANDLERS | |
fe55ad15 BP |
209 | STREAM_SSL_OPTION_HANDLERS |
210 | ||
064af421 | 211 | case OPT_PEER_CA_CERT: |
fe55ad15 | 212 | stream_ssl_set_peer_ca_cert_file(optarg); |
064af421 | 213 | break; |
6f61c75b BP |
214 | |
215 | case OPT_BOOTSTRAP_CA_CERT: | |
216 | stream_ssl_set_ca_cert_file(optarg, true); | |
217 | break; | |
064af421 | 218 | |
614c4892 | 219 | case OPT_ENABLE_DUMMY: |
8420c7ad | 220 | dummy_enable(optarg); |
614c4892 BP |
221 | break; |
222 | ||
579a77e0 EJ |
223 | case OPT_DISABLE_SYSTEM: |
224 | dp_blacklist_provider("system"); | |
898d7b05 | 225 | ovs_router_disable_system_routing_table(); |
579a77e0 EJ |
226 | break; |
227 | ||
064af421 BP |
228 | case '?': |
229 | exit(EXIT_FAILURE); | |
230 | ||
8a9562d2 | 231 | case OPT_DPDK: |
bab69409 | 232 | ovs_fatal(0, "Using --dpdk to configure DPDK is not supported."); |
8a9562d2 PS |
233 | break; |
234 | ||
b4e28b7f DDP |
235 | case OPT_DUMMY_NUMA: |
236 | ovs_numa_set_dummy(optarg); | |
237 | break; | |
238 | ||
064af421 BP |
239 | default: |
240 | abort(); | |
241 | } | |
242 | } | |
243 | free(short_options); | |
244 | ||
245 | argc -= optind; | |
246 | argv += optind; | |
247 | ||
80df177a BP |
248 | switch (argc) { |
249 | case 0: | |
250 | return xasprintf("unix:%s/db.sock", ovs_rundir()); | |
251 | ||
252 | case 1: | |
253 | return xstrdup(argv[0]); | |
254 | ||
255 | default: | |
256 | VLOG_FATAL("at most one non-option argument accepted; " | |
279c9e03 | 257 | "use --help for usage"); |
064af421 | 258 | } |
064af421 BP |
259 | } |
260 | ||
261 | static void | |
262 | usage(void) | |
263 | { | |
f30f26be | 264 | printf("%s: Open vSwitch daemon\n" |
80df177a BP |
265 | "usage: %s [OPTIONS] [DATABASE]\n" |
266 | "where DATABASE is a socket on which ovsdb-server is listening\n" | |
267 | " (default: \"unix:%s/db.sock\").\n", | |
268 | program_name, program_name, ovs_rundir()); | |
9467fe62 | 269 | stream_usage("DATABASE", true, false, true); |
064af421 BP |
270 | daemon_usage(); |
271 | vlog_usage(); | |
d1279464 | 272 | printf("\nDPDK options:\n" |
bab69409 AC |
273 | "Configuration of DPDK via command-line is removed from this\n" |
274 | "version of Open vSwitch. DPDK is configured through ovsdb.\n" | |
275 | ); | |
0b8b6f71 | 276 | printf("\nOther options:\n" |
58397e6c KT |
277 | " --unixctl=SOCKET override default control socket name\n" |
278 | " -h, --help display this help message\n" | |
279 | " -V, --version display version information\n"); | |
064af421 BP |
280 | exit(EXIT_SUCCESS); |
281 | } | |
9e15c889 BP |
282 | |
283 | static void | |
fe13ccdc AZ |
284 | ovs_vswitchd_exit(struct unixctl_conn *conn, int argc, |
285 | const char *argv[], void *exit_args_) | |
9e15c889 | 286 | { |
fe13ccdc AZ |
287 | struct ovs_vswitchd_exit_args *exit_args = exit_args_; |
288 | *exit_args->exiting = true; | |
289 | *exit_args->cleanup = argc == 2 && !strcmp(argv[1], "--cleanup"); | |
bde9f75d | 290 | unixctl_command_reply(conn, NULL); |
9e15c889 | 291 | } |