mod_proxy_balancer.c revision e8a023c6d3ea9f0faa895cbc7bdd649efb8a01d6
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Licensed to the Apache Software Foundation (ASF) under one or more
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * contributor license agreements. See the NOTICE file distributed with
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * this work for additional information regarding copyright ownership.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The ASF licenses this file to You under the Apache License, Version 2.0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * (the "License"); you may not use this file except in compliance with
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the License. You may obtain a copy of the License at
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * http://www.apache.org/licenses/LICENSE-2.0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Unless required by applicable law or agreed to in writing, software
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * distributed under the License is distributed on an "AS IS" BASIS,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * See the License for the specific language governing permissions and
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * limitations under the License.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Load balancer module for Apache proxy */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mod_proxy.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "scoreboard.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#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);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb 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,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *conf);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int proxy_balancer_canon(request_rec *r, char *url)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *host, *path;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *search = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *err;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_port_t port = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* TODO: offset of BALANCER_PREFIX ?? */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strncasecmp(url, "balancer:", 9) == 0) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb url += 9;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return DECLINED;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "canonicalising URL %s", url);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* do syntatic check.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * We break the URL into host, port, path, search
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (err) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01157)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "error parsing URL %s: %s",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb url, err);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return HTTP_BAD_REQUEST;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * now parse path/search args, according to rfc1738:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * process the path. With proxy-noncanon set (by
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * mod_proxy) we use the raw, unparsed uri
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (apr_table_get(r->notes, "proxy-nocanon")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb path = url; /* this is the raw path */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->proxyreq);
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe search = r->args;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (path == NULL)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return HTTP_BAD_REQUEST;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->filename = apr_pstrcat(r->pool, "proxy:", BALANCER_PREFIX, host,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "/", path, (search) ? "?" : "", (search) ? search : "", NULL);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->path_info = apr_pstrcat(r->pool, "/", path, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowestatic void init_balancer_members(apr_pool_t *p, server_rec *s,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer *balancer)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker **workers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb workers = (proxy_worker **)balancer->workers->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < balancer->workers->nelts; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int worker_is_initialized;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker *worker = *workers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01158)
c3e342e5b0b9fea6617ee16d2da02c3ef2108126dougm "Looking at %s -> %s initialized?", balancer->s->name, worker->s->name);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker_is_initialized = PROXY_WORKER_IS_INITIALIZED(worker);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (!worker_is_initialized) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_proxy_initialize_worker(worker, s, p);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ++workers;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Set default number of attempts to the number of
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * workers.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (!balancer->s->max_attempts_set && balancer->workers->nelts > 1) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe balancer->s->max_attempts = balancer->workers->nelts - 1;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe balancer->s->max_attempts_set = 1;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe}
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe/* Retrieve the parameter with the given name
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * Something like 'JSESSIONID=12345...N'
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowestatic char *get_path_param(apr_pool_t *pool, char *url,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe const char *name, int scolon_sep)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe char *path = NULL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe char *pathdelims = "?&";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (scolon_sep) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe pathdelims = ";?&";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe for (path = strstr(url, name); path; path = strstr(path + 1, name)) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe path += strlen(name);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (*path == '=') {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /*
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * Session path was found, get its value
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ++path;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (*path) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe char *q;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe path = apr_strtok(apr_pstrdup(pool, path), pathdelims, &q);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return path;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return NULL;
4775dfc34c90fada8c7c4d6a57ed8a3114d55c2dtrawick}
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowestatic char *get_cookie_param(request_rec *r, const char *name)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe const char *cookies;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe const char *start_cookie;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe for (start_cookie = ap_strstr_c(cookies, name); start_cookie;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe start_cookie = ap_strstr_c(start_cookie + 1, name)) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (start_cookie == cookies ||
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe start_cookie[-1] == ';' ||
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe start_cookie[-1] == ',' ||
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe isspace(start_cookie[-1])) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe start_cookie += strlen(name);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe while(*start_cookie && isspace(*start_cookie))
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ++start_cookie;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (*start_cookie++ == '=' && *start_cookie) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /*
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * Session cookie was found, get its value
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe char *end_cookie, *cookie;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe cookie = apr_pstrdup(r->pool, start_cookie);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((end_cookie = strchr(cookie, ';')) != NULL)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe *end_cookie = '\0';
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if((end_cookie = strchr(cookie, ',')) != NULL)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe *end_cookie = '\0';
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return cookie;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return NULL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe}
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe/* Find the worker that has the 'route' defined
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowestatic proxy_worker *find_route_worker(proxy_balancer *balancer,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe const char *route, request_rec *r)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe 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) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe workers = (proxy_worker **)balancer->workers->elts;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe for (i = 0; i < balancer->workers->nelts; i++, workers++) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe proxy_worker *worker = *workers;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ( (checking_standby ? !PROXY_WORKER_IS_STANDBY(worker) : PROXY_WORKER_IS_STANDBY(worker)) )
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe continue;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (*(worker->s->route) && strcmp(worker->s->route, route) == 0) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (worker && PROXY_WORKER_IS_USABLE(worker)) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return worker;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe } else {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /*
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * If the worker is in error state run
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * retry on that worker. It will be marked as
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * operational if the retry timeout is elapsed.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * The worker might still be unusable, but we try
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * anyway.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_proxy_retry_worker_fn("BALANCER", worker, r->server);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (PROXY_WORKER_IS_USABLE(worker)) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return worker;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe } else {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /*
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * We have a worker that is unusable.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * It can be in error or disabled, but in case
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * it has a redirection set use that redirection worker.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * This enables to safely remove the member from the
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * balancer. Of course you will need some kind of
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * session replication between those two remote.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (*worker->s->redirect) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe proxy_worker *rworker = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rworker = find_route_worker(balancer, worker->s->redirect, r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Check if the redirect worker is usable */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (rworker && !PROXY_WORKER_IS_USABLE(rworker)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * If the worker is in error state run
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * retry on that worker. It will be marked as
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * operational if the retry timeout is elapsed.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The worker might still be unusable, but we try
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * anyway.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_proxy_retry_worker_fn("BALANCER", rworker, r->server);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (rworker && PROXY_WORKER_IS_USABLE(rworker))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return rworker;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb checked_standby = checking_standby++;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic proxy_worker *find_session_route(proxy_balancer *balancer,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb request_rec *r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char **route,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char **sticky_used,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char **url)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker *worker = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!*balancer->s->sticky)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Try to find the sticky route inside url */
c6ed63d53853f79bf8265c434d2e25c9db8a7fd8trawick *route = get_path_param(r->pool, *url, balancer->s->sticky_path, balancer->s->scolonsep);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (*route) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01159)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe "Found value %s for stickysession %s",
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *route, balancer->s->sticky_path);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *sticky_used = balancer->s->sticky_path;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe else {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *route = get_cookie_param(r, balancer->s->sticky);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (*route) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *sticky_used = balancer->s->sticky;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01160)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe "Found value %s for stickysession %s",
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *route, balancer->s->sticky);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /*
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * If we found a value for sticksession, find the first '.' within.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * Everything after '.' (if present) is our route.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick if ((*route) && ((*route = strchr(*route, '.')) != NULL ))
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe (*route)++;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if ((*route) && (**route)) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01161) "Found route %s", *route);
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick /* 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 /*
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * Notice that the route of the worker chosen is different from
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * the route supplied by the client.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01162)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe "Route changed from %s to %s",
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *route, worker->s->route);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick return worker;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe else
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return NULL;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe}
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic proxy_worker *find_best_worker(proxy_balancer *balancer,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe request_rec *r)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe proxy_worker *candidate = NULL;
c6ed63d53853f79bf8265c434d2e25c9db8a7fd8trawick apr_status_t rv;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01163)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: Lock failed for find_best_worker()",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->name);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb candidate = (*balancer->lbmethod->finder)(balancer, r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (candidate)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb candidate->s->elected++;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01164)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: Unlock failed for find_best_worker()",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->name);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (candidate == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* All the workers are in error state or disabled.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * If the balancer has a timeout sleep for a while
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * and try again to find the worker. The chances are
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * that some other thread will release a connection.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * By default the timeout is not set, and the server
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * returns SERVER_BUSY.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (balancer->s->timeout) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* XXX: This can perhaps be build using some
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * smarter mechanism, like tread_cond.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * But since the statuses can came from
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * different childs, use the provided algo.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_interval_time_t timeout = balancer->s->timeout;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_interval_time_t step, tval = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Set the timeout to 0 so that we don't
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * end in infinite loop
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->timeout = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb step = timeout / 100;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb while (tval < timeout) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_sleep(step);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Try again */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((candidate = find_best_worker(balancer, r)))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb break;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb tval += step;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* restore the timeout */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->timeout = timeout;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return candidate;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int rewrite_url(request_rec *r, proxy_worker *worker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char **url)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *scheme = strstr(*url, "://");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *path = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (scheme)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb path = ap_strchr_c(scheme + 3, '/');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* we break the URL into host, port, uri */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!worker) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return ap_proxyerror(r, HTTP_BAD_REQUEST, apr_pstrcat(r->pool,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "missing worker. URI cannot be parsed: ", *url,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb NULL));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *url = apr_pstrcat(r->pool, worker->s->name, path, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic void force_recovery(proxy_balancer *balancer, server_rec *s)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int ok = 0;
4ca6cbe768b4e0917ac0b76333c26a7d5396d454trawick proxy_worker **worker;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker = (proxy_worker **)balancer->workers->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < balancer->workers->nelts; i++, worker++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ok = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb break;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Try if we can recover */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_proxy_retry_worker_fn("BALANCER", *worker, s);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!((*worker)->s->status & PROXY_WORKER_IN_ERROR)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ok = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb break;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!ok) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* If all workers are in error state force the recovery.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker = (proxy_worker **)balancer->workers->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < balancer->workers->nelts; i++, worker++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ++(*worker)->s->retries;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (*worker)->s->status &= ~PROXY_WORKER_IN_ERROR;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01165)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: Forcing recovery for worker (%s)",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->name, (*worker)->s->hostname);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int proxy_balancer_pre_request(proxy_worker **worker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer **balancer,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb request_rec *r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *conf, char **url)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int access_status;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker *runtime;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *route = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *sticky = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_status_t rv;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *worker = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Step 1: check if the url is for us
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The url we can handle starts with 'balancer://'
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * If balancer is already provided skip the search
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * for balancer, because this is failover attempt.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!*balancer &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb !(*balancer = ap_proxy_get_balancer(r->pool, conf, *url, 1)))
b29f87f4b6c6886a04dccc296177a7033f70dfedtrawick return DECLINED;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Step 2: Lock the LoadBalancer
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * XXX: perhaps we need the process lock here
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((rv = PROXY_THREAD_LOCK(*balancer)) != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01166)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: Lock failed for pre_request", (*balancer)->s->name);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return DECLINED;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Step 3: force recovery */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb force_recovery(*balancer, r->server);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Step 3.5: Update member list for the balancer */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* TODO: Implement as provider! */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_proxy_sync_balancer(*balancer, r->server, conf);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Step 4: find the session route */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb runtime = find_session_route(*balancer, r, &route, &sticky, url);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (runtime) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((*balancer)->lbmethod && (*balancer)->lbmethod->updatelbstatus) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Call the LB implementation */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (*balancer)->lbmethod->updatelbstatus(*balancer, runtime, r->server);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else { /* Use the default one */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i, total_factor = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker **workers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* We have a sticky load balancer
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Update the workers status
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * so that even session routes get
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * into account.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb workers = (proxy_worker **)(*balancer)->workers->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < (*balancer)->workers->nelts; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Take into calculation only the workers that are
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * not in error state or not disabled.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (PROXY_WORKER_IS_USABLE(*workers)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (*workers)->s->lbstatus += (*workers)->s->lbfactor;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb total_factor += (*workers)->s->lbfactor;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb workers++;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb runtime->s->lbstatus -= total_factor;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb runtime->s->elected++;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *worker = runtime;
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (route && (*balancer)->s->sticky_force) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i, member_of = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker **workers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe * We have a route provided that doesn't match the
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe * balancer name. See if the provider route is the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * member of the same balancer in which case return 503
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb workers = (proxy_worker **)(*balancer)->workers->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < (*balancer)->workers->nelts; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (*((*workers)->s->route) && strcmp((*workers)->s->route, route) == 0) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb member_of = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb break;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb workers++;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (member_of) {
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01167)
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe "%s: All workers are in error state for route (%s)",
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe (*balancer)->s->name, route);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01168)
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe "%s: Unlock failed for pre_request",
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe (*balancer)->s->name);
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe }
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe return HTTP_SERVICE_UNAVAILABLE;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01169)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: Unlock failed for pre_request",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (*balancer)->s->name);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!*worker) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb runtime = find_best_worker(*balancer, r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!runtime) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((*balancer)->workers->nelts) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01170)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: All workers are in error state",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (*balancer)->s->name);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb } else {
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01171)
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe "%s: No workers in balancer",
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe (*balancer)->s->name);
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe }
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe return HTTP_SERVICE_UNAVAILABLE;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe }
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe if (*(*balancer)->s->sticky && runtime) {
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe /*
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * This balancer has sticky sessions and the client either has not
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * supplied any routing information or all workers for this route
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * including possible redirect and hotstandby workers are in error
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe * state, but we have found another working worker for this
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * balancer where we can send the request. Thus notice that we have
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe * changed the route to the backend.
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe */
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe }
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe *worker = runtime;
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe }
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe (*worker)->s->busy++;
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe /* Add balancer/worker info to env. */
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe apr_table_setn(r->subprocess_env,
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe "BALANCER_NAME", (*balancer)->s->name);
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe apr_table_setn(r->subprocess_env,
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe "BALANCER_WORKER_NAME", (*worker)->s->name);
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe apr_table_setn(r->subprocess_env,
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe "BALANCER_WORKER_ROUTE", (*worker)->s->route);
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe /* Rewrite the url from 'balancer://url'
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe * to the 'worker_scheme://worker_hostname[:worker_port]/url'
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe * This replaces the balancers fictional name with the
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe * real hostname of the elected worker.
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe */
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe access_status = rewrite_url(r, *worker, url);
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe /* Add the session route to request notes if present */
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe if (route) {
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe apr_table_setn(r->notes, "session-sticky", sticky);
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe apr_table_setn(r->notes, "session-route", route);
580786e253bbe2fa462fdb24af47e52e1ef3dd83wrowe
580786e253bbe2fa462fdb24af47e52e1ef3dd83wrowe /* Add session info to env. */
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe apr_table_setn(r->subprocess_env,
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe "BALANCER_SESSION_STICKY", sticky);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_table_setn(r->subprocess_env,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "BALANCER_SESSION_ROUTE", route);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01172)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: worker (%s) rewritten to %s",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (*balancer)->s->name, (*worker)->s->name, *url);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return access_status;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int proxy_balancer_post_request(proxy_worker *worker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer *balancer,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb request_rec *r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *conf)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_status_t rv;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01173)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: Lock failed for post_request",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->name);
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe return HTTP_INTERNAL_SERVER_ERROR;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!apr_is_empty_array(balancer->errstatuses)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < balancer->errstatuses->nelts; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int val = ((int *)balancer->errstatuses->elts)[i];
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (r->status == val) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01174)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: Forcing recovery for worker (%s), "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "failonstatus %d",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->name, worker->s->name, val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->status |= PROXY_WORKER_IN_ERROR;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->error_time = apr_time_now();
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb break;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01175)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: Unlock failed for post_request", balancer->s->name);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01176)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "proxy_balancer_post_request for (%s)", balancer->s->name);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe if (worker && worker->s->busy)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->busy--;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic void recalc_factors(proxy_balancer *balancer)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker **workers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Recalculate lbfactors */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb workers = (proxy_worker **)balancer->workers->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Special case if there is only one worker its
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe * load factor will always be 1
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (balancer->workers->nelts == 1) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (*workers)->s->lbstatus = (*workers)->s->lbfactor = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < balancer->workers->nelts; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Update the status entries */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb workers[i]->s->lbstatus = workers[i]->s->lbfactor;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic apr_status_t lock_remove(void *data)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe proxy_balancer *balancer;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb server_rec *s = data;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb void *sconf = s->module_config;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer = (proxy_balancer *)conf->balancers->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (balancer->gmutex) {
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe apr_global_mutex_destroy(balancer->gmutex);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe balancer->gmutex = NULL;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe return(0);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe}
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe/* post_config hook: */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_t *ptemp, server_rec *s)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_status_t rv;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb void *sconf = s->module_config;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_slotmem_instance_t *new = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_time_t tstamp;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* balancer_post_config() will be called twice during startup. So, don't
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * set up the static data the 1st time through. */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!ap_proxy_retry_worker_fn) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_proxy_retry_worker_fn =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_RETRIEVE_OPTIONAL_FN(ap_proxy_retry_worker);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!ap_proxy_retry_worker_fn) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_error(
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe APLOG_MARK, APLOG_EMERG, 0, s, "mod_proxy must be loaded for mod_proxy_balancer");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return !OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Get slotmem setups
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb storage = ap_lookup_provider(AP_SLOTMEM_PROVIDER_GROUP, "shm",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb AP_SLOTMEM_PROVIDER_VERSION);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!storage) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01177)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Failed to lookup provider 'shm' for '%s': is "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "mod_slotmem_shm loaded??",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb AP_SLOTMEM_PROVIDER_GROUP);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return !OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb tstamp = apr_time_now();
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Go thru each Vhost and create the shared mem slotmem for
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * each balancer's workers
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe while (s) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i,j;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer *balancer;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe sconf = s->module_config;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe if (conf->balancers->nelts) {
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe conf->max_balancers = conf->balancers->nelts + conf->bgrowth;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01178) "Doing balancers create: %d, %d (%d)",
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe (int)ALIGNED_PROXY_BALANCER_SHARED_SIZE,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (int)conf->balancers->nelts, conf->max_balancers);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rv = storage->create(&new, conf->id,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ALIGNED_PROXY_BALANCER_SHARED_SIZE,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->max_balancers, AP_SLOTMEM_TYPE_PREGRAB, pconf);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (rv != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01179) "balancer slotmem_create failed");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return !OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->bslot = new;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->storage = storage;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Initialize shared scoreboard data */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer = (proxy_balancer *)conf->balancers->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker **workers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker *worker;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer_shared *bshm;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb unsigned int index;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->max_workers = balancer->workers->nelts + balancer->growth;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Create global mutex */
8aefbd756763807188d2e3ce336a8680e4893066wrowe rv = ap_global_mutex_create(&(balancer->gmutex), NULL, balancer_mutex_type,
8aefbd756763807188d2e3ce336a8680e4893066wrowe balancer->s->sname, s, pconf, 0);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (rv != APR_SUCCESS || !balancer->gmutex) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01180)
8aefbd756763807188d2e3ce336a8680e4893066wrowe "mutex creation of %s : %s failed", balancer_mutex_type,
8aefbd756763807188d2e3ce336a8680e4893066wrowe balancer->s->sname);
8aefbd756763807188d2e3ce336a8680e4893066wrowe return HTTP_INTERNAL_SERVER_ERROR;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_pool_cleanup_register(pconf, (void *)s, lock_remove,
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_pool_cleanup_null);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* setup shm for balancers */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = storage->grab(conf->bslot, &index)) != APR_SUCCESS) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed");
8aefbd756763807188d2e3ce336a8680e4893066wrowe return !OK;
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = storage->dptr(conf->bslot, index, (void *)&bshm)) != APR_SUCCESS) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed");
8aefbd756763807188d2e3ce336a8680e4893066wrowe return !OK;
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe }
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe if ((rv = ap_proxy_share_balancer(balancer, bshm, index)) != APR_SUCCESS) {
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01183) "Cannot share balancer");
d11e96111ae8731e8785837b4c927d81bf33c9b6wrowe return !OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* create slotmem slots for workers */
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01184) "Doing workers create: %s (%s), %d, %d",
8aefbd756763807188d2e3ce336a8680e4893066wrowe balancer->s->name, balancer->s->sname,
8aefbd756763807188d2e3ce336a8680e4893066wrowe (int)ALIGNED_PROXY_WORKER_SHARED_SIZE,
8aefbd756763807188d2e3ce336a8680e4893066wrowe (int)balancer->max_workers);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe rv = storage->create(&new, balancer->s->sname,
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe ALIGNED_PROXY_WORKER_SHARED_SIZE,
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe balancer->max_workers, AP_SLOTMEM_TYPE_PREGRAB, pconf);
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe if (rv != APR_SUCCESS) {
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01185) "worker slotmem_create failed");
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe return !OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe balancer->wslot = new;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe balancer->storage = storage;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe /* sync all timestamps */
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe balancer->wupdated = balancer->s->wupdated = tstamp;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* now go thru each worker */
8aefbd756763807188d2e3ce336a8680e4893066wrowe workers = (proxy_worker **)balancer->workers->elts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (j = 0; j < balancer->workers->nelts; j++, workers++) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_worker_shared *shm;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe worker = *workers;
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = storage->grab(balancer->wslot, &index)) != APR_SUCCESS) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01186) "worker slotmem_grab failed");
8aefbd756763807188d2e3ce336a8680e4893066wrowe return !OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = storage->dptr(balancer->wslot, index, (void *)&shm)) != APR_SUCCESS) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01187) "worker slotmem_dptr failed");
8aefbd756763807188d2e3ce336a8680e4893066wrowe return !OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = ap_proxy_share_worker(worker, shm, index)) != APR_SUCCESS) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01188) "Cannot share worker");
8aefbd756763807188d2e3ce336a8680e4893066wrowe return !OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe worker->s->updated = tstamp;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe s = s->next;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe return OK;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe}
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
a8d11d78181478da6a672f7fbc58b8d523351f49wrowestatic void create_radio(const char *name, unsigned int flag, request_rec *r)
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe{
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe ap_rvputs(r, "<td>On <input name='", name, "' id='", name, "' value='1' type=radio", NULL);
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe if (flag)
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe ap_rputs(" checked", r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rvputs(r, "> <br/> Off <input name='", name, "' id='", name, "' value='0' type=radio", NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!flag)
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rputs(" checked", r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_rputs("></td>\n", r);
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic void push2table(const char *input, apr_table_t *params,
d11e96111ae8731e8785837b4c927d81bf33c9b6wrowe const char *allowed[], apr_pool_t *p)
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *args;
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *tok, *val;
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *key;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (input == NULL) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
d11e96111ae8731e8785837b4c927d81bf33c9b6wrowe args = apr_pstrdup(p, input);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe key = apr_strtok(args, "&", &tok);
8aefbd756763807188d2e3ce336a8680e4893066wrowe while (key) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe val = strchr(key, '=');
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (val) {
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe *val++ = '\0';
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else {
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe val = "";
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_unescape_url(key);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_unescape_url(val);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe if (allowed == NULL) { /* allow all */
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe apr_table_set(params, key, val);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *ok = *allowed;
8aefbd756763807188d2e3ce336a8680e4893066wrowe while (ok) {
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe if (strcmp(ok, key) == 0) {
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe apr_table_set(params, key, val);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe break;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe ok++;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe key = apr_strtok(NULL, "&", &tok);
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* Manages the loadfactors and member status
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe * The balancer, worker and nonce are obtained from
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe * the request args (?b=...&w=...&nonce=....).
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe * All other params are pulled from any POST
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe * data that exists.
8aefbd756763807188d2e3ce336a8680e4893066wrowe * TODO:
8aefbd756763807188d2e3ce336a8680e4893066wrowe * /.../<whatever>/balancer/worker/nonce
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic int balancer_handler(request_rec *r)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe void *sconf;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_server_conf *conf;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_balancer *balancer, *bsel = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_worker *worker, *wsel = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_worker **workers = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_t *params;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int i, n;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int ok2change = 1;
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *name;
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *action;
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_status_t rv;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* is this for us? */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (strcmp(r->handler, "balancer-manager")) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->allowed = 0
8aefbd756763807188d2e3ce336a8680e4893066wrowe | (AP_METHOD_BIT << M_GET)
d11e96111ae8731e8785837b4c927d81bf33c9b6wrowe | (AP_METHOD_BIT << M_POST);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((r->method_number != M_GET) && (r->method_number != M_POST)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe sconf = r->server->module_config;
8aefbd756763807188d2e3ce336a8680e4893066wrowe conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe params = apr_table_make(r->pool, 10);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe balancer = (proxy_balancer *)conf->balancers->elts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01189)
8aefbd756763807188d2e3ce336a8680e4893066wrowe "%s: Lock failed for balancer_handler",
8aefbd756763807188d2e3ce336a8680e4893066wrowe balancer->s->name);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_proxy_sync_balancer(balancer, r->server, conf);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01190)
8aefbd756763807188d2e3ce336a8680e4893066wrowe "%s: Unlock failed for balancer_handler",
8aefbd756763807188d2e3ce336a8680e4893066wrowe balancer->s->name);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (r->args && (r->method_number == M_GET)) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe const char *allowed[] = { "w", "b", "nonce", NULL };
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01191) "parsing r->args");
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe push2table(r->args, params, allowed, r->pool);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (r->method_number == M_POST) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_bucket_brigade *ib;
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_size_t len = 1024;
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *buf = apr_pcalloc(r->pool, len+1);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe ib = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
8aefbd756763807188d2e3ce336a8680e4893066wrowe rv = ap_get_brigade(r->input_filters, ib, AP_MODE_READBYTES,
8aefbd756763807188d2e3ce336a8680e4893066wrowe APR_BLOCK_READ, len);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (rv != APR_SUCCESS) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return HTTP_INTERNAL_SERVER_ERROR;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_brigade_flatten(ib, buf, &len);
8aefbd756763807188d2e3ce336a8680e4893066wrowe buf[len] = '\0';
8aefbd756763807188d2e3ce336a8680e4893066wrowe push2table(buf, params, NULL, r->pool);
b29f87f4b6c6886a04dccc296177a7033f70dfedtrawick }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((name = apr_table_get(params, "b")))
b29f87f4b6c6886a04dccc296177a7033f70dfedtrawick bsel = ap_proxy_get_balancer(r->pool, conf,
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_pstrcat(r->pool, BALANCER_PREFIX, name, NULL), 0);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((name = apr_table_get(params, "w"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe wsel = ap_proxy_get_worker(r->pool, bsel, conf, name);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Check that the supplied nonce matches this server's nonce;
8aefbd756763807188d2e3ce336a8680e4893066wrowe * otherwise ignore all parameters, to prevent a CSRF attack. */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!bsel ||
8aefbd756763807188d2e3ce336a8680e4893066wrowe (*bsel->s->nonce &&
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe (
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe (name = apr_table_get(params, "nonce")) == NULL ||
8aefbd756763807188d2e3ce336a8680e4893066wrowe strcmp(bsel->s->nonce, name) != 0
8aefbd756763807188d2e3ce336a8680e4893066wrowe )
8aefbd756763807188d2e3ce336a8680e4893066wrowe )
8aefbd756763807188d2e3ce336a8680e4893066wrowe ) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_clear(params);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ok2change = 0;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* First set the params */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (wsel && ok2change) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *val;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe int was_usable = PROXY_WORKER_IS_USABLE(wsel);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01192) "settings worker params");
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "w_lf"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe int ival = atoi(val);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (ival >= 1 && ival <= 100) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe wsel->s->lbfactor = ival;
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (bsel)
8aefbd756763807188d2e3ce336a8680e4893066wrowe recalc_factors(bsel);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if ((val = apr_table_get(params, "w_wr"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (strlen(val) && strlen(val) < sizeof(wsel->s->route))
8aefbd756763807188d2e3ce336a8680e4893066wrowe strcpy(wsel->s->route, val);
8aefbd756763807188d2e3ce336a8680e4893066wrowe else
8aefbd756763807188d2e3ce336a8680e4893066wrowe *wsel->s->route = '\0';
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "w_rr"))) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (strlen(val) && strlen(val) < sizeof(wsel->s->redirect))
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe strcpy(wsel->s->redirect, val);
8aefbd756763807188d2e3ce336a8680e4893066wrowe else
8aefbd756763807188d2e3ce336a8680e4893066wrowe *wsel->s->redirect = '\0';
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "w_status_I"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_proxy_set_wstatus('I', atoi(val), wsel);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "w_status_N"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_proxy_set_wstatus('N', atoi(val), wsel);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "w_status_D"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_proxy_set_wstatus('D', atoi(val), wsel);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "w_status_H"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_proxy_set_wstatus('H', atoi(val), wsel);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "w_ls"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe int ival = atoi(val);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (ival >= 0 && ival <= 99) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe wsel->s->lbset = ival;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
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;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe if (bsel && ok2change) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *val;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int ival;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01193)
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe "settings balancer params");
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe if ((val = apr_table_get(params, "b_lbm"))) {
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe if ((strlen(val) < (sizeof(bsel->s->lbpname)-1)) &&
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe strcmp(val, bsel->s->lbpname)) {
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe proxy_balancer_method *lbmethod;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe lbmethod = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (lbmethod) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe PROXY_STRNCPY(bsel->s->lbpname, val);
8aefbd756763807188d2e3ce336a8680e4893066wrowe bsel->lbmethod = lbmethod;
8aefbd756763807188d2e3ce336a8680e4893066wrowe bsel->s->wupdated = apr_time_now();
8aefbd756763807188d2e3ce336a8680e4893066wrowe bsel->s->need_reset = 1;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "b_tmo"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ival = atoi(val);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (ival >= 0 && ival <= 7200) { /* 2 hrs enuff? */
8aefbd756763807188d2e3ce336a8680e4893066wrowe bsel->s->timeout = apr_time_from_sec(ival);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe if ((val = apr_table_get(params, "b_max"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ival = atoi(val);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (ival >= 0 && ival <= 99) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe bsel->s->max_attempts = ival;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "b_sforce"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ival = atoi(val);
8aefbd756763807188d2e3ce336a8680e4893066wrowe bsel->s->sticky_force = (ival != 0);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((val = apr_table_get(params, "b_ss")) && *val) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (strlen(val) < (sizeof(bsel->s->sticky_path)-1)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (*val == '-' && *(val+1) == '\0')
8aefbd756763807188d2e3ce336a8680e4893066wrowe *bsel->s->sticky_path = *bsel->s->sticky = '\0';
8aefbd756763807188d2e3ce336a8680e4893066wrowe else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *path;
948096a99010fccf648814fecf38f75c689172d7wrowe PROXY_STRNCPY(bsel->s->sticky_path, val);
948096a99010fccf648814fecf38f75c689172d7wrowe PROXY_STRNCPY(bsel->s->sticky, val);
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe if ((path = strchr((char *)bsel->s->sticky, '|'))) {
948096a99010fccf648814fecf38f75c689172d7wrowe *path++ = '\0';
948096a99010fccf648814fecf38f75c689172d7wrowe PROXY_STRNCPY(bsel->s->sticky_path, path);
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe if ((val = apr_table_get(params, "b_wyes")) &&
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe (*val == '1' && *(val+1) == '\0') &&
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe (val = apr_table_get(params, "b_nwrkr"))) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *ret;
948096a99010fccf648814fecf38f75c689172d7wrowe proxy_worker *nworker;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb nworker = ap_proxy_get_worker(conf->pool, bsel, conf, val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!nworker && storage->num_free_slots(bsel->wslot)) {
053497224246c4dbef9af594cacf5c00ed271e6cwrowe if ((rv = PROXY_GLOBAL_LOCK(bsel)) != APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01194)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "%s: Lock failed for adding worker",
948096a99010fccf648814fecf38f75c689172d7wrowe 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);
948096a99010fccf648814fecf38f75c689172d7wrowe 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) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01196)
948096a99010fccf648814fecf38f75c689172d7wrowe "%s: Unlock failed for adding worker",
948096a99010fccf648814fecf38f75c689172d7wrowe bsel->s->name);
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe return HTTP_BAD_REQUEST;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = storage->dptr(bsel->wslot, index, (void *)&shm)) != APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01197)
948096a99010fccf648814fecf38f75c689172d7wrowe "worker slotmem_dptr failed");
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01198)
948096a99010fccf648814fecf38f75c689172d7wrowe "%s: Unlock failed for adding worker",
948096a99010fccf648814fecf38f75c689172d7wrowe bsel->s->name);
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe return HTTP_BAD_REQUEST;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = ap_proxy_share_worker(nworker, shm, index)) != APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01199)
948096a99010fccf648814fecf38f75c689172d7wrowe "Cannot share worker");
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01200)
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe "%s: Unlock failed for adding worker",
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe bsel->s->name);
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe }
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe return HTTP_BAD_REQUEST;
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe }
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe if ((rv = ap_proxy_initialize_worker(nworker, r->server, conf->pool)) != APR_SUCCESS) {
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe ap_log_rerror(APLOG_MARK, APLOG_EMERG, rv, r, APLOGNO(01201)
948096a99010fccf648814fecf38f75c689172d7wrowe "Cannot init worker");
948096a99010fccf648814fecf38f75c689172d7wrowe if ((rv = PROXY_GLOBAL_UNLOCK(bsel)) != APR_SUCCESS) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01202)
053497224246c4dbef9af594cacf5c00ed271e6cwrowe "%s: Unlock failed for adding worker",
053497224246c4dbef9af594cacf5c00ed271e6cwrowe bsel->s->name);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return HTTP_BAD_REQUEST;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
948096a99010fccf648814fecf38f75c689172d7wrowe /* 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) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01203)
948096a99010fccf648814fecf38f75c689172d7wrowe "%s: Unlock failed for adding worker",
948096a99010fccf648814fecf38f75c689172d7wrowe bsel->s->name);
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe }
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe action = ap_construct_url(r->pool, r->uri, r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01204) "genning page");
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe if (apr_table_get(params, "xml")) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_set_content_type(r, "text/xml");
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs("<?xml version='1.0' encoding='UTF-8' ?>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs("<httpd:manager xmlns:httpd='http://httpd.apache.org'>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs(" <httpd:balancers>\n", r);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe balancer = (proxy_balancer *)conf->balancers->elts;
948096a99010fccf648814fecf38f75c689172d7wrowe for (i = 0; i < conf->balancers->nelts; i++) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs(" <httpd:balancer>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:name>", balancer->s->name, "</httpd:name>\n", NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs(" <httpd:workers>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe workers = (proxy_worker **)balancer->workers->elts;
948096a99010fccf648814fecf38f75c689172d7wrowe for (n = 0; n < balancer->workers->nelts; n++) {
948096a99010fccf648814fecf38f75c689172d7wrowe worker = *workers;
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs(" <httpd:worker>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:scheme>", worker->s->scheme,
948096a99010fccf648814fecf38f75c689172d7wrowe "</httpd:scheme>\n", NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, " <httpd:hostname>", worker->s->hostname,
948096a99010fccf648814fecf38f75c689172d7wrowe "</httpd:hostname>\n", NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rprintf(r, " <httpd:loadfactor>%d</httpd:loadfactor>\n",
948096a99010fccf648814fecf38f75c689172d7wrowe worker->s->lbfactor);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs(" </httpd:worker>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ++workers;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs(" </httpd:workers>\n", r);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_rputs(" </httpd:balancer>\n", r);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ++balancer;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs(" </httpd:balancers>\n", r);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_rputs("</httpd:manager>", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
053497224246c4dbef9af594cacf5c00ed271e6cwrowe else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_set_content_type(r, "text/html; charset=ISO-8859-1");
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_rputs(DOCTYPE_HTML_3_2
053497224246c4dbef9af594cacf5c00ed271e6cwrowe "<html><head><title>Balancer Manager</title>\n", r);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_rputs("<style type='text/css'>\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe "table {\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " border-width: 1px;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " border-spacing: 3px;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " border-style: solid;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " border-color: gray;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " border-collapse: collapse;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " background-color: white;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " text-align: center;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe "}\n"
948096a99010fccf648814fecf38f75c689172d7wrowe "th {\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " border-width: 1px;\n"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe " padding: 2px;\n"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb " border-style: dotted;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " border-color: gray;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " background-color: white;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " text-align: center;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe "}\n"
948096a99010fccf648814fecf38f75c689172d7wrowe "td {\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " border-width: 1px;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " padding: 2px;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " border-style: dotted;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " border-color: gray;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " background-color: white;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe " text-align: center;\n"
948096a99010fccf648814fecf38f75c689172d7wrowe "}\n"
948096a99010fccf648814fecf38f75c689172d7wrowe "</style>\n</head>\n", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs("<body><h1>Load Balancer Manager for ", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, ap_get_server_name(r), "</h1>\n\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<dl><dt>Server Version: ",
948096a99010fccf648814fecf38f75c689172d7wrowe ap_get_server_description(), "</dt>\n", NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, "<dt>Server Built: ",
948096a99010fccf648814fecf38f75c689172d7wrowe ap_get_server_built(), "\n</dt></dl>\n", NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe balancer = (proxy_balancer *)conf->balancers->elts;
948096a99010fccf648814fecf38f75c689172d7wrowe for (i = 0; i < conf->balancers->nelts; i++) {
948096a99010fccf648814fecf38f75c689172d7wrowe
696218c49632c863d18b25fa52ab63617088cb38wrowe ap_rputs("<hr />\n<h3>LoadBalancer Status for ", r);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, "<a href='", r->uri, "?b=",
948096a99010fccf648814fecf38f75c689172d7wrowe balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
948096a99010fccf648814fecf38f75c689172d7wrowe "&nonce=", balancer->s->nonce,
948096a99010fccf648814fecf38f75c689172d7wrowe "'>", NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, balancer->s->name, "</a></h3>\n", NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rputs("\n\n<table><tr>"
053497224246c4dbef9af594cacf5c00ed271e6cwrowe "<th>MaxMembers</th><th>StickySession</th><th>DisableFailover</th><th>Timeout</th><th>FailoverAttempts</th><th>Method</th>"
948096a99010fccf648814fecf38f75c689172d7wrowe "<th>Path</th><th>Active</th></tr>\n<tr>", r);
948096a99010fccf648814fecf38f75c689172d7wrowe /* the below is a safe cast, since the number of slots total will
053497224246c4dbef9af594cacf5c00ed271e6cwrowe * never be more than max_workers, which is restricted to int */
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ap_rprintf(r, "<td>%d [%d Used]</td>\n", balancer->max_workers,
948096a99010fccf648814fecf38f75c689172d7wrowe balancer->max_workers - (int)storage->num_free_slots(balancer->wslot));
948096a99010fccf648814fecf38f75c689172d7wrowe if (*balancer->s->sticky) {
053497224246c4dbef9af594cacf5c00ed271e6cwrowe if (strcmp(balancer->s->sticky, balancer->s->sticky_path)) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, "<td>", balancer->s->sticky, " | ",
053497224246c4dbef9af594cacf5c00ed271e6cwrowe balancer->s->sticky_path, NULL);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_rvputs(r, "<td>", balancer->s->sticky, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<td> (None) ", r);
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%s</td>\n",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->sticky_force ? "On" : "Off");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "</td><td>%" APR_TIME_T_FMT "</td>",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_time_sec(balancer->s->timeout));
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe ap_rprintf(r, "<td>%d</td>\n", balancer->s->max_attempts);
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe ap_rprintf(r, "<td>%s</td>\n",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->lbpname);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<td>", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (balancer->s->vhost && *(balancer->s->vhost)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, balancer->s->vhost, " -> ", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, balancer->s->vpath, "</td>\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%s</td>\n",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb !balancer->s->inactive ? "Yes" : "No");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("</table>\n<br />", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("\n\n<table><tr>"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "<th>Worker URL</th>"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "<th>Route</th><th>RouteRedir</th>"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "<th>Factor</th><th>Set</th><th>Status</th>"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "<th>Elected</th><th>Busy</th><th>Load</th><th>To</th><th>From</th>"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "</tr>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb workers = (proxy_worker **)balancer->workers->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (n = 0; n < balancer->workers->nelts; n++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char fbuf[50];
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker = *workers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<tr>\n<td><a href='", r->uri, "?b=",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->name + sizeof(BALANCER_PREFIX) - 1, "&w=",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_escape_uri(r->pool, worker->s->name),
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "&nonce=", balancer->s->nonce,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "'>", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, worker->s->name, "</a></td>", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<td>", ap_escape_html(r->pool, worker->s->route),
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "</td><td>",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_escape_html(r->pool, worker->s->redirect), NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "</td><td>%d</td>", worker->s->lbfactor);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%d</td><td>", worker->s->lbset);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, ap_proxy_parse_wstatus(r->pool, worker), NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("</td>", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td>", worker->s->elected);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td>", worker->s->busy);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rprintf(r, "<td>%d</td><td>", worker->s->lbstatus);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("</td><td>", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs(apr_strfsize(worker->s->read, fbuf), r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("</td></tr>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ++workers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("</table>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ++balancer;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<hr />\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (wsel && bsel) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<h3>Edit worker settings for ", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, wsel->s->name, "</h3>\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<form method='POST' enctype='application/x-www-form-urlencoded' action='", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, 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);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td>LB Set:</td><td><input name='w_ls' id='w_ls' type=text ", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb 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);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("'></td></tr>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td>Route Redirect:</td><td><input name='w_rr' id='w_rr' type=text ", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "value='", ap_escape_html(r->pool, wsel->s->redirect),
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("'></td></tr>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td>Status:</td>", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<td><table><tr><th>Ign</th><th>Drn</th><th>Dis</th><th>Stby</th></tr>\n<tr>", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb 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);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb create_radio("w_status_D", (PROXY_WORKER_DISABLED & wsel->s->status), r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb create_radio("w_status_H", (PROXY_WORKER_HOT_STANDBY & wsel->s->status), r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("</tr></table>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<tr><td colspan=2><input type=submit value='Submit'></td></tr>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "</table>\n<input type=hidden name='w' id='w' ", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "value='", ap_escape_uri(r->pool, wsel->s->name), "'>\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "<input type=hidden name='b' id='b' ", NULL);
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);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "</form>\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<hr />\n", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe } else if (bsel) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe const apr_array_header_t *provs;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe const ap_list_provider_names_t *pname;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe int i;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("<h3>Edit balancer settings for ", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rvputs(r, bsel->s->name, "</h3>\n", NULL);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("<form method='POST' enctype='application/x-www-form-urlencoded' action='", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rvputs(r, action, "'>\n", NULL);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("<dl>\n<table>\n", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe provs = ap_list_provider_names(r->pool, PROXY_LBMETHOD, "0");
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (provs) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("<tr><td>LBmethod:</td>", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("<td>\n<select name='b_lbm' id='b_lbm'>", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe pname = (ap_list_provider_names_t *)provs->elts;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe for (i = 0; i < provs->nelts; i++, pname++) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rvputs(r,"<option value='", pname->provider_name, "'", NULL);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (strcmp(pname->provider_name, bsel->s->lbpname) == 0)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs(" selected ", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rvputs(r, ">", pname->provider_name, "\n", NULL);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("</select>\n</td></tr>\n", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("<tr><td>Timeout:</td><td><input name='b_tmo' id='b_tmo' type=text ", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rprintf(r, "value='%" APR_TIME_T_FMT "'></td></tr>\n", apr_time_sec(bsel->s->timeout));
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("<tr><td>Failover Attempts:</td><td><input name='b_max' id='b_max' type=text ", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rprintf(r, "value='%d'></td></tr>\n", bsel->s->max_attempts);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("<tr><td>Disable Failover:</td>", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe create_radio("b_sforce", bsel->s->sticky_force, r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_rputs("<tr><td>Sticky Session:</td><td><input name='b_ss' id='b_ss' size=64 type=text ", r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (strcmp(bsel->s->sticky, bsel->s->sticky_path)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "value ='", bsel->s->sticky, " | ",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb bsel->s->sticky_path, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
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);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (storage->num_free_slots(bsel->wslot) != 0) {
4ca6cbe768b4e0917ac0b76333c26a7d5396d454trawick 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);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
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);
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);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rvputs(r, "</form>\n", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("<hr />\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs(ap_psignature("",r), r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rputs("</body></html>\n", r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_rflush(r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return DONE;
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic void balancer_child_init(apr_pool_t *p, server_rec *s)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb while (s) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer *balancer;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe int i;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe void *sconf = s->module_config;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe apr_status_t rv;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conf->balancers->nelts) {
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe apr_size_t size;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe unsigned int num;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe storage->attach(&(conf->bslot), conf->id, &size, &num, p);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe if (!conf->bslot) {
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, APLOGNO(01205) "slotmem_attach failed");
1b839c67d5c0e4b1f22b44a4217f9860b420d47cwrowe exit(1); /* Ugly, but what else? */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
1ab995011876f631740d68d960a6d729ddff5bfawrowe balancer = (proxy_balancer *)conf->balancers->elts;
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb rv = ap_proxy_initialize_balancer(balancer, s, p);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb if (rv != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(01206)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Failed to init balancer %s in child",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->name);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb exit(1); /* Ugly, but what else? */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb init_balancer_members(conf->pool, s, balancer);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb s = s->next;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowestatic void ap_proxy_balancer_register_hook(apr_pool_t *p)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Only the mpm_winnt has child init hook handler.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * make sure that we are called after the mpm
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * initializes
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb static const char *const aszPred[] = { "mpm_winnt.c", "mod_slotmem_shm.c", NULL};
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* manager handler */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_hook_post_config(balancer_post_config, NULL, NULL, APR_HOOK_MIDDLE);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_hook_pre_config(balancer_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_hook_handler(balancer_handler, NULL, NULL, APR_HOOK_FIRST);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_hook_child_init(balancer_child_init, aszPred, NULL, APR_HOOK_MIDDLE);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_hook_pre_request(proxy_balancer_pre_request, NULL, NULL, APR_HOOK_FIRST);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_hook_post_request(proxy_balancer_post_request, NULL, NULL, APR_HOOK_FIRST);
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe proxy_hook_canon_handler(proxy_balancer_canon, NULL, NULL, APR_HOOK_FIRST);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe}
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wroweAP_DECLARE_MODULE(proxy_balancer) = {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe STANDARD20_MODULE_STUFF,
117026201e6d8fe7d82416b8a7324830f5a87292wrowe NULL, /* create per-directory config structure */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe NULL, /* merge per-directory config structures */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe NULL, /* create per-server config structure */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe NULL, /* merge per-server config structures */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe NULL, /* command apr_table_t */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe ap_proxy_balancer_register_hook /* register hooks */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe};
117026201e6d8fe7d82416b8a7324830f5a87292wrowe