mod_proxy_balancer.c revision 5772afb03a895afcebaf30a107c44022fc9b5224
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
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * http://www.apache.org/licenses/LICENSE-2.0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
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 */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Load balancer module for Apache proxy */
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh#include "mod_proxy.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "scoreboard.h"
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh#include "ap_mpm.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_version.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "ap_hooks.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_date.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *balancer_mutex_type = "proxy-balancer-shm";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbap_slotmem_provider_t *storage = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbmodule AP_MODULE_DECLARE_DATA proxy_balancer_module;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int (*ap_proxy_retry_worker_fn)(const char *proxy_function,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker *worker, server_rec *s) = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Register our mutex type before the config is read so we
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * can adjust the mutex settings using the Mutex directive.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int balancer_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_t *ptemp)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_status_t rv;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rv = ap_mutex_register(pconf, balancer_mutex_type, NULL,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_LOCK_DEFAULT, 0);
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames if (rv != APR_SUCCESS) {
750d12c59545dbbac70390988de94f7e901b08f2niq return rv;
82632a19f2f9c346fee2b28a65920ba9737b3973minfrin }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
db455cbc662c98dbbf53175393c50086ff63370cchrisd}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#if 0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbextern void proxy_update_members(proxy_balancer **balancer, request_rec *r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *conf);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf
7184de27ec1d62a83c41cdeac0953ca9fd661e8csfstatic int proxy_balancer_canon(request_rec *r, char *url)
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf{
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf char *host, *path;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *search = NULL;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz const char *err;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz apr_port_t port = 0;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* TODO: offset of BALANCER_PREFIX ?? */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz if (strncasecmp(url, "balancer:", 9) == 0) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz url += 9;
18b5268e013574026b2503b1641baf3299045f45sf }
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz else {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz return DECLINED;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "canonicalising URL %s", url);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* do syntatic check.
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe * We break the URL into host, port, path, search
4f9c22c4f27571d54197be9674e1fc0d528192aestriker */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (err) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01157)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "error parsing URL %s: %s",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb url, err);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return HTTP_BAD_REQUEST;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /*
18b5268e013574026b2503b1641baf3299045f45sf * now parse path/search args, according to rfc1738:
18b5268e013574026b2503b1641baf3299045f45sf * process the path. With proxy-noncanon set (by
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * mod_proxy) we use the raw, unparsed uri
4f9c22c4f27571d54197be9674e1fc0d528192aestriker */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (apr_table_get(r->notes, "proxy-nocanon")) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker path = url; /* this is the raw path */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd r->proxyreq);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd search = r->args;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (path == NULL)
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi return HTTP_BAD_REQUEST;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe r->filename = apr_pstrcat(r->pool, "proxy:", BALANCER_PREFIX, host,
185aa71728867671e105178b4c66fbc22b65ae26sf "/", path, (search) ? "?" : "", (search) ? search : "", NULL);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe r->path_info = apr_pstrcat(r->pool, "/", path, NULL);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar return OK;
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf}
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sfstatic void init_balancer_members(apr_pool_t *p, server_rec *s,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe proxy_balancer *balancer)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe int i;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe proxy_worker **workers;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe workers = (proxy_worker **)balancer->workers->elts;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe for (i = 0; i < balancer->workers->nelts; i++) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe int worker_is_initialized;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe proxy_worker *worker = *workers;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01158)
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames "Looking at %s -> %s%s initialized?", balancer->s->name, worker->s->name,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe (worker->s->uds?"|":""));
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf worker_is_initialized = PROXY_WORKER_IS_INITIALIZED(worker);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (!worker_is_initialized) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_proxy_initialize_worker(worker, s, p);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf ++workers;
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar }
3770ed746d69c7a4111cba9966169bd5d7a509a6poirier
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar /* Set default number of attempts to the number of
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar * workers.
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar */
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar if (!balancer->s->max_attempts_set && balancer->workers->nelts > 1) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz balancer->s->max_attempts = balancer->workers->nelts - 1;
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar balancer->s->max_attempts_set = 1;
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar }
185aa71728867671e105178b4c66fbc22b65ae26sf}
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar/* Retrieve the parameter with the given name
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar * Something like 'JSESSIONID=12345...N'
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar */
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coarstatic char *get_path_param(apr_pool_t *pool, char *url,
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz const char *name, int scolon_sep)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe char *path = NULL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe char *pathdelims = "?&";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (scolon_sep) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker pathdelims = ";?&";
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames for (path = strstr(url, name); path; path = strstr(path + 1, name)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe path += strlen(name);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (*path == '=') {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /*
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * Session path was found, get its value
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ++path;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (*path) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf char *q;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe path = apr_strtok(apr_pstrdup(pool, path), pathdelims, &q);
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf return path;
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf }
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf }
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf }
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf return NULL;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe}
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowestatic char *get_cookie_param(request_rec *r, const char *name)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe const char *cookies;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker const char *start_cookie;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe for (start_cookie = ap_strstr_c(cookies, name); start_cookie;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar start_cookie = ap_strstr_c(start_cookie + 1, name)) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (start_cookie == cookies ||
4775dfc34c90fada8c7c4d6a57ed8a3114d55c2dtrawick start_cookie[-1] == ';' ||
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe start_cookie[-1] == ',' ||
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe isspace(start_cookie[-1])) {
11a0edf478ca9c59d80bf73491d89cf019259feeniq
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe start_cookie += strlen(name);
11a0edf478ca9c59d80bf73491d89cf019259feeniq while(*start_cookie && isspace(*start_cookie))
11a0edf478ca9c59d80bf73491d89cf019259feeniq ++start_cookie;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (*start_cookie++ == '=' && *start_cookie) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /*
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * Session cookie was found, get its value
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe char *end_cookie, *cookie;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf cookie = apr_pstrdup(r->pool, start_cookie);
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf if ((end_cookie = strchr(cookie, ';')) != NULL)
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf *end_cookie = '\0';
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf if((end_cookie = strchr(cookie, ',')) != NULL)
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf *end_cookie = '\0';
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return cookie;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return NULL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe}
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe/* Find the worker that has the 'route' defined
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowestatic proxy_worker *find_route_worker(proxy_balancer *balancer,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe const char *route, request_rec *r)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd{
4f9c22c4f27571d54197be9674e1fc0d528192aestriker int i;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe int checking_standby;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe int checked_standby;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd proxy_worker **workers;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd checking_standby = checked_standby = 0;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar while (!checked_standby) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes workers = (proxy_worker **)balancer->workers->elts;
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes for (i = 0; i < balancer->workers->nelts; i++, workers++) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes proxy_worker *worker = *workers;
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) )
18b5268e013574026b2503b1641baf3299045f45sf continue;
18b5268e013574026b2503b1641baf3299045f45sf if (*(worker->s->route) && strcmp(worker->s->route, route) == 0) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if (PROXY_WORKER_IS_USABLE(worker)) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return worker;
18b5268e013574026b2503b1641baf3299045f45sf } else {
18b5268e013574026b2503b1641baf3299045f45sf /*
18b5268e013574026b2503b1641baf3299045f45sf * If the worker is in error state run
18b5268e013574026b2503b1641baf3299045f45sf * retry on that worker. It will be marked as
d9cc5de428947d5c7221d7d42ceefea649bcab48sf * operational if the retry timeout is elapsed.
18b5268e013574026b2503b1641baf3299045f45sf * The worker might still be unusable, but we try
18b5268e013574026b2503b1641baf3299045f45sf * anyway.
18b5268e013574026b2503b1641baf3299045f45sf */
18b5268e013574026b2503b1641baf3299045f45sf ap_proxy_retry_worker_fn("BALANCER", worker, r->server);
18b5268e013574026b2503b1641baf3299045f45sf if (PROXY_WORKER_IS_USABLE(worker)) {
18b5268e013574026b2503b1641baf3299045f45sf return worker;
404381a78d109fd3a4a7702e69815e4d7ff6d93asf } else {
404381a78d109fd3a4a7702e69815e4d7ff6d93asf /*
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * We have a worker that is unusable.
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * It can be in error or disabled, but in case
185aa71728867671e105178b4c66fbc22b65ae26sf * it has a redirection set use that redirection worker.
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * This enables to safely remove the member from the
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * balancer. Of course you will need some kind of
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq * session replication between those two remote.
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq */
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq if (*worker->s->redirect) {
18b5268e013574026b2503b1641baf3299045f45sf proxy_worker *rworker = NULL;
18b5268e013574026b2503b1641baf3299045f45sf rworker = find_route_worker(balancer, worker->s->redirect, r);
18b5268e013574026b2503b1641baf3299045f45sf /* Check if the redirect worker is usable */
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if (rworker && !PROXY_WORKER_IS_USABLE(rworker)) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes /*
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes * If the worker is in error state run
18b5268e013574026b2503b1641baf3299045f45sf * retry on that worker. It will be marked as
18b5268e013574026b2503b1641baf3299045f45sf * operational if the retry timeout is elapsed.
18b5268e013574026b2503b1641baf3299045f45sf * The worker might still be unusable, but we try
18b5268e013574026b2503b1641baf3299045f45sf * anyway.
18b5268e013574026b2503b1641baf3299045f45sf */
18b5268e013574026b2503b1641baf3299045f45sf ap_proxy_retry_worker_fn("BALANCER", rworker, r->server);
18b5268e013574026b2503b1641baf3299045f45sf }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (rworker && PROXY_WORKER_IS_USABLE(rworker))
18b5268e013574026b2503b1641baf3299045f45sf return rworker;
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf }
d9cc5de428947d5c7221d7d42ceefea649bcab48sf }
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf checked_standby = checking_standby++;
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf return NULL;
18b5268e013574026b2503b1641baf3299045f45sf}
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes
18b5268e013574026b2503b1641baf3299045f45sfstatic proxy_worker *find_session_route(proxy_balancer *balancer,
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes request_rec *r,
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf char **route,
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf const char **sticky_used,
185aa71728867671e105178b4c66fbc22b65ae26sf char **url)
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf{
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf proxy_worker *worker = NULL;
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf if (!*balancer->s->sticky)
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf return NULL;
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes /* Try to find the sticky route inside url */
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes *route = get_path_param(r->pool, *url, balancer->s->sticky_path, balancer->s->scolonsep);
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if (*route) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01159)
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes "Found value %s for stickysession %s",
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe *route, balancer->s->sticky_path);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe *sticky_used = balancer->s->sticky_path;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker else {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe *route = get_cookie_param(r, balancer->s->sticky);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (*route) {
d176cb9e596e4603f76490f9211f62b5581b3091rooneg *sticky_used = balancer->s->sticky;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01160)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe "Found value %s for stickysession %s",
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe *route, balancer->s->sticky);
d176cb9e596e4603f76490f9211f62b5581b3091rooneg }
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf }
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf /*
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * If we found a value for stickysession, find the first '.' (or whatever
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * sticky_separator is set to) within. Everything after '.' (if present)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * is our route.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((*route) && (balancer->s->sticky_separator != 0) && ((*route = strchr(*route, balancer->s->sticky_separator)) != NULL ))
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe (*route)++;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((*route) && (**route)) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01161) "Found route %s", *route);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /* We have a route in path or in cookie
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * Find the worker that has this route defined.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe worker = find_route_worker(balancer, *route, r);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (worker && strcmp(*route, worker->s->route)) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /*
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * Notice that the route of the worker chosen is different from
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * the route supplied by the client.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01162)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe "Route changed from %s to %s",
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe *route, worker->s->route);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return worker;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker else
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return NULL;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker}
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdstatic proxy_worker *find_best_worker(proxy_balancer *balancer,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd request_rec *r)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe{
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe proxy_worker *candidate = NULL;
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp apr_status_t rv;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01163)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd "%s: Lock failed for find_best_worker()",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd balancer->s->name);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return NULL;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd candidate = (*balancer->lbmethod->finder)(balancer, r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (candidate)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd candidate->s->elected++;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
f46cb698a1b32d16a0107566568f67d8c3f8ee9csf ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01164)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "%s: Unlock failed for find_best_worker()",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd balancer->s->name);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (candidate == NULL) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* All the workers are in error state or disabled.
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * If the balancer has a timeout sleep for a while
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * and try again to find the worker. The chances are
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * that some other thread will release a connection.
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * By default the timeout is not set, and the server
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * returns SERVER_BUSY.
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (balancer->s->timeout) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* XXX: This can perhaps be build using some
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * smarter mechanism, like tread_cond.
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * But since the statuses can came from
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * different childs, use the provided algo.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd apr_interval_time_t timeout = balancer->s->timeout;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker apr_interval_time_t step, tval = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Set the timeout to 0 so that we don't
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * end in infinite loop
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd balancer->s->timeout = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd step = timeout / 100;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd while (tval < timeout) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd apr_sleep(step);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Try again */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if ((candidate = find_best_worker(balancer, r)))
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe break;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd tval += step;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* restore the timeout */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe balancer->s->timeout = timeout;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return candidate;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int rewrite_url(request_rec *r, proxy_worker *worker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char **url)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *scheme = strstr(*url, "://");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *path = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (scheme)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb path = ap_strchr_c(scheme + 3, '/');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* we break the URL into host, port, uri */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!worker) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return ap_proxyerror(r, HTTP_BAD_REQUEST, apr_pstrcat(r->pool,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe "missing worker. URI cannot be parsed: ", *url,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker NULL));
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *url = apr_pstrcat(r->pool, worker->s->name, path, NULL);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return OK;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe}
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic void force_recovery(proxy_balancer *balancer, server_rec *s)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe int i;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe int ok = 0;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe proxy_worker **worker;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe worker = (proxy_worker **)balancer->workers->elts;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz for (i = 0; i < balancer->workers->nelts; i++, worker++) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ok = 1;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe break;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe else {
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz /* Try if we can recover */
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz ap_proxy_retry_worker_fn("BALANCER", *worker, s);
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
1e911973bcb9df6701a4c16c037771ecf25ade13niq ok = 1;
1e911973bcb9df6701a4c16c037771ecf25ade13niq break;
c3e233736c4a453cbb2166a041f779e86230630asf }
c3e233736c4a453cbb2166a041f779e86230630asf }
c3e233736c4a453cbb2166a041f779e86230630asf }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (!ok && balancer->s->forcerecovery) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar /* If all workers are in error state force the recovery.
11fb2f3611e6ff9a541e10b13e3108934f828141gregames */
11fb2f3611e6ff9a541e10b13e3108934f828141gregames worker = (proxy_worker **)balancer->workers->elts;
11fb2f3611e6ff9a541e10b13e3108934f828141gregames for (i = 0; i < balancer->workers->nelts; i++, worker++) {
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz ++(*worker)->s->retries;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz (*worker)->s->status &= ~PROXY_WORKER_IN_ERROR;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01165)
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz "%s: Forcing recovery for worker (%s)",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker balancer->s->name, (*worker)->s->hostname);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe}
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic apr_status_t decrement_busy_count(void *worker_)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe proxy_worker *worker = worker_;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
c3e233736c4a453cbb2166a041f779e86230630asf if (worker->s->busy) {
c3e233736c4a453cbb2166a041f779e86230630asf worker->s->busy--;
c3e233736c4a453cbb2166a041f779e86230630asf }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar return APR_SUCCESS;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar}
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
c3e233736c4a453cbb2166a041f779e86230630asfstatic int proxy_balancer_pre_request(proxy_worker **worker,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe proxy_balancer **balancer,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar request_rec *r,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe proxy_server_conf *conf, char **url)
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe int access_status;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar proxy_worker *runtime;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe char *route = NULL;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe const char *sticky = NULL;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe apr_status_t rv;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz *worker = NULL;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz /* Step 1: check if the url is for us
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz * The url we can handle starts with 'balancer://'
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * If balancer is already provided skip the search
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * for balancer, because this is failover attempt.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!*balancer &&
8aefbd756763807188d2e3ce336a8680e4893066wrowe !(*balancer = ap_proxy_get_balancer(r->pool, conf, *url, 1)))
700b96db75e7cfadb5219978c1735b710d583763wrowe return DECLINED;
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Step 2: Lock the LoadBalancer
700b96db75e7cfadb5219978c1735b710d583763wrowe * XXX: perhaps we need the process lock here
700b96db75e7cfadb5219978c1735b710d583763wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((rv = PROXY_THREAD_LOCK(*balancer)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01166)
700b96db75e7cfadb5219978c1735b710d583763wrowe "%s: Lock failed for pre_request", (*balancer)->s->name);
700b96db75e7cfadb5219978c1735b710d583763wrowe return DECLINED;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Step 3: force recovery */
700b96db75e7cfadb5219978c1735b710d583763wrowe force_recovery(*balancer, r->server);
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Step 3.5: Update member list for the balancer */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* TODO: Implement as provider! */
103a93c625bcde1a6a7a5155b64dcda36f612180pquerna ap_proxy_sync_balancer(*balancer, r->server, conf);
113961f0559eb026ea0d379cb7350f82bc09d710druggeri
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Step 4: find the session route */
700b96db75e7cfadb5219978c1735b710d583763wrowe runtime = find_session_route(*balancer, r, &route, &sticky, url);
6964758306167dd898baedd21048bd1515dd9d30trawick if (runtime) {
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((*balancer)->lbmethod && (*balancer)->lbmethod->updatelbstatus) {
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf /* Call the LB implementation */
700b96db75e7cfadb5219978c1735b710d583763wrowe (*balancer)->lbmethod->updatelbstatus(*balancer, runtime, r->server);
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe else { /* Use the default one */
700b96db75e7cfadb5219978c1735b710d583763wrowe int i, total_factor = 0;
700b96db75e7cfadb5219978c1735b710d583763wrowe proxy_worker **workers;
700b96db75e7cfadb5219978c1735b710d583763wrowe /* We have a sticky load balancer
700b96db75e7cfadb5219978c1735b710d583763wrowe * Update the workers status
700b96db75e7cfadb5219978c1735b710d583763wrowe * so that even session routes get
700b96db75e7cfadb5219978c1735b710d583763wrowe * into account.
700b96db75e7cfadb5219978c1735b710d583763wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe workers = (proxy_worker **)(*balancer)->workers->elts;
700b96db75e7cfadb5219978c1735b710d583763wrowe for (i = 0; i < (*balancer)->workers->nelts; i++) {
700b96db75e7cfadb5219978c1735b710d583763wrowe /* Take into calculation only the workers that are
700b96db75e7cfadb5219978c1735b710d583763wrowe * not in error state or not disabled.
700b96db75e7cfadb5219978c1735b710d583763wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe if (PROXY_WORKER_IS_USABLE(*workers)) {
700b96db75e7cfadb5219978c1735b710d583763wrowe (*workers)->s->lbstatus += (*workers)->s->lbfactor;
700b96db75e7cfadb5219978c1735b710d583763wrowe total_factor += (*workers)->s->lbfactor;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe workers++;
103a93c625bcde1a6a7a5155b64dcda36f612180pquerna }
103a93c625bcde1a6a7a5155b64dcda36f612180pquerna runtime->s->lbstatus -= total_factor;
113961f0559eb026ea0d379cb7350f82bc09d710druggeri }
113961f0559eb026ea0d379cb7350f82bc09d710druggeri runtime->s->elected++;
113961f0559eb026ea0d379cb7350f82bc09d710druggeri
113961f0559eb026ea0d379cb7350f82bc09d710druggeri *worker = runtime;
113961f0559eb026ea0d379cb7350f82bc09d710druggeri }
700b96db75e7cfadb5219978c1735b710d583763wrowe else if (route && (*balancer)->s->sticky_force) {
700b96db75e7cfadb5219978c1735b710d583763wrowe int i, member_of = 0;
700b96db75e7cfadb5219978c1735b710d583763wrowe proxy_worker **workers;
8aefbd756763807188d2e3ce336a8680e4893066wrowe /*
8aefbd756763807188d2e3ce336a8680e4893066wrowe * We have a route provided that doesn't match the
8aefbd756763807188d2e3ce336a8680e4893066wrowe * balancer name. See if the provider route is the
8aefbd756763807188d2e3ce336a8680e4893066wrowe * member of the same balancer in which case return 503
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe workers = (proxy_worker **)(*balancer)->workers->elts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (i = 0; i < (*balancer)->workers->nelts; i++) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (*((*workers)->s->route) && strcmp((*workers)->s->route, route) == 0) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe member_of = 1;
8aefbd756763807188d2e3ce336a8680e4893066wrowe break;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe workers++;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (member_of) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01167)
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe "%s: All workers are in error state for route (%s)",
8aefbd756763807188d2e3ce336a8680e4893066wrowe (*balancer)->s->name, route);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01168)
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf "%s: Unlock failed for pre_request",
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe (*balancer)->s->name);
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return HTTP_SERVICE_UNAVAILABLE;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01169)
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe "%s: Unlock failed for pre_request",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (*balancer)->s->name);
23c6309e36a63b13b61c35999c978017521993d6wrowe }
23c6309e36a63b13b61c35999c978017521993d6wrowe if (!*worker) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker runtime = find_best_worker(*balancer, r);
23c6309e36a63b13b61c35999c978017521993d6wrowe if (!runtime) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((*balancer)->workers->nelts) {
23c6309e36a63b13b61c35999c978017521993d6wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01170)
185aa71728867671e105178b4c66fbc22b65ae26sf "%s: All workers are in error state",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (*balancer)->s->name);
23c6309e36a63b13b61c35999c978017521993d6wrowe } else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01171)
8aefbd756763807188d2e3ce336a8680e4893066wrowe "%s: No workers in balancer",
8aefbd756763807188d2e3ce336a8680e4893066wrowe (*balancer)->s->name);
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe return HTTP_SERVICE_UNAVAILABLE;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (*(*balancer)->s->sticky && runtime) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * This balancer has sticky sessions and the client either has not
185aa71728867671e105178b4c66fbc22b65ae26sf * supplied any routing information or all workers for this route
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * including possible redirect and hotstandby workers are in error
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * state, but we have found another working worker for this
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe * balancer where we can send the request. Thus notice that we have
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * changed the route to the backend.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe *worker = runtime;
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe (*worker)->s->busy++;
cf6ef072483172309861d06e85b1aeff4573c060wrowe apr_pool_cleanup_register(r->pool, *worker, decrement_busy_count,
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp apr_pool_cleanup_null);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Add balancer/worker info to env. */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker apr_table_setn(r->subprocess_env,
cf6ef072483172309861d06e85b1aeff4573c060wrowe "BALANCER_NAME", (*balancer)->s->name);
cf6ef072483172309861d06e85b1aeff4573c060wrowe apr_table_setn(r->subprocess_env,
cf6ef072483172309861d06e85b1aeff4573c060wrowe "BALANCER_WORKER_NAME", (*worker)->s->name);
cf6ef072483172309861d06e85b1aeff4573c060wrowe apr_table_setn(r->subprocess_env,
cf6ef072483172309861d06e85b1aeff4573c060wrowe "BALANCER_WORKER_ROUTE", (*worker)->s->route);
cf6ef072483172309861d06e85b1aeff4573c060wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Rewrite the url from 'balancer://url'
cf6ef072483172309861d06e85b1aeff4573c060wrowe * to the 'worker_scheme://worker_hostname[:worker_port]/url'
cf6ef072483172309861d06e85b1aeff4573c060wrowe * This replaces the balancers fictional name with the
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick * real hostname of the elected worker.
ecde48c75338ff5712f2036711f813c6dedca28ewrowe */
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick access_status = rewrite_url(r, *worker, url);
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick /* Add the session route to request notes if present */
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick if (route) {
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick apr_table_setn(r->notes, "session-sticky", sticky);
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick apr_table_setn(r->notes, "session-route", route);
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick /* Add session info to env. */
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick apr_table_setn(r->subprocess_env,
ecde48c75338ff5712f2036711f813c6dedca28ewrowe "BALANCER_SESSION_STICKY", sticky);
ecde48c75338ff5712f2036711f813c6dedca28ewrowe apr_table_setn(r->subprocess_env,
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick "BALANCER_SESSION_ROUTE", route);
ecde48c75338ff5712f2036711f813c6dedca28ewrowe }
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01172)
ecde48c75338ff5712f2036711f813c6dedca28ewrowe "%s: worker (%s) rewritten to %s",
ecde48c75338ff5712f2036711f813c6dedca28ewrowe (*balancer)->s->name, (*worker)->s->name, *url);
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick return access_status;
cf6ef072483172309861d06e85b1aeff4573c060wrowe}
cf6ef072483172309861d06e85b1aeff4573c060wrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarstatic int proxy_balancer_post_request(proxy_worker *worker,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_balancer *balancer,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar request_rec *r,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar proxy_server_conf *conf)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe{
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_status_t rv;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01173)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Lock failed for post_request",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd balancer->s->name);
23c6309e36a63b13b61c35999c978017521993d6wrowe return HTTP_INTERNAL_SERVER_ERROR;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (!apr_is_empty_array(balancer->errstatuses)) {
c2cf53a40a9814eb91db2cdf820f97d943f21628coar int i;
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem for (i = 0; i < balancer->errstatuses->nelts; i++) {
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem int val = ((int *)balancer->errstatuses->elts)[i];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (r->status == val) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01174)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Forcing worker (%s%s) into error state "
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "due to status code %d matching 'failonstatus' "
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "balancer parameter",
a9a4544168a37b43bd180b3703ccee995f27a80awrowe balancer->s->name, worker->s->name,
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem (worker->s->uds?"|":""), val);
a9a4544168a37b43bd180b3703ccee995f27a80awrowe worker->s->status |= PROXY_WORKER_IN_ERROR;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker worker->s->error_time = apr_time_now();
a9a4544168a37b43bd180b3703ccee995f27a80awrowe break;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem }
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem }
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem if (balancer->failontimeout
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem && (apr_table_get(r->notes, "proxy_timedout")) != NULL) {
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02460)
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem "%s: Forcing worker (%s%s) into error state "
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem "due to timeout and 'failonstatus' parameter being set",
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem balancer->s->name, worker->s->name, (worker->s->uds?"|":""));
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf worker->s->status |= PROXY_WORKER_IN_ERROR;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem worker->s->error_time = apr_time_now();
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem }
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01175)
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem "%s: Unlock failed for post_request", balancer->s->name);
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem }
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01176)
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem "proxy_balancer_post_request for (%s)", balancer->s->name);
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem return OK;
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem}
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem
eb12400ff685a3b69476736ca4b5389f348b9d63rpluemstatic void recalc_factors(proxy_balancer *balancer)
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem{
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem int i;
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem proxy_worker **workers;
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem /* Recalculate lbfactors */
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem workers = (proxy_worker **)balancer->workers->elts;
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem /* Special case if there is only one worker its
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem * load factor will always be 1
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem */
185aa71728867671e105178b4c66fbc22b65ae26sf if (balancer->workers->nelts == 1) {
75c02648f9afe9a1da5d5482703fcbca306ffcdcpquerna (*workers)->s->lbstatus = (*workers)->s->lbfactor = 1;
75c02648f9afe9a1da5d5482703fcbca306ffcdcpquerna return;
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem }
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem for (i = 0; i < balancer->workers->nelts; i++) {
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem /* Update the status entries */
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem workers[i]->s->lbstatus = workers[i]->s->lbfactor;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem }
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem}
185aa71728867671e105178b4c66fbc22b65ae26sf
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluemstatic apr_status_t lock_remove(void *data)
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem{
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem int i;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem proxy_balancer *balancer;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem server_rec *s = data;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem void *sconf = s->module_config;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem proxy_server_conf *conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
a9a4544168a37b43bd180b3703ccee995f27a80awrowe
a9a4544168a37b43bd180b3703ccee995f27a80awrowe balancer = (proxy_balancer *)conf->balancers->elts;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (balancer->gmutex) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_global_mutex_destroy(balancer->gmutex);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar balancer->gmutex = NULL;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return(0);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker}
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* post_config hook: */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowestatic int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_pool_t *ptemp, server_rec *s)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_status_t rv;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_server_conf *conf;
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_slotmem_instance_t *new = NULL;
cf6ef072483172309861d06e85b1aeff4573c060wrowe apr_time_t tstamp;
cf6ef072483172309861d06e85b1aeff4573c060wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* balancer_post_config() will be called twice during startup. So, don't
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * set up the static data the 1st time through. */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return OK;
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz }
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz if (!ap_proxy_retry_worker_fn) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_proxy_retry_worker_fn =
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe APR_RETRIEVE_OPTIONAL_FN(ap_proxy_retry_worker);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if (!ap_proxy_retry_worker_fn) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(02230)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "mod_proxy must be loaded for mod_proxy_balancer");
3dcf67a5060400edb8ccef3fb4a2024388965af9martin return !OK;
3dcf67a5060400edb8ccef3fb4a2024388965af9martin }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
2fd8d1e14fc47762d1e01660b544d5e2a75c825dtrawick
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Get slotmem setups
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe storage = ap_lookup_provider(AP_SLOTMEM_PROVIDER_GROUP, "shm",
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf AP_SLOTMEM_PROVIDER_VERSION);
700b96db75e7cfadb5219978c1735b710d583763wrowe if (!storage) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01177)
700b96db75e7cfadb5219978c1735b710d583763wrowe "Failed to lookup provider 'shm' for '%s': is "
700b96db75e7cfadb5219978c1735b710d583763wrowe "mod_slotmem_shm loaded??",
e0c4ebfec83bb3b424184984e5788f31297fe429sctemme AP_SLOTMEM_PROVIDER_GROUP);
113961f0559eb026ea0d379cb7350f82bc09d710druggeri return !OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker tstamp = apr_time_now();
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /*
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * Go thru each Vhost and create the shared mem slotmem for
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * each balancer's workers
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe while (s) {
59513b1275fdc2021d4949ee03ae8229469abb86wrowe int i,j;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker char *id;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe proxy_balancer *balancer;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_slotmem_type_t type;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker void *sconf = s->module_config;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /*
185aa71728867671e105178b4c66fbc22b65ae26sf * During create_proxy_config() we created a dummy id. Now that
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * we have identifying info, we can create the real id
4f9c22c4f27571d54197be9674e1fc0d528192aestriker */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe id = apr_psprintf(pconf, "%s.%s.%d.%s.%s.%u.%s",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (s->server_scheme ? s->server_scheme : "????"),
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (s->server_hostname ? s->server_hostname : "???"),
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (int)s->port,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (s->server_admin ? s->server_admin : "??"),
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (s->defn_name ? s->defn_name : "?"),
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe s->defn_line_number,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (s->error_fname ? s->error_fname : DEFAULT_ERRORLOG));
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe conf->id = apr_psprintf(pconf, "p%x",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_proxy_hashfunc(id, PROXY_HASHFUNC_DEFAULT));
cf6ef072483172309861d06e85b1aeff4573c060wrowe if (conf->bslot) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Shared memory already created for this proxy_server_conf.
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker s = s->next;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe continue;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (conf->bal_persist) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe type = AP_SLOTMEM_TYPE_PERSIST;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe } else {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker type = 0;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (conf->balancers->nelts) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe conf->max_balancers = conf->balancers->nelts + conf->bgrowth;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01178) "Doing balancers create: %d, %d (%d)",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (int)ALIGNED_PROXY_BALANCER_SHARED_SIZE,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (int)conf->balancers->nelts, conf->max_balancers);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe rv = storage->create(&new, conf->id,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ALIGNED_PROXY_BALANCER_SHARED_SIZE,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe conf->max_balancers, type, pconf);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if (rv != APR_SUCCESS) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01179) "balancer slotmem_create failed");
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe return !OK;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe conf->bslot = new;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker conf->storage = storage;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Initialize shared scoreboard data */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe balancer = (proxy_balancer *)conf->balancers->elts;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe proxy_worker **workers;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe proxy_worker *worker;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe proxy_balancer_shared *bshm;
cf6ef072483172309861d06e85b1aeff4573c060wrowe const char *sname;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker unsigned int index;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* now that we have the right id, we need to redo the sname field */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_pstr2_alnum(pconf, balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe &sname);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe sname = apr_pstrcat(pconf, conf->id, "_", sname, NULL);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe PROXY_STRNCPY(balancer->s->sname, sname); /* We know this will succeed */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe balancer->max_workers = balancer->workers->nelts + balancer->growth;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Create global mutex */
38bcc87d9a06e8ba81165421403f275eca4e313btrawick rv = ap_global_mutex_create(&(balancer->gmutex), NULL, balancer_mutex_type,
38bcc87d9a06e8ba81165421403f275eca4e313btrawick balancer->s->sname, s, pconf, 0);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if (rv != APR_SUCCESS || !balancer->gmutex) {
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01180)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "mutex creation of %s : %s failed", balancer_mutex_type,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe balancer->s->sname);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe return HTTP_INTERNAL_SERVER_ERROR;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
185aa71728867671e105178b4c66fbc22b65ae26sf
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe apr_pool_cleanup_register(pconf, (void *)s, lock_remove,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker apr_pool_cleanup_null);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* setup shm for balancers */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe bshm = ap_proxy_find_balancershm(storage, conf->bslot, balancer, &index);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if (bshm) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if ((rv = storage->fgrab(conf->bslot, index)) != APR_SUCCESS) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02408) "balancer slotmem_fgrab failed");
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz return !OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
cf6ef072483172309861d06e85b1aeff4573c060wrowe if ((rv = storage->grab(conf->bslot, &index)) != APR_SUCCESS) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed");
8aefbd756763807188d2e3ce336a8680e4893066wrowe return !OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = storage->dptr(conf->bslot, index, (void *)&bshm)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed");
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return !OK;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = ap_proxy_share_balancer(balancer, bshm, index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01183) "Cannot share balancer");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return !OK;
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* create slotmem slots for workers */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01184) "Doing workers create: %s (%s), %d, %d [%u]",
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz balancer->s->name, balancer->s->sname,
cf6ef072483172309861d06e85b1aeff4573c060wrowe (int)ALIGNED_PROXY_WORKER_SHARED_SIZE,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe (int)balancer->max_workers, i);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe rv = storage->create(&new, balancer->s->sname,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ALIGNED_PROXY_WORKER_SHARED_SIZE,
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz balancer->max_workers, type, pconf);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (rv != APR_SUCCESS) {
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01185) "worker slotmem_create failed");
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz return !OK;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz balancer->wslot = new;
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz balancer->storage = storage;
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* sync all timestamps */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar balancer->wupdated = balancer->s->wupdated = tstamp;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* now go thru each worker */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe workers = (proxy_worker **)balancer->workers->elts;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe for (j = 0; j < balancer->workers->nelts; j++, workers++) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_worker_shared *shm;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe worker = *workers;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf shm = ap_proxy_find_workershm(storage, balancer->wslot, worker, &index);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (shm) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = storage->fgrab(balancer->wslot, index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02409) "worker slotmem_fgrab failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return !OK;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = storage->grab(balancer->wslot, &index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01186) "worker slotmem_grab failed");
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return !OK;
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe 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");
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe return !OK;
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe }
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe }
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick if ((rv = ap_proxy_share_worker(worker, shm, index)) != APR_SUCCESS) {
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01188) "Cannot share worker");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return !OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe worker->s->updated = tstamp;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe if (conf->bal_persist) {
700b96db75e7cfadb5219978c1735b710d583763wrowe /* We could have just read-in a persisted config. Force a sync. */
700b96db75e7cfadb5219978c1735b710d583763wrowe balancer->wupdated--;
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_proxy_sync_balancer(balancer, s, conf);
700b96db75e7cfadb5219978c1735b710d583763wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe s = s->next;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe}
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowestatic void create_radio(const char *name, unsigned int flag, request_rec *r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe{
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, "<td>On <input name='", name, "' id='", name, "' value='1' type=radio", NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (flag)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_rputs(" checked", r);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_rvputs(r, "> <br/> Off <input name='", name, "' id='", name, "' value='0' type=radio", NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!flag)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_rputs(" checked", r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs("></td>\n", r);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarstatic void push2table(const char *input, apr_table_t *params,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker const char *allowed[], apr_pool_t *p)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *args;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar char *tok, *val;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar char *key;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (input == NULL) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe args = apr_pstrdup(p, input);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe key = apr_strtok(args, "&", &tok);
8aefbd756763807188d2e3ce336a8680e4893066wrowe while (key) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe val = strchr(key, '=');
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (val) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe *val++ = '\0';
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe val = "";
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e8f95a682820a599fe41b22977010636be5c2717jim ap_unescape_url(key);
e8f95a682820a599fe41b22977010636be5c2717jim ap_unescape_url(val);
700b96db75e7cfadb5219978c1735b710d583763wrowe if (allowed == NULL) { /* allow all */
113961f0559eb026ea0d379cb7350f82bc09d710druggeri apr_table_set(params, key, val);
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe else {
700b96db75e7cfadb5219978c1735b710d583763wrowe const char **ok = allowed;
113961f0559eb026ea0d379cb7350f82bc09d710druggeri while (*ok) {
700b96db75e7cfadb5219978c1735b710d583763wrowe if (strcmp(*ok, key) == 0) {
113961f0559eb026ea0d379cb7350f82bc09d710druggeri apr_table_set(params, key, val);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe break;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ok++;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe key = apr_strtok(NULL, "&", &tok);
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe}
700b96db75e7cfadb5219978c1735b710d583763wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* Manages the loadfactors and member status
700b96db75e7cfadb5219978c1735b710d583763wrowe * The balancer, worker and nonce are obtained from
700b96db75e7cfadb5219978c1735b710d583763wrowe * the request args (?b=...&w=...&nonce=....).
700b96db75e7cfadb5219978c1735b710d583763wrowe * All other params are pulled from any POST
700b96db75e7cfadb5219978c1735b710d583763wrowe * data that exists.
700b96db75e7cfadb5219978c1735b710d583763wrowe * TODO:
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * /.../<whatever>/balancer/worker/nonce
700b96db75e7cfadb5219978c1735b710d583763wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowestatic int balancer_handler(request_rec *r)
700b96db75e7cfadb5219978c1735b710d583763wrowe{
700b96db75e7cfadb5219978c1735b710d583763wrowe void *sconf;
700b96db75e7cfadb5219978c1735b710d583763wrowe proxy_server_conf *conf;
700b96db75e7cfadb5219978c1735b710d583763wrowe proxy_balancer *balancer, *bsel = NULL;
700b96db75e7cfadb5219978c1735b710d583763wrowe proxy_worker *worker, *wsel = NULL;
700b96db75e7cfadb5219978c1735b710d583763wrowe proxy_worker **workers = NULL;
700b96db75e7cfadb5219978c1735b710d583763wrowe apr_table_t *params;
700b96db75e7cfadb5219978c1735b710d583763wrowe int i, n;
700b96db75e7cfadb5219978c1735b710d583763wrowe int ok2change = 1;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar const char *name;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *action;
700b96db75e7cfadb5219978c1735b710d583763wrowe apr_status_t rv;
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe /* is this for us? */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (strcmp(r->handler, "balancer-manager")) {
700b96db75e7cfadb5219978c1735b710d583763wrowe return DECLINED;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->allowed = 0
700b96db75e7cfadb5219978c1735b710d583763wrowe | (AP_METHOD_BIT << M_GET)
700b96db75e7cfadb5219978c1735b710d583763wrowe | (AP_METHOD_BIT << M_POST);
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((r->method_number != M_GET) && (r->method_number != M_POST)) {
700b96db75e7cfadb5219978c1735b710d583763wrowe return DECLINED;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe sconf = r->server->module_config;
700b96db75e7cfadb5219978c1735b710d583763wrowe conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
700b96db75e7cfadb5219978c1735b710d583763wrowe params = apr_table_make(r->pool, 10);
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe balancer = (proxy_balancer *)conf->balancers->elts;
700b96db75e7cfadb5219978c1735b710d583763wrowe for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
700b96db75e7cfadb5219978c1735b710d583763wrowe if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01189)
700b96db75e7cfadb5219978c1735b710d583763wrowe "%s: Lock failed for balancer_handler",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe balancer->s->name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_proxy_sync_balancer(balancer, r->server, conf);
2520f59894a3e07fefa881ef68aaded763a8d447ben if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01190)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "%s: Unlock failed for balancer_handler",
8aefbd756763807188d2e3ce336a8680e4893066wrowe balancer->s->name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (r->args && (r->method_number == M_GET)) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar const char *allowed[] = { "w", "b", "nonce", "xml", NULL };
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01191) "parsing r->args");
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe push2table(r->args, params, allowed, r->pool);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (r->method_number == M_POST) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker apr_bucket_brigade *ib;
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz apr_size_t len = 1024;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *buf = apr_pcalloc(r->pool, len+1);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz ib = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe rv = ap_get_brigade(r->input_filters, ib, AP_MODE_READBYTES,
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz APR_BLOCK_READ, len);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz if (rv != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return HTTP_INTERNAL_SERVER_ERROR;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_brigade_flatten(ib, buf, &len);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe buf[len] = '\0';
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz push2table(buf, params, NULL, r->pool);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz }
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz if ((name = apr_table_get(params, "b")))
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz bsel = ap_proxy_get_balancer(r->pool, conf,
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_pstrcat(r->pool, BALANCER_PREFIX, name, NULL), 0);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((name = apr_table_get(params, "w"))) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker wsel = ap_proxy_get_worker(r->pool, bsel, conf, name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
ecde48c75338ff5712f2036711f813c6dedca28ewrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Check that the supplied nonce matches this server's nonce;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar * otherwise ignore all parameters, to prevent a CSRF attack. */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!bsel ||
cf6ef072483172309861d06e85b1aeff4573c060wrowe (*bsel->s->nonce &&
cf6ef072483172309861d06e85b1aeff4573c060wrowe (
cf6ef072483172309861d06e85b1aeff4573c060wrowe (name = apr_table_get(params, "nonce")) == NULL ||
cf6ef072483172309861d06e85b1aeff4573c060wrowe strcmp(bsel->s->nonce, name) != 0
cf6ef072483172309861d06e85b1aeff4573c060wrowe )
cf6ef072483172309861d06e85b1aeff4573c060wrowe )
cf6ef072483172309861d06e85b1aeff4573c060wrowe ) {
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick apr_table_clear(params);
cf6ef072483172309861d06e85b1aeff4573c060wrowe ok2change = 0;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe /* First set the params */
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe if (wsel && ok2change) {
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe const char *val;
cf6ef072483172309861d06e85b1aeff4573c060wrowe int was_usable = PROXY_WORKER_IS_USABLE(wsel);
cf6ef072483172309861d06e85b1aeff4573c060wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01192) "settings worker params");
cf6ef072483172309861d06e85b1aeff4573c060wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((val = apr_table_get(params, "w_lf"))) {
e8f95a682820a599fe41b22977010636be5c2717jim int ival = atoi(val);
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick if (ival >= 1 && ival <= 100) {
e8f95a682820a599fe41b22977010636be5c2717jim wsel->s->lbfactor = ival;
e8f95a682820a599fe41b22977010636be5c2717jim if (bsel)
e8f95a682820a599fe41b22977010636be5c2717jim recalc_factors(bsel);
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick if ((val = apr_table_get(params, "w_wr"))) {
e8f95a682820a599fe41b22977010636be5c2717jim if (strlen(val) && strlen(val) < sizeof(wsel->s->route))
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick strcpy(wsel->s->route, val);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe *wsel->s->route = '\0';
c2cf53a40a9814eb91db2cdf820f97d943f21628coar }
c2cf53a40a9814eb91db2cdf820f97d943f21628coar if ((val = apr_table_get(params, "w_rr"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (strlen(val) && strlen(val) < sizeof(wsel->s->redirect))
cf6ef072483172309861d06e85b1aeff4573c060wrowe strcpy(wsel->s->redirect, val);
8aefbd756763807188d2e3ce336a8680e4893066wrowe else
8aefbd756763807188d2e3ce336a8680e4893066wrowe *wsel->s->redirect = '\0';
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
185aa71728867671e105178b4c66fbc22b65ae26sf if ((val = apr_table_get(params, "w_status_I"))) {
a1072ba3065ee7e37162e72f2fd4e7b209e49a33covener ap_proxy_set_wstatus('I', atoi(val), wsel);
a1072ba3065ee7e37162e72f2fd4e7b209e49a33covener }
a1072ba3065ee7e37162e72f2fd4e7b209e49a33covener if ((val = apr_table_get(params, "w_status_N"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_proxy_set_wstatus('N', atoi(val), wsel);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((val = apr_table_get(params, "w_status_D"))) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_proxy_set_wstatus('D', atoi(val), wsel);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((val = apr_table_get(params, "w_status_H"))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_proxy_set_wstatus('H', atoi(val), wsel);
185aa71728867671e105178b4c66fbc22b65ae26sf }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((val = apr_table_get(params, "w_ls"))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int ival = atoi(val);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (ival >= 0 && ival <= 99) {
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe wsel->s->lbset = ival;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* if enabling, we need to reset all lb params */
cf6ef072483172309861d06e85b1aeff4573c060wrowe if (bsel && !was_usable && PROXY_WORKER_IS_USABLE(wsel)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->s->need_reset = 1;
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz if (bsel && ok2change) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *val;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int ival;
cf6ef072483172309861d06e85b1aeff4573c060wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01193)
cf6ef072483172309861d06e85b1aeff4573c060wrowe "settings balancer params");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((val = apr_table_get(params, "b_lbm"))) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((strlen(val) < (sizeof(bsel->s->lbpname)-1)) &&
700b96db75e7cfadb5219978c1735b710d583763wrowe strcmp(val, bsel->s->lbpname)) {
185aa71728867671e105178b4c66fbc22b65ae26sf proxy_balancer_method *lbmethod;
71fe373d064756fb261876443806ece033ee3309slive lbmethod = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
71fe373d064756fb261876443806ece033ee3309slive if (lbmethod) {
c2cf53a40a9814eb91db2cdf820f97d943f21628coar PROXY_STRNCPY(bsel->s->lbpname, val);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->lbmethod = lbmethod;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->s->wupdated = apr_time_now();
ecde48c75338ff5712f2036711f813c6dedca28ewrowe bsel->s->need_reset = 1;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
ecde48c75338ff5712f2036711f813c6dedca28ewrowe }
ecde48c75338ff5712f2036711f813c6dedca28ewrowe }
e8f95a682820a599fe41b22977010636be5c2717jim if ((val = apr_table_get(params, "b_tmo"))) {
ecde48c75338ff5712f2036711f813c6dedca28ewrowe ival = atoi(val);
ecde48c75338ff5712f2036711f813c6dedca28ewrowe if (ival >= 0 && ival <= 7200) { /* 2 hrs enuff? */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->s->timeout = apr_time_from_sec(ival);
ecde48c75338ff5712f2036711f813c6dedca28ewrowe }
ecde48c75338ff5712f2036711f813c6dedca28ewrowe }
ecde48c75338ff5712f2036711f813c6dedca28ewrowe if ((val = apr_table_get(params, "b_max"))) {
185aa71728867671e105178b4c66fbc22b65ae26sf ival = atoi(val);
ecde48c75338ff5712f2036711f813c6dedca28ewrowe if (ival >= 0 && ival <= 99) {
ecde48c75338ff5712f2036711f813c6dedca28ewrowe bsel->s->max_attempts = ival;
ecde48c75338ff5712f2036711f813c6dedca28ewrowe }
ecde48c75338ff5712f2036711f813c6dedca28ewrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((val = apr_table_get(params, "b_sforce"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ival = atoi(val);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->s->sticky_force = (ival != 0);
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe if ((val = apr_table_get(params, "b_ss")) && *val) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe if (strlen(val) < (sizeof(bsel->s->sticky_path)-1)) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe if (*val == '-' && *(val+1) == '\0')
cf6ef072483172309861d06e85b1aeff4573c060wrowe *bsel->s->sticky_path = *bsel->s->sticky = '\0';
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick else {
cf6ef072483172309861d06e85b1aeff4573c060wrowe char *path;
cf6ef072483172309861d06e85b1aeff4573c060wrowe PROXY_STRNCPY(bsel->s->sticky_path, val);
cf6ef072483172309861d06e85b1aeff4573c060wrowe PROXY_STRNCPY(bsel->s->sticky, val);
cf6ef072483172309861d06e85b1aeff4573c060wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe if ((path = strchr((char *)bsel->s->sticky, '|'))) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe *path++ = '\0';
cf6ef072483172309861d06e85b1aeff4573c060wrowe PROXY_STRNCPY(bsel->s->sticky_path, path);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe if ((val = apr_table_get(params, "b_wyes")) &&
cf6ef072483172309861d06e85b1aeff4573c060wrowe (*val == '1' && *(val+1) == '\0') &&
cf6ef072483172309861d06e85b1aeff4573c060wrowe (val = apr_table_get(params, "b_nwrkr"))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *ret;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_worker *nworker;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe nworker = ap_proxy_get_worker(r->pool, bsel, conf, val);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!nworker && storage->num_free_slots(bsel->wslot)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_GLOBAL_LOCK(bsel)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01194)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Lock failed for adding worker",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker bsel->s->name);
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ret = ap_proxy_define_worker(conf->pool, &nworker, bsel, conf, val, 0);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (!ret) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe unsigned int index;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar proxy_worker_shared *shm;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe PROXY_COPY_CONF_PARAMS(nworker, conf);
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener if ((rv = storage->grab(bsel->wslot, &index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01195)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "worker slotmem_grab failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
700b96db75e7cfadb5219978c1735b710d583763wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01196)
700b96db75e7cfadb5219978c1735b710d583763wrowe "%s: Unlock failed for adding worker",
700b96db75e7cfadb5219978c1735b710d583763wrowe bsel->s->name);
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe return HTTP_BAD_REQUEST;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = storage->dptr(bsel->wslot, index, (void *)&shm)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01197)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "worker slotmem_dptr failed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01198)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Unlock failed for adding worker",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->s->name);
700b96db75e7cfadb5219978c1735b710d583763wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return HTTP_BAD_REQUEST;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = ap_proxy_share_worker(nworker, shm, index)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01199)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "Cannot share worker");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01200)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd "%s: Unlock failed for adding worker",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->s->name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar return HTTP_BAD_REQUEST;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = ap_proxy_initialize_worker(nworker, r->server, conf->pool)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01201)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "Cannot init worker");
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01202)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "%s: Unlock failed for adding worker",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->s->name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return HTTP_BAD_REQUEST;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* sync all timestamps */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe bsel->wupdated = bsel->s->wupdated = nworker->s->updated = apr_time_now();
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* by default, all new workers are disabled */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_proxy_set_wstatus('D', 1, nworker);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01203)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "%s: Unlock failed for adding worker",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd bsel->s->name);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
c2cf53a40a9814eb91db2cdf820f97d943f21628coar
c2cf53a40a9814eb91db2cdf820f97d943f21628coar action = ap_construct_url(r->pool, r->uri, r);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01204) "genning page");
c2cf53a40a9814eb91db2cdf820f97d943f21628coar
0ec08ecdcb42129d147888bda504787b164da39cerikabele if (apr_table_get(params, "xml")) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe char date[APR_RFC822_DATE_LEN];
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_set_content_type(r, "text/xml");
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rputs("<?xml version='1.0' encoding='UTF-8' ?>\n", r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rputs("<httpd:manager xmlns:httpd='http://httpd.apache.org'>\n", r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rputs(" <httpd:balancers>\n", r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe balancer = (proxy_balancer *)conf->balancers->elts;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe for (i = 0; i < conf->balancers->nelts; i++) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rputs(" <httpd:balancer>\n", r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Start proxy_balancer */
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rvputs(r, " <httpd:name>", balancer->s->name, "</httpd:name>\n", NULL);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar if (balancer->s->sticky) {
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_rvputs(r, " <httpd:stickysession>", balancer->s->sticky,
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick "</httpd:stickysession>\n", NULL);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_rprintf(r,
8aefbd756763807188d2e3ce336a8680e4893066wrowe " <httpd:nofailover>%s</httpd:nofailover>\n",
8aefbd756763807188d2e3ce336a8680e4893066wrowe (balancer->s->sticky_force ? "On" : "Off"));
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rprintf(r,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe " <httpd:timeout>%" APR_TIME_T_FMT "</httpd:timeout>",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe apr_time_sec(balancer->s->timeout));
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if (balancer->s->max_attempts_set) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ap_rprintf(r,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe " <httpd:maxattempts>%d</httpd:maxattempts>\n",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe balancer->s->max_attempts);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rvputs(r, " <httpd:lbmethod>", balancer->lbmethod->name,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "</httpd:lbmethod>\n", NULL);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (balancer->s->sticky) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rprintf(r,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " <httpd:scolonpathdelim>%s</httpd:scolonpathdelim>\n",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe (balancer->s->scolonsep ? "On" : "Off"));
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* End proxy_balancer */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs(" <httpd:workers>\n", r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd workers = (proxy_worker **)balancer->workers->elts;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd for (n = 0; n < balancer->workers->nelts; n++) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd worker = *workers;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe /* Start proxy_worker */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ap_rputs(" <httpd:worker>\n", r);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rvputs(r, " <httpd:name>", worker->s->name, (worker->s->uds?"|":""),
0540a0b469147b52e858587270dba31c2aaa9e09wrowe "</httpd:name>\n", NULL);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rvputs(r, " <httpd:scheme>", worker->s->scheme,
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe "</httpd:scheme>\n", NULL);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rvputs(r, " <httpd:hostname>", worker->s->hostname,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe "</httpd:hostname>\n", NULL);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rprintf(r, " <httpd:loadfactor>%d</httpd:loadfactor>\n",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe worker->s->lbfactor);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rprintf(r,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe " <httpd:port>%d</httpd:port>\n",
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe worker->s->port);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rprintf(r, " <httpd:min>%d</httpd:min>\n",
8aefbd756763807188d2e3ce336a8680e4893066wrowe worker->s->min);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rprintf(r, " <httpd:smax>%d</httpd:smax>\n",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe worker->s->smax);
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe ap_rprintf(r, " <httpd:max>%d</httpd:max>\n",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->hmax);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rprintf(r,
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf " <httpd:ttl>%" APR_TIME_T_FMT "</httpd:ttl>\n",
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf apr_time_sec(worker->s->ttl));
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (worker->s->timeout_set) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:timeout>%" APR_TIME_T_FMT "</httpd:timeout>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe apr_time_sec(worker->s->timeout));
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
948096a99010fccf648814fecf38f75c689172d7wrowe if (worker->s->acquire_set) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rprintf(r,
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe " <httpd:acquire>%" APR_TIME_T_FMT "</httpd:acquire>\n",
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe apr_time_msec(worker->s->acquire));
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (worker->s->recv_buffer_size_set) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_rprintf(r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " <httpd:recv_buffer_size>%" APR_SIZE_T_FMT "</httpd:recv_buffer_size>\n",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->recv_buffer_size);
42da244268b11ec661b528510f80a18b73c51727brianp }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (worker->s->io_buffer_size_set) {
42da244268b11ec661b528510f80a18b73c51727brianp ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:io_buffer_size>%" APR_SIZE_T_FMT "</httpd:io_buffer_size>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe worker->s->io_buffer_size);
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe if (worker->s->keepalive_set) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:keepalive>%s</httpd:keepalive>\n",
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz (worker->s->keepalive ? "On" : "Off"));
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe /* Begin proxy_worker_stat */
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs(" <httpd:status>", r);
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz if (worker->s->status & PROXY_WORKER_DISABLED)
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs("Disabled", r);
948096a99010fccf648814fecf38f75c689172d7wrowe else if (worker->s->status & PROXY_WORKER_IN_ERROR)
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_rputs("Error", r);
948096a99010fccf648814fecf38f75c689172d7wrowe else if (worker->s->status & PROXY_WORKER_STOPPED)
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs("Stopped", r);
948096a99010fccf648814fecf38f75c689172d7wrowe else if (worker->s->status & PROXY_WORKER_HOT_STANDBY)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("Standby", r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd else if (PROXY_WORKER_IS_USABLE(worker))
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rputs("OK", r);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar else if (!PROXY_WORKER_IS_INITIALIZED(worker))
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs("Uninitialized", r);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rputs("</httpd:status>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe if ((worker->s->error_time > 0) && apr_rfc822_date(date, worker->s->error_time) == APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:error_time>", date,
053497224246c4dbef9af594cacf5c00ed271e6cwrowe "</httpd:error_time>\n", NULL);
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rprintf(r,
a9a4544168a37b43bd180b3703ccee995f27a80awrowe " <httpd:retries>%d</httpd:retries>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker worker->s->retries);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:lbstatus>%d</httpd:lbstatus>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe worker->s->lbstatus);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:loadfactor>%d</httpd:loadfactor>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe worker->s->lbfactor);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:transferred>%" APR_OFF_T_FMT "</httpd:transferred>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe worker->s->transferred);
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:read>%" APR_OFF_T_FMT "</httpd:read>\n",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd worker->s->read);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " <httpd:elected>%" APR_SIZE_T_FMT "</httpd:elected>\n",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd worker->s->elected);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:route>",
948096a99010fccf648814fecf38f75c689172d7wrowe ap_escape_html(r->pool, worker->s->route),
948096a99010fccf648814fecf38f75c689172d7wrowe "</httpd:route>\n", NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:redirect>",
948096a99010fccf648814fecf38f75c689172d7wrowe ap_escape_html(r->pool, worker->s->redirect),
053497224246c4dbef9af594cacf5c00ed271e6cwrowe "</httpd:redirect>\n", NULL);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rprintf(r,
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " <httpd:busy>%" APR_SIZE_T_FMT "</httpd:busy>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker worker->s->busy);
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf ap_rprintf(r, " <httpd:lbset>%d</httpd:lbset>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker worker->s->lbset);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* End proxy_worker_stat */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz if (!strcasecmp(worker->s->scheme, "ajp")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs(" <httpd:flushpackets>", r);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe switch (worker->s->flush_packets) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker case flush_off:
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_rputs("Off", r);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe break;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe case flush_on:
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rputs("On", r);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar break;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar case flush_auto:
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick ap_rputs("Auto", r);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar break;
b6b1df87b7ce62620d48526a7ab630897cdaad90chrisd }
b6b1df87b7ce62620d48526a7ab630897cdaad90chrisd ap_rputs("</httpd:flushpackets>\n", r);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (worker->s->flush_packets == flush_auto) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rprintf(r,
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz " <httpd:flushwait>%d</httpd:flushwait>\n",
053497224246c4dbef9af594cacf5c00ed271e6cwrowe worker->s->flush_wait);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
948096a99010fccf648814fecf38f75c689172d7wrowe if (worker->s->ping_timeout_set) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:ping>%" APR_TIME_T_FMT "</httpd:ping>",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe apr_time_msec(worker->s->ping_timeout));
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe if (worker->s->disablereuse_set) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:disablereuse>%s</httpd:disablereuse>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (worker->s->disablereuse ? "On" : "Off"));
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe if (worker->s->conn_timeout_set) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rprintf(r,
948096a99010fccf648814fecf38f75c689172d7wrowe " <httpd:connectiontimeout>%" APR_TIME_T_FMT "</httpd:connectiontimeout>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe apr_time_msec(worker->s->conn_timeout));
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
948096a99010fccf648814fecf38f75c689172d7wrowe if (worker->s->retry_set) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " <httpd:retry>%" APR_TIME_T_FMT "</httpd:retry>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker apr_time_sec(worker->s->retry));
948096a99010fccf648814fecf38f75c689172d7wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rputs(" </httpd:worker>\n", r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ++workers;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rputs(" </httpd:workers>\n", r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rputs(" </httpd:balancer>\n", r);
696218c49632c863d18b25fa52ab63617088cb38wrowe ++balancer;
948096a99010fccf648814fecf38f75c689172d7wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rputs(" </httpd:balancers>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs("</httpd:manager>", r);
948096a99010fccf648814fecf38f75c689172d7wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker else {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_set_content_type(r, "text/html; charset=ISO-8859-1");
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs(DOCTYPE_HTML_3_2
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd "<html><head><title>Balancer Manager</title>\n", r);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_rputs("<style type='text/css'>\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "table {\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " border-width: 1px;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-spacing: 3px;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-style: solid;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-color: gray;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-collapse: collapse;\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " background-color: white;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " text-align: center;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe "}\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd "th {\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-width: 1px;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " padding: 2px;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-style: dotted;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " border-color: gray;\n"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd " background-color: white;\n"
a9a4544168a37b43bd180b3703ccee995f27a80awrowe " text-align: center;\n"
a9a4544168a37b43bd180b3703ccee995f27a80awrowe "}\n"
a9a4544168a37b43bd180b3703ccee995f27a80awrowe "td {\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " border-width: 1px;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " padding: 2px;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " border-style: dotted;\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar " border-color: gray;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " background-color: white;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " text-align: center;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe "}\n"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "</style>\n</head>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs("<body><h1>Load Balancer Manager for ", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, ap_escape_html(r->pool, ap_get_server_name(r)),
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "</h1>\n\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<dl><dt>Server Version: ",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_get_server_description(), "</dt>\n", NULL);
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe ap_rvputs(r, "<dt>Server Built: ",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_get_server_built(), "</dt>\n", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "<dt>Balancer changes will ", conf->bal_persist ? "" : "NOT ",
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf "be persisted on restart.</dt>", NULL);
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_rvputs(r, "<dt>Balancers are ", conf->inherit ? "" : "NOT ",
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf "inherited from main server.</dt>", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "<dt>ProxyPass settings are ", conf->ppinherit ? "" : "NOT ",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "inherited from main server.</dt>", NULL);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs("</dl>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer = (proxy_balancer *)conf->balancers->elts;
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf for (i = 0; i < conf->balancers->nelts; i++) {
11e076839c8d5a82d55e710194d0daac51390dbdsf
11e076839c8d5a82d55e710194d0daac51390dbdsf ap_rputs("<hr />\n<h3>LoadBalancer Status for ", r);
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_rvputs(r, "<a href=\"", ap_escape_uri(r->pool, r->uri), "?b=",
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe "&nonce=", balancer->s->nonce,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "\">", NULL);
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe ap_rvputs(r, balancer->s->name, "</a> [",balancer->s->sname, "]</h3>\n", NULL);
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe ap_rputs("\n\n<table><tr>"
b5bd19d82874782007a2f9bcb19341a483c1270cwrowe "<th>MaxMembers</th><th>StickySession</th><th>DisableFailover</th><th>Timeout</th><th>FailoverAttempts</th><th>Method</th>"
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe "<th>Path</th><th>Active</th></tr>\n<tr>", r);
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe /* the below is a safe cast, since the number of slots total will
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * never be more than max_workers, which is restricted to int */
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp ap_rprintf(r, "<td>%d [%d Used]</td>\n", balancer->max_workers,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd balancer->max_workers - (int)storage->num_free_slots(balancer->wslot));
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (*balancer->s->sticky) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (strcmp(balancer->s->sticky, balancer->s->sticky_path)) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "<td>", balancer->s->sticky, " | ",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe balancer->s->sticky_path, NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_rvputs(r, "<td>", balancer->s->sticky, NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker else {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<td> (None) ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%s</td>\n",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->sticky_force ? "On" : "Off");
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_rprintf(r, "</td><td>%" APR_TIME_T_FMT "</td>",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_time_sec(balancer->s->timeout));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%d</td>\n", balancer->s->max_attempts);
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_rprintf(r, "<td>%s</td>\n",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->lbpname);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<td>", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (balancer->s->vhost && *(balancer->s->vhost)) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, balancer->s->vhost, " -> ", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, balancer->s->vpath, "</td>\n", NULL);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rprintf(r, "<td>%s</td>\n",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker !balancer->s->inactive ? "Yes" : "No");
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_rputs("</table>\n<br />", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("\n\n<table><tr>"
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "<th>Worker URL</th>"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "<th>Route</th><th>RouteRedir</th>"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "<th>Factor</th><th>Set</th><th>Status</th>"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "<th>Elected</th><th>Busy</th><th>Load</th><th>To</th><th>From</th>"
a9a4544168a37b43bd180b3703ccee995f27a80awrowe "</tr>\n", r);
a9a4544168a37b43bd180b3703ccee995f27a80awrowe
a9a4544168a37b43bd180b3703ccee995f27a80awrowe workers = (proxy_worker **)balancer->workers->elts;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker for (n = 0; n < balancer->workers->nelts; n++) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar char fbuf[50];
aa047239dedf0d26e8efecfade32e7337f35df19wrowe worker = *workers;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_rvputs(r, "<tr>\n<td><a href=\"",
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_escape_uri(r->pool, r->uri), "?b=",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe balancer->s->name + sizeof(BALANCER_PREFIX) - 1, "&w=",
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_escape_uri(r->pool, worker->s->name),
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "&nonce=", balancer->s->nonce,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "\">", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, (worker->s->uds ? "<i>" : ""), worker->s->name,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe (worker->s->uds ? "|</i>" : ""), "</a></td>", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "<td>", ap_escape_html(r->pool, worker->s->route),
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "</td><td>",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_escape_html(r->pool, worker->s->redirect), NULL);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rprintf(r, "</td><td>%d</td>", worker->s->lbfactor);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "<td>%d</td><td>", worker->s->lbset);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, ap_proxy_parse_wstatus(r->pool, worker), NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("</td>", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td>", worker->s->elected);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td>", worker->s->busy);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%d</td><td>", worker->s->lbstatus);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rputs("</td><td>", r);
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf ap_rputs(apr_strfsize(worker->s->read, fbuf), r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("</td></tr>\n", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ++workers;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs("</table>\n", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ++balancer;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<hr />\n", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (wsel && bsel) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<h3>Edit worker settings for ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, (wsel->s->uds?"<i>":""), wsel->s->name, (wsel->s->uds?"|</i>":""), "</h3>\n", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<form method=\"POST\" enctype=\"application/x-www-form-urlencoded\" action=\"", r);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rvputs(r, ap_escape_uri(r->pool, action), "\">\n", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<dl>\n<table><tr><td>Load factor:</td><td><input name='w_lf' id='w_lf' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "value='%d'></td></tr>\n", wsel->s->lbfactor);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<tr><td>LB Set:</td><td><input name='w_ls' id='w_ls' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe 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);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->route),
aa047239dedf0d26e8efecfade32e7337f35df19wrowe NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("\"></td></tr>\n", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<tr><td>Route Redirect:</td><td><input name='w_rr' id='w_rr' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->redirect),
aa047239dedf0d26e8efecfade32e7337f35df19wrowe NULL);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs("\"></td></tr>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td>Status:</td>", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<td><table><tr>"
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "<th>Ignore Errors</th>"
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "<th>Draining Mode</th>"
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "<th>Disabled</th>"
0540a0b469147b52e858587270dba31c2aaa9e09wrowe "<th>Hot Standby</th></tr>\n<tr>", r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar create_radio("w_status_I", (PROXY_WORKER_IGNORE_ERRORS & wsel->s->status), r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar create_radio("w_status_N", (PROXY_WORKER_DRAIN & wsel->s->status), r);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe create_radio("w_status_D", (PROXY_WORKER_DISABLED & wsel->s->status), r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar create_radio("w_status_H", (PROXY_WORKER_HOT_STANDBY & wsel->s->status), r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("</tr></table>\n", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<tr><td colspan=2><input type=submit value='Submit'></td></tr>\n", r);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_rvputs(r, "</table>\n<input type=hidden name='w' id='w' ", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, "value='", ap_escape_uri(r->pool, wsel->s->name), "'>\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<input type=hidden name='b' id='b' ", NULL);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_rvputs(r, "value='", bsel->s->name + sizeof(BALANCER_PREFIX) - 1,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd "'>\n", NULL);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rvputs(r, "<input type=hidden name='nonce' id='nonce' value='",
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd bsel->s->nonce, "'>\n", NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("</form>\n", r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rputs("<hr />\n", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe } else if (bsel) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const apr_array_header_t *provs;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const ap_list_provider_names_t *pname;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int i;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs("<h3>Edit balancer settings for ", r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rvputs(r, bsel->s->name, "</h3>\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<form method='POST' enctype='application/x-www-form-urlencoded' action='", r);
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe ap_rvputs(r, action, "'>\n", NULL);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs("<dl>\n<table>\n", r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd provs = ap_list_provider_names(r->pool, PROXY_LBMETHOD, "0");
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (provs) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs("<tr><td>LBmethod:</td>", r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_rputs("<td>\n<select name='b_lbm' id='b_lbm'>", r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd pname = (ap_list_provider_names_t *)provs->elts;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe for (i = 0; i < provs->nelts; i++, pname++) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ap_rvputs(r,"<option value='", pname->provider_name, "'", NULL);
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (strcmp(pname->provider_name, bsel->s->lbpname) == 0)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs(" selected ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rvputs(r, ">", pname->provider_name, "\n", NULL);
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rputs("</select>\n</td></tr>\n", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rputs("<tr><td>Timeout:</td><td><input name='b_tmo' id='b_tmo' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "value='%" APR_TIME_T_FMT "'></td></tr>\n", apr_time_sec(bsel->s->timeout));
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar ap_rputs("<tr><td>Failover Attempts:</td><td><input name='b_max' id='b_max' type=text ", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_rprintf(r, "value='%d'></td></tr>\n", bsel->s->max_attempts);
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe ap_rputs("<tr><td>Disable Failover:</td>", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb create_radio("b_sforce", bsel->s->sticky_force, r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td>Sticky Session:</td><td><input name='b_ss' id='b_ss' size=64 type=text ", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strcmp(bsel->s->sticky, bsel->s->sticky_path)) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rvputs(r, "value ='", bsel->s->sticky, " | ",
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf bsel->s->sticky_path, NULL);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf else {
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_rvputs(r, "value ='", bsel->s->sticky, NULL);
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs("'>&nbsp;&nbsp;&nbsp;&nbsp;(Use '-' to delete)</td></tr>\n", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (storage->num_free_slots(bsel->wslot) != 0) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs("<tr><td>Add New Worker:</td><td><input name='b_nwrkr' id='b_nwrkr' size=32 type=text>"
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf "&nbsp;&nbsp;&nbsp;&nbsp;Are you sure? <input name='b_wyes' id='b_wyes' type=checkbox value='1'>"
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf "</td></tr>", r);
6b15044d54a096e6323ff1540f1a491e8de7622dsf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs("<tr><td colspan=2><input type=submit value='Submit'></td></tr>\n", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rvputs(r, "</table>\n<input type=hidden name='b' id='b' ", NULL);
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_rvputs(r, "value='", bsel->s->name + sizeof(BALANCER_PREFIX) - 1,
11e076839c8d5a82d55e710194d0daac51390dbdsf "'>\n", NULL);
11e076839c8d5a82d55e710194d0daac51390dbdsf ap_rvputs(r, "<input type=hidden name='nonce' id='nonce' value='",
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf bsel->s->nonce, "'>\n", NULL);
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_rputs("</form>\n", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs("<hr />\n", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs(ap_psignature("",r), r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rputs("</body></html>\n", r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_rflush(r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf return DONE;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf}
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sfstatic void balancer_child_init(apr_pool_t *p, server_rec *s)
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf{
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf while (s) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf proxy_balancer *balancer;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf int i;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf void *sconf = s->module_config;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf apr_status_t rv;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (conf->balancers->nelts) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf apr_size_t size;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf unsigned int num;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf storage->attach(&(conf->bslot), conf->id, &size, &num, p);
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf if (!conf->bslot) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01205) "slotmem_attach failed");
6b15044d54a096e6323ff1540f1a491e8de7622dsf exit(1); /* Ugly, but what else? */
6b15044d54a096e6323ff1540f1a491e8de7622dsf }
6b15044d54a096e6323ff1540f1a491e8de7622dsf }
6b15044d54a096e6323ff1540f1a491e8de7622dsf
6b15044d54a096e6323ff1540f1a491e8de7622dsf balancer = (proxy_balancer *)conf->balancers->elts;
6b15044d54a096e6323ff1540f1a491e8de7622dsf for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
6b15044d54a096e6323ff1540f1a491e8de7622dsf rv = ap_proxy_initialize_balancer(balancer, s, p);
6b15044d54a096e6323ff1540f1a491e8de7622dsf
6b15044d54a096e6323ff1540f1a491e8de7622dsf if (rv != APR_SUCCESS) {
6b15044d54a096e6323ff1540f1a491e8de7622dsf ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(01206)
6b15044d54a096e6323ff1540f1a491e8de7622dsf "Failed to init balancer %s in child",
185aa71728867671e105178b4c66fbc22b65ae26sf balancer->s->name);
6b15044d54a096e6323ff1540f1a491e8de7622dsf exit(1); /* Ugly, but what else? */
6b15044d54a096e6323ff1540f1a491e8de7622dsf }
6b15044d54a096e6323ff1540f1a491e8de7622dsf init_balancer_members(conf->pool, s, balancer);
6b15044d54a096e6323ff1540f1a491e8de7622dsf }
6b15044d54a096e6323ff1540f1a491e8de7622dsf s = s->next;
6b15044d54a096e6323ff1540f1a491e8de7622dsf }
6b15044d54a096e6323ff1540f1a491e8de7622dsf
6b15044d54a096e6323ff1540f1a491e8de7622dsf}
6b15044d54a096e6323ff1540f1a491e8de7622dsf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sfstatic void ap_proxy_balancer_register_hook(apr_pool_t *p)
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf{
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* Only the mpm_winnt has child init hook handler.
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * make sure that we are called after the mpm
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * initializes
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf static const char *const aszPred[] = { "mpm_winnt.c", "mod_slotmem_shm.c", NULL};
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf static const char *const aszPred2[] = { "mod_proxy.c", NULL};
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* manager handler */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_hook_post_config(balancer_post_config, aszPred2, NULL, APR_HOOK_MIDDLE);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_hook_pre_config(balancer_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_hook_handler(balancer_handler, NULL, NULL, APR_HOOK_FIRST);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_hook_child_init(balancer_child_init, aszPred, NULL, APR_HOOK_MIDDLE);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf proxy_hook_pre_request(proxy_balancer_pre_request, NULL, NULL, APR_HOOK_FIRST);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf proxy_hook_post_request(proxy_balancer_post_request, NULL, NULL, APR_HOOK_FIRST);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf proxy_hook_canon_handler(proxy_balancer_canon, NULL, NULL, APR_HOOK_FIRST);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf}
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sfAP_DECLARE_MODULE(proxy_balancer) = {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf STANDARD20_MODULE_STUFF,
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf NULL, /* create per-directory config structure */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf NULL, /* merge per-directory config structures */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf NULL, /* create per-server config structure */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf NULL, /* merge per-server config structures */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf NULL, /* command apr_table_t */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_proxy_balancer_register_hook /* register hooks */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf};
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf