Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit httpd balancer member host and port #365

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion modules/proxy/mod_proxy_balancer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,27 @@ static int balancer_process_balancer_worker(request_rec *r, proxy_server_conf *c
else
*wsel->s->route = '\0';
}

if ((val = apr_table_get(params, "b_ewyes")) &&
(*val == '1' && *(val+1) == '\0') &&
(val = apr_table_get(params, "b_ewrkr"))) {
if (strlen(val)){
apr_status_t rc;
apr_uri_t wurl;
rc = apr_uri_parse(r->pool, val, &wurl);

if(rc == APR_SUCCESS && wurl.scheme && wurl.hostname){
wsel->s->port = wurl.port;
ap_str_tolower(wurl.hostname);
strcpy(wsel->s->hostname_ex, wurl.hostname);
ap_str_tolower(val);
strcpy(wsel->s->name_ex, val);
} else{
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01192) "Edit worker url failed");
}
}
}

if ((val = apr_table_get(params, "w_rr"))) {
if (*val && strlen(val) < sizeof(wsel->s->redirect))
strcpy(wsel->s->redirect, val);
Expand Down Expand Up @@ -1789,7 +1810,12 @@ static void balancer_display_page(request_rec *r, proxy_server_conf *conf,
ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->redirect),
NULL);
ap_rputs("\"></td></tr>\n", r);
ap_rputs("<tr><td>Status:</td>", r);
ap_rputs("<tr><td>Worker URL:</td><td><input name='b_ewrkr' id='b_ewrkr' size=32 type=text ", r);
ap_rvputs(r, "value=\"", ap_escape_html(r->pool, wsel->s->name_ex),
NULL);
ap_rputs("\">&nbsp;&nbsp;&nbsp;&nbsp;Are you sure? <input name='b_ewyes' id='b_ewyes' type=checkbox value='1'>"
"</td></tr>\n", r);
ap_rputs("<tr><td>Status:</td>", r);
ap_rputs("<td><table><tr>"
"<th>Ignore Errors</th>"
"<th>Draining Mode</th>"
Expand Down
4 changes: 3 additions & 1 deletion modules/proxy/mod_proxy_hcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ static proxy_worker *hc_get_hcworker(sctx_t *ctx, proxy_worker *worker,
}
/* This *could* have changed via the Balancer Manager */
/* TODO */
if (hc->s->method != worker->s->method) {
if (hc->s->method != worker->s->method || !strcmp(hc->s->hostname_ex, worker->s->hostname_ex) || hc->s->port != worker->s->port) {
Mrida marked this conversation as resolved.
Show resolved Hide resolved
wctx_t *wctx = hc->context;
port = (worker->s->port ? worker->s->port
: ap_proxy_port_of_scheme(worker->s->scheme));
Expand All @@ -543,6 +543,8 @@ static proxy_worker *hc_get_hcworker(sctx_t *ctx, proxy_worker *worker,
worker, worker->s->scheme, worker->s->hostname_ex,
(int)port);
hc->s->method = worker->s->method;
hc->s->port = port;
strcpy(hc->s->hostname_ex, worker->s->hostname_ex);
create_hcheck_req(wctx, hc, ctx->p);
}
return hc;
Expand Down
11 changes: 10 additions & 1 deletion modules/proxy/proxy_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2768,7 +2768,16 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
socket_cleanup(conn);
conn->close = 0;
}
if (will_reuse) {
if (will_reuse) {
if(!strcmp(conn->hostname, worker->s->hostname_ex) || conn->port != worker->s->port) {
apr_sockaddr_t *addr;
err = apr_sockaddr_info_get(&addr,
worker->s->hostname_ex, APR_UNSPEC,
worker->s->port, 0,
worker->cp->dns_pool);
worker->cp->addr = addr;
}
Copy link
Member

@ylavic ylavic Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coincidentally I just started a discussion there https://lists.apache.org/thread/jftfd6mo6p3b0tw694rlh09gdl7189hq about the unsafety of changing worker->cp->addr like this. We need a thread-safe way to do it, probably outside the scope of this PR though..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to talk about changing worker->s->hostname_ex/port (even under the worker lock) while there are concurrent readers like here which don't take the lock.


/*
* Looking up the backend address for the worker only makes sense if
* we can reuse the address.
Expand Down