Hi here a little patch to enable set-mark for the FreeBSD platform.

Kind regards.
From 4acee3742a9385f4b1c9b611e59e7f2713d47a04 Mon Sep 17 00:00:00 2001
From: David Carlier <[email protected]>
Date: Sat, 26 Jun 2021 12:04:36 +0100
Subject: [PATCH] BUILD/MEDIUM: tcp: set-mark setting support for FreeBSD.

This platform has a similar socket option from Linux's SO_MARK,
 marking a socket with an id for packet filter purpose, DTrace
monitoring and so on.
---
 include/haproxy/connection.h | 5 ++++-
 src/tcp_act.c                | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h
index d4843462f..02096b036 100644
--- a/include/haproxy/connection.h
+++ b/include/haproxy/connection.h
@@ -694,8 +694,11 @@ static inline void conn_set_mark(const struct connection *conn, int mark)
 	if (!conn || !conn_ctrl_ready(conn))
 		return;
 
-#ifdef SO_MARK
+#if defined(SO_MARK)
 	setsockopt(conn->handle.fd, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
+#elif defined(SO_USER_COOKIE)
+	uint32_t mval = (uint32_t)mark;
+	setsockopt(conn->handle.fd, SOL_SOCKET, SO_USER_COOKIE, &mval, sizeof(mval));
 #endif
 }
 
diff --git a/src/tcp_act.c b/src/tcp_act.c
index ff521d2c2..a6c58fb88 100644
--- a/src/tcp_act.c
+++ b/src/tcp_act.c
@@ -305,7 +305,7 @@ static enum act_parse_ret tcp_parse_set_src_dst(const char **args, int *orig_arg
 static enum act_parse_ret tcp_parse_set_mark(const char **args, int *cur_arg, struct proxy *px,
 					     struct act_rule *rule, char **err)
 {
-#ifdef SO_MARK
+#if defined(SO_MARK) || defined(SO_USER_COOKIE)
 	char *endp;
 	unsigned int mark;
 
@@ -328,7 +328,7 @@ static enum act_parse_ret tcp_parse_set_mark(const char **args, int *cur_arg, st
 	global.last_checks |= LSTCHK_NETADM;
 	return ACT_RET_PRS_OK;
 #else
-	memprintf(err, "not supported on this platform (SO_MARK undefined)");
+	memprintf(err, "not supported on this platform (SO_MARK|SO_USER_COOKIE undefined)");
 	return ACT_RET_PRS_ERR;
 #endif
 }
-- 
2.32.0

Reply via email to