Commit 76c28f1f authored by Andy Grover's avatar Andy Grover Committed by Nicholas Bellinger

target/iscsi: Fix np_ip bracket issue by removing np_ip

Revert commit 1997e625, which causes double brackets on ipv6
inaddr_any addresses.

Since we have np_sockaddr, if we need a textual representation we can
use "%pISc".

Change iscsit_add_network_portal() and iscsit_add_np() signatures to remove
*ip_str parameter.

Fix and extend some comments earlier in the function.

Tested to work for :: and ::1 via iscsiadm, previously :: failed, see
https://bugzilla.redhat.com/show_bug.cgi?id=1249107 .

CC: stable@vger.kernel.org
Signed-off-by: default avatarAndy Grover <agrover@redhat.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 109e2381
...@@ -341,7 +341,6 @@ static struct iscsi_np *iscsit_get_np( ...@@ -341,7 +341,6 @@ static struct iscsi_np *iscsit_get_np(
struct iscsi_np *iscsit_add_np( struct iscsi_np *iscsit_add_np(
struct __kernel_sockaddr_storage *sockaddr, struct __kernel_sockaddr_storage *sockaddr,
char *ip_str,
int network_transport) int network_transport)
{ {
struct sockaddr_in *sock_in; struct sockaddr_in *sock_in;
...@@ -370,11 +369,9 @@ struct iscsi_np *iscsit_add_np( ...@@ -370,11 +369,9 @@ struct iscsi_np *iscsit_add_np(
np->np_flags |= NPF_IP_NETWORK; np->np_flags |= NPF_IP_NETWORK;
if (sockaddr->ss_family == AF_INET6) { if (sockaddr->ss_family == AF_INET6) {
sock_in6 = (struct sockaddr_in6 *)sockaddr; sock_in6 = (struct sockaddr_in6 *)sockaddr;
snprintf(np->np_ip, IPV6_ADDRESS_SPACE, "%s", ip_str);
np->np_port = ntohs(sock_in6->sin6_port); np->np_port = ntohs(sock_in6->sin6_port);
} else { } else {
sock_in = (struct sockaddr_in *)sockaddr; sock_in = (struct sockaddr_in *)sockaddr;
sprintf(np->np_ip, "%s", ip_str);
np->np_port = ntohs(sock_in->sin_port); np->np_port = ntohs(sock_in->sin_port);
} }
...@@ -411,8 +408,8 @@ struct iscsi_np *iscsit_add_np( ...@@ -411,8 +408,8 @@ struct iscsi_np *iscsit_add_np(
list_add_tail(&np->np_list, &g_np_list); list_add_tail(&np->np_list, &g_np_list);
mutex_unlock(&np_lock); mutex_unlock(&np_lock);
pr_debug("CORE[0] - Added Network Portal: %s:%hu on %s\n", pr_debug("CORE[0] - Added Network Portal: %pISc:%hu on %s\n",
np->np_ip, np->np_port, np->np_transport->name); &np->np_sockaddr, np->np_port, np->np_transport->name);
return np; return np;
} }
...@@ -481,8 +478,8 @@ int iscsit_del_np(struct iscsi_np *np) ...@@ -481,8 +478,8 @@ int iscsit_del_np(struct iscsi_np *np)
list_del(&np->np_list); list_del(&np->np_list);
mutex_unlock(&np_lock); mutex_unlock(&np_lock);
pr_debug("CORE[0] - Removed Network Portal: %s:%hu on %s\n", pr_debug("CORE[0] - Removed Network Portal: %pISc:%hu on %s\n",
np->np_ip, np->np_port, np->np_transport->name); &np->np_sockaddr, np->np_port, np->np_transport->name);
iscsit_put_transport(np->np_transport); iscsit_put_transport(np->np_transport);
kfree(np); kfree(np);
...@@ -3463,7 +3460,6 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, ...@@ -3463,7 +3460,6 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,
tpg_np_list) { tpg_np_list) {
struct iscsi_np *np = tpg_np->tpg_np; struct iscsi_np *np = tpg_np->tpg_np;
bool inaddr_any = iscsit_check_inaddr_any(np); bool inaddr_any = iscsit_check_inaddr_any(np);
char *fmt_str;
if (np->np_network_transport != network_transport) if (np->np_network_transport != network_transport)
continue; continue;
...@@ -3491,15 +3487,18 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, ...@@ -3491,15 +3487,18 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,
} }
} }
if (np->np_sockaddr.ss_family == AF_INET6) if (inaddr_any) {
fmt_str = "TargetAddress=[%s]:%hu,%hu"; len = sprintf(buf, "TargetAddress="
else "%s:%hu,%hu",
fmt_str = "TargetAddress=%s:%hu,%hu"; conn->local_ip,
np->np_port,
len = sprintf(buf, fmt_str, tpg->tpgt);
inaddr_any ? conn->local_ip : np->np_ip, } else {
np->np_port, len = sprintf(buf, "TargetAddress="
tpg->tpgt); "%pISpc,%hu",
&np->np_sockaddr,
tpg->tpgt);
}
len += 1; len += 1;
if ((len + payload_len) > buffer_len) { if ((len + payload_len) > buffer_len) {
......
...@@ -13,7 +13,7 @@ extern int iscsit_deaccess_np(struct iscsi_np *, struct iscsi_portal_group *, ...@@ -13,7 +13,7 @@ extern int iscsit_deaccess_np(struct iscsi_np *, struct iscsi_portal_group *,
extern bool iscsit_check_np_match(struct __kernel_sockaddr_storage *, extern bool iscsit_check_np_match(struct __kernel_sockaddr_storage *,
struct iscsi_np *, int); struct iscsi_np *, int);
extern struct iscsi_np *iscsit_add_np(struct __kernel_sockaddr_storage *, extern struct iscsi_np *iscsit_add_np(struct __kernel_sockaddr_storage *,
char *, int); int);
extern int iscsit_reset_np_thread(struct iscsi_np *, struct iscsi_tpg_np *, extern int iscsit_reset_np_thread(struct iscsi_np *, struct iscsi_tpg_np *,
struct iscsi_portal_group *, bool); struct iscsi_portal_group *, bool);
extern int iscsit_del_np(struct iscsi_np *); extern int iscsit_del_np(struct iscsi_np *);
......
...@@ -99,7 +99,7 @@ static ssize_t lio_target_np_store_sctp( ...@@ -99,7 +99,7 @@ static ssize_t lio_target_np_store_sctp(
* Use existing np->np_sockaddr for SCTP network portal reference * Use existing np->np_sockaddr for SCTP network portal reference
*/ */
tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
np->np_ip, tpg_np, ISCSI_SCTP_TCP); tpg_np, ISCSI_SCTP_TCP);
if (!tpg_np_sctp || IS_ERR(tpg_np_sctp)) if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
goto out; goto out;
} else { } else {
...@@ -177,7 +177,7 @@ static ssize_t lio_target_np_store_iser( ...@@ -177,7 +177,7 @@ static ssize_t lio_target_np_store_iser(
} }
tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
np->np_ip, tpg_np, ISCSI_INFINIBAND); tpg_np, ISCSI_INFINIBAND);
if (IS_ERR(tpg_np_iser)) { if (IS_ERR(tpg_np_iser)) {
rc = PTR_ERR(tpg_np_iser); rc = PTR_ERR(tpg_np_iser);
goto out; goto out;
...@@ -248,8 +248,8 @@ static struct se_tpg_np *lio_target_call_addnptotpg( ...@@ -248,8 +248,8 @@ static struct se_tpg_np *lio_target_call_addnptotpg(
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
str++; /* Skip over leading "[" */ str++; /* Skip over leading "[" */
*str2 = '\0'; /* Terminate the IPv6 address */ *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
str2++; /* Skip over the "]" */ 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\""
...@@ -316,7 +316,7 @@ static struct se_tpg_np *lio_target_call_addnptotpg( ...@@ -316,7 +316,7 @@ static struct se_tpg_np *lio_target_call_addnptotpg(
* sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
* *
*/ */
tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, str, NULL, tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
ISCSI_TCP); ISCSI_TCP);
if (IS_ERR(tpg_np)) { if (IS_ERR(tpg_np)) {
iscsit_put_tpg(tpg); iscsit_put_tpg(tpg);
...@@ -344,8 +344,8 @@ static void lio_target_call_delnpfromtpg( ...@@ -344,8 +344,8 @@ static void lio_target_call_delnpfromtpg(
se_tpg = &tpg->tpg_se_tpg; se_tpg = &tpg->tpg_se_tpg;
pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
" PORTAL: %s:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), " PORTAL: %pISc:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
tpg->tpgt, tpg_np->tpg_np->np_ip, tpg_np->tpg_np->np_port); tpg->tpgt, &tpg_np->tpg_np->np_sockaddr, tpg_np->tpg_np->np_port);
ret = iscsit_tpg_del_network_portal(tpg, tpg_np); ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
if (ret < 0) if (ret < 0)
......
...@@ -823,8 +823,8 @@ static void iscsi_handle_login_thread_timeout(unsigned long data) ...@@ -823,8 +823,8 @@ static void iscsi_handle_login_thread_timeout(unsigned long data)
struct iscsi_np *np = (struct iscsi_np *) data; struct iscsi_np *np = (struct iscsi_np *) data;
spin_lock_bh(&np->np_thread_lock); spin_lock_bh(&np->np_thread_lock);
pr_err("iSCSI Login timeout on Network Portal %s:%hu\n", pr_err("iSCSI Login timeout on Network Portal %pISc:%hu\n",
np->np_ip, np->np_port); &np->np_sockaddr, np->np_port);
if (np->np_login_timer_flags & ISCSI_TF_STOP) { if (np->np_login_timer_flags & ISCSI_TF_STOP) {
spin_unlock_bh(&np->np_thread_lock); spin_unlock_bh(&np->np_thread_lock);
...@@ -1302,8 +1302,8 @@ static int __iscsi_target_login_thread(struct iscsi_np *np) ...@@ -1302,8 +1302,8 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
spin_lock_bh(&np->np_thread_lock); spin_lock_bh(&np->np_thread_lock);
if (np->np_thread_state != ISCSI_NP_THREAD_ACTIVE) { if (np->np_thread_state != ISCSI_NP_THREAD_ACTIVE) {
spin_unlock_bh(&np->np_thread_lock); spin_unlock_bh(&np->np_thread_lock);
pr_err("iSCSI Network Portal on %s:%hu currently not" pr_err("iSCSI Network Portal on %pISc:%hu currently not"
" active.\n", np->np_ip, np->np_port); " active.\n", &np->np_sockaddr, np->np_port);
iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE); ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE);
goto new_sess_out; goto new_sess_out;
......
...@@ -461,7 +461,6 @@ static bool iscsit_tpg_check_network_portal( ...@@ -461,7 +461,6 @@ static bool iscsit_tpg_check_network_portal(
struct iscsi_tpg_np *iscsit_tpg_add_network_portal( struct iscsi_tpg_np *iscsit_tpg_add_network_portal(
struct iscsi_portal_group *tpg, struct iscsi_portal_group *tpg,
struct __kernel_sockaddr_storage *sockaddr, struct __kernel_sockaddr_storage *sockaddr,
char *ip_str,
struct iscsi_tpg_np *tpg_np_parent, struct iscsi_tpg_np *tpg_np_parent,
int network_transport) int network_transport)
{ {
...@@ -471,8 +470,8 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal( ...@@ -471,8 +470,8 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal(
if (!tpg_np_parent) { if (!tpg_np_parent) {
if (iscsit_tpg_check_network_portal(tpg->tpg_tiqn, sockaddr, if (iscsit_tpg_check_network_portal(tpg->tpg_tiqn, sockaddr,
network_transport)) { network_transport)) {
pr_err("Network Portal: %s already exists on a" pr_err("Network Portal: %pISc already exists on a"
" different TPG on %s\n", ip_str, " different TPG on %s\n", sockaddr,
tpg->tpg_tiqn->tiqn); tpg->tpg_tiqn->tiqn);
return ERR_PTR(-EEXIST); return ERR_PTR(-EEXIST);
} }
...@@ -485,7 +484,7 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal( ...@@ -485,7 +484,7 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal(
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
np = iscsit_add_np(sockaddr, ip_str, network_transport); np = iscsit_add_np(sockaddr, network_transport);
if (IS_ERR(np)) { if (IS_ERR(np)) {
kfree(tpg_np); kfree(tpg_np);
return ERR_CAST(np); return ERR_CAST(np);
...@@ -515,8 +514,8 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal( ...@@ -515,8 +514,8 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal(
spin_unlock(&tpg_np_parent->tpg_np_parent_lock); spin_unlock(&tpg_np_parent->tpg_np_parent_lock);
} }
pr_debug("CORE[%s] - Added Network Portal: %s:%hu,%hu on %s\n", pr_debug("CORE[%s] - Added Network Portal: %pISc:%hu,%hu on %s\n",
tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt, tpg->tpg_tiqn->tiqn, &np->np_sockaddr, np->np_port, tpg->tpgt,
np->np_transport->name); np->np_transport->name);
return tpg_np; return tpg_np;
...@@ -529,8 +528,8 @@ static int iscsit_tpg_release_np( ...@@ -529,8 +528,8 @@ static int iscsit_tpg_release_np(
{ {
iscsit_clear_tpg_np_login_thread(tpg_np, tpg, true); iscsit_clear_tpg_np_login_thread(tpg_np, tpg, true);
pr_debug("CORE[%s] - Removed Network Portal: %s:%hu,%hu on %s\n", pr_debug("CORE[%s] - Removed Network Portal: %pISc:%hu,%hu on %s\n",
tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt, tpg->tpg_tiqn->tiqn, &np->np_sockaddr, np->np_port, tpg->tpgt,
np->np_transport->name); np->np_transport->name);
tpg_np->tpg_np = NULL; tpg_np->tpg_np = NULL;
......
...@@ -22,7 +22,7 @@ extern struct iscsi_node_attrib *iscsit_tpg_get_node_attrib(struct iscsi_session ...@@ -22,7 +22,7 @@ extern struct iscsi_node_attrib *iscsit_tpg_get_node_attrib(struct iscsi_session
extern void iscsit_tpg_del_external_nps(struct iscsi_tpg_np *); extern void iscsit_tpg_del_external_nps(struct iscsi_tpg_np *);
extern struct iscsi_tpg_np *iscsit_tpg_locate_child_np(struct iscsi_tpg_np *, int); extern struct iscsi_tpg_np *iscsit_tpg_locate_child_np(struct iscsi_tpg_np *, int);
extern struct iscsi_tpg_np *iscsit_tpg_add_network_portal(struct iscsi_portal_group *, extern struct iscsi_tpg_np *iscsit_tpg_add_network_portal(struct iscsi_portal_group *,
struct __kernel_sockaddr_storage *, char *, struct iscsi_tpg_np *, struct __kernel_sockaddr_storage *, struct iscsi_tpg_np *,
int); int);
extern int iscsit_tpg_del_network_portal(struct iscsi_portal_group *, extern int iscsit_tpg_del_network_portal(struct iscsi_portal_group *,
struct iscsi_tpg_np *); struct iscsi_tpg_np *);
......
...@@ -778,7 +778,6 @@ struct iscsi_np { ...@@ -778,7 +778,6 @@ struct iscsi_np {
enum iscsi_timer_flags_table np_login_timer_flags; enum iscsi_timer_flags_table np_login_timer_flags;
u32 np_exports; u32 np_exports;
enum np_flags_table np_flags; enum np_flags_table np_flags;
unsigned char np_ip[IPV6_ADDRESS_SPACE];
u16 np_port; u16 np_port;
spinlock_t np_thread_lock; spinlock_t np_thread_lock;
struct completion np_restart_comp; struct completion np_restart_comp;
......
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