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