Support HAProxy proxy v1 protocol

Added:
-H option - expect HAProxy proxy v1 header, e.g. `proxy -H`

parent ha type - send HAProxy proxy v1 header (must be last in redirection), e.g.

allow *
parent 1000 ha
parent 1000 proxy 1.2.3.4 3128
socks
This commit is contained in:
Vladimir Dubrovin committed 2026-04-08 19:21:25 +03:00
1 parent e373d84717
commit 7e7a0d4336
5 files changed
+111 -55

No files matched your search

+34
View File
@@ -74,6 +74,37 @@ void * threadfunc (void *p) {
#endif
#endif
if(param->srv->haproxy){
char buf[128];
int i;
i = sockgetlinebuf(param, CLIENT, (unsigned char *)buf, sizeof(buf)-1, '\n', conf.timeouts[STRING_S]);
if(i > 12 && !strncasecmp(buf, "PROXY TCP", 9)){
char *token, *token2=NULL;
unsigned short u1=0, u2=0;
buf[i] = 0;
token = strchr(buf, ' ');
if(token) token = strchr(token+1, ' ');
if(token) token++;
if(token) token2 = strchr(token+1, ' ');
if(token2) {
*token2 = 0;
getip46(46, (unsigned char*) token, (struct sockaddr *)&param->sincr);
token = token2+1;
token2 = strchr(token, ' ');
}
if(token2) {
*token2 = 0;
getip46(46, (unsigned char *) token, (struct sockaddr *)&param->sincl);
token = token2+1;
token2 = strchr(token, ' ');
}
if(token){
sscanf(token,"%hu%hu", &u1, &u2);
if(u1) *SAPORT(&param->sincr) = htons(u1);
if(u2) *SAPORT(&param->sincl) = htons(u1);
}
}
}
((struct clientparam *) p)->srv->pf((struct clientparam *)p);
}
#ifdef _WIN32
@@ -417,6 +448,9 @@ int MODULEMAINFUNC (int argc, char** argv){
case 'h':
hostname = argv[i] + 2;
break;
case 'H':
srv.haproxy=1;
break;
case 'c':
srv.requirecert = 1;
if(isdigit(argv[i][2])) srv.requirecert = atoi(argv[i]+2);