Commit 69d75574 authored by Andy Grover's avatar Andy Grover Committed by Nicholas Bellinger

target/iscsi: Keep local_ip as the actual sockaddr

This is a more natural format that lets us format it with the appropriate
printk specifier as needed.

This also lets us handle v4-mapped ipv6 addresses a little more nicely, by
storing the addr as an actual v4 sockaddr in conn->local_sockaddr.

Finally, we no longer need to maintain variables for port, since this is
contained in sockaddr. Remove iscsi_np.np_port and iscsi_conn.local_port.
Signed-off-by: default avatarAndy Grover <agrover@redhat.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 76c28f1f
...@@ -3218,9 +3218,7 @@ isert_set_conn_info(struct iscsi_np *np, struct iscsi_conn *conn, ...@@ -3218,9 +3218,7 @@ isert_set_conn_info(struct iscsi_np *np, struct iscsi_conn *conn,
conn->login_port = ntohs(sock_in6->sin6_port); conn->login_port = ntohs(sock_in6->sin6_port);
sock_in6 = (struct sockaddr_in6 *)&cm_route->addr.src_addr; sock_in6 = (struct sockaddr_in6 *)&cm_route->addr.src_addr;
snprintf(conn->local_ip, sizeof(conn->local_ip), "%pI6c", memcpy(&conn->local_sockaddr , &sock_in6, sizeof(sock_in6));
&sock_in6->sin6_addr.in6_u);
conn->local_port = ntohs(sock_in6->sin6_port);
} else { } else {
sock_in = (struct sockaddr_in *)&cm_route->addr.dst_addr; sock_in = (struct sockaddr_in *)&cm_route->addr.dst_addr;
sprintf(conn->login_ip, "%pI4", sprintf(conn->login_ip, "%pI4",
...@@ -3228,9 +3226,7 @@ isert_set_conn_info(struct iscsi_np *np, struct iscsi_conn *conn, ...@@ -3228,9 +3226,7 @@ isert_set_conn_info(struct iscsi_np *np, struct iscsi_conn *conn,
conn->login_port = ntohs(sock_in->sin_port); conn->login_port = ntohs(sock_in->sin_port);
sock_in = (struct sockaddr_in *)&cm_route->addr.src_addr; sock_in = (struct sockaddr_in *)&cm_route->addr.src_addr;
sprintf(conn->local_ip, "%pI4", memcpy(&conn->local_sockaddr , &sock_in, sizeof(sock_in));
&sock_in->sin_addr.s_addr);
conn->local_port = ntohs(sock_in->sin_port);
} }
} }
......
...@@ -276,7 +276,7 @@ bool iscsit_check_np_match( ...@@ -276,7 +276,7 @@ bool iscsit_check_np_match(
struct sockaddr_in *sock_in, *sock_in_e; struct sockaddr_in *sock_in, *sock_in_e;
struct sockaddr_in6 *sock_in6, *sock_in6_e; struct sockaddr_in6 *sock_in6, *sock_in6_e;
bool ip_match = false; bool ip_match = false;
u16 port; u16 port, port_e;
if (sockaddr->ss_family == AF_INET6) { if (sockaddr->ss_family == AF_INET6) {
sock_in6 = (struct sockaddr_in6 *)sockaddr; sock_in6 = (struct sockaddr_in6 *)sockaddr;
...@@ -288,6 +288,7 @@ bool iscsit_check_np_match( ...@@ -288,6 +288,7 @@ bool iscsit_check_np_match(
ip_match = true; ip_match = true;
port = ntohs(sock_in6->sin6_port); port = ntohs(sock_in6->sin6_port);
port_e = ntohs(sock_in6_e->sin6_port);
} else { } else {
sock_in = (struct sockaddr_in *)sockaddr; sock_in = (struct sockaddr_in *)sockaddr;
sock_in_e = (struct sockaddr_in *)&np->np_sockaddr; sock_in_e = (struct sockaddr_in *)&np->np_sockaddr;
...@@ -296,9 +297,10 @@ bool iscsit_check_np_match( ...@@ -296,9 +297,10 @@ bool iscsit_check_np_match(
ip_match = true; ip_match = true;
port = ntohs(sock_in->sin_port); port = ntohs(sock_in->sin_port);
port_e = ntohs(sock_in_e->sin_port);
} }
if (ip_match && (np->np_port == port) && if (ip_match && (port_e == port) &&
(np->np_network_transport == network_transport)) (np->np_network_transport == network_transport))
return true; return true;
...@@ -343,8 +345,6 @@ struct iscsi_np *iscsit_add_np( ...@@ -343,8 +345,6 @@ struct iscsi_np *iscsit_add_np(
struct __kernel_sockaddr_storage *sockaddr, struct __kernel_sockaddr_storage *sockaddr,
int network_transport) int network_transport)
{ {
struct sockaddr_in *sock_in;
struct sockaddr_in6 *sock_in6;
struct iscsi_np *np; struct iscsi_np *np;
int ret; int ret;
...@@ -367,14 +367,6 @@ struct iscsi_np *iscsit_add_np( ...@@ -367,14 +367,6 @@ struct iscsi_np *iscsit_add_np(
} }
np->np_flags |= NPF_IP_NETWORK; np->np_flags |= NPF_IP_NETWORK;
if (sockaddr->ss_family == AF_INET6) {
sock_in6 = (struct sockaddr_in6 *)sockaddr;
np->np_port = ntohs(sock_in6->sin6_port);
} else {
sock_in = (struct sockaddr_in *)sockaddr;
np->np_port = ntohs(sock_in->sin_port);
}
np->np_network_transport = network_transport; np->np_network_transport = network_transport;
spin_lock_init(&np->np_thread_lock); spin_lock_init(&np->np_thread_lock);
init_completion(&np->np_restart_comp); init_completion(&np->np_restart_comp);
...@@ -408,8 +400,8 @@ struct iscsi_np *iscsit_add_np( ...@@ -408,8 +400,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: %pISc:%hu on %s\n", pr_debug("CORE[0] - Added Network Portal: %pISpc on %s\n",
&np->np_sockaddr, np->np_port, np->np_transport->name); &np->np_sockaddr, np->np_transport->name);
return np; return np;
} }
...@@ -478,8 +470,8 @@ int iscsit_del_np(struct iscsi_np *np) ...@@ -478,8 +470,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: %pISc:%hu on %s\n", pr_debug("CORE[0] - Removed Network Portal: %pISpc on %s\n",
&np->np_sockaddr, np->np_port, np->np_transport->name); &np->np_sockaddr, np->np_transport->name);
iscsit_put_transport(np->np_transport); iscsit_put_transport(np->np_transport);
kfree(np); kfree(np);
...@@ -3460,6 +3452,7 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, ...@@ -3460,6 +3452,7 @@ 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);
struct __kernel_sockaddr_storage *sockaddr;
if (np->np_network_transport != network_transport) if (np->np_network_transport != network_transport)
continue; continue;
...@@ -3487,18 +3480,15 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, ...@@ -3487,18 +3480,15 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,
} }
} }
if (inaddr_any) { if (inaddr_any)
len = sprintf(buf, "TargetAddress=" sockaddr = &conn->local_sockaddr;
"%s:%hu,%hu", else
conn->local_ip, sockaddr = &np->np_sockaddr;
np->np_port,
tpg->tpgt);
} else {
len = sprintf(buf, "TargetAddress=" len = sprintf(buf, "TargetAddress="
"%pISpc,%hu", "%pISpc,%hu",
&np->np_sockaddr, sockaddr,
tpg->tpgt); tpg->tpgt);
}
len += 1; len += 1;
if ((len + payload_len) > buffer_len) { if ((len + payload_len) > buffer_len) {
......
...@@ -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: %pISc:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
tpg->tpgt, &tpg_np->tpg_np->np_sockaddr, tpg_np->tpg_np->np_port); tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
ret = iscsit_tpg_del_network_portal(tpg, tpg_np); ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
if (ret < 0) if (ret < 0)
......
...@@ -729,8 +729,8 @@ int iscsi_post_login_handler( ...@@ -729,8 +729,8 @@ int iscsi_post_login_handler(
} }
pr_debug("iSCSI Login successful on CID: %hu from %s to" pr_debug("iSCSI Login successful on CID: %hu from %s to"
" %s:%hu,%hu\n", conn->cid, conn->login_ip, " %pISpc,%hu\n", conn->cid, conn->login_ip,
conn->local_ip, conn->local_port, tpg->tpgt); &conn->local_sockaddr, tpg->tpgt);
list_add_tail(&conn->conn_list, &sess->sess_conn_list); list_add_tail(&conn->conn_list, &sess->sess_conn_list);
atomic_inc(&sess->nconn); atomic_inc(&sess->nconn);
...@@ -774,8 +774,8 @@ int iscsi_post_login_handler( ...@@ -774,8 +774,8 @@ int iscsi_post_login_handler(
pr_debug("Moving to TARG_SESS_STATE_LOGGED_IN.\n"); pr_debug("Moving to TARG_SESS_STATE_LOGGED_IN.\n");
sess->session_state = TARG_SESS_STATE_LOGGED_IN; sess->session_state = TARG_SESS_STATE_LOGGED_IN;
pr_debug("iSCSI Login successful on CID: %hu from %s to %s:%hu,%hu\n", pr_debug("iSCSI Login successful on CID: %hu from %s to %pISpc,%hu\n",
conn->cid, conn->login_ip, conn->local_ip, conn->local_port, conn->cid, conn->login_ip, &conn->local_sockaddr,
tpg->tpgt); tpg->tpgt);
spin_lock_bh(&sess->conn_lock); spin_lock_bh(&sess->conn_lock);
...@@ -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 %pISc:%hu\n", pr_err("iSCSI Login timeout on Network Portal %pISpc\n",
&np->np_sockaddr, np->np_port); &np->np_sockaddr);
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);
...@@ -1027,13 +1027,15 @@ int iscsit_accept_np(struct iscsi_np *np, struct iscsi_conn *conn) ...@@ -1027,13 +1027,15 @@ int iscsit_accept_np(struct iscsi_np *np, struct iscsi_conn *conn)
rc = conn->sock->ops->getname(conn->sock, rc = conn->sock->ops->getname(conn->sock,
(struct sockaddr *)&sock_in6, &err, 0); (struct sockaddr *)&sock_in6, &err, 0);
if (!rc) { if (!rc) {
if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) {
snprintf(conn->local_ip, sizeof(conn->local_ip), "[%pI6c]", memcpy(&conn->local_sockaddr, &sock_in6, sizeof(sock_in6));
&sock_in6.sin6_addr.in6_u); } else {
else /* Pretend to be an ipv4 socket */
snprintf(conn->local_ip, sizeof(conn->local_ip), "%pI4", sock_in.sin_family = AF_INET;
&sock_in6.sin6_addr.s6_addr32[3]); sock_in.sin_port = sock_in6.sin6_port;
conn->local_port = ntohs(sock_in6.sin6_port); memcpy(&sock_in.sin_addr, &sock_in6.sin6_addr.s6_addr32[3], 4);
memcpy(&conn->local_sockaddr, &sock_in, sizeof(sock_in));
}
} }
} else { } else {
memset(&sock_in, 0, sizeof(struct sockaddr_in)); memset(&sock_in, 0, sizeof(struct sockaddr_in));
...@@ -1048,11 +1050,8 @@ int iscsit_accept_np(struct iscsi_np *np, struct iscsi_conn *conn) ...@@ -1048,11 +1050,8 @@ int iscsit_accept_np(struct iscsi_np *np, struct iscsi_conn *conn)
rc = conn->sock->ops->getname(conn->sock, rc = conn->sock->ops->getname(conn->sock,
(struct sockaddr *)&sock_in, &err, 0); (struct sockaddr *)&sock_in, &err, 0);
if (!rc) { if (!rc)
sprintf(conn->local_ip, "%pI4", memcpy(&conn->local_sockaddr, &sock_in, sizeof(sock_in));
&sock_in.sin_addr.s_addr);
conn->local_port = ntohs(sock_in.sin_port);
}
} }
return 0; return 0;
...@@ -1302,8 +1301,8 @@ static int __iscsi_target_login_thread(struct iscsi_np *np) ...@@ -1302,8 +1301,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 %pISc:%hu currently not" pr_err("iSCSI Network Portal on %pISpc currently not"
" active.\n", &np->np_sockaddr, np->np_port); " active.\n", &np->np_sockaddr);
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;
...@@ -1313,8 +1312,8 @@ static int __iscsi_target_login_thread(struct iscsi_np *np) ...@@ -1313,8 +1312,8 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
conn->network_transport = np->np_network_transport; conn->network_transport = np->np_network_transport;
pr_debug("Received iSCSI login request from %s on %s Network" pr_debug("Received iSCSI login request from %s on %s Network"
" Portal %s:%hu\n", conn->login_ip, np->np_transport->name, " Portal %pISpc\n", conn->login_ip, np->np_transport->name,
conn->local_ip, conn->local_port); &conn->local_sockaddr);
pr_debug("Moving to TARG_CONN_STATE_IN_LOGIN.\n"); pr_debug("Moving to TARG_CONN_STATE_IN_LOGIN.\n");
conn->conn_state = TARG_CONN_STATE_IN_LOGIN; conn->conn_state = TARG_CONN_STATE_IN_LOGIN;
......
...@@ -514,8 +514,8 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal( ...@@ -514,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: %pISc:%hu,%hu on %s\n", pr_debug("CORE[%s] - Added Network Portal: %pISpc,%hu on %s\n",
tpg->tpg_tiqn->tiqn, &np->np_sockaddr, np->np_port, tpg->tpgt, tpg->tpg_tiqn->tiqn, &np->np_sockaddr, tpg->tpgt,
np->np_transport->name); np->np_transport->name);
return tpg_np; return tpg_np;
...@@ -528,8 +528,8 @@ static int iscsit_tpg_release_np( ...@@ -528,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: %pISc:%hu,%hu on %s\n", pr_debug("CORE[%s] - Removed Network Portal: %pISpc,%hu on %s\n",
tpg->tpg_tiqn->tiqn, &np->np_sockaddr, np->np_port, tpg->tpgt, tpg->tpg_tiqn->tiqn, &np->np_sockaddr, tpg->tpgt,
np->np_transport->name); np->np_transport->name);
tpg_np->tpg_np = NULL; tpg_np->tpg_np = NULL;
......
...@@ -519,7 +519,6 @@ struct iscsi_conn { ...@@ -519,7 +519,6 @@ struct iscsi_conn {
u16 cid; u16 cid;
/* Remote TCP Port */ /* Remote TCP Port */
u16 login_port; u16 login_port;
u16 local_port;
int net_size; int net_size;
int login_family; int login_family;
u32 auth_id; u32 auth_id;
...@@ -531,7 +530,7 @@ struct iscsi_conn { ...@@ -531,7 +530,7 @@ struct iscsi_conn {
u32 stat_sn; u32 stat_sn;
#define IPV6_ADDRESS_SPACE 48 #define IPV6_ADDRESS_SPACE 48
unsigned char login_ip[IPV6_ADDRESS_SPACE]; unsigned char login_ip[IPV6_ADDRESS_SPACE];
unsigned char local_ip[IPV6_ADDRESS_SPACE]; struct __kernel_sockaddr_storage local_sockaddr;
int conn_usage_count; int conn_usage_count;
int conn_waiting_on_uc; int conn_waiting_on_uc;
atomic_t check_immediate_queue; atomic_t check_immediate_queue;
...@@ -778,7 +777,6 @@ struct iscsi_np { ...@@ -778,7 +777,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;
u16 np_port;
spinlock_t np_thread_lock; spinlock_t np_thread_lock;
struct completion np_restart_comp; struct completion np_restart_comp;
struct socket *np_socket; struct socket *np_socket;
......
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