]>
Commit | Line | Data |
---|---|---|
a7ff9bd7 | 1 | /* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks |
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 | ||
18 | #include <assert.h> | |
19 | #include <errno.h> | |
20 | #include <getopt.h> | |
21 | #include <limits.h> | |
22 | #include <signal.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
86a06318 BP |
25 | #ifdef HAVE_MLOCKALL |
26 | #include <sys/mman.h> | |
27 | #endif | |
064af421 BP |
28 | |
29 | #include "bridge.h" | |
064af421 BP |
30 | #include "command-line.h" |
31 | #include "compiler.h" | |
32 | #include "daemon.h" | |
5792c5c6 | 33 | #include "dpif.h" |
614c4892 | 34 | #include "dummy.h" |
064af421 | 35 | #include "leak-checker.h" |
8b61709d | 36 | #include "netdev.h" |
76343538 | 37 | #include "ovsdb-idl.h" |
064af421 | 38 | #include "poll-loop.h" |
064af421 BP |
39 | #include "process.h" |
40 | #include "signals.h" | |
fe55ad15 | 41 | #include "stream-ssl.h" |
76343538 | 42 | #include "stream.h" |
cc01d0bb | 43 | #include "stress.h" |
064af421 BP |
44 | #include "svec.h" |
45 | #include "timeval.h" | |
46 | #include "unixctl.h" | |
47 | #include "util.h" | |
064af421 | 48 | #include "vconn.h" |
5136ce49 | 49 | #include "vlog.h" |
76343538 | 50 | #include "vswitchd/vswitch-idl.h" |
064af421 | 51 | |
d98e6007 | 52 | VLOG_DEFINE_THIS_MODULE(vswitchd); |
064af421 | 53 | |
9e15c889 BP |
54 | static unixctl_cb_func ovs_vswitchd_exit; |
55 | ||
76343538 | 56 | static const char *parse_options(int argc, char *argv[]); |
064af421 | 57 | static void usage(void) NO_RETURN; |
064af421 BP |
58 | |
59 | int | |
60 | main(int argc, char *argv[]) | |
61 | { | |
62 | struct unixctl_server *unixctl; | |
63 | struct signal *sighup; | |
76343538 | 64 | const char *remote; |
c5187f17 | 65 | bool exiting; |
064af421 BP |
66 | int retval; |
67 | ||
40f0707c | 68 | proctitle_init(argc, argv); |
064af421 | 69 | set_program_name(argv[0]); |
cc01d0bb | 70 | stress_init_command(); |
76343538 | 71 | remote = parse_options(argc, argv); |
064af421 BP |
72 | signal(SIGPIPE, SIG_IGN); |
73 | sighup = signal_register(SIGHUP); | |
74 | process_init(); | |
bd76d25d | 75 | ovsrec_init(); |
064af421 BP |
76 | |
77 | die_if_already_running(); | |
95440284 | 78 | daemonize_start(); |
064af421 BP |
79 | |
80 | retval = unixctl_server_create(NULL, &unixctl); | |
81 | if (retval) { | |
4d12270a | 82 | exit(EXIT_FAILURE); |
064af421 | 83 | } |
9e15c889 | 84 | unixctl_command_register("exit", ovs_vswitchd_exit, &exiting); |
064af421 | 85 | |
c5187f17 | 86 | bridge_init(remote); |
9e15c889 BP |
87 | exiting = false; |
88 | while (!exiting) { | |
76343538 | 89 | if (signal_poll(sighup)) { |
064af421 | 90 | vlog_reopen_log_file(); |
064af421 | 91 | } |
c5187f17 | 92 | bridge_run(); |
064af421 | 93 | unixctl_server_run(unixctl); |
5792c5c6 | 94 | dp_run(); |
8b61709d | 95 | netdev_run(); |
064af421 | 96 | |
064af421 | 97 | signal_wait(sighup); |
c5187f17 | 98 | bridge_wait(); |
064af421 | 99 | unixctl_server_wait(unixctl); |
5792c5c6 | 100 | dp_wait(); |
8b61709d | 101 | netdev_wait(); |
6d37aaf1 BP |
102 | if (exiting) { |
103 | poll_immediate_wake(); | |
104 | } | |
064af421 BP |
105 | poll_block(); |
106 | } | |
ee45ad81 BP |
107 | bridge_exit(); |
108 | unixctl_server_destroy(unixctl); | |
064af421 BP |
109 | |
110 | return 0; | |
111 | } | |
112 | ||
76343538 | 113 | static const char * |
064af421 BP |
114 | parse_options(int argc, char *argv[]) |
115 | { | |
116 | enum { | |
117 | OPT_PEER_CA_CERT = UCHAR_MAX + 1, | |
86a06318 | 118 | OPT_MLOCKALL, |
064af421 | 119 | VLOG_OPTION_ENUMS, |
6f61c75b | 120 | LEAK_CHECKER_OPTION_ENUMS, |
614c4892 | 121 | OPT_BOOTSTRAP_CA_CERT, |
8274ae95 BP |
122 | OPT_ENABLE_DUMMY, |
123 | DAEMON_OPTION_ENUMS | |
064af421 BP |
124 | }; |
125 | static struct option long_options[] = { | |
126 | {"help", no_argument, 0, 'h'}, | |
127 | {"version", no_argument, 0, 'V'}, | |
86a06318 | 128 | {"mlockall", no_argument, 0, OPT_MLOCKALL}, |
064af421 BP |
129 | DAEMON_LONG_OPTIONS, |
130 | VLOG_LONG_OPTIONS, | |
131 | LEAK_CHECKER_LONG_OPTIONS, | |
132 | #ifdef HAVE_OPENSSL | |
fe55ad15 | 133 | STREAM_SSL_LONG_OPTIONS |
064af421 | 134 | {"peer-ca-cert", required_argument, 0, OPT_PEER_CA_CERT}, |
6f61c75b | 135 | {"bootstrap-ca-cert", required_argument, 0, OPT_BOOTSTRAP_CA_CERT}, |
064af421 | 136 | #endif |
614c4892 | 137 | {"enable-dummy", no_argument, 0, OPT_ENABLE_DUMMY}, |
064af421 BP |
138 | {0, 0, 0, 0}, |
139 | }; | |
140 | char *short_options = long_options_to_short_options(long_options); | |
064af421 BP |
141 | |
142 | for (;;) { | |
143 | int c; | |
144 | ||
145 | c = getopt_long(argc, argv, short_options, long_options, NULL); | |
146 | if (c == -1) { | |
147 | break; | |
148 | } | |
149 | ||
150 | switch (c) { | |
151 | case 'H': | |
152 | case 'h': | |
153 | usage(); | |
154 | ||
155 | case 'V': | |
156 | OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION); | |
157 | exit(EXIT_SUCCESS); | |
158 | ||
86a06318 BP |
159 | case OPT_MLOCKALL: |
160 | #ifdef HAVE_MLOCKALL | |
161 | if (mlockall(MCL_CURRENT | MCL_FUTURE)) { | |
162 | VLOG_ERR("mlockall failed: %s", strerror(errno)); | |
163 | } | |
164 | #else | |
165 | VLOG_ERR("mlockall not supported on this system"); | |
166 | #endif | |
167 | break; | |
168 | ||
064af421 BP |
169 | VLOG_OPTION_HANDLERS |
170 | DAEMON_OPTION_HANDLERS | |
064af421 BP |
171 | LEAK_CHECKER_OPTION_HANDLERS |
172 | ||
173 | #ifdef HAVE_OPENSSL | |
fe55ad15 BP |
174 | STREAM_SSL_OPTION_HANDLERS |
175 | ||
064af421 | 176 | case OPT_PEER_CA_CERT: |
fe55ad15 | 177 | stream_ssl_set_peer_ca_cert_file(optarg); |
064af421 | 178 | break; |
6f61c75b BP |
179 | |
180 | case OPT_BOOTSTRAP_CA_CERT: | |
181 | stream_ssl_set_ca_cert_file(optarg, true); | |
182 | break; | |
064af421 BP |
183 | #endif |
184 | ||
614c4892 BP |
185 | case OPT_ENABLE_DUMMY: |
186 | dummy_enable(); | |
187 | break; | |
188 | ||
064af421 BP |
189 | case '?': |
190 | exit(EXIT_FAILURE); | |
191 | ||
192 | default: | |
193 | abort(); | |
194 | } | |
195 | } | |
196 | free(short_options); | |
197 | ||
198 | argc -= optind; | |
199 | argv += optind; | |
200 | ||
201 | if (argc != 1) { | |
76343538 | 202 | ovs_fatal(0, "database socket is only non-option argument; " |
064af421 BP |
203 | "use --help for usage"); |
204 | } | |
205 | ||
76343538 | 206 | return argv[0]; |
064af421 BP |
207 | } |
208 | ||
209 | static void | |
210 | usage(void) | |
211 | { | |
f30f26be | 212 | printf("%s: Open vSwitch daemon\n" |
76343538 BP |
213 | "usage: %s [OPTIONS] DATABASE\n" |
214 | "where DATABASE is a socket on which ovsdb-server is listening.\n", | |
064af421 | 215 | program_name, program_name); |
9467fe62 | 216 | stream_usage("DATABASE", true, false, true); |
064af421 BP |
217 | daemon_usage(); |
218 | vlog_usage(); | |
0b8b6f71 | 219 | printf("\nOther options:\n" |
064af421 BP |
220 | " -h, --help display this help message\n" |
221 | " -V, --version display version information\n"); | |
222 | leak_checker_usage(); | |
223 | exit(EXIT_SUCCESS); | |
224 | } | |
9e15c889 BP |
225 | |
226 | static void | |
227 | ovs_vswitchd_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED, | |
228 | void *exiting_) | |
229 | { | |
230 | bool *exiting = exiting_; | |
231 | *exiting = true; | |
232 | unixctl_command_reply(conn, 200, NULL); | |
233 | } |