aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven <sluong@cisco.com>2017-07-21 16:38:41 -0700
committerSteven <sluong@cisco.com>2017-07-21 16:38:41 -0700
commit6a4de2764d9e6cadf36af824dddb3f33c2d6dc7e (patch)
tree140af2bbab0b44a6b045972dd411e9b0e1f9df92
parent45fe7399152f5ca511ba0b03fee3d5a3dffd1897 (diff)
vhost: debug vhost-user command needs better error checking on the syntax (VPP-916)
The syntax for debug vhost-user is debug vhost-user <on | off> However, currently the code does not reject the invalid command such as below debug vhost-user debug vhost-user on blah debug vhost-user off blah The fix is to enforece the correct syntax and reject the command when invalid option is entered. Change-Id: I1a04ae8ddb6dd299aa6d15b043362964e685ddde Signed-off-by: Steven <sluong@cisco.com>
-rw-r--r--src/vnet/devices/virtio/vhost-user.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/vnet/devices/virtio/vhost-user.c b/src/vnet/devices/virtio/vhost-user.c
index 2e2b49c2126..82f7653356d 100644
--- a/src/vnet/devices/virtio/vhost-user.c
+++ b/src/vnet/devices/virtio/vhost-user.c
@@ -3540,22 +3540,43 @@ debug_vhost_user_command_fn (vlib_main_t * vm,
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error = NULL;
vhost_user_main_t *vum = &vhost_user_main;
+ u8 onoff = 0;
+ u8 input_found = 0;
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, "missing argument");
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
+ if (input_found)
+ {
+ error = clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, line_input);
+ goto done;
+ }
+
if (unformat (line_input, "on"))
- vum->debug = 1;
+ {
+ input_found = 1;
+ onoff = 1;
+ }
else if (unformat (line_input, "off"))
- vum->debug = 0;
+ {
+ input_found = 1;
+ onoff = 0;
+ }
else
- error = clib_error_return (0, "unknown input `%U'",
- format_unformat_error, line_input);
+ {
+ error = clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, line_input);
+ goto done;
+ }
}
+ vum->debug = onoff;
+
+done:
unformat_free (line_input);
return error;