proxy_util.c revision c6cf638d68b4cfff4f74ebc360abca97ad38cd71
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Licensed to the Apache Software Foundation (ASF) under one or more
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * contributor license agreements. See the NOTICE file distributed with
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * this work for additional information regarding copyright ownership.
bc8fd1b0b1afdf89b8d28eefa8cd74e26ba97986fielding * The ASF licenses this file to You under the Apache License, Version 2.0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * (the "License"); you may not use this file except in compliance with
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the License. You may obtain a copy of the License at
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Unless required by applicable law or agreed to in writing, software
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * distributed under the License is distributed on an "AS IS" BASIS,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * See the License for the specific language governing permissions and
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * limitations under the License.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Utility routines for Apache proxy */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Opaque structure containing target server info when
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * using a forward proxy.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Up to now only used in combination with HTTP CONNECT.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbtypedef struct {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int use_http_connect; /* Use SSL Tunneling via HTTP CONNECT */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Global balancer counter */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int lb_workers_limit = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int proxy_match_hostname(struct dirconn_entry *This, request_rec *r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int proxy_match_word(struct dirconn_entry *This, request_rec *r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, create_req,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* already called in the knowledge that the characters are hex digits */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#else /*APR_CHARSET_EBCDIC*/
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * we assume that the hex value refers to an ASCII character
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * so convert to EBCDIC so that it makes sense locally;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * example:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * client specifies %20 in URL to refer to a space char;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz * at this point we're called with EBCDIC "20"; after turning
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz * EBCDIC "20" into binary 0x20, we then need to assume that 0x20
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz * represents an ASCII char and convert 0x20 to EBCDIC, yielding
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return buf[0];
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif /*APR_CHARSET_EBCDIC*/
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb x[0] = '%';
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (i >= 10) {
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick if (i >= 10) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar#else /*APR_CHARSET_EBCDIC*/
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe x[0] = '%';
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#endif /*APR_CHARSET_EBCDIC*/
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar * canonicalise a URL-encoded string
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar * Convert a URL-encoded string to canonical form.
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar * It decodes characters which need not be encoded,
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz * and encodes those which must be encoded, and does not touch
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz * those which must not be touched.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowePROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe char *allowed; /* characters which should not be encoded */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar char *reserved; /* characters which much not be en/de-coded */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * N.B. in addition to :@&=, this allows ';' in an http path
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * and '?' in an ftp path -- this may be revised
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * Also, it makes a '+' character in a search string reserved, as
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * it may be form-encoded. (Although RFC 1738 doesn't allow this -
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * it only permits ; / ? : @ = & as reserved chars.)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (t == enc_search) {
4775dfc34c90fada8c7c4d6a57ed8a3114d55c2dtrawick else if (t == enc_user) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (t == enc_fpath) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else { /* if (t == enc_parm) */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (t == enc_search) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe for (i = 0, j = 0; i < len; i++, j++) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe/* always handle '/' first */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * decode it if not already done. do not decode reverse proxied URLs
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * unless specifically forced
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if ((forcedec || (proxyreq && proxyreq != PROXYREQ_REVERSE)) && ch == '%') {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (!apr_isxdigit(x[i + 1]) || !apr_isxdigit(x[i + 2])) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (ch != 0 && strchr(reserved, ch)) { /* keep it encoded */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz/* recode it, if necessary */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz y[j] = '\0';
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * Parses network-location.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * urlp on input the URL; on output the path, after the leading /
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * user NULL if no user/password permitted
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * password holder for password
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * host holder for host
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * port port number; only set if one is supplied.
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz * Returns an error string.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar return "Malformed URL";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* find _last_ '@' since it might occur in user/password part */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe/* find password */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe password = ap_proxy_canonenc(p, strp + 1, strlen(strp + 1), enc_user, 1, 0);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "Bad %-escape in URL (password)";
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe user = ap_proxy_canonenc(p, user, strlen(user), enc_user, 1, 0);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return "Bad %-escape in URL (username)";
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * Parse the host string to separate host portion from optional port.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * Perform range checking on port.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker rv = apr_parse_addr_port(&addr, &scope_id, &tmp_port, host, p);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (rv != APR_SUCCESS || addr == NULL || scope_id != NULL) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return "Invalid host/port";
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (tmp_port != 0) { /* only update caller's port if port was specified */
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp ap_str_tolower(addr); /* DNS names are case-insensitive */
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp * If the date is a valid RFC 850 date or asctime() date, then it
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp * is converted to the RFC 1123 format.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowePROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * list is a comma-separated list of case-insensitive tokens, with
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * optional whitespace around the tokens.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The return returns 1 if the token val is found in the list, or 0
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick * otherwise.
c2cf53a40a9814eb91db2cdf820f97d943f21628coarPROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *p;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (p != NULL) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe } while (apr_isspace(*p));
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz if (i == len && strncasecmp(list, val, len) == 0) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * list is a comma-separated list of case-insensitive tokens, with
659ad814f714e556bdd03e1d771cba156baab92ewrowe * optional whitespace around the tokens.
659ad814f714e556bdd03e1d771cba156baab92ewrowe * if val appears on the list of tokens, it is removed from the list,
659ad814f714e556bdd03e1d771cba156baab92ewrowe * and the new list is returned.
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarPROXY_DECLARE(char *)ap_proxy_removestr(apr_pool_t *pool, const char *list, const char *val)
11fb2f3611e6ff9a541e10b13e3108934f828141gregames const char *p;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (p != NULL) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe } while (apr_isspace(*p));
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* do nothing */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar new = apr_pstrcat(pool, new, ",", apr_pstrndup(pool, list, i), NULL);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * Converts 8 hex digits to a time integer
8aefbd756763807188d2e3ce336a8680e4893066wrowe unsigned int j;
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (i = 0, j = 0; i < 8; i++) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (j == 0xffffffff) {
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * Converts a time integer to 8 hex digits
4f9c22c4f27571d54197be9674e1fc0d528192aestriker unsigned int j = t;
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (i = 7; i >= 0; i--) {
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerPROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "The proxy server could not handle the request "
cf6ef072483172309861d06e85b1aeff4573c060wrowe "Reason: <strong>",
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Allow "error-notes" string to be printed by ap_send_error_response() */
cf6ef072483172309861d06e85b1aeff4573c060wrowe apr_table_setn(r->notes, "verbose-error-to", apr_pstrdup(r->pool, "*"));
cf6ef072483172309861d06e85b1aeff4573c060wrowe r->status_line = apr_psprintf(r->pool, "%3.3u Proxy Error", statuscode);
cf6ef072483172309861d06e85b1aeff4573c060wrowestatic const char *
cf6ef072483172309861d06e85b1aeff4573c060wrowe char *url, *user = NULL, *password = NULL, *err, *host;
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick /* Set url to the first char after "scheme://" */
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick if ((url = strchr(r->uri, ':')) == NULL || url[1] != '/' || url[2] != '/') {
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick url = apr_pstrdup(r->pool, &url[1]); /* make it point to "//", which is what proxy_canon_netloc expects */
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick err = ap_proxy_canon_netloc(r->pool, &url, &user, &password, &host, &port);
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "%s", err);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar/* Return TRUE if addr represents an IP address (or an IP network address) */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowePROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * if the address is given with an explicit netmask, use that
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * Due to a deficiency in apr_inet_addr(), it is impossible to parse
c2cf53a40a9814eb91db2cdf820f97d943f21628coar * "partial" addresses (with less than 4 quads) correctly, i.e.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * 192.168.123 is parsed as 192.168.0.123, which is not what I want.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * I therefore have to parse the IP address manually:
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * if (proxy_readmask(This->name, &This->addr.s_addr, &This->mask.s_addr) == 0)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * addr and mask were set by proxy_readmask()
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * return 1;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * Parse IP addr manually, optionally allowing
a9a4544168a37b43bd180b3703ccee995f27a80awrowe * abbreviated net addresses like 192.168.
a9a4544168a37b43bd180b3703ccee995f27a80awrowe /* Iterate over up to 4 (dotted) quads. */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker for (quads = 0; quads < 4 && *addr != '\0'; ++quads) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (*addr == '/' && quads > 0) { /* netmask starts here. */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return 0; /* no digit at start of quad */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (tmp == addr) { /* expected a digit, found something else */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* invalid octet */
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz ++addr; /* after the 4th quad, a dot would be illegal */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe This->addr.s_addr |= htonl(ip_addr[i] << (24 - 8 * i));
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (addr[0] == '/' && apr_isdigit(addr[1])) { /* net mask follows: */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (tmp == addr) { /* expected a digit, found something else */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (bits < 0 || bits > 32) { /* netmask must be between 0 and 32 */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * Determine (i.e., "guess") netmask by counting the
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * number of trailing .0's; reduce #quads appropriately
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * (so that 192.168.0.0 is equivalent to 192.168.)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* "IP Address should be given in dotted-quad form, optionally followed by a netmask (e.g., 192.168.111.0/24)"; */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* every zero-byte counts as 8 zero-bits */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if (bits != 32) { /* no warning for fully qualified IP address */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "Warning: NetMask not supplied with IP-Addr; guessing: %s/%ld",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe This->mask.s_addr = htonl(APR_INADDR_NONE << (32 - bits));
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (*addr == '\0' && (This->addr.s_addr & ~This->mask.s_addr) != 0) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "Warning: NetMask and IP-Addr disagree in %s/%ld",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe return (*addr == '\0'); /* okay iff we've parsed the whole string */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe/* Return TRUE if addr represents an IP address (or an IP network address) */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowestatic int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if (4 == sscanf(host, "%d.%d.%d.%d", &ip_addr[0], &ip_addr[1], &ip_addr[2], &ip_addr[3])) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* ap_proxy_is_ipaddr() already confirmed that we have
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * a valid octet in ip_addr[i]
38bcc87d9a06e8ba81165421403f275eca4e313btrawick if (This->addr.s_addr == (addr.s_addr & This->mask.s_addr)) {
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz "1)IP-Match: %s[%s] <-> ", host, inet_ntoa(addr));
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (apr_sockaddr_info_get(&reqaddr, host, APR_UNSPEC, 0, 0, r->pool)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "2)IP-NoMatch: hostname=%s msg=Host not found", host);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Try to deal with multiple IP addr's for a host */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* FIXME: This needs to be able to deal with IPv6 */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (This->addr.s_addr == (ip->s_addr & This->mask.s_addr)) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz "3)IP-Match: %s[%s] <-> ", host, inet_ntoa(*ip));
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar/* Return TRUE if addr represents a domain name */
8aefbd756763807188d2e3ce336a8680e4893066wrowePROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Domain name must start with a '.' */
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe /* rfc1035 says DNS names must consist of "[-a-zA-Z0-9]" and '.' */
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe for (i = 0; apr_isalnum(addr[i]) || addr[i] == '-' || addr[i] == '.'; ++i) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "@@@@ handle optional port in proxy_is_domainname()");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* @@@@ handle optional port */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Strip trailing dots */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (i = strlen(addr) - 1; i > 0 && addr[i] == '.'; --i) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar/* Return TRUE if host "host" is in domain "domain" */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarstatic int proxy_match_domainname(struct dirconn_entry *This, request_rec *r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (host == NULL) { /* some error was logged already */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* @@@ do this within the setup? */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Ignore trailing dots in domain comparison: */
8aefbd756763807188d2e3ce336a8680e4893066wrowe && strncasecmp(&host[h_len - d_len], This->name, d_len) == 0;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz/* Return TRUE if host represents a host name */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzPROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* Host names must not start with a '.' */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* rfc1035 says DNS names must consist of "[-a-zA-Z0-9]" and '.' */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (i = 0; apr_isalnum(host[i]) || host[i] == '-' || host[i] == '.'; ++i);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (host[i] != '\0' || apr_sockaddr_info_get(&addr, host, APR_UNSPEC, 0, 0, p) != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Strip trailing dots */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (i = strlen(host) - 1; i > 0 && host[i] == '.'; --i) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* Return TRUE if host "host" is equal to host2 "host2" */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowestatic int proxy_match_hostname(struct dirconn_entry *This, request_rec *r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return 0; /* oops! */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Try to deal with multiple IP addr's for a host */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Ignore trailing dots in host2 comparison: */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz/* Return TRUE if addr is to be matched as a word */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantzPROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar/* Return TRUE if string "str2" occurs literally in "str1" */
c2cf53a40a9814eb91db2cdf820f97d943f21628coarstatic int proxy_match_word(struct dirconn_entry *This, request_rec *r)
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe return host != NULL && ap_strstr_c(host, This->name) != NULL;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz/* checks whether a host in uri_addr matches proxyblock */
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerPROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf,
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* XXX FIXME: conf->noproxies->elts is part of an opaque structure */
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe "proxy: checking remote machine [%s] against [%s]", uri_addr->hostname, npent[j].name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((npent[j].name && ap_strstr_c(uri_addr->hostname, npent[j].name))
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "proxy: connect to remote machine %s blocked: name %s matched", uri_addr->hostname, npent[j].name);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar "proxy: ProxyBlock comparing %s and %s", conf_ip, uri_ip);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "proxy: connect to remote machine %s blocked: IP %s matched", uri_addr->hostname, conf_ip);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* set up the minimal filter set */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowePROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r)
8aefbd756763807188d2e3ce336a8680e4893066wrowe * converts a series of buckets into a string
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * XXX: BillS says this function performs essentially the same function as
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * ap_rgetline() in protocol.c. Deprecate this function and use ap_rgetline()
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * instead? I think ap_proxy_string_read() will not work properly on non ASCII
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * (EBCDIC) machines either.
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarPROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb,
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* start with an empty string */
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* loop through each brigade */
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe /* get brigade from network one line at a time */
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe if (APR_SUCCESS != (rv = ap_get_brigade(c->input_filters, bb,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* loop through each bucket */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* The connection aborted or timed out */
8aefbd756763807188d2e3ce336a8680e4893066wrowe (const char **)&response,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * is string LF terminated?
8aefbd756763807188d2e3ce336a8680e4893066wrowe * XXX: This check can be made more efficient by simply checking
8aefbd756763807188d2e3ce336a8680e4893066wrowe * if the last character in the 'response' buffer is an ASCII_LF.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * See ap_rgetline() for an example.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* concat strings until buff is full - then throw the data away */
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe if (len > 0) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe/* unmerge an element in the table */
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantzPROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* get the value to unmerge */
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* remove the value from the headers */
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* find each comma */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowePROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r,
cf6ef072483172309861d06e85b1aeff4573c060wrowe * XXX FIXME: Make sure this handled the ambiguous case of the :<PORT>
cf6ef072483172309861d06e85b1aeff4573c060wrowe * after the hostname
cf6ef072483172309861d06e85b1aeff4573c060wrowe * XXX FIXME: Ensure the /uri component is a case sensitive match
cf6ef072483172309861d06e85b1aeff4573c060wrowe rconf = ap_get_module_config(r->request_config, &proxy_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_get_module_config(r->server->module_config, &proxy_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * First check if mapping against a balancer and see
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * if we have such a entity. If so, then we need to
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar * find the particulars of the actual worker which may
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * or may not be the right one... basically, we need
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar * to find which member actually handled this request.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe (balancer = ap_proxy_get_balancer(r->pool, sconf, real))) {
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar int n, l3 = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_worker **worker = (proxy_worker **)balancer->workers->elts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* The balancer comparison is a bit trickier. Given the context
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * BalancerMember balancer://alias http://example.com/foo
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * ProxyPassReverse /bash balancer://alias/bar
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * translate url http://example.com/foo/bar/that to /bash/that
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* urlpart (l3) assuredly starts with its own '/' */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else if (l1 >= l2 && strncasecmp((*worker)->name, url, l2) == 0) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe u = apr_pstrcat(r->pool, ent[i].fake, &url[l2], NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe u = apr_pstrcat(r->pool, ent[i].fake, &part[l2], NULL);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * Cookies are a bit trickier to match: we've got two substrings to worry
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * about, and we can't just find them with strstr 'cos of case. Regexp
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * matching would be an easy fix, but for better consistency with all the
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * other matches we'll refrain and use apr_strmatch to find path=/domain=
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * and stick to plain strings for the config values.
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarPROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar proxy_req_conf *rconf = ap_get_module_config(r->request_config,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe const char *pathp;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe const char *domainp;
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe * Find the match and replacement, but save replacing until we've done
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * both path and domain so we know the new strlen
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((pathp = apr_strmatch(conf->cookie_path_str, str, len)) != NULL) {
948096a99010fccf648814fecf38f75c689172d7wrowe ent = (struct proxy_alias *)rconf->cookie_paths->elts;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz for (i = 0; i < conf->cookie_paths->nelts; i++) {
948096a99010fccf648814fecf38f75c689172d7wrowe if ((domainp = apr_strmatch(conf->cookie_domain_str, str, len)) != NULL) {
948096a99010fccf648814fecf38f75c689172d7wrowe ent = (struct proxy_alias *)rconf->cookie_domains->elts;
948096a99010fccf648814fecf38f75c689172d7wrowe ent = (struct proxy_alias *)conf->cookie_domains->elts;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (l1 >= l2 && strncasecmp(ent[i].fake, domainp, l2) == 0) {
c2cf53a40a9814eb91db2cdf820f97d943f21628coarPROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker const char *url)
948096a99010fccf648814fecf38f75c689172d7wrowe if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') {
948096a99010fccf648814fecf38f75c689172d7wrowe /* remove path from uri */
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerPROXY_DECLARE(const char *) ap_proxy_add_balancer(proxy_balancer **balancer,
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar const char *url)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0')
948096a99010fccf648814fecf38f75c689172d7wrowe return "Bad syntax for a balancer name";
948096a99010fccf648814fecf38f75c689172d7wrowe /* remove path from uri */
053497224246c4dbef9af594cacf5c00ed271e6cwrowe * NOTE: The default method is byrequests, which we assume
a9a4544168a37b43bd180b3703ccee995f27a80awrowe lbmethod = ap_lookup_provider(PROXY_LBMETHOD, "byrequests", "0");
948096a99010fccf648814fecf38f75c689172d7wrowe return "Can't find 'byrequests' lb method";
948096a99010fccf648814fecf38f75c689172d7wrowe (*balancer)->workers = apr_array_make(p, 5, sizeof(proxy_worker *));
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar /* XXX Is this a right place to create mutex */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* XXX: Do we need to log something here */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "can not create thread mutex";
0540a0b469147b52e858587270dba31c2aaa9e09wrowePROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe const char *url)
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe const char *c;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * We need to find the start of the path and
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * therefore we know the length of the scheme://hostname/
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * part to we can force-lowercase everything up to
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the start of the path.
a9a4544168a37b43bd180b3703ccee995f27a80awrowe * Do a "longest match" on the worker name to find the worker that
a9a4544168a37b43bd180b3703ccee995f27a80awrowe * fits best to the URL, but keep in mind that we must have at least
a9a4544168a37b43bd180b3703ccee995f27a80awrowe * a minimum matching of length min_match such that
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * scheme://hostname[:port] matches between worker and url.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if ( ((worker_name_length = strlen(worker->name)) <= url_length)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar && (strncmp(url_copy, worker->name, worker_name_length) == 0) ) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowestatic void init_conn_pool(apr_pool_t *p, proxy_worker *worker)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar * Create a connection pool's subpool.
c2cf53a40a9814eb91db2cdf820f97d943f21628coar * This pool is used for connection recycling.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * Once the worker is added it is never removed but
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * it can be disabled.
0540a0b469147b52e858587270dba31c2aaa9e09wrowe * Alloc from the same pool as worker.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * proxy_conn_pool is permanently attached to the worker.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cp = (proxy_conn_pool *)apr_pcalloc(p, sizeof(proxy_conn_pool));
aa047239dedf0d26e8efecfade32e7337f35df19wrowePROXY_DECLARE(const char *) ap_proxy_add_worker(proxy_worker **worker,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe const char *url)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar return "Unable to parse URL";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return "URL must be absolute!";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe (*worker)->name = apr_uri_unparse(p, &uri, APR_URI_UNP_REVEALPASSWORD);
a9a4544168a37b43bd180b3703ccee995f27a80awrowe /* Increase the total worker count */
aa047239dedf0d26e8efecfade32e7337f35df19wrowePROXY_DECLARE(proxy_worker *) ap_proxy_create_worker(apr_pool_t *p)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker = (proxy_worker *)apr_pcalloc(p, sizeof(proxy_worker));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Increase the total worker count */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbap_proxy_add_worker_to_balancer(apr_pool_t *pool, proxy_balancer *balancer,
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe /* Increase the total runtime count */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbPROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe access_status = proxy_run_pre_request(worker, balancer, r, conf, url);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe "proxy: %s: found worker %s for %s",
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe "proxy: *: found forward proxy worker for %s",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "proxy: *: found reverse proxy worker for %s",
e57e920838f31508f1418aa4c25ce55b345b2cebrbb else if (access_status == DECLINED && *balancer != NULL) {
e57e920838f31508f1418aa4c25ce55b345b2cebrbb /* All the workers are busy */
e57e920838f31508f1418aa4c25ce55b345b2cebrbb "proxy: all workers are busy. Unable to serve %s",
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowePROXY_DECLARE(int) ap_proxy_post_request(proxy_worker *worker,
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe access_status = proxy_run_post_request(worker, balancer, r, conf);
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe access_status = OK; /* no post_request handler available */
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe /* TODO: recycle direct worker */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* DEPRECATED */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbPROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **newsock,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *backend_name,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = apr_socket_create(newsock, backend_addr->family,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "proxy: %s: error creating fam %d socket for target %s",
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar * this could be an IPv6 address from the DNS but the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * local machine won't give us an IPv6 socket; hopefully the
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar * DNS returned an additional address to try
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "apr_socket_opt_set(SO_RCVBUF): Failed to set "
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "ProxyReceiveBufferSize, using default");
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe rv = apr_socket_opt_set(*newsock, APR_TCP_NODELAY, 1);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe "apr_socket_opt_set(APR_TCP_NODELAY): "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Failed to set");
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe /* Set a timeout on the socket */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "proxy: %s: fam %d socket created to connect to %s",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* make the connection out of the socket */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* if an error occurred, loop round and try again */
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard loglevel = backend_addr->next ? APLOG_DEBUG : APLOG_ERR;
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard "proxy: %s: attempt to connect to %pI (%s) failed",
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe * If the connection pool is NULL the worker
117026201e6d8fe7d82416b8a7324830f5a87292wrowe * cleanup has been run. Just return.
6c24fd6cfe148639988d5b335185ffb215662801wrowe /* Sanity check: Did we already return the pooled connection? */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe "proxy: Pooled connection 0x%pp for worker %s has been"
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* determine if the connection need to be closed */
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe if (conn->close || !worker->is_address_reusable || worker->disablereuse) {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe /* Always return the SUCCESS */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowePROXY_DECLARE(apr_status_t) ap_proxy_ssl_connection_cleanup(proxy_conn_rec *conn,
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * If we have an existing SSL connection it might be possible that the
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * server sent some SSL message we have not read so far (e.g. a SSL
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * shutdown message if the server closed the keepalive connection while
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * the connection was held unused in our pool).
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * So ensure that if present (=> APR_NONBLOCK_READ) it is read and
c2cf53a40a9814eb91db2cdf820f97d943f21628coar * processed. We don't expect any data to be in the returned brigade.
c2cf53a40a9814eb91db2cdf820f97d943f21628coar bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe rv = ap_get_brigade(conn->connection->input_filters, bb,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if ((rv != APR_SUCCESS) && !APR_STATUS_IS_EAGAIN(rv)) {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe "proxy: SSL cleanup brigade contained %"
c2cf53a40a9814eb91db2cdf820f97d943f21628coar/* reslist constructor */
cadddb2c31d24d48f4017db4df0a29687432326cwrowestatic apr_status_t connection_constructor(void **resource, void *params,
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * Create the subpool for each connection
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * This keeps the memory consumption constant
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * when disconnecting from backend.
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * Create another subpool that manages the data for the
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * socket and the connection member of the proxy_conn_rec struct as we
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * destroy this data more frequently than other data in the proxy_conn_rec
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * struct like hostname and addr (at least in the case where we have
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * keepalive connections that timed out).
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#if APR_HAS_THREADS /* only needed when threads are used */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* reslist destructor */
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowestatic apr_status_t connection_destructor(void *resource, void *params,
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe /* Destroy the pool only if not called from reslist_destroy */
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * ap_proxy_initialize_worker_share() concerns itself
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * with initializing those parts of worker which
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * are, or could be, shared. Basically worker->s
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoarPROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf,
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe /* The worker share is already initialized */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "proxy: worker %s already initialized",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe /* Get scoreboard slot */
c2cf53a40a9814eb91db2cdf820f97d943f21628coar score = (proxy_worker_stat *) ap_get_scoreboard_lb(worker->id);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "proxy: ap_get_scoreboard_lb(%d) failed in child %" APR_PID_T_FMT " for worker %s",
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "proxy: grabbed scoreboard slot %d in child %" APR_PID_T_FMT " for worker %s",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe score = (proxy_worker_stat *) apr_pcalloc(conf->pool, sizeof(proxy_worker_stat));
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "proxy: initialized plain memory in child %" APR_PID_T_FMT " for worker %s",
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz * recheck to see if we've already been here. Possible
0540a0b469147b52e858587270dba31c2aaa9e09wrowe * if proxy is using scoreboard to hold shared stats
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* The worker share is already initialized */
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe "proxy: worker %s already initialized",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->status |= (worker->status | PROXY_WORKER_INITIALIZED);
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddardPROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker, server_rec *s, apr_pool_t *p)
66e89b91046a4d0998bcb11c8aeb39ac444ed2dfjerenkrantz if (worker->status & PROXY_WORKER_INITIALIZED) {
66e89b91046a4d0998bcb11c8aeb39ac444ed2dfjerenkrantz /* The worker is already initialized */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Set default parameters */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->retry = apr_time_from_sec(PROXY_WORKER_DEFAULT_RETRY);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* By default address is reusable unless DisableReuse is set */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz "can not create connection pool");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rv = apr_thread_mutex_create(&(worker->mutex), APR_THREAD_MUTEX_DEFAULT, p);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "can not create thread mutex");
#if (APR_MAJOR_VERSION > 0)
void *conn;
return rv;
server_rec *s)
return OK;
return DECLINED;
return OK;
server_rec *s)
return HTTP_SERVICE_UNAVAILABLE;
#if APR_HAS_THREADS
return HTTP_SERVICE_UNAVAILABLE;
#if APR_HAS_THREADS
return OK;
server_rec *s)
return OK;
PROXY_DECLARE(int)
char **url,
const char *proxyname,
char *server_portstr,
int server_portstr_size)
int server_port;
NULL));
if (!proxyname) {
if (proxyname) {
const char *proxy_auth;
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
server_rec *s)
int status;
int complete = 0;
int len = 0;
if (!complete) {
buffer);
code_str);
return(status);
server_rec *s)
int connected = 0;
int loglevel;
conn_rec *c,
server_rec *s)
int rc;
return OK;
0, NULL,
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return rc;
return OK;
int ap_proxy_lb_workers(void)
if (!lb_workers_limit)
return lb_workers_limit;
apr_bucket *e;
if (r->main)
c->bucket_alloc);
apr_bucket *e;
const char *data;
e = APR_BUCKET_NEXT(e)) {
if (!APR_BUCKET_IS_METADATA(e)) {
else if (APR_BUCKET_IS_FLUSH(e)) {
else if (APR_BUCKET_IS_EOS(e)) {
return rv;