mod_proxy.h revision 0ad70f568b434ff0d849a00d017751fd3db9b28b
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* Licensed to the Apache Software Foundation (ASF) under one or more
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * contributor license agreements. See the NOTICE file distributed with
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * this work for additional information regarding copyright ownership.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * The ASF licenses this file to You under the Apache License, Version 2.0
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * (the "License"); you may not use this file except in compliance with
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * the License. You may obtain a copy of the License at
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * http://www.apache.org/licenses/LICENSE-2.0
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * Unless required by applicable law or agreed to in writing, software
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * distributed under the License is distributed on an "AS IS" BASIS,
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * See the License for the specific language governing permissions and
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * limitations under the License.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz#ifndef MOD_PROXY_H
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define MOD_PROXY_H
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz/**
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * @file mod_proxy.h
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * @brief Proxy Extension Module for Apache
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * @defgroup MOD_PROXY mod_proxy
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * @ingroup APACHE_MODS
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * @{
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz */
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_hooks.h"
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz#include "apr_optional.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_lib.h"
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz#include "apr_strings.h"
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz#include "apr_buckets.h"
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#include "apr_md5.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_network_io.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_pools.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_strings.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_uri.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_date.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_strmatch.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_fnmatch.h"
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz#include "apr_reslist.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define APR_WANT_STRFUNC
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_want.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_uuid.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "util_mutex.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_global_mutex.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "apr_thread_mutex.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz#include "httpd.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_config.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "ap_config.h"
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz#include "http_core.h"
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz#include "http_protocol.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "http_request.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_vhost.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_main.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_log.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_connection.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "util_filter.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "util_ebcdic.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "ap_provider.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "ap_slotmem.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#if APR_HAVE_NETINET_IN_H
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include <netinet/in.h>
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#endif
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#if APR_HAVE_ARPA_INET_H
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include <arpa/inet.h>
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#endif
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz/* for proxy_canonenc() */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulzenum enctype {
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz enc_path, enc_search, enc_user, enc_fpath, enc_parm
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz};
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define BALANCER_PREFIX "balancer://"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#if APR_CHARSET_EBCDIC
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#define CRLF "\r\n"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#else /*APR_CHARSET_EBCDIC*/
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define CRLF "\015\012"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#endif /*APR_CHARSET_EBCDIC*/
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* default Max-Forwards header setting */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* Set this to -1, which complies with RFC2616 by not setting
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * max-forwards if the client didn't send it to us.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define DEFAULT_MAX_FORWARDS -1
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulztypedef struct proxy_balancer proxy_balancer;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulztypedef struct proxy_worker proxy_worker;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulztypedef struct proxy_conn_pool proxy_conn_pool;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulztypedef struct proxy_balancer_method proxy_balancer_method;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* static information about a remote proxy */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulzstruct proxy_remote {
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz const char *scheme; /* the schemes handled by this proxy, or '*' */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz const char *protocol; /* the scheme used to talk to this proxy */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz const char *hostname; /* the hostname of this proxy */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz ap_regex_t *regexp; /* compiled regex (if any) for the remote */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz int use_regex; /* simple boolean. True if we have a regex pattern */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz apr_port_t port; /* the port for this proxy */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz};
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define PROXYPASS_NOCANON 0x01
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define PROXYPASS_INTERPOLATE 0x02
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulzstruct proxy_alias {
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz const char *real;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz const char *fake;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz ap_regex_t *regex;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz unsigned int flags;
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz proxy_balancer *balancer; /* only valid for reverse-proxys */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz};
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulzstruct dirconn_entry {
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz char *name;
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz struct in_addr addr, mask;
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz struct apr_sockaddr_t *hostaddr;
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz int (*matcher) (struct dirconn_entry * This, request_rec *r);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz};
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulzstruct noproxy_entry {
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz const char *name;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz struct apr_sockaddr_t *addr;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz};
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulztypedef struct {
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_array_header_t *proxies;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_array_header_t *sec_proxy;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_array_header_t *aliases;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_array_header_t *noproxies;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_array_header_t *dirconn;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_array_header_t *workers; /* non-balancer workers, eg ProxyPass http://example.com */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_array_header_t *balancers; /* list of balancers @ config time */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz proxy_worker *forward; /* forward proxy worker */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz proxy_worker *reverse; /* reverse "module-driven" proxy worker */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz const char *domain; /* domain name to use in absence of a domain name in the request */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz const char *id;
9316034585ad46e11b1307ec8289f25b7699d74dEwaryst Schulz apr_pool_t *pool; /* Pool used for allocating this struct */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz int req; /* true if proxy requests are enabled */
9316034585ad46e11b1307ec8289f25b7699d74dEwaryst Schulz int max_balancers; /* maximum number of allowed balancers */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz int bgrowth; /* number of post-config balancers can added */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz enum {
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz via_off,
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz via_on,
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz via_block,
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz via_full
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz } viaopt; /* how to deal with proxy Via: headers */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_size_t recv_buffer_size;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_size_t io_buffer_size;
21c27810fa966e9253073efaf7f36458715d84bbEwaryst Schulz long maxfwd;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_interval_time_t timeout;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz enum {
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz bad_error,
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz bad_ignore,
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz bad_body
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz } badopt; /* how to deal with bad headers */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz enum {
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz status_off,
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz status_on,
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz status_full
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz } proxy_status; /* Status display options */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_sockaddr_t *source_address;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_global_mutex_t *mutex; /* global lock (needed??) */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_slotmem_instance_t *bslot; /* balancers shm data - runtime */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_slotmem_provider_t *storage;
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz unsigned int req_set:1;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz unsigned int viaopt_set:1;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz unsigned int recv_buffer_size_set:1;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz unsigned int io_buffer_size_set:1;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz unsigned int maxfwd_set:1;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz unsigned int timeout_set:1;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz unsigned int badopt_set:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int proxy_status_set:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int source_address_set:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int bgrowth_set:1;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz} proxy_server_conf;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulztypedef struct {
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz const char *p; /* The path */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz ap_regex_t *r; /* Is this a regex? */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* FIXME
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * ProxyPassReverse and friends are documented as working inside
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * <Location>. But in fact they never have done in the case of
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * more than one <Location>, because the server_conf can't see it.
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * We need to move them to the per-dir config.
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz * Discussed in February 2005:
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz * http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=110726027118798&w=2
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz apr_array_header_t *raliases;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz apr_array_header_t* cookie_paths;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz apr_array_header_t* cookie_domains;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz signed char p_is_fnmatch; /* Is the path an fnmatch candidate? */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz signed char interpolate_env;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz struct proxy_alias *alias;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz /**
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * the following setting masks the error page
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * returned from the 'proxied server' and just
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * forwards the status code upwards.
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * This allows the main server (us) to generate
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * the error page, (so it will look like a error
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * returned from the rest of the system
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int error_override:1;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int preserve_host:1;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int preserve_host_set:1;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int error_override_set:1;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int alias_set:1;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int add_forwarded_headers:1;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz} proxy_dir_conf;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* if we interpolate env vars per-request, we'll need a per-request
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * copy of the reverse proxy config
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulztypedef struct {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_array_header_t *raliases;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_array_header_t* cookie_paths;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_array_header_t* cookie_domains;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz} proxy_req_conf;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulztypedef struct {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz conn_rec *connection;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz request_rec *r; /* Request record of the backend request
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * that is used over the backend connection. */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz proxy_worker *worker; /* Connection pool this connection belongs to */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_pool_t *pool; /* Subpool for hostname and addr data */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz const char *hostname;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_sockaddr_t *addr; /* Preparsed remote address info */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_pool_t *scpool; /* Subpool used for socket and connection data */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_socket_t *sock; /* Connection socket */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz void *data; /* per scheme connection data */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz void *forward; /* opaque forward proxy data */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_uint32_t flags; /* Connection flags */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_port_t port;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int is_ssl:1;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int close:1; /* Close 'this' connection */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int need_flush:1; /* Flag to decide whether we need to flush the
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * filter chain or not */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int inreslist:1; /* connection in apr_reslist? */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz} proxy_conn_rec;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulztypedef struct {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz float cache_completion; /* completion percentage */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int content_length; /* length of the content */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz} proxy_completion;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* Connection pool */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulzstruct proxy_conn_pool {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_pool_t *pool; /* The pool used in constructor and destructor calls */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_sockaddr_t *addr; /* Preparsed remote address info */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz apr_reslist_t *res; /* Connection resource list */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz proxy_conn_rec *conn; /* Single connection for prefork mpm */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz};
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz/* Keep below in sync with proxy_util.c! */
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz/* worker status bits */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz#define PROXY_WORKER_INITIALIZED 0x0001
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz#define PROXY_WORKER_IGNORE_ERRORS 0x0002
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz#define PROXY_WORKER_DRAIN 0x0004
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz#define PROXY_WORKER_IN_SHUTDOWN 0x0010
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz#define PROXY_WORKER_DISABLED 0x0020
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#define PROXY_WORKER_STOPPED 0x0040
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#define PROXY_WORKER_IN_ERROR 0x0080
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#define PROXY_WORKER_HOT_STANDBY 0x0100
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#define PROXY_WORKER_FREE 0x0200
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz/* worker status flags */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz#define PROXY_WORKER_INITIALIZED_FLAG 'O'
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#define PROXY_WORKER_IGNORE_ERRORS_FLAG 'I'
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_WORKER_DRAIN_FLAG 'N'
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_WORKER_IN_SHUTDOWN_FLAG 'U'
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_WORKER_DISABLED_FLAG 'D'
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_WORKER_STOPPED_FLAG 'S'
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_WORKER_IN_ERROR_FLAG 'E'
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_WORKER_HOT_STANDBY_FLAG 'H'
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_WORKER_FREE_FLAG 'F'
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst SchulzPROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz/* NOTE: these check the shared status */
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz#define PROXY_WORKER_IS_INITIALIZED(f) ( (f)->s->status & PROXY_WORKER_INITIALIZED )
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz#define PROXY_WORKER_IS_STANDBY(f) ( (f)->s->status & PROXY_WORKER_HOT_STANDBY )
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_WORKER_IS_USABLE(f) ( ( !( (f)->s->status & PROXY_WORKER_NOT_USABLE_BITMAP) ) && \
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz PROXY_WORKER_IS_INITIALIZED(f) )
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#define PROXY_WORKER_IS_DRAINING(f) ( (f)->s->status & PROXY_WORKER_DRAIN )
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz/* default worker retry timeout in seconds */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_WORKER_DEFAULT_RETRY 60
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz/* Some max char string sizes, for shm fields */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_WORKER_MAX_SCHEME_SIZE 16
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_WORKER_MAX_ROUTE_SIZE 64
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_BALANCER_MAX_ROUTE_SIZE PROXY_WORKER_MAX_ROUTE_SIZE
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_WORKER_MAX_NAME_SIZE 96
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_BALANCER_MAX_NAME_SIZE PROXY_WORKER_MAX_NAME_SIZE
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_WORKER_MAX_HOSTNAME_SIZE 64
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_BALANCER_MAX_HOSTNAME_SIZE PROXY_WORKER_MAX_HOSTNAME_SIZE
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_BALANCER_MAX_STICKY_SIZE 64
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_MAX_PROVIDER_NAME_SIZE 16
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#define PROXY_STRNCPY(dst, src) ap_proxy_strncpy((dst), (src), (sizeof(dst)))
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#define PROXY_COPY_CONF_PARAMS(w, c) \
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulzdo { \
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz(w)->s->timeout = (c)->timeout; \
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz(w)->s->timeout_set = (c)->timeout_set; \
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz(w)->s->recv_buffer_size = (c)->recv_buffer_size; \
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz(w)->s->recv_buffer_size_set = (c)->recv_buffer_size_set; \
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz(w)->s->io_buffer_size = (c)->io_buffer_size; \
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz(w)->s->io_buffer_size_set = (c)->io_buffer_size_set; \
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz} while (0)
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz/* use 2 hashes */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulztypedef struct {
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int def;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz unsigned int fnv;
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz} proxy_hashes ;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* Runtime worker status informations. Shared in scoreboard */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulztypedef struct {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz char name[PROXY_WORKER_MAX_NAME_SIZE];
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz char scheme[PROXY_WORKER_MAX_SCHEME_SIZE]; /* scheme to use ajp|http|https */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz char hostname[PROXY_WORKER_MAX_HOSTNAME_SIZE]; /* remote backend address */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz char route[PROXY_WORKER_MAX_ROUTE_SIZE]; /* balancing route */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz char redirect[PROXY_WORKER_MAX_ROUTE_SIZE]; /* temporary balancing redirection route */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz char flusher[PROXY_WORKER_MAX_SCHEME_SIZE]; /* flush provider used by mod_proxy_fdpass */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int lbset; /* load balancer cluster set */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int retries; /* number of retries on this worker */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int lbstatus; /* Current lbstatus */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz int lbfactor; /* dynamic lbfactor */
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz int min; /* Desired minimum number of available connections */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int smax; /* Soft maximum on the total number of connections */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int hmax; /* Hard maximum on the total number of connections */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int flush_wait; /* poll wait time in microseconds if flush_auto */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int index; /* shm array index */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz proxy_hashes hash; /* hash of worker name */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz unsigned int status; /* worker status bitfield */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz enum {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz flush_off,
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz flush_on,
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz flush_auto
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz } flush_packets; /* control AJP flushing */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_time_t updated; /* timestamp of last update */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_time_t error_time; /* time of the last error */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_interval_time_t ttl; /* maximum amount of time in seconds a connection
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * may be available while exceeding the soft limit */
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz apr_interval_time_t retry; /* retry interval */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_interval_time_t timeout; /* connection timeout */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_interval_time_t acquire; /* acquire timeout when the maximum number of connections is exceeded */
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz apr_interval_time_t ping_timeout;
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz apr_interval_time_t conn_timeout;
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz apr_size_t recv_buffer_size;
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_size_t io_buffer_size;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_size_t elected; /* Number of times the worker was elected */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_size_t busy; /* busyness factor */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_port_t port;
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_off_t transferred;/* Number of bytes transferred to remote */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_off_t read; /* Number of bytes read from remote */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz void *context; /* general purpose storage */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned int keepalive:1;
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz unsigned int disablereuse:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int is_address_reusable:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int retry_set:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int timeout_set:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int acquire_set:1;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz unsigned int ping_timeout_set:1;
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz unsigned int conn_timeout_set:1;
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz unsigned int recv_buffer_size_set:1;
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz unsigned int io_buffer_size_set:1;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz unsigned int keepalive_set:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int disablereuse_set:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int was_malloced:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz} proxy_worker_shared;
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#define ALIGNED_PROXY_WORKER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_worker_shared)))
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz/* Worker configuration */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulzstruct proxy_worker {
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz proxy_hashes hash; /* hash of worker name */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz unsigned int local_status; /* status of per-process worker */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz proxy_conn_pool *cp; /* Connection pool to use */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz proxy_worker_shared *s; /* Shared data */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz proxy_balancer *balancer; /* which balancer am I in? */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_thread_mutex_t *tmutex; /* Thread lock for updating address cache */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz void *context; /* general purpose storage */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz};
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz/*
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz * Time to wait (in microseconds) to find out if more data is currently
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz * available at the backend.
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#define PROXY_FLUSH_WAIT 10000
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulztypedef struct {
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char sticky_path[PROXY_BALANCER_MAX_STICKY_SIZE]; /* URL sticky session identifier */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char sticky[PROXY_BALANCER_MAX_STICKY_SIZE]; /* sticky session identifier */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char lbpname[PROXY_MAX_PROVIDER_NAME_SIZE]; /* lbmethod provider name */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char nonce[APR_UUID_FORMATTED_LENGTH + 1];
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz char name[PROXY_BALANCER_MAX_NAME_SIZE];
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char sname[PROXY_BALANCER_MAX_NAME_SIZE];
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char vpath[PROXY_BALANCER_MAX_ROUTE_SIZE];
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz char vhost[PROXY_BALANCER_MAX_HOSTNAME_SIZE];
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_interval_time_t timeout; /* Timeout for waiting on free connection */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz apr_time_t wupdated; /* timestamp of last change to workers list */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz int max_attempts; /* Number of attempts before failing */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz int index; /* shm array index */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz proxy_hashes hash;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int sticky_force:1; /* Disable failover for sticky sessions */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int scolonsep:1; /* true if ';' seps sticky session paths */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int max_attempts_set:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int was_malloced:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int need_reset:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int vhosted:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz unsigned int inactive:1;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz} proxy_balancer_shared;
#define ALIGNED_PROXY_BALANCER_SHARED_SIZE (APR_ALIGN_DEFAULT(sizeof(proxy_balancer_shared)))
struct proxy_balancer {
apr_array_header_t *workers; /* initially configured workers */
apr_array_header_t *errstatuses; /* statuses to force members into error */
ap_slotmem_instance_t *wslot; /* worker shm data - runtime */
ap_slotmem_provider_t *storage;
int growth; /* number of post-config workers can added */
int max_workers; /* maximum number of allowed workers */
proxy_hashes hash;
apr_time_t wupdated; /* timestamp of last change to workers list */
proxy_balancer_method *lbmethod;
apr_global_mutex_t *gmutex; /* global lock for updating list of workers */
apr_thread_mutex_t *tmutex; /* Thread lock for updating shm */
proxy_server_conf *sconf;
void *context; /* general purpose storage */
proxy_balancer_shared *s; /* Shared data */
};
struct proxy_balancer_method {
const char *name; /* name of the load balancer method*/
proxy_worker *(*finder)(proxy_balancer *balancer,
request_rec *r);
void *context; /* general purpose storage */
apr_status_t (*reset)(proxy_balancer *balancer, server_rec *s);
apr_status_t (*age)(proxy_balancer *balancer, server_rec *s);
apr_status_t (*updatelbstatus)(proxy_balancer *balancer, proxy_worker *elected, server_rec *s);
};
#define PROXY_THREAD_LOCK(x) ( (x) && (x)->tmutex ? apr_thread_mutex_lock((x)->tmutex) : APR_SUCCESS)
#define PROXY_THREAD_UNLOCK(x) ( (x) && (x)->tmutex ? apr_thread_mutex_unlock((x)->tmutex) : APR_SUCCESS)
#define PROXY_GLOBAL_LOCK(x) ( (x) && (x)->gmutex ? apr_global_mutex_lock((x)->gmutex) : APR_SUCCESS)
#define PROXY_GLOBAL_UNLOCK(x) ( (x) && (x)->gmutex ? apr_global_mutex_unlock((x)->gmutex) : APR_SUCCESS)
/* hooks */
/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
* PROXY_DECLARE_DATA with appropriate export and import tags for the platform
*/
#if !defined(WIN32)
#define PROXY_DECLARE(type) type
#define PROXY_DECLARE_NONSTD(type) type
#define PROXY_DECLARE_DATA
#elif defined(PROXY_DECLARE_STATIC)
#define PROXY_DECLARE(type) type __stdcall
#define PROXY_DECLARE_NONSTD(type) type
#define PROXY_DECLARE_DATA
#elif defined(PROXY_DECLARE_EXPORT)
#define PROXY_DECLARE(type) __declspec(dllexport) type __stdcall
#define PROXY_DECLARE_NONSTD(type) __declspec(dllexport) type
#define PROXY_DECLARE_DATA __declspec(dllexport)
#else
#define PROXY_DECLARE(type) __declspec(dllimport) type __stdcall
#define PROXY_DECLARE_NONSTD(type) __declspec(dllimport) type
#define PROXY_DECLARE_DATA __declspec(dllimport)
#endif
/**
* Hook an optional proxy hook. Unlike static hooks, this uses a macro
* instead of a function.
*/
#define PROXY_OPTIONAL_HOOK(name,fn,pre,succ,order) \
APR_OPTIONAL_HOOK(proxy,name,fn,pre,succ,order)
APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r,
proxy_worker *worker, proxy_server_conf *conf, char *url,
const char *proxyhost, apr_port_t proxyport))
APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r,
char *url))
APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr))
APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r))
/**
* pre request hook.
* It will return the most suitable worker at the moment
* and coresponding balancer.
* The url is rewritten from balancer://cluster/uri to scheme://host:port/uri
* and then the scheme_handler is called.
*
*/
APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, pre_request, (proxy_worker **worker,
proxy_balancer **balancer,
request_rec *r,
proxy_server_conf *conf, char **url))
/**
* post request hook.
* It is called after request for updating runtime balancer status.
*/
APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, post_request, (proxy_worker *worker,
proxy_balancer *balancer, request_rec *r,
proxy_server_conf *conf))
/**
* request status hook
* It is called after all proxy processing has been done. This gives other
* modules a chance to create default content on failure, for example
*/
APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, request_status,
(int *status, request_rec *r))
/* proxy_util.c */
PROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char *dst, const char *src, size_t dlen);
PROXY_DECLARE(request_rec *) ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
int forcedec, int proxyreq);
PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
char **passwordp, char **hostp, apr_port_t *port);
PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x);
PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y);
PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message);
PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
PROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r);
PROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key);
/* DEPRECATED (will be replaced with ap_proxy_connect_backend */
PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, apr_sockaddr_t *, const char *, proxy_server_conf *, request_rec *);
PROXY_DECLARE(apr_status_t) ap_proxy_ssl_connection_cleanup(proxy_conn_rec *conn,
request_rec *r);
PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c);
PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c);
PROXY_DECLARE(int) ap_proxy_conn_is_https(conn_rec *c);
PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var);
/* Header mapping functions, and a typedef of their signature */
PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *url);
PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *str);
#if !defined(WIN32)
typedef const char *(*ap_proxy_header_reverse_map_fn)(request_rec *,
proxy_dir_conf *, const char *);
#elif defined(PROXY_DECLARE_STATIC)
typedef const char *(__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
proxy_dir_conf *, const char *);
#elif defined(PROXY_DECLARE_EXPORT)
typedef __declspec(dllexport) const char *
(__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
proxy_dir_conf *, const char *);
#else
typedef __declspec(dllimport) const char *
(__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
proxy_dir_conf *, const char *);
#endif
/* Connection pool API */
/**
* Get the worker from proxy configuration
* @param p memory pool used for finding worker
* @param balancer the balancer that the worker belongs to
* @param conf current proxy server configuration
* @param url url to find the worker from
* @return proxy_worker or NULL if not found
*/
PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
proxy_balancer *balancer,
proxy_server_conf *conf,
const char *url);
/**
* Define and Allocate space for the worker to proxy configuration
* @param p memory pool to allocate worker from
* @param worker the new worker
* @param balancer the balancer that the worker belongs to
* @param conf current proxy server configuration
* @param url url containing worker name
* @param do_malloc true if shared struct should be malloced
* @return error message or NULL if successful (*worker is new worker)
*/
PROXY_DECLARE(char *) ap_proxy_define_worker(apr_pool_t *p,
proxy_worker **worker,
proxy_balancer *balancer,
proxy_server_conf *conf,
const char *url,
int do_malloc);
/**
* Share a defined proxy worker via shm
* @param worker worker to be shared
* @param shm location of shared info
* @param i index into shm
* @return APR_SUCCESS or error code
*/
PROXY_DECLARE(apr_status_t) ap_proxy_share_worker(proxy_worker *worker,
proxy_worker_shared *shm,
int i);
/**
* Initialize the worker by setting up worker connection pool and mutex
* @param worker worker to initialize
* @param s current server record
* @param p memory pool used for mutex and connection pool
* @return APR_SUCCESS or error code
*/
PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker,
server_rec *s,
apr_pool_t *p);
/**
* Verifies valid balancer name (eg: balancer://foo)
* @param name name to test
* @param i number of chars to test; 0 for all.
* @return true/false
*/
PROXY_DECLARE(int) ap_proxy_valid_balancer_name(char *name, int i);
/**
* Get the balancer from proxy configuration
* @param p memory pool used for temporary storage while finding balancer
* @param conf current proxy server configuration
* @param url url to find the worker from; must have balancer:// prefix
* @param careactive true if we care if the balancer is active or not
* @return proxy_balancer or NULL if not found
*/
PROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p,
proxy_server_conf *conf,
const char *url,
int careactive);
/**
* Update the balancer's vhost related fields
* @param p memory pool used for temporary storage while finding balancer
* @param balancer balancer to be updated
* @param url url to find vhost info
* @return error string or NULL if OK
*/
PROXY_DECLARE(char *) ap_proxy_update_balancer(apr_pool_t *p,
proxy_balancer *balancer,
const char *url);
/**
* Define and Allocate space for the balancer to proxy configuration
* @param p memory pool to allocate balancer from
* @param balancer the new balancer
* @param conf current proxy server configuration
* @param url url containing balancer name
* @param alias alias/fake-path to this balancer
* @param do_malloc true if shared struct should be malloced
* @return error message or NULL if successfull
*/
PROXY_DECLARE(char *) ap_proxy_define_balancer(apr_pool_t *p,
proxy_balancer **balancer,
proxy_server_conf *conf,
const char *url,
const char *alias,
int do_malloc);
/**
* Share a defined proxy balancer via shm
* @param balancer balancer to be shared
* @param shm location of shared info
* @param i index into shm
* @return APR_SUCCESS or error code
*/
PROXY_DECLARE(apr_status_t) ap_proxy_share_balancer(proxy_balancer *balancer,
proxy_balancer_shared *shm,
int i);
/**
* Initialize the balancer as needed
* @param balancer balancer to initialize
* @param s current server record
* @param p memory pool used for mutex and connection pool
* @return APR_SUCCESS or error code
*/
PROXY_DECLARE(apr_status_t) ap_proxy_initialize_balancer(proxy_balancer *balancer,
server_rec *s,
apr_pool_t *p);
/**
* Get the most suitable worker and/or balancer for the request
* @param worker worker used for processing request
* @param balancer balancer used for processing request
* @param r current request
* @param conf current proxy server configuration
* @param url request url that balancer can rewrite.
* @return OK or HTTP_XXX error
* @note It calls balancer pre_request hook if the url starts with balancer://
* The balancer then rewrites the url to particular worker, like http://host:port
*/
PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
proxy_balancer **balancer,
request_rec *r,
proxy_server_conf *conf,
char **url);
/**
* Post request worker and balancer cleanup
* @param worker worker used for processing request
* @param balancer balancer used for processing request
* @param r current request
* @param conf current proxy server configuration
* @return OK or HTTP_XXX error
* @note Whenever the pre_request is called, the post_request has to be
* called too.
*/
PROXY_DECLARE(int) ap_proxy_post_request(proxy_worker *worker,
proxy_balancer *balancer,
request_rec *r,
proxy_server_conf *conf);
/**
* Determine backend hostname and port
* @param p memory pool used for processing
* @param r current request
* @param conf current proxy server configuration
* @param worker worker used for processing request
* @param conn proxy connection struct
* @param uri processed uri
* @param url request url
* @param proxyname are we connecting directly or via a proxy
* @param proxyport proxy host port
* @param server_portstr Via headers server port
* @param server_portstr_size size of the server_portstr buffer
* @return OK or HTTP_XXX error
*/
PROXY_DECLARE(int) ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
proxy_server_conf *conf,
proxy_worker *worker,
proxy_conn_rec *conn,
apr_uri_t *uri,
char **url,
const char *proxyname,
apr_port_t proxyport,
char *server_portstr,
int server_portstr_size);
/**
* Mark a worker for retry
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param worker worker used for retrying
* @param s current server record
* @return OK if marked for retry, DECLINED otherwise
* @note The error status of the worker will cleared if the retry interval has
* elapsed since the last error.
*/
APR_DECLARE_OPTIONAL_FN(int, ap_proxy_retry_worker,
(const char *proxy_function, proxy_worker *worker, server_rec *s));
/**
* Acquire a connection from worker connection pool
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param conn acquired connection
* @param worker worker used for obtaining connection
* @param s current server record
* @return OK or HTTP_XXX error
* @note If the connection limit has been reached, the function will
* block until a connection becomes available or the timeout has
* elapsed.
*/
PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
proxy_conn_rec **conn,
proxy_worker *worker,
server_rec *s);
/**
* Release a connection back to worker connection pool
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param conn acquired connection
* @param s current server record
* @return OK or HTTP_XXX error
* @note The connection will be closed if conn->close_on_release is set
*/
PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
proxy_conn_rec *conn,
server_rec *s);
/**
* Make a connection to the backend
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param conn acquired connection
* @param worker connection worker
* @param s current server record
* @return OK or HTTP_XXX error
* @note In case the socket already exists for conn, just check the link
* status.
*/
PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
proxy_conn_rec *conn,
proxy_worker *worker,
server_rec *s);
/**
* Make a connection record for backend connection
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param conn acquired connection
* @param c client connection record
* @param s current server record
* @return OK or HTTP_XXX error
* @note The function will return immediately if conn->connection
* is already set,
*/
PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
proxy_conn_rec *conn,
conn_rec *c, server_rec *s);
/**
* Signal the upstream chain that the connection to the backend broke in the
* middle of the response. This is done by sending an error bucket with
* status HTTP_BAD_GATEWAY and an EOS bucket up the filter chain.
* @param r current request record of client request
* @param brigade The brigade that is sent through the output filter chain
*/
PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r,
apr_bucket_brigade *brigade);
/**
* Return a hash based on the passed string
* @param str string to produce hash from
* @param method hashing method to use
* @return hash as unsigned int
*/
typedef enum { PROXY_HASHFUNC_DEFAULT, PROXY_HASHFUNC_APR, PROXY_HASHFUNC_FNV } proxy_hash_t;
PROXY_DECLARE(unsigned int) ap_proxy_hashfunc(const char *str, proxy_hash_t method);
/**
* Set/unset the worker status bitfield depending on flag
* @param c flag
* @param set set or unset bit
* @param w worker to use
* @return APR_SUCCESS if valid flag
*/
PROXY_DECLARE(apr_status_t) ap_proxy_set_wstatus(char c, int set, proxy_worker *w);
/**
* Create readable representation of worker status bitfield
* @param p pool
* @param w worker to use
* @return string representation of status
*/
PROXY_DECLARE(char *) ap_proxy_parse_wstatus(apr_pool_t *p, proxy_worker *w);
/**
* Sync balancer and workers based on any updates w/i shm
* @param b balancer to check/update member list of
* @param s server rec
* @param conf config
* @return APR_SUCCESS if all goes well
*/
PROXY_DECLARE(apr_status_t) ap_proxy_sync_balancer(proxy_balancer *b,
server_rec *s,
proxy_server_conf *conf);
/**
* Find the matched alias for this request and setup for proxy handler
* @param r request
* @param ent proxy_alias record
* @param dconf per-dir config or NULL
* @return DECLINED, DONE or OK if matched
*/
PROXY_DECLARE(int) ap_proxy_trans_match(request_rec *r,
struct proxy_alias *ent,
proxy_dir_conf *dconf);
#define PROXY_LBMETHOD "proxylbmethod"
/* The number of dynamic workers that can be added when reconfiguring.
* If this limit is reached you must stop and restart the server.
*/
#define PROXY_DYNAMIC_BALANCER_LIMIT 16
/**
* Calculate maximum number of workers in scoreboard.
* @return number of workers to allocate in the scoreboard
*/
int ap_proxy_lb_workers(void);
/* For proxy_util */
extern module PROXY_DECLARE_DATA proxy_module;
extern int PROXY_DECLARE_DATA proxy_lb_workers;
extern const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_path;
extern const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_domain;
#endif /*MOD_PROXY_H*/
/** @} */