From 3a08001dd40a3c73772c6601c2bcea25af8ed3a7 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 9 Aug 2018 14:07:15 +0900 Subject: [PATCH] iscsi&scripts/rpc: Add get_iscsi_auth_groups RPC to get current configuration Add an new RPC to get current authentication group configuration. This patch is utilized in the next patch to support JSON config dump for authentication group configuration. Change-Id: I34be9e196f8e7a484bcd316da54f05d0f6ee0300 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/421468 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Ben Walker Reviewed-by: Pawel Wodkowski Reviewed-by: Jim Harris --- doc/jsonrpc.md | 59 +++++++++++++++++++++++++++++++++++++ lib/iscsi/iscsi.h | 1 + lib/iscsi/iscsi_rpc.c | 25 ++++++++++++++++ lib/iscsi/iscsi_subsystem.c | 39 ++++++++++++++++++++++++ scripts/rpc.py | 8 +++++ scripts/rpc/iscsi.py | 9 ++++++ 6 files changed, 141 insertions(+) diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index 7892f502e..0487d60d4 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -2008,6 +2008,65 @@ Example response: } ~~~ +## get_iscsi_auth_groups {#rpc_get_iscsi_auth_groups} + +Show information about all existing authentication group for CHAP authentication. + +### Parameters + +This method has no parameters. + +### Result + +Array of objects describing authentication group. + +Name | Type | Description +--------------------------- | --------| ----------- +tag | number | Authentication group tag +secrets | array | Array of @ref rpc_add_iscsi_auth_group_secret objects + +### Example + +Example request: + +~~~ +{ + "jsonrpc": "2.0", + "method": "get_iscsi_auth_groups", + "id": 1 +} +~~~ +Example response: + +~~~ +{ + "jsonrpc": "2.0", + "id": 1, + "result": [ + { + "secrets": [ + { + "muser": "mu1", + "secret": "s1", + "user": "u1", + "msecret": "ms1" + } + ], + "tag": 1 + }, + { + "secrets": [ + { + "secret": "s2", + "user": "u2" + } + ], + "tag": 2 + } + ] +} +~~~ + ## add_secret_to_iscsi_auth_group {#rpc_add_secret_to_iscsi_auth_group} Add a secret to an existing authentication group for CHAP authentication. diff --git a/lib/iscsi/iscsi.h b/lib/iscsi/iscsi.h index e987a4406..e8a0b07b6 100644 --- a/lib/iscsi/iscsi.h +++ b/lib/iscsi/iscsi.h @@ -408,6 +408,7 @@ int spdk_iscsi_auth_group_add_secret(struct spdk_iscsi_auth_group *group, const char *muser, const char *msecret); int spdk_iscsi_auth_group_delete_secret(struct spdk_iscsi_auth_group *group, const char *user); +void spdk_iscsi_auth_groups_info_json(struct spdk_json_write_ctx *w); void spdk_iscsi_send_nopin(struct spdk_iscsi_conn *conn); void spdk_iscsi_task_response(struct spdk_iscsi_conn *conn, diff --git a/lib/iscsi/iscsi_rpc.c b/lib/iscsi/iscsi_rpc.c index 5cdf8d4fd..dd9777a31 100644 --- a/lib/iscsi/iscsi_rpc.c +++ b/lib/iscsi/iscsi_rpc.c @@ -1515,3 +1515,28 @@ spdk_rpc_delete_secret_from_iscsi_auth_group(struct spdk_jsonrpc_request *reques } SPDK_RPC_REGISTER("delete_secret_from_iscsi_auth_group", spdk_rpc_delete_secret_from_iscsi_auth_group, SPDK_RPC_RUNTIME) + +static void +spdk_rpc_get_iscsi_auth_groups(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) +{ + struct spdk_json_write_ctx *w; + + if (params != NULL) { + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + "get_iscsi_auth_groups requires no parameters"); + return; + } + + w = spdk_jsonrpc_begin_result(request); + if (w == NULL) { + return; + } + + spdk_json_write_array_begin(w); + spdk_iscsi_auth_groups_info_json(w); + spdk_json_write_array_end(w); + + spdk_jsonrpc_end_result(request, w); +} +SPDK_RPC_REGISTER("get_iscsi_auth_groups", spdk_rpc_get_iscsi_auth_groups, SPDK_RPC_RUNTIME) diff --git a/lib/iscsi/iscsi_subsystem.c b/lib/iscsi/iscsi_subsystem.c index f63fc32e8..10389cbc8 100644 --- a/lib/iscsi/iscsi_subsystem.c +++ b/lib/iscsi/iscsi_subsystem.c @@ -1424,6 +1424,45 @@ spdk_iscsi_opts_info_json(struct spdk_json_write_ctx *w) spdk_json_write_object_end(w); } +static void +spdk_iscsi_auth_group_info_json(struct spdk_iscsi_auth_group *group, + struct spdk_json_write_ctx *w) +{ + struct spdk_iscsi_auth_secret *_secret; + + spdk_json_write_object_begin(w); + + spdk_json_write_named_int32(w, "tag", group->tag); + + spdk_json_write_named_array_begin(w, "secrets"); + TAILQ_FOREACH(_secret, &group->secret_head, tailq) { + spdk_json_write_object_begin(w); + + spdk_json_write_named_string(w, "user", _secret->user); + spdk_json_write_named_string(w, "secret", _secret->secret); + + if (_secret->muser[0] != '\0') { + spdk_json_write_named_string(w, "muser", _secret->muser); + spdk_json_write_named_string(w, "msecret", _secret->msecret); + } + + spdk_json_write_object_end(w); + } + spdk_json_write_array_end(w); + + spdk_json_write_object_end(w); +} + +void +spdk_iscsi_auth_groups_info_json(struct spdk_json_write_ctx *w) +{ + struct spdk_iscsi_auth_group *group; + + TAILQ_FOREACH(group, &g_spdk_iscsi.auth_group_head, tailq) { + spdk_iscsi_auth_group_info_json(group, w); + } +} + static void spdk_iscsi_opts_config_json(struct spdk_json_write_ctx *w) { diff --git a/scripts/rpc.py b/scripts/rpc.py index 41d49eb75..344a71cd8 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -600,6 +600,14 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse p.add_argument('-u', '--user', help='User name for one-way CHAP authentication', required=True) p.set_defaults(func=delete_secret_from_iscsi_auth_group) + @call_cmd + def get_iscsi_auth_groups(args): + print_dict(rpc.iscsi.get_iscsi_auth_groups(args.client)) + + p = subparsers.add_parser('get_iscsi_auth_groups', + help='Display current authentication group configuration') + p.set_defaults(func=get_iscsi_auth_groups) + @call_cmd def get_portal_groups(args): print_dict(rpc.iscsi.get_portal_groups(args.client)) diff --git a/scripts/rpc/iscsi.py b/scripts/rpc/iscsi.py index 341e746f1..a824ad20b 100755 --- a/scripts/rpc/iscsi.py +++ b/scripts/rpc/iscsi.py @@ -118,6 +118,15 @@ def set_iscsi_discovery_auth( return client.call('set_iscsi_discovery_auth', params) +def get_iscsi_auth_groups(client): + """Display current authentication group configuration. + + Returns: + List of current authentication group configuration. + """ + return client.call('get_iscsi_auth_groups') + + def get_portal_groups(client): """Display current portal group configuration.