mirror of
https://github.com/apache/httpd.git
synced 2025-08-08 15:02:10 +03:00
mod_proxy: Handle backend address renewal with address_ttl= parameter.
Define a new proxy_address struct holding the current/latest sockaddr in use by each proxy worker and conn. Since backend addresses can be updated when their TTL expires and while connections are being processed, each address is refcounted and freed only when the last worker (or conn) using it grabs the new one. The lifetime of the addresses is handled at a single place by the new ap_proxy_determine_address() function. It guarantees to bind the current/latest backend address to the passed in conn (or do nothing if it's up to date already). The function is called indirectly by ap_proxy_determine_connection() for the proxy modules that use it, or directly by mod_proxy_ftp and mod_proxy_hcheck. It also is called eventually by ap_proxy_connect_backend() when connect()ing all the current addresses fails, to check (PROXY_DETERMINE_ADDRESS_CHECK) if some new addrs are available. This commit is also a rework of the lifetime of conn->addr, conn->hostname and conn->forward, using the conn->uds_pool and conn->fwd_pool for the cases where the backend is connected through a UDS socket and a remote CONNECT proxy respectively. * include/ap_mmn.h: Minor bump for new function/fields. * modules/proxy/mod_proxy.h (struct proxy_address, ap_proxy_determine_addresss()): Declare ap_proxy_determine_addresss() and opaque struct proxy_address, new fields to structs proxy_conn_rec/proxy_worker_shared/proxy_worker. * modules/proxy/mod_proxy.c (set_worker_param): Parse/set the new worker->address_ttl parameter. * modules/proxy/proxy_util.c (proxy_util_register_hooks(), ap_proxy_initialize_worker(), ap_proxy_connection_reusable(), ap_proxyerror(), proxyerror_core(), init_conn_pool(), make_conn_subpool(), connection_make(), connection_cleanup(), connection_constructor()): Initialize *proxy_start_time in proxy_util_register_hooks() as the epoch from which expiration times are relative (i.e. seconds stored in an uint32_t for atomic changes). Make sure worker->s->is_address_reusable and worker->s->disablereuse are consistant in ap_proxy_initialize_worker(), thus no need to check for both in ap_proxy_connection_reusable(). New proxyerror_core() helper taking an apr_status_t to log, wrap in ap_proxyerror(). New make_conn_subpool() to create worker->cp->{pool,dns} with their own allocator. New connection_make() helper to factorize code in connection_cleanup() and connection_constructor(). * modules/proxy/proxy_util.c (proxy_address_inc(), proxy_address_dec(), proxy_address_cleanup(), proxy_address_set_expired(), worker_address_get(), worker_address_set(), worker_address_resolve(), proxy_addrs_equal(), ap_proxy_determine_address(), ap_proxy_determine_connection(), ap_proxy_connect_backend()): Implement ap_proxy_determine_address() using the above helpers for atomic changes, and call it from ap_proxy_determine_connection() and ap_proxy_connect_backend(). * modules/proxy/mod_proxy_ftp.c (proxy_ftp_handler): Use ap_proxy_determine_address() and use the returned backend->addr. * modules/proxy/mod_proxy_hcheck.c (hc_determine_connection, hc_get_backend, hc_init_worker, hc_watchdog_callback): Use ap_proxy_determine_address() in hc_determine_connection() and call the latter from hc_get_backend(), replace hc_init_worker() by hc_init_baton() which now calls hc_get_hcworker() and hc_get_backend() to resolve the first address at init time. * modules/proxy/mod_proxy_http.c (proxy_http_handler): Use backend->addr and ->hostname instead of worker->cp->addr and worker->s->hostname_ex respectively. * modules/proxy/mod_proxy_ajp.c (ap_proxy_ajp_request): Use backend->addr and ->hostname instead of worker->cp->addr and worker->s->hostname_ex respectively. Closes #367 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1912459 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -269,6 +269,8 @@ typedef struct {
|
||||
apr_array_header_t* cookie_domains;
|
||||
} proxy_req_conf;
|
||||
|
||||
struct proxy_address; /* opaque TTL'ed and refcount'ed address */
|
||||
|
||||
typedef struct {
|
||||
conn_rec *connection;
|
||||
request_rec *r; /* Request record of the backend request
|
||||
@@ -294,6 +296,9 @@ typedef struct {
|
||||
* and its scpool/bucket_alloc (NULL before),
|
||||
* must be left cleaned when used (locally).
|
||||
*/
|
||||
apr_pool_t *uds_pool; /* Subpool for reusing UDS paths */
|
||||
apr_pool_t *fwd_pool; /* Subpool for reusing ProxyRemote infos */
|
||||
struct proxy_address *address; /* Current remote address */
|
||||
} proxy_conn_rec;
|
||||
|
||||
typedef struct {
|
||||
@@ -488,6 +493,9 @@ typedef struct {
|
||||
unsigned int was_malloced:1;
|
||||
unsigned int is_name_matchable:1;
|
||||
unsigned int response_field_size_set:1;
|
||||
unsigned int address_ttl_set:1;
|
||||
apr_int32_t address_ttl; /* backend address' TTL (seconds) */
|
||||
apr_uint32_t address_expiry; /* backend address' next expiry time */
|
||||
} proxy_worker_shared;
|
||||
|
||||
#define ALIGNED_PROXY_WORKER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_worker_shared)))
|
||||
@@ -504,6 +512,7 @@ struct proxy_worker {
|
||||
#endif
|
||||
void *context; /* general purpose storage */
|
||||
ap_conf_vector_t *section_config; /* <Proxy>-section wherein defined */
|
||||
struct proxy_address *volatile address; /* current worker address (if reusable) */
|
||||
};
|
||||
|
||||
/* default to health check every 30 seconds */
|
||||
@@ -1041,6 +1050,29 @@ PROXY_DECLARE(int) ap_proxy_post_request(proxy_worker *worker,
|
||||
request_rec *r,
|
||||
proxy_server_conf *conf);
|
||||
|
||||
/* Bitmask for ap_proxy_determine_address() */
|
||||
#define PROXY_DETERMINE_ADDRESS_CHECK (1u << 0)
|
||||
/**
|
||||
* Resolve an address, reusing the one of the worker if any.
|
||||
* @param proxy_function calling proxy scheme (http, ajp, ...)
|
||||
* @param conn proxy connection the address is used for
|
||||
* @param hostname host to resolve (should be the worker's if reusable)
|
||||
* @param hostport port to resolve (should be the worker's if reusable)
|
||||
* @param flags bitmask of PROXY_DETERMINE_ADDRESS_*
|
||||
* @param r current request (if any)
|
||||
* @param s current server (or NULL if r != NULL and ap_proxyerror()
|
||||
* should be called on error)
|
||||
* @return APR_SUCCESS or an error, APR_EEXIST if the address is still
|
||||
* the same and PROXY_DETERMINE_ADDRESS_CHECK is asked
|
||||
*/
|
||||
PROXY_DECLARE(apr_status_t) ap_proxy_determine_address(const char *proxy_function,
|
||||
proxy_conn_rec *conn,
|
||||
const char *hostname,
|
||||
apr_port_t hostport,
|
||||
unsigned int flags,
|
||||
request_rec *r,
|
||||
server_rec *s);
|
||||
|
||||
/**
|
||||
* Determine backend hostname and port
|
||||
* @param p memory pool used for processing
|
||||
|
Reference in New Issue
Block a user