From 4efe723996cf2444c2a1eb1c6215ca6c96c4a555 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Fri, 11 Jun 2021 22:52:31 -0700 Subject: [PATCH] Issue #2: Implement a `ProxyProtocolIgnore` directive, which can be used in conjunction with `mod_ifsession` for reading -- then ignoring -- the PROXY protocol from some clients. --- mod_proxy_protocol.c | 36 ++- mod_proxy_protocol.html | 37 +++ .../Modules/mod_proxy_protocol/ifsession.pm | 261 ++++++++++++++++++ 3 files changed, 333 insertions(+), 1 deletion(-) diff --git a/mod_proxy_protocol.c b/mod_proxy_protocol.c index 0dcb446..bbd79d8 100644 --- a/mod_proxy_protocol.c +++ b/mod_proxy_protocol.c @@ -1253,6 +1253,26 @@ MODRET set_proxyprotocolengine(cmd_rec *cmd) { return PR_HANDLED(cmd); } +/* usage: ProxyProtocolIgnore on|off */ +MODRET set_proxyprotocolignore(cmd_rec *cmd) { + int ignore = 0; + config_rec *c; + + CHECK_ARGS(cmd, 1); + CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL); + + ignore = get_boolean(cmd, 1); + if (ignore == -1) { + CONF_ERROR(cmd, "expected Boolean parameter"); + } + + c = add_config_param(cmd->argv[0], 1, NULL); + c->argv[0] = pcalloc(c->pool, sizeof(int)); + *((int *) c->argv[0]) = ignore; + + return PR_HANDLED(cmd); +} + /* usage: ProxyProtocolOptions opt1 ... */ MODRET set_proxyprotocoloptions(cmd_rec *cmd) { register unsigned int i; @@ -1334,7 +1354,7 @@ MODRET set_proxyprotocolversion(cmd_rec *cmd) { static int proxy_protocol_sess_init(void) { config_rec *c; - int engine = 0, res = 0, timerno = -1, xerrno; + int engine = 0, ignore = FALSE, res = 0, timerno = -1, xerrno; const pr_netaddr_t *proxied_src_addr = NULL, *proxied_dst_addr = NULL; unsigned int proxied_src_port = 0, proxied_dst_port = 0; const char *remote_ip = NULL, *remote_name = NULL; @@ -1349,6 +1369,12 @@ static int proxy_protocol_sess_init(void) { return 0; } + /* ProxyProtocolIgnore */ + c = find_config(main_server->conf, CONF_PARAM, "ProxyProtocolIgnore", FALSE); + if (c != NULL) { + ignore = *((int *) c->argv[0]); + } + /* ProxyProtocolOptions */ c = find_config(main_server->conf, CONF_PARAM, "ProxyProtocolOptions", FALSE); while (c != NULL) { @@ -1419,6 +1445,13 @@ static int proxy_protocol_sess_init(void) { return -1; } + if (ignore == TRUE) { + pr_log_debug(DEBUG10, MOD_PROXY_PROTOCOL_VERSION + ": ProxyProtocolIgnore is in effect, ignoring proxied source " + "address '%s'", pr_netaddr_get_ipstr(proxied_src_addr)); + return 0; + } + if (proxied_src_addr != NULL) { remote_ip = pstrdup(session.pool, pr_netaddr_get_ipstr(pr_netaddr_get_sess_remote_addr())); @@ -1539,6 +1572,7 @@ static int proxy_protocol_sess_init(void) { static conftable proxy_protocol_conftab[] = { { "ProxyProtocolEngine", set_proxyprotocolengine, NULL }, + { "ProxyProtocolIgnore", set_proxyprotocolignore, NULL }, { "ProxyProtocolOptions", set_proxyprotocoloptions, NULL }, { "ProxyProtocolTimeout", set_proxyprotocoltimeout, NULL }, { "ProxyProtocolVersion", set_proxyprotocolversion, NULL }, diff --git a/mod_proxy_protocol.html b/mod_proxy_protocol.html index 24d3985..58e3f86 100644 --- a/mod_proxy_protocol.html +++ b/mod_proxy_protocol.html @@ -46,6 +46,7 @@

Author

Directives