Commit 4459e042 authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Jens Axboe

iscsi-target: use generic inet_pton_with_scope

Instead of parsing address strings, use a generic
helper.
Acked-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 0928f9b4
...@@ -167,10 +167,7 @@ static struct se_tpg_np *lio_target_call_addnptotpg( ...@@ -167,10 +167,7 @@ static struct se_tpg_np *lio_target_call_addnptotpg(
struct iscsi_portal_group *tpg; struct iscsi_portal_group *tpg;
struct iscsi_tpg_np *tpg_np; struct iscsi_tpg_np *tpg_np;
char *str, *str2, *ip_str, *port_str; char *str, *str2, *ip_str, *port_str;
struct sockaddr_storage sockaddr; struct sockaddr_storage sockaddr = { };
struct sockaddr_in *sock_in;
struct sockaddr_in6 *sock_in6;
unsigned long port;
int ret; int ret;
char buf[MAX_PORTAL_LEN + 1]; char buf[MAX_PORTAL_LEN + 1];
...@@ -182,21 +179,19 @@ static struct se_tpg_np *lio_target_call_addnptotpg( ...@@ -182,21 +179,19 @@ static struct se_tpg_np *lio_target_call_addnptotpg(
memset(buf, 0, MAX_PORTAL_LEN + 1); memset(buf, 0, MAX_PORTAL_LEN + 1);
snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name); snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
str = strstr(buf, "["); str = strstr(buf, "[");
if (str) { if (str) {
const char *end;
str2 = strstr(str, "]"); str2 = strstr(str, "]");
if (!str2) { if (!str2) {
pr_err("Unable to locate trailing \"]\"" pr_err("Unable to locate trailing \"]\""
" in IPv6 iSCSI network portal address\n"); " in IPv6 iSCSI network portal address\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
str++; /* Skip over leading "[" */
ip_str = str + 1; /* Skip over leading "[" */
*str2 = '\0'; /* Terminate the unbracketed IPv6 address */ *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
str2++; /* Skip over the \0 */ str2++; /* Skip over the \0 */
port_str = strstr(str2, ":"); port_str = strstr(str2, ":");
if (!port_str) { if (!port_str) {
pr_err("Unable to locate \":port\"" pr_err("Unable to locate \":port\""
...@@ -205,23 +200,8 @@ static struct se_tpg_np *lio_target_call_addnptotpg( ...@@ -205,23 +200,8 @@ static struct se_tpg_np *lio_target_call_addnptotpg(
} }
*port_str = '\0'; /* Terminate string for IP */ *port_str = '\0'; /* Terminate string for IP */
port_str++; /* Skip over ":" */ port_str++; /* Skip over ":" */
ret = kstrtoul(port_str, 0, &port);
if (ret < 0) {
pr_err("kstrtoul() failed for port_str: %d\n", ret);
return ERR_PTR(ret);
}
sock_in6 = (struct sockaddr_in6 *)&sockaddr;
sock_in6->sin6_family = AF_INET6;
sock_in6->sin6_port = htons((unsigned short)port);
ret = in6_pton(str, -1,
(void *)&sock_in6->sin6_addr.in6_u, -1, &end);
if (ret <= 0) {
pr_err("in6_pton returned: %d\n", ret);
return ERR_PTR(-EINVAL);
}
} else { } else {
str = ip_str = &buf[0]; ip_str = &buf[0];
port_str = strstr(ip_str, ":"); port_str = strstr(ip_str, ":");
if (!port_str) { if (!port_str) {
pr_err("Unable to locate \":port\"" pr_err("Unable to locate \":port\""
...@@ -230,17 +210,15 @@ static struct se_tpg_np *lio_target_call_addnptotpg( ...@@ -230,17 +210,15 @@ static struct se_tpg_np *lio_target_call_addnptotpg(
} }
*port_str = '\0'; /* Terminate string for IP */ *port_str = '\0'; /* Terminate string for IP */
port_str++; /* Skip over ":" */ port_str++; /* Skip over ":" */
}
ret = kstrtoul(port_str, 0, &port); ret = inet_pton_with_scope(&init_net, AF_UNSPEC, ip_str,
if (ret < 0) { port_str, &sockaddr);
pr_err("kstrtoul() failed for port_str: %d\n", ret); if (ret) {
return ERR_PTR(ret); pr_err("malformed ip/port passed: %s\n", name);
} return ERR_PTR(ret);
sock_in = (struct sockaddr_in *)&sockaddr;
sock_in->sin_family = AF_INET;
sock_in->sin_port = htons((unsigned short)port);
sock_in->sin_addr.s_addr = in_aton(ip_str);
} }
tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
ret = iscsit_get_tpg(tpg); ret = iscsit_get_tpg(tpg);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment