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.
diff --git a/src/protocol.c b/src/protocol.c
index b33e494..dc0e41d 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -35,12 +35,15 @@
/* 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);
}