diff --git a/lib/iscsi/portal_grp.c b/lib/iscsi/portal_grp.c index 78e3bb48a..43d8e21eb 100644 --- a/lib/iscsi/portal_grp.c +++ b/lib/iscsi/portal_grp.c @@ -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) { diff --git a/lib/iscsi/portal_grp.h b/lib/iscsi/portal_grp.h index 3a50fc5ad..923e0d50e 100644 --- a/lib/iscsi/portal_grp.h +++ b/lib/iscsi/portal_grp.h @@ -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 */ diff --git a/lib/iscsi/tgt_node.c b/lib/iscsi/tgt_node.c index 390550f4c..2a70e0e95 100644 --- a/lib/iscsi/tgt_node.c +++ b/lib/iscsi/tgt_node.c @@ -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; diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index d146706bc..e0ce2b084 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -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; }