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.
This commit is contained in:
Willy Tarreau 2021-10-27 17:05:36 +02:00
parent bdcee7fbc9
commit 337edfdbc5
7 changed files with 17 additions and 0 deletions

View 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() */

View 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,

View 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,

View 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,

View 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,

View 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,

View 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,