You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2013/03/01 17:21:50 UTC
svn commit: r1451633 - in /httpd/httpd/trunk: include/ap_mmn.h
modules/proxy/mod_proxy.h modules/proxy/proxy_util.c
Author: jim
Date: Fri Mar 1 16:21:49 2013
New Revision: 1451633
URL: http://svn.apache.org/r1451633
Log:
Add in rough uds support (Bugx 54101) from Blaise Tarr <bl...@gmail.com>
Modified:
httpd/httpd/trunk/include/ap_mmn.h
httpd/httpd/trunk/modules/proxy/mod_proxy.h
httpd/httpd/trunk/modules/proxy/proxy_util.c
Modified: httpd/httpd/trunk/include/ap_mmn.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_mmn.h?rev=1451633&r1=1451632&r2=1451633&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_mmn.h (original)
+++ httpd/httpd/trunk/include/ap_mmn.h Fri Mar 1 16:21:49 2013
@@ -414,6 +414,7 @@
* add ap_has_cntrl()
* 20121222.2 (2.5.0-dev) Add ap_password_validate()
* 20121222.3 (2.5.0-dev) Add ppinherit to proxy_server_conf
+ * 20121222.4 (2.5.0-dev) Add uds_path to proxy_conn_rec
*/
#define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.h?rev=1451633&r1=1451632&r2=1451633&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.h (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.h Fri Mar 1 16:21:49 2013
@@ -236,6 +236,7 @@ typedef struct {
* that is used over the backend connection. */
proxy_worker *worker; /* Connection pool this connection belongs to */
apr_pool_t *pool; /* Subpool for hostname and addr data */
+ const char *uds_path; /* Unix domain socket path */
const char *hostname;
apr_sockaddr_t *addr; /* Preparsed remote address info */
apr_pool_t *scpool; /* Subpool used for socket and connection data */
Modified: httpd/httpd/trunk/modules/proxy/proxy_util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c?rev=1451633&r1=1451632&r2=1451633&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/proxy_util.c (original)
+++ httpd/httpd/trunk/modules/proxy/proxy_util.c Fri Mar 1 16:21:49 2013
@@ -31,6 +31,11 @@
#define apr_socket_create apr_socket_create_ex
#endif
+#if APR_HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#include "apr_support.h" /* for apr_wait_for_io_or_timeout() */
+
APLOG_USE_MODULE(proxy);
/*
@@ -2008,6 +2013,7 @@ PROXY_DECLARE(int) ap_proxy_acquire_conn
(*conn)->worker = worker;
(*conn)->close = 0;
(*conn)->inreslist = 0;
+ (*conn)->uds_path = NULL;
return OK;
}
@@ -2024,6 +2030,30 @@ PROXY_DECLARE(int) ap_proxy_release_conn
return OK;
}
+/*
+ * Decodes a '%' escaped string, and returns the number of characters
+ */
+static int decodeenc(char *x)
+{
+ int i, j, ch;
+
+ if (x[0] == '\0') {
+ /* special case for no characters */
+ return 0;
+ }
+ for (i = 0, j = 0; x[i] != '\0'; i++, j++) {
+ /* decode it if not already done */
+ ch = x[i];
+ if (ch == '%' && apr_isxdigit(x[i + 1]) && apr_isxdigit(x[i + 2])) {
+ ch = ap_proxy_hex2c(&x[i + 1]);
+ i += 2;
+ }
+ x[j] = ch;
+ }
+ x[j] = '\0';
+ return j;
+}
+
PROXY_DECLARE(int)
ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
proxy_server_conf *conf,
@@ -2118,10 +2148,17 @@ ap_proxy_determine_connection(apr_pool_t
conn->port = uri->port;
}
socket_cleanup(conn);
- err = apr_sockaddr_info_get(&(conn->addr),
- conn->hostname, APR_UNSPEC,
- conn->port, 0,
- conn->pool);
+ if (strncmp(conn->hostname, "socket=", 7) == 0) {
+ char *uds_path = apr_pstrdup(conn->pool, conn->hostname + 7);
+ decodeenc(uds_path);
+ conn->uds_path = uds_path;
+ }
+ else {
+ err = apr_sockaddr_info_get(&(conn->addr),
+ conn->hostname, APR_UNSPEC,
+ conn->port, 0,
+ conn->pool);
+ }
}
else if (!worker->cp->addr) {
if ((err = PROXY_THREAD_LOCK(worker)) != APR_SUCCESS) {
@@ -2346,6 +2383,50 @@ static apr_status_t send_http_connect(pr
}
+/* lifted from mod_proxy_fdpass.c; tweaked addrlen in connect() call */
+static apr_status_t socket_connect_un(apr_socket_t *sock,
+ struct sockaddr_un *sa)
+{
+ apr_status_t rv;
+ apr_os_sock_t rawsock;
+ apr_interval_time_t t;
+
+ rv = apr_os_sock_get(&rawsock, sock);
+ if (rv != APR_SUCCESS) {
+ return rv;
+ }
+
+ rv = apr_socket_timeout_get(sock, &t);
+ if (rv != APR_SUCCESS) {
+ return rv;
+ }
+
+ do {
+ const socklen_t addrlen = APR_OFFSETOF(struct sockaddr_un, sun_path)
+ + strlen(sa->sun_path) + 1;
+ rv = connect(rawsock, (struct sockaddr*)sa, addrlen);
+ } while (rv == -1 && errno == EINTR);
+
+ if ((rv == -1) && (errno == EINPROGRESS || errno == EALREADY)
+ && (t > 0)) {
+#if APR_MAJOR_VERSION < 2
+ rv = apr_wait_for_io_or_timeout(NULL, sock, 0);
+#else
+ rv = apr_socket_wait(sock, APR_WAIT_WRITE);
+#endif
+
+ if (rv != APR_SUCCESS) {
+ return rv;
+ }
+ }
+
+ if (rv == -1 && errno != EISCONN) {
+ return errno;
+ }
+
+ return APR_SUCCESS;
+}
+
PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
proxy_conn_rec *conn,
proxy_worker *worker,
@@ -2370,93 +2451,127 @@ PROXY_DECLARE(int) ap_proxy_connect_back
proxy_function);
}
}
- while (backend_addr && !connected) {
- if ((rv = apr_socket_create(&newsock, backend_addr->family,
- SOCK_STREAM, APR_PROTO_TCP,
- conn->scpool)) != APR_SUCCESS) {
- loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
- ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00952)
- "%s: error creating fam %d socket for target %s",
- proxy_function,
- backend_addr->family,
- worker->s->hostname);
- /*
- * this could be an IPv6 address from the DNS but the
- * local machine won't give us an IPv6 socket; hopefully the
- * DNS returned an additional address to try
- */
- backend_addr = backend_addr->next;
- continue;
- }
- conn->connection = NULL;
+ while ((backend_addr || conn->uds_path) && !connected) {
+ if (conn->uds_path) {
+ struct sockaddr_un sa;
- if (worker->s->recv_buffer_size > 0 &&
- (rv = apr_socket_opt_set(newsock, APR_SO_RCVBUF,
- worker->s->recv_buffer_size))) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00953)
- "apr_socket_opt_set(SO_RCVBUF): Failed to set "
- "ProxyReceiveBufferSize, using default");
- }
+ rv = apr_socket_create(&newsock, AF_UNIX, SOCK_STREAM, 0,
+ conn->scpool);
+ if (rv != APR_SUCCESS) {
+ loglevel = APLOG_ERR;
+ ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO()
+ "%s: error creating Unix domain socket for "
+ "target %s",
+ proxy_function,
+ worker->s->hostname);
+ break;
+ }
+ conn->connection = NULL;
- rv = apr_socket_opt_set(newsock, APR_TCP_NODELAY, 1);
- if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00954)
- "apr_socket_opt_set(APR_TCP_NODELAY): "
- "Failed to set");
- }
+ sa.sun_family = AF_UNIX;
+ apr_cpystrn(sa.sun_path, conn->uds_path, sizeof(sa.sun_path));
- /* Set a timeout for connecting to the backend on the socket */
- if (worker->s->conn_timeout_set) {
- apr_socket_timeout_set(newsock, worker->s->conn_timeout);
- }
- else if (worker->s->timeout_set) {
- apr_socket_timeout_set(newsock, worker->s->timeout);
- }
- else if (conf->timeout_set) {
- apr_socket_timeout_set(newsock, conf->timeout);
- }
- else {
- apr_socket_timeout_set(newsock, s->timeout);
- }
- /* Set a keepalive option */
- if (worker->s->keepalive) {
- if ((rv = apr_socket_opt_set(newsock,
- APR_SO_KEEPALIVE, 1)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00955)
- "apr_socket_opt_set(SO_KEEPALIVE): Failed to set"
- " Keepalive");
- }
- }
- ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, s,
- "%s: fam %d socket created to connect to %s",
- proxy_function, backend_addr->family, worker->s->hostname);
-
- if (conf->source_address_set) {
- local_addr = apr_pmemdup(conn->pool, conf->source_address,
- sizeof(apr_sockaddr_t));
- local_addr->pool = conn->pool;
- rv = apr_socket_bind(newsock, local_addr);
+ rv = socket_connect_un(newsock, &sa);
if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00956)
- "%s: failed to bind socket to local address",
- proxy_function);
+ apr_socket_close(newsock);
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO()
+ "%s: attempt to connect to Unix domain socket "
+ "%s (%s) failed",
+ proxy_function,
+ conn->uds_path,
+ worker->s->hostname);
+ break;
}
}
+ else {
+ if ((rv = apr_socket_create(&newsock, backend_addr->family,
+ SOCK_STREAM, APR_PROTO_TCP,
+ conn->scpool)) != APR_SUCCESS) {
+ loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
+ ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00952)
+ "%s: error creating fam %d socket for "
+ "target %s",
+ proxy_function,
+ backend_addr->family,
+ worker->s->hostname);
+ /*
+ * this could be an IPv6 address from the DNS but the
+ * local machine won't give us an IPv6 socket; hopefully the
+ * DNS returned an additional address to try
+ */
+ backend_addr = backend_addr->next;
+ continue;
+ }
+ conn->connection = NULL;
- /* make the connection out of the socket */
- rv = apr_socket_connect(newsock, backend_addr);
+ if (worker->s->recv_buffer_size > 0 &&
+ (rv = apr_socket_opt_set(newsock, APR_SO_RCVBUF,
+ worker->s->recv_buffer_size))) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00953)
+ "apr_socket_opt_set(SO_RCVBUF): Failed to set "
+ "ProxyReceiveBufferSize, using default");
+ }
- /* if an error occurred, loop round and try again */
- if (rv != APR_SUCCESS) {
- apr_socket_close(newsock);
- loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
- ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00957)
- "%s: attempt to connect to %pI (%s) failed",
- proxy_function,
- backend_addr,
- worker->s->hostname);
- backend_addr = backend_addr->next;
- continue;
+ rv = apr_socket_opt_set(newsock, APR_TCP_NODELAY, 1);
+ if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00954)
+ "apr_socket_opt_set(APR_TCP_NODELAY): "
+ "Failed to set");
+ }
+
+ /* Set a timeout for connecting to the backend on the socket */
+ if (worker->s->conn_timeout_set) {
+ apr_socket_timeout_set(newsock, worker->s->conn_timeout);
+ }
+ else if (worker->s->timeout_set) {
+ apr_socket_timeout_set(newsock, worker->s->timeout);
+ }
+ else if (conf->timeout_set) {
+ apr_socket_timeout_set(newsock, conf->timeout);
+ }
+ else {
+ apr_socket_timeout_set(newsock, s->timeout);
+ }
+ /* Set a keepalive option */
+ if (worker->s->keepalive) {
+ if ((rv = apr_socket_opt_set(newsock,
+ APR_SO_KEEPALIVE, 1)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00955)
+ "apr_socket_opt_set(SO_KEEPALIVE): Failed to set"
+ " Keepalive");
+ }
+ }
+ ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, s,
+ "%s: fam %d socket created to connect to %s",
+ proxy_function, backend_addr->family, worker->s->hostname);
+
+ if (conf->source_address_set) {
+ local_addr = apr_pmemdup(conn->pool, conf->source_address,
+ sizeof(apr_sockaddr_t));
+ local_addr->pool = conn->pool;
+ rv = apr_socket_bind(newsock, local_addr);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00956)
+ "%s: failed to bind socket to local address",
+ proxy_function);
+ }
+ }
+
+ /* make the connection out of the socket */
+ rv = apr_socket_connect(newsock, backend_addr);
+
+ /* if an error occurred, loop round and try again */
+ if (rv != APR_SUCCESS) {
+ apr_socket_close(newsock);
+ loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
+ ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00957)
+ "%s: attempt to connect to %pI (%s) failed",
+ proxy_function,
+ backend_addr,
+ worker->s->hostname);
+ backend_addr = backend_addr->next;
+ continue;
+ }
}
/* Set a timeout on the socket */
@@ -2472,7 +2587,7 @@ PROXY_DECLARE(int) ap_proxy_connect_back
conn->sock = newsock;
- if (conn->forward) {
+ if (!conn->uds_path && conn->forward) {
forward_info *forward = (forward_info *)conn->forward;
/*
* For HTTP CONNECT we need to prepend CONNECT request before
Re: svn commit: r1451633 - in /httpd/httpd/trunk: include/ap_mmn.h modules/proxy/mod_proxy.h modules/proxy/proxy_util.c
Posted by Jim Jagielski <ji...@jaguNET.com>.
Hopefully r1451905 addressed this, but not having a test
platform, I'm only guessing...
On Mar 2, 2013, at 9:12 AM, Jim Jagielski <ji...@jaguNET.com> wrote:
> Is there any way you could add the #ifdef stuff? Since I lack
> a Windows and/or NetWare system, it would be better, I think,
> if someone who did actually fixed this instead of us simply
> removing it, and the person who fixed it was able to test
> the fix :)
>
> Thx!
>
> On Mar 1, 2013, at 9:10 PM, Guenter Knauf <fu...@apache.org> wrote:
>
>> Hi Jim,
>> Am 01.03.2013 17:21, schrieb jim@apache.org:
>>> Author: jim
>>> Date: Fri Mar 1 16:21:49 2013
>>> New Revision: 1451633
>>>
>>> URL: http://svn.apache.org/r1451633
>>> Log:
>>> Add in rough uds support (Bugx 54101) from Blaise Tarr<bl...@gmail.com>
>>>
>>> Modified:
>>> httpd/httpd/trunk/include/ap_mmn.h
>>> httpd/httpd/trunk/modules/proxy/mod_proxy.h
>>> httpd/httpd/trunk/modules/proxy/proxy_util.c
>> please revert this - it breaks winsock platforms which lack support for unix sockets and sockaddr_un (Windows as well as NetWare when build with winsock).
>> If we need this then we must either move that stuff into a separate unix-only file or ifdef everything related to unix sockets with "#if APR_HAVE_SYS_UN_H" ...
>>
>> Gün.
>>
>>
>>
>
Re: svn commit: r1451633 - in /httpd/httpd/trunk: include/ap_mmn.h
modules/proxy/mod_proxy.h modules/proxy/proxy_util.c
Posted by "Gregg Smith (gsmith)" <gl...@gknw.net>.
On 3/2/2013 11:21 AM, Guenter Knauf wrote:
> Am 02.03.2013 15:12, schrieb Jim Jagielski:
>> Is there any way you could add the #ifdef stuff? Since I lack
>> a Windows and/or NetWare system, it would be better, I think,
>> if someone who did actually fixed this instead of us simply
>> removing it, and the person who fixed it was able to test
>> the fix :)
> sure ...
> 1st it breaks here:
>
> CC proxy_util.c
> ### mwccnlm Compiler:
> # File: proxy_util.c
> # ---------------------
> # 2405: const socklen_t addrlen = APR_OFFSETOF(struct
> sockaddr_un, sun_path)
> # Error: ^^^^^^^
> # ';' expected
> # Too many errors printed, aborting program
>
> this is because it should be apr_socklen_t; but when I fix this then
> next is with the struct sockaddr_un ...
>
> I've just ifdef'd this problemaric function which makes proxy_util.c
> compile again for NetWare; lets see what Gregg says for Windows ...
> http://svn.apache.org/r1451921
Compiles fine on Windows
Re: svn commit: r1451633 - in /httpd/httpd/trunk: include/ap_mmn.h
modules/proxy/mod_proxy.h modules/proxy/proxy_util.c
Posted by Guenter Knauf <fu...@apache.org>.
Am 02.03.2013 15:12, schrieb Jim Jagielski:
> Is there any way you could add the #ifdef stuff? Since I lack
> a Windows and/or NetWare system, it would be better, I think,
> if someone who did actually fixed this instead of us simply
> removing it, and the person who fixed it was able to test
> the fix :)
sure ...
1st it breaks here:
CC proxy_util.c
### mwccnlm Compiler:
# File: proxy_util.c
# ---------------------
# 2405: const socklen_t addrlen = APR_OFFSETOF(struct
sockaddr_un, sun_path)
# Error: ^^^^^^^
# ';' expected
# Too many errors printed, aborting program
this is because it should be apr_socklen_t; but when I fix this then
next is with the struct sockaddr_un ...
I've just ifdef'd this problemaric function which makes proxy_util.c
compile again for NetWare; lets see what Gregg says for Windows ...
http://svn.apache.org/r1451921
Gün.
Re: svn commit: r1451633 - in /httpd/httpd/trunk: include/ap_mmn.h modules/proxy/mod_proxy.h modules/proxy/proxy_util.c
Posted by Jim Jagielski <ji...@jaguNET.com>.
Is there any way you could add the #ifdef stuff? Since I lack
a Windows and/or NetWare system, it would be better, I think,
if someone who did actually fixed this instead of us simply
removing it, and the person who fixed it was able to test
the fix :)
Thx!
On Mar 1, 2013, at 9:10 PM, Guenter Knauf <fu...@apache.org> wrote:
> Hi Jim,
> Am 01.03.2013 17:21, schrieb jim@apache.org:
>> Author: jim
>> Date: Fri Mar 1 16:21:49 2013
>> New Revision: 1451633
>>
>> URL: http://svn.apache.org/r1451633
>> Log:
>> Add in rough uds support (Bugx 54101) from Blaise Tarr<bl...@gmail.com>
>>
>> Modified:
>> httpd/httpd/trunk/include/ap_mmn.h
>> httpd/httpd/trunk/modules/proxy/mod_proxy.h
>> httpd/httpd/trunk/modules/proxy/proxy_util.c
> please revert this - it breaks winsock platforms which lack support for unix sockets and sockaddr_un (Windows as well as NetWare when build with winsock).
> If we need this then we must either move that stuff into a separate unix-only file or ifdef everything related to unix sockets with "#if APR_HAVE_SYS_UN_H" ...
>
> Gün.
>
>
>
Re: svn commit: r1451633 - in /httpd/httpd/trunk: include/ap_mmn.h
modules/proxy/mod_proxy.h modules/proxy/proxy_util.c
Posted by Guenter Knauf <fu...@apache.org>.
Hi Jim,
Am 01.03.2013 17:21, schrieb jim@apache.org:
> Author: jim
> Date: Fri Mar 1 16:21:49 2013
> New Revision: 1451633
>
> URL: http://svn.apache.org/r1451633
> Log:
> Add in rough uds support (Bugx 54101) from Blaise Tarr<bl...@gmail.com>
>
> Modified:
> httpd/httpd/trunk/include/ap_mmn.h
> httpd/httpd/trunk/modules/proxy/mod_proxy.h
> httpd/httpd/trunk/modules/proxy/proxy_util.c
please revert this - it breaks winsock platforms which lack support for
unix sockets and sockaddr_un (Windows as well as NetWare when build with
winsock).
If we need this then we must either move that stuff into a separate
unix-only file or ifdef everything related to unix sockets with "#if
APR_HAVE_SYS_UN_H" ...
Gün.
Re: svn commit: r1451633 - in /httpd/httpd/trunk: include/ap_mmn.h
modules/proxy/mod_proxy.h modules/proxy/proxy_util.c
Posted by Christophe JAILLET <ch...@wanadoo.fr>.
Le 01/03/2013 17:21, jim@apache.org a écrit :
> Author: jim
> Date: Fri Mar 1 16:21:49 2013
> New Revision: 1451633
>
> URL: http://svn.apache.org/r1451633
> Log:
> Add in rough uds support (Bugx 54101) from Blaise Tarr <bl...@gmail.com>
>
> Modified:
> httpd/httpd/trunk/include/ap_mmn.h
> httpd/httpd/trunk/modules/proxy/mod_proxy.h
> httpd/httpd/trunk/modules/proxy/proxy_util.c
>
> Modified: httpd/httpd/trunk/modules/proxy/proxy_util.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c?rev=1451633&r1=1451632&r2=1451633&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/proxy/proxy_util.c (original)
> +++ httpd/httpd/trunk/modules/proxy/proxy_util.c Fri Mar 1 16:21:49 2013
> @@ -31,6 +31,11 @@
> #define apr_socket_create apr_socket_create_ex
> #endif
>
> +#if APR_HAVE_SYS_UN_H
> +#include <sys/un.h>
> +#endif
> +#include "apr_support.h" /* for apr_wait_for_io_or_timeout() */
> +
> APLOG_USE_MODULE(proxy);
This break build with APR trunk with :
proxy_util.c:37:71: fatal error: apr_support.h: No such file or
directory
because, on APR trunk, apr_support.h is in "include/private"
Not an issue for now, one should not use APR trunk for building, but
could become one in the future.
Best regards,
CJ