lib/iscsi: Check if IP address-port pair is valid as redirect portal
Add a helper function iscsi_parse_redirect_addr() to validate the passed IP address-port pair. iSCSI login redirection will support only numeric IP address and TCP port, and add AI_NUMERICSERV and AI_NUMERICHOST. This function is almost same as nvme_tcp_parse_addr() and nvme_rdma_parse_addr(). Besides, update error log in posix_sock_create() to use gai_strerror(). gai_strerror() will provide more accurate information as done by nvme_tcp_parse_addr() and nvme_rdma_parse_addr(). Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I65c6de81a64dcb26551ce796172d0458e1c298a7 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3357 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
99d3695c2c
commit
0f22282fc3
@ -271,6 +271,40 @@ iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
iscsi_parse_redirect_addr(struct sockaddr_storage *sa,
|
||||
const char *host, const char *port)
|
||||
{
|
||||
struct addrinfo hints, *res;
|
||||
int rc;
|
||||
|
||||
if (host == NULL || port == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_NUMERICSERV;
|
||||
hints.ai_flags |= AI_NUMERICHOST;
|
||||
rc = getaddrinfo(host, port, &hints, &res);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("getaddinrfo failed: %s (%d)\n", gai_strerror(rc), rc);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (res->ai_addrlen > sizeof(*sa)) {
|
||||
SPDK_ERRLOG("getaddrinfo() ai_addrlen %zu too large\n",
|
||||
(size_t)res->ai_addrlen);
|
||||
rc = -EINVAL;
|
||||
} else {
|
||||
memcpy(sa, res->ai_addr, res->ai_addrlen);
|
||||
}
|
||||
|
||||
freeaddrinfo(res);
|
||||
return rc;
|
||||
}
|
||||
|
||||
struct spdk_iscsi_portal_grp *
|
||||
iscsi_portal_grp_create(int tag)
|
||||
{
|
||||
|
@ -90,4 +90,7 @@ void iscsi_portal_grps_config_text(FILE *fp);
|
||||
void iscsi_portal_grps_info_json(struct spdk_json_write_ctx *w);
|
||||
void iscsi_portal_grps_config_json(struct spdk_json_write_ctx *w);
|
||||
|
||||
int iscsi_parse_redirect_addr(struct sockaddr_storage *sa,
|
||||
const char *host, const char *port);
|
||||
|
||||
#endif /* SPDK_PORTAL_GRP_H */
|
||||
|
@ -320,7 +320,7 @@ iscsi_send_tgt_portals(struct spdk_iscsi_conn *conn,
|
||||
}
|
||||
host = p->host;
|
||||
/* wildcard? */
|
||||
if (!strcasecmp(host, "[::]") || !strcasecmp(host, "0.0.0.0")) {
|
||||
if (strcasecmp(host, "[::]") == 0 || strcasecmp(host, "0.0.0.0") == 0) {
|
||||
if (spdk_sock_is_ipv6(conn->sock)) {
|
||||
snprintf(buf, sizeof buf, "[%s]", conn->target_addr);
|
||||
host = buf;
|
||||
|
@ -440,7 +440,7 @@ posix_sock_create(const char *ip, int port,
|
||||
hints.ai_flags |= AI_NUMERICHOST;
|
||||
rc = getaddrinfo(ip, portnum, &hints, &res0);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("getaddrinfo() failed (errno=%d)\n", errno);
|
||||
SPDK_ERRLOG("getaddrinfo() failed %s (%d)\n", gai_strerror(rc), rc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user