1 /* Copyright (c) 2008, 2009 Nicira Networks
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * In addition, as a special exception, Nicira Networks gives permission
17 * to link the code of its release of vswitchd with the OpenSSL project's
18 * "OpenSSL" library (or with modified versions of it that use the same
19 * license as the "OpenSSL" library), and distribute the linked
20 * executables. You must obey the GNU General Public License in all
21 * respects for all of the code used other than "OpenSSL". If you modify
22 * this file, you may extend this exception to your version of the file,
23 * but you are not obligated to do so. If you do not wish to do so,
24 * delete this exception statement from your version.
39 #include "command-line.h"
43 #include "leak-checker.h"
45 #include "ovs-vswitchd.h"
46 #include "poll-loop.h"
48 #include "proc-net-compat.h"
55 #include "vconn-ssl.h"
59 #define THIS_MODULE VLM_vswitchd
61 static void parse_options(int argc, char *argv[]);
62 static void usage(void) NO_RETURN;
63 static void reload(struct unixctl_conn *, const char *args);
65 static bool need_reconfigure;
66 static struct unixctl_conn **conns;
67 static size_t n_conns;
70 main(int argc, char *argv[])
72 struct unixctl_server *unixctl;
73 struct signal *sighup;
76 set_program_name(argv[0]);
77 register_fault_handlers();
80 parse_options(argc, argv);
81 signal(SIGPIPE, SIG_IGN);
82 sighup = signal_register(SIGHUP);
85 die_if_already_running();
88 retval = unixctl_server_create(NULL, &unixctl);
90 ovs_fatal(retval, "could not listen for control connections");
92 unixctl_command_register("vswitchd/reload", reload);
100 need_reconfigure = false;
102 if (need_reconfigure || signal_poll(sighup)) {
103 need_reconfigure = false;
104 vlog_reopen_log_file();
109 need_reconfigure = true;
111 unixctl_server_run(unixctl);
113 if (need_reconfigure) {
114 poll_immediate_wake();
119 unixctl_server_wait(unixctl);
127 reload(struct unixctl_conn *conn, const char *args UNUSED)
129 need_reconfigure = true;
130 conns = xrealloc(conns, sizeof *conns * (n_conns + 1));
131 conns[n_conns++] = conn;
140 bridge_reconfigure();
144 for (i = 0; i < n_conns; i++) {
145 unixctl_command_reply(conns[i], 202, NULL);
153 parse_options(int argc, char *argv[])
156 OPT_PEER_CA_CERT = UCHAR_MAX + 1,
159 LEAK_CHECKER_OPTION_ENUMS
161 static struct option long_options[] = {
162 {"help", no_argument, 0, 'h'},
163 {"version", no_argument, 0, 'V'},
164 {"fake-proc-net", no_argument, 0, OPT_FAKE_PROC_NET},
167 LEAK_CHECKER_LONG_OPTIONS,
169 VCONN_SSL_LONG_OPTIONS
170 {"peer-ca-cert", required_argument, 0, OPT_PEER_CA_CERT},
174 char *short_options = long_options_to_short_options(long_options);
175 const char *config_file;
181 c = getopt_long(argc, argv, short_options, long_options, NULL);
192 OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION);
195 case OPT_FAKE_PROC_NET:
196 error = proc_net_compat_init();
198 ovs_fatal(error, "failed to initialize /proc/net "
204 DAEMON_OPTION_HANDLERS
205 VCONN_SSL_OPTION_HANDLERS
206 LEAK_CHECKER_OPTION_HANDLERS
209 case OPT_PEER_CA_CERT:
210 vconn_ssl_set_peer_ca_cert_file(optarg);
227 ovs_fatal(0, "config file is only non-option argument; "
228 "use --help for usage");
231 config_file = argv[0];
232 error = cfg_set_file(config_file);
234 ovs_fatal(error, "failed to add configuration file \"%s\"",
242 printf("%s: virtual switch daemon\n"
243 "usage: %s [OPTIONS] CONFIG\n"
244 "CONFIG is a configuration file in ovs-vswitchd.conf(5) format.\n",
245 program_name, program_name);
248 printf("\nLegacy compatibility options:\n"
249 " --fake-proc-net simulate some files in /proc/net\n"
251 " -h, --help display this help message\n"
252 " -V, --version display version information\n");
253 leak_checker_usage();