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.
24 #include "command-line.h"
28 #include "dynamic-string.h"
33 #include "jsonrpc-server.h"
34 #include "leak-checker.h"
38 #include "ovsdb-data.h"
39 #include "ovsdb-types.h"
40 #include "ovsdb-error.h"
41 #include "poll-loop.h"
45 #include "stream-ssl.h"
51 #include "transaction.h"
57 VLOG_DEFINE_THIS_MODULE(ovsdb_server);
60 /* Initialized in main(). */
62 struct ovsdb_file *file;
65 /* Only used by update_remote_status(). */
66 struct ovsdb_txn *txn;
69 /* SSL configuration. */
70 static char *private_key_file;
71 static char *certificate_file;
72 static char *ca_cert_file;
73 static bool bootstrap_ca_cert;
75 static unixctl_cb_func ovsdb_server_exit;
76 static unixctl_cb_func ovsdb_server_compact;
77 static unixctl_cb_func ovsdb_server_reconnect;
79 struct add_remote_aux {
84 static unixctl_cb_func ovsdb_server_add_remote;
85 static unixctl_cb_func ovsdb_server_remove_remote;
86 static unixctl_cb_func ovsdb_server_list_remotes;
88 static void parse_options(int *argc, char **argvp[],
89 struct sset *remotes, char **unixctl_pathp,
91 static void usage(void) NO_RETURN;
93 static void reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
94 const struct db dbs[], size_t n_dbs,
95 struct sset *remotes);
97 static void update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
98 const struct sset *remotes,
99 struct db dbs[], size_t n_dbs);
102 main(int argc, char *argv[])
104 char *unixctl_path = NULL;
105 char *run_command = NULL;
106 struct unixctl_server *unixctl;
107 struct ovsdb_jsonrpc_server *jsonrpc;
109 struct process *run_process;
112 long long int status_timer = LLONG_MIN;
113 struct add_remote_aux add_remote_aux;
119 proctitle_init(argc, argv);
120 set_program_name(argv[0]);
121 stress_init_command();
122 signal(SIGPIPE, SIG_IGN);
125 parse_options(&argc, &argv, &remotes, &unixctl_path, &run_command);
129 n_dbs = MAX(1, argc);
130 dbs = xcalloc(n_dbs + 1, sizeof *dbs);
132 for (i = 0; i < argc; i++) {
133 dbs[i].filename = argv[i];
136 dbs[0].filename = xasprintf("%s/conf.db", ovs_dbdir());
139 for (i = 0; i < n_dbs; i++) {
140 struct ovsdb_error *error;
142 error = ovsdb_file_open(dbs[i].filename, false,
143 &dbs[i].db, &dbs[i].file);
145 ovs_fatal(0, "%s", ovsdb_error_to_string(error));
149 jsonrpc = ovsdb_jsonrpc_server_create();
150 for (i = 0; i < n_dbs; i++) {
151 if (!ovsdb_jsonrpc_server_add_db(jsonrpc, dbs[i].db)) {
152 ovs_fatal(0, "%s: duplicate database name",
153 dbs[i].db->schema->name);
156 reconfigure_from_db(jsonrpc, dbs, n_dbs, &remotes);
158 retval = unixctl_server_create(unixctl_path, &unixctl);
166 run_argv[0] = "/bin/sh";
168 run_argv[2] = run_command;
171 retval = process_start(run_argv, NULL, 0, NULL, 0, &run_process);
173 ovs_fatal(retval, "%s: process failed to start", run_command);
179 daemonize_complete();
182 /* ovsdb-server is usually a long-running process, in which case it
183 * makes plenty of sense to log the version, but --run makes
184 * ovsdb-server more like a command-line tool, so skip it. */
185 VLOG_INFO("%s (Open vSwitch) %s", program_name, VERSION);
188 unixctl_command_register("exit", "", 0, 0, ovsdb_server_exit, &exiting);
189 unixctl_command_register("ovsdb-server/compact", "", 0, 1,
190 ovsdb_server_compact, dbs);
191 unixctl_command_register("ovsdb-server/reconnect", "", 0, 0,
192 ovsdb_server_reconnect, jsonrpc);
194 add_remote_aux.remotes = &remotes;
195 add_remote_aux.dbs = dbs;
196 add_remote_aux.n_dbs = n_dbs;
197 unixctl_command_register("ovsdb-server/add-remote", "REMOTE", 1, 1,
198 ovsdb_server_add_remote, &add_remote_aux);
199 unixctl_command_register("ovsdb-server/remove-remote", "REMOTE", 1, 1,
200 ovsdb_server_remove_remote, &remotes);
201 unixctl_command_register("ovsdb-server/list-remotes", "", 0, 0,
202 ovsdb_server_list_remotes, &remotes);
209 if (memory_should_report()) {
213 ovsdb_jsonrpc_server_get_memory_usage(jsonrpc, &usage);
214 for (i = 0; i < n_dbs; i++) {
215 ovsdb_get_memory_usage(dbs[i].db, &usage);
217 memory_report(&usage);
218 simap_destroy(&usage);
221 /* Run unixctl_server_run() before reconfigure_from_db() because
222 * ovsdb-server/add-remote and ovsdb-server/remove-remote can change
223 * the set of remotes that reconfigure_from_db() uses. */
224 unixctl_server_run(unixctl);
226 reconfigure_from_db(jsonrpc, dbs, n_dbs, &remotes);
227 ovsdb_jsonrpc_server_run(jsonrpc);
229 for (i = 0; i < n_dbs; i++) {
230 ovsdb_trigger_run(dbs[i].db, time_msec());
232 if (run_process && process_exited(run_process)) {
236 /* update Manager status(es) every 5 seconds */
237 if (time_msec() >= status_timer) {
238 status_timer = time_msec() + 5000;
239 update_remote_status(jsonrpc, &remotes, dbs, n_dbs);
243 ovsdb_jsonrpc_server_wait(jsonrpc);
244 unixctl_server_wait(unixctl);
245 for (i = 0; i < n_dbs; i++) {
246 ovsdb_trigger_wait(dbs[i].db, time_msec());
249 process_wait(run_process);
252 poll_immediate_wake();
254 poll_timer_wait_until(status_timer);
257 ovsdb_jsonrpc_server_destroy(jsonrpc);
258 for (i = 0; i < n_dbs; i++) {
259 ovsdb_destroy(dbs[i].db);
261 sset_destroy(&remotes);
262 unixctl_server_destroy(unixctl);
264 if (run_process && process_exited(run_process)) {
265 int status = process_status(run_process);
267 ovs_fatal(0, "%s: child exited, %s",
268 run_command, process_status_msg(status));
275 static const struct db *
276 find_db(const struct db dbs[], size_t n_dbs, const char *db_name)
280 for (i = 0; i < n_dbs; i++) {
281 if (!strcmp(dbs[i].db->schema->name, db_name)) {
289 static char * WARN_UNUSED_RESULT
290 parse_db_column__(const struct db dbs[], size_t n_dbs,
291 const char *name_, char *name,
292 const struct db **dbp,
293 const struct ovsdb_table **tablep,
294 const struct ovsdb_column **columnp)
296 const char *table_name, *column_name;
297 const struct ovsdb_column *column;
298 const struct ovsdb_table *table;
299 const char *tokens[3];
300 char *save_ptr = NULL;
307 strtok_r(name, ":", &save_ptr); /* "db:" */
308 tokens[0] = strtok_r(NULL, ",", &save_ptr);
309 tokens[1] = strtok_r(NULL, ",", &save_ptr);
310 tokens[2] = strtok_r(NULL, ",", &save_ptr);
311 if (!tokens[0] || !tokens[1]) {
312 return xasprintf("\"%s\": invalid syntax", name_);
315 const char *db_name = tokens[0];
316 table_name = tokens[1];
317 column_name = tokens[2];
319 db = find_db(dbs, n_dbs, tokens[0]);
321 return xasprintf("\"%s\": no database named %s", name_, db_name);
325 return xasprintf("\"%s\": database name must be specified "
326 "(because multiple databases are configured)",
330 table_name = tokens[0];
331 column_name = tokens[1];
335 table = ovsdb_get_table(db->db, table_name);
337 return xasprintf("\"%s\": no table named %s", name_, table_name);
340 column = ovsdb_table_schema_get_column(table->schema, column_name);
342 return xasprintf("\"%s\": table \"%s\" has no column \"%s\"",
343 name_, table_name, column_name);
352 /* Returns NULL if successful, otherwise a malloc()'d string describing the
354 static char * WARN_UNUSED_RESULT
355 parse_db_column(const struct db dbs[], size_t n_dbs,
357 const struct db **dbp,
358 const struct ovsdb_table **tablep,
359 const struct ovsdb_column **columnp)
361 char *name = xstrdup(name_);
362 char *retval = parse_db_column__(dbs, n_dbs, name_, name,
363 dbp, tablep, columnp);
368 /* Returns NULL if successful, otherwise a malloc()'d string describing the
370 static char * WARN_UNUSED_RESULT
371 parse_db_string_column(const struct db dbs[], size_t n_dbs,
373 const struct db **dbp,
374 const struct ovsdb_table **tablep,
375 const struct ovsdb_column **columnp)
379 retval = parse_db_column(dbs, n_dbs, name, dbp, tablep, columnp);
384 if ((*columnp)->type.key.type != OVSDB_TYPE_STRING
385 || (*columnp)->type.value.type != OVSDB_TYPE_VOID) {
386 return xasprintf("\"%s\": table \"%s\" column \"%s\" is "
387 "not string or set of strings",
388 name, (*tablep)->schema->name, (*columnp)->name);
394 static OVS_UNUSED const char *
395 query_db_string(const struct db dbs[], size_t n_dbs, const char *name)
397 if (!name || strncmp(name, "db:", 3)) {
400 const struct ovsdb_column *column;
401 const struct ovsdb_table *table;
402 const struct ovsdb_row *row;
406 retval = parse_db_string_column(dbs, n_dbs, name,
407 &db, &table, &column);
409 ovs_fatal(0, "%s", retval);
412 HMAP_FOR_EACH (row, hmap_node, &table->rows) {
413 const struct ovsdb_datum *datum;
416 datum = &row->fields[column->index];
417 for (i = 0; i < datum->n; i++) {
418 if (datum->keys[i].string[0]) {
419 return datum->keys[i].string;
427 static struct ovsdb_jsonrpc_options *
428 add_remote(struct shash *remotes, const char *target)
430 struct ovsdb_jsonrpc_options *options;
432 options = shash_find_data(remotes, target);
434 options = ovsdb_jsonrpc_default_options(target);
435 shash_add(remotes, target, options);
441 static struct ovsdb_datum *
442 get_datum(struct ovsdb_row *row, const char *column_name,
443 const enum ovsdb_atomic_type key_type,
444 const enum ovsdb_atomic_type value_type,
447 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
448 const struct ovsdb_table_schema *schema = row->table->schema;
449 const struct ovsdb_column *column;
451 column = ovsdb_table_schema_get_column(schema, column_name);
453 VLOG_DBG_RL(&rl, "Table `%s' has no `%s' column",
454 schema->name, column_name);
458 if (column->type.key.type != key_type
459 || column->type.value.type != value_type
460 || column->type.n_max != n_max) {
461 if (!VLOG_DROP_DBG(&rl)) {
462 char *type_name = ovsdb_type_to_english(&column->type);
463 VLOG_DBG("Table `%s' column `%s' has type %s, not expected "
464 "key type %s, value type %s, max elements %zd.",
465 schema->name, column_name, type_name,
466 ovsdb_atomic_type_to_string(key_type),
467 ovsdb_atomic_type_to_string(value_type),
474 return &row->fields[column->index];
477 /* Read string-string key-values from a map. Returns the value associated with
478 * 'key', if found, or NULL */
480 read_map_string_column(const struct ovsdb_row *row, const char *column_name,
483 const struct ovsdb_datum *datum;
484 union ovsdb_atom *atom_key = NULL, *atom_value = NULL;
487 datum = get_datum(CONST_CAST(struct ovsdb_row *, row), column_name,
488 OVSDB_TYPE_STRING, OVSDB_TYPE_STRING, UINT_MAX);
494 for (i = 0; i < datum->n; i++) {
495 atom_key = &datum->keys[i];
496 if (!strcmp(atom_key->string, key)){
497 atom_value = &datum->values[i];
502 return atom_value ? atom_value->string : NULL;
505 static const union ovsdb_atom *
506 read_column(const struct ovsdb_row *row, const char *column_name,
507 enum ovsdb_atomic_type type)
509 const struct ovsdb_datum *datum;
511 datum = get_datum(CONST_CAST(struct ovsdb_row *, row), column_name, type,
513 return datum && datum->n ? datum->keys : NULL;
517 read_integer_column(const struct ovsdb_row *row, const char *column_name,
518 long long int *integerp)
520 const union ovsdb_atom *atom;
522 atom = read_column(row, column_name, OVSDB_TYPE_INTEGER);
523 *integerp = atom ? atom->integer : 0;
528 read_string_column(const struct ovsdb_row *row, const char *column_name,
529 const char **stringp)
531 const union ovsdb_atom *atom;
533 atom = read_column(row, column_name, OVSDB_TYPE_STRING);
534 *stringp = atom ? atom->string : NULL;
539 write_bool_column(struct ovsdb_row *row, const char *column_name, bool value)
541 const struct ovsdb_column *column;
542 struct ovsdb_datum *datum;
544 column = ovsdb_table_schema_get_column(row->table->schema, column_name);
545 datum = get_datum(row, column_name, OVSDB_TYPE_BOOLEAN,
552 ovsdb_datum_destroy(datum, &column->type);
555 datum->keys = xmalloc(sizeof *datum->keys);
556 datum->values = NULL;
559 datum->keys[0].boolean = value;
563 write_string_string_column(struct ovsdb_row *row, const char *column_name,
564 char **keys, char **values, size_t n)
566 const struct ovsdb_column *column;
567 struct ovsdb_datum *datum;
570 column = ovsdb_table_schema_get_column(row->table->schema, column_name);
571 datum = get_datum(row, column_name, OVSDB_TYPE_STRING, OVSDB_TYPE_STRING,
574 for (i = 0; i < n; i++) {
581 /* Free existing data. */
582 ovsdb_datum_destroy(datum, &column->type);
584 /* Allocate space for new values. */
586 datum->keys = xmalloc(n * sizeof *datum->keys);
587 datum->values = xmalloc(n * sizeof *datum->values);
589 for (i = 0; i < n; ++i) {
590 datum->keys[i].string = keys[i];
591 datum->values[i].string = values[i];
594 /* Sort and check constraints. */
595 ovsdb_datum_sort_assert(datum, column->type.key.type);
598 /* Adds a remote and options to 'remotes', based on the Manager table row in
601 add_manager_options(struct shash *remotes, const struct ovsdb_row *row)
603 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
604 struct ovsdb_jsonrpc_options *options;
605 long long int max_backoff, probe_interval;
606 const char *target, *dscp_string;
608 if (!read_string_column(row, "target", &target) || !target) {
609 VLOG_INFO_RL(&rl, "Table `%s' has missing or invalid `target' column",
610 row->table->schema->name);
614 options = add_remote(remotes, target);
615 if (read_integer_column(row, "max_backoff", &max_backoff)) {
616 options->max_backoff = max_backoff;
618 if (read_integer_column(row, "inactivity_probe", &probe_interval)) {
619 options->probe_interval = probe_interval;
622 options->dscp = DSCP_DEFAULT;
623 dscp_string = read_map_string_column(row, "other_config", "dscp");
625 int dscp = atoi(dscp_string);
626 if (dscp >= 0 && dscp <= 63) {
627 options->dscp = dscp;
633 query_db_remotes(const char *name, const struct db dbs[], size_t n_dbs,
634 struct shash *remotes)
636 const struct ovsdb_column *column;
637 const struct ovsdb_table *table;
638 const struct ovsdb_row *row;
642 retval = parse_db_column(dbs, n_dbs, name, &db, &table, &column);
644 ovs_fatal(0, "%s", retval);
647 if (column->type.key.type == OVSDB_TYPE_STRING
648 && column->type.value.type == OVSDB_TYPE_VOID) {
649 HMAP_FOR_EACH (row, hmap_node, &table->rows) {
650 const struct ovsdb_datum *datum;
653 datum = &row->fields[column->index];
654 for (i = 0; i < datum->n; i++) {
655 add_remote(remotes, datum->keys[i].string);
658 } else if (column->type.key.type == OVSDB_TYPE_UUID
659 && column->type.key.u.uuid.refTable
660 && column->type.value.type == OVSDB_TYPE_VOID) {
661 const struct ovsdb_table *ref_table = column->type.key.u.uuid.refTable;
662 HMAP_FOR_EACH (row, hmap_node, &table->rows) {
663 const struct ovsdb_datum *datum;
666 datum = &row->fields[column->index];
667 for (i = 0; i < datum->n; i++) {
668 const struct ovsdb_row *ref_row;
670 ref_row = ovsdb_table_get_row(ref_table, &datum->keys[i].uuid);
672 add_manager_options(remotes, ref_row);
680 update_remote_row(const struct ovsdb_row *row, struct ovsdb_txn *txn,
681 const struct ovsdb_jsonrpc_server *jsonrpc)
683 struct ovsdb_jsonrpc_remote_status status;
684 struct ovsdb_row *rw_row;
686 char *keys[8], *values[8];
689 /* Get the "target" (protocol/host/port) spec. */
690 if (!read_string_column(row, "target", &target)) {
691 /* Bad remote spec or incorrect schema. */
694 rw_row = ovsdb_txn_row_modify(txn, row);
695 ovsdb_jsonrpc_server_get_remote_status(jsonrpc, target, &status);
697 /* Update status information columns. */
698 write_bool_column(rw_row, "is_connected", status.is_connected);
701 keys[n] = xstrdup("state");
702 values[n++] = xstrdup(status.state);
704 if (status.sec_since_connect != UINT_MAX) {
705 keys[n] = xstrdup("sec_since_connect");
706 values[n++] = xasprintf("%u", status.sec_since_connect);
708 if (status.sec_since_disconnect != UINT_MAX) {
709 keys[n] = xstrdup("sec_since_disconnect");
710 values[n++] = xasprintf("%u", status.sec_since_disconnect);
712 if (status.last_error) {
713 keys[n] = xstrdup("last_error");
715 xstrdup(ovs_retval_to_string(status.last_error));
717 if (status.locks_held && status.locks_held[0]) {
718 keys[n] = xstrdup("locks_held");
719 values[n++] = xstrdup(status.locks_held);
721 if (status.locks_waiting && status.locks_waiting[0]) {
722 keys[n] = xstrdup("locks_waiting");
723 values[n++] = xstrdup(status.locks_waiting);
725 if (status.locks_lost && status.locks_lost[0]) {
726 keys[n] = xstrdup("locks_lost");
727 values[n++] = xstrdup(status.locks_lost);
729 if (status.n_connections > 1) {
730 keys[n] = xstrdup("n_connections");
731 values[n++] = xasprintf("%d", status.n_connections);
733 write_string_string_column(rw_row, "status", keys, values, n);
735 ovsdb_jsonrpc_server_free_remote_status(&status);
739 update_remote_rows(const struct db dbs[], size_t n_dbs,
740 const char *remote_name,
741 const struct ovsdb_jsonrpc_server *jsonrpc)
743 const struct ovsdb_table *table, *ref_table;
744 const struct ovsdb_column *column;
745 const struct ovsdb_row *row;
749 if (strncmp("db:", remote_name, 3)) {
753 retval = parse_db_column(dbs, n_dbs, remote_name, &db, &table, &column);
755 ovs_fatal(0, "%s", retval);
758 if (column->type.key.type != OVSDB_TYPE_UUID
759 || !column->type.key.u.uuid.refTable
760 || column->type.value.type != OVSDB_TYPE_VOID) {
764 ref_table = column->type.key.u.uuid.refTable;
766 HMAP_FOR_EACH (row, hmap_node, &table->rows) {
767 const struct ovsdb_datum *datum;
770 datum = &row->fields[column->index];
771 for (i = 0; i < datum->n; i++) {
772 const struct ovsdb_row *ref_row;
774 ref_row = ovsdb_table_get_row(ref_table, &datum->keys[i].uuid);
776 update_remote_row(ref_row, db->txn, jsonrpc);
783 update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
784 const struct sset *remotes,
785 struct db dbs[], size_t n_dbs)
787 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
791 for (i = 0; i < n_dbs; i++) {
792 dbs[i].txn = ovsdb_txn_create(dbs[i].db);
795 /* Iterate over --remote arguments given on command line. */
796 SSET_FOR_EACH (remote, remotes) {
797 update_remote_rows(dbs, n_dbs, remote, jsonrpc);
800 for (i = 0; i < n_dbs; i++) {
801 struct ovsdb_error *error = ovsdb_txn_commit(dbs[i].txn, false);
803 VLOG_ERR_RL(&rl, "Failed to update remote status: %s",
804 ovsdb_error_to_string(error));
805 ovsdb_error_destroy(error);
810 /* Reconfigures ovsdb-server based on information in the database. */
812 reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
813 const struct db dbs[], size_t n_dbs, struct sset *remotes)
815 struct shash resolved_remotes;
818 /* Configure remotes. */
819 shash_init(&resolved_remotes);
820 SSET_FOR_EACH (name, remotes) {
821 if (!strncmp(name, "db:", 3)) {
822 query_db_remotes(name, dbs, n_dbs, &resolved_remotes);
824 add_remote(&resolved_remotes, name);
827 ovsdb_jsonrpc_server_set_remotes(jsonrpc, &resolved_remotes);
828 shash_destroy_free_data(&resolved_remotes);
831 stream_ssl_set_key_and_cert(query_db_string(dbs, n_dbs, private_key_file),
832 query_db_string(dbs, n_dbs, certificate_file));
833 stream_ssl_set_ca_cert_file(query_db_string(dbs, n_dbs, ca_cert_file),
838 ovsdb_server_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
839 const char *argv[] OVS_UNUSED,
842 bool *exiting = exiting_;
844 unixctl_command_reply(conn, NULL);
848 ovsdb_server_compact(struct unixctl_conn *conn, int argc,
849 const char *argv[], void *dbs_)
851 struct db *dbs = dbs_;
857 for (db = dbs; db->filename != NULL; db++) {
858 const char *name = db->db->schema->name;
860 if (argc < 2 || !strcmp(argv[1], name)) {
861 struct ovsdb_error *error;
863 VLOG_INFO("compacting %s database by user request", name);
865 error = ovsdb_file_compact(db->file);
867 char *s = ovsdb_error_to_string(error);
868 ds_put_format(&reply, "%s\n", s);
877 unixctl_command_reply_error(conn, "no database by that name");
878 } else if (reply.length) {
879 unixctl_command_reply_error(conn, ds_cstr(&reply));
881 unixctl_command_reply(conn, NULL);
886 /* "ovsdb-server/reconnect": makes ovsdb-server drop all of its JSON-RPC
887 * connections and reconnect. */
889 ovsdb_server_reconnect(struct unixctl_conn *conn, int argc OVS_UNUSED,
890 const char *argv[] OVS_UNUSED, void *jsonrpc_)
892 struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_;
894 ovsdb_jsonrpc_server_reconnect(jsonrpc);
895 unixctl_command_reply(conn, NULL);
898 /* "ovsdb-server/add-remote REMOTE": adds REMOTE to the set of remotes that
899 * ovsdb-server services. */
901 ovsdb_server_add_remote(struct unixctl_conn *conn, int argc OVS_UNUSED,
902 const char *argv[], void *aux_)
904 struct add_remote_aux *aux = aux_;
905 const char *remote = argv[1];
907 const struct ovsdb_column *column;
908 const struct ovsdb_table *table;
912 retval = (strncmp("db:", remote, 3)
914 : parse_db_column(aux->dbs, aux->n_dbs, remote,
915 &db, &table, &column));
917 sset_add(aux->remotes, remote);
918 unixctl_command_reply(conn, NULL);
920 unixctl_command_reply_error(conn, retval);
925 /* "ovsdb-server/remove-remote REMOTE": removes REMOTE frmo the set of remotes
926 * that ovsdb-server services. */
928 ovsdb_server_remove_remote(struct unixctl_conn *conn, int argc OVS_UNUSED,
929 const char *argv[], void *remotes_)
931 struct sset *remotes = remotes_;
932 struct sset_node *node;
934 node = sset_find(remotes, argv[1]);
936 sset_delete(remotes, node);
937 unixctl_command_reply(conn, NULL);
939 unixctl_command_reply_error(conn, "no such remote");
943 /* "ovsdb-server/list-remotes": outputs a list of configured rmeotes. */
945 ovsdb_server_list_remotes(struct unixctl_conn *conn, int argc OVS_UNUSED,
946 const char *argv[] OVS_UNUSED, void *remotes_)
948 struct sset *remotes = remotes_;
949 const char **list, **p;
954 list = sset_sort(remotes);
955 for (p = list; *p; p++) {
956 ds_put_format(&s, "%s\n", *p);
960 unixctl_command_reply(conn, ds_cstr(&s));
965 parse_options(int *argcp, char **argvp[],
966 struct sset *remotes, char **unixctl_pathp, char **run_command)
969 OPT_REMOTE = UCHAR_MAX + 1,
972 OPT_BOOTSTRAP_CA_CERT,
975 LEAK_CHECKER_OPTION_ENUMS,
978 static struct option long_options[] = {
979 {"remote", required_argument, NULL, OPT_REMOTE},
980 {"unixctl", required_argument, NULL, OPT_UNIXCTL},
981 {"run", required_argument, NULL, OPT_RUN},
982 {"help", no_argument, NULL, 'h'},
983 {"version", no_argument, NULL, 'V'},
986 LEAK_CHECKER_LONG_OPTIONS,
987 {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
988 {"private-key", required_argument, NULL, 'p'},
989 {"certificate", required_argument, NULL, 'c'},
990 {"ca-cert", required_argument, NULL, 'C'},
991 {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
994 char *short_options = long_options_to_short_options(long_options);
996 char **argv = *argvp;
1002 c = getopt_long(argc, argv, short_options, long_options, NULL);
1009 sset_add(remotes, optarg);
1013 *unixctl_pathp = optarg;
1017 *run_command = optarg;
1024 ovs_print_version(0, 0);
1027 VLOG_OPTION_HANDLERS
1028 DAEMON_OPTION_HANDLERS
1029 LEAK_CHECKER_OPTION_HANDLERS
1032 private_key_file = optarg;
1036 certificate_file = optarg;
1040 ca_cert_file = optarg;
1041 bootstrap_ca_cert = false;
1044 case OPT_BOOTSTRAP_CA_CERT:
1045 ca_cert_file = optarg;
1046 bootstrap_ca_cert = true;
1049 case OPT_ENABLE_DUMMY:
1050 dummy_enable(optarg && !strcmp(optarg, "override"));
1060 free(short_options);
1069 printf("%s: Open vSwitch database server\n"
1070 "usage: %s [OPTIONS] [DATABASE...]\n"
1071 "where each DATABASE is a database file in ovsdb format.\n"
1072 "The default DATABASE, if none is given, is\n%s/conf.db.\n",
1073 program_name, program_name, ovs_dbdir());
1074 printf("\nJSON-RPC options (may be specified any number of times):\n"
1075 " --remote=REMOTE connect or listen to REMOTE\n");
1076 stream_usage("JSON-RPC", true, true, true);
1079 printf("\nOther options:\n"
1080 " --run COMMAND run COMMAND as subprocess then exit\n"
1081 " --unixctl=SOCKET override default control socket name\n"
1082 " -h, --help display this help message\n"
1083 " -V, --version display version information\n");
1084 leak_checker_usage();