Check the parameters when setting up the controller. The parameters will only take effect when none of the following three parameters are repeated; Otherwise, a prompt message will be returned 1.ip address 2.port no 3.protocol type
v5: modified the subject summary Signed-off-by: yaolingfei <543981...@qq.com> --- tests/ovs-vsctl.at | 4 ++++ utilities/ovs-vsctl.c | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at index 59245fff8..76fe74414 100644 --- a/tests/ovs-vsctl.at +++ b/tests/ovs-vsctl.at @@ -492,6 +492,8 @@ AT_CHECK([RUN_OVS_VSCTL_TOGETHER( [get-controller br0], [--inactivity-probe=30000 set-controller br0 tcp:1.2.3.4], + [get-controller br0], + [set-controller br0 tcp:8.9.10.11 tcp:8.9.10.11], [get-controller br0])], [0], [ @@ -501,6 +503,8 @@ tcp:4.5.6.7 tcp:5.4.3.2\ntcp:8.9.10.11 +tcp:1.2.3.4 +Controller parameter is duplicated tcp:1.2.3.4 ]) OVS_VSCTL_CLEANUP diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index d90db934b..f39952d72 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -2348,6 +2348,24 @@ insert_controllers(struct ctl_context *ctx, char *targets[], size_t n) return controllers; } +static int +check_dup_controllers(char *targets[], size_t n) +{ + size_t i; + size_t j; + + /* check if the input parameters are duplicated */ + for (i = 0; i < n; i++) { + for (j = i + 1; j < n; j++) { + if (!strcmp(targets[i], targets[j])) { + return 0; + } + } + } + + return 1; +} + static void cmd_set_controller(struct ctl_context *ctx) { @@ -2361,9 +2379,15 @@ cmd_set_controller(struct ctl_context *ctx) br = find_real_bridge(vsctl_ctx, ctx->argv[1], true)->br_cfg; verify_controllers(br); + n = ctx->argc - 2; + if (!check_dup_controllers(&ctx->argv[2], n)) { + /* controller parameters are duplicated */ + ds_put_format(&ctx->output, "Controller parameter is duplicated\n"); + return; + } + delete_controllers(br->controller, br->n_controller); - n = ctx->argc - 2; controllers = insert_controllers(ctx, &ctx->argv[2], n); ovsrec_bridge_set_controller(br, controllers, n); free(controllers); -- 2.40.1.windows.1 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev