mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-29 06:40:59 +01:00
MINOR: protocol: perform a live check for SO_REUSEPORT support
When testing if a protocol supports SO_REUSEPORT, we're now able to verify if the OS does really support it. While it may be supported at build time, it may possibly have been blocked in a container for example so we'd rather know what it's like.
This commit is contained in:
parent
b073573c10
commit
f1003ea7fa
@ -66,6 +66,7 @@ enum proto_type {
|
|||||||
|
|
||||||
/* Flags for protocol->flags */
|
/* Flags for protocol->flags */
|
||||||
#define PROTO_F_REUSEPORT_SUPPORTED 0x00000001 /* SO_REUSEPORT is supported */
|
#define PROTO_F_REUSEPORT_SUPPORTED 0x00000001 /* SO_REUSEPORT is supported */
|
||||||
|
#define PROTO_F_REUSEPORT_TESTED 0x00000002 /* SO_REUSEPORT support was tested */
|
||||||
|
|
||||||
/* protocol families define standard functions acting on a given address family
|
/* protocol families define standard functions acting on a given address family
|
||||||
* for a socket implementation, such as AF_INET/PF_INET for example.
|
* for a socket implementation, such as AF_INET/PF_INET for example.
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
#include <haproxy/proto_quic.h>
|
#include <haproxy/proto_quic.h>
|
||||||
#include <haproxy/protocol.h>
|
#include <haproxy/protocol.h>
|
||||||
#include <haproxy/proxy.h>
|
#include <haproxy/proxy.h>
|
||||||
|
#include <haproxy/sock.h>
|
||||||
#include <haproxy/tools.h>
|
#include <haproxy/tools.h>
|
||||||
|
|
||||||
|
|
||||||
@ -92,12 +93,23 @@ void protocol_setf_all(uint flag)
|
|||||||
int protocol_supports_flag(struct protocol *proto, uint flag)
|
int protocol_supports_flag(struct protocol *proto, uint flag)
|
||||||
{
|
{
|
||||||
if (flag == PROTO_F_REUSEPORT_SUPPORTED) {
|
if (flag == PROTO_F_REUSEPORT_SUPPORTED) {
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
/* check if the protocol supports SO_REUSEPORT */
|
/* check if the protocol supports SO_REUSEPORT */
|
||||||
if (!(_HA_ATOMIC_LOAD(&proto->flags) & PROTO_F_REUSEPORT_SUPPORTED))
|
if (!(_HA_ATOMIC_LOAD(&proto->flags) & PROTO_F_REUSEPORT_SUPPORTED))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* OK it looks like it is supported */
|
/* at least nobody said it was not supported */
|
||||||
|
if (_HA_ATOMIC_LOAD(&proto->flags) & PROTO_F_REUSEPORT_TESTED)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
/* run a live check */
|
||||||
|
ret = _sock_supports_reuseport(proto->fam, proto->sock_type, proto->sock_prot);
|
||||||
|
if (!ret)
|
||||||
|
_HA_ATOMIC_AND(&proto->flags, ~PROTO_F_REUSEPORT_SUPPORTED);
|
||||||
|
|
||||||
|
_HA_ATOMIC_OR(&proto->flags, PROTO_F_REUSEPORT_TESTED);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user