Browse Source

Fix server address (do not use the listen address)

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent
commit
f030824550
  1. 4
      include/lighttpd/connection.h
  2. 2
      include/lighttpd/server.h
  3. 4
      src/main/condition.c
  4. 5
      src/main/connection.c
  5. 5
      src/main/server.c
  6. 8
      src/main/worker.c
  7. 2
      src/modules/mod_accesslog.c
  8. 2
      src/modules/mod_debug.c
  9. 2
      src/modules/mod_dirlist.c
  10. 8
      src/modules/mod_fastcgi.c
  11. 2
      src/modules/mod_redirect.c
  12. 2
      src/modules/mod_rewrite.c
  13. 2
      src/modules/mod_status.c

4
include/lighttpd/connection.h

@ -39,8 +39,8 @@ struct liConnection {
liChunkQueue *in, *out; /* link to mainvr->in/out */
ev_io sock_watcher;
liSocketAddress remote_addr;
GString *remote_addr_str;
liSocketAddress remote_addr, local_addr;
GString *remote_addr_str, *local_addr_str;
gboolean is_ssl, keep_alive;
liVRequest *mainvr;

2
include/lighttpd/server.h

@ -26,8 +26,6 @@ struct liServerSocket {
gint refcount;
liServer *srv;
ev_io watcher;
liSocketAddress local_addr;
GString *local_addr_str;
/* Custom sockets (ssl) */
gpointer data;

4
src/main/condition.c

@ -357,7 +357,7 @@ static liHandlerResult li_condition_check_eval_string(liVRequest *vr, liConditio
switch (cond->lvalue->type) {
case LI_COMP_REQUEST_LOCALIP:
val = con->srv_sock->local_addr_str->str;
val = con->local_addr_str->str;
break;
case LI_COMP_REQUEST_REMOTEIP:
val = con->remote_addr_str->str;
@ -533,7 +533,7 @@ static liHandlerResult li_condition_check_eval_ip(liVRequest *vr, liCondition *c
switch (cond->lvalue->type) {
case LI_COMP_REQUEST_LOCALIP:
if (!condition_ip_from_socket(&ipval, con->srv_sock->local_addr.addr))
if (!condition_ip_from_socket(&ipval, con->local_addr.addr))
return LI_HANDLER_GO_ON;
break;
case LI_COMP_REQUEST_REMOTEIP:

5
src/main/connection.c

@ -449,6 +449,7 @@ liConnection* li_connection_new(liWorker *wrk) {
ev_io_set(&con->sock_watcher, -1, 0);
con->sock_watcher.data = con;
con->remote_addr_str = g_string_sized_new(INET6_ADDRSTRLEN);
con->local_addr_str = g_string_sized_new(INET6_ADDRSTRLEN);
con->is_ssl = FALSE;
con->keep_alive = TRUE;
@ -516,6 +517,8 @@ void li_connection_reset(liConnection *con) {
g_string_truncate(con->remote_addr_str, 0);
li_sockaddr_clear(&con->remote_addr);
g_string_truncate(con->local_addr_str, 0);
li_sockaddr_clear(&con->local_addr);
con->keep_alive = TRUE;
li_chunkqueue_reset(con->raw_in);
@ -686,6 +689,8 @@ void li_connection_free(liConnection *con) {
ev_io_set(&con->sock_watcher, -1, 0);
g_string_free(con->remote_addr_str, TRUE);
li_sockaddr_clear(&con->remote_addr);
g_string_free(con->local_addr_str, TRUE);
li_sockaddr_clear(&con->local_addr);
con->keep_alive = TRUE;
li_chunkqueue_free(con->raw_in);

5
src/main/server.c

@ -10,9 +10,6 @@ static liServerSocket* server_socket_new(int fd) {
sock->refcount = 1;
sock->watcher.data = sock;
sock->local_addr = li_sockaddr_local_from_socket(fd);
sock->local_addr_str = g_string_sized_new(0);
li_sockaddr_to_string(sock->local_addr, sock->local_addr_str, FALSE);
li_fd_init(fd);
ev_init(&sock->watcher, li_server_listen_cb);
ev_io_set(&sock->watcher, fd, EV_READ);
@ -25,8 +22,6 @@ void li_server_socket_release(liServerSocket* sock) {
if (g_atomic_int_dec_and_test(&sock->refcount)) {
if (sock->release_cb) sock->release_cb(sock);
li_sockaddr_clear(&sock->local_addr);
g_string_free(sock->local_addr_str, TRUE);
g_slice_free(liServerSocket, sock);
}
}

8
src/main/worker.c

@ -269,13 +269,19 @@ void li_worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr
con->srv_sock = srv_sock;
con->state = LI_CON_STATE_REQUEST_START;
con->remote_addr = remote_addr;
ev_io_set(&con->sock_watcher, s, EV_READ);
ev_io_start(wrk->loop, &con->sock_watcher);
con->ts = CUR_TS(con->wrk);
con->remote_addr = remote_addr;
li_sockaddr_to_string(remote_addr, con->remote_addr_str, FALSE);
con->local_addr = li_sockaddr_local_from_socket(s);
li_sockaddr_to_string(con->local_addr, con->local_addr_str, FALSE);
li_waitqueue_push(&wrk->io_timeout_queue, &con->io_timeout_elem);
if (srv_sock->new_cb) {
if (!srv_sock->new_cb(con)) {
li_connection_error(con);

2
src/modules/mod_accesslog.c

@ -240,7 +240,7 @@ static GString *al_format_log(liConnection *con, al_data *ald, GArray *format) {
g_string_append_len(str, GSTR_LEN(con->remote_addr_str));
break;
case AL_FORMAT_LOCAL_ADDR:
g_string_append_len(str, GSTR_LEN(con->srv_sock->local_addr_str));
g_string_append_len(str, GSTR_LEN(con->local_addr_str));
break;
case AL_FORMAT_BYTES_RESPONSE:
g_string_append_printf(str, "%jd", vr->out->bytes_out);

2
src/modules/mod_debug.c

@ -96,7 +96,7 @@ static gpointer debug_collect_func(liWorker *wrk, gpointer fdata) {
cd->is_ssl = c->is_ssl;
cd->keep_alive = c->keep_alive;
cd->remote_addr_str = g_string_new_len(GSTR_LEN(c->remote_addr_str));
cd->local_addr_str = g_string_new_len(GSTR_LEN(c->srv_sock->local_addr_str));
cd->local_addr_str = g_string_new_len(GSTR_LEN(c->local_addr_str));
cd->host = g_string_new_len(GSTR_LEN(c->mainvr->request.uri.host));
cd->path = g_string_new_len(GSTR_LEN(c->mainvr->request.uri.path));
cd->query = g_string_new_len(GSTR_LEN(c->mainvr->request.uri.query));

2
src/modules/mod_dirlist.c

@ -209,7 +209,7 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context
}
/* redirect to scheme + host + path + / + querystring if directory without trailing slash */
/* TODO: local addr if HTTP 1.0 without host header, url encoding */
host = vr->request.uri.authority->len ? vr->request.uri.authority : vr->con->srv_sock->local_addr_str;
host = vr->request.uri.authority->len ? vr->request.uri.authority : vr->con->local_addr_str;
uri = g_string_sized_new(
8 /* https:// */ + host->len +
vr->request.uri.orig_path->len + 2 /* /? */ + vr->request.uri.query->len

8
src/modules/mod_fastcgi.c

@ -330,10 +330,10 @@ static void fastcgi_env_create(liVRequest *vr, liEnvironmentDup *envdup, GByteAr
fastcgi_env_add(buf, envdup, CONST_STR_LEN("GATEWAY_INTERFACE"), CONST_STR_LEN("CGI/1.1"));
{
guint port = 0;
switch (con->srv_sock->local_addr.addr->plain.sa_family) {
case AF_INET: port = con->srv_sock->local_addr.addr->ipv4.sin_port; break;
switch (con->local_addr.addr->plain.sa_family) {
case AF_INET: port = con->local_addr.addr->ipv4.sin_port; break;
#ifdef HAVE_IPV6
case AF_INET6: port = con->srv_sock->local_addr.addr->ipv6.sin6_port; break;
case AF_INET6: port = con->local_addr.addr->ipv6.sin6_port; break;
#endif
}
if (port) {
@ -341,7 +341,7 @@ static void fastcgi_env_create(liVRequest *vr, liEnvironmentDup *envdup, GByteAr
fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_PORT"), GSTR_LEN(tmp));
}
}
fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_ADDR"), GSTR_LEN(con->srv_sock->local_addr_str));
fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_ADDR"), GSTR_LEN(con->local_addr_str));
{
guint port = 0;

2
src/modules/mod_redirect.c

@ -297,7 +297,7 @@ static gboolean redirect_internal(liVRequest *vr, GString *dest, redirect_rule *
case REDIRECT_PART_VAR:
switch (rp->data.cond_lval) {
case LI_COMP_REQUEST_LOCALIP: str = vr->con->srv_sock->local_addr_str; break;
case LI_COMP_REQUEST_LOCALIP: str = vr->con->local_addr_str; break;
case LI_COMP_REQUEST_REMOTEIP: str = vr->con->remote_addr_str; break;
case LI_COMP_REQUEST_SCHEME: str = NULL; break;
case LI_COMP_REQUEST_PATH: str = vr->request.uri.path; break;

2
src/modules/mod_rewrite.c

@ -281,7 +281,7 @@ static gboolean rewrite_internal(liVRequest *vr, GString *dest_path, GString *de
case REWRITE_PART_VAR:
switch (rp->data.cond_lval) {
case LI_COMP_REQUEST_LOCALIP: str = vr->con->srv_sock->local_addr_str; break;
case LI_COMP_REQUEST_LOCALIP: str = vr->con->local_addr_str; break;
case LI_COMP_REQUEST_REMOTEIP: str = vr->con->remote_addr_str; break;
case LI_COMP_REQUEST_SCHEME: str = NULL; break;
case LI_COMP_REQUEST_PATH: str = vr->request.uri.path; break;

2
src/modules/mod_status.c

@ -262,7 +262,7 @@ static gpointer status_collect_func(liWorker *wrk, gpointer fdata) {
cd->is_ssl = c->is_ssl;
cd->keep_alive = c->keep_alive;
cd->remote_addr_str = g_string_new_len(GSTR_LEN(c->remote_addr_str));
cd->local_addr_str = g_string_new_len(GSTR_LEN(c->srv_sock->local_addr_str));
cd->local_addr_str = g_string_new_len(GSTR_LEN(c->local_addr_str));
cd->host = g_string_new_len(GSTR_LEN(c->mainvr->request.uri.host));
cd->path = g_string_new_len(GSTR_LEN(c->mainvr->request.uri.path));
cd->query = g_string_new_len(GSTR_LEN(c->mainvr->request.uri.query));

Loading…
Cancel
Save