You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jf...@apache.org on 2021/03/03 11:01:03 UTC

svn commit: r1887138 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c mod_proxy_balancer.c

Author: jfclere
Date: Wed Mar  3 11:01:02 2021
New Revision: 1887138

URL: http://svn.apache.org/viewvc?rev=1887138&view=rev
Log:
Allow empty <balancer://mycluster/> and add a provider to allow other modules to create workers.

Modified:
    httpd/httpd/trunk/modules/proxy/mod_proxy.c
    httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.c?rev=1887138&r1=1887137&r2=1887138&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.c Wed Mar  3 11:01:02 2021
@@ -2969,79 +2969,78 @@ static const char *proxysection(cmd_parm
 
     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 <yl...@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 (!worker->section_config) {
-                worker->section_config = new_dir_conf;
-            }
+        if (!balancer->section_config) {
+            balancer->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 {
+        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);
             }
-            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);
+                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 (!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;

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c?rev=1887138&r1=1887137&r2=1887138&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy_balancer.c Wed Mar  3 11:01:02 2021
@@ -1109,12 +1109,12 @@ static void push2table(const char *input
  */
 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_wor
 
     }
 
-    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_wor
 }
 
 /*
+ * 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
 
     /* 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_h
     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);