Author: trasz
Date: Wed May  7 07:37:55 2014
New Revision: 265513
URL: http://svnweb.freebsd.org/changeset/base/265513

Log:
  MFC r264530:
  
  Properly pass the initiator address when running in proxy mode.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  stable/10/sys/cam/ctl/ctl_frontend_iscsi.c
  stable/10/sys/cam/ctl/ctl_frontend_iscsi.h
  stable/10/sys/cam/ctl/ctl_ioctl.h
  stable/10/sys/dev/iscsi/icl.h
  stable/10/sys/dev/iscsi/icl_proxy.c
  stable/10/usr.sbin/ctld/ctld.c
  stable/10/usr.sbin/ctld/ctld.h
  stable/10/usr.sbin/ctld/kernel.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c
==============================================================================
--- stable/10/sys/cam/ctl/ctl_frontend_iscsi.c  Wed May  7 07:36:46 2014        
(r265512)
+++ stable/10/sys/cam/ctl/ctl_frontend_iscsi.c  Wed May  7 07:37:55 2014        
(r265513)
@@ -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: stable/10/sys/cam/ctl/ctl_frontend_iscsi.h
==============================================================================
--- stable/10/sys/cam/ctl/ctl_frontend_iscsi.h  Wed May  7 07:36:46 2014        
(r265512)
+++ stable/10/sys/cam/ctl/ctl_frontend_iscsi.h  Wed May  7 07:37:55 2014        
(r265513)
@@ -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: stable/10/sys/cam/ctl/ctl_ioctl.h
==============================================================================
--- stable/10/sys/cam/ctl/ctl_ioctl.h   Wed May  7 07:36:46 2014        
(r265512)
+++ stable/10/sys/cam/ctl/ctl_ioctl.h   Wed May  7 07:37:55 2014        
(r265513)
@@ -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: stable/10/sys/dev/iscsi/icl.h
==============================================================================
--- stable/10/sys/dev/iscsi/icl.h       Wed May  7 07:36:46 2014        
(r265512)
+++ stable/10/sys/dev/iscsi/icl.h       Wed May  7 07:37:55 2014        
(r265513)
@@ -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: stable/10/sys/dev/iscsi/icl_proxy.c
==============================================================================
--- stable/10/sys/dev/iscsi/icl_proxy.c Wed May  7 07:36:46 2014        
(r265512)
+++ stable/10/sys/dev/iscsi/icl_proxy.c Wed May  7 07:37:55 2014        
(r265513)
@@ -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: stable/10/usr.sbin/ctld/ctld.c
==============================================================================
--- stable/10/usr.sbin/ctld/ctld.c      Wed May  7 07:36:46 2014        
(r265512)
+++ stable/10/usr.sbin/ctld/ctld.c      Wed May  7 07:37:55 2014        
(r265513)
@@ -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: stable/10/usr.sbin/ctld/ctld.h
==============================================================================
--- stable/10/usr.sbin/ctld/ctld.h      Wed May  7 07:36:46 2014        
(r265512)
+++ stable/10/usr.sbin/ctld/ctld.h      Wed May  7 07:37:55 2014        
(r265513)
@@ -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: stable/10/usr.sbin/ctld/kernel.c
==============================================================================
--- stable/10/usr.sbin/ctld/kernel.c    Wed May  7 07:36:46 2014        
(r265512)
+++ stable/10/usr.sbin/ctld/kernel.c    Wed May  7 07:37:55 2014        
(r265513)
@@ -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
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to