chuck 97/04/10 22:10:55
Modified: src/modules/proxy mod_proxy.c mod_proxy.h proxy_connect.c
proxy_ftp.c proxy_http.c proxy_util.c
Log:
For hosts with multiple IP addresses, try all additional addresses if
necessary to get a connect(). Fail only if hostent address list is
exhausted.
Revision Changes Path
1.10 +10 -4 apache/src/modules/proxy/mod_proxy.c
Index: mod_proxy.c
===================================================================
RCS file: /export/home/cvs/apache/src/modules/proxy/mod_proxy.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C3 -r1.9 -r1.10
*** mod_proxy.c 1997/03/02 05:05:21 1.9
--- mod_proxy.c 1997/04/11 05:10:49 1.10
***************
*** 335,340 ****
--- 335,341 ----
get_module_config (s->module_config, &proxy_module);
struct noproxy_entry *new;
struct noproxy_entry *list=(struct noproxy_entry*)conf->noproxies->elts;
+ struct hostent hp;
int found = 0;
int i;
***************
*** 350,357 ****
new = push_array (conf->noproxies);
new->name = arg;
/* Don't do name lookups on things that aren't dotted */
! if (strchr(arg, '.') != NULL)
! proxy_host2addr(new->name, &new->addr);
else
new->addr.s_addr = 0;
}
--- 351,360 ----
new = push_array (conf->noproxies);
new->name = arg;
/* Don't do name lookups on things that aren't dotted */
! if (strchr(arg, '.') != NULL) {
! proxy_host2addr(new->name, &hp);
! memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr));
! }
else
new->addr.s_addr = 0;
}
***************
*** 473,478 ****
--- 476,482 ----
get_module_config (s->module_config, &proxy_module);
struct nocache_entry *new;
struct nocache_entry *list=(struct nocache_entry*)conf->nocaches->elts;
+ struct hostent hp;
int found = 0;
int i;
***************
*** 488,495 ****
new = push_array (conf->nocaches);
new->name = arg;
/* Don't do name lookups on things that aren't dotted */
! if (strchr(arg, '.') != NULL)
! proxy_host2addr(new->name, &new->addr);
else
new->addr.s_addr= 0;
}
--- 492,501 ----
new = push_array (conf->nocaches);
new->name = arg;
/* Don't do name lookups on things that aren't dotted */
! if (strchr(arg, '.') != NULL) {
! proxy_host2addr(new->name, &hp);
! memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr));
! }
else
new->addr.s_addr= 0;
}
1.10 +1 -1 apache/src/modules/proxy/mod_proxy.h
Index: mod_proxy.h
===================================================================
RCS file: /export/home/cvs/apache/src/modules/proxy/mod_proxy.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C3 -r1.9 -r1.10
*** mod_proxy.h 1997/03/20 18:40:14 1.9
--- mod_proxy.h 1997/04/11 05:10:50 1.10
***************
*** 270,275 ****
server_rec *s);
BUFF *proxy_cache_error(struct cache_req *r);
int proxyerror(request_rec *r, const char *message);
! const char *proxy_host2addr(const char *host, struct in_addr *addr);
int proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r);
--- 270,275 ----
server_rec *s);
BUFF *proxy_cache_error(struct cache_req *r);
int proxyerror(request_rec *r, const char *message);
! const char *proxy_host2addr(const char *host, struct hostent *reqhp);
int proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r);
1.7 +12 -3 apache/src/modules/proxy/proxy_connect.c
Index: proxy_connect.c
===================================================================
RCS file: /export/home/cvs/apache/src/modules/proxy/proxy_connect.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C3 -r1.6 -r1.7
*** proxy_connect.c 1997/01/07 21:51:57 1.6
--- proxy_connect.c 1997/04/11 05:10:50 1.7
***************
*** 88,98 ****
{
struct sockaddr_in server;
struct in_addr destaddr;
const char *host, *err;
char *p;
int port, sock;
char buffer[HUGE_STRING_LEN];
! int nbytes, i;
fd_set fds;
void *sconf = r->server->module_config;
--- 88,99 ----
{
struct sockaddr_in server;
struct in_addr destaddr;
+ struct hostent server_hp;
const char *host, *err;
char *p;
int port, sock;
char buffer[HUGE_STRING_LEN];
! int nbytes, i, j;
fd_set fds;
void *sconf = r->server->module_config;
***************
*** 136,142 ****
Explain2("CONNECT to %s on port %d", host, port);
server.sin_port = htons(port);
! err = proxy_host2addr(host, &server.sin_addr);
if (err != NULL)
return proxyerror(r, err); /* give up */
--- 137,143 ----
Explain2("CONNECT to %s on port %d", host, port);
server.sin_port = htons(port);
! err = proxy_host2addr(host, &server_hp);
if (err != NULL)
return proxyerror(r, err); /* give up */
***************
*** 148,154 ****
}
note_cleanups_for_fd(r->pool, sock);
! i = proxy_doconnect(sock, &server, r);
if (i == -1 )
return proxyerror(r, "Could not connect to remote machine");
--- 149,163 ----
}
note_cleanups_for_fd(r->pool, sock);
! j = 0;
! while (server_hp.h_addr_list[j] != NULL) {
! memcpy(&server.sin_addr, server_hp.h_addr_list[j],
! sizeof(struct in_addr));
! i = proxy_doconnect(sock, &server, r);
! if (i == 0)
! break;
! j++;
! }
if (i == -1 )
return proxyerror(r, "Could not connect to remote machine");
1.17 +14 -4 apache/src/modules/proxy/proxy_ftp.c
Index: proxy_ftp.c
===================================================================
RCS file: /export/home/cvs/apache/src/modules/proxy/proxy_ftp.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C3 -r1.16 -r1.17
*** proxy_ftp.c 1997/04/11 05:01:53 1.16
--- proxy_ftp.c 1997/04/11 05:10:51 1.17
***************
*** 360,369 ****
{
char *host, *path, *p, *user, *password, *parms;
const char *err;
! int port, userlen, i, len, sock, dsock, rc, nocache;
int passlen = 0;
int csd = 0;
struct sockaddr_in server;
struct hdr_entry *hdr;
struct in_addr destaddr;
array_header *resp_hdrs;
--- 360,370 ----
{
char *host, *path, *p, *user, *password, *parms;
const char *err;
! int port, userlen, i, j, len, sock, dsock, rc, nocache;
int passlen = 0;
int csd = 0;
struct sockaddr_in server;
+ struct hostent server_hp;
struct hdr_entry *hdr;
struct in_addr destaddr;
array_header *resp_hdrs;
***************
*** 454,460 ****
memset(&server, 0, sizeof(struct sockaddr_in));
server.sin_family = AF_INET;
server.sin_port = htons(port);
! err = proxy_host2addr(host, &server.sin_addr);
if (err != NULL) return proxyerror(r, err); /* give up */
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
--- 455,461 ----
memset(&server, 0, sizeof(struct sockaddr_in));
server.sin_family = AF_INET;
server.sin_port = htons(port);
! err = proxy_host2addr(host, &server_hp);
if (err != NULL) return proxyerror(r, err); /* give up */
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
***************
*** 475,482 ****
return SERVER_ERROR;
}
! i = proxy_doconnect(sock, &server, r);
! if (i == -1) return proxyerror(r, "Could not connect to remote
machine");
f = bcreate(pool, B_RDWR);
bpushfd(f, sock, sock);
--- 476,492 ----
return SERVER_ERROR;
}
! j = 0;
! while (server_hp.h_addr_list[j] != NULL) {
! memcpy(&server.sin_addr, server_hp.h_addr_list[j],
! sizeof(struct in_addr));
! i = proxy_doconnect(sock, &server, r);
! if (i == 0)
! break;
! j++;
! }
! if (i == -1)
! return proxyerror(r, "Could not connect to remote machine");
f = bcreate(pool, B_RDWR);
bpushfd(f, sock, sock);
1.17 +14 -4 apache/src/modules/proxy/proxy_http.c
Index: proxy_http.c
===================================================================
RCS file: /export/home/cvs/apache/src/modules/proxy/proxy_http.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C3 -r1.16 -r1.17
*** proxy_http.c 1997/04/06 07:43:49 1.16
--- proxy_http.c 1997/04/11 05:10:51 1.17
***************
*** 143,153 ****
{
char *p;
const char *err, *desthost;
! int i, sock, len;
array_header *reqhdrs_arr, *resp_hdrs;
table_entry *reqhdrs;
struct sockaddr_in server;
struct in_addr destaddr;
BUFF *f, *cache;
struct hdr_entry *hdr;
char buffer[HUGE_STRING_LEN], inprotocol[9], outprotocol[9];
--- 143,154 ----
{
char *p;
const char *err, *desthost;
! int i, j, sock, len;
array_header *reqhdrs_arr, *resp_hdrs;
table_entry *reqhdrs;
struct sockaddr_in server;
struct in_addr destaddr;
+ struct hostent server_hp;
BUFF *f, *cache;
struct hdr_entry *hdr;
char buffer[HUGE_STRING_LEN], inprotocol[9], outprotocol[9];
***************
*** 208,219 ****
{
url = r->uri; /* restore original URL */
server.sin_port = htons(proxyport);
! err = proxy_host2addr(proxyhost, &server.sin_addr);
if (err != NULL) return DECLINED; /* try another */
} else
{
server.sin_port = htons(destport);
! err = proxy_host2addr(desthost, &server.sin_addr);
if (err != NULL) return proxyerror(r, err); /* give up */
}
--- 209,220 ----
{
url = r->uri; /* restore original URL */
server.sin_port = htons(proxyport);
! err = proxy_host2addr(proxyhost, &server_hp);
if (err != NULL) return DECLINED; /* try another */
} else
{
server.sin_port = htons(destport);
! err = proxy_host2addr(desthost, &server_hp);
if (err != NULL) return proxyerror(r, err); /* give up */
}
***************
*** 225,231 ****
}
note_cleanups_for_fd(pool, sock);
! i = proxy_doconnect(sock, &server, r);
if (i == -1)
{
if (proxyhost != NULL) return DECLINED; /* try again another way */
--- 226,241 ----
}
note_cleanups_for_fd(pool, sock);
!
! j = 0;
! while (server_hp.h_addr_list[j] != NULL) {
! memcpy(&server.sin_addr, server_hp.h_addr_list[j],
! sizeof(struct in_addr));
! i = proxy_doconnect(sock, &server, r);
! if (i == 0)
! break;
! j++;
! }
if (i == -1)
{
if (proxyhost != NULL) return DECLINED; /* try again another way */
1.12 +7 -5 apache/src/modules/proxy/proxy_util.c
Index: proxy_util.c
===================================================================
RCS file: /export/home/cvs/apache/src/modules/proxy/proxy_util.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C3 -r1.11 -r1.12
*** proxy_util.c 1997/04/09 06:51:07 1.11
--- proxy_util.c 1997/04/11 05:10:52 1.12
***************
*** 690,699 ****
* This routine returns its own error message
*/
const char *
! proxy_host2addr(const char *host, struct in_addr *addr)
{
int i;
! unsigned long ipaddr;
for (i=0; host[i] != '\0'; i++)
if (!isdigit(host[i]) && host[i] != '.')
--- 690,700 ----
* This routine returns its own error message
*/
const char *
! proxy_host2addr(const char *host, struct hostent *reqhp)
{
int i;
! struct in_addr ipaddr;
! char *addr_str;
for (i=0; host[i] != '\0'; i++)
if (!isdigit(host[i]) && host[i] != '.')
***************
*** 705,716 ****
hp = gethostbyname(host);
if (hp == NULL) return "Host not found";
! memcpy(addr, hp->h_addr, sizeof(struct in_addr));
} else
{
! if ((ipaddr = inet_addr(host)) == -1)
return "Bad IP address";
! memcpy(addr, &ipaddr, sizeof(unsigned long));
}
return NULL;
}
--- 706,718 ----
hp = gethostbyname(host);
if (hp == NULL) return "Host not found";
! memcpy(reqhp, hp, sizeof(struct hostent));
} else
{
! if ((ipaddr.s_addr = inet_addr(host)) == -1)
return "Bad IP address";
! Explain1("Address is %s", addr_str);
! memcpy(reqhp->h_addr, &ipaddr, sizeof(struct in_addr));
}
return NULL;
}