From 3d383c1c35b28638e9df5f60c20f4680c79d4fd6 Mon Sep 17 00:00:00 2001 From: Pascal Bach Date: Thu, 9 Jul 2015 13:37:56 +0200 Subject: [PATCH] [mod_proxy] add unix domain socket support If the server is set to a path like value, starting with "/" mod_proxy will try to establish a connection via unix domain socket. Signed-off-by: Pascal Bach --- src/mod_proxy.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/mod_proxy.c b/src/mod_proxy.c index 7821072..5b9a40f 100644 --- a/src/mod_proxy.c +++ b/src/mod_proxy.c @@ -361,6 +361,9 @@ static void proxy_connection_close(server *srv, handler_ctx *hctx) { static int proxy_establish_connection(server *srv, handler_ctx *hctx) { struct sockaddr *proxy_addr; struct sockaddr_in proxy_addr_in; +#ifdef HAVE_SYS_UN_H + struct sockaddr_un proxy_addr_un; +#endif #if defined(HAVE_IPV6) && defined(HAVE_INET_PTON) struct sockaddr_in6 proxy_addr_in6; #endif @@ -371,6 +374,15 @@ static int proxy_establish_connection(server *srv, handler_ctx *hctx) { int proxy_fd = hctx->fd; +#ifdef HAVE_SYS_UN_H + if (strstr(host->host->ptr, "/")) { + memset(&proxy_addr_un, 0, sizeof(proxy_addr_un)); + proxy_addr_un.sun_family = AF_UNIX; + strcpy(proxy_addr_un.sun_path, host->host->ptr); + servlen = sizeof(proxy_addr_un); + proxy_addr = (struct sockaddr *) &proxy_addr_un; + } else +#endif #if defined(HAVE_IPV6) && defined(HAVE_INET_PTON) if (strstr(host->host->ptr, ":")) { memset(&proxy_addr_in6, 0, sizeof(proxy_addr_in6)); @@ -716,6 +728,14 @@ static handler_t proxy_write_request(server *srv, handler_ctx *hctx) { break; case PROXY_STATE_INIT: +#ifdef HAVE_SYS_UN_H + if (strstr(host->host->ptr,"/")) { + if (-1 == (hctx->fd = socket(AF_UNIX, SOCK_STREAM, 0))) { + log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed: ", strerror(errno)); + return HANDLER_ERROR; + } + } else +#endif #if defined(HAVE_IPV6) && defined(HAVE_INET_PTON) if (strstr(host->host->ptr,":")) { if (-1 == (hctx->fd = socket(AF_INET6, SOCK_STREAM, 0))) { -- 1.9.1