DEBUG: protocol: yell loudly during registration of invalid sock_domain

The test on the sock_domain is a bit useless because the protocols are
registered at boot time, and the test silently fails and returns no
error. Use a BUG_ON() instead to make sure to catch such bugs in the
code if any.
This commit is contained in:
Willy Tarreau 2021-10-27 15:06:35 +02:00
parent 52b28d2f30
commit bdcee7fbc9

View File

@ -35,12 +35,15 @@ __decl_spinlock(proto_lock);
/* Registers the protocol <proto> */
void protocol_register(struct protocol *proto)
{
int sock_domain = proto->fam->sock_domain;
BUG_ON(sock_domain < 0 || sock_domain >= AF_CUST_MAX);
HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
LIST_APPEND(&protocols, &proto->list);
if (proto->fam->sock_domain >= 0 && proto->fam->sock_domain < AF_CUST_MAX)
__protocol_by_family[proto->fam->sock_domain]
[proto->sock_type == SOCK_DGRAM]
[proto->ctrl_type == SOCK_DGRAM] = proto;
__protocol_by_family[sock_domain]
[proto->sock_type == SOCK_DGRAM]
[proto->ctrl_type == SOCK_DGRAM] = proto;
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
}