#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 */
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,
};
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,
/* Registers the protocol <proto> */
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);
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);