mod_proxy_balancer.c revision 9acdc6e89570bd3d79206c6d2ca2b5ccf85b20c7
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Load balancer module for Apache proxy */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *balancer_mutex_type = "proxy-balancer-shm";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int (*ap_proxy_retry_worker_fn)(const char *proxy_function,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Register our mutex type before the config is read so we
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * can adjust the mutex settings using the Mutex directive.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int balancer_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rv = ap_mutex_register(pconf, balancer_mutex_type, NULL,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbextern void proxy_update_members(proxy_balancer **balancer, request_rec *r,
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzstatic int proxy_balancer_canon(request_rec *r, char *url)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz const char *err;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* TODO: offset of BALANCER_PREFIX ?? */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "canonicalising URL %s", url);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* do syntatic check.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * We break the URL into host, port, path, search
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01157)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "error parsing URL %s: %s",
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * now parse path/search args, according to rfc1738:
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * process the path. With proxy-noncanon set (by
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick * mod_proxy) we use the raw, unparsed uri
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe r->filename = apr_pstrcat(r->pool, "proxy:", BALANCER_PREFIX, host,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe "/", path, (search) ? "?" : "", (search) ? search : "", NULL);
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames r->path_info = apr_pstrcat(r->pool, "/", path, NULL);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coarstatic void init_balancer_members(apr_pool_t *p, server_rec *s,
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz for (i = 0; i < balancer->workers->nelts; i++) {
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01158)
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar worker_is_initialized = PROXY_WORKER_IS_INITIALIZED(worker);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Set default number of attempts to the number of
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (!balancer->s->max_attempts_set && balancer->workers->nelts > 1) {
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames balancer->s->max_attempts = balancer->workers->nelts - 1;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe/* Retrieve the parameter with the given name
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * Something like 'JSESSIONID=12345...N'
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowestatic char *get_path_param(apr_pool_t *pool, char *url,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe for (path = strstr(url, name); path; path = strstr(path + 1, name)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * Session path was found, get its value
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe path = apr_strtok(apr_pstrdup(pool, path), pathdelims, &q);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowestatic char *get_cookie_param(request_rec *r, const char *name)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe const char *cookies;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe for (start_cookie = ap_strstr_c(cookies, name); start_cookie;
d176cb9e596e4603f76490f9211f62b5581b3091rooneg * Session cookie was found, get its value
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe/* Find the worker that has the 'route' defined
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzstatic proxy_worker *find_route_worker(proxy_balancer *balancer,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe for (i = 0; i < balancer->workers->nelts; i++, workers++) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) )
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (*(worker->s->route) && strcmp(worker->s->route, route) == 0) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe * If the worker is in error state run
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * retry on that worker. It will be marked as
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * operational if the retry timeout is elapsed.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * The worker might still be unusable, but we try
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_proxy_retry_worker_fn("BALANCER", worker, r->server);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * We have a worker that is unusable.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * It can be in error or disabled, but in case
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp * it has a redirection set use that redirection worker.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * This enables to safely remove the member from the
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * balancer. Of course you will need some kind of
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp * session replication between those two remote.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe rworker = find_route_worker(balancer, worker->s->redirect, r);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /* Check if the redirect worker is usable */
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp * If the worker is in error state run
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp * retry on that worker. It will be marked as
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp * operational if the retry timeout is elapsed.
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp * The worker might still be unusable, but we try
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp ap_proxy_retry_worker_fn("BALANCER", rworker, r->server);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowestatic proxy_worker *find_session_route(proxy_balancer *balancer,
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp const char **sticky_used,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Try to find the sticky route inside url */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *route = get_path_param(r->pool, *url, balancer->s->sticky_path, balancer->s->scolonsep);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01159)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Found value %s for stickysession %s",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01160)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Found value %s for stickysession %s",
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * If we found a value for stickysession, find the first '.' (or whatever
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * sticky_separator is set to) within. Everything after '.' (if present)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * is our route.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if ((*route) && (balancer->s->sticky_separator != 0) && ((*route = strchr(*route, balancer->s->sticky_separator)) != NULL ))
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01161) "Found route %s", *route);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* We have a route in path or in cookie
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * Find the worker that has this route defined.
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz * Notice that the route of the worker chosen is different from
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * the route supplied by the client.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01162)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe "Route changed from %s to %s",
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarstatic proxy_worker *find_best_worker(proxy_balancer *balancer,
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01163)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "%s: Lock failed for find_best_worker()",
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe candidate = (*balancer->lbmethod->finder)(balancer, r);
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01164)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe "%s: Unlock failed for find_best_worker()",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* All the workers are in error state or disabled.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * If the balancer has a timeout sleep for a while
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar * and try again to find the worker. The chances are
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * that some other thread will release a connection.
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick * By default the timeout is not set, and the server
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * returns SERVER_BUSY.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* XXX: This can perhaps be build using some
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * smarter mechanism, like tread_cond.
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz * But since the statuses can came from
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz * different childs, use the provided algo.
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz apr_interval_time_t timeout = balancer->s->timeout;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* Set the timeout to 0 so that we don't
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * end in infinite loop
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Try again */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* restore the timeout */
700b96db75e7cfadb5219978c1735b710d583763wrowestatic int rewrite_url(request_rec *r, proxy_worker *worker,
700b96db75e7cfadb5219978c1735b710d583763wrowe /* we break the URL into host, port, uri */
700b96db75e7cfadb5219978c1735b710d583763wrowe return ap_proxyerror(r, HTTP_BAD_REQUEST, apr_pstrcat(r->pool,
700b96db75e7cfadb5219978c1735b710d583763wrowe *url = apr_pstrcat(r->pool, worker->s->name, path, NULL);
700b96db75e7cfadb5219978c1735b710d583763wrowestatic void force_recovery(proxy_balancer *balancer, server_rec *s)
700b96db75e7cfadb5219978c1735b710d583763wrowe for (i = 0; i < balancer->workers->nelts; i++, worker++) {
700b96db75e7cfadb5219978c1735b710d583763wrowe if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Try if we can recover */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* If all workers are in error state force the recovery.
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (i = 0; i < balancer->workers->nelts; i++, worker++) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01165)
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe "%s: Forcing recovery for worker (%s)",
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowestatic apr_status_t decrement_busy_count(void *worker_)
23c6309e36a63b13b61c35999c978017521993d6wrowestatic int proxy_balancer_pre_request(proxy_worker **worker,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Step 1: check if the url is for us
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * The url we can handle starts with 'balancer://'
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe * If balancer is already provided skip the search
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * for balancer, because this is failover attempt.
cf6ef072483172309861d06e85b1aeff4573c060wrowe !(*balancer = ap_proxy_get_balancer(r->pool, conf, *url, 1)))
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Step 2: Lock the LoadBalancer
cf6ef072483172309861d06e85b1aeff4573c060wrowe * XXX: perhaps we need the process lock here
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp if ((rv = PROXY_THREAD_LOCK(*balancer)) != APR_SUCCESS) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01166)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "%s: Lock failed for pre_request", (*balancer)->s->name);
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Step 3: force recovery */
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Step 3.5: Update member list for the balancer */
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* TODO: Implement as provider! */
ecde48c75338ff5712f2036711f813c6dedca28ewrowe /* Step 4: find the session route */
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick runtime = find_session_route(*balancer, r, &route, &sticky, url);
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick if ((*balancer)->lbmethod && (*balancer)->lbmethod->updatelbstatus) {
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick /* Call the LB implementation */
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick (*balancer)->lbmethod->updatelbstatus(*balancer, runtime, r->server);
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick else { /* Use the default one */
ecde48c75338ff5712f2036711f813c6dedca28ewrowe /* We have a sticky load balancer
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick * Update the workers status
ecde48c75338ff5712f2036711f813c6dedca28ewrowe * so that even session routes get
ecde48c75338ff5712f2036711f813c6dedca28ewrowe * into account.
ecde48c75338ff5712f2036711f813c6dedca28ewrowe workers = (proxy_worker **)(*balancer)->workers->elts;
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick /* Take into calculation only the workers that are
cf6ef072483172309861d06e85b1aeff4573c060wrowe * not in error state or not disabled.
c2cf53a40a9814eb91db2cdf820f97d943f21628coar * We have a route provided that doesn't match the
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem * balancer name. See if the provider route is the
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem * member of the same balancer in which case return 503
4f9c22c4f27571d54197be9674e1fc0d528192aestriker workers = (proxy_worker **)(*balancer)->workers->elts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (*((*workers)->s->route) && strcmp((*workers)->s->route, route) == 0) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01167)
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem "%s: All workers are in error state for route (%s)",
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01168)
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem "%s: Unlock failed for pre_request",
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01169)
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem "%s: Unlock failed for pre_request",
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01170)
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem "%s: All workers are in error state",
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01171)
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem "%s: No workers in balancer",
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem * This balancer has sticky sessions and the client either has not
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem * supplied any routing information or all workers for this route
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem * including possible redirect and hotstandby workers are in error
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem * state, but we have found another working worker for this
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem * balancer where we can send the request. Thus notice that we have
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem * changed the route to the backend.
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
a9a4544168a37b43bd180b3703ccee995f27a80awrowe apr_pool_cleanup_register(r->pool, *worker, decrement_busy_count,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Add balancer/worker info to env. */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Rewrite the url from 'balancer://url'
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * to the 'worker_scheme://worker_hostname[:worker_port]/url'
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * This replaces the balancers fictional name with the
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * real hostname of the elected worker.
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Add the session route to request notes if present */
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz /* Add session info to env. */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01172)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "%s: worker (%s) rewritten to %s",
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic int proxy_balancer_post_request(proxy_worker *worker,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01173)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "%s: Lock failed for post_request",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker for (i = 0; i < balancer->errstatuses->nelts; i++) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01174)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "%s: Forcing worker (%s) into error state "
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "due to status code %d matching 'failonstatus' "
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "balancer parameter",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe balancer->s->name, ap_proxy_worker_name(r->pool, worker),
cf6ef072483172309861d06e85b1aeff4573c060wrowe && (apr_table_get(r->notes, "proxy_timedout")) != NULL) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02460)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "%s: Forcing worker (%s) into error state "
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "due to timeout and 'failonstatus' parameter being set",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe balancer->s->name, ap_proxy_worker_name(r->pool, worker));
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01175)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "%s: Unlock failed for post_request", balancer->s->name);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01176)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "proxy_balancer_post_request for (%s)", balancer->s->name);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Recalculate lbfactors */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Special case if there is only one worker its
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * load factor will always be 1
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (*workers)->s->lbstatus = (*workers)->s->lbfactor = 1;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Update the status entries */
38bcc87d9a06e8ba81165421403f275eca4e313btrawick proxy_server_conf *conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz balancer = (proxy_balancer *)conf->balancers->elts;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe/* post_config hook: */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowestatic int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* balancer_post_config() will be called twice during startup. So, don't
8aefbd756763807188d2e3ce336a8680e4893066wrowe * set up the static data the 1st time through. */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02230)
cf6ef072483172309861d06e85b1aeff4573c060wrowe "mod_proxy must be loaded for mod_proxy_balancer");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Get slotmem setups
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe storage = ap_lookup_provider(AP_SLOTMEM_PROVIDER_GROUP, "shm",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01177)
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz "Failed to lookup provider 'shm' for '%s': is "
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz "mod_slotmem_shm loaded??",
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Go thru each Vhost and create the shared mem slotmem for
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * each balancer's workers
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe while (s) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * During create_proxy_config() we created a dummy id. Now that
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * we have identifying info, we can create the real id
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe (s->error_fname ? s->error_fname : DEFAULT_ERRORLOG));
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe /* Shared memory already created for this proxy_server_conf.
700b96db75e7cfadb5219978c1735b710d583763wrowe conf->max_balancers = conf->balancers->nelts + conf->bgrowth;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01178) "Doing balancers create: %d, %d (%d)",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01179) "balancer slotmem_create failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Initialize shared scoreboard data */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar const char *sname;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar unsigned int index;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar /* now that we have the right id, we need to redo the sname field */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_pstr2_alnum(pconf, balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sname = apr_pstrcat(pconf, conf->id, "_", sname, NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe PROXY_STRNCPY(balancer->s->sname, sname); /* We know this will succeed */
8aefbd756763807188d2e3ce336a8680e4893066wrowe balancer->max_workers = balancer->workers->nelts + balancer->growth;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Create global mutex */
8aefbd756763807188d2e3ce336a8680e4893066wrowe rv = ap_global_mutex_create(&(balancer->gmutex), NULL, balancer_mutex_type,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01180)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "mutex creation of %s : %s failed", balancer_mutex_type,
700b96db75e7cfadb5219978c1735b710d583763wrowe apr_pool_cleanup_register(pconf, (void *)s, lock_remove,
700b96db75e7cfadb5219978c1735b710d583763wrowe /* setup shm for balancers */
43c3e6a4b559b76b750c245ee95e2782c15b4296jim bshm = ap_proxy_find_balancershm(storage, conf->bslot, balancer, &index);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = storage->fgrab(conf->bslot, index)) != APR_SUCCESS) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02408) "balancer slotmem_fgrab failed");
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((rv = storage->grab(conf->bslot, &index)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed");
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((rv = storage->dptr(conf->bslot, index, (void *)&bshm)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed");
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((rv = ap_proxy_share_balancer(balancer, bshm, index)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01183) "Cannot share balancer");
700b96db75e7cfadb5219978c1735b710d583763wrowe /* create slotmem slots for workers */
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01184) "Doing workers create: %s (%s), %d, %d [%u]",
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01185) "worker slotmem_create failed");
700b96db75e7cfadb5219978c1735b710d583763wrowe /* sync all timestamps */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* now go thru each worker */
700b96db75e7cfadb5219978c1735b710d583763wrowe for (j = 0; j < balancer->workers->nelts; j++, workers++) {
700b96db75e7cfadb5219978c1735b710d583763wrowe shm = ap_proxy_find_workershm(storage, balancer->wslot, worker, &index);
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((rv = storage->fgrab(balancer->wslot, index)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02409) "worker slotmem_fgrab failed");
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz if ((rv = storage->grab(balancer->wslot, &index)) != APR_SUCCESS) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01186) "worker slotmem_grab failed");
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if ((rv = storage->dptr(balancer->wslot, index, (void *)&shm)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01187) "worker slotmem_dptr failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = ap_proxy_share_worker(worker, shm, index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01188) "Cannot share worker");
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz /* We could have just read-in a persisted config. Force a sync. */
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantzstatic void create_radio(const char *name, unsigned int flag, request_rec *r)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, "<td>On <input name='", name, "' id='", name, "' value='1' type=radio", NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_rvputs(r, "> <br/> Off <input name='", name, "' id='", name, "' value='0' type=radio", NULL);
cf6ef072483172309861d06e85b1aeff4573c060wrowestatic void push2table(const char *input, apr_table_t *params,
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* Manages the loadfactors and member status
8aefbd756763807188d2e3ce336a8680e4893066wrowe * The balancer, worker and nonce are obtained from
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * the request args (?b=...&w=...&nonce=....).
cf6ef072483172309861d06e85b1aeff4573c060wrowe * All other params are pulled from any POST
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * data that exists.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * /.../<whatever>/balancer/worker/nonce
cadddb2c31d24d48f4017db4df0a29687432326cwrowe const char *name;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *action;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* is this for us? */
71fe373d064756fb261876443806ece033ee3309slive if ((r->method_number != M_GET) && (r->method_number != M_POST)) {
ecde48c75338ff5712f2036711f813c6dedca28ewrowe conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
e8f95a682820a599fe41b22977010636be5c2717jim for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
ecde48c75338ff5712f2036711f813c6dedca28ewrowe if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
ecde48c75338ff5712f2036711f813c6dedca28ewrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01189)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Lock failed for balancer_handler",
ecde48c75338ff5712f2036711f813c6dedca28ewrowe if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
ecde48c75338ff5712f2036711f813c6dedca28ewrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01190)
ecde48c75338ff5712f2036711f813c6dedca28ewrowe "%s: Unlock failed for balancer_handler",
cf6ef072483172309861d06e85b1aeff4573c060wrowe const char *allowed[] = { "w", "b", "nonce", "xml", NULL };
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01191) "parsing r->args");
cf6ef072483172309861d06e85b1aeff4573c060wrowe ib = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
cf6ef072483172309861d06e85b1aeff4573c060wrowe rv = ap_get_brigade(r->input_filters, ib, AP_MODE_READBYTES,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_pstrcat(r->pool, BALANCER_PREFIX, name, NULL), 0);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe wsel = ap_proxy_get_worker(r->pool, bsel, conf, name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Check that the supplied nonce matches this server's nonce;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar * otherwise ignore all parameters, to prevent a CSRF attack. */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* First set the params */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *val;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01192) "settings worker params");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (strlen(val) && strlen(val) < sizeof(wsel->s->route))
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (strlen(val) && strlen(val) < sizeof(wsel->s->redirect))
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* if enabling, we need to reset all lb params */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (bsel && !was_usable && PROXY_WORKER_IS_USABLE(wsel)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *val;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01193)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "settings balancer params");
8aefbd756763807188d2e3ce336a8680e4893066wrowe lbmethod = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
0540a0b469147b52e858587270dba31c2aaa9e09wrowe nworker = ap_proxy_get_worker(r->pool, bsel, conf, val);
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz if (!nworker && storage->num_free_slots(bsel->wslot)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01194)
42da244268b11ec661b528510f80a18b73c51727brianp "%s: Lock failed for adding worker",
948096a99010fccf648814fecf38f75c689172d7wrowe ret = ap_proxy_define_worker(conf->pool, &nworker, bsel, conf, val, 0);
948096a99010fccf648814fecf38f75c689172d7wrowe unsigned int index;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz if ((rv = storage->grab(bsel->wslot, &index)) != APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01195)
948096a99010fccf648814fecf38f75c689172d7wrowe "worker slotmem_grab failed");
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01196)
948096a99010fccf648814fecf38f75c689172d7wrowe "%s: Unlock failed for adding worker",
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = storage->dptr(bsel->wslot, index, (void *)&shm)) != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01197)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "worker slotmem_dptr failed");
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01198)
948096a99010fccf648814fecf38f75c689172d7wrowe "%s: Unlock failed for adding worker",
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if ((rv = ap_proxy_share_worker(nworker, shm, index)) != APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01199)
a9a4544168a37b43bd180b3703ccee995f27a80awrowe "Cannot share worker");
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01200)
a9a4544168a37b43bd180b3703ccee995f27a80awrowe "%s: Unlock failed for adding worker",
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = ap_proxy_initialize_worker(nworker, r->server, conf->pool)) != APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01201)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "Cannot init worker");
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01202)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "%s: Unlock failed for adding worker",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* sync all timestamps */
948096a99010fccf648814fecf38f75c689172d7wrowe bsel->wupdated = bsel->s->wupdated = nworker->s->updated = apr_time_now();
948096a99010fccf648814fecf38f75c689172d7wrowe /* by default, all new workers are disabled */
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01203)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe "%s: Unlock failed for adding worker",
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01204) "genning page");
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_rputs("<?xml version='1.0' encoding='UTF-8' ?>\n", r);
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick ap_rputs("<httpd:manager xmlns:httpd='http://httpd.apache.org'>\n", r);
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* Start proxy_balancer */
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_rvputs(r, " <httpd:name>", balancer->s->name, "</httpd:name>\n", NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:stickysession>", balancer->s->sticky,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe " <httpd:nofailover>%s</httpd:nofailover>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:timeout>%" APR_TIME_T_FMT "</httpd:timeout>",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:maxattempts>%d</httpd:maxattempts>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:lbmethod>", balancer->lbmethod->name,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker " <httpd:scolonpathdelim>%s</httpd:scolonpathdelim>\n",
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar /* End proxy_balancer */
948096a99010fccf648814fecf38f75c689172d7wrowe /* Start proxy_worker */
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:name>", ap_proxy_worker_name(r->pool, worker),
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:hostname>", worker->s->hostname,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rprintf(r, " <httpd:loadfactor>%d</httpd:loadfactor>\n",
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " <httpd:port>%d</httpd:port>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:timeout>%" APR_TIME_T_FMT "</httpd:timeout>\n",
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe " <httpd:acquire>%" APR_TIME_T_FMT "</httpd:acquire>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker " <httpd:recv_buffer_size>%" APR_SIZE_T_FMT "</httpd:recv_buffer_size>\n",
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe " <httpd:io_buffer_size>%" APR_SIZE_T_FMT "</httpd:io_buffer_size>\n",
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe " <httpd:keepalive>%s</httpd:keepalive>\n",
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp /* Begin proxy_worker_stat */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (worker->s->status & PROXY_WORKER_HOT_STANDBY)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz if ((worker->s->error_time > 0) && apr_rfc822_date(date, worker->s->error_time) == APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " <httpd:retries>%d</httpd:retries>\n",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe " <httpd:lbstatus>%d</httpd:lbstatus>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker " <httpd:loadfactor>%d</httpd:loadfactor>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker " <httpd:transferred>%" APR_OFF_T_FMT "</httpd:transferred>\n",
a9a4544168a37b43bd180b3703ccee995f27a80awrowe " <httpd:elected>%" APR_SIZE_T_FMT "</httpd:elected>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* End proxy_worker_stat */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe " <httpd:flushwait>%d</httpd:flushwait>\n",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe " <httpd:disablereuse>%s</httpd:disablereuse>\n",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " <httpd:connectiontimeout>%" APR_TIME_T_FMT "</httpd:connectiontimeout>\n",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_set_content_type(r, "text/html; charset=ISO-8859-1");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "<html><head><title>Balancer Manager</title>\n", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "table {\n"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe " border-width: 1px;\n"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe " border-spacing: 3px;\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " border-style: solid;\n"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe " border-color: gray;\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " border-collapse: collapse;\n"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " background-color: white;\n"
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe " text-align: center;\n"
a9a4544168a37b43bd180b3703ccee995f27a80awrowe " border-width: 1px;\n"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe " padding: 2px;\n"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe " border-style: dotted;\n"
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe " border-color: gray;\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " background-color: white;\n"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe " text-align: center;\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " border-width: 1px;\n"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe " padding: 2px;\n"
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe " border-style: dotted;\n"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " border-color: gray;\n"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " background-color: white;\n"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " text-align: center;\n"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "</style>\n</head>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, ap_escape_html(r->pool, ap_get_server_name(r)),
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<dt>Balancer changes will ", conf->bal_persist ? "" : "NOT ",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<dt>Balancers are ", conf->inherit ? "" : "NOT ",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<dt>ProxyPass settings are ", conf->ppinherit ? "" : "NOT ",
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe ap_rvputs(r, "<a href=\"", ap_escape_uri(r->pool, r->uri), "?b=",
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe ap_rvputs(r, balancer->s->name, "</a> [",balancer->s->sname, "]</h3>\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "<th>MaxMembers</th><th>StickySession</th><th>DisableFailover</th><th>Timeout</th><th>FailoverAttempts</th><th>Method</th>"
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe "<th>Path</th><th>Active</th></tr>\n<tr>", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* the below is a safe cast, since the number of slots total will
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe * never be more than max_workers, which is restricted to int */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rprintf(r, "<td>%d [%d Used]</td>\n", balancer->max_workers,
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe balancer->max_workers - (int)storage->num_free_slots(balancer->wslot));
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (strcmp(balancer->s->sticky, balancer->s->sticky_path)) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rprintf(r, "<td>%d</td>\n", balancer->s->max_attempts);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe "<th>Worker URL</th>"
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe "<th>Route</th><th>RouteRedir</th>"
e57e920838f31508f1418aa4c25ce55b345b2cebrbb "<th>Factor</th><th>Set</th><th>Status</th>"
e57e920838f31508f1418aa4c25ce55b345b2cebrbb "<th>Elected</th><th>Busy</th><th>Load</th><th>To</th><th>From</th>"
e57e920838f31508f1418aa4c25ce55b345b2cebrbb "</tr>\n", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe balancer->s->name + sizeof(BALANCER_PREFIX) - 1, "&w=",
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rvputs(r, (worker->s->uds ? "<i>" : ""), ap_proxy_worker_name(r->pool, worker),
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, "<td>", ap_escape_html(r->pool, worker->s->route),
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe ap_rprintf(r, "</td><td>%d</td>", worker->s->lbfactor);
098ae874f43f7a0b66be5406a7e2fb971bbbe00ewrowe ap_rvputs(r, ap_proxy_parse_wstatus(r->pool, worker), NULL);
098ae874f43f7a0b66be5406a7e2fb971bbbe00ewrowe ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td>", worker->s->elected);
098ae874f43f7a0b66be5406a7e2fb971bbbe00ewrowe ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td>", worker->s->busy);
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe ap_rprintf(r, "<td>%d</td><td>", worker->s->lbstatus);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r);
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames ap_rvputs(r, (wsel->s->uds?"<i>":""), ap_proxy_worker_name(r->pool, wsel), (wsel->s->uds?"</i>":""), "</h3>\n", NULL);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rputs("<form method=\"POST\" enctype=\"application/x-www-form-urlencoded\" action=\"", r);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, ap_escape_uri(r->pool, action), "\">\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<dl>\n<table><tr><td>Load factor:</td><td><input name='w_lf' id='w_lf' type=text ", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "value='%d'></td></tr>\n", wsel->s->lbfactor);
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes ap_rputs("<tr><td>LB Set:</td><td><input name='w_ls' id='w_ls' type=text ", r);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rprintf(r, "value='%d'></td></tr>\n", wsel->s->lbset);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td>Route:</td><td><input name='w_wr' id='w_wr' type=text ", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->route),
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes ap_rputs("<tr><td>Route Redirect:</td><td><input name='w_rr' id='w_rr' type=text ", r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->redirect),
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe "<th>Ignore Errors</th>"
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe "<th>Draining Mode</th>"
e8eee56a2ea20f673e5942fb58e1426a7561c7acstas "<th>Disabled</th>"
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe "<th>Hot Standby</th></tr>\n<tr>", r);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe create_radio("w_status_I", (PROXY_WORKER_IGNORE_ERRORS & wsel->s->status), r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb create_radio("w_status_N", (PROXY_WORKER_DRAIN & wsel->s->status), r);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe create_radio("w_status_D", (PROXY_WORKER_DISABLED & wsel->s->status), r);
8011ccb9e0700e5a396e2362dab1d9386206277fcolm create_radio("w_status_H", (PROXY_WORKER_HOT_STANDBY & wsel->s->status), r);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ap_rputs("<tr><td colspan=2><input type=submit value='Submit'></td></tr>\n", r);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ap_rvputs(r, "</table>\n<input type=hidden name='w' id='w' ", NULL);
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe ap_rvputs(r, "value='", ap_escape_uri(r->pool, wsel->s->name), "'>\n", NULL);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb ap_rvputs(r, "<input type=hidden name='b' id='b' ", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "value='", bsel->s->name + sizeof(BALANCER_PREFIX) - 1,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<input type=hidden name='nonce' id='nonce' value='",
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar } else if (bsel) {
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd ap_rputs("<form method='POST' enctype='application/x-www-form-urlencoded' action='", r);
a8c55845ffa7170766e410dbd799353127b628f9nd provs = ap_list_provider_names(r->pool, PROXY_LBMETHOD, "0");
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard ap_rvputs(r,"<option value='", pname->provider_name, "'", NULL);
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard if (strcmp(pname->provider_name, bsel->s->lbpname) == 0)
6edf0ccf36ca2792b20058833680375b9256f2e0colm ap_rputs("<tr><td>Timeout:</td><td><input name='b_tmo' id='b_tmo' type=text ", r);
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard ap_rprintf(r, "value='%" APR_TIME_T_FMT "'></td></tr>\n", apr_time_sec(bsel->s->timeout));
6edf0ccf36ca2792b20058833680375b9256f2e0colm ap_rputs("<tr><td>Failover Attempts:</td><td><input name='b_max' id='b_max' type=text ", r);
6edf0ccf36ca2792b20058833680375b9256f2e0colm ap_rprintf(r, "value='%d'></td></tr>\n", bsel->s->max_attempts);
6edf0ccf36ca2792b20058833680375b9256f2e0colm ap_rputs("<tr><td>Sticky Session:</td><td><input name='b_ss' id='b_ss' size=64 type=text ", r);
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard if (strcmp(bsel->s->sticky, bsel->s->sticky_path)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("'> (Use '-' to delete)</td></tr>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td>Add New Worker:</td><td><input name='b_nwrkr' id='b_nwrkr' size=32 type=text>"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " Are you sure? <input name='b_wyes' id='b_wyes' type=checkbox value='1'>"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "</td></tr>", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td colspan=2><input type=submit value='Submit'></td></tr>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "</table>\n<input type=hidden name='b' id='b' ", NULL);
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe ap_rvputs(r, "value='", bsel->s->name + sizeof(BALANCER_PREFIX) - 1,
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe ap_rvputs(r, "<input type=hidden name='nonce' id='nonce' value='",
117026201e6d8fe7d82416b8a7324830f5a87292wrowestatic void balancer_child_init(apr_pool_t *p, server_rec *s)
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames while (s) {
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames unsigned int num;
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe storage->attach(&(conf->bslot), conf->id, &size, &num, p);
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01205) "slotmem_attach failed");
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames balancer = (proxy_balancer *)conf->balancers->elts;
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
dc3a3d949b7ef46b8385858c822267e39b665c12nd ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(01206)
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames "Failed to init balancer %s in child",
cadddb2c31d24d48f4017db4df0a29687432326cwrowestatic void ap_proxy_balancer_register_hook(apr_pool_t *p)
85bb5b92490e4f095aae394118fc588a8f4c486fwrowe /* Only the mpm_winnt has child init hook handler.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * make sure that we are called after the mpm
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe * initializes
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe static const char *const aszPred[] = { "mpm_winnt.c", "mod_slotmem_shm.c", NULL};
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick static const char *const aszPred2[] = { "mod_proxy.c", NULL};
e8f95a682820a599fe41b22977010636be5c2717jim /* manager handler */
e8f95a682820a599fe41b22977010636be5c2717jim ap_hook_post_config(balancer_post_config, aszPred2, NULL, APR_HOOK_MIDDLE);
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick ap_hook_pre_config(balancer_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_hook_handler(balancer_handler, NULL, NULL, APR_HOOK_FIRST);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_hook_child_init(balancer_child_init, aszPred, NULL, APR_HOOK_MIDDLE);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe proxy_hook_pre_request(proxy_balancer_pre_request, NULL, NULL, APR_HOOK_FIRST);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe proxy_hook_post_request(proxy_balancer_post_request, NULL, NULL, APR_HOOK_FIRST);