diff options
author | trasz <trasz@FreeBSD.org> | 2014-05-07 07:36:46 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2014-05-07 07:36:46 +0000 |
commit | a59839947cb5d7096df809172f3a5d5085bf9b8a (patch) | |
tree | 73b2e86069d7903f82eba8a4d98d92798a49ff2b | |
parent | 04b1f4adf57fd2b112a952d43ae4f981d90d30f3 (diff) | |
download | FreeBSD-src-a59839947cb5d7096df809172f3a5d5085bf9b8a.zip FreeBSD-src-a59839947cb5d7096df809172f3a5d5085bf9b8a.tar.gz |
MFC r264529:
Use socket address from accept(2) instead of retrieving it via
getpeername(2).
Sponsored by: The FreeBSD Foundation
-rw-r--r-- | usr.sbin/ctld/ctld.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index a8b1f6b..2e4a3e6 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -1588,11 +1588,10 @@ wait_for_children(bool block) } static void -handle_connection(struct portal *portal, int fd, bool dont_fork) +handle_connection(struct portal *portal, int fd, const struct sockaddr_storage *ss, + socklen_t sslen, bool dont_fork) { struct connection *conn; - struct sockaddr_storage ss; - socklen_t sslen = sizeof(ss); int error; pid_t pid; char host[NI_MAXHOST + 1]; @@ -1634,13 +1633,10 @@ handle_connection(struct portal *portal, int fd, bool dont_fork) } else { #endif assert(proxy_mode == false); - error = getpeername(fd, (struct sockaddr *)&ss, &sslen); - if (error != 0) - log_err(1, "getpeername"); - error = getnameinfo((struct sockaddr *)&ss, sslen, + error = getnameinfo((struct sockaddr *)ss, sslen, host, sizeof(host), NULL, 0, NI_NUMERICHOST); if (error != 0) - log_errx(1, "getaddrinfo: %s", gai_strerror(error)); + log_errx(1, "getnameinfo: %s", gai_strerror(error)); log_debugx("accepted connection from %s; portal group \"%s\"", host, portal->p_portal_group->pg_name); @@ -1686,6 +1682,8 @@ main_loop(struct conf *conf, bool dont_fork) { struct portal_group *pg; struct portal *portal; + struct sockaddr_storage client_sa; + socklen_t client_salen; #ifdef ICL_KERNEL_PROXY int connection_id; int portal_id; @@ -1717,7 +1715,7 @@ main_loop(struct conf *conf, bool dont_fork) portal_id); found: - handle_connection(portal, connection_id, dont_fork); + handle_connection(portal, connection_id, NULL, 0, dont_fork); } else { #endif assert(proxy_mode == false); @@ -1738,10 +1736,14 @@ found: TAILQ_FOREACH(portal, &pg->pg_portals, p_next) { if (!FD_ISSET(portal->p_socket, &fdset)) continue; - client_fd = accept(portal->p_socket, NULL, 0); + client_salen = sizeof(client_sa); + client_fd = accept(portal->p_socket, + (struct sockaddr *)&client_sa, + &client_salen); if (client_fd < 0) log_err(1, "accept"); - handle_connection(portal, client_fd, dont_fork); + handle_connection(portal, client_fd, + &client_sa, client_salen, dont_fork); break; } } |