ASF Bugzilla – Attachment 18579 Details for
Bug 29404
Allow definition of source address of outgoing connections from mod_proxy
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Proxy source address patch against httpd-2.2.2
apache-proxy-source-addr-patch-2.2.2.diff (text/plain), 6.30 KB, created by
Aron Ujvari
on 2006-07-10 10:48:55 UTC
(
hide
)
Description:
Proxy source address patch against httpd-2.2.2
Filename:
MIME Type:
Creator:
Aron Ujvari
Created:
2006-07-10 10:48:55 UTC
Size:
6.30 KB
patch
obsolete
>diff -Nur httpd-2.2.2-orig/modules/proxy/mod_proxy.c httpd-2.2.2/modules/proxy/mod_proxy.c >--- httpd-2.2.2-orig/modules/proxy/mod_proxy.c 2006-04-22 03:53:06.000000000 +0200 >+++ httpd-2.2.2/modules/proxy/mod_proxy.c 2006-07-10 12:32:06.000000000 +0200 >@@ -238,6 +238,21 @@ > else > worker->flush_wait = ival * 1000; /* change to microseconds */ > } >+ else if (!strcasecmp(key, "bind")) { >+ apr_status_t status; >+ >+ worker->bind_addr = NULL; >+ if ((status = apr_sockaddr_info_get(&worker->bind_addr, val, APR_UNSPEC, >+ 0, 0, p)) >+ != APR_SUCCESS) { >+ ap_log_perror(APLOG_MARK, APLOG_CRIT, status, p, >+ "ProxySourceAddress: failed to set up sockaddr for %s", >+ val); >+ /* should free allocated pool memory, but we're about to exit */ >+ worker->bind_addr = NULL; >+ return "Proxy Source Address invalid"; >+ } >+ } > else { > return "unknown Worker parameter"; > } >@@ -845,6 +860,7 @@ > ps->error_override_set = 0; > ps->preserve_host_set = 0; > ps->preserve_host = 0; >+ ps->bind_addr = NULL; > ps->timeout = 0; > ps->timeout_set = 0; > ps->badopt = bad_error; >@@ -879,6 +895,7 @@ > ps->maxfwd = (overrides->maxfwd_set == 0) ? base->maxfwd : overrides->maxfwd; > ps->error_override = (overrides->error_override_set == 0) ? base->error_override : overrides->error_override; > ps->preserve_host = (overrides->preserve_host_set == 0) ? base->preserve_host : overrides->preserve_host; >+ ps->bind_addr = (overrides->bind_addr == NULL) ? base->bind_addr : overrides->bind_addr; > ps->timeout= (overrides->timeout_set == 0) ? base->timeout : overrides->timeout; > ps->badopt = (overrides->badopt_set == 0) ? base->badopt : overrides->badopt; > ps->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status; >@@ -1348,6 +1365,29 @@ > return NULL; > } > >+static const char * >+ set_source_address(cmd_parms *parms, void *dummy, const char *arg) >+{ >+ apr_status_t status; >+ apr_pool_t *pool = parms->server->process->pconf; >+ proxy_server_conf *psf = >+ ap_get_module_config (parms->server->module_config, &proxy_module); >+ >+ psf->bind_addr = NULL; >+ if ((status = apr_sockaddr_info_get(&psf->bind_addr, arg, APR_UNSPEC, >+ 0, 0, pool)) >+ != APR_SUCCESS) { >+ ap_log_perror(APLOG_MARK, APLOG_CRIT, status, pool, >+ "ProxySourceAddress: failed to set up sockaddr for %s", >+ arg); >+ /* should free allocated pool memory, but we're about to exit */ >+ psf->bind_addr = NULL; >+ return "Proxy Source Address invalid"; >+ } >+ >+ return NULL; >+} >+ > static const char* > set_via_opt(cmd_parms *parms, void *dummy, const char *arg) > { >@@ -1688,6 +1728,8 @@ > "use our error handling pages instead of the servers' we are proxying"), > AP_INIT_FLAG("ProxyPreserveHost", set_preserve_host, NULL, RSRC_CONF, > "on if we should preserve host header while proxying"), >+ AP_INIT_TAKE1("ProxySourceAddress", set_source_address, NULL, RSRC_CONF, >+ "The IP address from which proxy requests will appear to come"), > AP_INIT_TAKE1("ProxyTimeout", set_proxy_timeout, NULL, RSRC_CONF, > "Set the timeout (in seconds) for a proxied connection. " > "This overrides the server timeout"), >diff -Nur httpd-2.2.2-orig/modules/proxy/mod_proxy.h httpd-2.2.2/modules/proxy/mod_proxy.h >--- httpd-2.2.2-orig/modules/proxy/mod_proxy.h 2006-04-22 03:53:06.000000000 +0200 >+++ httpd-2.2.2/modules/proxy/mod_proxy.h 2006-07-10 12:32:06.000000000 +0200 >@@ -167,6 +167,7 @@ > int error_override_set; > int preserve_host; > int preserve_host_set; >+ apr_sockaddr_t *bind_addr; /* source address */ > apr_interval_time_t timeout; > char timeout_set; > enum { >@@ -287,6 +288,7 @@ > int hmax; /* Hard maximum on the total number of connections */ > apr_interval_time_t ttl; /* maximum amount of time in seconds a connection > * may be available while exceeding the soft limit */ >+ apr_sockaddr_t *bind_addr; /* source address */ > apr_interval_time_t timeout; /* connection timeout */ > char timeout_set; > apr_interval_time_t acquire; /* acquire timeout when the maximum number of connections is exceeded */ >diff -Nur httpd-2.2.2-orig/modules/proxy/proxy_util.c httpd-2.2.2/modules/proxy/proxy_util.c >--- httpd-2.2.2-orig/modules/proxy/proxy_util.c 2006-04-22 03:53:06.000000000 +0200 >+++ httpd-2.2.2/modules/proxy/proxy_util.c 2006-07-10 12:32:06.000000000 +0200 >@@ -1479,6 +1479,20 @@ > apr_socket_timeout_set(*newsock, s->timeout); > } > >+ if (conf->bind_addr != NULL && >+ apr_socket_bind(*newsock, conf->bind_addr) != APR_SUCCESS) { >+ apr_socket_close(*newsock); >+ loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR; >+ ap_log_error(APLOG_MARK, loglevel, rv, s, >+ "proxy: %s: attempt to bind to source address %pI failed for target %s", >+ proxy_function, >+ conf->bind_addr, >+ backend_name >+ ); >+ backend_addr = backend_addr->next; >+ continue; >+ } >+ > ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, > "proxy: %s: fam %d socket created to connect to %s", > proxy_function, backend_addr->family, backend_name); >@@ -2033,6 +2047,21 @@ > else { > apr_socket_timeout_set(newsock, s->timeout); > } >+ >+ if (worker->bind_addr != NULL && >+ apr_socket_bind(newsock, worker->bind_addr) != APR_SUCCESS) { >+ apr_socket_close(newsock); >+ loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR; >+ ap_log_error(APLOG_MARK, loglevel, rv, s, >+ "proxy: %s: attempt to bind to source address %pI failed for target %s", >+ proxy_function, >+ worker->bind_addr, >+ worker->hostname >+ ); >+ backend_addr = backend_addr->next; >+ continue; >+ } >+ > /* Set a keepalive option */ > if (worker->keepalive) { > if ((rv = apr_socket_opt_set(newsock,
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 29404
:
11770
|
11796
| 18579 |
21507
|
21508
|
24440
|
24441
|
25229