From 337edfdbc50412ac1d0d437de8a777cb009a054c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 27 Oct 2021 17:05:36 +0200 Subject: [PATCH] MINOR: protocols: add a new protocol type selector The protocol selection is currently performed based on the family, control type and socket type. But this is often not enough, as both only provide DGRAM or STREAM, leaving few variants. Protocols like SCTP for example might be indistinguishable from TCP here. Same goes for TCP extensions like MPTCP. This commit introduces a new enum proto_type that is placed in each and every protocol definition, that will usually more or less match the sock_type, but being an enum, will support additional values. --- include/haproxy/protocol-t.h | 8 ++++++++ src/proto_quic.c | 2 ++ src/proto_sockpair.c | 1 + src/proto_tcp.c | 2 ++ src/proto_udp.c | 2 ++ src/proto_uxdg.c | 1 + src/proto_uxst.c | 1 + 7 files changed, 17 insertions(+) diff --git a/include/haproxy/protocol-t.h b/include/haproxy/protocol-t.h index 7ce73db87..895ad3bc5 100644 --- a/include/haproxy/protocol-t.h +++ b/include/haproxy/protocol-t.h @@ -48,6 +48,13 @@ struct connection; # error "Can't build on the target system, AF_CUST_MAX overflow" #endif +/* socket-level protocol types, used for protocol selection */ +enum proto_type { + PROTO_TYPE_STREAM, /* streaming protocol (like TCP) */ + PROTO_TYPE_DGRAM, /* datagram protocol (like UDP) */ + PROTO_NUM_TYPES /* must be the last one */ +}; + /* max length of a protocol name, including trailing zero */ #define PROTO_NAME_LEN 16 @@ -83,6 +90,7 @@ struct protocol { char name[PROTO_NAME_LEN]; /* protocol name, zero-terminated */ struct proto_fam *fam; /* protocol family */ int ctrl_type; /* control layer type (SOCK_STREAM/SOCK_DGRAM) */ + enum proto_type proto_type; /* protocol type (PROTO_TYPE_*) */ int sock_type; /* socket type, as passed to socket() */ int sock_prot; /* socket protocol, as passed to socket() */ diff --git a/src/proto_quic.c b/src/proto_quic.c index 58679eb3a..1aa3e6950 100644 --- a/src/proto_quic.c +++ b/src/proto_quic.c @@ -78,6 +78,7 @@ struct protocol proto_quic4 = { .fam = &proto_fam_inet4, /* socket layer */ + .proto_type = PROTO_TYPE_DGRAM, .sock_type = SOCK_DGRAM, .sock_prot = IPPROTO_UDP, .rx_enable = sock_enable, @@ -115,6 +116,7 @@ struct protocol proto_quic6 = { .fam = &proto_fam_inet6, /* socket layer */ + .proto_type = PROTO_TYPE_DGRAM, .sock_type = SOCK_DGRAM, .sock_prot = IPPROTO_UDP, .rx_enable = sock_enable, diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index 7d4f7eeec..c63f02ae1 100644 --- a/src/proto_sockpair.c +++ b/src/proto_sockpair.c @@ -87,6 +87,7 @@ struct protocol proto_sockpair = { .fam = &proto_fam_sockpair, /* socket layer */ + .proto_type = PROTO_TYPE_STREAM, .sock_type = SOCK_STREAM, .sock_prot = 0, .rx_enable = sock_enable, diff --git a/src/proto_tcp.c b/src/proto_tcp.c index a8b15b21a..83d93fd64 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -79,6 +79,7 @@ struct protocol proto_tcpv4 = { .fam = &proto_fam_inet4, /* socket layer */ + .proto_type = PROTO_TYPE_STREAM, .sock_type = SOCK_STREAM, .sock_prot = IPPROTO_TCP, .rx_enable = sock_enable, @@ -121,6 +122,7 @@ struct protocol proto_tcpv6 = { .fam = &proto_fam_inet6, /* socket layer */ + .proto_type = PROTO_TYPE_STREAM, .sock_type = SOCK_STREAM, .sock_prot = IPPROTO_TCP, .rx_enable = sock_enable, diff --git a/src/proto_udp.c b/src/proto_udp.c index c5ecfacd0..d2849c035 100644 --- a/src/proto_udp.c +++ b/src/proto_udp.c @@ -67,6 +67,7 @@ struct protocol proto_udp4 = { .fam = &proto_fam_inet4, /* socket layer */ + .proto_type = PROTO_TYPE_DGRAM, .sock_type = SOCK_DGRAM, .sock_prot = IPPROTO_UDP, .rx_enable = sock_enable, @@ -100,6 +101,7 @@ struct protocol proto_udp6 = { .fam = &proto_fam_inet6, /* socket layer */ + .proto_type = PROTO_TYPE_DGRAM, .sock_type = SOCK_DGRAM, .sock_prot = IPPROTO_UDP, .rx_enable = sock_enable, diff --git a/src/proto_uxdg.c b/src/proto_uxdg.c index b0efe867c..6f070b4c1 100644 --- a/src/proto_uxdg.c +++ b/src/proto_uxdg.c @@ -57,6 +57,7 @@ struct protocol proto_uxdg = { .fam = &proto_fam_unix, /* socket layer */ + .proto_type = PROTO_TYPE_DGRAM, .sock_type = SOCK_DGRAM, .sock_prot = 0, .rx_enable = sock_enable, diff --git a/src/proto_uxst.c b/src/proto_uxst.c index 45cb56f36..b615a8eae 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -73,6 +73,7 @@ struct protocol proto_uxst = { .fam = &proto_fam_unix, /* socket layer */ + .proto_type = PROTO_TYPE_STREAM, .sock_type = SOCK_STREAM, .sock_prot = 0, .rx_enable = sock_enable,