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

(-)modules/proxy/proxy_util.c (-1 / +24 lines)
Lines 2275-2281 Link Here
2275
    apr_status_t rv;
2275
    apr_status_t rv;
2276
    int connected = 0;
2276
    int connected = 0;
2277
    int loglevel;
2277
    int loglevel;
2278
    apr_sockaddr_t *backend_addr = conn->addr;
2278
    apr_sockaddr_t *backend_addr = conn->addr, *local_addr;
2279
    apr_socket_t *newsock;
2279
    apr_socket_t *newsock;
2280
    void *sconf = s->module_config;
2280
    void *sconf = s->module_config;
2281
    proxy_server_conf *conf =
2281
    proxy_server_conf *conf =
Lines 2349-2354 Link Here
2349
                     "proxy: %s: fam %d socket created to connect to %s",
2349
                     "proxy: %s: fam %d socket created to connect to %s",
2350
                     proxy_function, backend_addr->family, worker->hostname);
2350
                     proxy_function, backend_addr->family, worker->hostname);
2351
2351
2352
        if (conf->bindopt_set) {
2353
            const int start = conf->bind_port;
2354
            const int end = conf->bind_port + conf->bind_range;
2355
            for(int i = start; i < end; ++i) { /* loop until we can bind correctly*/
2356
                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "proxy: %s: trying to bind to %s:%d",
2357
                        proxy_function, conf->bind_addr,i, NULL);
2358
2359
                apr_sockaddr_info_get(&local_addr, conf->bind_addr, APR_UNSPEC,
2360
                            i, 0, conn->scpool);
2361
2362
                if ((rv = apr_socket_bind(newsock, local_addr)) == APR_SUCCESS) {
2363
                    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "proxy: %s: bound to %s:%d",
2364
                            proxy_function, conf->bind_addr, local_addr->port, NULL);
2365
                    break;
2366
                }
2367
            }
2368
            if (rv != APR_SUCCESS) {
2369
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "proxy: %s: can not bound to %s:%d+%d",
2370
                        proxy_function,conf->bind_addr, conf->bind_port, conf->bind_range, NULL);
2371
                return DECLINED;
2372
            }
2373
        }
2374
2352
        /* make the connection out of the socket */
2375
        /* make the connection out of the socket */
2353
        rv = apr_socket_connect(newsock, backend_addr);
2376
        rv = apr_socket_connect(newsock, backend_addr);
2354
2377
(-)modules/proxy/mod_proxy.c (+30 lines)
Lines 1066-1071 Link Here
1066
    ps->timeout_set = 0;
1066
    ps->timeout_set = 0;
1067
    ps->badopt = bad_error;
1067
    ps->badopt = bad_error;
1068
    ps->badopt_set = 0;
1068
    ps->badopt_set = 0;
1069
    ps->bindopt_set = 0;
1069
    ps->pool = p;
1070
    ps->pool = p;
1070
1071
1071
    return ps;
1072
    return ps;
Lines 1109-1114 Link Here
1109
    ps->badopt_set = overrides->badopt_set || base->badopt_set;
1110
    ps->badopt_set = overrides->badopt_set || base->badopt_set;
1110
    ps->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status;
1111
    ps->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status;
1111
    ps->proxy_status_set = overrides->proxy_status_set || base->proxy_status_set;
1112
    ps->proxy_status_set = overrides->proxy_status_set || base->proxy_status_set;
1113
    ps->bindopt_set = overrides->bindopt_set || base->bindopt_set;
1112
    ps->pool = p;
1114
    ps->pool = p;
1113
    return ps;
1115
    return ps;
1114
}
1116
}
Lines 1706-1711 Link Here
1706
    return NULL;
1708
    return NULL;
1707
}
1709
}
1708
1710
1711
static const char*
1712
    set_proxy_bindaddr(cmd_parms *parms, void *dummy, const char *arg)
1713
{
1714
    const char* port;
1715
    const char* range;
1716
    
1717
    proxy_server_conf *psf =
1718
    ap_get_module_config(parms->server->module_config, &proxy_module);
1719
    port = ap_strstr_c(arg, ":");
1720
    if (!port) {
1721
        psf->bind_addr = arg;
1722
        psf->bind_port = 0;
1723
        psf->bind_range = 1; /* when port=0, bind should not fail */
1724
        return NULL;
1725
    }
1726
    psf->bind_addr = apr_pstrndup(parms->pool, arg, port-arg);
1727
    range = ap_strstr_c(port, "+");
1728
    if (!range)
1729
        return "ProxyBindAddress format is <addr>:<port>+<range>";
1730
    psf->bind_port = atoi(port+1);
1731
    psf->bind_range = atoi(range+1);
1732
1733
    psf->bindopt_set = 1;
1734
    return NULL;
1735
}
1736
1709
static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
1737
static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
1710
{
1738
{
1711
    server_rec *s = cmd->server;
1739
    server_rec *s = cmd->server;
Lines 2088-2093 Link Here
2088
     "A balancer or worker name with list of params"),
2116
     "A balancer or worker name with list of params"),
2089
    AP_INIT_TAKE1("ProxyFtpDirCharset", set_ftp_directory_charset, NULL,
2117
    AP_INIT_TAKE1("ProxyFtpDirCharset", set_ftp_directory_charset, NULL,
2090
     RSRC_CONF|ACCESS_CONF, "Define the character set for proxied FTP listings"),
2118
     RSRC_CONF|ACCESS_CONF, "Define the character set for proxied FTP listings"),
2119
    AP_INIT_TAKE1("ProxyBindAddress", set_proxy_bindaddr, NULL, RSRC_CONF,
2120
     "Set the source address for a proxied connection. "),
2091
    {NULL}
2121
    {NULL}
2092
};
2122
};
2093
2123
(-)modules/proxy/mod_proxy.h (+5 lines)
Lines 190-195 Link Here
190
        status_full
190
        status_full
191
    } proxy_status;             /* Status display options */
191
    } proxy_status;             /* Status display options */
192
    char proxy_status_set;
192
    char proxy_status_set;
193
    /*bind to local ports*/
194
    const char *bind_addr;
195
    int bind_port;
196
    int bind_range;             /* restrict the source ports used by mod_proxy */
197
    char bindopt_set;
193
    apr_pool_t *pool;           /* Pool used for allocating this struct */
198
    apr_pool_t *pool;           /* Pool used for allocating this struct */
194
} proxy_server_conf;
199
} proxy_server_conf;
195
200

Return to bug 44806