diff options
author | trasz <trasz@FreeBSD.org> | 2014-05-07 07:37:55 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2014-05-07 07:37:55 +0000 |
commit | 21ec0cf2d04e4aa633946733cbc2771bb4ceb398 (patch) | |
tree | 58555ca5911d866052e6587412bcb42076b5e484 /usr.sbin/ctld | |
parent | a59839947cb5d7096df809172f3a5d5085bf9b8a (diff) | |
download | FreeBSD-src-21ec0cf2d04e4aa633946733cbc2771bb4ceb398.zip FreeBSD-src-21ec0cf2d04e4aa633946733cbc2771bb4ceb398.tar.gz |
MFC r264530:
Properly pass the initiator address when running in proxy mode.
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'usr.sbin/ctld')
-rw-r--r-- | usr.sbin/ctld/ctld.c | 45 | ||||
-rw-r--r-- | usr.sbin/ctld/ctld.h | 13 | ||||
-rw-r--r-- | usr.sbin/ctld/kernel.c | 7 |
3 files changed, 34 insertions, 31 deletions
diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index 2e4a3e6..cb49da2 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -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)); - - 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_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 @@ 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; } } diff --git a/usr.sbin/ctld/ctld.h b/usr.sbin/ctld/ctld.h index fe5abfe..b75d5d1 100644 --- a/usr.sbin/ctld/ctld.h +++ b/usr.sbin/ctld/ctld.h @@ -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); diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c index 6907868..ad83679 100644 --- a/usr.sbin/ctld/kernel.c +++ b/usr.sbin/ctld/kernel.c @@ -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 |