1 /* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 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"
37 #include "openflow/openflow.h"
38 #include "ovsdb-idl.h"
39 #include "poll-loop.h"
43 #include "stream-ssl.h"
52 #include "lib/vswitch-idl.h"
55 VLOG_DEFINE_THIS_MODULE(vswitchd
);
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
;
61 static unixctl_cb_func ovs_vswitchd_exit
;
63 static char *parse_options(int argc
, char *argv
[], char **unixctl_path
);
64 static void usage(void) NO_RETURN
;
67 main(int argc
, char *argv
[])
69 char *unixctl_path
= NULL
;
70 struct unixctl_server
*unixctl
;
71 struct signal
*sighup
;
76 proctitle_init(argc
, argv
);
77 set_program_name(argv
[0]);
78 stress_init_command();
79 remote
= parse_options(argc
, argv
, &unixctl_path
);
80 signal(SIGPIPE
, SIG_IGN
);
81 sighup
= signal_register(SIGHUP
);
89 if (mlockall(MCL_CURRENT
| MCL_FUTURE
)) {
90 VLOG_ERR("mlockall failed: %s", ovs_strerror(errno
));
93 VLOG_ERR("mlockall not supported on this system");
99 retval
= unixctl_server_create(unixctl_path
, &unixctl
);
103 unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit
, &exiting
);
111 if (signal_poll(sighup
)) {
112 vlog_reopen_log_file();
115 if (memory_should_report()) {
119 bridge_get_memory_usage(&usage
);
120 memory_report(&usage
);
121 simap_destroy(&usage
);
126 unixctl_server_run(unixctl
);
133 unixctl_server_wait(unixctl
);
136 poll_immediate_wake();
141 unixctl_server_destroy(unixctl
);
147 parse_options(int argc
, char *argv
[], char **unixctl_pathp
)
150 OPT_PEER_CA_CERT
= UCHAR_MAX
+ 1,
154 OPT_BOOTSTRAP_CA_CERT
,
159 static const struct option long_options
[] = {
160 {"help", no_argument
, NULL
, 'h'},
161 {"version", no_argument
, NULL
, 'V'},
162 {"mlockall", no_argument
, NULL
, OPT_MLOCKALL
},
163 {"unixctl", required_argument
, NULL
, OPT_UNIXCTL
},
166 STREAM_SSL_LONG_OPTIONS
,
167 {"peer-ca-cert", required_argument
, NULL
, OPT_PEER_CA_CERT
},
168 {"bootstrap-ca-cert", required_argument
, NULL
, OPT_BOOTSTRAP_CA_CERT
},
169 {"enable-dummy", optional_argument
, NULL
, OPT_ENABLE_DUMMY
},
170 {"disable-system", no_argument
, NULL
, OPT_DISABLE_SYSTEM
},
173 char *short_options
= long_options_to_short_options(long_options
);
178 c
= getopt_long(argc
, argv
, short_options
, long_options
, NULL
);
188 ovs_print_version(OFP10_VERSION
, OFP10_VERSION
);
192 want_mlockall
= true;
196 *unixctl_pathp
= optarg
;
200 DAEMON_OPTION_HANDLERS
201 STREAM_SSL_OPTION_HANDLERS
203 case OPT_PEER_CA_CERT
:
204 stream_ssl_set_peer_ca_cert_file(optarg
);
207 case OPT_BOOTSTRAP_CA_CERT
:
208 stream_ssl_set_ca_cert_file(optarg
, true);
211 case OPT_ENABLE_DUMMY
:
212 dummy_enable(optarg
&& !strcmp(optarg
, "override"));
215 case OPT_DISABLE_SYSTEM
:
216 dp_blacklist_provider("system");
233 return xasprintf("unix:%s/db.sock", ovs_rundir());
236 return xstrdup(argv
[0]);
239 VLOG_FATAL("at most one non-option argument accepted; "
240 "use --help for usage");
247 printf("%s: Open vSwitch daemon\n"
248 "usage: %s [OPTIONS] [DATABASE]\n"
249 "where DATABASE is a socket on which ovsdb-server is listening\n"
250 " (default: \"unix:%s/db.sock\").\n",
251 program_name
, program_name
, ovs_rundir());
252 stream_usage("DATABASE", true, false, true);
255 printf("\nOther options:\n"
256 " --unixctl=SOCKET override default control socket name\n"
257 " -h, --help display this help message\n"
258 " -V, --version display version information\n");
263 ovs_vswitchd_exit(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
264 const char *argv
[] OVS_UNUSED
, void *exiting_
)
266 bool *exiting
= exiting_
;
268 unixctl_command_reply(conn
, NULL
);