diff options
Diffstat (limited to 'src/mod_proxy.c')
-rw-r--r-- | src/mod_proxy.c | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/mod_proxy.c b/src/mod_proxy.c index 92549e2..5f6a7da 100644 --- a/src/mod_proxy.c +++ b/src/mod_proxy.c @@ -332,7 +332,7 @@ SETDEFAULTS_FUNC(mod_proxy_set_defaults) { return HANDLER_GO_ON; } -void proxy_connection_close(server *srv, handler_ctx *hctx) { +static void proxy_connection_close(server *srv, handler_ctx *hctx) { plugin_data *p; connection *con; @@ -356,20 +356,35 @@ void proxy_connection_close(server *srv, handler_ctx *hctx) { static int proxy_establish_connection(server *srv, handler_ctx *hctx) { struct sockaddr *proxy_addr; struct sockaddr_in proxy_addr_in; +#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON) + struct sockaddr_in6 proxy_addr_in6; +#endif socklen_t servlen; plugin_data *p = hctx->plugin_data; data_proxy *host= hctx->host; int proxy_fd = hctx->fd; - memset(&proxy_addr, 0, sizeof(proxy_addr)); - proxy_addr_in.sin_family = AF_INET; - proxy_addr_in.sin_addr.s_addr = inet_addr(host->host->ptr); - proxy_addr_in.sin_port = htons(host->port); - servlen = sizeof(proxy_addr_in); +#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON) + if (strstr(host->host->ptr, ":")) { + memset(&proxy_addr_in6, 0, sizeof(proxy_addr_in6)); + proxy_addr_in6.sin6_family = AF_INET6; + inet_pton(AF_INET6, host->host->ptr, (char *) &proxy_addr_in6.sin6_addr); + proxy_addr_in6.sin6_port = htons(host->port); + servlen = sizeof(proxy_addr_in6); + proxy_addr = (struct sockaddr *) &proxy_addr_in6; + } else +#endif + { + memset(&proxy_addr_in, 0, sizeof(proxy_addr_in)); + proxy_addr_in.sin_family = AF_INET; + proxy_addr_in.sin_addr.s_addr = inet_addr(host->host->ptr); + proxy_addr_in.sin_port = htons(host->port); + servlen = sizeof(proxy_addr_in); + proxy_addr = (struct sockaddr *) &proxy_addr_in; + } - proxy_addr = (struct sockaddr *) &proxy_addr_in; if (-1 == connect(proxy_fd, proxy_addr, servlen)) { if (errno == EINPROGRESS || errno == EALREADY) { @@ -395,7 +410,7 @@ static int proxy_establish_connection(server *srv, handler_ctx *hctx) { return 0; } -void proxy_set_header(connection *con, const char *key, const char *value) { +static void proxy_set_header(connection *con, const char *key, const char *value) { data_string *ds_dst; if (NULL == (ds_dst = (data_string *)array_get_unused_element(con->request.headers, TYPE_STRING))) { @@ -407,7 +422,7 @@ void proxy_set_header(connection *con, const char *key, const char *value) { array_insert_unique(con->request.headers, (data_unset *)ds_dst); } -void proxy_append_header(connection *con, const char *key, const char *value) { +static void proxy_append_header(connection *con, const char *key, const char *value) { data_string *ds_dst; if (NULL == (ds_dst = (data_string *)array_get_unused_element(con->request.headers, TYPE_STRING))) { @@ -741,9 +756,16 @@ static handler_t proxy_write_request(server *srv, handler_ctx *hctx) { switch(hctx->state) { case PROXY_STATE_INIT: - if (-1 == (hctx->fd = socket(AF_INET, SOCK_STREAM, 0))) { + if (strstr(host->host->ptr,":")) { + if (-1 == (hctx->fd = socket(AF_INET6, SOCK_STREAM, 0))) { + log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed: ", strerror(errno)); + return HANDLER_ERROR; + } + } else { + if (-1 == (hctx->fd = socket(AF_INET, SOCK_STREAM, 0))) { log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed: ", strerror(errno)); return HANDLER_ERROR; + } } hctx->fde_ndx = -1; @@ -1209,7 +1231,7 @@ static handler_t mod_proxy_check_extension(server *srv, connection *con, void *p if (ndx >= (int) extension->value->used) { /* didn't found a higher id, wrap to the start */ - for (ndx = 0; ndx < (int) k; ndx++) { + for (ndx = 0; ndx <= (int) k; ndx++) { host = (data_proxy *)extension->value->data[ndx]; if (!host->is_disabled) break; } @@ -1321,6 +1343,7 @@ TRIGGER_FUNC(mod_proxy_trigger) { } +int mod_proxy_plugin_init(plugin *p); int mod_proxy_plugin_init(plugin *p) { p->version = LIGHTTPD_VERSION_ID; p->name = buffer_init_string("proxy"); |