mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
MINOR: sock_set_mark: take sock family in account
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.
This commit is contained in:
parent
d602d568e0
commit
772d070ab5
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user