/* Returns the file name that would be used for a pidfile if 'name' were * provided to set_pidfile(). The caller must free the returned string. */ static char * make_pidfile_name(const char *name) { return (!name ? xasprintf("%s/%s.pid", ovs_rundir(), program_name) : abs_file_name(ovs_rundir(), name)); }
int ofcds_init(void *UNUSED(data)) { if (!ovsdb_path) { /* default path */ asprintf(&ovsdb_path, "unix:%s/db.sock", ovs_rundir()); } if (ofc_init(ovsdb_path) == false) { return EXIT_FAILURE; } /* hack - OVS calls openlog() and rewrites the syslog settings of the * ofc-server. So we have to rewrite syslog settings back by another * openlog() call */ if (ofc_daemonize) { openlog("ofc-server", LOG_PID, LOG_DAEMON); } else { openlog("ofc-server", LOG_PID | LOG_PERROR, LOG_DAEMON); } /* get startup data */ gds_startup = xmlReadFile(OFC_DATADIR "/startup.xml", NULL, XML_READ_OPT); /* check that there are some data, if not, continue with empty startup */ if (!xmlDocGetRootElement(gds_startup)) { xmlFreeDoc(gds_startup); gds_startup = NULL; } nc_verb_verbose("OF-CONFIG datastore initialized."); return EXIT_SUCCESS; }
static void usage(void) { printf("%s: Open vSwitch daemon\n" "usage: %s [OPTIONS] [DATABASE]\n" "where DATABASE is a socket on which ovsdb-server is listening\n" " (default: \"unix:%s/db.sock\").\n", program_name, program_name, ovs_rundir()); stream_usage("DATABASE", true, false, true); daemon_usage(); vlog_usage(); printf("\nDPDK options:\n" " --dpdk [VHOST] [DPDK] Initialize DPDK datapath.\n" " where DPDK are options for initializing DPDK lib and VHOST is\n" #ifdef VHOST_CUSE " option to override default character device name used for\n" " for use with userspace vHost\n" " -cuse_dev_name NAME\n" #else " option to override default directory where vhost-user\n" " sockets are created.\n" " -vhost_sock_dir DIR\n" #endif ); printf("\nOther options:\n" " --unixctl=SOCKET override default control socket name\n" " -h, --help display this help message\n" " -V, --version display version information\n"); exit(EXIT_SUCCESS); }
static void usage(void) { printf("%s: Open vSwitch database JSON-RPC client\n" "usage: %s [OPTIONS] COMMAND [ARG...]\n" "\nValid commands are:\n" "\n list-dbs [SERVER]\n" " list databases available on SERVER\n" "\n get-schema [SERVER] [DATABASE]\n" " retrieve schema for DATABASE from SERVER\n" "\n get-schema-version [SERVER] [DATABASE]\n" " retrieve schema for DATABASE from SERVER and report only its\n" " version number on stdout\n" "\n list-tables [SERVER] [DATABASE]\n" " list tables for DATABASE on SERVER\n" "\n list-columns [SERVER] [DATABASE] [TABLE]\n" " list columns in TABLE (or all tables) in DATABASE on SERVER\n" "\n transact [SERVER] TRANSACTION\n" " run TRANSACTION (a JSON array of operations) on SERVER\n" " and print the results as JSON on stdout\n" "\n monitor [SERVER] [DATABASE] TABLE [COLUMN,...]...\n" " monitor contents of COLUMNs in TABLE in DATABASE on SERVER.\n" " COLUMNs may include !initial, !insert, !delete, !modify\n" " to avoid seeing the specified kinds of changes.\n" "\n monitor-cond [SERVER] [DATABASE] CONDITION TABLE [COLUMN,...]...\n" " monitor contents that match CONDITION of COLUMNs in TABLE in\n" " DATABASE on SERVER.\n" " COLUMNs may include !initial, !insert, !delete, !modify\n" " to avoid seeing the specified kinds of changes.\n" "\n monitor [SERVER] [DATABASE] ALL\n" " monitor all changes to all columns in all tables\n" " in DATBASE on SERVER.\n" "\n dump [SERVER] [DATABASE]\n" " dump contents of DATABASE on SERVER to stdout\n" "\n lock [SERVER] LOCK\n" " create or wait for LOCK in SERVER\n" "\n steal [SERVER] LOCK\n" " steal LOCK from SERVER\n" "\n unlock [SERVER] LOCK\n" " unlock LOCK from SERVER\n" "\nThe default SERVER is unix:%s/db.sock.\n" "The default DATABASE is Open_vSwitch.\n", program_name, program_name, ovs_rundir()); stream_usage("SERVER", true, true, true); printf("\nOutput formatting options:\n" " -f, --format=FORMAT set output formatting to FORMAT\n" " (\"table\", \"html\", \"csv\", " "or \"json\")\n" " --no-headings omit table heading row\n" " --pretty pretty-print JSON in output\n" " --timestamp timestamp \"monitor\" output"); daemon_usage(); vlog_usage(); printf("\nOther options:\n" " -h, --help display this help message\n" " -V, --version display version information\n"); exit(EXIT_SUCCESS); }
/* Returns the file name that would be used for a pidfile if 'name' were * provided to set_pidfile(). The caller must free the returned string. */ char * make_pidfile_name(const char *name) { if (name && strchr(name, ':')) { return xstrdup(name); } else { return xasprintf("%s/%s.pid", ovs_rundir(), program_name); } }
void daemon_usage(void) { printf( "\nService options:\n" " --service run in background as a service.\n" " --service-monitor restart the service in case of an " "unexpected failure. \n", ovs_rundir(), program_name); }
static const char * sbctl_default_db(void) { static char *def; if (!def) { def = getenv("OVN_SB_DB"); if (!def) { def = xasprintf("unix:%s/ovnsb_db.sock", ovs_rundir()); } } return def; }
void daemon_usage(void) { printf( "\nDaemon options:\n" " --detach run in background as daemon\n" " --no-chdir do not chdir to '/'\n" " --pidfile[=FILE] create pidfile (default: %s/%s.pid)\n" " --overwrite-pidfile with --pidfile, start even if already " "running\n", ovs_rundir(), program_name); }
void daemon_usage(void) { printf( "\nDaemon options:\n" " --detach run in background as daemon\n" " --monitor creates a process to monitor this daemon\n" " --user=username[:group] changes the effective daemon user:group\n" " --no-chdir do not chdir to '/'\n" " --pidfile[=FILE] create pidfile (default: %s/%s.pid)\n" " --overwrite-pidfile with --pidfile, start even if already " "running\n", ovs_rundir(), program_name); }
static void usage(void) { printf("%s: Open vSwitch daemon\n" "usage: %s [OPTIONS] [DATABASE]\n" "where DATABASE is a socket on which ovsdb-server is listening\n" " (default: \"unix:%s/db.sock\").\n", program_name, program_name, ovs_rundir()); stream_usage("DATABASE", true, false, true); daemon_usage(); vlog_usage(); printf("\nOther options:\n" " --unixctl=SOCKET override default control socket name\n" " -h, --help display this help message\n" " -V, --version display version information\n"); exit(EXIT_SUCCESS); }
static int unix_open(const char *name, char *suffix, struct stream **streamp, uint8_t dscp OVS_UNUSED) { char *connect_path; int fd; connect_path = abs_file_name(ovs_rundir(), suffix); fd = make_unix_socket(SOCK_STREAM, true, NULL, connect_path); if (fd < 0) { VLOG_DBG("%s: connection failed (%s)", connect_path, ovs_strerror(-fd)); free(connect_path); return -fd; } free(connect_path); return new_fd_stream(name, fd, check_connection_completion(fd), streamp); }
static void usage(void) { printf("%s: Open vSwitch daemon\n" "usage: %s [OPTIONS] [DATABASE]\n" "where DATABASE is a socket on which ovsdb-server is listening\n" " (default: \"unix:%s/db.sock\").\n", program_name, program_name, ovs_rundir()); stream_usage("DATABASE", true, false, true); daemon_usage(); vlog_usage(); printf("\nDPDK options:\n" " --dpdk options Initialize DPDK datapath.\n" " --cuse_dev_name BASENAME override default character device name\n" " for use with userspace vHost.\n"); printf("\nOther options:\n" " --unixctl=SOCKET override default control socket name\n" " -h, --help display this help message\n" " -V, --version display version information\n"); exit(EXIT_SUCCESS); }
static int windows_open(const char *name, char *suffix, struct stream **streamp, uint8_t dscp) { int error, port; FILE *file; char *suffix_new, *path; /* If the path does not contain a ':', assume it is relative to * OVS_RUNDIR. */ if (!strchr(suffix, ':')) { path = xasprintf("%s/%s", ovs_rundir(), suffix); } else { path = xstrdup(suffix); } file = fopen(path, "r"); if (!file) { error = errno; VLOG_DBG("%s: could not open %s (%s)", name, suffix, ovs_strerror(error)); return error; } error = fscanf(file, "%d", &port); if (error != 1) { VLOG_ERR("failed to read port from %s", suffix); fclose(file); return EINVAL; } fclose(file); suffix_new = xasprintf("127.0.0.1:%d", port); error = tcp_open(name, suffix_new, streamp, dscp); free(suffix_new); free(path); return error; }
static char * parse_options(int argc, char *argv[]) { enum { OPT_PEER_CA_CERT = UCHAR_MAX + 1, OPT_MLOCKALL, VLOG_OPTION_ENUMS, LEAK_CHECKER_OPTION_ENUMS, OPT_BOOTSTRAP_CA_CERT, OPT_ENABLE_DUMMY, OPT_DISABLE_SYSTEM, DAEMON_OPTION_ENUMS }; static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"mlockall", no_argument, NULL, OPT_MLOCKALL}, DAEMON_LONG_OPTIONS, VLOG_LONG_OPTIONS, LEAK_CHECKER_LONG_OPTIONS, STREAM_SSL_LONG_OPTIONS, {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT}, {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, {"enable-dummy", no_argument, NULL, OPT_ENABLE_DUMMY}, {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM}, {NULL, 0, NULL, 0}, }; char *short_options = long_options_to_short_options(long_options); for (;;) { int c; c = getopt_long(argc, argv, short_options, long_options, NULL); if (c == -1) { break; } switch (c) { case 'h': usage(); case 'V': ovs_print_version(OFP_VERSION, OFP_VERSION); exit(EXIT_SUCCESS); case OPT_MLOCKALL: #ifdef HAVE_MLOCKALL if (mlockall(MCL_CURRENT | MCL_FUTURE)) { VLOG_ERR("mlockall failed: %s", strerror(errno)); } #else VLOG_ERR("mlockall not supported on this system"); #endif break; VLOG_OPTION_HANDLERS DAEMON_OPTION_HANDLERS LEAK_CHECKER_OPTION_HANDLERS STREAM_SSL_OPTION_HANDLERS case OPT_PEER_CA_CERT: stream_ssl_set_peer_ca_cert_file(optarg); break; case OPT_BOOTSTRAP_CA_CERT: stream_ssl_set_ca_cert_file(optarg, true); break; case OPT_ENABLE_DUMMY: dummy_enable(); break; case OPT_DISABLE_SYSTEM: dp_blacklist_provider("system"); break; case '?': exit(EXIT_FAILURE); default: abort(); } } free(short_options); argc -= optind; argv += optind; switch (argc) { case 0: return xasprintf("unix:%s/db.sock", ovs_rundir()); case 1: return xstrdup(argv[0]); default: VLOG_FATAL("at most one non-option argument accepted; " "use --help for usage"); } }
static void dpdk_init__(const struct smap *ovs_other_config) { char **argv = NULL, **argv_to_release = NULL; int result; int argc, argc_tmp; bool auto_determine = true; int err = 0; cpu_set_t cpuset; char *sock_dir_subcomponent; if (process_vhost_flags("vhost-sock-dir", xstrdup(ovs_rundir()), NAME_MAX, ovs_other_config, &sock_dir_subcomponent)) { struct stat s; if (!strstr(sock_dir_subcomponent, "..")) { vhost_sock_dir = xasprintf("%s/%s", ovs_rundir(), sock_dir_subcomponent); err = stat(vhost_sock_dir, &s); if (err) { VLOG_ERR("vhost-user sock directory '%s' does not exist.", vhost_sock_dir); } } else { vhost_sock_dir = xstrdup(ovs_rundir()); VLOG_ERR("vhost-user sock directory request '%s/%s' has invalid" "characters '..' - using %s instead.", ovs_rundir(), sock_dir_subcomponent, ovs_rundir()); } free(sock_dir_subcomponent); } else { vhost_sock_dir = sock_dir_subcomponent; } argv = grow_argv(&argv, 0, 1); argc = 1; argv[0] = xstrdup(ovs_get_program_name()); argc_tmp = get_dpdk_args(ovs_other_config, &argv, argc); while (argc_tmp != argc) { if (!strcmp("-c", argv[argc]) || !strcmp("-l", argv[argc])) { auto_determine = false; break; } argc++; } argc = argc_tmp; /** * NOTE: This is an unsophisticated mechanism for determining the DPDK * lcore for the DPDK Master. */ if (auto_determine) { int i; /* Get the main thread affinity */ CPU_ZERO(&cpuset); err = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); if (!err) { for (i = 0; i < CPU_SETSIZE; i++) { if (CPU_ISSET(i, &cpuset)) { argv = grow_argv(&argv, argc, 2); argv[argc++] = xstrdup("-c"); argv[argc++] = xasprintf("0x%08llX", (1ULL<<i)); i = CPU_SETSIZE; } } } else { VLOG_ERR("Thread getaffinity error %d. Using core 0x1", err); /* User did not set dpdk-lcore-mask and unable to get current * thread affintity - default to core 0x1 */ argv = grow_argv(&argv, argc, 2); argv[argc++] = xstrdup("-c"); argv[argc++] = xasprintf("0x%X", 1); } } argv = grow_argv(&argv, argc, 1); argv[argc] = NULL; optind = 1; if (VLOG_IS_INFO_ENABLED()) { struct ds eal_args; int opt; ds_init(&eal_args); ds_put_cstr(&eal_args, "EAL ARGS:"); for (opt = 0; opt < argc; ++opt) { ds_put_cstr(&eal_args, " "); ds_put_cstr(&eal_args, argv[opt]); } VLOG_INFO("%s", ds_cstr_ro(&eal_args)); ds_destroy(&eal_args); } argv_to_release = grow_argv(&argv_to_release, 0, argc); for (argc_tmp = 0; argc_tmp < argc; ++argc_tmp) { argv_to_release[argc_tmp] = argv[argc_tmp]; } /* Make sure things are initialized ... */ result = rte_eal_init(argc, argv); if (result < 0) { ovs_abort(result, "Cannot init EAL"); } argv_release(argv, argv_to_release, argc); /* Set the main thread affinity back to pre rte_eal_init() value */ if (auto_determine && !err) { err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); if (err) { VLOG_ERR("Thread setaffinity error %d", err); } } rte_memzone_dump(stdout); /* We are called from the main thread here */ RTE_PER_LCORE(_lcore_id) = NON_PMD_CORE_ID; #ifdef DPDK_PDUMP VLOG_INFO("DPDK pdump packet capture enabled"); err = rte_pdump_init(ovs_rundir()); if (err) { VLOG_INFO("Error initialising DPDK pdump"); rte_pdump_uninit(); } else { char *server_socket_path; server_socket_path = xasprintf("%s/%s", ovs_rundir(), "pdump_server_socket"); fatal_signal_add_file_to_unlink(server_socket_path); free(server_socket_path); } #endif /* Finally, register the dpdk classes */ netdev_dpdk_register(); }
NULL, /* wait */ }; /* Passive UNIX socket. */ static int punix_accept(int fd, const struct sockaddr_storage *ss, size_t ss_len, struct stream **streamp); static int punix_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp, uint8_t dscp OVS_UNUSED) { char *bind_path; int fd, error; bind_path = abs_file_name(ovs_rundir(), suffix); fd = make_unix_socket(SOCK_STREAM, true, bind_path, NULL); if (fd < 0) { VLOG_ERR("%s: binding failed: %s", bind_path, ovs_strerror(errno)); free(bind_path); return errno; } if (listen(fd, 10) < 0) { error = errno; VLOG_ERR("%s: listen: %s", name, ovs_strerror(error)); close(fd); free(bind_path); return error; }
int main(int argc, char *argv[]) { const struct ovsdb_client_command *command; char *database; struct jsonrpc *rpc; ovs_cmdl_proctitle_init(argc, argv); set_program_name(argv[0]); parse_options(argc, argv); fatal_ignore_sigpipe(); daemon_become_new_user(false); if (optind >= argc) { ovs_fatal(0, "missing command name; use --help for help"); } for (command = get_all_commands(); ; command++) { if (!command->name) { VLOG_FATAL("unknown command '%s'; use --help for help", argv[optind]); } else if (!strcmp(command->name, argv[optind])) { break; } } optind++; if (command->need != NEED_NONE) { if (argc - optind > command->min_args && (isalpha((unsigned char) argv[optind][0]) && strchr(argv[optind], ':'))) { rpc = open_jsonrpc(argv[optind++]); } else { char *sock = xasprintf("unix:%s/db.sock", ovs_rundir()); rpc = open_jsonrpc(sock); free(sock); } } else { rpc = NULL; } if (command->need == NEED_DATABASE) { struct svec dbs; svec_init(&dbs); fetch_dbs(rpc, &dbs); if (argc - optind > command->min_args && svec_contains(&dbs, argv[optind])) { database = xstrdup(argv[optind++]); } else if (dbs.n == 1) { database = xstrdup(dbs.names[0]); } else if (svec_contains(&dbs, "Open_vSwitch")) { database = xstrdup("Open_vSwitch"); } else { jsonrpc_close(rpc); ovs_fatal(0, "no default database for `%s' command, please " "specify a database name", command->name); } svec_destroy(&dbs); } else { database = NULL; } if (argc - optind < command->min_args || argc - optind > command->max_args) { free(database); VLOG_FATAL("invalid syntax for '%s' (use --help for help)", command->name); } command->handler(rpc, database, argc - optind, argv + optind); free(database); jsonrpc_close(rpc); if (ferror(stdout)) { VLOG_FATAL("write to stdout failed"); } if (ferror(stderr)) { VLOG_FATAL("write to stderr failed"); } return 0; }
static char * parse_options(int argc, char *argv[], char **unixctl_pathp) { enum { OPT_PEER_CA_CERT = UCHAR_MAX + 1, OPT_MLOCKALL, OPT_UNIXCTL, VLOG_OPTION_ENUMS, OPT_BOOTSTRAP_CA_CERT, OPT_ENABLE_DUMMY, OPT_DISABLE_SYSTEM, DAEMON_OPTION_ENUMS, OPT_DPDK, }; static const struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"mlockall", no_argument, NULL, OPT_MLOCKALL}, {"unixctl", required_argument, NULL, OPT_UNIXCTL}, DAEMON_LONG_OPTIONS, VLOG_LONG_OPTIONS, STREAM_SSL_LONG_OPTIONS, {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT}, {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY}, {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM}, {"dpdk", required_argument, NULL, OPT_DPDK}, {NULL, 0, NULL, 0}, }; char *short_options = ovs_cmdl_long_options_to_short_options(long_options); for (;;) { int c; c = getopt_long(argc, argv, short_options, long_options, NULL); if (c == -1) { break; } switch (c) { case 'h': usage(); case 'V': ovs_print_version(OFP10_VERSION, OFP10_VERSION); exit(EXIT_SUCCESS); case OPT_MLOCKALL: want_mlockall = true; break; case OPT_UNIXCTL: *unixctl_pathp = optarg; break; VLOG_OPTION_HANDLERS DAEMON_OPTION_HANDLERS STREAM_SSL_OPTION_HANDLERS case OPT_PEER_CA_CERT: stream_ssl_set_peer_ca_cert_file(optarg); break; case OPT_BOOTSTRAP_CA_CERT: stream_ssl_set_ca_cert_file(optarg, true); break; case OPT_ENABLE_DUMMY: dummy_enable(optarg && !strcmp(optarg, "override")); break; case OPT_DISABLE_SYSTEM: dp_blacklist_provider("system"); break; case '?': exit(EXIT_FAILURE); case OPT_DPDK: ovs_fatal(0, "--dpdk must be given at beginning of command line."); break; default: abort(); } } free(short_options); argc -= optind; argv += optind; switch (argc) { case 0: return xasprintf("unix:%s/db.sock", ovs_rundir()); case 1: return xstrdup(argv[0]); default: VLOG_FATAL("at most one non-option argument accepted; " "use --help for usage"); } }
int main(int argc, char *argv[]) { struct unixctl_server *unixctl; bool exiting; int retval; ovs_cmdl_proctitle_init(argc, argv); set_program_name(argv[0]); parse_options(argc, argv); fatal_ignore_sigpipe(); daemonize_start(); retval = unixctl_server_create(NULL, &unixctl); if (retval) { exit(EXIT_FAILURE); } unixctl_command_register("exit", "", 0, 0, ovn_controller_exit, &exiting); daemonize_complete(); ovsrec_init(); sbrec_init(); ofctrl_init(); lflow_init(); /* Connect to OVS OVSDB instance. We do not monitor all tables by * default, so modules must register their interest explicitly. */ struct idl_loop ovs_idl_loop = IDL_LOOP_INITIALIZER( ovsdb_idl_create(ovs_remote, &ovsrec_idl_class, false, true)); ovsdb_idl_add_table(ovs_idl_loop.idl, &ovsrec_table_open_vswitch); ovsdb_idl_add_column(ovs_idl_loop.idl, &ovsrec_open_vswitch_col_external_ids); chassis_register_ovs_idl(ovs_idl_loop.idl); encaps_register_ovs_idl(ovs_idl_loop.idl); binding_register_ovs_idl(ovs_idl_loop.idl); physical_register_ovs_idl(ovs_idl_loop.idl); get_initial_snapshot(ovs_idl_loop.idl); /* Connect to OVN SB database. */ char *ovnsb_remote = get_ovnsb_remote(ovs_idl_loop.idl); struct idl_loop ovnsb_idl_loop = IDL_LOOP_INITIALIZER( ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true)); get_initial_snapshot(ovnsb_idl_loop.idl); /* Main loop. */ exiting = false; while (!exiting) { struct controller_ctx ctx = { .ovs_idl = ovs_idl_loop.idl, .ovs_idl_txn = idl_loop_run(&ovs_idl_loop), .ovnsb_idl = ovnsb_idl_loop.idl, .ovnsb_idl_txn = idl_loop_run(&ovnsb_idl_loop), }; const struct ovsrec_bridge *br_int = get_br_int(ctx.ovs_idl); const char *chassis_id = get_chassis_id(ctx.ovs_idl); if (chassis_id) { chassis_run(&ctx, chassis_id); encaps_run(&ctx, br_int, chassis_id); binding_run(&ctx, br_int, chassis_id); } if (br_int) { struct hmap flow_table = HMAP_INITIALIZER(&flow_table); lflow_run(&ctx, &flow_table); if (chassis_id) { physical_run(&ctx, br_int, chassis_id, &flow_table); } ofctrl_run(br_int, &flow_table); hmap_destroy(&flow_table); } unixctl_server_run(unixctl); unixctl_server_wait(unixctl); if (exiting) { poll_immediate_wake(); } idl_loop_commit_and_wait(&ovnsb_idl_loop); idl_loop_commit_and_wait(&ovs_idl_loop); if (br_int) { ofctrl_wait(); } poll_block(); } /* It's time to exit. Clean up the databases. */ bool done = false; while (!done) { struct controller_ctx ctx = { .ovs_idl = ovs_idl_loop.idl, .ovs_idl_txn = idl_loop_run(&ovs_idl_loop), .ovnsb_idl = ovnsb_idl_loop.idl, .ovnsb_idl_txn = idl_loop_run(&ovnsb_idl_loop), }; const struct ovsrec_bridge *br_int = get_br_int(ctx.ovs_idl); const char *chassis_id = get_chassis_id(ctx.ovs_idl); /* Run all of the cleanup functions, even if one of them returns false. * We're done if all of them return true. */ done = binding_cleanup(&ctx, chassis_id); done = chassis_cleanup(&ctx, chassis_id) && done; done = encaps_cleanup(&ctx, br_int) && done; if (done) { poll_immediate_wake(); } idl_loop_commit_and_wait(&ovnsb_idl_loop); idl_loop_commit_and_wait(&ovs_idl_loop); poll_block(); } unixctl_server_destroy(unixctl); lflow_destroy(); ofctrl_destroy(); idl_loop_destroy(&ovs_idl_loop); idl_loop_destroy(&ovnsb_idl_loop); free(ovnsb_remote); free(ovs_remote); exit(retval); } static void parse_options(int argc, char *argv[]) { enum { OPT_PEER_CA_CERT = UCHAR_MAX + 1, VLOG_OPTION_ENUMS, DAEMON_OPTION_ENUMS }; static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, VLOG_LONG_OPTIONS, DAEMON_LONG_OPTIONS, STREAM_SSL_LONG_OPTIONS, {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT}, {NULL, 0, NULL, 0} }; char *short_options = ovs_cmdl_long_options_to_short_options(long_options); for (;;) { int c; c = getopt_long(argc, argv, short_options, long_options, NULL); if (c == -1) { break; } switch (c) { case 'h': usage(); case 'V': ovs_print_version(OFP13_VERSION, OFP13_VERSION); exit(EXIT_SUCCESS); VLOG_OPTION_HANDLERS DAEMON_OPTION_HANDLERS STREAM_SSL_OPTION_HANDLERS case OPT_PEER_CA_CERT: stream_ssl_set_peer_ca_cert_file(optarg); break; case '?': exit(EXIT_FAILURE); default: abort(); } } free(short_options); argc -= optind; argv += optind; if (argc == 0) { ovs_remote = xasprintf("unix:%s/db.sock", ovs_rundir()); } else if (argc == 1) { ovs_remote = xstrdup(argv[0]); } else { VLOG_FATAL("exactly zero or one non-option argument required; " "use --help for usage"); } } static void usage(void) { printf("%s: OVN controller\n" "usage %s [OPTIONS] [OVS-DATABASE]\n" "where OVS-DATABASE is a socket on which the OVS OVSDB server is listening.\n", program_name, program_name); stream_usage("OVS-DATABASE", true, false, false); daemon_usage(); vlog_usage(); printf("\nOther options:\n" " -h, --help display this help message\n" " -V, --version display version information\n"); exit(EXIT_SUCCESS); } static void ovn_controller_exit(struct unixctl_conn *conn, int argc OVS_UNUSED, const char *argv[] OVS_UNUSED, void *exiting_) { bool *exiting = exiting_; *exiting = true; unixctl_command_reply(conn, NULL); }
static char * parse_options(int argc, char *argv[], char **unixctl_pathp) { enum { OPT_PEER_CA_CERT = UCHAR_MAX + 1, OPT_UNIXCTL, VLOG_OPTION_ENUMS, OPT_BOOTSTRAP_CA_CERT, OPT_ENABLE_DUMMY, OPT_DISABLE_SYSTEM, DAEMON_OPTION_ENUMS, OPT_DPDK, }; static const struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"unixctl", required_argument, NULL, OPT_UNIXCTL}, DAEMON_LONG_OPTIONS, VLOG_LONG_OPTIONS, STREAM_SSL_LONG_OPTIONS, {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT}, {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, {NULL, 0, NULL, 0}, }; char *short_options = long_options_to_short_options(long_options); for (;;) { int c; c = getopt_long(argc, argv, short_options, long_options, NULL); if (c == -1) { break; } switch (c) { case 'h': usage(); case 'V': ovs_print_version(OFP10_VERSION, OFP10_VERSION); exit(EXIT_SUCCESS); case OPT_UNIXCTL: *unixctl_pathp = optarg; break; VLOG_OPTION_HANDLERS DAEMON_OPTION_HANDLERS STREAM_SSL_OPTION_HANDLERS case OPT_PEER_CA_CERT: stream_ssl_set_peer_ca_cert_file(optarg); break; case OPT_BOOTSTRAP_CA_CERT: stream_ssl_set_ca_cert_file(optarg, true); break; case '?': exit(EXIT_FAILURE); default: abort(); } } free(short_options); argc -= optind; argv += optind; switch (argc) { case 0: return xasprintf("unix:%s/db.sock", ovs_rundir()); case 1: return xstrdup(argv[0]); default: VLOG_FATAL("at most one non-option argument accepted; " "use --help for usage"); } }