summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorJean-Frederic Clere <jfclere@apache.org>2021-03-03 12:01:02 +0100
committerJean-Frederic Clere <jfclere@apache.org>2021-03-03 12:01:02 +0100
commit89d543337b7eead1edebcb8d32604835f0249e22 (patch)
tree1622f85e80acb530d5e616e3d5d887458b427a65 /modules
parentFixed regression in r1887085 where a SSL function was used that is not availa... (diff)
downloadapache2-89d543337b7eead1edebcb8d32604835f0249e22.tar.xz
apache2-89d543337b7eead1edebcb8d32604835f0249e22.zip
Allow empty <balancer://mycluster/> and add a provider to allow other modules to create workers.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1887138 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules')
-rw-r--r--modules/proxy/mod_proxy.c133
-rw-r--r--modules/proxy/mod_proxy_balancer.c67
2 files changed, 119 insertions, 81 deletions
diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c
index 3380e1d5e0..233019ccec 100644
--- a/modules/proxy/mod_proxy.c
+++ b/modules/proxy/mod_proxy.c
@@ -2969,79 +2969,78 @@ static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg)
ap_add_per_proxy_conf(cmd->server, new_dir_conf);
- if (*arg != '\0') {
- if (thiscmd->cmd_data)
- return "Multiple <ProxyMatch> arguments not (yet) supported.";
- if (conf->p_is_fnmatch)
- return apr_pstrcat(cmd->pool, thiscmd->name,
- "> arguments are not supported for wildchar url.",
- NULL);
- if (!ap_strchr_c(conf->p, ':'))
- return apr_pstrcat(cmd->pool, thiscmd->name,
- "> arguments are not supported for non url.",
- NULL);
- if (ap_proxy_valid_balancer_name((char *)conf->p, 9)) {
- balancer = ap_proxy_get_balancer(cmd->pool, sconf, conf->p, 0);
- if (!balancer) {
- err = ap_proxy_define_balancer(cmd->pool, &balancer,
- sconf, conf->p, "/", 0);
- if (err)
- return apr_pstrcat(cmd->temp_pool, thiscmd->name,
- " ", err, NULL);
- }
- if (!balancer->section_config) {
- balancer->section_config = new_dir_conf;
- }
+ /* if (*arg != '\0') { Yann Ylavic <ylavic.dev@gmail.com> */
+ if (thiscmd->cmd_data)
+ return "Multiple <ProxyMatch> arguments not (yet) supported.";
+ if (conf->p_is_fnmatch)
+ return apr_pstrcat(cmd->pool, thiscmd->name,
+ "> arguments are not supported for wildchar url.",
+ NULL);
+ if (!ap_strchr_c(conf->p, ':'))
+ return apr_pstrcat(cmd->pool, thiscmd->name,
+ "> arguments are not supported for non url.",
+ NULL);
+ if (ap_proxy_valid_balancer_name((char *)conf->p, 9)) {
+ balancer = ap_proxy_get_balancer(cmd->pool, sconf, conf->p, 0);
+ if (!balancer) {
+ err = ap_proxy_define_balancer(cmd->pool, &balancer,
+ sconf, conf->p, "/", 0);
+ if (err)
+ return apr_pstrcat(cmd->temp_pool, thiscmd->name,
+ " ", err, NULL);
}
- else {
- worker = ap_proxy_get_worker(cmd->temp_pool, NULL, sconf,
- ap_proxy_de_socketfy(cmd->temp_pool, (char*)conf->p));
- if (!worker) {
- if (use_regex) {
- err = ap_proxy_define_match_worker(cmd->pool, &worker, NULL,
- sconf, conf->p, 0);
- }
- else {
- err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
- sconf, conf->p, 0);
- }
- if (err)
- return apr_pstrcat(cmd->temp_pool, thiscmd->name,
- " ", err, NULL);
- }
- else if ((use_regex != 0) ^ (worker->s->is_name_matchable != 0)) {
- return apr_pstrcat(cmd->temp_pool, "ProxyPass/<Proxy> and "
- "ProxyPassMatch/<ProxyMatch> can't be used "
- "altogether with the same worker name ",
- "(", worker->s->name, ")", NULL);
+ if (!balancer->section_config) {
+ balancer->section_config = new_dir_conf;
+ }
+ }
+ else {
+ worker = ap_proxy_get_worker(cmd->temp_pool, NULL, sconf,
+ ap_proxy_de_socketfy(cmd->temp_pool, (char*)conf->p));
+ if (!worker) {
+ if (use_regex) {
+ err = ap_proxy_define_match_worker(cmd->pool, &worker, NULL,
+ sconf, conf->p, 0);
}
- if (!worker->section_config) {
- worker->section_config = new_dir_conf;
+ else {
+ err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
+ sconf, conf->p, 0);
}
+ if (err)
+ return apr_pstrcat(cmd->temp_pool, thiscmd->name,
+ " ", err, NULL);
}
- if (worker == NULL && balancer == NULL) {
- return apr_pstrcat(cmd->pool, thiscmd->name,
- "> arguments are supported only for workers.",
- NULL);
+ else if ((use_regex != 0) ^ (worker->s->is_name_matchable != 0)) {
+ return apr_pstrcat(cmd->temp_pool, "ProxyPass/<Proxy> and "
+ "ProxyPassMatch/<ProxyMatch> can't be used "
+ "altogether with the same worker name ",
+ "(", worker->s->name, ")", NULL);
}
- while (*arg) {
- word = ap_getword_conf(cmd->pool, &arg);
- val = strchr(word, '=');
- if (!val) {
- return "Invalid Proxy parameter. Parameter must be "
- "in the form 'key=value'";
- }
- else
- *val++ = '\0';
- if (worker)
- err = set_worker_param(cmd->pool, cmd->server, worker, word, val);
- else
- err = set_balancer_param(sconf, cmd->pool, balancer,
- word, val);
- if (err)
- return apr_pstrcat(cmd->temp_pool, thiscmd->name, " ", err, " ",
- word, "=", val, "; ", conf->p, NULL);
+ if (!worker->section_config) {
+ worker->section_config = new_dir_conf;
+ }
+ }
+ if (worker == NULL && balancer == NULL) {
+ return apr_pstrcat(cmd->pool, thiscmd->name,
+ "> arguments are supported only for workers.",
+ NULL);
+ }
+ while (*arg) {
+ word = ap_getword_conf(cmd->pool, &arg);
+ val = strchr(word, '=');
+ if (!val) {
+ return "Invalid Proxy parameter. Parameter must be "
+ "in the form 'key=value'";
}
+ else
+ *val++ = '\0';
+ if (worker)
+ err = set_worker_param(cmd->pool, cmd->server, worker, word, val);
+ else
+ err = set_balancer_param(sconf, cmd->pool, balancer,
+ word, val);
+ if (err)
+ return apr_pstrcat(cmd->temp_pool, thiscmd->name, " ", err, " ",
+ word, "=", val, "; ", conf->p, NULL);
}
cmd->path = old_path;
diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c
index 66be13a6d6..5032e2d55a 100644
--- a/modules/proxy/mod_proxy_balancer.c
+++ b/modules/proxy/mod_proxy_balancer.c
@@ -1109,12 +1109,12 @@ static void push2table(const char *input, apr_table_t *params,
*/
static int balancer_process_balancer_worker(request_rec *r, proxy_server_conf *conf,
proxy_balancer *bsel,
- proxy_worker *wsel, int ok2change,
+ proxy_worker *wsel,
apr_table_t *params)
{
apr_status_t rv;
/* First set the params */
- if (wsel && ok2change) {
+ if (wsel) {
const char *val;
int was_usable = PROXY_WORKER_IS_USABLE(wsel);
@@ -1223,7 +1223,7 @@ static int balancer_process_balancer_worker(request_rec *r, proxy_server_conf *c
}
- if (bsel && ok2change) {
+ if (bsel) {
const char *val;
int ival;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01193)
@@ -1374,6 +1374,42 @@ static int balancer_process_balancer_worker(request_rec *r, proxy_server_conf *c
}
/*
+ * Process a request for balancer or worker management from another module
+ */
+static int balancer_manage(request_rec *r, apr_table_t *params)
+{
+ void *sconf;
+ proxy_server_conf *conf;
+ proxy_balancer *bsel = NULL;
+ proxy_worker *wsel = NULL;
+ const char *name;
+ sconf = r->server->module_config;
+ conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+
+ /* Process the parameters */
+ if ((name = apr_table_get(params, "b"))) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "balancer_manage "
+ "balancer: %s", name);
+ bsel = ap_proxy_get_balancer(r->pool, conf,
+ apr_pstrcat(r->pool, BALANCER_PREFIX, name, NULL), 0);
+ }
+
+ if ((name = apr_table_get(params, "w"))) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "balancer_manage "
+ "worker: %s", name);
+ wsel = ap_proxy_get_worker(r->pool, bsel, conf, name);
+ }
+ if (bsel) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "balancer_manage "
+ "balancer: %s", bsel->s->name);
+ return(balancer_process_balancer_worker(r, conf, bsel, wsel, params));
+ }
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "balancer_manage failed: "
+ "No balancer!");
+ return HTTP_BAD_REQUEST;
+}
+
+/*
* builds the page and links to configure via HTLM or XML.
*/
static void balancer_display_page(request_rec *r, proxy_server_conf *conf,
@@ -1947,21 +1983,23 @@ static int balancer_handler(request_rec *r)
/* Check that the supplied nonce matches this server's nonce;
* otherwise ignore all parameters, to prevent a CSRF attack. */
- if (!bsel ||
- (*bsel->s->nonce &&
- (
- (name = apr_table_get(params, "nonce")) == NULL ||
- strcmp(bsel->s->nonce, name) != 0
- )
- )
- ) {
+ if ((name = apr_table_get(params, "nonce"))) {
+ /* we have a nonce */
+ if (bsel) {
+ /* we have a balancer */
+ if (*bsel->s->nonce && strcmp(bsel->s->nonce, name) != 0)
+ ok2change = 0;
+ }
+ } else {
ok2change = 0;
}
/* process the parameters and add the worker to the balancer */
- rv = balancer_process_balancer_worker(r, conf, bsel, wsel, ok2change, params);
- if (rv != APR_SUCCESS) {
- return HTTP_BAD_REQUEST;
+ if (ok2change) {
+ rv = balancer_process_balancer_worker(r, conf, bsel, wsel, params);
+ if (rv != APR_SUCCESS) {
+ return HTTP_BAD_REQUEST;
+ }
}
/* display the HTML or XML page */
@@ -2030,6 +2068,7 @@ static void ap_proxy_balancer_register_hook(apr_pool_t *p)
static const char *const aszPred[] = { "mpm_winnt.c", "mod_slotmem_shm.c", NULL};
static const char *const aszPred2[] = { "mod_proxy.c", NULL};
/* manager handler */
+ ap_register_provider(p, "balancer", "manager", "0", &balancer_manage);
ap_hook_post_config(balancer_post_config, aszPred2, NULL, APR_HOOK_MIDDLE);
ap_hook_pre_config(balancer_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_handler(balancer_handler, NULL, NULL, APR_HOOK_FIRST);