MINOR: sock: Add protocol and socket types parameters to sock_create_server_socket()

This patch only adds <proto_type> new proto_type enum parameter and <sock_type>
socket type parameter to sock_create_server_socket() and adapts its callers.
This is to prepare the use of this function by QUIC servers/backends.
This commit is contained in:
Frederic Lecaille 2025-06-03 16:25:53 +02:00
parent 61454f5a52
commit 3ebda4e143
5 changed files with 10 additions and 7 deletions

View File

@ -28,9 +28,11 @@
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/connection-t.h> #include <haproxy/connection-t.h>
#include <haproxy/listener-t.h> #include <haproxy/listener-t.h>
#include <haproxy/protocol-t.h>
#include <haproxy/sock-t.h> #include <haproxy/sock-t.h>
int sock_create_server_socket(struct connection *conn, struct proxy *be, int *stream_err); int sock_create_server_socket(struct connection *conn, struct proxy *be,
enum proto_type proto_type, int sock_type, int *stream_err);
void sock_enable(struct receiver *rx); void sock_enable(struct receiver *rx);
void sock_disable(struct receiver *rx); void sock_disable(struct receiver *rx);
void sock_unbind(struct receiver *rx); void sock_unbind(struct receiver *rx);

View File

@ -306,7 +306,7 @@ int quic_connect_server(struct connection *conn, int flags)
} }
/* perform common checks on obtained socket FD, return appropriate Stream Error Flag in case of failure */ /* perform common checks on obtained socket FD, return appropriate Stream Error Flag in case of failure */
fd = conn->handle.fd = sock_create_server_socket(conn, be, &stream_err); fd = conn->handle.fd = sock_create_server_socket(conn, be, PROTO_TYPE_DGRAM, SOCK_DGRAM, &stream_err);
if (fd == -1) if (fd == -1)
return stream_err; return stream_err;

View File

@ -397,7 +397,7 @@ int tcp_connect_server(struct connection *conn, int flags)
/* perform common checks on obtained socket FD, return appropriate Stream Error Flag in case of failure */ /* perform common checks on obtained socket FD, return appropriate Stream Error Flag in case of failure */
fd = conn->handle.fd = sock_create_server_socket(conn, be, &stream_err); fd = conn->handle.fd = sock_create_server_socket(conn, be, PROTO_TYPE_STREAM, SOCK_STREAM, &stream_err);
if (fd == -1) if (fd == -1)
return stream_err; return stream_err;

View File

@ -330,7 +330,7 @@ static int uxst_connect_server(struct connection *conn, int flags)
} }
/* perform common checks on obtained socket FD, return appropriate Stream Error Flag in case of failure */ /* perform common checks on obtained socket FD, return appropriate Stream Error Flag in case of failure */
fd = conn->handle.fd = sock_create_server_socket(conn, be, &stream_err); fd = conn->handle.fd = sock_create_server_socket(conn, be, PROTO_TYPE_STREAM, SOCK_STREAM, &stream_err);
if (fd == -1) if (fd == -1)
return stream_err; return stream_err;

View File

@ -265,7 +265,8 @@ static int sock_handle_system_err(struct connection *conn, struct proxy *be)
* upper level is set as SF_ERR_NONE; -1 on failure, stream_err is set to * upper level is set as SF_ERR_NONE; -1 on failure, stream_err is set to
* appropriate value. * appropriate value.
*/ */
int sock_create_server_socket(struct connection *conn, struct proxy *be, int *stream_err) int sock_create_server_socket(struct connection *conn, struct proxy *be,
enum proto_type proto_type, int sock_type, int *stream_err)
{ {
const struct netns_entry *ns = NULL; const struct netns_entry *ns = NULL;
const struct protocol *proto; const struct protocol *proto;
@ -279,9 +280,9 @@ int sock_create_server_socket(struct connection *conn, struct proxy *be, int *st
ns = __objt_server(conn->target)->netns; ns = __objt_server(conn->target)->netns;
} }
#endif #endif
proto = protocol_lookup(conn->dst->ss_family, PROTO_TYPE_STREAM, conn->ctrl->sock_prot == IPPROTO_MPTCP); proto = protocol_lookup(conn->dst->ss_family, proto_type , conn->ctrl->sock_prot == IPPROTO_MPTCP);
BUG_ON(!proto); BUG_ON(!proto);
sock_fd = my_socketat(ns, proto->fam->sock_domain, SOCK_STREAM, proto->sock_prot); sock_fd = my_socketat(ns, proto->fam->sock_domain, sock_type, proto->sock_prot);
/* at first, handle common to all proto families system limits and permission related errors */ /* at first, handle common to all proto families system limits and permission related errors */
if (sock_fd == -1) { if (sock_fd == -1) {