Browse Source

Add IPv6 support to mod_proxy (fixes #1537)

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2484 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.23
Stefan Bühler 13 years ago
parent
commit
4a47537696
  1. 1
      NEWS
  2. 2
      SConstruct
  3. 2
      configure.ac
  4. 1
      src/CMakeLists.txt
  5. 36
      src/mod_proxy.c

1
NEWS

@ -32,6 +32,7 @@ NEWS
* Add evasive.silent option (fixes #1438)
* Make mod_extforward headers configurable (fixes #1545)
* Add '%_' pattern for complete hostname in mod_evhost (fixes #1737)
* Add IPv6 support to mod_proxy (fixes #1537)
- 1.4.22 - 2009-03-07
* Fix wrong lua type for CACHE_MISS/CACHE_HIT in mod_cml (fixes #533)

2
SConstruct

@ -159,7 +159,7 @@ if 1:
strdup strerror strstr strtol sendfile getopt socket \
gethostbyname poll sigtimedwait epoll_ctl getrlimit chroot \
getuid select signal pathconf madvise prctl\
writev sigaction sendfile64 send_file kqueue port_create localtime_r posix_fadvise'))
writev sigaction sendfile64 send_file kqueue port_create localtime_r posix_fadvise issetugid inet_pton'))
checkTypes(autoconf, Split('pid_t size_t off_t'))

2
configure.ac

@ -77,7 +77,7 @@ dnl AC_FUNC_REALLOC
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([issetugid])
AC_CHECK_FUNCS([issetugid inet_pton])
dnl Checks for database.
MYSQL_INCLUDE=""

1
src/CMakeLists.txt

@ -146,6 +146,7 @@ CHECK_C_SOURCE_COMPILES("
return 0;
}" HAVE_IPV6)
CHECK_FUNCTION_EXISTS(issetugid HAVE_ISSETUGID)
CHECK_FUNCTION_EXISTS(inet_pton HAVE_INET_PTON)
## refactor me
MACRO(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)

36
src/mod_proxy.c

@ -356,20 +356,35 @@ static 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) {
@ -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;

Loading…
Cancel
Save