]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sock_set_mark: take sock family in account
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Thu, 25 Apr 2024 16:57:27 +0000 (18:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 30 Apr 2024 19:38:29 +0000 (21:38 +0200)
SO_MARK, SO_USER_COOKIE, SO_RTABLE socket options (used to set the special
mark/ID on socket, in order to perform mark-based routing) are only supported
by AF_INET sockets. So, let's check socket address family, when we enter into
this function.

include/haproxy/connection.h
include/haproxy/sock.h
src/sock.c

index 8934bb62cdf893a01566eae8819f323a337c4e6b..6ca737c0dee41d677aaf74f66d85dfc8f5d302b6 100644 (file)
@@ -433,7 +433,7 @@ static inline void conn_set_mark(const struct connection *conn, int mark)
        if (!conn || !conn_ctrl_ready(conn) || (conn->flags & CO_FL_FDLESS))
                return;
 
-       sock_set_mark(conn->handle.fd, mark);
+       sock_set_mark(conn->handle.fd, conn->ctrl->fam->sock_family, mark);
 }
 
 /* Sets adjust the TCP quick-ack feature on the connection's socket. The
index 4f628e8a982d3a125b8e2bac366284f34f133244..b8bd731b07a75cbf80d7f43ce74af525ef567f7b 100644 (file)
@@ -70,15 +70,19 @@ static inline void sock_set_tos(int fd, struct sockaddr_storage *addr, int tos)
 }
 
 /* Sets mark sockopt on socket */
-static inline void sock_set_mark(int fd, int mark)
+static inline void sock_set_mark(int fd, sa_family_t sock_family, int mark)
 {
+       if ((sock_family == AF_INET) || (sock_family == AF_INET6)) {
 #if defined(SO_MARK)
-       setsockopt(fd, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
+               setsockopt(fd, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
+/* FreeBSD */
 #elif defined(SO_USER_COOKIE)
-       setsockopt(fd, SOL_SOCKET, SO_USER_COOKIE, &mark, sizeof(mark));
+               setsockopt(fd, SOL_SOCKET, SO_USER_COOKIE, &mark, sizeof(mark));
+/* OpenBSD */
 #elif defined(SO_RTABLE)
-       setsockopt(fd, SOL_SOCKET, SO_RTABLE, &mark, sizeof(mark));
+               setsockopt(fd, SOL_SOCKET, SO_RTABLE, &mark, sizeof(mark));
 #endif
+       }
 }
 
 #endif /* _HAPROXY_SOCK_H */
index 80cddcd63dfb0ce3a75b703c72614b0688de14fb..215fddb5178a91a14d3837ad16a1c371cc67ffd1 100644 (file)
@@ -218,7 +218,7 @@ int sock_create_server_socket(struct connection *conn)
        if (sock_fd == -1)
                goto end;
        if (conn->flags & CO_FL_OPT_MARK)
-               sock_set_mark(sock_fd, conn->mark);
+               sock_set_mark(sock_fd, conn->ctrl->fam->sock_family, conn->mark);
        if (conn->flags & CO_FL_OPT_TOS)
                sock_set_tos(sock_fd, conn->dst, conn->tos);