mirror of
https://github.com/curl/curl.git
synced 2026-08-25 07:23:31 +03:00
haproxy: add --haproxy-clientip flag to spoof client IPs
CURLOPT_HAPROXY_CLIENT_IP in the library Closes #10779
This commit is contained in:
parent
9ad23c38e5
commit
0a75964d0d
21 changed files with 267 additions and 4 deletions
|
|
@ -71,6 +71,7 @@ static CURLcode cf_haproxy_date_out_set(struct Curl_cfilter*cf,
|
|||
struct cf_haproxy_ctx *ctx = cf->ctx;
|
||||
CURLcode result;
|
||||
const char *tcp_version;
|
||||
const char *client_ip;
|
||||
|
||||
DEBUGASSERT(ctx);
|
||||
DEBUGASSERT(ctx->state == HAPROXY_INIT);
|
||||
|
|
@ -82,11 +83,15 @@ static CURLcode cf_haproxy_date_out_set(struct Curl_cfilter*cf,
|
|||
#endif /* USE_UNIX_SOCKETS */
|
||||
/* Emit the correct prefix for IPv6 */
|
||||
tcp_version = cf->conn->bits.ipv6 ? "TCP6" : "TCP4";
|
||||
if(data->set.str[STRING_HAPROXY_CLIENT_IP])
|
||||
client_ip = data->set.str[STRING_HAPROXY_CLIENT_IP];
|
||||
else
|
||||
client_ip = data->info.conn_primary_ip;
|
||||
|
||||
result = Curl_dyn_addf(&ctx->data_out, "PROXY %s %s %s %i %i\r\n",
|
||||
tcp_version,
|
||||
data->info.conn_local_ip,
|
||||
data->info.conn_primary_ip,
|
||||
client_ip,
|
||||
data->info.conn_local_port,
|
||||
data->info.conn_primary_port);
|
||||
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ struct curl_easyoption Curl_easyopts[] = {
|
|||
{"HAPPY_EYEBALLS_TIMEOUT_MS", CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS,
|
||||
CURLOT_LONG, 0},
|
||||
{"HAPROXYPROTOCOL", CURLOPT_HAPROXYPROTOCOL, CURLOT_LONG, 0},
|
||||
{"HAPROXY_CLIENT_IP", CURLOPT_HAPROXY_CLIENT_IP, CURLOT_STRING, 0},
|
||||
{"HEADER", CURLOPT_HEADER, CURLOT_LONG, 0},
|
||||
{"HEADERDATA", CURLOPT_HEADERDATA, CURLOT_CBPTR, 0},
|
||||
{"HEADERFUNCTION", CURLOPT_HEADERFUNCTION, CURLOT_FUNCTION, 0},
|
||||
|
|
@ -372,6 +373,6 @@ struct curl_easyoption Curl_easyopts[] = {
|
|||
*/
|
||||
int Curl_easyopts_check(void)
|
||||
{
|
||||
return ((CURLOPT_LASTENTRY%10000) != (322 + 1));
|
||||
return ((CURLOPT_LASTENTRY%10000) != (323 + 1));
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1867,6 +1867,15 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
|
|||
*/
|
||||
data->set.haproxyprotocol = (0 != va_arg(param, long)) ? TRUE : FALSE;
|
||||
break;
|
||||
case CURLOPT_HAPROXY_CLIENT_IP:
|
||||
/*
|
||||
* Set the client IP to send through HAProxy PROXY protocol
|
||||
*/
|
||||
result = Curl_setstropt(&data->set.str[STRING_HAPROXY_CLIENT_IP],
|
||||
va_arg(param, char *));
|
||||
/* We enable implicitly the HAProxy protocol if we use this flag. */
|
||||
data->set.haproxyprotocol = TRUE;
|
||||
break;
|
||||
#endif
|
||||
case CURLOPT_INTERFACE:
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -1563,6 +1563,7 @@ enum dupstring {
|
|||
STRING_DNS_LOCAL_IP6,
|
||||
STRING_SSL_EC_CURVES,
|
||||
STRING_AWS_SIGV4, /* Parameters for V4 signature */
|
||||
STRING_HAPROXY_CLIENT_IP, /* CURLOPT_HAPROXY_CLIENT_IP */
|
||||
|
||||
/* -- end of null-terminated strings -- */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue