On Wed, Apr 10, 2013 at 01:42:29PM -0700, Ansis Atteka wrote: > One thing I noticed - if you will try to add invalid remote from "db:", > then parse_db_column() might fail and call ovs_fatal(). Seems a little > harsh...
Oops. Here's an incremental for the commit that adds add-remote to fix that. It requires an additional preparation commit that I'll send out in a bit as part of a complete revised series. diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 39bc98e..61095e2 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -75,6 +75,12 @@ static bool bootstrap_ca_cert; static unixctl_cb_func ovsdb_server_exit; static unixctl_cb_func ovsdb_server_compact; static unixctl_cb_func ovsdb_server_reconnect; + +struct add_remote_aux { + struct sset *remotes; + struct db *dbs; + size_t n_dbs; +}; static unixctl_cb_func ovsdb_server_add_remote; static unixctl_cb_func ovsdb_server_remove_remote; static unixctl_cb_func ovsdb_server_list_remotes; @@ -104,6 +110,7 @@ main(int argc, char *argv[]) bool exiting; int retval; long long int status_timer = LLONG_MIN; + struct add_remote_aux add_remote_aux; struct db *dbs; int n_dbs; @@ -183,8 +190,12 @@ main(int argc, char *argv[]) ovsdb_server_compact, dbs); unixctl_command_register("ovsdb-server/reconnect", "", 0, 0, ovsdb_server_reconnect, jsonrpc); + + add_remote_aux.remotes = &remotes; + add_remote_aux.dbs = dbs; + add_remote_aux.n_dbs = n_dbs; unixctl_command_register("ovsdb-server/add-remote", "REMOTE", 1, 1, - ovsdb_server_add_remote, &remotes); + ovsdb_server_add_remote, &add_remote_aux); unixctl_command_register("ovsdb-server/remove-remote", "REMOTE", 1, 1, ovsdb_server_remove_remote, &remotes); unixctl_command_register("ovsdb-server/list-remotes", "", 0, 0, @@ -888,12 +899,27 @@ ovsdb_server_reconnect(struct unixctl_conn *conn, int argc OVS_UNUSED, * ovsdb-server services. */ static void ovsdb_server_add_remote(struct unixctl_conn *conn, int argc OVS_UNUSED, - const char *argv[], void *remotes_) + const char *argv[], void *aux_) { - struct sset *remotes = remotes_; + struct add_remote_aux *aux = aux_; + const char *remote = argv[1]; - sset_add(remotes, argv[1]); - unixctl_command_reply(conn, NULL); + const struct ovsdb_column *column; + const struct ovsdb_table *table; + const struct db *db; + char *retval; + + retval = (strncmp("db:", remote, 3) + ? NULL + : parse_db_column(aux->dbs, aux->n_dbs, remote, + &db, &table, &column)); + if (!retval) { + sset_add(aux->remotes, remote); + unixctl_command_reply(conn, NULL); + } else { + unixctl_command_reply_error(conn, retval); + free(retval); + } } /* "ovsdb-server/remove-remote REMOTE": removes REMOTE frmo the set of remotes diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at index d310912..50f95bd 100644 --- a/tests/ovsdb-server.at +++ b/tests/ovsdb-server.at @@ -253,6 +253,11 @@ AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/list-remotes], punix:socket2 ]) +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/add-remote db:x,y,z], [2], + [], ["db:x,y,z": no database named x +ovs-appctl: ovsdb-server: server returned an error +]) + AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/remove-remote punix:socket1]) OVS_WAIT_UNTIL([test ! -e socket1]) AT_CHECK([test -S socket2]) _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev