View | Details | Raw Unified | Return to bug 44806
Collapse All | Expand All

(-)file_not_specified_in_diff (-3 / +123 lines)
Line  Link Here
0
-- /usr/src/httpd-2.2.8/modules/proxy/proxy_util.c~    2007-10-07 12:29:36.000000000 +0000
0
++ /usr/src/httpd-2.2.8/modules/proxy/proxy_util.c     2008-06-04 22:28:27.000000000 +0000
Lines 2086-2091 Link Here
2086
}
2086
}
2087
#endif /* USE_ALTERNATE_IS_CONNECTED */
2087
#endif /* USE_ALTERNATE_IS_CONNECTED */
2088
2088
2089
apr_status_t bind_to_addr(apr_socket_t *newsock, apr_sockaddr_t *laddr,
2090
        const char *proxy_function, proxy_server_conf *conf, server_rec *s)
2091
{
2092
    int i;
2093
    const int idx = conf->bind_idx;
2094
    const int range = conf->bind_range;
2095
    const int start = conf->bind_port;
2096
    for(i = 0; i < range; ++i) { /* loop until we can bind correctly*/
2097
        int port = start + ((idx + i) % range);
2098
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "proxy: %s: trying to bind to %s:%u AF=%u",
2099
                proxy_function, laddr->hostname, port, laddr->family, NULL);
2100
2101
        laddr->sa.sin.sin_port = htons(port);
2102
        laddr->port = port;
2103
        if (apr_socket_bind(newsock, laddr) == APR_SUCCESS) {
2104
            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "proxy: %s: bound to %s:%u",
2105
                    proxy_function, laddr->hostname, laddr->port, NULL);
2106
            conf->bind_idx = i + 1;
2107
            return APR_SUCCESS;
2108
        }
2109
    }
2110
    return APR_EINVAL;
2111
}
2112
2113
2089
PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
2114
PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
2090
                                            proxy_conn_rec *conn,
2115
                                            proxy_conn_rec *conn,
2091
                                            proxy_worker *worker,
2116
                                            proxy_worker *worker,
Lines 2094-2100 Link Here
2094
    apr_status_t rv;
2119
    apr_status_t rv;
2095
    int connected = 0;
2120
    int connected = 0;
2096
    int loglevel;
2121
    int loglevel;
2097
    apr_sockaddr_t *backend_addr = conn->addr;
2122
    apr_sockaddr_t *addr, *backend_addr = conn->addr;
2098
    apr_socket_t *newsock;
2123
    apr_socket_t *newsock;
2099
    void *sconf = s->module_config;
2124
    void *sconf = s->module_config;
2100
    proxy_server_conf *conf =
2125
    proxy_server_conf *conf =
Lines 2173-2178 Link Here
2173
                     "proxy: %s: fam %d socket created to connect to %s",
2198
                     "proxy: %s: fam %d socket created to connect to %s",
2174
                     proxy_function, backend_addr->family, worker->hostname);
2199
                     proxy_function, backend_addr->family, worker->hostname);
2175
2200
2201
        if (conf->bindopt_set) {
2202
            rv = APR_EINVAL;
2203
           if (!conf->bind_addr) /* DEBUG STATEMENT */
2204
               ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
2205
               "ProxyBindAddress: conf->bind_addr is NULL, port=%u, range=%u (%08lX)",
2206
               conf->bind_port,conf->bind_range, conf);
2207
            for(addr = conf->bind_addr ; addr; addr = addr->next) {
2208
               ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
2209
                     "proxy: %s: Checking host %s fam %u for ProxyBindAddress",
2210
                     proxy_function, addr->hostname, addr->family);  /* DEBUG STATEMENT */
2211
2212
                if (addr->family != backend_addr->family) continue;
2213
                rv = bind_to_addr(newsock, addr, proxy_function, conf, s);
2214
                if (rv == APR_SUCCESS) break;
2215
            }
2216
            if (rv != APR_SUCCESS) {
2217
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, 
2218
                    "proxy: %s: All addresses and ports in range specified failed to bind",
2219
                    proxy_function, NULL);
2220
                return DECLINED;
2221
            }
2222
        }
2223
2176
        /* make the connection out of the socket */
2224
        /* make the connection out of the socket */
2177
        rv = apr_socket_connect(newsock, backend_addr);
2225
        rv = apr_socket_connect(newsock, backend_addr);
2178
2226
2179
-- /usr/src/httpd-2.2.8/modules/proxy/mod_proxy.c~     2008-01-02 19:25:08.000000000 +0000
2227
++ /usr/src/httpd-2.2.8/modules/proxy/mod_proxy.c      2008-06-04 22:28:05.000000000 +0000
Lines 37-42 Link Here
37
#define MAX(x,y) ((x) >= (y) ? (x) : (y))
37
#define MAX(x,y) ((x) >= (y) ? (x) : (y))
38
#endif
38
#endif
39
39
40
/* Value from /usr/sys/port_kernel.h is it exposed in any portable header? */
41
#define PORT_MAX_PORTS 0x10000
42
43
/* a sane value for RANGE of bind */
44
#define MIN_RANGE_HINT 8
45
40
/*
46
/*
41
 * A Web proxy module. Stages:
47
 * A Web proxy module. Stages:
42
 *
48
 *
Lines 942-947 Link Here
942
    ps->timeout_set = 0;
948
    ps->timeout_set = 0;
943
    ps->badopt = bad_error;
949
    ps->badopt = bad_error;
944
    ps->badopt_set = 0;
950
    ps->badopt_set = 0;
951
    ps->bindopt_set = 0;
952
    ps->bind_idx = 0;
953
    ps->bind_addr = 0;
945
    ps->pool = p;
954
    ps->pool = p;
946
955
947
    return ps;
956
    return ps;
Lines 985-990 Link Here
985
    ps->badopt_set = overrides->badopt_set || base->badopt_set;
994
    ps->badopt_set = overrides->badopt_set || base->badopt_set;
986
    ps->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status;
995
    ps->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status;
987
    ps->proxy_status_set = overrides->proxy_status_set || base->proxy_status_set;
996
    ps->proxy_status_set = overrides->proxy_status_set || base->proxy_status_set;
997
    ps->bindopt_set = overrides->bindopt_set || base->bindopt_set;
988
    ps->pool = p;
998
    ps->pool = p;
989
    return ps;
999
    return ps;
990
}
1000
}
Lines 1565-1570 Link Here
1565
    return NULL;
1575
    return NULL;
1566
}
1576
}
1567
1577
1578
static const char*
1579
    set_proxy_bindaddr(cmd_parms *parms, void *dummy, const char *addr)
1580
{
1581
    char *range, *host, *scope_id;
1582
    apr_port_t port;
1583
    int r = 0;
1584
1585
    proxy_server_conf *psf =
1586
    ap_get_module_config(parms->server->module_config, &proxy_module);
1587
1588
    range = ap_strrchr((char*)addr, '+');
1589
    if (range) {
1590
        *range++ = 0;
1591
        r = atoi(range);
1592
        if (r < MIN_RANGE_HINT)
1593
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
1594
                    "range %u is too low, consider increasing the bind range.", r, NULL);
1595
    }
1596
1597
    /* We dont accept a single port with out a range as it would be same
1598
     * as a single threaded single process http-client
1599
     *
1600
     * We do not allow ip:0+0 or ip:0 as it can be specified more clearly
1601
     * as just ip.
1602
     *
1603
     * we dont accept a range with out a port either.
1604
     */
1605
    if((apr_parse_addr_port(&host, &scope_id, &port, addr, parms->pool)
1606
                != APR_SUCCESS)
1607
            || scope_id               /* we dont know how to use scope_id */
1608
            || (!port && range)       /* only a combo [port+range] is valid */
1609
            || (port && (!range || r < 0)) /* Let admin specify r=0 if he wants to */
1610
            || ((port + r) >= PORT_MAX_PORTS)
1611
      )
1612
        return "ProxyBindAddress:  Invalid address -"
1613
               " format is <addr>[:<port>+<range>]";
1614
1615
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, "ProxyBindAddress = %s : %u + %u (%08lX).",
1616
      host, port, r, psf, NULL);  /* DEBUG STATEMENT */
1617
1618
    /* Preparse the address */
1619
    if (apr_sockaddr_info_get(&(psf->bind_addr), host, APR_UNSPEC, port, 0, parms->pool)
1620
            != APR_SUCCESS) /* || !psf->bind_addr) */    
1621
        return "ProxyBindAddress: Hostname did not resolve.";
1622
1623
apr_sockaddr_t *addr;  /* DEBUG STATEMENT */
1624
for (addr = psf->bind_addr ; addr ; addr = addr->next)
1625
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL, "ProxyBindAddress found AF=%u %s (%0lX)",
1626
        addr->family, addr->hostname, addr, NULL);  /* DEBUG STATEMENT */
1627
1628
    psf->bind_port = port;
1629
    /* If there didn't exist a port then there was no range either. so we have the
1630
     * starting value 0 for r when no port was specified.*/
1631
    psf->bind_range = r + 1;
1632
    psf->bind_idx = 0;
1633
    psf->bindopt_set = 1;
1634
1635
    return NULL;
1636
}
1637
1568
static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
1638
static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
1569
{
1639
{
1570
    server_rec *s = cmd->server;
1640
    server_rec *s = cmd->server;
Lines 1945-1950 Link Here
1945
     "A balancer or worker name with list of params"),
2014
     "A balancer or worker name with list of params"),
1946
    AP_INIT_TAKE1("ProxyFtpDirCharset", set_ftp_directory_charset, NULL,
2015
    AP_INIT_TAKE1("ProxyFtpDirCharset", set_ftp_directory_charset, NULL,
1947
     RSRC_CONF|ACCESS_CONF, "Define the character set for proxied FTP listings"),
2016
     RSRC_CONF|ACCESS_CONF, "Define the character set for proxied FTP listings"),
2017
    AP_INIT_TAKE1("ProxyBindAddress", set_proxy_bindaddr, NULL, RSRC_CONF,
2018
     "Set the source address for a proxied connection. "),
1948
    {NULL}
2019
    {NULL}
1949
};
2020
};

Return to bug 44806