1 /* Copyright (c) 2009, 2010, 2011, 2012 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 static void parse_options(int *argc
, char **argvp
[],
80 struct sset
*remotes
, char **unixctl_pathp
,
82 static void usage(void) NO_RETURN
;
84 static void reconfigure_from_db(struct ovsdb_jsonrpc_server
*jsonrpc
,
85 const struct db dbs
[], size_t n_dbs
,
86 struct sset
*remotes
);
88 static void update_remote_status(const struct ovsdb_jsonrpc_server
*jsonrpc
,
89 const struct sset
*remotes
,
90 struct db dbs
[], size_t n_dbs
);
93 main(int argc
, char *argv
[])
95 char *unixctl_path
= NULL
;
96 char *run_command
= NULL
;
97 struct unixctl_server
*unixctl
;
98 struct ovsdb_jsonrpc_server
*jsonrpc
;
100 struct process
*run_process
;
103 long long int status_timer
= LLONG_MIN
;
109 proctitle_init(argc
, argv
);
110 set_program_name(argv
[0]);
111 stress_init_command();
112 signal(SIGPIPE
, SIG_IGN
);
115 parse_options(&argc
, &argv
, &remotes
, &unixctl_path
, &run_command
);
119 n_dbs
= MAX(1, argc
);
120 dbs
= xcalloc(n_dbs
+ 1, sizeof *dbs
);
122 for (i
= 0; i
< argc
; i
++) {
123 dbs
[i
].filename
= argv
[i
];
126 dbs
[0].filename
= xasprintf("%s/conf.db", ovs_dbdir());
129 for (i
= 0; i
< n_dbs
; i
++) {
130 struct ovsdb_error
*error
;
132 error
= ovsdb_file_open(dbs
[i
].filename
, false,
133 &dbs
[i
].db
, &dbs
[i
].file
);
135 ovs_fatal(0, "%s", ovsdb_error_to_string(error
));
139 jsonrpc
= ovsdb_jsonrpc_server_create();
140 for (i
= 0; i
< n_dbs
; i
++) {
141 if (!ovsdb_jsonrpc_server_add_db(jsonrpc
, dbs
[i
].db
)) {
142 ovs_fatal(0, "%s: duplicate database name",
143 dbs
[i
].db
->schema
->name
);
146 reconfigure_from_db(jsonrpc
, dbs
, n_dbs
, &remotes
);
148 retval
= unixctl_server_create(unixctl_path
, &unixctl
);
156 run_argv
[0] = "/bin/sh";
158 run_argv
[2] = run_command
;
161 retval
= process_start(run_argv
, NULL
, 0, NULL
, 0, &run_process
);
163 ovs_fatal(retval
, "%s: process failed to start", run_command
);
169 daemonize_complete();
172 /* ovsdb-server is usually a long-running process, in which case it
173 * makes plenty of sense to log the version, but --run makes
174 * ovsdb-server more like a command-line tool, so skip it. */
175 VLOG_INFO("%s (Open vSwitch) %s", program_name
, VERSION
);
178 unixctl_command_register("exit", "", 0, 0, ovsdb_server_exit
, &exiting
);
179 unixctl_command_register("ovsdb-server/compact", "", 0, 1,
180 ovsdb_server_compact
, dbs
);
181 unixctl_command_register("ovsdb-server/reconnect", "", 0, 0,
182 ovsdb_server_reconnect
, jsonrpc
);
189 if (memory_should_report()) {
193 ovsdb_jsonrpc_server_get_memory_usage(jsonrpc
, &usage
);
194 for (i
= 0; i
< n_dbs
; i
++) {
195 ovsdb_get_memory_usage(dbs
[i
].db
, &usage
);
197 memory_report(&usage
);
198 simap_destroy(&usage
);
201 reconfigure_from_db(jsonrpc
, dbs
, n_dbs
, &remotes
);
202 ovsdb_jsonrpc_server_run(jsonrpc
);
203 unixctl_server_run(unixctl
);
205 for (i
= 0; i
< n_dbs
; i
++) {
206 ovsdb_trigger_run(dbs
[i
].db
, time_msec());
208 if (run_process
&& process_exited(run_process
)) {
212 /* update Manager status(es) every 5 seconds */
213 if (time_msec() >= status_timer
) {
214 status_timer
= time_msec() + 5000;
215 update_remote_status(jsonrpc
, &remotes
, dbs
, n_dbs
);
219 ovsdb_jsonrpc_server_wait(jsonrpc
);
220 unixctl_server_wait(unixctl
);
221 for (i
= 0; i
< n_dbs
; i
++) {
222 ovsdb_trigger_wait(dbs
[i
].db
, time_msec());
225 process_wait(run_process
);
228 poll_immediate_wake();
230 poll_timer_wait_until(status_timer
);
233 ovsdb_jsonrpc_server_destroy(jsonrpc
);
234 for (i
= 0; i
< n_dbs
; i
++) {
235 ovsdb_destroy(dbs
[i
].db
);
237 sset_destroy(&remotes
);
238 unixctl_server_destroy(unixctl
);
240 if (run_process
&& process_exited(run_process
)) {
241 int status
= process_status(run_process
);
243 ovs_fatal(0, "%s: child exited, %s",
244 run_command
, process_status_msg(status
));
251 static const struct db
*
252 find_db(const struct db dbs
[], size_t n_dbs
, const char *db_name
)
256 for (i
= 0; i
< n_dbs
; i
++) {
257 if (!strcmp(dbs
[i
].db
->schema
->name
, db_name
)) {
266 parse_db_column(const struct db dbs
[], size_t n_dbs
,
268 const struct db
**dbp
,
269 const struct ovsdb_table
**tablep
,
270 const struct ovsdb_column
**columnp
)
272 const char *table_name
, *column_name
;
273 const struct ovsdb_column
*column
;
274 const struct ovsdb_table
*table
;
275 const char *tokens
[3];
276 char *save_ptr
= NULL
;
280 name
= xstrdup(name_
);
281 strtok_r(name
, ":", &save_ptr
); /* "db:" */
282 tokens
[0] = strtok_r(NULL
, ",", &save_ptr
);
283 tokens
[1] = strtok_r(NULL
, ",", &save_ptr
);
284 tokens
[2] = strtok_r(NULL
, ",", &save_ptr
);
285 if (!tokens
[0] || !tokens
[1]) {
286 ovs_fatal(0, "\"%s\": invalid syntax", name_
);
289 const char *db_name
= tokens
[0];
290 table_name
= tokens
[1];
291 column_name
= tokens
[2];
293 db
= find_db(dbs
, n_dbs
, tokens
[0]);
295 ovs_fatal(0, "\"%s\": no database named %s", name_
, db_name
);
299 ovs_fatal(0, "\"%s\": database name must be specified (because "
300 "multiple databases are configured)", name_
);
303 table_name
= tokens
[0];
304 column_name
= tokens
[1];
308 table
= ovsdb_get_table(db
->db
, table_name
);
310 ovs_fatal(0, "\"%s\": no table named %s", name_
, table_name
);
313 column
= ovsdb_table_schema_get_column(table
->schema
, column_name
);
315 ovs_fatal(0, "\"%s\": table \"%s\" has no column \"%s\"",
316 name_
, table_name
, column_name
);
326 parse_db_string_column(const struct db dbs
[], size_t n_dbs
,
328 const struct db
**dbp
,
329 const struct ovsdb_table
**tablep
,
330 const struct ovsdb_column
**columnp
)
332 const struct ovsdb_column
*column
;
333 const struct ovsdb_table
*table
;
336 parse_db_column(dbs
, n_dbs
, name
, &db
, &table
, &column
);
338 if (column
->type
.key
.type
!= OVSDB_TYPE_STRING
339 || column
->type
.value
.type
!= OVSDB_TYPE_VOID
) {
340 ovs_fatal(0, "\"%s\": table \"%s\" column \"%s\" is "
341 "not string or set of strings",
342 name
, table
->schema
->name
, column
->name
);
350 static OVS_UNUSED
const char *
351 query_db_string(const struct db dbs
[], size_t n_dbs
, const char *name
)
353 if (!name
|| strncmp(name
, "db:", 3)) {
356 const struct ovsdb_column
*column
;
357 const struct ovsdb_table
*table
;
358 const struct ovsdb_row
*row
;
361 parse_db_string_column(dbs
, n_dbs
, name
, &db
, &table
, &column
);
363 HMAP_FOR_EACH (row
, hmap_node
, &table
->rows
) {
364 const struct ovsdb_datum
*datum
;
367 datum
= &row
->fields
[column
->index
];
368 for (i
= 0; i
< datum
->n
; i
++) {
369 if (datum
->keys
[i
].string
[0]) {
370 return datum
->keys
[i
].string
;
378 static struct ovsdb_jsonrpc_options
*
379 add_remote(struct shash
*remotes
, const char *target
)
381 struct ovsdb_jsonrpc_options
*options
;
383 options
= shash_find_data(remotes
, target
);
385 options
= ovsdb_jsonrpc_default_options(target
);
386 shash_add(remotes
, target
, options
);
392 static struct ovsdb_datum
*
393 get_datum(struct ovsdb_row
*row
, const char *column_name
,
394 const enum ovsdb_atomic_type key_type
,
395 const enum ovsdb_atomic_type value_type
,
398 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
399 const struct ovsdb_table_schema
*schema
= row
->table
->schema
;
400 const struct ovsdb_column
*column
;
402 column
= ovsdb_table_schema_get_column(schema
, column_name
);
404 VLOG_DBG_RL(&rl
, "Table `%s' has no `%s' column",
405 schema
->name
, column_name
);
409 if (column
->type
.key
.type
!= key_type
410 || column
->type
.value
.type
!= value_type
411 || column
->type
.n_max
!= n_max
) {
412 if (!VLOG_DROP_DBG(&rl
)) {
413 char *type_name
= ovsdb_type_to_english(&column
->type
);
414 VLOG_DBG("Table `%s' column `%s' has type %s, not expected "
415 "key type %s, value type %s, max elements %zd.",
416 schema
->name
, column_name
, type_name
,
417 ovsdb_atomic_type_to_string(key_type
),
418 ovsdb_atomic_type_to_string(value_type
),
425 return &row
->fields
[column
->index
];
428 /* Read string-string key-values from a map. Returns the value associated with
429 * 'key', if found, or NULL */
431 read_map_string_column(const struct ovsdb_row
*row
, const char *column_name
,
434 const struct ovsdb_datum
*datum
;
435 union ovsdb_atom
*atom_key
= NULL
, *atom_value
= NULL
;
438 datum
= get_datum(CONST_CAST(struct ovsdb_row
*, row
), column_name
,
439 OVSDB_TYPE_STRING
, OVSDB_TYPE_STRING
, UINT_MAX
);
445 for (i
= 0; i
< datum
->n
; i
++) {
446 atom_key
= &datum
->keys
[i
];
447 if (!strcmp(atom_key
->string
, key
)){
448 atom_value
= &datum
->values
[i
];
453 return atom_value
? atom_value
->string
: NULL
;
456 static const union ovsdb_atom
*
457 read_column(const struct ovsdb_row
*row
, const char *column_name
,
458 enum ovsdb_atomic_type type
)
460 const struct ovsdb_datum
*datum
;
462 datum
= get_datum(CONST_CAST(struct ovsdb_row
*, row
), column_name
, type
,
464 return datum
&& datum
->n
? datum
->keys
: NULL
;
468 read_integer_column(const struct ovsdb_row
*row
, const char *column_name
,
469 long long int *integerp
)
471 const union ovsdb_atom
*atom
;
473 atom
= read_column(row
, column_name
, OVSDB_TYPE_INTEGER
);
474 *integerp
= atom
? atom
->integer
: 0;
479 read_string_column(const struct ovsdb_row
*row
, const char *column_name
,
480 const char **stringp
)
482 const union ovsdb_atom
*atom
;
484 atom
= read_column(row
, column_name
, OVSDB_TYPE_STRING
);
485 *stringp
= atom
? atom
->string
: NULL
;
490 write_bool_column(struct ovsdb_row
*row
, const char *column_name
, bool value
)
492 const struct ovsdb_column
*column
;
493 struct ovsdb_datum
*datum
;
495 column
= ovsdb_table_schema_get_column(row
->table
->schema
, column_name
);
496 datum
= get_datum(row
, column_name
, OVSDB_TYPE_BOOLEAN
,
503 ovsdb_datum_destroy(datum
, &column
->type
);
506 datum
->keys
= xmalloc(sizeof *datum
->keys
);
507 datum
->values
= NULL
;
510 datum
->keys
[0].boolean
= value
;
514 write_string_string_column(struct ovsdb_row
*row
, const char *column_name
,
515 char **keys
, char **values
, size_t n
)
517 const struct ovsdb_column
*column
;
518 struct ovsdb_datum
*datum
;
521 column
= ovsdb_table_schema_get_column(row
->table
->schema
, column_name
);
522 datum
= get_datum(row
, column_name
, OVSDB_TYPE_STRING
, OVSDB_TYPE_STRING
,
525 for (i
= 0; i
< n
; i
++) {
532 /* Free existing data. */
533 ovsdb_datum_destroy(datum
, &column
->type
);
535 /* Allocate space for new values. */
537 datum
->keys
= xmalloc(n
* sizeof *datum
->keys
);
538 datum
->values
= xmalloc(n
* sizeof *datum
->values
);
540 for (i
= 0; i
< n
; ++i
) {
541 datum
->keys
[i
].string
= keys
[i
];
542 datum
->values
[i
].string
= values
[i
];
545 /* Sort and check constraints. */
546 ovsdb_datum_sort_assert(datum
, column
->type
.key
.type
);
549 /* Adds a remote and options to 'remotes', based on the Manager table row in
552 add_manager_options(struct shash
*remotes
, const struct ovsdb_row
*row
)
554 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
555 struct ovsdb_jsonrpc_options
*options
;
556 long long int max_backoff
, probe_interval
;
557 const char *target
, *dscp_string
;
559 if (!read_string_column(row
, "target", &target
) || !target
) {
560 VLOG_INFO_RL(&rl
, "Table `%s' has missing or invalid `target' column",
561 row
->table
->schema
->name
);
565 options
= add_remote(remotes
, target
);
566 if (read_integer_column(row
, "max_backoff", &max_backoff
)) {
567 options
->max_backoff
= max_backoff
;
569 if (read_integer_column(row
, "inactivity_probe", &probe_interval
)) {
570 options
->probe_interval
= probe_interval
;
573 options
->dscp
= DSCP_DEFAULT
;
574 dscp_string
= read_map_string_column(row
, "other_config", "dscp");
576 int dscp
= atoi(dscp_string
);
577 if (dscp
>= 0 && dscp
<= 63) {
578 options
->dscp
= dscp
;
584 query_db_remotes(const char *name
, const struct db dbs
[], size_t n_dbs
,
585 struct shash
*remotes
)
587 const struct ovsdb_column
*column
;
588 const struct ovsdb_table
*table
;
589 const struct ovsdb_row
*row
;
592 parse_db_column(dbs
, n_dbs
, name
, &db
, &table
, &column
);
594 if (column
->type
.key
.type
== OVSDB_TYPE_STRING
595 && column
->type
.value
.type
== OVSDB_TYPE_VOID
) {
596 HMAP_FOR_EACH (row
, hmap_node
, &table
->rows
) {
597 const struct ovsdb_datum
*datum
;
600 datum
= &row
->fields
[column
->index
];
601 for (i
= 0; i
< datum
->n
; i
++) {
602 add_remote(remotes
, datum
->keys
[i
].string
);
605 } else if (column
->type
.key
.type
== OVSDB_TYPE_UUID
606 && column
->type
.key
.u
.uuid
.refTable
607 && column
->type
.value
.type
== OVSDB_TYPE_VOID
) {
608 const struct ovsdb_table
*ref_table
= column
->type
.key
.u
.uuid
.refTable
;
609 HMAP_FOR_EACH (row
, hmap_node
, &table
->rows
) {
610 const struct ovsdb_datum
*datum
;
613 datum
= &row
->fields
[column
->index
];
614 for (i
= 0; i
< datum
->n
; i
++) {
615 const struct ovsdb_row
*ref_row
;
617 ref_row
= ovsdb_table_get_row(ref_table
, &datum
->keys
[i
].uuid
);
619 add_manager_options(remotes
, ref_row
);
627 update_remote_row(const struct ovsdb_row
*row
, struct ovsdb_txn
*txn
,
628 const struct ovsdb_jsonrpc_server
*jsonrpc
)
630 struct ovsdb_jsonrpc_remote_status status
;
631 struct ovsdb_row
*rw_row
;
633 char *keys
[8], *values
[8];
636 /* Get the "target" (protocol/host/port) spec. */
637 if (!read_string_column(row
, "target", &target
)) {
638 /* Bad remote spec or incorrect schema. */
641 rw_row
= ovsdb_txn_row_modify(txn
, row
);
642 ovsdb_jsonrpc_server_get_remote_status(jsonrpc
, target
, &status
);
644 /* Update status information columns. */
645 write_bool_column(rw_row
, "is_connected", status
.is_connected
);
648 keys
[n
] = xstrdup("state");
649 values
[n
++] = xstrdup(status
.state
);
651 if (status
.sec_since_connect
!= UINT_MAX
) {
652 keys
[n
] = xstrdup("sec_since_connect");
653 values
[n
++] = xasprintf("%u", status
.sec_since_connect
);
655 if (status
.sec_since_disconnect
!= UINT_MAX
) {
656 keys
[n
] = xstrdup("sec_since_disconnect");
657 values
[n
++] = xasprintf("%u", status
.sec_since_disconnect
);
659 if (status
.last_error
) {
660 keys
[n
] = xstrdup("last_error");
662 xstrdup(ovs_retval_to_string(status
.last_error
));
664 if (status
.locks_held
&& status
.locks_held
[0]) {
665 keys
[n
] = xstrdup("locks_held");
666 values
[n
++] = xstrdup(status
.locks_held
);
668 if (status
.locks_waiting
&& status
.locks_waiting
[0]) {
669 keys
[n
] = xstrdup("locks_waiting");
670 values
[n
++] = xstrdup(status
.locks_waiting
);
672 if (status
.locks_lost
&& status
.locks_lost
[0]) {
673 keys
[n
] = xstrdup("locks_lost");
674 values
[n
++] = xstrdup(status
.locks_lost
);
676 if (status
.n_connections
> 1) {
677 keys
[n
] = xstrdup("n_connections");
678 values
[n
++] = xasprintf("%d", status
.n_connections
);
680 write_string_string_column(rw_row
, "status", keys
, values
, n
);
682 ovsdb_jsonrpc_server_free_remote_status(&status
);
686 update_remote_rows(const struct db dbs
[], size_t n_dbs
,
687 const char *remote_name
,
688 const struct ovsdb_jsonrpc_server
*jsonrpc
)
690 const struct ovsdb_table
*table
, *ref_table
;
691 const struct ovsdb_column
*column
;
692 const struct ovsdb_row
*row
;
695 if (strncmp("db:", remote_name
, 3)) {
699 parse_db_column(dbs
, n_dbs
, remote_name
, &db
, &table
, &column
);
701 if (column
->type
.key
.type
!= OVSDB_TYPE_UUID
702 || !column
->type
.key
.u
.uuid
.refTable
703 || column
->type
.value
.type
!= OVSDB_TYPE_VOID
) {
707 ref_table
= column
->type
.key
.u
.uuid
.refTable
;
709 HMAP_FOR_EACH (row
, hmap_node
, &table
->rows
) {
710 const struct ovsdb_datum
*datum
;
713 datum
= &row
->fields
[column
->index
];
714 for (i
= 0; i
< datum
->n
; i
++) {
715 const struct ovsdb_row
*ref_row
;
717 ref_row
= ovsdb_table_get_row(ref_table
, &datum
->keys
[i
].uuid
);
719 update_remote_row(ref_row
, db
->txn
, jsonrpc
);
726 update_remote_status(const struct ovsdb_jsonrpc_server
*jsonrpc
,
727 const struct sset
*remotes
,
728 struct db dbs
[], size_t n_dbs
)
730 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
734 for (i
= 0; i
< n_dbs
; i
++) {
735 dbs
[i
].txn
= ovsdb_txn_create(dbs
[i
].db
);
738 /* Iterate over --remote arguments given on command line. */
739 SSET_FOR_EACH (remote
, remotes
) {
740 update_remote_rows(dbs
, n_dbs
, remote
, jsonrpc
);
743 for (i
= 0; i
< n_dbs
; i
++) {
744 struct ovsdb_error
*error
= ovsdb_txn_commit(dbs
[i
].txn
, false);
746 VLOG_ERR_RL(&rl
, "Failed to update remote status: %s",
747 ovsdb_error_to_string(error
));
748 ovsdb_error_destroy(error
);
753 /* Reconfigures ovsdb-server based on information in the database. */
755 reconfigure_from_db(struct ovsdb_jsonrpc_server
*jsonrpc
,
756 const struct db dbs
[], size_t n_dbs
, struct sset
*remotes
)
758 struct shash resolved_remotes
;
761 /* Configure remotes. */
762 shash_init(&resolved_remotes
);
763 SSET_FOR_EACH (name
, remotes
) {
764 if (!strncmp(name
, "db:", 3)) {
765 query_db_remotes(name
, dbs
, n_dbs
, &resolved_remotes
);
767 add_remote(&resolved_remotes
, name
);
770 ovsdb_jsonrpc_server_set_remotes(jsonrpc
, &resolved_remotes
);
771 shash_destroy_free_data(&resolved_remotes
);
774 stream_ssl_set_key_and_cert(query_db_string(dbs
, n_dbs
, private_key_file
),
775 query_db_string(dbs
, n_dbs
, certificate_file
));
776 stream_ssl_set_ca_cert_file(query_db_string(dbs
, n_dbs
, ca_cert_file
),
781 ovsdb_server_exit(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
782 const char *argv
[] OVS_UNUSED
,
785 bool *exiting
= exiting_
;
787 unixctl_command_reply(conn
, NULL
);
791 ovsdb_server_compact(struct unixctl_conn
*conn
, int argc
,
792 const char *argv
[], void *dbs_
)
794 struct db
*dbs
= dbs_
;
800 for (db
= dbs
; db
->filename
!= NULL
; db
++) {
801 const char *name
= db
->db
->schema
->name
;
803 if (argc
< 2 || !strcmp(argv
[1], name
)) {
804 struct ovsdb_error
*error
;
806 VLOG_INFO("compacting %s database by user request", name
);
808 error
= ovsdb_file_compact(db
->file
);
810 char *s
= ovsdb_error_to_string(error
);
811 ds_put_format(&reply
, "%s\n", s
);
820 unixctl_command_reply_error(conn
, "no database by that name");
821 } else if (reply
.length
) {
822 unixctl_command_reply_error(conn
, ds_cstr(&reply
));
824 unixctl_command_reply(conn
, NULL
);
829 /* "ovsdb-server/reconnect": makes ovsdb-server drop all of its JSON-RPC
830 * connections and reconnect. */
832 ovsdb_server_reconnect(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
833 const char *argv
[] OVS_UNUSED
, void *jsonrpc_
)
835 struct ovsdb_jsonrpc_server
*jsonrpc
= jsonrpc_
;
837 ovsdb_jsonrpc_server_reconnect(jsonrpc
);
838 unixctl_command_reply(conn
, NULL
);
842 parse_options(int *argcp
, char **argvp
[],
843 struct sset
*remotes
, char **unixctl_pathp
, char **run_command
)
846 OPT_REMOTE
= UCHAR_MAX
+ 1,
849 OPT_BOOTSTRAP_CA_CERT
,
852 LEAK_CHECKER_OPTION_ENUMS
,
855 static struct option long_options
[] = {
856 {"remote", required_argument
, NULL
, OPT_REMOTE
},
857 {"unixctl", required_argument
, NULL
, OPT_UNIXCTL
},
858 {"run", required_argument
, NULL
, OPT_RUN
},
859 {"help", no_argument
, NULL
, 'h'},
860 {"version", no_argument
, NULL
, 'V'},
863 LEAK_CHECKER_LONG_OPTIONS
,
864 {"bootstrap-ca-cert", required_argument
, NULL
, OPT_BOOTSTRAP_CA_CERT
},
865 {"private-key", required_argument
, NULL
, 'p'},
866 {"certificate", required_argument
, NULL
, 'c'},
867 {"ca-cert", required_argument
, NULL
, 'C'},
868 {"enable-dummy", optional_argument
, NULL
, OPT_ENABLE_DUMMY
},
871 char *short_options
= long_options_to_short_options(long_options
);
873 char **argv
= *argvp
;
879 c
= getopt_long(argc
, argv
, short_options
, long_options
, NULL
);
886 sset_add(remotes
, optarg
);
890 *unixctl_pathp
= optarg
;
894 *run_command
= optarg
;
901 ovs_print_version(0, 0);
905 DAEMON_OPTION_HANDLERS
906 LEAK_CHECKER_OPTION_HANDLERS
909 private_key_file
= optarg
;
913 certificate_file
= optarg
;
917 ca_cert_file
= optarg
;
918 bootstrap_ca_cert
= false;
921 case OPT_BOOTSTRAP_CA_CERT
:
922 ca_cert_file
= optarg
;
923 bootstrap_ca_cert
= true;
926 case OPT_ENABLE_DUMMY
:
927 dummy_enable(optarg
&& !strcmp(optarg
, "override"));
946 printf("%s: Open vSwitch database server\n"
947 "usage: %s [OPTIONS] [DATABASE...]\n"
948 "where each DATABASE is a database file in ovsdb format.\n"
949 "The default DATABASE, if none is given, is\n%s/conf.db.\n",
950 program_name
, program_name
, ovs_dbdir());
951 printf("\nJSON-RPC options (may be specified any number of times):\n"
952 " --remote=REMOTE connect or listen to REMOTE\n");
953 stream_usage("JSON-RPC", true, true, true);
956 printf("\nOther options:\n"
957 " --run COMMAND run COMMAND as subprocess then exit\n"
958 " --unixctl=SOCKET override default control socket name\n"
959 " -h, --help display this help message\n"
960 " -V, --version display version information\n");
961 leak_checker_usage();