1 /* Copyright (c) 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.
25 #include "command-line.h"
29 #include "dynamic-string.h"
34 #include "jsonrpc-server.h"
35 #include "leak-checker.h"
39 #include "ovsdb-data.h"
40 #include "ovsdb-types.h"
41 #include "ovsdb-error.h"
42 #include "poll-loop.h"
46 #include "stream-ssl.h"
52 #include "transaction.h"
58 VLOG_DEFINE_THIS_MODULE(ovsdb_server);
61 /* Initialized in main(). */
63 struct ovsdb_file *file;
66 /* Only used by update_remote_status(). */
67 struct ovsdb_txn *txn;
70 /* SSL configuration. */
71 static char *private_key_file;
72 static char *certificate_file;
73 static char *ca_cert_file;
74 static bool bootstrap_ca_cert;
76 static unixctl_cb_func ovsdb_server_exit;
77 static unixctl_cb_func ovsdb_server_compact;
78 static unixctl_cb_func ovsdb_server_reconnect;
80 struct add_remote_aux {
85 static unixctl_cb_func ovsdb_server_add_remote;
86 static unixctl_cb_func ovsdb_server_remove_remote;
87 static unixctl_cb_func ovsdb_server_list_remotes;
89 static void parse_options(int *argc, char **argvp[],
90 struct sset *remotes, char **unixctl_pathp,
92 static void usage(void) NO_RETURN;
94 static void reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
95 const struct db dbs[], size_t n_dbs,
96 struct sset *remotes);
98 static void update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
99 const struct sset *remotes,
100 struct db dbs[], size_t n_dbs);
103 main(int argc, char *argv[])
105 char *unixctl_path = NULL;
106 char *run_command = NULL;
107 struct unixctl_server *unixctl;
108 struct ovsdb_jsonrpc_server *jsonrpc;
110 struct process *run_process;
113 long long int status_timer = LLONG_MIN;
114 struct add_remote_aux add_remote_aux;
120 proctitle_init(argc, argv);
121 set_program_name(argv[0]);
122 stress_init_command();
123 signal(SIGPIPE, SIG_IGN);
126 parse_options(&argc, &argv, &remotes, &unixctl_path, &run_command);
130 n_dbs = MAX(1, argc);
131 dbs = xcalloc(n_dbs + 1, sizeof *dbs);
133 for (i = 0; i < argc; i++) {
134 dbs[i].filename = argv[i];
137 dbs[0].filename = xasprintf("%s/conf.db", ovs_dbdir());
140 for (i = 0; i < n_dbs; i++) {
141 struct ovsdb_error *error;
143 error = ovsdb_file_open(dbs[i].filename, false,
144 &dbs[i].db, &dbs[i].file);
146 ovs_fatal(0, "%s", ovsdb_error_to_string(error));
150 jsonrpc = ovsdb_jsonrpc_server_create();
151 for (i = 0; i < n_dbs; i++) {
152 if (!ovsdb_jsonrpc_server_add_db(jsonrpc, dbs[i].db)) {
153 ovs_fatal(0, "%s: duplicate database name",
154 dbs[i].db->schema->name);
157 reconfigure_from_db(jsonrpc, dbs, n_dbs, &remotes);
159 retval = unixctl_server_create(unixctl_path, &unixctl);
167 run_argv[0] = "/bin/sh";
169 run_argv[2] = run_command;
172 retval = process_start(run_argv, NULL, 0, NULL, 0, &run_process);
174 ovs_fatal(retval, "%s: process failed to start", run_command);
180 daemonize_complete();
183 /* ovsdb-server is usually a long-running process, in which case it
184 * makes plenty of sense to log the version, but --run makes
185 * ovsdb-server more like a command-line tool, so skip it. */
186 VLOG_INFO("%s (Open vSwitch) %s", program_name, VERSION);
189 unixctl_command_register("exit", "", 0, 0, ovsdb_server_exit, &exiting);
190 unixctl_command_register("ovsdb-server/compact", "", 0, 1,
191 ovsdb_server_compact, dbs);
192 unixctl_command_register("ovsdb-server/reconnect", "", 0, 0,
193 ovsdb_server_reconnect, jsonrpc);
195 add_remote_aux.remotes = &remotes;
196 add_remote_aux.dbs = dbs;
197 add_remote_aux.n_dbs = n_dbs;
198 unixctl_command_register("ovsdb-server/add-remote", "REMOTE", 1, 1,
199 ovsdb_server_add_remote, &add_remote_aux);
200 unixctl_command_register("ovsdb-server/remove-remote", "REMOTE", 1, 1,
201 ovsdb_server_remove_remote, &remotes);
202 unixctl_command_register("ovsdb-server/list-remotes", "", 0, 0,
203 ovsdb_server_list_remotes, &remotes);
210 if (memory_should_report()) {
214 ovsdb_jsonrpc_server_get_memory_usage(jsonrpc, &usage);
215 for (i = 0; i < n_dbs; i++) {
216 ovsdb_get_memory_usage(dbs[i].db, &usage);
218 memory_report(&usage);
219 simap_destroy(&usage);
222 /* Run unixctl_server_run() before reconfigure_from_db() because
223 * ovsdb-server/add-remote and ovsdb-server/remove-remote can change
224 * the set of remotes that reconfigure_from_db() uses. */
225 unixctl_server_run(unixctl);
227 reconfigure_from_db(jsonrpc, dbs, n_dbs, &remotes);
228 ovsdb_jsonrpc_server_run(jsonrpc);
230 for (i = 0; i < n_dbs; i++) {
231 ovsdb_trigger_run(dbs[i].db, time_msec());
233 if (run_process && process_exited(run_process)) {
237 /* update Manager status(es) every 5 seconds */
238 if (time_msec() >= status_timer) {
239 status_timer = time_msec() + 5000;
240 update_remote_status(jsonrpc, &remotes, dbs, n_dbs);
244 ovsdb_jsonrpc_server_wait(jsonrpc);
245 unixctl_server_wait(unixctl);
246 for (i = 0; i < n_dbs; i++) {
247 ovsdb_trigger_wait(dbs[i].db, time_msec());
250 process_wait(run_process);
253 poll_immediate_wake();
255 poll_timer_wait_until(status_timer);
258 ovsdb_jsonrpc_server_destroy(jsonrpc);
259 for (i = 0; i < n_dbs; i++) {
260 ovsdb_destroy(dbs[i].db);
262 sset_destroy(&remotes);
263 unixctl_server_destroy(unixctl);
265 if (run_process && process_exited(run_process)) {
266 int status = process_status(run_process);
268 ovs_fatal(0, "%s: child exited, %s",
269 run_command, process_status_msg(status));
276 static const struct db *
277 find_db(const struct db dbs[], size_t n_dbs, const char *db_name)
281 for (i = 0; i < n_dbs; i++) {
282 if (!strcmp(dbs[i].db->schema->name, db_name)) {
290 static char * WARN_UNUSED_RESULT
291 parse_db_column__(const struct db dbs[], size_t n_dbs,
292 const char *name_, char *name,
293 const struct db **dbp,
294 const struct ovsdb_table **tablep,
295 const struct ovsdb_column **columnp)
297 const char *table_name, *column_name;
298 const struct ovsdb_column *column;
299 const struct ovsdb_table *table;
300 const char *tokens[3];
301 char *save_ptr = NULL;
308 strtok_r(name, ":", &save_ptr); /* "db:" */
309 tokens[0] = strtok_r(NULL, ",", &save_ptr);
310 tokens[1] = strtok_r(NULL, ",", &save_ptr);
311 tokens[2] = strtok_r(NULL, ",", &save_ptr);
312 if (!tokens[0] || !tokens[1]) {
313 return xasprintf("\"%s\": invalid syntax", name_);
316 const char *db_name = tokens[0];
317 table_name = tokens[1];
318 column_name = tokens[2];
320 db = find_db(dbs, n_dbs, tokens[0]);
322 return xasprintf("\"%s\": no database named %s", name_, db_name);
326 return xasprintf("\"%s\": database name must be specified "
327 "(because multiple databases are configured)",
331 table_name = tokens[0];
332 column_name = tokens[1];
336 table = ovsdb_get_table(db->db, table_name);
338 return xasprintf("\"%s\": no table named %s", name_, table_name);
341 column = ovsdb_table_schema_get_column(table->schema, column_name);
343 return xasprintf("\"%s\": table \"%s\" has no column \"%s\"",
344 name_, table_name, column_name);
353 /* Returns NULL if successful, otherwise a malloc()'d string describing the
355 static char * WARN_UNUSED_RESULT
356 parse_db_column(const struct db dbs[], size_t n_dbs,
358 const struct db **dbp,
359 const struct ovsdb_table **tablep,
360 const struct ovsdb_column **columnp)
362 char *name = xstrdup(name_);
363 char *retval = parse_db_column__(dbs, n_dbs, name_, name,
364 dbp, tablep, columnp);
369 /* Returns NULL if successful, otherwise a malloc()'d string describing the
371 static char * WARN_UNUSED_RESULT
372 parse_db_string_column(const struct db dbs[], size_t n_dbs,
374 const struct db **dbp,
375 const struct ovsdb_table **tablep,
376 const struct ovsdb_column **columnp)
380 retval = parse_db_column(dbs, n_dbs, name, dbp, tablep, columnp);
385 if ((*columnp)->type.key.type != OVSDB_TYPE_STRING
386 || (*columnp)->type.value.type != OVSDB_TYPE_VOID) {
387 return xasprintf("\"%s\": table \"%s\" column \"%s\" is "
388 "not string or set of strings",
389 name, (*tablep)->schema->name, (*columnp)->name);
395 static OVS_UNUSED const char *
396 query_db_string(const struct db dbs[], size_t n_dbs, const char *name)
398 if (!name || strncmp(name, "db:", 3)) {
401 const struct ovsdb_column *column;
402 const struct ovsdb_table *table;
403 const struct ovsdb_row *row;
407 retval = parse_db_string_column(dbs, n_dbs, name,
408 &db, &table, &column);
410 ovs_fatal(0, "%s", retval);
413 HMAP_FOR_EACH (row, hmap_node, &table->rows) {
414 const struct ovsdb_datum *datum;
417 datum = &row->fields[column->index];
418 for (i = 0; i < datum->n; i++) {
419 if (datum->keys[i].string[0]) {
420 return datum->keys[i].string;
428 static struct ovsdb_jsonrpc_options *
429 add_remote(struct shash *remotes, const char *target)
431 struct ovsdb_jsonrpc_options *options;
433 options = shash_find_data(remotes, target);
435 options = ovsdb_jsonrpc_default_options(target);
436 shash_add(remotes, target, options);
442 static struct ovsdb_datum *
443 get_datum(struct ovsdb_row *row, const char *column_name,
444 const enum ovsdb_atomic_type key_type,
445 const enum ovsdb_atomic_type value_type,
448 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
449 const struct ovsdb_table_schema *schema = row->table->schema;
450 const struct ovsdb_column *column;
452 column = ovsdb_table_schema_get_column(schema, column_name);
454 VLOG_DBG_RL(&rl, "Table `%s' has no `%s' column",
455 schema->name, column_name);
459 if (column->type.key.type != key_type
460 || column->type.value.type != value_type
461 || column->type.n_max != n_max) {
462 if (!VLOG_DROP_DBG(&rl)) {
463 char *type_name = ovsdb_type_to_english(&column->type);
464 VLOG_DBG("Table `%s' column `%s' has type %s, not expected "
465 "key type %s, value type %s, max elements %zd.",
466 schema->name, column_name, type_name,
467 ovsdb_atomic_type_to_string(key_type),
468 ovsdb_atomic_type_to_string(value_type),
475 return &row->fields[column->index];
478 /* Read string-string key-values from a map. Returns the value associated with
479 * 'key', if found, or NULL */
481 read_map_string_column(const struct ovsdb_row *row, const char *column_name,
484 const struct ovsdb_datum *datum;
485 union ovsdb_atom *atom_key = NULL, *atom_value = NULL;
488 datum = get_datum(CONST_CAST(struct ovsdb_row *, row), column_name,
489 OVSDB_TYPE_STRING, OVSDB_TYPE_STRING, UINT_MAX);
495 for (i = 0; i < datum->n; i++) {
496 atom_key = &datum->keys[i];
497 if (!strcmp(atom_key->string, key)){
498 atom_value = &datum->values[i];
503 return atom_value ? atom_value->string : NULL;
506 static const union ovsdb_atom *
507 read_column(const struct ovsdb_row *row, const char *column_name,
508 enum ovsdb_atomic_type type)
510 const struct ovsdb_datum *datum;
512 datum = get_datum(CONST_CAST(struct ovsdb_row *, row), column_name, type,
514 return datum && datum->n ? datum->keys : NULL;
518 read_integer_column(const struct ovsdb_row *row, const char *column_name,
519 long long int *integerp)
521 const union ovsdb_atom *atom;
523 atom = read_column(row, column_name, OVSDB_TYPE_INTEGER);
524 *integerp = atom ? atom->integer : 0;
529 read_string_column(const struct ovsdb_row *row, const char *column_name,
530 const char **stringp)
532 const union ovsdb_atom *atom;
534 atom = read_column(row, column_name, OVSDB_TYPE_STRING);
535 *stringp = atom ? atom->string : NULL;
540 write_bool_column(struct ovsdb_row *row, const char *column_name, bool value)
542 const struct ovsdb_column *column;
543 struct ovsdb_datum *datum;
545 column = ovsdb_table_schema_get_column(row->table->schema, column_name);
546 datum = get_datum(row, column_name, OVSDB_TYPE_BOOLEAN,
553 ovsdb_datum_destroy(datum, &column->type);
556 datum->keys = xmalloc(sizeof *datum->keys);
557 datum->values = NULL;
560 datum->keys[0].boolean = value;
564 write_string_string_column(struct ovsdb_row *row, const char *column_name,
565 char **keys, char **values, size_t n)
567 const struct ovsdb_column *column;
568 struct ovsdb_datum *datum;
571 column = ovsdb_table_schema_get_column(row->table->schema, column_name);
572 datum = get_datum(row, column_name, OVSDB_TYPE_STRING, OVSDB_TYPE_STRING,
575 for (i = 0; i < n; i++) {
582 /* Free existing data. */
583 ovsdb_datum_destroy(datum, &column->type);
585 /* Allocate space for new values. */
587 datum->keys = xmalloc(n * sizeof *datum->keys);
588 datum->values = xmalloc(n * sizeof *datum->values);
590 for (i = 0; i < n; ++i) {
591 datum->keys[i].string = keys[i];
592 datum->values[i].string = values[i];
595 /* Sort and check constraints. */
596 ovsdb_datum_sort_assert(datum, column->type.key.type);
599 /* Adds a remote and options to 'remotes', based on the Manager table row in
602 add_manager_options(struct shash *remotes, const struct ovsdb_row *row)
604 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
605 struct ovsdb_jsonrpc_options *options;
606 long long int max_backoff, probe_interval;
607 const char *target, *dscp_string;
609 if (!read_string_column(row, "target", &target) || !target) {
610 VLOG_INFO_RL(&rl, "Table `%s' has missing or invalid `target' column",
611 row->table->schema->name);
615 options = add_remote(remotes, target);
616 if (read_integer_column(row, "max_backoff", &max_backoff)) {
617 options->max_backoff = max_backoff;
619 if (read_integer_column(row, "inactivity_probe", &probe_interval)) {
620 options->probe_interval = probe_interval;
623 options->dscp = DSCP_DEFAULT;
624 dscp_string = read_map_string_column(row, "other_config", "dscp");
626 int dscp = atoi(dscp_string);
627 if (dscp >= 0 && dscp <= 63) {
628 options->dscp = dscp;
634 query_db_remotes(const char *name, const struct db dbs[], size_t n_dbs,
635 struct shash *remotes)
637 const struct ovsdb_column *column;
638 const struct ovsdb_table *table;
639 const struct ovsdb_row *row;
643 retval = parse_db_column(dbs, n_dbs, name, &db, &table, &column);
645 ovs_fatal(0, "%s", retval);
648 if (column->type.key.type == OVSDB_TYPE_STRING
649 && column->type.value.type == OVSDB_TYPE_VOID) {
650 HMAP_FOR_EACH (row, hmap_node, &table->rows) {
651 const struct ovsdb_datum *datum;
654 datum = &row->fields[column->index];
655 for (i = 0; i < datum->n; i++) {
656 add_remote(remotes, datum->keys[i].string);
659 } else if (column->type.key.type == OVSDB_TYPE_UUID
660 && column->type.key.u.uuid.refTable
661 && column->type.value.type == OVSDB_TYPE_VOID) {
662 const struct ovsdb_table *ref_table = column->type.key.u.uuid.refTable;
663 HMAP_FOR_EACH (row, hmap_node, &table->rows) {
664 const struct ovsdb_datum *datum;
667 datum = &row->fields[column->index];
668 for (i = 0; i < datum->n; i++) {
669 const struct ovsdb_row *ref_row;
671 ref_row = ovsdb_table_get_row(ref_table, &datum->keys[i].uuid);
673 add_manager_options(remotes, ref_row);
681 update_remote_row(const struct ovsdb_row *row, struct ovsdb_txn *txn,
682 const struct ovsdb_jsonrpc_server *jsonrpc)
684 struct ovsdb_jsonrpc_remote_status status;
685 struct ovsdb_row *rw_row;
687 char *keys[9], *values[9];
690 /* Get the "target" (protocol/host/port) spec. */
691 if (!read_string_column(row, "target", &target)) {
692 /* Bad remote spec or incorrect schema. */
695 rw_row = ovsdb_txn_row_modify(txn, row);
696 ovsdb_jsonrpc_server_get_remote_status(jsonrpc, target, &status);
698 /* Update status information columns. */
699 write_bool_column(rw_row, "is_connected", status.is_connected);
702 keys[n] = xstrdup("state");
703 values[n++] = xstrdup(status.state);
705 if (status.sec_since_connect != UINT_MAX) {
706 keys[n] = xstrdup("sec_since_connect");
707 values[n++] = xasprintf("%u", status.sec_since_connect);
709 if (status.sec_since_disconnect != UINT_MAX) {
710 keys[n] = xstrdup("sec_since_disconnect");
711 values[n++] = xasprintf("%u", status.sec_since_disconnect);
713 if (status.last_error) {
714 keys[n] = xstrdup("last_error");
716 xstrdup(ovs_retval_to_string(status.last_error));
718 if (status.locks_held && status.locks_held[0]) {
719 keys[n] = xstrdup("locks_held");
720 values[n++] = xstrdup(status.locks_held);
722 if (status.locks_waiting && status.locks_waiting[0]) {
723 keys[n] = xstrdup("locks_waiting");
724 values[n++] = xstrdup(status.locks_waiting);
726 if (status.locks_lost && status.locks_lost[0]) {
727 keys[n] = xstrdup("locks_lost");
728 values[n++] = xstrdup(status.locks_lost);
730 if (status.n_connections > 1) {
731 keys[n] = xstrdup("n_connections");
732 values[n++] = xasprintf("%d", status.n_connections);
734 if (status.bound_port != htons(0)) {
735 keys[n] = xstrdup("bound_port");
736 values[n++] = xasprintf("%"PRIu16, ntohs(status.bound_port));
738 write_string_string_column(rw_row, "status", keys, values, n);
740 ovsdb_jsonrpc_server_free_remote_status(&status);
744 update_remote_rows(const struct db dbs[], size_t n_dbs,
745 const char *remote_name,
746 const struct ovsdb_jsonrpc_server *jsonrpc)
748 const struct ovsdb_table *table, *ref_table;
749 const struct ovsdb_column *column;
750 const struct ovsdb_row *row;
754 if (strncmp("db:", remote_name, 3)) {
758 retval = parse_db_column(dbs, n_dbs, remote_name, &db, &table, &column);
760 ovs_fatal(0, "%s", retval);
763 if (column->type.key.type != OVSDB_TYPE_UUID
764 || !column->type.key.u.uuid.refTable
765 || column->type.value.type != OVSDB_TYPE_VOID) {
769 ref_table = column->type.key.u.uuid.refTable;
771 HMAP_FOR_EACH (row, hmap_node, &table->rows) {
772 const struct ovsdb_datum *datum;
775 datum = &row->fields[column->index];
776 for (i = 0; i < datum->n; i++) {
777 const struct ovsdb_row *ref_row;
779 ref_row = ovsdb_table_get_row(ref_table, &datum->keys[i].uuid);
781 update_remote_row(ref_row, db->txn, jsonrpc);
788 update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
789 const struct sset *remotes,
790 struct db dbs[], size_t n_dbs)
792 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
796 for (i = 0; i < n_dbs; i++) {
797 dbs[i].txn = ovsdb_txn_create(dbs[i].db);
800 /* Iterate over --remote arguments given on command line. */
801 SSET_FOR_EACH (remote, remotes) {
802 update_remote_rows(dbs, n_dbs, remote, jsonrpc);
805 for (i = 0; i < n_dbs; i++) {
806 struct ovsdb_error *error = ovsdb_txn_commit(dbs[i].txn, false);
808 VLOG_ERR_RL(&rl, "Failed to update remote status: %s",
809 ovsdb_error_to_string(error));
810 ovsdb_error_destroy(error);
815 /* Reconfigures ovsdb-server based on information in the database. */
817 reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
818 const struct db dbs[], size_t n_dbs, struct sset *remotes)
820 struct shash resolved_remotes;
823 /* Configure remotes. */
824 shash_init(&resolved_remotes);
825 SSET_FOR_EACH (name, remotes) {
826 if (!strncmp(name, "db:", 3)) {
827 query_db_remotes(name, dbs, n_dbs, &resolved_remotes);
829 add_remote(&resolved_remotes, name);
832 ovsdb_jsonrpc_server_set_remotes(jsonrpc, &resolved_remotes);
833 shash_destroy_free_data(&resolved_remotes);
836 stream_ssl_set_key_and_cert(query_db_string(dbs, n_dbs, private_key_file),
837 query_db_string(dbs, n_dbs, certificate_file));
838 stream_ssl_set_ca_cert_file(query_db_string(dbs, n_dbs, ca_cert_file),
843 ovsdb_server_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
844 const char *argv[] OVS_UNUSED,
847 bool *exiting = exiting_;
849 unixctl_command_reply(conn, NULL);
853 ovsdb_server_compact(struct unixctl_conn *conn, int argc,
854 const char *argv[], void *dbs_)
856 struct db *dbs = dbs_;
862 for (db = dbs; db->filename != NULL; db++) {
863 const char *name = db->db->schema->name;
865 if (argc < 2 || !strcmp(argv[1], name)) {
866 struct ovsdb_error *error;
868 VLOG_INFO("compacting %s database by user request", name);
870 error = ovsdb_file_compact(db->file);
872 char *s = ovsdb_error_to_string(error);
873 ds_put_format(&reply, "%s\n", s);
882 unixctl_command_reply_error(conn, "no database by that name");
883 } else if (reply.length) {
884 unixctl_command_reply_error(conn, ds_cstr(&reply));
886 unixctl_command_reply(conn, NULL);
891 /* "ovsdb-server/reconnect": makes ovsdb-server drop all of its JSON-RPC
892 * connections and reconnect. */
894 ovsdb_server_reconnect(struct unixctl_conn *conn, int argc OVS_UNUSED,
895 const char *argv[] OVS_UNUSED, void *jsonrpc_)
897 struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_;
899 ovsdb_jsonrpc_server_reconnect(jsonrpc);
900 unixctl_command_reply(conn, NULL);
903 /* "ovsdb-server/add-remote REMOTE": adds REMOTE to the set of remotes that
904 * ovsdb-server services. */
906 ovsdb_server_add_remote(struct unixctl_conn *conn, int argc OVS_UNUSED,
907 const char *argv[], void *aux_)
909 struct add_remote_aux *aux = aux_;
910 const char *remote = argv[1];
912 const struct ovsdb_column *column;
913 const struct ovsdb_table *table;
917 retval = (strncmp("db:", remote, 3)
919 : parse_db_column(aux->dbs, aux->n_dbs, remote,
920 &db, &table, &column));
922 sset_add(aux->remotes, remote);
923 unixctl_command_reply(conn, NULL);
925 unixctl_command_reply_error(conn, retval);
930 /* "ovsdb-server/remove-remote REMOTE": removes REMOTE frmo the set of remotes
931 * that ovsdb-server services. */
933 ovsdb_server_remove_remote(struct unixctl_conn *conn, int argc OVS_UNUSED,
934 const char *argv[], void *remotes_)
936 struct sset *remotes = remotes_;
937 struct sset_node *node;
939 node = sset_find(remotes, argv[1]);
941 sset_delete(remotes, node);
942 unixctl_command_reply(conn, NULL);
944 unixctl_command_reply_error(conn, "no such remote");
948 /* "ovsdb-server/list-remotes": outputs a list of configured rmeotes. */
950 ovsdb_server_list_remotes(struct unixctl_conn *conn, int argc OVS_UNUSED,
951 const char *argv[] OVS_UNUSED, void *remotes_)
953 struct sset *remotes = remotes_;
954 const char **list, **p;
959 list = sset_sort(remotes);
960 for (p = list; *p; p++) {
961 ds_put_format(&s, "%s\n", *p);
965 unixctl_command_reply(conn, ds_cstr(&s));
970 parse_options(int *argcp, char **argvp[],
971 struct sset *remotes, char **unixctl_pathp, char **run_command)
974 OPT_REMOTE = UCHAR_MAX + 1,
977 OPT_BOOTSTRAP_CA_CERT,
980 LEAK_CHECKER_OPTION_ENUMS,
983 static const struct option long_options[] = {
984 {"remote", required_argument, NULL, OPT_REMOTE},
985 {"unixctl", required_argument, NULL, OPT_UNIXCTL},
986 {"run", required_argument, NULL, OPT_RUN},
987 {"help", no_argument, NULL, 'h'},
988 {"version", no_argument, NULL, 'V'},
991 LEAK_CHECKER_LONG_OPTIONS,
992 {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
993 {"private-key", required_argument, NULL, 'p'},
994 {"certificate", required_argument, NULL, 'c'},
995 {"ca-cert", required_argument, NULL, 'C'},
996 {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
999 char *short_options = long_options_to_short_options(long_options);
1001 char **argv = *argvp;
1007 c = getopt_long(argc, argv, short_options, long_options, NULL);
1014 sset_add(remotes, optarg);
1018 *unixctl_pathp = optarg;
1022 *run_command = optarg;
1029 ovs_print_version(0, 0);
1032 VLOG_OPTION_HANDLERS
1033 DAEMON_OPTION_HANDLERS
1034 LEAK_CHECKER_OPTION_HANDLERS
1037 private_key_file = optarg;
1041 certificate_file = optarg;
1045 ca_cert_file = optarg;
1046 bootstrap_ca_cert = false;
1049 case OPT_BOOTSTRAP_CA_CERT:
1050 ca_cert_file = optarg;
1051 bootstrap_ca_cert = true;
1054 case OPT_ENABLE_DUMMY:
1055 dummy_enable(optarg && !strcmp(optarg, "override"));
1065 free(short_options);
1074 printf("%s: Open vSwitch database server\n"
1075 "usage: %s [OPTIONS] [DATABASE...]\n"
1076 "where each DATABASE is a database file in ovsdb format.\n"
1077 "The default DATABASE, if none is given, is\n%s/conf.db.\n",
1078 program_name, program_name, ovs_dbdir());
1079 printf("\nJSON-RPC options (may be specified any number of times):\n"
1080 " --remote=REMOTE connect or listen to REMOTE\n");
1081 stream_usage("JSON-RPC", true, true, true);
1084 printf("\nOther options:\n"
1085 " --run COMMAND run COMMAND as subprocess then exit\n"
1086 " --unixctl=SOCKET override default control socket name\n"
1087 " -h, --help display this help message\n"
1088 " -V, --version display version information\n");
1089 leak_checker_usage();