diff --git a/include/haproxy/protocol-t.h b/include/haproxy/protocol-t.h index fde7590a48..838c7c31c1 100644 --- a/include/haproxy/protocol-t.h +++ b/include/haproxy/protocol-t.h @@ -70,7 +70,17 @@ enum proto_type { #define PROTO_F_REUSEPORT_TESTED 0x00000002 /* SO_REUSEPORT support was tested */ /* 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. There is + * permanent confusion between domain and family. Here's how it works: + * - the domain defines the format of addresses (e.g. sockaddr_in etc), + * it is passed as the first argument to socket() + * - the family is part of the address and is stored in receivers, servers + * and everywhere there is an address. It's also a proto_fam selector. + * Domains are often PF_xxx though man 2 socket on Linux quotes 4.x BSD's man + * that says AF_* can be used everywhere. At least it tends to keep the code + * clearer about the intent. In HAProxy we're defining new address families + * with AF_CUST_* which appear in addresses, and they cannot be used for the + * domain, the socket() call must use sock_domain instead. */ struct proto_fam { char name[PROTO_NAME_LEN]; /* family name, zero-terminated */ diff --git a/src/proto_rhttp.c b/src/proto_rhttp.c index 0bf5bdc511..e831a59365 100644 --- a/src/proto_rhttp.c +++ b/src/proto_rhttp.c @@ -22,8 +22,8 @@ struct proto_fam proto_fam_rhttp = { .name = "rhttp", - .sock_domain = AF_CUST_RHTTP_SRV, - .sock_family = AF_INET, + .sock_domain = AF_INET, + .sock_family = AF_CUST_RHTTP_SRV, .bind = rhttp_bind_receiver, }; diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index a719063a81..69ab45cfcb 100644 --- a/src/proto_sockpair.c +++ b/src/proto_sockpair.c @@ -50,8 +50,8 @@ struct connection *sockpair_accept_conn(struct listener *l, int *status); struct proto_fam proto_fam_sockpair = { .name = "sockpair", - .sock_domain = AF_CUST_SOCKPAIR, - .sock_family = AF_UNIX, + .sock_domain = AF_UNIX, + .sock_family = AF_CUST_SOCKPAIR, .sock_addrlen = sizeof(struct sockaddr_un), .l3_addrlen = sizeof(((struct sockaddr_un*)0)->sun_path), .addrcmp = NULL, diff --git a/src/protocol.c b/src/protocol.c index 399835a887..69f4595bb2 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -38,14 +38,14 @@ __decl_spinlock(proto_lock); /* Registers the protocol */ void protocol_register(struct protocol *proto) { - int sock_domain = proto->fam->sock_domain; + int sock_family = proto->fam->sock_family; - BUG_ON(sock_domain < 0 || sock_domain >= AF_CUST_MAX); + BUG_ON(sock_family < 0 || sock_family >= AF_CUST_MAX); BUG_ON(proto->proto_type >= PROTO_NUM_TYPES); HA_SPIN_LOCK(PROTO_LOCK, &proto_lock); LIST_APPEND(&protocols, &proto->list); - __protocol_by_family[sock_domain] + __protocol_by_family[sock_family] [proto->proto_type] [proto->xprt_type == PROTO_TYPE_DGRAM] = proto; HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock); diff --git a/src/sock.c b/src/sock.c index df82c6ea7b..61ebf4a929 100644 --- a/src/sock.c +++ b/src/sock.c @@ -1147,7 +1147,7 @@ int _sock_supports_reuseport(const struct proto_fam *fam, int type, int protocol fd1 = fd2 = -1; /* ignore custom sockets */ - if (!fam || fam->sock_domain >= AF_MAX) + if (!fam || fam->sock_family >= AF_MAX) goto leave; fd1 = socket(fam->sock_domain, type, protocol);