Properly pass the initiator address when running in proxy mode.
Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
9a95cfffd8
commit
8eab95d646
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=264530
@ -1353,7 +1353,7 @@ cfiscsi_module_event_handler(module_t mod, int what, void *arg)
|
||||
|
||||
#ifdef ICL_KERNEL_PROXY
|
||||
static void
|
||||
cfiscsi_accept(struct socket *so, int portal_id)
|
||||
cfiscsi_accept(struct socket *so, struct sockaddr *sa, int portal_id)
|
||||
{
|
||||
struct cfiscsi_session *cs;
|
||||
|
||||
@ -1364,6 +1364,7 @@ cfiscsi_accept(struct socket *so, int portal_id)
|
||||
}
|
||||
|
||||
icl_conn_handoff_sock(cs->cs_conn, so);
|
||||
cs->cs_initiator_sa = sa;
|
||||
cs->cs_portal_id = portal_id;
|
||||
cs->cs_waiting_for_ctld = true;
|
||||
cv_signal(&cfiscsi_softc.accept_cv);
|
||||
@ -1788,6 +1789,16 @@ cfiscsi_ioctl_accept(struct ctl_iscsi *ci)
|
||||
|
||||
ciap->connection_id = cs->cs_id;
|
||||
ciap->portal_id = cs->cs_portal_id;
|
||||
ciap->initiator_addrlen = cs->cs_initiator_sa->sa_len;
|
||||
error = copyout(cs->cs_initiator_sa, ciap->initiator_addr,
|
||||
cs->cs_initiator_sa->sa_len);
|
||||
if (error != 0) {
|
||||
snprintf(ci->error_str, sizeof(ci->error_str),
|
||||
"copyout failed with error %d", error);
|
||||
ci->status = CTL_ISCSI_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
ci->status = CTL_ISCSI_OK;
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,7 @@ struct cfiscsi_session {
|
||||
unsigned int cs_id;
|
||||
int cs_ctl_initid;
|
||||
#ifdef ICL_KERNEL_PROXY
|
||||
struct sockaddr *cs_initiator_sa;
|
||||
int cs_portal_id;
|
||||
bool cs_login_phase;
|
||||
bool cs_waiting_for_ctld;
|
||||
|
@ -706,8 +706,9 @@ struct ctl_iscsi_listen_params {
|
||||
|
||||
struct ctl_iscsi_accept_params {
|
||||
int connection_id;
|
||||
struct sockaddr *initiator_addr;
|
||||
int portal_id;
|
||||
struct sockaddr *initiator_addr;
|
||||
socklen_t initiator_addrlen;
|
||||
int spare[4];
|
||||
};
|
||||
|
||||
|
@ -128,7 +128,8 @@ struct icl_listen_sock {
|
||||
struct icl_listen {
|
||||
TAILQ_HEAD(, icl_listen_sock) il_sockets;
|
||||
struct sx il_lock;
|
||||
void (*il_accept)(struct socket *, int);
|
||||
void (*il_accept)(struct socket *,
|
||||
struct sockaddr *, int);
|
||||
};
|
||||
|
||||
/*
|
||||
@ -140,7 +141,8 @@ int icl_conn_connect(struct icl_conn *ic, bool rdma,
|
||||
/*
|
||||
* Target part.
|
||||
*/
|
||||
struct icl_listen *icl_listen_new(void (*accept_cb)(struct socket *, int));
|
||||
struct icl_listen *icl_listen_new(void (*accept_cb)(struct socket *,
|
||||
struct sockaddr *, int));
|
||||
void icl_listen_free(struct icl_listen *il);
|
||||
int icl_listen_add(struct icl_listen *il, bool rdma,
|
||||
int domain, int socktype, int protocol,
|
||||
|
@ -182,7 +182,7 @@ icl_conn_connect(struct icl_conn *ic, bool rdma, int domain, int socktype,
|
||||
}
|
||||
|
||||
struct icl_listen *
|
||||
icl_listen_new(void (*accept_cb)(struct socket *, int))
|
||||
icl_listen_new(void (*accept_cb)(struct socket *, struct sockaddr *, int))
|
||||
{
|
||||
struct icl_listen *il;
|
||||
|
||||
@ -296,9 +296,10 @@ icl_accept_thread(void *arg)
|
||||
if (sa != NULL)
|
||||
free(sa, M_SONAME);
|
||||
soclose(so);
|
||||
continue;
|
||||
}
|
||||
|
||||
(ils->ils_listen->il_accept)(so, ils->ils_id);
|
||||
(ils->ils_listen->il_accept)(so, sa, ils->ils_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1588,8 +1588,8 @@ wait_for_children(bool block)
|
||||
}
|
||||
|
||||
static void
|
||||
handle_connection(struct portal *portal, int fd, const struct sockaddr_storage *ss,
|
||||
socklen_t sslen, bool dont_fork)
|
||||
handle_connection(struct portal *portal, int fd,
|
||||
const struct sockaddr *client_sa, socklen_t client_salen, bool dont_fork)
|
||||
{
|
||||
struct connection *conn;
|
||||
int error;
|
||||
@ -1624,27 +1624,15 @@ handle_connection(struct portal *portal, int fd, const struct sockaddr_storage *
|
||||
}
|
||||
pidfile_close(conf->conf_pidfh);
|
||||
|
||||
#ifdef ICL_KERNEL_PROXY
|
||||
/*
|
||||
* XXX
|
||||
*/
|
||||
if (proxy_mode) {
|
||||
log_set_peer_addr("XXX");
|
||||
} else {
|
||||
#endif
|
||||
assert(proxy_mode == false);
|
||||
error = getnameinfo((struct sockaddr *)ss, sslen,
|
||||
host, sizeof(host), NULL, 0, NI_NUMERICHOST);
|
||||
if (error != 0)
|
||||
log_errx(1, "getnameinfo: %s", gai_strerror(error));
|
||||
error = getnameinfo(client_sa, client_salen,
|
||||
host, sizeof(host), NULL, 0, NI_NUMERICHOST);
|
||||
if (error != 0)
|
||||
log_errx(1, "getnameinfo: %s", gai_strerror(error));
|
||||
|
||||
log_debugx("accepted connection from %s; portal group \"%s\"",
|
||||
host, portal->p_portal_group->pg_name);
|
||||
log_set_peer_addr(host);
|
||||
setproctitle("%s", host);
|
||||
#ifdef ICL_KERNEL_PROXY
|
||||
}
|
||||
#endif
|
||||
log_debugx("accepted connection from %s; portal group \"%s\"",
|
||||
host, portal->p_portal_group->pg_name);
|
||||
log_set_peer_addr(host);
|
||||
setproctitle("%s", host);
|
||||
|
||||
conn = connection_new(portal, fd, host);
|
||||
set_timeout(conf);
|
||||
@ -1699,7 +1687,9 @@ main_loop(struct conf *conf, bool dont_fork)
|
||||
|
||||
#ifdef ICL_KERNEL_PROXY
|
||||
if (proxy_mode) {
|
||||
kernel_accept(&connection_id, &portal_id);
|
||||
client_salen = sizeof(client_sa);
|
||||
kernel_accept(&connection_id, &portal_id,
|
||||
(struct sockaddr *)&client_sa, &client_salen);
|
||||
|
||||
log_debugx("incoming connection, id %d, portal id %d",
|
||||
connection_id, portal_id);
|
||||
@ -1715,7 +1705,9 @@ main_loop(struct conf *conf, bool dont_fork)
|
||||
portal_id);
|
||||
|
||||
found:
|
||||
handle_connection(portal, connection_id, NULL, 0, dont_fork);
|
||||
handle_connection(portal, connection_id,
|
||||
(struct sockaddr *)&client_sa, client_salen,
|
||||
dont_fork);
|
||||
} else {
|
||||
#endif
|
||||
assert(proxy_mode == false);
|
||||
@ -1743,7 +1735,8 @@ main_loop(struct conf *conf, bool dont_fork)
|
||||
if (client_fd < 0)
|
||||
log_err(1, "accept");
|
||||
handle_connection(portal, client_fd,
|
||||
&client_sa, client_salen, dont_fork);
|
||||
(struct sockaddr *)&client_sa,
|
||||
client_salen, dont_fork);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,10 @@
|
||||
#define CTLD_H
|
||||
|
||||
#include <sys/queue.h>
|
||||
#ifdef ICL_KERNEL_PROXY
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <stdbool.h>
|
||||
#include <libutil.h>
|
||||
|
||||
@ -269,14 +273,15 @@ int kernel_port_on(void);
|
||||
int kernel_port_off(void);
|
||||
void kernel_capsicate(void);
|
||||
|
||||
/*
|
||||
* ICL_KERNEL_PROXY
|
||||
*/
|
||||
#ifdef ICL_KERNEL_PROXY
|
||||
void kernel_listen(struct addrinfo *ai, bool iser,
|
||||
int portal_id);
|
||||
void kernel_accept(int *connection_id, int *portal_id);
|
||||
void kernel_accept(int *connection_id, int *portal_id,
|
||||
struct sockaddr *client_sa,
|
||||
socklen_t *client_salen);
|
||||
void kernel_send(struct pdu *pdu);
|
||||
void kernel_receive(struct pdu *pdu);
|
||||
#endif
|
||||
|
||||
struct keys *keys_new(void);
|
||||
void keys_delete(struct keys *keys);
|
||||
|
@ -700,13 +700,16 @@ kernel_listen(struct addrinfo *ai, bool iser, int portal_id)
|
||||
}
|
||||
|
||||
void
|
||||
kernel_accept(int *connection_id, int *portal_id)
|
||||
kernel_accept(int *connection_id, int *portal_id,
|
||||
struct sockaddr *client_sa, socklen_t *client_salen)
|
||||
{
|
||||
struct ctl_iscsi req;
|
||||
struct sockaddr_storage ss;
|
||||
|
||||
bzero(&req, sizeof(req));
|
||||
|
||||
req.type = CTL_ISCSI_ACCEPT;
|
||||
req.data.accept.initiator_addr = (struct sockaddr *)&ss;
|
||||
|
||||
if (ioctl(ctl_fd, CTL_ISCSI, &req) == -1)
|
||||
log_err(1, "error issuing CTL_ISCSI ioctl");
|
||||
@ -718,6 +721,8 @@ kernel_accept(int *connection_id, int *portal_id)
|
||||
|
||||
*connection_id = req.data.accept.connection_id;
|
||||
*portal_id = req.data.accept.portal_id;
|
||||
*client_salen = req.data.accept.initiator_addrlen;
|
||||
memcpy(client_sa, &ss, *client_salen);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user