Lines 31-36
Link Here
|
31 |
#define apr_socket_create apr_socket_create_ex |
31 |
#define apr_socket_create apr_socket_create_ex |
32 |
#endif |
32 |
#endif |
33 |
|
33 |
|
|
|
34 |
#if APR_HAVE_SYS_UN_H |
35 |
#include <sys/un.h> |
36 |
#endif |
37 |
#if (APR_MAJOR_VERSION < 2) |
38 |
#include "apr_support.h" /* for apr_wait_for_io_or_timeout() */ |
39 |
#endif |
40 |
|
34 |
APLOG_USE_MODULE(proxy); |
41 |
APLOG_USE_MODULE(proxy); |
35 |
|
42 |
|
36 |
/* |
43 |
/* |
Lines 86-99
PROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char
Link Here
|
86 |
char *thenil; |
93 |
char *thenil; |
87 |
apr_size_t thelen; |
94 |
apr_size_t thelen; |
88 |
|
95 |
|
|
|
96 |
/* special case handling */ |
97 |
if (!dlen) { |
98 |
/* XXX: APR_ENOSPACE would be better */ |
99 |
return APR_EGENERAL; |
100 |
} |
101 |
if (!src) { |
102 |
*dst = '\0'; |
103 |
return APR_SUCCESS; |
104 |
} |
89 |
thenil = apr_cpystrn(dst, src, dlen); |
105 |
thenil = apr_cpystrn(dst, src, dlen); |
90 |
thelen = thenil - dst; |
106 |
thelen = thenil - dst; |
91 |
/* Assume the typical case is smaller copying into bigger |
107 |
if (src[thelen] == '\0') { |
92 |
so we have a fast return */ |
|
|
93 |
if ((thelen < dlen-1) || ((strlen(src)) == thelen)) { |
94 |
return APR_SUCCESS; |
108 |
return APR_SUCCESS; |
95 |
} |
109 |
} |
96 |
/* XXX: APR_ENOSPACE would be better */ |
|
|
97 |
return APR_EGENERAL; |
110 |
return APR_EGENERAL; |
98 |
} |
111 |
} |
99 |
|
112 |
|
Lines 1218-1228
PROXY_DECLARE(apr_status_t) ap_proxy_share_balance
Link Here
|
1218 |
} else { |
1231 |
} else { |
1219 |
action = "re-using"; |
1232 |
action = "re-using"; |
1220 |
} |
1233 |
} |
|
|
1234 |
balancer->s = shm; |
1235 |
balancer->s->index = i; |
1221 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02337) |
1236 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02337) |
1222 |
"%s shm[%d] (0x%pp) for %s", action, i, (void *)shm, |
1237 |
"%s shm[%d] (0x%pp) for %s", action, i, (void *)shm, |
1223 |
balancer->s->name); |
1238 |
balancer->s->name); |
1224 |
balancer->s = shm; |
|
|
1225 |
balancer->s->index = i; |
1226 |
/* the below should always succeed */ |
1239 |
/* the below should always succeed */ |
1227 |
lbmethod = ap_lookup_provider(PROXY_LBMETHOD, balancer->s->lbpname, "0"); |
1240 |
lbmethod = ap_lookup_provider(PROXY_LBMETHOD, balancer->s->lbpname, "0"); |
1228 |
if (lbmethod) { |
1241 |
if (lbmethod) { |
Lines 1356-1362
static apr_status_t connection_cleanup(void *theco
Link Here
|
1356 |
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, conn->pool, APLOGNO(00923) |
1369 |
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, conn->pool, APLOGNO(00923) |
1357 |
"Pooled connection 0x%pp for worker %s has been" |
1370 |
"Pooled connection 0x%pp for worker %s has been" |
1358 |
" already returned to the connection pool.", conn, |
1371 |
" already returned to the connection pool.", conn, |
1359 |
worker->s->name); |
1372 |
ap_proxy_worker_name(conn->pool, worker)); |
1360 |
return APR_SUCCESS; |
1373 |
return APR_SUCCESS; |
1361 |
} |
1374 |
} |
1362 |
|
1375 |
|
Lines 1480-1485
static apr_status_t connection_destructor(void *re
Link Here
|
1480 |
* WORKER related... |
1493 |
* WORKER related... |
1481 |
*/ |
1494 |
*/ |
1482 |
|
1495 |
|
|
|
1496 |
PROXY_DECLARE(char *) ap_proxy_worker_name(apr_pool_t *p, |
1497 |
proxy_worker *worker) |
1498 |
{ |
1499 |
if (!(*worker->s->uds_path) || !p) { |
1500 |
/* just in case */ |
1501 |
return worker->s->name; |
1502 |
} |
1503 |
return apr_pstrcat(p, "unix:", worker->s->uds_path, "|", worker->s->name, NULL); |
1504 |
} |
1505 |
|
1483 |
PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p, |
1506 |
PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p, |
1484 |
proxy_balancer *balancer, |
1507 |
proxy_balancer *balancer, |
1485 |
proxy_server_conf *conf, |
1508 |
proxy_server_conf *conf, |
Lines 1495-1500
PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(
Link Here
|
1495 |
char *url_copy; |
1518 |
char *url_copy; |
1496 |
int i; |
1519 |
int i; |
1497 |
|
1520 |
|
|
|
1521 |
if (!url) { |
1522 |
return NULL; |
1523 |
} |
1524 |
|
1498 |
c = ap_strchr_c(url, ':'); |
1525 |
c = ap_strchr_c(url, ':'); |
1499 |
if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') { |
1526 |
if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') { |
1500 |
return NULL; |
1527 |
return NULL; |
Lines 1573-1592
PROXY_DECLARE(char *) ap_proxy_define_worker(apr_p
Link Here
|
1573 |
int do_malloc) |
1600 |
int do_malloc) |
1574 |
{ |
1601 |
{ |
1575 |
int rv; |
1602 |
int rv; |
1576 |
apr_uri_t uri; |
1603 |
apr_uri_t uri, urisock; |
1577 |
proxy_worker_shared *wshared; |
1604 |
proxy_worker_shared *wshared; |
1578 |
char *ptr; |
1605 |
char *ptr, *sockpath = NULL; |
1579 |
|
1606 |
|
|
|
1607 |
/* |
1608 |
* Look to see if we are using UDS: |
1609 |
* require format: unix:/path/foo/bar.sock|http://ignored/path2/ |
1610 |
* This results in talking http to the socket at /path/foo/bar.sock |
1611 |
*/ |
1612 |
ptr = ap_strchr((char *)url, '|'); |
1613 |
if (ptr) { |
1614 |
*ptr = '\0'; |
1615 |
rv = apr_uri_parse(p, url, &urisock); |
1616 |
if (rv == APR_SUCCESS && !strcasecmp(urisock.scheme, "unix")) { |
1617 |
sockpath = ap_runtime_dir_relative(p, urisock.path);; |
1618 |
url = ptr+1; /* so we get the scheme for the uds */ |
1619 |
} |
1620 |
else { |
1621 |
*ptr = '|'; |
1622 |
} |
1623 |
} |
1580 |
rv = apr_uri_parse(p, url, &uri); |
1624 |
rv = apr_uri_parse(p, url, &uri); |
1581 |
|
1625 |
|
1582 |
if (rv != APR_SUCCESS) { |
1626 |
if (rv != APR_SUCCESS) { |
1583 |
return "Unable to parse URL"; |
1627 |
return apr_pstrcat(p, "Unable to parse URL: ", url, NULL); |
1584 |
} |
1628 |
} |
1585 |
if (!uri.hostname || !uri.scheme) { |
1629 |
if (!uri.scheme) { |
1586 |
return "URL must be absolute!"; |
1630 |
return apr_pstrcat(p, "URL must be absolute!: ", url, NULL); |
1587 |
} |
1631 |
} |
1588 |
|
1632 |
/* allow for unix:/path|http: */ |
1589 |
ap_str_tolower(uri.hostname); |
1633 |
if (!uri.hostname) { |
|
|
1634 |
if (sockpath) { |
1635 |
uri.hostname = "localhost"; |
1636 |
} |
1637 |
else { |
1638 |
return apr_pstrcat(p, "URL must be absolute!: ", url, NULL); |
1639 |
} |
1640 |
} |
1641 |
else { |
1642 |
ap_str_tolower(uri.hostname); |
1643 |
} |
1590 |
ap_str_tolower(uri.scheme); |
1644 |
ap_str_tolower(uri.scheme); |
1591 |
/* |
1645 |
/* |
1592 |
* Workers can be associated w/ balancers or on their |
1646 |
* Workers can be associated w/ balancers or on their |
Lines 1642-1648
PROXY_DECLARE(char *) ap_proxy_define_worker(apr_p
Link Here
|
1642 |
wshared->hash.def = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_DEFAULT); |
1696 |
wshared->hash.def = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_DEFAULT); |
1643 |
wshared->hash.fnv = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_FNV); |
1697 |
wshared->hash.fnv = ap_proxy_hashfunc(wshared->name, PROXY_HASHFUNC_FNV); |
1644 |
wshared->was_malloced = (do_malloc != 0); |
1698 |
wshared->was_malloced = (do_malloc != 0); |
|
|
1699 |
if (sockpath) { |
1700 |
if (PROXY_STRNCPY(wshared->uds_path, sockpath) != APR_SUCCESS) { |
1701 |
return apr_psprintf(p, "worker uds path (%s) too long", sockpath); |
1702 |
} |
1645 |
|
1703 |
|
|
|
1704 |
} |
1705 |
else { |
1706 |
*wshared->uds_path = '\0'; |
1707 |
} |
1708 |
|
1646 |
(*worker)->hash = wshared->hash; |
1709 |
(*worker)->hash = wshared->hash; |
1647 |
(*worker)->context = NULL; |
1710 |
(*worker)->context = NULL; |
1648 |
(*worker)->cp = NULL; |
1711 |
(*worker)->cp = NULL; |
Lines 1670-1681
PROXY_DECLARE(apr_status_t) ap_proxy_share_worker(
Link Here
|
1670 |
} else { |
1733 |
} else { |
1671 |
action = "re-using"; |
1734 |
action = "re-using"; |
1672 |
} |
1735 |
} |
1673 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02338) |
|
|
1674 |
"%s shm[%d] (0x%pp) for worker: %s", action, i, (void *)shm, |
1675 |
worker->s->name); |
1676 |
|
1677 |
worker->s = shm; |
1736 |
worker->s = shm; |
1678 |
worker->s->index = i; |
1737 |
worker->s->index = i; |
|
|
1738 |
{ |
1739 |
apr_pool_t *pool; |
1740 |
apr_pool_create(&pool, ap_server_conf->process->pool); |
1741 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02338) |
1742 |
"%s shm[%d] (0x%pp) for worker: %s", action, i, (void *)shm, |
1743 |
ap_proxy_worker_name(pool, worker)); |
1744 |
if (pool) { |
1745 |
apr_pool_destroy(pool); |
1746 |
} |
1747 |
} |
1679 |
return APR_SUCCESS; |
1748 |
return APR_SUCCESS; |
1680 |
} |
1749 |
} |
1681 |
|
1750 |
|
Lines 1687-1697
PROXY_DECLARE(apr_status_t) ap_proxy_initialize_wo
Link Here
|
1687 |
if (worker->s->status & PROXY_WORKER_INITIALIZED) { |
1756 |
if (worker->s->status & PROXY_WORKER_INITIALIZED) { |
1688 |
/* The worker is already initialized */ |
1757 |
/* The worker is already initialized */ |
1689 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00924) |
1758 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00924) |
1690 |
"worker %s shared already initialized", worker->s->name); |
1759 |
"worker %s shared already initialized", |
|
|
1760 |
ap_proxy_worker_name(p, worker)); |
1691 |
} |
1761 |
} |
1692 |
else { |
1762 |
else { |
1693 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00925) |
1763 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00925) |
1694 |
"initializing worker %s shared", worker->s->name); |
1764 |
"initializing worker %s shared", |
|
|
1765 |
ap_proxy_worker_name(p, worker)); |
1695 |
/* Set default parameters */ |
1766 |
/* Set default parameters */ |
1696 |
if (!worker->s->retry_set) { |
1767 |
if (!worker->s->retry_set) { |
1697 |
worker->s->retry = apr_time_from_sec(PROXY_WORKER_DEFAULT_RETRY); |
1768 |
worker->s->retry = apr_time_from_sec(PROXY_WORKER_DEFAULT_RETRY); |
Lines 1727-1737
PROXY_DECLARE(apr_status_t) ap_proxy_initialize_wo
Link Here
|
1727 |
/* What if local is init'ed and shm isn't?? Even possible? */ |
1798 |
/* What if local is init'ed and shm isn't?? Even possible? */ |
1728 |
if (worker->local_status & PROXY_WORKER_INITIALIZED) { |
1799 |
if (worker->local_status & PROXY_WORKER_INITIALIZED) { |
1729 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00926) |
1800 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00926) |
1730 |
"worker %s local already initialized", worker->s->name); |
1801 |
"worker %s local already initialized", |
|
|
1802 |
ap_proxy_worker_name(p, worker)); |
1731 |
} |
1803 |
} |
1732 |
else { |
1804 |
else { |
1733 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00927) |
1805 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00927) |
1734 |
"initializing worker %s local", worker->s->name); |
1806 |
"initializing worker %s local", |
|
|
1807 |
ap_proxy_worker_name(p, worker)); |
1735 |
apr_global_mutex_lock(proxy_mutex); |
1808 |
apr_global_mutex_lock(proxy_mutex); |
1736 |
/* Now init local worker data */ |
1809 |
/* Now init local worker data */ |
1737 |
if (worker->tmutex == NULL) { |
1810 |
if (worker->tmutex == NULL) { |
Lines 2023-2028
PROXY_DECLARE(int) ap_proxy_acquire_connection(con
Link Here
|
2023 |
(*conn)->close = 0; |
2096 |
(*conn)->close = 0; |
2024 |
(*conn)->inreslist = 0; |
2097 |
(*conn)->inreslist = 0; |
2025 |
|
2098 |
|
|
|
2099 |
if (*worker->s->uds_path) { |
2100 |
if ((*conn)->uds_path == NULL) { |
2101 |
/* use (*conn)->pool instead of worker->cp->pool to match lifetime */ |
2102 |
(*conn)->uds_path = apr_pstrdup((*conn)->pool, worker->s->uds_path); |
2103 |
} |
2104 |
if ((*conn)->uds_path) { |
2105 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02545) |
2106 |
"%s: has determined UDS as %s", |
2107 |
proxy_function, (*conn)->uds_path); |
2108 |
} |
2109 |
else { |
2110 |
/* should never happen */ |
2111 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02546) |
2112 |
"%s: cannot determine UDS (%s)", |
2113 |
proxy_function, worker->s->uds_path); |
2114 |
|
2115 |
} |
2116 |
} |
2117 |
else { |
2118 |
(*conn)->uds_path = NULL; |
2119 |
} |
2120 |
|
2121 |
|
2026 |
return OK; |
2122 |
return OK; |
2027 |
} |
2123 |
} |
2028 |
|
2124 |
|
Lines 2094-2100
ap_proxy_determine_connection(apr_pool_t *p, reque
Link Here
|
2094 |
* spilling the cached addr from the worker. |
2190 |
* spilling the cached addr from the worker. |
2095 |
*/ |
2191 |
*/ |
2096 |
if (!conn->hostname || !worker->s->is_address_reusable || |
2192 |
if (!conn->hostname || !worker->s->is_address_reusable || |
2097 |
worker->s->disablereuse) { |
2193 |
worker->s->disablereuse || *worker->s->uds_path) { |
2098 |
if (proxyname) { |
2194 |
if (proxyname) { |
2099 |
conn->hostname = apr_pstrdup(conn->pool, proxyname); |
2195 |
conn->hostname = apr_pstrdup(conn->pool, proxyname); |
2100 |
conn->port = proxyport; |
2196 |
conn->port = proxyport; |
Lines 2132-2138
ap_proxy_determine_connection(apr_pool_t *p, reque
Link Here
|
2132 |
conn->port = uri->port; |
2228 |
conn->port = uri->port; |
2133 |
} |
2229 |
} |
2134 |
socket_cleanup(conn); |
2230 |
socket_cleanup(conn); |
2135 |
if (!worker->s->is_address_reusable || worker->s->disablereuse) { |
2231 |
if (!(*worker->s->uds_path) && |
|
|
2232 |
(!worker->s->is_address_reusable || worker->s->disablereuse)) { |
2136 |
/* |
2233 |
/* |
2137 |
* Only do a lookup if we should not reuse the backend address. |
2234 |
* Only do a lookup if we should not reuse the backend address. |
2138 |
* Otherwise we will look it up once for the worker. |
2235 |
* Otherwise we will look it up once for the worker. |
Lines 2143-2149
ap_proxy_determine_connection(apr_pool_t *p, reque
Link Here
|
2143 |
conn->pool); |
2240 |
conn->pool); |
2144 |
} |
2241 |
} |
2145 |
} |
2242 |
} |
2146 |
if (worker->s->is_address_reusable && !worker->s->disablereuse) { |
2243 |
if (!(*worker->s->uds_path) && worker->s->is_address_reusable && !worker->s->disablereuse) { |
2147 |
/* |
2244 |
/* |
2148 |
* Looking up the backend address for the worker only makes sense if |
2245 |
* Looking up the backend address for the worker only makes sense if |
2149 |
* we can reuse the address. |
2246 |
* we can reuse the address. |
Lines 2372-2377
static apr_status_t send_http_connect(proxy_conn_r
Link Here
|
2372 |
} |
2469 |
} |
2373 |
|
2470 |
|
2374 |
|
2471 |
|
|
|
2472 |
#if APR_HAVE_SYS_UN_H |
2473 |
/* lifted from mod_proxy_fdpass.c; tweaked addrlen in connect() call */ |
2474 |
static apr_status_t socket_connect_un(apr_socket_t *sock, |
2475 |
struct sockaddr_un *sa) |
2476 |
{ |
2477 |
apr_status_t rv; |
2478 |
apr_os_sock_t rawsock; |
2479 |
apr_interval_time_t t; |
2480 |
|
2481 |
rv = apr_os_sock_get(&rawsock, sock); |
2482 |
if (rv != APR_SUCCESS) { |
2483 |
return rv; |
2484 |
} |
2485 |
|
2486 |
rv = apr_socket_timeout_get(sock, &t); |
2487 |
if (rv != APR_SUCCESS) { |
2488 |
return rv; |
2489 |
} |
2490 |
|
2491 |
do { |
2492 |
const socklen_t addrlen = APR_OFFSETOF(struct sockaddr_un, sun_path) |
2493 |
+ strlen(sa->sun_path) + 1; |
2494 |
rv = connect(rawsock, (struct sockaddr*)sa, addrlen); |
2495 |
} while (rv == -1 && errno == EINTR); |
2496 |
|
2497 |
if ((rv == -1) && (errno == EINPROGRESS || errno == EALREADY) |
2498 |
&& (t > 0)) { |
2499 |
#if APR_MAJOR_VERSION < 2 |
2500 |
rv = apr_wait_for_io_or_timeout(NULL, sock, 0); |
2501 |
#else |
2502 |
rv = apr_socket_wait(sock, APR_WAIT_WRITE); |
2503 |
#endif |
2504 |
|
2505 |
if (rv != APR_SUCCESS) { |
2506 |
return rv; |
2507 |
} |
2508 |
} |
2509 |
|
2510 |
if (rv == -1 && errno != EISCONN) { |
2511 |
return errno; |
2512 |
} |
2513 |
|
2514 |
return APR_SUCCESS; |
2515 |
} |
2516 |
#endif |
2517 |
|
2375 |
PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, |
2518 |
PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, |
2376 |
proxy_conn_rec *conn, |
2519 |
proxy_conn_rec *conn, |
2377 |
proxy_worker *worker, |
2520 |
proxy_worker *worker, |
Lines 2396-2488
PROXY_DECLARE(int) ap_proxy_connect_backend(const
Link Here
|
2396 |
proxy_function); |
2539 |
proxy_function); |
2397 |
} |
2540 |
} |
2398 |
} |
2541 |
} |
2399 |
while (backend_addr && !connected) { |
2542 |
while ((backend_addr || conn->uds_path) && !connected) { |
2400 |
if ((rv = apr_socket_create(&newsock, backend_addr->family, |
2543 |
#if APR_HAVE_SYS_UN_H |
2401 |
SOCK_STREAM, APR_PROTO_TCP, |
2544 |
if (conn->uds_path) |
2402 |
conn->scpool)) != APR_SUCCESS) { |
2545 |
{ |
2403 |
loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR; |
2546 |
struct sockaddr_un sa; |
2404 |
ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00952) |
|
|
2405 |
"%s: error creating fam %d socket for target %s", |
2406 |
proxy_function, |
2407 |
backend_addr->family, |
2408 |
worker->s->hostname); |
2409 |
/* |
2410 |
* this could be an IPv6 address from the DNS but the |
2411 |
* local machine won't give us an IPv6 socket; hopefully the |
2412 |
* DNS returned an additional address to try |
2413 |
*/ |
2414 |
backend_addr = backend_addr->next; |
2415 |
continue; |
2416 |
} |
2417 |
conn->connection = NULL; |
2418 |
|
2547 |
|
2419 |
if (worker->s->recv_buffer_size > 0 && |
2548 |
rv = apr_socket_create(&newsock, AF_UNIX, SOCK_STREAM, 0, |
2420 |
(rv = apr_socket_opt_set(newsock, APR_SO_RCVBUF, |
2549 |
conn->scpool); |
2421 |
worker->s->recv_buffer_size))) { |
2550 |
if (rv != APR_SUCCESS) { |
2422 |
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00953) |
2551 |
loglevel = APLOG_ERR; |
2423 |
"apr_socket_opt_set(SO_RCVBUF): Failed to set " |
2552 |
ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(02453) |
2424 |
"ProxyReceiveBufferSize, using default"); |
2553 |
"%s: error creating Unix domain socket for " |
2425 |
} |
2554 |
"target %s", |
|
|
2555 |
proxy_function, |
2556 |
worker->s->hostname); |
2557 |
break; |
2558 |
} |
2559 |
conn->connection = NULL; |
2426 |
|
2560 |
|
2427 |
rv = apr_socket_opt_set(newsock, APR_TCP_NODELAY, 1); |
2561 |
sa.sun_family = AF_UNIX; |
2428 |
if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) { |
2562 |
apr_cpystrn(sa.sun_path, conn->uds_path, sizeof(sa.sun_path)); |
2429 |
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00954) |
|
|
2430 |
"apr_socket_opt_set(APR_TCP_NODELAY): " |
2431 |
"Failed to set"); |
2432 |
} |
2433 |
|
2563 |
|
2434 |
/* Set a timeout for connecting to the backend on the socket */ |
2564 |
rv = socket_connect_un(newsock, &sa); |
2435 |
if (worker->s->conn_timeout_set) { |
2565 |
if (rv != APR_SUCCESS) { |
2436 |
apr_socket_timeout_set(newsock, worker->s->conn_timeout); |
2566 |
apr_socket_close(newsock); |
|
|
2567 |
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(02454) |
2568 |
"%s: attempt to connect to Unix domain socket " |
2569 |
"%s (%s) failed", |
2570 |
proxy_function, |
2571 |
conn->uds_path, |
2572 |
worker->s->hostname); |
2573 |
break; |
2574 |
} |
2437 |
} |
2575 |
} |
2438 |
else if (worker->s->timeout_set) { |
2576 |
else |
2439 |
apr_socket_timeout_set(newsock, worker->s->timeout); |
2577 |
#endif |
2440 |
} |
2578 |
{ |
2441 |
else if (conf->timeout_set) { |
2579 |
if ((rv = apr_socket_create(&newsock, backend_addr->family, |
2442 |
apr_socket_timeout_set(newsock, conf->timeout); |
2580 |
SOCK_STREAM, APR_PROTO_TCP, |
2443 |
} |
2581 |
conn->scpool)) != APR_SUCCESS) { |
2444 |
else { |
2582 |
loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR; |
2445 |
apr_socket_timeout_set(newsock, s->timeout); |
2583 |
ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00952) |
2446 |
} |
2584 |
"%s: error creating fam %d socket for " |
2447 |
/* Set a keepalive option */ |
2585 |
"target %s", |
2448 |
if (worker->s->keepalive) { |
2586 |
proxy_function, |
2449 |
if ((rv = apr_socket_opt_set(newsock, |
2587 |
backend_addr->family, |
2450 |
APR_SO_KEEPALIVE, 1)) != APR_SUCCESS) { |
2588 |
worker->s->hostname); |
2451 |
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00955) |
2589 |
/* |
2452 |
"apr_socket_opt_set(SO_KEEPALIVE): Failed to set" |
2590 |
* this could be an IPv6 address from the DNS but the |
2453 |
" Keepalive"); |
2591 |
* local machine won't give us an IPv6 socket; hopefully the |
|
|
2592 |
* DNS returned an additional address to try |
2593 |
*/ |
2594 |
backend_addr = backend_addr->next; |
2595 |
continue; |
2454 |
} |
2596 |
} |
2455 |
} |
2597 |
conn->connection = NULL; |
2456 |
ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, s, |
|
|
2457 |
"%s: fam %d socket created to connect to %s", |
2458 |
proxy_function, backend_addr->family, worker->s->hostname); |
2459 |
|
2598 |
|
2460 |
if (conf->source_address_set) { |
2599 |
if (worker->s->recv_buffer_size > 0 && |
2461 |
local_addr = apr_pmemdup(conn->pool, conf->source_address, |
2600 |
(rv = apr_socket_opt_set(newsock, APR_SO_RCVBUF, |
2462 |
sizeof(apr_sockaddr_t)); |
2601 |
worker->s->recv_buffer_size))) { |
2463 |
local_addr->pool = conn->pool; |
2602 |
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00953) |
2464 |
rv = apr_socket_bind(newsock, local_addr); |
2603 |
"apr_socket_opt_set(SO_RCVBUF): Failed to set " |
2465 |
if (rv != APR_SUCCESS) { |
2604 |
"ProxyReceiveBufferSize, using default"); |
2466 |
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00956) |
|
|
2467 |
"%s: failed to bind socket to local address", |
2468 |
proxy_function); |
2469 |
} |
2605 |
} |
2470 |
} |
|
|
2471 |
|
2606 |
|
2472 |
/* make the connection out of the socket */ |
2607 |
rv = apr_socket_opt_set(newsock, APR_TCP_NODELAY, 1); |
2473 |
rv = apr_socket_connect(newsock, backend_addr); |
2608 |
if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) { |
|
|
2609 |
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00954) |
2610 |
"apr_socket_opt_set(APR_TCP_NODELAY): " |
2611 |
"Failed to set"); |
2612 |
} |
2474 |
|
2613 |
|
2475 |
/* if an error occurred, loop round and try again */ |
2614 |
/* Set a timeout for connecting to the backend on the socket */ |
2476 |
if (rv != APR_SUCCESS) { |
2615 |
if (worker->s->conn_timeout_set) { |
2477 |
apr_socket_close(newsock); |
2616 |
apr_socket_timeout_set(newsock, worker->s->conn_timeout); |
2478 |
loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR; |
2617 |
} |
2479 |
ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00957) |
2618 |
else if (worker->s->timeout_set) { |
2480 |
"%s: attempt to connect to %pI (%s) failed", |
2619 |
apr_socket_timeout_set(newsock, worker->s->timeout); |
2481 |
proxy_function, |
2620 |
} |
2482 |
backend_addr, |
2621 |
else if (conf->timeout_set) { |
2483 |
worker->s->hostname); |
2622 |
apr_socket_timeout_set(newsock, conf->timeout); |
2484 |
backend_addr = backend_addr->next; |
2623 |
} |
2485 |
continue; |
2624 |
else { |
|
|
2625 |
apr_socket_timeout_set(newsock, s->timeout); |
2626 |
} |
2627 |
/* Set a keepalive option */ |
2628 |
if (worker->s->keepalive) { |
2629 |
if ((rv = apr_socket_opt_set(newsock, |
2630 |
APR_SO_KEEPALIVE, 1)) != APR_SUCCESS) { |
2631 |
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00955) |
2632 |
"apr_socket_opt_set(SO_KEEPALIVE): Failed to set" |
2633 |
" Keepalive"); |
2634 |
} |
2635 |
} |
2636 |
ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, s, |
2637 |
"%s: fam %d socket created to connect to %s", |
2638 |
proxy_function, backend_addr->family, worker->s->hostname); |
2639 |
|
2640 |
if (conf->source_address_set) { |
2641 |
local_addr = apr_pmemdup(conn->pool, conf->source_address, |
2642 |
sizeof(apr_sockaddr_t)); |
2643 |
local_addr->pool = conn->pool; |
2644 |
rv = apr_socket_bind(newsock, local_addr); |
2645 |
if (rv != APR_SUCCESS) { |
2646 |
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(00956) |
2647 |
"%s: failed to bind socket to local address", |
2648 |
proxy_function); |
2649 |
} |
2650 |
} |
2651 |
|
2652 |
/* make the connection out of the socket */ |
2653 |
rv = apr_socket_connect(newsock, backend_addr); |
2654 |
|
2655 |
/* if an error occurred, loop round and try again */ |
2656 |
if (rv != APR_SUCCESS) { |
2657 |
apr_socket_close(newsock); |
2658 |
loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR; |
2659 |
ap_log_error(APLOG_MARK, loglevel, rv, s, APLOGNO(00957) |
2660 |
"%s: attempt to connect to %pI (%s) failed", |
2661 |
proxy_function, |
2662 |
backend_addr, |
2663 |
worker->s->hostname); |
2664 |
backend_addr = backend_addr->next; |
2665 |
continue; |
2666 |
} |
2486 |
} |
2667 |
} |
2487 |
|
2668 |
|
2488 |
/* Set a timeout on the socket */ |
2669 |
/* Set a timeout on the socket */ |
Lines 2498-2504
PROXY_DECLARE(int) ap_proxy_connect_backend(const
Link Here
|
2498 |
|
2679 |
|
2499 |
conn->sock = newsock; |
2680 |
conn->sock = newsock; |
2500 |
|
2681 |
|
2501 |
if (conn->forward) { |
2682 |
if (!conn->uds_path && conn->forward) { |
2502 |
forward_info *forward = (forward_info *)conn->forward; |
2683 |
forward_info *forward = (forward_info *)conn->forward; |
2503 |
/* |
2684 |
/* |
2504 |
* For HTTP CONNECT we need to prepend CONNECT request before |
2685 |
* For HTTP CONNECT we need to prepend CONNECT request before |
Lines 2779-2785
PROXY_DECLARE(apr_status_t) ap_proxy_sync_balancer
Link Here
|
2779 |
found = 1; |
2960 |
found = 1; |
2780 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02402) |
2961 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(02402) |
2781 |
"re-grabbing shm[%d] (0x%pp) for worker: %s", i, (void *)shm, |
2962 |
"re-grabbing shm[%d] (0x%pp) for worker: %s", i, (void *)shm, |
2782 |
worker->s->name); |
2963 |
ap_proxy_worker_name(conf->pool, worker)); |
2783 |
break; |
2964 |
break; |
2784 |
} |
2965 |
} |
2785 |
} |
2966 |
} |