From b1bbdce53cc1b04dd805bebc41951b070027ee3b Mon Sep 17 00:00:00 2001
From: Roberto Moreda <moreda@allenta.com>
Date: Mon, 3 Mar 2025 20:48:01 +0100
Subject: [PATCH 1/3] MEDIUM: log: add options eval for log-forward

This commit adds parsing of options in log-forward config sections and
prepares the scenario to implement actual changes of behaviuor. So far
we only take in account proxy->options2, which is the bit container with
more available positions.
---
 src/log.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/log.c b/src/log.c
index 90b5645cb..595691bd3 100644
--- a/src/log.c
+++ b/src/log.c
@@ -6011,6 +6011,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
 		px->accept = frontend_accept;
 		px->default_target = &syslog_applet.obj_type;
 		px->id = strdup(args[1]);
+		px->options2 = 0;
 	}
 	else if (strcmp(args[0], "maxconn") == 0) {  /* maxconn */
 		if (warnifnotcap(cfg_log_forward, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
@@ -6188,6 +6189,34 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm)
 		}
 		cfg_log_forward->timeout.client = MS_TO_TICKS(timeout);
 	}
+	else if (strcmp(args[0], "option") == 0) {
+		int optnum;
+
+		if (*(args[1]) == '\0') {
+			ha_alert("parsing [%s:%d]: '%s' expects an option name.\n",
+				 file, linenum, args[0]);
+			err_code |= ERR_ALERT | ERR_FATAL;
+			goto out;
+		}
+
+		for (optnum = 0; cfg_opts2[optnum].name; optnum++) {
+			if (strcmp(args[1], cfg_opts2[optnum].name) == 0) {
+				if (cfg_opts2[optnum].cap == PR_CAP_NONE) {
+					ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n",
+					         file, linenum, cfg_opts2[optnum].name);
+					err_code |= ERR_ALERT | ERR_FATAL;
+					goto out;
+				}
+				if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code))
+					goto out;
+				if (warnifnotcap(cfg_log_forward, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) {
+					err_code |= ERR_WARN;
+					goto out;
+				}
+				cfg_log_forward->options2 |= cfg_opts2[optnum].val;
+			}
+		}
+	}
 	else {
 		ha_alert("parsing [%s:%d] : unknown keyword '%s' in log-forward section.\n", file, linenum, args[0]);
 		err_code |= ERR_ALERT | ERR_ABORT;
-- 
2.42.0

