haproxy: add --haproxy-clientip flag to spoof client IPs

CURLOPT_HAPROXY_CLIENT_IP in the library

Closes #10779
This commit is contained in:
Raito Bezarius 2023-03-16 14:20:11 +01:00 committed by Daniel Stenberg
parent 9ad23c38e5
commit 0a75964d0d
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
21 changed files with 267 additions and 4 deletions

View file

@ -54,6 +54,7 @@ static void free_config_fields(struct OperationConfig *config)
Curl_safefree(config->useragent);
Curl_safefree(config->altsvc);
Curl_safefree(config->hsts);
Curl_safefree(config->haproxy_clientip);
curl_slist_free_all(config->cookies);
Curl_safefree(config->cookiejar);
curl_slist_free_all(config->cookiefiles);

View file

@ -278,6 +278,7 @@ struct OperationConfig {
long happy_eyeballs_timeout_ms; /* happy eyeballs timeout in milliseconds.
0 is valid. default: CURL_HET_DEFAULT. */
bool haproxy_protocol; /* whether to send HAProxy protocol v1 */
char *haproxy_clientip; /* client IP for HAProxy protocol */
bool disallow_username_in_url; /* disallow usernames in URLs */
char *aws_sigv4;
enum {

View file

@ -122,6 +122,7 @@ static const struct LongShort aliases[]= {
{"*x", "krb4", ARG_STRING},
/* 'krb4' is the previous name */
{"*X", "haproxy-protocol", ARG_BOOL},
{"*P", "haproxy-clientip", ARG_STRING},
{"*y", "max-filesize", ARG_STRING},
{"*z", "disable-eprt", ARG_BOOL},
{"*Z", "eprt", ARG_BOOL},
@ -1055,6 +1056,9 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
case 'X': /* --haproxy-protocol */
config->haproxy_protocol = toggle;
break;
case 'P': /* --haproxy-clientip */
GetStr(&config->haproxy_clientip, nextarg);
break;
case 'y': /* --max-filesize */
{
curl_off_t value;

View file

@ -249,6 +249,9 @@ const struct helptxt helptext[] = {
{" --haproxy-protocol",
"Send HAProxy PROXY protocol v1 header",
CURLHELP_HTTP | CURLHELP_PROXY},
{" --haproxy-clientip",
"Sets the HAProxy PROXY protocol v1 client IP",
CURLHELP_HTTP | CURLHELP_PROXY},
{"-I, --head",
"Show document info only",
CURLHELP_HTTP | CURLHELP_FTP | CURLHELP_FILE},

View file

@ -2161,6 +2161,11 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(config->haproxy_protocol)
my_setopt(curl, CURLOPT_HAPROXYPROTOCOL, 1L);
/* new in 8.2.0 */
if(config->haproxy_clientip)
my_setopt_str(curl, CURLOPT_HAPROXY_CLIENT_IP,
config->haproxy_clientip);
if(config->disallow_username_in_url)
my_setopt(curl, CURLOPT_DISALLOW_USERNAME_IN_URL, 1L);