ASF Bugzilla – Attachment 22039 Details for
Bug 44806
Set the IP address+port used for backend proxy requests.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Slightly better, staggers the starting index so that the number of tries for bind is less
patch (text/plain), 4.91 KB, created by
rahul
on 2008-05-30 09:33:09 UTC
(
hide
)
Description:
Slightly better, staggers the starting index so that the number of tries for bind is less
Filename:
MIME Type:
Creator:
rahul
Created:
2008-05-30 09:33:09 UTC
Size:
4.91 KB
patch
obsolete
>Index: modules/proxy/proxy_util.c >=================================================================== >--- modules/proxy/proxy_util.c (revision 661736) >+++ modules/proxy/proxy_util.c (working copy) >@@ -2275,7 +2275,7 @@ > apr_status_t rv; > int connected = 0; > int loglevel; >- apr_sockaddr_t *backend_addr = conn->addr; >+ apr_sockaddr_t *backend_addr = conn->addr, *local_addr; > apr_socket_t *newsock; > void *sconf = s->module_config; > proxy_server_conf *conf = >@@ -2349,6 +2349,35 @@ > "proxy: %s: fam %d socket created to connect to %s", > proxy_function, backend_addr->family, worker->hostname); > >+ if (conf->bindopt_set) { >+ const int idx = conf->bind_idx; >+ const int range = conf->bind_range; >+ const int start = conf->bind_port; >+ for(int i = 0; i < range; ++i) { /* loop until we can bind correctly*/ >+ int port = start + ((idx + i) % range); >+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "proxy: %s: trying to bind to %s:%d", >+ proxy_function, conf->bind_addr,port, NULL); >+ >+ apr_sockaddr_info_get(&local_addr, conf->bind_addr, APR_UNSPEC, >+ port, 0, conn->scpool); >+ >+ if ((rv = apr_socket_bind(newsock, local_addr)) == APR_SUCCESS) { >+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "proxy: %s: bound to %s:%d", >+ proxy_function, conf->bind_addr, local_addr->port, NULL); >+ conf->bind_idx = i + 1; >+ break; >+ } else { >+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "proxy: %s: not bound to %s:%d", >+ proxy_function, conf->bind_addr, local_addr->port, NULL); >+ } >+ } >+ if (rv != APR_SUCCESS) { >+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "proxy: %s: can not bound to %s:%d+%d", >+ proxy_function,conf->bind_addr, conf->bind_port, conf->bind_range, NULL); >+ return DECLINED; >+ } >+ } >+ > /* make the connection out of the socket */ > rv = apr_socket_connect(newsock, backend_addr); > >Index: modules/proxy/mod_proxy.c >=================================================================== >--- modules/proxy/mod_proxy.c (revision 661736) >+++ modules/proxy/mod_proxy.c (working copy) >@@ -1066,6 +1066,8 @@ > ps->timeout_set = 0; > ps->badopt = bad_error; > ps->badopt_set = 0; >+ ps->bindopt_set = 0; >+ ps->bind_idx = 0; > ps->pool = p; > > return ps; >@@ -1109,6 +1111,7 @@ > ps->badopt_set = overrides->badopt_set || base->badopt_set; > ps->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status; > ps->proxy_status_set = overrides->proxy_status_set || base->proxy_status_set; >+ ps->bindopt_set = overrides->bindopt_set || base->bindopt_set; > ps->pool = p; > return ps; > } >@@ -1706,6 +1709,33 @@ > return NULL; > } > >+static const char* >+ set_proxy_bindaddr(cmd_parms *parms, void *dummy, const char *arg) >+{ >+ const char* port; >+ const char* range; >+ >+ proxy_server_conf *psf = >+ ap_get_module_config(parms->server->module_config, &proxy_module); >+ port = ap_strstr_c(arg, ":"); >+ if (!port) { >+ psf->bind_addr = arg; >+ psf->bind_port = 0; >+ psf->bind_range = 1; /* when port=0, bind should not fail */ >+ return NULL; >+ } >+ psf->bind_addr = apr_pstrndup(parms->pool, arg, port-arg); >+ range = ap_strstr_c(port, "+"); >+ if (!range) >+ return "ProxyBindAddress format is <addr>:<port>+<range>"; >+ psf->bind_port = atoi(port+1); >+ psf->bind_range = atoi(range+1); >+ psf->bind_idx = 0; >+ >+ psf->bindopt_set = 1; >+ return NULL; >+} >+ > static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg) > { > server_rec *s = cmd->server; >@@ -2088,6 +2118,8 @@ > "A balancer or worker name with list of params"), > AP_INIT_TAKE1("ProxyFtpDirCharset", set_ftp_directory_charset, NULL, > RSRC_CONF|ACCESS_CONF, "Define the character set for proxied FTP listings"), >+ AP_INIT_TAKE1("ProxyBindAddress", set_proxy_bindaddr, NULL, RSRC_CONF, >+ "Set the source address for a proxied connection. "), > {NULL} > }; > >Index: modules/proxy/mod_proxy.h >=================================================================== >--- modules/proxy/mod_proxy.h (revision 661736) >+++ modules/proxy/mod_proxy.h (working copy) >@@ -190,6 +190,12 @@ > status_full > } proxy_status; /* Status display options */ > char proxy_status_set; >+ /*bind to local ports*/ >+ const char *bind_addr; >+ int bind_port; >+ int bind_range; /* restrict the source ports used by mod_proxy */ >+ int bind_idx; >+ char bindopt_set; > apr_pool_t *pool; /* Pool used for allocating this struct */ > } proxy_server_conf; >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 44806
:
22038
|
22039
|
22040
|
22051
|
22058
|
22068
|
22074
|
22134