Re: how to bind mod_proxy to a specific ip address?

Ian Holsman <[email protected]> Fri, 14 Nov 2003 07:49:03 +1100
Newsgroups gmane.comp.apache.mod-proxy
Message-ID <[email protected]>
On 14/11/2003, at 7:38 AM, Cahya Wirawan wrote:

> On Tue, Nov 11, 2003 at 03:38:31PM +0200, Eli Marmor wrote:
>> I wrote:
>>
>>> ...
>>> And as the original sender hinted by the "Subject" header, it is easy
>>> to implement: just "bind()" the required IP into the socket before
>>> calling "apr_connect()" (it may require a minor fix in APR, I'm not
>>> sure).
>>
>> After looking at srclib/apr/network_io/unix/sockets.c and
>> srclib/apr/network_io/win32/sockets.c, I believe that the feature
>> request is doable, and doesn't require any change in APR, but only in
>> files belong to modules/proxy.
>>
>
> Hi,
> Because I want to try this feature in next days, I tried to change
> the mod_proxy myself. but since I have no experience with mod_proxy
> programming at all, I would like you to correct my change or tell
> me if the change can have a bad side effect. my change will bind
> mod_proxy to the  ip address defined in VirtualHost, and it works
> here at least.
> The change is only in the proxy_util.c , here is the patch:
> ____________________________________________
> diff -Naur httpd-2.0.48/modules/proxy/proxy_util.c 
> httpd-2.0.48-new/modules/proxy/proxy_util.c
> --- httpd-2.0.48/modules/proxy/proxy_util.c     2003-11-12 
> 18:20:06.000000000 +0100
> +++ httpd-2.0.48-new/modules/proxy/proxy_util.c 2003-11-13 
> 21:08:31.000000000 +0100
> @@ -1162,6 +1162,8 @@
>                                                 apr_pool_t *p)
>  {
>      apr_status_t rv;
> +    apr_status_t err;
> +    apr_sockaddr_t *vhost_addr;
>      int connected = 0;
>      int loglevel;
>
> @@ -1181,6 +1183,10 @@
>              backend_addr = backend_addr->next;
>              continue;
>          }
> +
> +       err = apr_sockaddr_info_get(&vhost_addr, s->addrs->virthost,
> +             APR_UNSPEC, 0, 0, p);
> +       apr_socket_bind(*newsock, vhost_addr);
>

two points.
where are you specifying *which* ip you want to bind to.
are you relying on the request coming in on the same ip# your request 
should be going out on?

'err' isn't required, just use 'rv', and CHECK the result code it 
returns.. (and put a errorlog line if it fails)
you'll thank me in 2 months when something wierd happens ;-)

>  #if !defined(TPF) && !defined(BEOS)
>          if (conf->recv_buffer_size > 0 &&
> _____________________________________________
>
>
> Thanks,
> cahya
>
>
--
Ian Holsman
Director
Network Management Systems
CNET Networks
PH: (61) 3-9857-3742 (Australia)/ 415-344-2608 (USA)