You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1998/09/16 12:34:42 UTC
HINTS PLEASE: how to determine named-based vhost
A poked around in our http_vhost.c source but couldn't find an API function
which can be used. The problem is this: SSL interfaces like mod_ssl and
Apache-SSL should check whether the configured SSL-vhost is name-based or not.
Because fo SSL it _has_ to be IP-based. So, what's basically needed (and it
would be fine when we could add it for 1.3.2 and not patch it into the code
for mod_ssl, Apache-SSL, etc.) is
int ap_is_name_based_vhost(server_rec *s);
As it looks it has to search "s" inside the iphash_table from http_vhost and
when it is found it has to look for the "names" attribute.
In other words:
API_EXPORT int ap_is_name_based_vhost(server_rec *s)
{
ipaddr_chain *ic;
int rc = 0;
int i;
for (i = 0; i < IPHASH_TABLE_SIZE; i++) {
for (ic = iphash_table[i]; ic != NULL; ic = ic->next) {
if (ic->server == s) {
if (ic->names == NULL)
rc = 1;
break;
}
}
}
return rc;
}
Is this correct and if yes, is it ok to be added to httpd_vhost.c? Dean?
Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com
Re: HINTS PLEASE: how to determine named-based vhost
Posted by Dean Gaudet <dg...@arctic.org>.
On Wed, 16 Sep 1998, Ralf S. Engelschall wrote:
> A poked around in our http_vhost.c source but couldn't find an API function
> which can be used. The problem is this: SSL interfaces like mod_ssl and
> Apache-SSL should check whether the configured SSL-vhost is name-based or not.
> Because fo SSL it _has_ to be IP-based. So, what's basically needed (and it
> would be fine when we could add it for 1.3.2 and not patch it into the code
> for mod_ssl, Apache-SSL, etc.) is
>
> int ap_is_name_based_vhost(server_rec *s);
This is an impossible question to answer. Consider:
NameVirtualHost 10.1.1.1
<VirtualHost 10.1.1.1 10.1.1.2>
ServerName foobar
blah blah
</VirtualHost>
<VirtualHost 10.1.1.1>
ServerName whatever
...
</VirtualHost>
Is foobar a name-vhost or not?
> As it looks it has to search "s" inside the iphash_table from http_vhost and
> when it is found it has to look for the "names" attribute.
> In other words:
>
> API_EXPORT int ap_is_name_based_vhost(server_rec *s)
> {
> ipaddr_chain *ic;
> int rc = 0;
> int i;
>
> for (i = 0; i < IPHASH_TABLE_SIZE; i++) {
> for (ic = iphash_table[i]; ic != NULL; ic = ic->next) {
> if (ic->server == s) {
> if (ic->names == NULL)
> rc = 1;
> break;
> }
> }
> }
> return rc;
> }
This code doesn't do what you want... it answers the question: for
one of the IP:port pairs that s can respond to requests on, is it an
*ip*-based vhost.
I'm not sure if the real question you want to ask is:
- does this server have exactly one IP address and is that addr
shared with no other server?
or
- are all of this server's addresses unique to this server
To do the first you'll want to look at s->addrs... in either case you
always have to scan the entire hash table... which is ugly O(n^2) if you
have to do it for every server. So you may want to instead add a field
to server_rec, and add the calculation of these answers to the hashing
process in ap_fini_vhost_config().
Dean