Date: Wed, 16 Apr 2014 11:00:10 +0000 (UTC) From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264530 - in head: sys/cam/ctl sys/dev/iscsi usr.sbin/ctld Message-ID: <201404161100.s3GB0AHb073985@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: trasz Date: Wed Apr 16 11:00:10 2014 New Revision: 264530 URL: http://svnweb.freebsd.org/changeset/base/264530 Log: Properly pass the initiator address when running in proxy mode. Sponsored by: The FreeBSD Foundation Modified: head/sys/cam/ctl/ctl_frontend_iscsi.c head/sys/cam/ctl/ctl_frontend_iscsi.h head/sys/cam/ctl/ctl_ioctl.h head/sys/dev/iscsi/icl.h head/sys/dev/iscsi/icl_proxy.c head/usr.sbin/ctld/ctld.c head/usr.sbin/ctld/ctld.h head/usr.sbin/ctld/kernel.c Modified: head/sys/cam/ctl/ctl_frontend_iscsi.c ============================================================================== --- head/sys/cam/ctl/ctl_frontend_iscsi.c Wed Apr 16 10:49:48 2014 (r264529) +++ head/sys/cam/ctl/ctl_frontend_iscsi.c Wed Apr 16 11:00:10 2014 (r264530) @@ -1353,7 +1353,7 @@ cfiscsi_module_event_handler(module_t mo #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 po } 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 *c 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; } Modified: head/sys/cam/ctl/ctl_frontend_iscsi.h ============================================================================== --- head/sys/cam/ctl/ctl_frontend_iscsi.h Wed Apr 16 10:49:48 2014 (r264529) +++ head/sys/cam/ctl/ctl_frontend_iscsi.h Wed Apr 16 11:00:10 2014 (r264530) @@ -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; Modified: head/sys/cam/ctl/ctl_ioctl.h ============================================================================== --- head/sys/cam/ctl/ctl_ioctl.h Wed Apr 16 10:49:48 2014 (r264529) +++ head/sys/cam/ctl/ctl_ioctl.h Wed Apr 16 11:00:10 2014 (r264530) @@ -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]; }; Modified: head/sys/dev/iscsi/icl.h ============================================================================== --- head/sys/dev/iscsi/icl.h Wed Apr 16 10:49:48 2014 (r264529) +++ head/sys/dev/iscsi/icl.h Wed Apr 16 11:00:10 2014 (r264530) @@ -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 * /* * 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, Modified: head/sys/dev/iscsi/icl_proxy.c ============================================================================== --- head/sys/dev/iscsi/icl_proxy.c Wed Apr 16 10:49:48 2014 (r264529) +++ head/sys/dev/iscsi/icl_proxy.c Wed Apr 16 11:00:10 2014 (r264530) @@ -182,7 +182,7 @@ icl_conn_connect(struct icl_conn *ic, bo } 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); } } Modified: head/usr.sbin/ctld/ctld.c ============================================================================== --- head/usr.sbin/ctld/ctld.c Wed Apr 16 10:49:48 2014 (r264529) +++ head/usr.sbin/ctld/ctld.c Wed Apr 16 11:00:10 2014 (r264530) @@ -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, } 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)); - - 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 + 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); conn = connection_new(portal, fd, host); set_timeout(conf); @@ -1699,7 +1687,9 @@ main_loop(struct conf *conf, bool dont_f #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_f 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 @@ found: 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; } } Modified: head/usr.sbin/ctld/ctld.h ============================================================================== --- head/usr.sbin/ctld/ctld.h Wed Apr 16 10:49:48 2014 (r264529) +++ head/usr.sbin/ctld/ctld.h Wed Apr 16 11:00:10 2014 (r264530) @@ -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); Modified: head/usr.sbin/ctld/kernel.c ============================================================================== --- head/usr.sbin/ctld/kernel.c Wed Apr 16 10:49:48 2014 (r264529) +++ head/usr.sbin/ctld/kernel.c Wed Apr 16 11:00:10 2014 (r264530) @@ -700,13 +700,16 @@ kernel_listen(struct addrinfo *ai, bool } 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 *p *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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404161100.s3GB0AHb073985>