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