diff options
author | Robert James Kaes <rjkaes@users.sourceforge.net> | 2004-04-27 18:53:14 +0000 |
---|---|---|
committer | Robert James Kaes <rjkaes@users.sourceforge.net> | 2004-04-27 18:53:14 +0000 |
commit | 18df4910a43e8f1b0d9d10df37236fabf0ba8508 (patch) | |
tree | ac5ab56ac77e8c7325cbde33c2b7e7864ead25ea /src/reqs.c | |
parent | 3b961ec66bdcf892c14045685f533febe3386ffb (diff) | |
download | tinyproxy-18df4910a43e8f1b0d9d10df37236fabf0ba8508.tar.gz tinyproxy-18df4910a43e8f1b0d9d10df37236fabf0ba8508.zip |
Added the "BindSame" configure directive from Oswald Buddenhagen.
This allows tinyproxy to respond to a request bound to the same
interface that the request came in on. As Oswald explains:
"attached is a patch that adds the BindSame option. it causes
binding an outgoing connection to the ip address of the respective
incoming connection. that way one can simulate an entire proxy farm
with a single instance of tinyproxy on a multi-homed machine."
Cool.
Diffstat (limited to '')
-rw-r--r-- | src/reqs.c | 29 |
1 files changed, 19 insertions, 10 deletions
@@ -1,4 +1,4 @@ -/* $Id: reqs.c,v 1.111 2004-02-13 21:27:42 rjkaes Exp $ +/* $Id: reqs.c,v 1.112 2004-04-27 18:53:14 rjkaes Exp $ * * This is where all the work in tinyproxy is actually done. Incoming * connections have a new child created for them. The child then @@ -645,7 +645,8 @@ process_request(struct conn_s *connptr, hashmap_t hashofheaders) free_request_struct(request); return NULL; - } + } else if (ret == 2) + request->protocol[0] = 0; /* * FIXME: We need to add code for the simple HTTP/0.9 style GET @@ -1111,7 +1112,7 @@ remove_connection_headers(hashmap_t hashofheaders) /* Advance ptr to the next token */ ptr += strlen(ptr) + 1; - while (*ptr == '\0') + while (ptr < data + len && *ptr == '\0') ptr++; } @@ -1609,7 +1610,7 @@ connect_to_upstream(struct conn_s *connptr, struct request_s *request) } connptr->server_fd = - opensock(cur_upstream->host, cur_upstream->port); + opensock(cur_upstream->host, cur_upstream->port, connptr->server_ip_addr); if (connptr->server_fd < 0) { log_message(LOG_WARNING, @@ -1674,15 +1675,22 @@ handle_connection(int fd) struct request_s *request = NULL; hashmap_t hashofheaders = NULL; - char peer_ipaddr[PEER_IP_LENGTH]; - char peer_string[PEER_STRING_LENGTH]; + char sock_ipaddr[IP_LENGTH]; + char peer_ipaddr[IP_LENGTH]; + char peer_string[HOSTNAME_LENGTH]; getpeer_information(fd, peer_ipaddr, peer_string); - log_message(LOG_CONN, "Connect (file descriptor %d): %s [%s]", - fd, peer_string, peer_ipaddr); + if (config.bindsame) + getsock_ip(fd, sock_ipaddr); + + log_message(LOG_CONN, config.bindsame ? + "Connect (file descriptor %d): %s [%s] at [%s]" : + "Connect (file descriptor %d): %s [%s]", + fd, peer_string, peer_ipaddr, sock_ipaddr); - connptr = initialize_conn(fd, peer_ipaddr, peer_string); + connptr = initialize_conn(fd, peer_ipaddr, peer_string, + config.bindsame ? sock_ipaddr : 0); if (!connptr) { close(fd); return; @@ -1748,7 +1756,8 @@ handle_connection(int fd) goto send_error; } } else { - connptr->server_fd = opensock(request->host, request->port); + connptr->server_fd = opensock(request->host, request->port, + connptr->server_ip_addr); if (connptr->server_fd < 0) { indicate_http_error(connptr, 500, "Unable to connect", "detail", PACKAGE " was unable to connect to the remote web server.", |