]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: protocols: add a new protocol type selector
authorWilly Tarreau <w@1wt.eu>
Wed, 27 Oct 2021 15:05:36 +0000 (17:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 27 Oct 2021 15:05:36 +0000 (17:05 +0200)
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
src/proto_quic.c
src/proto_sockpair.c
src/proto_tcp.c
src/proto_udp.c
src/proto_uxdg.c
src/proto_uxst.c

index 7ce73db8742971cebc25bfbc49320fa40dfb1372..895ad3bc53af74011ebeb9c6fedd500bb9908185 100644 (file)
@@ -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() */
 
index 58679eb3abdb06986a4d0496d0971f5ade8e6c9f..1aa3e69500c64bf99884b5378e9b6b9ed76cf843 100644 (file)
@@ -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,
index 7d4f7eeecf4ea404da59927cd9f06fe6ac5f5b8f..c63f02ae101ee4d8dda27527d2ab9f6f2efab8d9 100644 (file)
@@ -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,
index a8b15b21adaf29651ce65aa61c4de018f98f1496..83d93fd64a8434525115a5a2402480c480a5f4aa 100644 (file)
@@ -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,
index c5ecfacd0fd5277de145313750ad71739af675f0..d2849c035102b0f35614f5ef7d04d8e84b5b13af 100644 (file)
@@ -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,
index b0efe867c494afc6349dcf234a969bb3f3602e5d..6f070b4c17af046f2c72ee3ffc815cd9c586f1bc 100644 (file)
@@ -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,
index 45cb56f369ae193313bf7fe201e7686379df59f1..b615a8eae56063b99bcc2b3f8e7ca2393b6a2a0e 100644 (file)
@@ -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,